Skip to content

Pg

src/Pg.res
type queryValue = String(string) | Float(float) | Bool(bool)

Represents a value that can be used in a PostgreSQL query parameter.
Supports string, float, and boolean values.

src/Pg.res:6:1


src/Pg.res
type fieldDef = {
name: string,
tableID: int,
columnID: int,
dataTypeID: int,
dataTypeSize: int,
dataTypeModifier: int,
format: string,
}

Represents metadata about a field in a PostgreSQL result set.

src/Pg.res:14:1


src/Pg.res
type result<'a> = {
command: string,
rowCount: option<int>,
oid: int,
fields: array<fieldDef>,
rows: array<'a>,
}

Represents the result of a PostgreSQL query.
@param 'a The type of the rows returned by the query

src/Pg.res:28:1


src/Pg.res
type client

src/Pg.res:37:3


src/Pg.res
let make: unit => client

src/Pg.res:40:7


src/Pg.res
let query: (
client,
string,
array<queryValue>,
'a,
) => promise<result<'a>>

Executes a parameterized SQL query using the PostgreSQL client.
@param client The PostgreSQL client instance
@param string The SQL query string with parameter placeholders
@param array Array of parameter values to bind to the query
@param 'a Type hint for the expected result row type
@returns A promise that resolves to the query result

src/Pg.res:50:7


src/Pg.res
let query2: (client, string) => promise<result<string>>

Executes a simple SQL query without parameters using the PostgreSQL client.
@param client The PostgreSQL client instance
@param string The SQL query string
@returns A promise that resolves to the query result with string row type

src/Pg.res:63:7


src/Pg.res
let end: client => promise<unit>

Closes the PostgreSQL client connection gracefully.
@param client The PostgreSQL client instance to close
@returns A promise that resolves when the connection is closed

src/Pg.res:70:7


src/Pg.res
let release: client => unit

Releases the client back to the connection pool (for pooled clients).
@param client The PostgreSQL client instance to release

src/Pg.res:76:7


src/Pg.res
let onError: (client, RescriptCore.Error.t => unit) => unit

Registers an error event handler for the PostgreSQL client.
@param client The PostgreSQL client instance
@param Error.t => unit Callback function to handle error events

src/Pg.res:83:7


src/Pg.res
let onNotice: (client, RescriptCore.Error.t => unit) => unit

Registers a notice event handler for the PostgreSQL client.
@param client The PostgreSQL client instance
@param Error.t => unit Callback function to handle notice events

src/Pg.res:90:7


src/Pg.res
type notification = {
processId: int,
channel: string,
payload?: string,
}

Represents a PostgreSQL notification message.

src/Pg.res:95:3


src/Pg.res
let onNotification: (client, notification => unit) => unit

Registers a notification event handler for the PostgreSQL client.
@param client The PostgreSQL client instance
@param notification => unit Callback function to handle notification events

src/Pg.res:106:7


src/Pg.res:1:1


src/Pg.res
type pool

src/Pg.res:113:3


src/Pg.res
let make: unit => pool

src/Pg.res:116:7


src/Pg.res
let query: (pool, string, array<queryValue>, 'a) => promise<result<'a>>

Executes a parameterized SQL query using a connection from the pool.
@param pool The PostgreSQL connection pool instance
@param string The SQL query string with parameter placeholders
@param array Array of parameter values to bind to the query
@param 'a Type hint for the expected result row type
@returns A promise that resolves to the query result

src/Pg.res:126:7


src/Pg.res
let connect: pool => promise<Client.client>

Acquires a client connection from the pool.
@param pool The PostgreSQL connection pool instance
@returns A promise that resolves to a client instance from the pool

src/Pg.res:138:7


src/Pg.res
let end: pool => promise<unit>

Closes all connections in the pool and shuts down the pool.
@param pool The PostgreSQL connection pool instance to close
@returns A promise that resolves when the pool is closed

src/Pg.res:145:7


src/Pg.res
let transaction: (pool, Client.client => promise<'a>) => promise<'a>

Executes a function within a database transaction, automatically handling BEGIN, COMMIT, and ROLLBACK.
If the function throws an error, the transaction is rolled back and the error is re-raised.
@param pool The PostgreSQL connection pool instance
@param Client.client => promise<'a> Function to execute within the transaction context
@returns A promise that resolves to the result of the transaction function

src/Pg.res:154:7


src/Pg.res:1:1