Skip to Content
Cell Values (KalamCellValue)

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

ts snippetTS
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.

typescript snippettypescript
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.

typescript snippettypescript
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.

typescript snippettypescript
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():

ts snippetTS
import { wrapRowMap } from '@kalamdb/client'; const typedRow = wrapRowMap({ id: '1', name: 'Alice' });

RowData Type

typescript snippettypescript
type RowData = Record<string, KalamCellValue>;

Use RowData as the type annotation for typed result rows throughout your application.

Type Guards

MethodReturns
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.

typescript snippettypescript
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).

typescript snippettypescript
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.

typescript snippettypescript
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.

ts snippetTS
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).

typescript snippettypescript
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".

typescript snippettypescript
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): 1704067200000Date
  • ISO 8601 strings: "2024-01-01T00:00:00Z"Date
  • Numeric timestamp strings: "1704067200000"Date
typescript snippettypescript
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.

ts snippetTS
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.

ts snippetTS
const startsAt = row.starts_at.asTimeString();

.asUuid(): string | null

Validates and lowercases UUID values.

ts snippetTS
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.

ts snippetTS
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.

ts snippetTS
const payload = row.payload.asBytes();

.asEmbedding(): number[] | null

Returns EMBEDDING(n) vectors as a number array.

ts snippetTS
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).

typescript snippettypescript
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.

typescript snippettypescript
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:

ts snippetTS
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

ts snippetTS
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

MemberSignatureDescription
KalamCellValue.from(raw: unknown) => KalamCellValueWrap 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) => KalamCellValueAccess column as KalamCellValue
KalamRow.typedDataRowData (getter)All columns as KalamCellValue map
asJson() => JsonValueRaw underlying value (preferred)
toJson() => JsonValueRaw underlying value
isNull() => booleanTrue if SQL NULL
isString() => booleanTrue if JSON string
isNumber() => booleanTrue if JSON number
isBool() => booleanTrue if JSON boolean
isObject() => booleanTrue if JSON object
isArray() => booleanTrue if JSON array
asString() => string | nullValue as string
asInt() => number | nullValue as integer
asBigInt() => bigint | nullValue as bigint
asSeqId() => SeqId | nullValue as typed sequence ID
asFloat() => number | nullValue as float
asBool() => boolean | nullValue as boolean
asDate() => Date | nullValue as Date
asDateOnly() => Date | nullDATE value as UTC midnight Date
asTimeString() => string | nullTIME value as HH:mm:ss[.fraction]
asUuid() => string | nullValidated UUID string
asDecimal() => string | nullExact DECIMAL string
asBytes() => Uint8Array | nullBYTES value as byte array
asEmbedding() => number[] | nullEMBEDDING vector
asObject() => Record<string, JsonValue> | nullValue as object
asArray() => JsonValue[] | nullValue as array
asFile() => FileRef | nullFILE column as FileRef
asFileUrl(baseUrl, namespace, table) => string | nullFILE column URL
toString() => stringDisplay string
Last updated on