@knorm/postgres
Postgres plugin for @knorm/knorm
that enables running queries agaisnt postgres. Also, it adds postgres-specific
features such as:
- automatically JSON-stringifying all
json
and jsonb
fields before save (insert or update) - automatically validating all
string
fields with maxLength: 255
limit
, offset
, returning
query options and ilike
where option,
via sql-bricks-postgres- updating multiple rows using a single query with
UPDATE FROM
, via
sql-bricks-postgres - connection pooling, via pg
- transactions
Installation
npm install --save @knorm/knorm @knorm/postgres
@knorm/postgres has a peer dependency on @knorm/knorm
Usage
const knorm = require('@knorm/knorm');
const knormPostgres = require('@knorm/postgres');
const orm = knorm({
}).use(
knormPostgres({
})
);
Options
Option | Type | Description |
---|
name | string | the name of the plugin, defaults to 'postgres' |
connection | object or string | if set, this option is passed directly to pg. However, connections can also be configured via environment variables |
initClient | (async) function | a function called when a new client is acquired from the pool. useful for configuring the connection e.g. setting session variables. it's called with the client as the only argument |
restoreClient | (async) function | a function called before a client is released back into the pool. useful for restoring a client e.g. unsetting session variables. it's called with the client as the only argument |
NOTE that all options are optional.