DataAccess

Main entry point to the data access layer, providing a unified API for interacting with PostgreSQL.

This facade orchestrates different interaction patterns:

  1. Direct Queries: Execution of single SELECT, INSERT, UPDATE, or DELETE operations in auto-commit mode.

  2. Managed Transactions: Atomic execution of complex logic blocks where multiple operations must succeed or fail together.

  3. Declarative Transaction Plans: Execution of pre-built sequences of operations (TransactionPlan) that can handle step dependencies.

  4. Pub/Sub Messaging: Native integration with PostgreSQL LISTEN/NOTIFY mechanism for real-time updates.

Implementation is typically thread-safe and manages an underlying connection pool (e.g., HikariCP). Call close or use the interface within a use block to ensure proper resource cleanup.

Functions

Link copied to clipboard
abstract override fun close()

Closes the data access object and releases any underlying resources (e.g., connection pool).

Link copied to clipboard

Creates a new PgChannelListener backed by a dedicated database connection.

Link copied to clipboard
abstract fun deleteFrom(table: String): DeleteQueryBuilder

Starts building a DELETE query.

Link copied to clipboard
abstract fun executeTransactionPlan(plan: TransactionPlan, propagation: TransactionPropagation = TransactionPropagation.REQUIRED, isolation: IsolationLevel = IsolationLevel.DEFAULT, readOnly: Boolean = false, timeoutSeconds: Int? = null): DataResult<TransactionPlanResult>

Executes a pre-configured TransactionPlan as a single, atomic transaction.

Link copied to clipboard
abstract fun insertInto(table: String): InsertQueryBuilder

Starts building an INSERT query.

Link copied to clipboard
abstract fun notify(channel: String, payload: String? = null): DataResult<Unit>

Sends a notification to the given PostgreSQL channel via pg_notify.

Link copied to clipboard
abstract fun rawQuery(sql: String): RawQueryBuilder

Enables execution of a raw SQL query.

Link copied to clipboard
abstract fun select(vararg columns: String): SelectQueryBuilder

Starts building a SELECT query.

Link copied to clipboard
abstract fun <T> transaction(propagation: TransactionPropagation = TransactionPropagation.REQUIRED, isolation: IsolationLevel = IsolationLevel.DEFAULT, readOnly: Boolean = false, timeoutSeconds: Int? = null, block: (tx: QueryOperations) -> DataResult<T>): DataResult<T>

Executes a block of code within a managed transaction scope.

Link copied to clipboard
abstract fun update(table: String): UpdateQueryBuilder

Starts building an UPDATE query.