@venturekit/data API
Functions
Section titled “Functions”RDS Configuration
Section titled “RDS Configuration”| Function | Description |
|---|---|
createRdsConfig(options) | Create RDS configuration |
buildRdsConfig(config) | Build RDS infrastructure config |
Query Utilities
Section titled “Query Utilities”| Function | Signature | Description |
|---|---|---|
query | (sql: string, params?: unknown[], resultsMapper?: (rows) => T) => Promise<T> | Execute a SQL query with automatic dot-notation mapping |
getPool | () => Pool | Get the PostgreSQL connection pool |
mapResults | (rows: Record<string, unknown>[]) => Record<string, unknown>[] | Map flat rows with dot-notation keys into nested objects |
mapRow | (row: Record<string, unknown>) => Record<string, unknown> | Map a single flat row into a nested object |
Result Mapping (dot-notation)
Section titled “Result Mapping (dot-notation)”All queries automatically run through mapResults() which converts dot-notation column aliases into nested objects:
SELECT p.id, p.title, u.id AS "author.id", u.name AS "author.name"FROM posts p JOIN users u ON u.id = p.author_idReturns:
[{ "id": "1", "title": "Hello", "author": { "id": "5", "name": "Alice" } }]Custom Result Mappers
Section titled “Custom Result Mappers”The optional third argument to query() transforms the mapped rows into any shape:
// Extract a single columnconst titles = await query<string[]>( 'SELECT title FROM posts', [], (rows) => rows.map(r => r.title as string),);
// Return a single row or nullconst post = await query<Post | null>( 'SELECT * FROM posts WHERE id = $1', [id], (rows) => (rows[0] as Post) ?? null,);Error Handling
Section titled “Error Handling”- Throws the underlying
pgdriver error on connection/query failures. - If
resultsMapperthrows, that error propagates unchanged. - An empty result set is not an error — it returns
[](or whatever your mapper produces for an empty array).
Transactions
Section titled “Transactions”| Function | Signature | Description |
|---|---|---|
beginTransaction | () => Promise<Transaction> | Start a new transaction |
withTransaction | (fn: (tx: Transaction) => Promise<T>) => Promise<T> | Execute within auto-commit/rollback transaction |
buildTransaction | (client: PoolClient) => Transaction | Build a Transaction from a pool client (used internally by beginTransaction and the handler’s transactional option) |
Migration Utilities
Section titled “Migration Utilities”| Function | Description |
|---|---|
createMigrationConfig(options) | Create migration configuration |
getFlywayEnv(config) | Get Flyway-compatible environment variables |
| Type | Description |
|---|---|
RdsOutputs | RDS deployment outputs (endpoint, port, secret ARN) |
RdsInfraConfig | RDS infrastructure configuration |
Transaction | Transaction object with query(), commit(), rollback() |
ResultsMapper | Function type for mapping query results |
Constants
Section titled “Constants”| Constant | Description |
|---|---|
DEFAULT_RDS_CONFIG | Default RDS configuration |
DEFAULT_MIGRATION_CONFIG | Default migration configuration |