{"id":20199916,"url":"https://github.com/fortunejs/fortune-postgres","last_synced_at":"2025-08-10T19:10:35.744Z","repository":{"id":10544463,"uuid":"12741343","full_name":"fortunejs/fortune-postgres","owner":"fortunejs","description":"Postgres adapter for Fortune.","archived":false,"fork":false,"pushed_at":"2023-07-19T05:23:54.000Z","size":210,"stargazers_count":23,"open_issues_count":5,"forks_count":21,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-09T06:35:58.622Z","etag":null,"topics":["postgres","postgres-adapter","postgresql"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fortunejs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-09-10T21:41:16.000Z","updated_at":"2024-09-21T08:41:59.000Z","dependencies_parsed_at":"2024-06-19T17:39:12.105Z","dependency_job_id":"40f92ad7-78f2-4016-bdc4-689024789ca6","html_url":"https://github.com/fortunejs/fortune-postgres","commit_stats":{"total_commits":104,"total_committers":13,"mean_commits":8.0,"dds":0.6538461538461539,"last_synced_commit":"4c5a9c6b6f21b238411204411436c858aaef0bbf"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/fortunejs/fortune-postgres","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fortunejs%2Ffortune-postgres","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fortunejs%2Ffortune-postgres/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fortunejs%2Ffortune-postgres/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fortunejs%2Ffortune-postgres/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fortunejs","download_url":"https://codeload.github.com/fortunejs/fortune-postgres/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fortunejs%2Ffortune-postgres/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269707063,"owners_count":24462304,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-10T02:00:08.965Z","response_time":71,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["postgres","postgres-adapter","postgresql"],"created_at":"2024-11-14T04:40:25.968Z","updated_at":"2025-08-10T19:10:35.646Z","avatar_url":"https://github.com/fortunejs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fortune Postgres Adapter\n\n[![Build Status](https://img.shields.io/travis/fortunejs/fortune-postgres/master.svg?style=flat-square)](https://travis-ci.org/fortunejs/fortune-postgres)\n[![npm Version](https://img.shields.io/npm/v/fortune-postgres.svg?style=flat-square)](https://www.npmjs.com/package/fortune-postgres)\n[![License](https://img.shields.io/npm/l/fortune-postgres.svg?style=flat-square)](https://raw.githubusercontent.com/fortunejs/fortune-postgres/master/LICENSE)\n\nThis is a Postgres adapter for Fortune which makes use of specific Postgres functionality. Key features include:\n\n- **Non-destructive table setup**: it will create tables and columns automatically upon connection, but will not alter columns. Data migrations are not handled by this adapter.\n- **Emulates array foreign keys**: this adapter will *not* create junction tables, but instead create array columns, which is much faster than joins but lacks a database-level foreign key constraint, this is delegated to Fortune.\n- **SQL query building**: it interprets arguments from Fortune's adapter interface directly, and generates optimized queries.\n\nTo use this adapter, the [database user](http://www.postgresql.org/docs/9.4/static/app-createuser.html) must be setup prior to attempting to connect, or the default `postgres` user can be used.\n\n*This adapter, along with Fortune.js, does not implement ORM. This adapter sets up tables, and translates the adapter interface directly into SQL statements. It is a plain query builder for Postgres.*\n\n\n## Requirements\n\n- Postgres version **9.4** or newer. Older versions are untested and will not work.\n\n\n## Usage\n\nInstall the `fortune-postgres` package from `npm`:\n\n```\n$ npm install fortune-postgres\n```\n\nThen use it with Fortune:\n\n```js\nconst fortune = require('fortune')\nconst postgresAdapter = require('fortune-postgres')\n\nconst store = fortune({ ... }, {\n  adapter: [\n    postgresAdapter,\n    {\n      // options object, URL is mandatory.\n      url: `postgres://${username}:${password}@${host}:${port}/${db}`\n    }\n  ]\n})\n```\n\n\n## Options\n\n- `url`: Connection URL string. **Required** if no other connection options are given. Add the query param `ssl=true` to enable SSL.\n- `connection`: Connection object, see [documentation](https://github.com/brianc/node-pg-pool). This takes precendence over the URL. Optional.\n- `pool`: an instance of `node-pg-pool` can be passed in directly. This takes precendence over all connection settings. Optional.\n- `isNative`: Whether or not to use native bindings, requires `pg-native` module, which is an optional dependency of this one. Default: `false`.\n- `typeMap`: an object keyed by type name and valued by table name.\n- `primaryKeyType`: Data type of the primary key. May be `String`, `Number`, or a string for custom type. Default: `String`.\n- `generatePrimaryKey`: A function that accepts one argument, the `type` of the record, and returns either a `String` or `Number`. By default,\n  it returns 15 random bytes, base64 encoded in a URI-safe way. Set this to a falsey value like `null` to turn this off.\n- `useForeignKeys`: Whether or not to use foreign key constraint, optional since it will only be applied to non-array fields. Default: `false`.\n\n\n## Extension\n\nThe `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.\n\n\n## SSL\n\nSSL can be enabled by adding `ssl=true` as a query parameter the database URL (e.g. `postgres://postgres@localhost:5432/app_db?ssl=true`). If using the `connection` object, add an `ssl` property with the value `true`.\n\n\n## Internal Usage\n\nThe database client pool is exposed as the `pool` property on the adapter instance, so for example, `store.adapter.pool` (or the alias `store.adapter.client`) lets you use the Postgres driver directly. This should be considered private since it is provided by the underlying implementation `node-pg-pool`, and is exposed for the sake of transparency.\n\nFor more on the API of the `pool` object, refer to [the node-pg-pool documentation](https://github.com/brianc/node-pg-pool).\n\n\n## License\n\nThis software is licensed under the [MIT License](//github.com/fortunejs/fortune-postgres/blob/master/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffortunejs%2Ffortune-postgres","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffortunejs%2Ffortune-postgres","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffortunejs%2Ffortune-postgres/lists"}