Cell Values
KalamCellValue is the SDK’s typed wrapper around every individual cell value
returned in a query result or subscription event.
Instead of receiving plain Record<string, unknown> rows (where you must guess
the type and cast manually), you get RowData = Record<string, KalamCellValue>
rows with named accessor methods that mirror the Rust implementation.
Topic consumer payloads stay raw JSON until you explicitly wrap them with wrapRowMap().
Quick Example
import { createClient, Auth } from '@kalamdb/client'; const client = createClient({ url: 'http://localhost:2900', authProvider: async () => Auth.basic('admin', 'kalamdb123') }); // queryAll() returns RowData[] — every cell is a KalamCellValueconst rows = await client.queryAll('SELECT id, name, score, avatar FROM users'); for (const row of rows) { const id = row.id.asString(); // string | null const name = row.name.asString(); // string | null const score = row.score.asFloat(); // number | null const born = row.born_at.asDate(); // Date | null const uuid = row.public_id.asUuid(); // string | null const amount = row.total.asDecimal(); // exact string | null const avatar = row.avatar.asFile(); // FileRef | null const url = row.avatar.asFileUrl('http://localhost:2900', 'default', 'users'); console.log(id, name, score, born?.toISOString(), url);} // Single row:const row = await client.queryOne('SELECT * FROM users WHERE id = $1', [42]);if (row) console.log(row.name.asString());Creating a KalamCellValue
KalamCellValue.from(raw)
Wrap any raw JS value as a KalamCellValue. Pass null / undefined for SQL NULL.
const cell = KalamCellValue.from(someRawValue);client.queryAll(sql, params?)
Execute a SQL query and return all rows with every cell pre-wrapped as
KalamCellValue. This is the recommended method for typed cell access.
const rows = await client.queryAll('SELECT * FROM orders');for (const row of rows) { console.log(row.status.asString(), row.total.asFloat());}client.queryOne(sql, params?)
Single-row variant of queryAll() — returns the first row, or null.
const row = await client.queryOne('SELECT * FROM users WHERE id = $1', [42]);console.log(row?.name.asString());wrapRowMap(raw)
Convert a raw object row into RowData when you are handling row-shaped JSON outside queryOne() / queryAll():
import { wrapRowMap } from '@kalamdb/client'; const typedRow = wrapRowMap({ id: '1', name: 'Alice' });RowData Type
type RowData = Record<string, KalamCellValue>;Use RowData as the type annotation for typed result rows throughout your
application.
Type Guards
| Method | Returns |
|---|---|
cell.isNull() | boolean — true if this cell is SQL NULL |
cell.isString() | boolean — true if underlying value is a JSON string |
cell.isNumber() | boolean — true if underlying JSON is a number |
cell.isBool() | boolean — true if underlying JSON is a boolean |
cell.isObject() | boolean — true if underlying JSON is an object |
cell.isArray() | boolean — true if underlying JSON is an array |
Typed Accessors
.asString(): string | null
Returns the value as a string, or null for SQL NULL.
Handles { "Utf8": "..." } Rust-side string envelopes automatically.
const name = row.name.asString(); // "Alice"const nullCell = row.deleted_at.asString(); // null.asInt(): number | null
Returns the value as an integer (Math.trunc-ed), or null.
Parses string-encoded integers ("42" → 42).
const count = row.item_count.asInt(); // 7.asBigInt(): bigint | null
Returns the value as a native bigint. Use this for Int64 / UInt64 columns
that may exceed Number.MAX_SAFE_INTEGER.
const id = row.snowflake_id.asBigInt();.asSeqId(): SeqId | null
Returns the value as a SeqId wrapper when the cell contains a KalamDB sequence ID such as _seq.
const seq = row._seq.asSeqId();console.log(seq?.timestampMillis());.asFloat(): number | null
Returns the value as a floating-point number, or null.
Parses string-encoded floats ("3.14" → 3.14).
const price = row.price.asFloat(); // 19.99.asBool(): boolean | null
Returns the value as a boolean, or null.
Handles string-encoded booleans: "true", "false", "1", "0".
const active = row.is_active.asBool(); // true.asDate(): Date | null
Returns the value as a Date, or null for SQL NULL / unparseable values.
Handles:
- Unix milliseconds (number):
1704067200000→Date - ISO 8601 strings:
"2024-01-01T00:00:00Z"→Date - Numeric timestamp strings:
"1704067200000"→Date
const created = row.created_at.asDate(); // Date objectconsole.log(created?.toLocaleDateString());.asDateOnly(): Date | null
Returns a UTC midnight Date for KalamDB DATE columns. Handles Date32 day
offsets from the wire and ISO date strings.
const invoiceDate = row.invoice_date.asDateOnly();console.log(invoiceDate?.toISOString().slice(0, 10));.asTimeString(): string | null
Returns a KalamDB TIME value as HH:mm:ss or HH:mm:ss.ffffff. Handles the
server wire value of microseconds since midnight.
const startsAt = row.starts_at.asTimeString();.asUuid(): string | null
Validates and lowercases UUID values.
const id = row.public_id.asUuid();.asDecimal(): string | null
Returns DECIMAL(p,s) values as exact strings. This avoids precision loss from
coercing fixed-point values into JavaScript numbers.
const total = row.total.asDecimal();.asBytes(): Uint8Array | null
Returns BYTES values as Uint8Array. The accessor accepts the server’s byte
array wire format and base64 strings when interoperating with older tooling.
const payload = row.payload.asBytes();.asEmbedding(): number[] | null
Returns EMBEDDING(n) vectors as a number array.
const vector = row.doc_embedding.asEmbedding();.asObject(): Record<string, JsonValue> | null
Returns the raw value as a plain object, or null.
.asArray(): JsonValue[] | null
Returns the raw value as an array, or null.
FILE Column Support
.asFile(): FileRef | null
Parse a FILE column value and return a FileRef instance (or null).
const ref = row.attachment.asFile();if (ref) { console.log(ref.name, ref.mime, ref.formatSize()); console.log(ref.isImage()); // true for image/* MIME types}See FILE Columns & Uploads for the full FileRef API.
.asFileUrl(baseUrl, namespace, table): string | null
Convenience method — parse a FILE column and return the download URL in one call.
const url = row.avatar.asFileUrl('http://localhost:2900', 'default', 'users');// e.g. "http://localhost:2900/v1/files/default/users/f0001/12345-photo.png"img.src = url ?? '/placeholder.png';The generated URL uses KalamDB’s stored filename path, so it is safe to fetch directly with the caller’s bearer token.
Serialisation
.asJson(): JsonValue
Returns the underlying raw JSON value. This is the preferred JSON accessor.
.toJson(): JsonValue
Compatibility alias of .asJson().
Returns the underlying raw JSON value. Use this when you need to pass the value
to code that expects plain JSON (e.g. FileRef.from(cell.asJson())).
.toString(): string
Human-readable display:
- SQL NULL →
"NULL" - strings → value as-is
- objects / arrays → compact JSON
- other →
String(value)
Using with Live Rows
live() callbacks receive rows as RowData, where each column is already a
KalamCellValue. Use the same typed accessors as query results:
import type { RowData } from '@kalamdb/client'; const stop = await client.live<RowData>('SELECT * FROM default.users', (rows) => { for (const row of rows) { console.log(row.name.asString(), row.score.asFloat()); // FILE columns still work via KalamCellValue helpers. const avatar = row.avatar?.asFile(); if (avatar) console.log(avatar.downloadUrl()); }});KalamRow.cell(column): KalamCellValue
Access a single column as a KalamCellValue. KalamRow is used by queryRows();
live rows expose the same cell values directly on RowData.
KalamRow.typedData: RowData
All column values wrapped as KalamCellValue in a Record<string, KalamCellValue>.
Cached on first access for performance.
Using with Consumers
import { Auth, wrapRowMap } from '@kalamdb/client';import { createConsumerClient } from '@kalamdb/consumer'; const worker = createConsumerClient({ url: 'http://localhost:2900', authProvider: async () => Auth.basic('worker', 'Secret123!'),}); await worker.consumer({ topic: 'events', group_id: 'events-reader', auto_ack: true }).run(async (ctx) => { const row = wrapRowMap(ctx.message.value as Record<string, unknown>); console.log(row.event_type.asString(), row.created_at.asDate());});Full API Reference
| Member | Signature | Description |
|---|---|---|
KalamCellValue.from | (raw: unknown) => KalamCellValue | Wrap a raw value |
client.queryAll | (sql, params?) => Promise<RowData[]> | Query with typed cells |
client.queryOne | (sql, params?) => Promise<RowData | null> | Single row query |
KalamRow.cell | (column) => KalamCellValue | Access column as KalamCellValue |
KalamRow.typedData | RowData (getter) | All columns as KalamCellValue map |
asJson | () => JsonValue | Raw underlying value (preferred) |
toJson | () => JsonValue | Raw underlying value |
isNull | () => boolean | True if SQL NULL |
isString | () => boolean | True if JSON string |
isNumber | () => boolean | True if JSON number |
isBool | () => boolean | True if JSON boolean |
isObject | () => boolean | True if JSON object |
isArray | () => boolean | True if JSON array |
asString | () => string | null | Value as string |
asInt | () => number | null | Value as integer |
asBigInt | () => bigint | null | Value as bigint |
asSeqId | () => SeqId | null | Value as typed sequence ID |
asFloat | () => number | null | Value as float |
asBool | () => boolean | null | Value as boolean |
asDate | () => Date | null | Value as Date |
asDateOnly | () => Date | null | DATE value as UTC midnight Date |
asTimeString | () => string | null | TIME value as HH:mm:ss[.fraction] |
asUuid | () => string | null | Validated UUID string |
asDecimal | () => string | null | Exact DECIMAL string |
asBytes | () => Uint8Array | null | BYTES value as byte array |
asEmbedding | () => number[] | null | EMBEDDING vector |
asObject | () => Record<string, JsonValue> | null | Value as object |
asArray | () => JsonValue[] | null | Value as array |
asFile | () => FileRef | null | FILE column as FileRef |
asFileUrl | (baseUrl, namespace, table) => string | null | FILE column URL |
toString | () => string | Display string |