FILE Columns & Uploads
@kalamdb/client supports file upload and retrieval patterns for KalamDB FILE columns.
Upload through Drizzle (@kalamdb/orm)
When you use Drizzle, pass upload bytes in .values() or .set(). You do not need a separate queryWithFiles() wrapper for ORM builders:
kalamFile(name, blob) marks an upload for the driver. You can also pass a File or Blob directly to a generated file() column. kalamDriver() compiles the query, rewrites upload params to FILE("name"), and calls client.queryWithFiles() automatically.
Upserts work the same way — include kalamFile(...) in both .values() and .onConflictDoUpdate().set() when the FILE column changes. See Drizzle ORM & Generator.
Upload with raw SQL (@kalamdb/client)
Use queryWithFiles(sql, files, params?, onProgress?) when you are not going through Drizzle:
Insert + read FileRefs (end-to-end)
downloadUrl() returns the authenticated file-download endpoint for the stored
file path:
Fetch it with the same bearer token you use for SQL calls:
For user tables, SDK helpers intentionally generate an owner-scoped URL without
user_id. A normal user can download only files in their own user-table scope.
Service-role clients may upload or write through authorized EXECUTE AS USER
flows, but raw cross-user FILE downloads are reserved for dba and system
tokens that explicitly add an authorized user_id query parameter.
Progress callback
In browser environments (XMLHttpRequest available), pass onProgress:
Auth behavior
From source:
- SDK builds auth header via
buildAuthHeader(auth) - sends multipart request to
POST /v1/api/sql - falls back to
fetchwhen XHR progress is unavailable
FileRef model
file_ref.ts exposes FileRef and helpers:
Parse and use file metadata
When rows come from queryOne/queryAll, FILE values are KalamCellValue:
Build download URL
That URL points at /v1/files/.../{stored_name} and uses the sanitized stored
filename, not the raw file id alone.
Type helpers
Storage-path internals documented by source
FileRef includes:
id,sub,name,size,mime,sha256, optionalshard- filename sanitization and extension normalization
- shared-table shard-aware
relativePath()generation
This is useful for building file galleries, attachment viewers, and audit tooling.