This is a Postgres adapter for Fortune. To use this adapter, the user and database must be setup prior to attempting to connect.
$ createuser [username]
$ createdb [dbname]
- Postgres version 9.4 or newer. Older versions are untested and will not work.
Install the fortune-postgres
package from npm
:
$ npm install fortune-postgres
Then use it with Fortune:
import Fortune from 'fortune'
import postgresAdapter from 'fortune-postgres'
const fortune = new Fortune({
adapter: {
type: postgresAdapter,
options: {
url: `postgres://${username}:${password}@${host}:${port}/${db}`
}
}
})
url
: Connection URL string. Required.isNative
: Whether or not to use native bindings, requirespg-native
module, which is an optional dependency of this one. Default:false
.primaryKeyType
: Data type of the primary key. May eitherString
orNumber
. Default:String
.generatePrimaryKey
: A function that accepts one argument, thetype
of the record, and returns either aString
orNumber
. By default, it returns 15 random bytes, base64 encoded.useForeignKeys
: Whether or not to use foreign key constraint, optional since it will only be applied to non-array fields. Default:false
.
The query
field for the options
object should be a string containing arbitrary SQL. It's not recommended to allow direct user input for this, for obvious reasons (SQL injection).
This software is licensed under the MIT License.