{"id":42772,"library":"fortune-postgres","title":"Fortune Postgres Adapter","description":"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.","status":"maintenance","version":"1.6.11","language":"javascript","source_language":"en","source_url":"https://github.com/fortunejs/fortune-postgres","tags":["javascript","fortune","postgres","postgresql","sql","adapter"],"install":[{"cmd":"npm install fortune-postgres","lang":"bash","label":"npm"},{"cmd":"yarn add fortune-postgres","lang":"bash","label":"yarn"},{"cmd":"pnpm add fortune-postgres","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"PostgreSQL client driver","package":"pg","optional":false},{"reason":"Connection pooling (may be included by pg, but explicitly used)","package":"pg-pool","optional":false}],"imports":[{"note":"Package is CommonJS-only, no ESM exports. Use require().","wrong":"import postgresAdapter from 'fortune-postgres'","symbol":"default","correct":"const postgresAdapter = require('fortune-postgres')"},{"note":"Adapter must be passed as an array with options object as second element.","wrong":"const store = fortune(schema, { adapter: postgresAdapter })","symbol":"Fortune store with adapter","correct":"const store = fortune(schema, { adapter: [postgresAdapter, { url }] })"},{"note":"pool property exists, but consider it private. Use store.adapter.client alias.","wrong":"store.adapter.pool.query(...)","symbol":"Pool access","correct":"store.adapter.pool"}],"quickstart":{"code":"const fortune = require('fortune');\nconst postgresAdapter = require('fortune-postgres');\n\nconst store = fortune({\n  user: {\n    name: { type: String },\n    posts: { link: 'post', inverse: 'author', isArray: true }\n  },\n  post: {\n    title: { type: String },\n    author: { link: 'user', inverse: 'posts' }\n  }\n}, {\n  adapter: [\n    postgresAdapter,\n    {\n      url: process.env.DATABASE_URL || 'postgres://postgres:password@localhost:5432/myapp',\n      useForeignKeys: false\n    }\n  ]\n});\n\nstore.connect().then(() => {\n  console.log('Connected to PostgreSQL');\n  return store.create('user', { name: 'Alice' });\n}).then(user => {\n  console.log('Created user:', user);\n  return store.find('user', { query: { name: 'Alice' } });\n}).then(users => {\n  console.log('Found users:', users);\n  store.disconnect();\n}).catch(err => {\n  console.error('Error:', err);\n  store.disconnect();\n});","lang":"javascript","description":"Shows how to set up Fortune.js with the Postgres adapter, define a simple schema, and perform create/find operations."},"warnings":[{"fix":"Upgrade Node to version 10 or higher.","message":"Requires Node >=10, older versions unsupported.","severity":"breaking","affected_versions":"<10"},{"fix":"Manually alter tables using SQL or a migration tool.","message":"Adapter does not alter existing columns; schema changes require manual migration.","severity":"gotcha","affected_versions":"all"},{"fix":"Use `useForeignKeys: true` in options to enable FK constraints on non-array fields, but note it adds overhead.","message":"Array foreign keys are emulated (no database-level FK constraints); referential integrity is handled by Fortune only.","severity":"gotcha","affected_versions":"all"},{"fix":"Provide custom `generatePrimaryKey` function or use UUIDs.","message":"Default primary key generation uses base64-encoded random bytes, may conflict with some systems.","severity":"deprecated","affected_versions":"all"},{"fix":"Add `?ssl=true` to URL or set `ssl: true` in connection object.","message":"SSL must be explicitly enabled via URL query parameter or connection object.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'1.6.11':41 '2020':45 '9.4':51 'adapt':3,6,56,73,97 'also':74 'array':28,70 'avoid':65 'base':55 'build':36 'cadenc':85 'chang':90 'column':71 'current':37 'data':13 'deleg':58 'destruct':25 'direct':15 'enforc':61 'expect':91 'expos':75 'foreign':29,59 'fortun':1,11,93 'fortune.js':8,63 'interfac':14 'javascript':92 'junction':66 'key':30,60 'last':42 'low':87 'mainten':48 'major':89 'map':10 'non':24 'non-destruct':23 'optim':34 'orm':20,54 'orm-bas':53 'overhead':21 'perform':32 'pg':79 'pg-pool':78 'pool':80 'postgr':2,94 'postgresql':5,50,95 'queri':35,83 'raw':82 'releas':84 'requir':49 'setup':27 'sporad':47 'sql':17,96 'stabl':38 'statement':18 'support':22 'tabl':26,67 'under':77 'unlik':52 'updat':43 'use':69 'version':39 'without':19","created_at":"2026-06-05T16:56:35.111657+00:00","updated_at":"2026-06-05T16:56:35.111657+00:00","problems":[{"fix":"Run `npm install fortune-postgres` and ensure it's in dependencies.","cause":"Package not installed or missing from node_modules.","error":"Cannot find module 'fortune-postgres'"},{"fix":"Use `adapter: [postgresAdapter, { url: '...' }]`.","cause":"Passed adapter function directly instead of array.","error":"The `adapter` option must be an array of adapter and options."},{"fix":"Ensure PostgreSQL is running and connection URL is correct.","cause":"PostgreSQL server not running or connection details incorrect.","error":"Error: connect ECONNREFUSED 127.0.0.1:5432"},{"fix":"Ensure `store.connect()` is called before accessing pool.","cause":"Adapter not yet connected or initialization failed.","error":"TypeError: store.adapter.pool is undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/fortunejs/fortune-postgres#readme","github":"https://github.com/fortunejs/fortune-postgres","docs":null,"changelog":null,"pypi":null,"npm":"fortune-postgres","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}