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
Creating a KalamCellValue
KalamCellValue.from(raw)
Wrap any raw JS value as a KalamCellValue. Pass null / undefined for SQL NULL.
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.
client.queryOne(sql, params?)
Single-row variant of queryAll() — returns the first row, or null.
wrapRowMap(raw)
Convert a raw object row into RowData when you are handling row-shaped JSON outside queryOne() / queryAll():
RowData Type
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.
.asInt(): number | null
Returns the value as an integer (Math.trunc-ed), or null.
Parses string-encoded integers ("42" → 42).
.asBigInt(): bigint | null
Returns the value as a native bigint. Use this for Int64 / UInt64 columns
that may exceed Number.MAX_SAFE_INTEGER.
.asSeqId(): SeqId | null
Returns the value as a SeqId wrapper when the cell contains a KalamDB sequence ID such as _seq.
.asFloat(): number | null
Returns the value as a floating-point number, or null.
Parses string-encoded floats ("3.14" → 3.14).
.asBool(): boolean | null
Returns the value as a boolean, or null.
Handles string-encoded booleans: "true", "false", "1", "0".
.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
.asDateOnly(): Date | null
Returns a UTC midnight Date for KalamDB DATE columns. Handles Date32 day
offsets from the wire and ISO date strings.
.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.
.asUuid(): string | null
Validates and lowercases UUID values.
.asDecimal(): string | null
Returns DECIMAL(p,s) values as exact strings. This avoids precision loss from
coercing fixed-point values into JavaScript numbers.
.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.
.asEmbedding(): number[] | null
Returns EMBEDDING(n) vectors as a number array.
.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).
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.
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 Subscriptions
subscribeRows() wraps each row as KalamRow<T>. Use .cell(column) or
.typedData for the same KalamCellValue access pattern as queryAll():
KalamRow.cell(column): KalamCellValue
Access a single column as a KalamCellValue. Works the same whether the row
came from queryRows() or subscribeRows().
KalamRow.typedData: RowData
All column values wrapped as KalamCellValue in a Record<string, KalamCellValue>.
Cached on first access for performance.
Using with Consumers
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 |