{ } qjs-modules

pgsql

Source: quickjs-pgsql.c — module exports PGconn, PGerror, PGresult

Asynchronous PostgreSQL client (wraps libpq). Connection and queries run non-blocking against the connection's socket fd.

PGconn

new PGconn()   // length 1

Methods

MethodArgsDescription
connect(params)1Connects using a conninfo string/object; resolves when ready.
query(sql)1Runs a query; resolves to a PGresult (alias execute).
close()0Closes the connection.
escapeString(str)1Escapes a string literal value.
escapeLiteral(str)1Quotes-and-escapes a string literal.
escapeIdentifier(str)1Quotes-and-escapes an identifier.
escapeBytea(buf)1Encodes binary data as bytea.
unescapeBytea(str)1Decodes a bytea representation.
valueString(value)0Renders a single value as SQL.
valuesString(values)1Renders a value list as SQL.
insertQuery(table, row)2Builds an INSERT statement.

Properties

PropertyKindDescription
cmdTuples / affectedRowsgetterRows affected by the last command.
nonblockinggetter/setterNon-blocking mode flag.
fdgetterConnection socket descriptor.
errorMessagegetterLast error text.
optionsgetterConnection options.
insertIdgetterLast inserted id.
charsetgetter/setterClient encoding.
protocolVersion / serverVersiongetterProtocol / server version.
user, password, host, port, db, conninfogetterConnection parameters.

Static functions

escapeString(str), escapeBytea(buf), unescapeBytea(str).

PGresult

A result set; iterable.

MemberArgsKindDescription
fetchRow()0methodNext row as an array.
fetchAssoc()0methodNext row as an object.
fetchField(i)1methodMetadata for one field.
fetchFields()0methodMetadata for all fields.
eof—getterWhether rows are exhausted.
numRows—getterRow count (enumerable).
numFields—getterField count (enumerable).
[Symbol.iterator]()0methodRow iteration.

PGerror

Error subclass (name = "PGerror") carrying PostgreSQL error details.