NativeQuery

class NativeQuery(sql: String, queryExecutor: QueryExecutor, typeManager: TypeManager) : Query<NativeQuery>

Represents a query that uses standard PostgreSQL positional parameters (e.g., $1, $2).

NativeQuery passes the provided SQL string and parameters directly to the underlying QueryExecutor without any intermediate parsing or modification of the SQL statement. It provides various execution methods to fetch rows, map results to Kotlin objects, extract single fields, or perform data modifications (updates).

Constructors

Link copied to clipboard
internal constructor(sql: String, queryExecutor: QueryExecutor, typeManager: TypeManager)

Properties

Link copied to clipboard

Parameter converters local to this query, chained to the session's. Converters here are tried first.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Result converters local to this query, chained to the session's. Converters here are tried first.

Link copied to clipboard
Link copied to clipboard
internal val sql: String
Link copied to clipboard
internal val typeManager: TypeManager

The session's type manager, resolving OIDs and holding the parent registries.

Functions

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

Executes a statement with no result and no row count — DDL, SET, administrative commands.

Link copied to clipboard
inline fun <T> fetchField(vararg params: Any?): T

Executes the query and returns the first column of its single row.

Link copied to clipboard
inline fun <T> fetchFields(vararg params: Any?): List<T>

Executes the query and returns the first column of every row, mapped to T.

Link copied to clipboard
inline fun <T> fetchFieldStrict(vararg params: Any?): T

Executes the query and returns the first column of its single row, requiring exactly one row.

Link copied to clipboard
inline fun <T : Any> fetchObject(vararg params: Any?): T?

Executes the query and maps its single row onto T, or returns null when nothing matched.

Link copied to clipboard
inline fun <T : Any> fetchObjects(vararg params: Any?): List<T>

Executes the query and maps every row onto T.

Link copied to clipboard
inline fun <T : Any> fetchObjectStrict(vararg params: Any?): T

Executes the query and maps its single row onto T, requiring exactly one row.

Link copied to clipboard
fun fetchRow(vararg params: Any?): Row?

Executes the query and returns its single row, or null when nothing matched.

Link copied to clipboard
fun fetchRows(vararg params: Any?): List<Row>

Executes the query and returns every row, undecoded into any particular shape.

Link copied to clipboard
fun fetchRowStrict(vararg params: Any?): Row

Executes the query and returns its single row, requiring exactly one.

Link copied to clipboard
inline fun <T> forEachField(vararg params: Any?, fetchSize: Int, crossinline block: (T) -> Unit)

Streams the result, handing the first column of each row to block as T.

Link copied to clipboard
inline fun <T : Any> forEachObject(vararg params: Any?, fetchSize: Int, crossinline block: (T) -> Unit)

Streams the result, mapping each row onto T and handing it to block.

Link copied to clipboard
fun forEachRow(vararg params: Any?, fetchSize: Int, block: (Row) -> Unit)

Streams the result, handing each row to block as it arrives.

Link copied to clipboard

Registers a ParameterConverter for this query only, ahead of any the session already holds.

Link copied to clipboard

Registers a ResultConverter for this query only, ahead of any the session already holds.

Link copied to clipboard
fun update(vararg params: Any?): Long

Executes a statement that changes rows without returning any — INSERT, UPDATE, DELETE.

Link copied to clipboard
internal inline fun <R> withPositionalContext(params: Array<out Any?>, block: () -> R): R

Names this query's parameters for a QueryContext and runs block under it.

Link copied to clipboard
internal inline fun <R> withQueryContext(sql: String, crossinline paramsProvider: () -> Map<String, Any?>, crossinline dbSqlProvider: () -> String? = { null }, crossinline dbParamsProvider: () -> List<Any?>? = { null }, block: () -> R): R