Kura
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

MethodReturnsDescription
kuradb.queryRow[]Execute a query, return all rows
kuradb.singleRow | nullReturn the first row
kuradb.scalarT | nullReturn a single value
kuradb.updatenumberExecute an update, return affected rows
kuradb.insertTExecute an insert, return the inserted id
kuradb.prepareTExecute a prepared statement
kuradb.rawExecuteTExecute with multiple parameter sets
kuradb.batchT[]Pipeline multiple executions of the same statement
kuradb.insertManyTMulti-row bulk insert
kuradb.transactionbooleanDeclarative transaction (query list)
kuradb.startTransactionT | true | falseImperative transaction (callback with payload-or-false return semantics)
kuradb.notifybooleanSend a PostgreSQL NOTIFY
kuradb.listenSubscriptionSubscribe to a PostgreSQL channel
kuradb.unlistenbooleanUnsubscribe from a channel
kuradb.copyFrom{ bytes, chunks }Bulk ingest via COPY FROM
kuradb.copyTostringBulk export via COPY TO
kuradb.isReadybooleanCheck if the connection pool is ready
kuradb.awaitConnectiontrueWait for the pool to connect
kuradb.storenumberStore 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:

  • false rolls back and resolves to false
  • undefined commits and resolves to true
  • 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';

On this page