QueryExecutor

internal class QueryExecutor(stream: PgStream, maxParameterWriterCapacity: Int?, initialParameterWriterCapacity: Int?, logParameterValues: Boolean)

Handles the low-level execution of PostgreSQL queries over the wire protocol.

This executor manages communication with the database using both the Simple Query Protocol (for utility statements) and the Extended Query Protocol (for parameterized DML and DQL). It is responsible for parsing responses, managing the transaction state flag, and mapping results back into usable domain objects.

Constructors

Link copied to clipboard
constructor(stream: PgStream, maxParameterWriterCapacity: Int?, initialParameterWriterCapacity: Int?, logParameterValues: Boolean)

Properties

Link copied to clipboard

Whether a statement that finds no transaction on the server opens one first.

Link copied to clipboard

What the next BEGIN carries after it - SET TRANSACTION, SET LOCAL - or null for nothing.

Functions

Link copied to clipboard

Opens the transaction a BEGIN is waiting on, for the one caller that talks to the server without an exchange of this class: a COPY, whose transfer outlives any single exchange. This one waits for the answer, a round trip of its own, before the COPY goes out.

Link copied to clipboard
fun control(sql: String)

Runs a statement that manages the connection or its transaction itself: COMMIT, ROLLBACK, a savepoint being rolled back to or released, a session setting, the validation probe.

Link copied to clipboard
fun execute(sql: String, ignoreRows: Boolean = false)

Uses Simple Query Protocol (Q). Intended for calls that do not return results or where results are ignored (e.g., SET TIME ZONE, BEGIN).

Link copied to clipboard
fun executeUpdate(sql: String, params: Array<out Any?> = emptyArray(), parameterSerializer: ParameterSerializer? = null): Long

Uses Extended Query Protocol (Parse, Bind, Execute, Sync). Intended for DML (INSERT, UPDATE, DELETE). Expects no rows returned. Returns the number of updated rows.

Link copied to clipboard
fun query(sql: String, params: Array<out Any?> = emptyArray(), parameterSerializer: ParameterSerializer? = null, mapper: ResultMapper, maxRows: Int = 0): List<Row>

Uses Extended Query Protocol. Intended for DQL (SELECT). Returns a parsed list of rows (Row) immediately.

fun <R> query(sql: String, params: Array<out Any?> = emptyArray(), parameterSerializer: ParameterSerializer?, mapper: ResultMapper, maxRows: Int = 0, transform: (Row) -> R): List<R>

Uses Extended Query Protocol. Intended for DQL (SELECT). Returns a parsed list of elements using the provided transform function immediately.

Link copied to clipboard
fun <R> queryForEach(sql: String, params: Array<out Any?> = emptyArray(), parameterSerializer: ParameterSerializer, mapper: ResultMapper, fetchSize: Int, transform: (Row) -> R, block: (R) -> Unit)

Uses Extended Query Protocol. Intended for DQL (SELECT). Iterates over rows in batches of fetchSize and applies the given transform and block. A fetchSize of 0 is Execute's own "no limit": one batch carrying the whole result.