Skip to content

DbClientPg

do- edited this page Jan 14, 2023 · 74 revisions

DbClientPg is a thin wrapper above the native PostgreSQL client designed for using in doix Jobs.

Instances are created by DbPoolPg objects, part of Application. Application developers should never instantiate those objects directly.

Properties

Name Description
uuid The unique ID of this client, mainly for logging purposes
raw The pg.Client instance used by this wrapper

Events

Name Payload Description
start {sql, params} emitted before executing any database query.
error the error caught emitted when an error occurs while executing a query
finish emitted right after the query execution is terminated (one way or another)

Static functions

DbClientPg.normalizeSQL (sql)

Returns the sql string with all comments stripped off and ?s replaced with $1, $2 and so on.

? occurring right after ::jsonb are not replaced (to let use JSONB operators).

Methods

do (sql, params = [])

This asynchronous method executes the given sql with the given params list. Basically it forwards the call to the native client.query returning the same result or throwing the same error.

getArray (sql, params = [], options = {})

This asynchronous method executes the given sql with the given params list and returns the resulting record set as an Array.

Options

Name Type Description
into Array If set, retrieved records are pushed into this array, and it is returned upon a successful execution.

getStream (sql, params = [], options = {})

This asynchronous method executes the given sql with the given params list and returns the resulting record set as a Readable stream.

Options

Name Type Description
rowMode String If 'array', records are Arrays of column values, otherwise plain Objets (key-value pairs)

Clone this wiki locally