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:
const fortune = require('fortune')
const postgresAdapter = require('fortune-postgres')
const store = fortune({ ... }, {
adapter: [
postgresAdapter,
{
// options object, URL is mandatory.
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
.typeMap
: an object keyed by type name and valued by table name.primaryKeyType
: Data type of the primary key. May beString
,Number
, or a string for custom type. 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. Set this to a falsy value likenull
to turn this off.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 function that accepts two arguments, the prepared SQL query and parameters, and returns an SQL query.
The database client is exposed as the client
property on the adapter instance, so for example, store.adapter.client
lets you use the Postgres driver directly.
This software is licensed under the MIT License.