Pg
queryValue
Section titled “queryValue”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
fieldDef
Section titled “fieldDef”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
result
Section titled “result”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
Client
Section titled “Client”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
@param 'a Type hint for the expected result row type
@returns A promise that resolves to the query result
src/Pg.res:50:7
query2
Section titled “query2”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
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
release
Section titled “release”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
onError
Section titled “onError”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
onNotice
Section titled “onNotice”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
notification
Section titled “notification”type notification = { processId: int, channel: string, payload?: string,}
Represents a PostgreSQL notification message.
src/Pg.res:95:3
onNotification
Section titled “onNotification”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
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
@param 'a Type hint for the expected result row type
@returns A promise that resolves to the query result
src/Pg.res:126:7
connect
Section titled “connect”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
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
transaction
Section titled “transaction”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