Registry / database / fortune-postgres

fortune-postgres

JSON →
library1.6.11jsnpmunverified

A PostgreSQL adapter for Fortune.js that maps Fortune's data interface directly to SQL statements without ORM overhead. Supports non-destructive table setup, array foreign keys for performance, and optimized query building. Current stable version is 1.6.11, last updated in 2020 with sporadic maintenance. Requires PostgreSQL 9.4+. Unlike ORM-based adapters, it delegates foreign key enforcement to Fortune.js and avoids junction tables by using array columns. The adapter also exposes the underlying pg-pool for raw queries. Release cadence is low; no major changes expected.

npm install fortune-postgres
INSTALL
IMPORT
SIG · FORTUNE-POSTGRES
F
fortune-postgres
databasejavascriptv1.6.11
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
✓ const postgresAdapter = require('fortune-postgres')
✗ import postgresAdapter from 'fortune-postgres'
Package is CommonJS-only, no ESM exports. Use require().
Fortune store with adapter
✓ const store = fortune(schema, { adapter: [postgresAdapter, { url }] })
✗ const store = fortune(schema, { adapter: postgresAdapter })
Adapter must be passed as an array with options object as second element.
Pool access
✓ store.adapter.pool
✗ store.adapter.pool.query(...)
pool property exists, but consider it private. Use store.adapter.client alias.

Shows how to set up Fortune.js with the Postgres adapter, define a simple schema, and perform create/find operations.

const fortune = require('fortune'); const postgresAdapter = require('fortune-postgres'); const store = fortune({ user: { name: { type: String }, posts: { link: 'post', inverse: 'author', isArray: true } }, post: { title: { type: String }, author: { link: 'user', inverse: 'posts' } } }, { adapter: [ postgresAdapter, { url: process.env.DATABASE_URL || 'postgres://postgres:password@localhost:5432/myapp', useForeignKeys: false } ] }); store.connect().then(() => { console.log('Connected to PostgreSQL'); return store.create('user', { name: 'Alice' }); }).then(user => { console.log('Created user:', user); return store.find('user', { query: { name: 'Alice' } }); }).then(users => { console.log('Found users:', users); store.disconnect(); }).catch(err => { console.error('Error:', err); store.disconnect(); });
Debug
Known issues
breakingRequires Node >=10, older versions unsupported.
fix
Upgrade Node to version 10 or higher.
affects: <10
gotchaAdapter does not alter existing columns; schema changes require manual migration.
fix
Manually alter tables using SQL or a migration tool.
affects: all
gotchaArray foreign keys are emulated (no database-level FK constraints); referential integrity is handled by Fortune only.
fix
Use `useForeignKeys: true` in options to enable FK constraints on non-array fields, but note it adds overhead.
affects: all
deprecatedDefault primary key generation uses base64-encoded random bytes, may conflict with some systems.
fix
Provide custom `generatePrimaryKey` function or use UUIDs.
affects: all
gotchaSSL must be explicitly enabled via URL query parameter or connection object.
fix
Add `?ssl=true` to URL or set `ssl: true` in connection object.
affects: all
Errors
Common errors & fixes
Cannot find module 'fortune-postgres'
Package not installed or missing from node_modules.
fix
Run `npm install fortune-postgres` and ensure it's in dependencies.
The `adapter` option must be an array of adapter and options.
Passed adapter function directly instead of array.
fix
Use `adapter: [postgresAdapter, { url: '...' }]`.
Error: connect ECONNREFUSED 127.0.0.1:5432
PostgreSQL server not running or connection details incorrect.
fix
Ensure PostgreSQL is running and connection URL is correct.
TypeError: store.adapter.pool is undefined
Adapter not yet connected or initialization failed.
fix
Ensure `store.connect()` is called before accessing pool.
Upgrade
Version history
1.6.11latest on npm
Audit
Dependencies
pgrequiredPostgreSQL client driver
pg-poolrequiredConnection pooling (may be included by pg, but explicitly used)
Agent activity
12 hits · last 30 days
node
10
Anthropic
1
Resources
fortune-postgres — npm install fortune-postgres · libregistry