{ } 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.

Export list

Generated by utilities/doc-api.js from the pgsql dump of utilities/api-surface.sh: 56 members. Edit the text above this block, not the block.

PGconn

class, constructible

  • static methods: escapeBytea(), escapeString(), unescapeBytea()
  • static values: RESULT_OBJECT = 1, RESULT_STRING = 2, RESULT_TBLNAM = 4
  • methods: close(), connect(), escapeBytea(), escapeIdentifier(), escapeLiteral(), escapeString(), execute(), insertQuery(), query(), unescapeBytea(), valueString(), valuesString()
  • properties: RESULT_OBJECT = 1, RESULT_STRING = 2, RESULT_TBLNAM = 4, affectedRows (get), charset (get/set), cmdTuples (get), conninfo (get), db (get), errorMessage (get), fd (get), host (get), insertId (get), nonblocking (get/set), options (get), password (get), port (get), protocolVersion (get), serverVersion (get), user (get), [Symbol.toStringTag]

PGerror

class, constructible

  • properties: name, type = 0, [Symbol.toStringTag]

PGresult

class, constructible

  • methods: fetchAssoc(), fetchField(), fetchFields(), fetchRow(), [Symbol.iterator]()
  • properties: eof (get), numFields (get), numRows (get), [Symbol.toStringTag]