fortune-postgres travis-ci npm

Postgres adapter for Fortune.

Fortune Postgres Adapter

Build Status npm Version License

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: [
      // 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, requires pg-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 be String, Number, or a string for custom type. Default: String.
  • generatePrimaryKey: A function that accepts one argument, the type of the record, and returns either a String or Number. By default, it returns 15 random bytes, base64 encoded. Set this to a falsy value like null 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.

Internal Usage

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.

Related Repositories



Postgres adapter for Fortune. ...

Top Contributors

sapeien jcallaha Voles itsravenous kketch


-   1.4.6 zip tar
-   1.4.5 zip tar
-   1.4.3 zip tar
-   1.4.2 zip tar
-   1.4.1 zip tar
-   1.4.0 zip tar