Skip to content

@venturekit/data API

FunctionDescription
createRdsConfig(options)Create RDS configuration
buildRdsConfig(config)Build RDS infrastructure config
FunctionSignatureDescription
query(sql: string, params?: unknown[], resultsMapper?: (rows) => T) => Promise<T>Execute a SQL query with automatic dot-notation mapping
getPool() => PoolGet 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

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_id

Returns:

[{ "id": "1", "title": "Hello", "author": { "id": "5", "name": "Alice" } }]

The optional third argument to query() transforms the mapped rows into any shape:

// Extract a single column
const titles = await query<string[]>(
'SELECT title FROM posts',
[],
(rows) => rows.map(r => r.title as string),
);
// Return a single row or null
const post = await query<Post | null>(
'SELECT * FROM posts WHERE id = $1',
[id],
(rows) => (rows[0] as Post) ?? null,
);
  • Throws the underlying pg driver error on connection/query failures.
  • If resultsMapper throws, that error propagates unchanged.
  • An empty result set is not an error — it returns [] (or whatever your mapper produces for an empty array).
FunctionSignatureDescription
beginTransaction() => Promise<Transaction>Start a new transaction
withTransaction(fn: (tx: Transaction) => Promise<T>) => Promise<T>Execute within auto-commit/rollback transaction
buildTransaction(client: PoolClient) => TransactionBuild a Transaction from a pool client (used internally by beginTransaction and the handler’s transactional option)
FunctionDescription
createMigrationConfig(options)Create migration configuration
getFlywayEnv(config)Get Flyway-compatible environment variables
TypeDescription
RdsOutputsRDS deployment outputs (endpoint, port, secret ARN)
RdsInfraConfigRDS infrastructure configuration
TransactionTransaction object with query(), commit(), rollback()
ResultsMapperFunction type for mapping query results
ConstantDescription
DEFAULT_RDS_CONFIGDefault RDS configuration
DEFAULT_MIGRATION_CONFIGDefault migration configuration