Querying & DML
Raw SQL execution
With parameters:
From client.ts, params are sent through queryWithParams(sql, JSON.stringify(params)).
Vector search queries
Vector search uses the same query() and helper APIs as any other SQL workflow.
Typical SQL setup:
See /docs/server/architecture/vector-search for the full schema and retrieval pattern.
Row helpers (named_rows)
query() returns a raw QueryResponse. Results are exposed via results?.[0]?.named_rows as plain named-column maps from the server.
For ergonomic access, use:
queryOne(sql, params?)→RowData | nullqueryAll(sql, params?)→RowData[]queryRows<T>(sql, tableName, params?)→KalamRow<T>[]
queryOne() and queryAll() are intentionally not generic. They return RowData with KalamCellValue wrappers. Use queryRows<T>() when you want typed application objects plus FILE-aware row helpers.
For FILE-aware row wrappers (.file() / .downloadUrl()):
The helper methods above wrap each value as KalamCellValue (.asString(), .asInt(), .asFile(), etc.).
See /docs/ts-sdk/cell-values for the full API.
executeAsUser
Source behavior:
- wraps SQL as
EXECUTE AS '<user_id>' ( <statement> ) - strips trailing semicolons in inner SQL
- escapes
'in the target user id - requires one non-empty statement and a non-empty user id
- is valid for USER and STREAM tables; SHARED tables use their table policy directly
- KalamDB authorizes cross-user targets with its role matrix: system can target any role, DBA can target DBA/service/user, service can target service/user, and regular users can only target themselves
For the underlying table policy and role matrix, see /docs/server/architecture/table-types and /docs/server/sql-reference/impersonation.
Convenience DML methods
Important caveat
update() builds SQL string values directly (with quote escaping for strings). For complex/untrusted inputs, prefer query() with parameter placeholders where possible.
Type shape notes from generated declarations
Generated SDK types mark some fields optional:
Handle missing results/schema defensively in generic tooling; prefer named_rows when present.