Early Access: Documentation is actively evolving and may change without notice.
TypeScript
Use KuraDB from TypeScript resources with full type safety.
KuraDB provides a typed TypeScript client at lib/KuraDB.ts that wraps the resource exports.
Query builder
The query builder is available inside the kuradb resource. Builders are thenable — just await them:
import { db } from './queryBuilder';
import { users } from './schema';
import { eq, and, isNull } from './queryBuilder/operators';
// Select
const activeUsers = await db.select().from(users).where(isNull('deleted_at'));
// Insert
await db.insert(users).values({ username: 'john', email: 'john@example.com' });
// Update
await db.update(users).set({ username: 'jane' }).where(eq('id', userId));
// Delete
await db.delete(users).where(eq('id', userId));You can also use the Lua-shaped alias if you want API parity in shared examples:
import { kura } from './queryBuilder';
await kura.db.insert('users').values({ username: 'john' });db.insert(users) is still the preferred TypeScript style when you want typed table definitions.
Raw SQL
For complex queries beyond the builder:
import { kuradb } from '@your-scope/kuradb';
const user = await kuradb.single<{ id: string; license: string }>(
'SELECT id, license FROM "public"."users" WHERE id = $1',
[userId]
);API reference
| Method | Returns | Description |
|---|---|---|
kuradb.query | Row[] | Execute a query, return all rows |
kuradb.single | Row | null | Return the first row |
kuradb.scalar | T | null | Return a single value |
kuradb.update | number | Execute an update, return affected rows |
kuradb.insert | T | Execute an insert, return the inserted id |
kuradb.prepare | T | Execute a prepared statement |
kuradb.rawExecute | T | Execute with multiple parameter sets |
kuradb.batch | T[] | Pipeline multiple executions of the same statement |
kuradb.insertMany | T | Multi-row bulk insert |
kuradb.transaction | boolean | Declarative transaction (query list) |
kuradb.startTransaction | T | true | false | Imperative transaction (callback with payload-or-false return semantics) |
kuradb.notify | boolean | Send a PostgreSQL NOTIFY |
kuradb.listen | Subscription | Subscribe to a PostgreSQL channel |
kuradb.unlisten | boolean | Unsubscribe from a channel |
kuradb.copyFrom | { bytes, chunks } | Bulk ingest via COPY FROM |
kuradb.copyTo | string | Bulk export via COPY TO |
kuradb.isReady | boolean | Check if the connection pool is ready |
kuradb.awaitConnection | true | Wait for the pool to connect |
kuradb.store | number | Store a query string for reuse |
Connection
Wait for the database to be ready before running queries:
kuradb.ready(() => {
console.log('KuraDB connected');
});Or use the async version:
await kuradb.awaitConnection();Imperative transactions
kuradb.startTransaction(...) is generic and returns the callback outcome:
falserolls back and resolves tofalseundefinedcommits and resolves totrue- any other payload commits and resolves to that payload
const account = await kuradb.startTransaction(async (query) => {
const rows = await query(
'SELECT id, license FROM "public"."accounts" WHERE license = $1',
[license]
);
if (rows.length === 0) return false;
return rows[0];
});Schema exports
The TypeScript helper re-exports all ORM utilities:
import { defineColumn, defineTable, defineSchema } from '@kuradb/lib/KuraDB';
import type { ColumnDefinition, TableDefinition, SchemaDefinition } from '@kuradb/lib/KuraDB';