Skip to content

Inspect, audit, and manage the per-database SQL execution log. The history records every query the engine processes against a given database file, including metadata about duration and outcome.

Retrieve query execution history for a database with an optional limit.

NameInTypeRequiredDescription
dbquerystringYesDatabase file path
limitqueryintegerNoMaximum number of entries to return. Default: 100
{
"entries": [
{
"id": 1842,
"db": "app.db",
"query": "SELECT id, email FROM users WHERE active = 1",
"duration_ms": 3.21,
"rows_affected": 47,
"timestamp": 1717691234,
"status": "ok"
},
{
"id": 1841,
"db": "app.db",
"query": "UPDATE users SET last_login = ? WHERE id = ?",
"duration_ms": 1.04,
"rows_affected": 1,
"timestamp": 1717691190,
"status": "ok"
}
],
"total": 1842,
"returned": 2
}
const result = await client.sqlite.history.list({
db: "app.db",
limit: 50,
});

Retrieve aggregated statistics about query execution history.

NameInTypeRequiredDescription
dbquerystringYesDatabase file path
{
"db": "app.db",
"total_queries": 1842,
"successful_queries": 1829,
"failed_queries": 13,
"avg_duration_ms": 2.47,
"p95_duration_ms": 18.3,
"first_entry": 1715000000,
"last_entry": 1717691234
}
const stats = await client.sqlite.history.getStats({
db: "app.db",
});

Delete all query history entries for a database.

NameInTypeRequiredDescription
dbquerystringYesDatabase file path
{
"db": "app.db",
"deleted": 1842
}
await client.sqlite.history.clear({
db: "app.db",
});

Delete a specific query history entry by ID.

NameInTypeRequiredDescription
indexpathintegerYesHistory entry ID
dbquerystringYesDatabase file path
{
"db": "app.db",
"deleted_id": 1842
}
await client.sqlite.history.deleteEntry({
index: 1842,
db: "app.db",
});

Reconstruct a key or an entire table at a specific moment in time, compare two moments to see exactly what changed, and roll back operations when something went wrong. These endpoints read the operation log produced by every KV write.

Retrieve the operation history for a specific key, showing all changes over time.

NameInTypeRequiredDescription
keypathstringYesKey name
dbquerystringYesDatabase file path
tablequerystringNoCustom table name. Default: "kv_store"
limitqueryintegerNoMaximum number of operations to return (0 → default 50, clamped to maximum 1000). Default: 50
{
"key": "session:user:42",
"db": "app.db",
"table": "kv_store",
"operations": [
{
"op_number": 9183,
"operation": "set",
"value": "{\"theme\":\"dark\"}",
"ttl": null,
"timestamp": 1717691234,
"actor": "session-service"
},
{
"op_number": 9012,
"operation": "set",
"value": "{\"theme\":\"light\"}",
"ttl": null,
"timestamp": 1717689000,
"actor": "session-service"
},
{
"op_number": 8744,
"operation": "create",
"value": "{}",
"ttl": null,
"timestamp": 1717680000,
"actor": "session-service"
}
],
"returned": 3
}
const history = await client.sqlite.kvStore.getHistory({
key: "session:user:42",
db: "app.db",
limit: 100,
});

Reconstruct the value of a key as it was at a specific operation number.

NameInTypeRequiredDescription
keypathstringYesKey name
dbquerystringYesDatabase file path
tablequerystringNoCustom table name. Default: "kv_store"
op_numberqueryintegerYesOperation number to reconstruct from
{
"key": "session:user:42",
"db": "app.db",
"table": "kv_store",
"op_number": 9012,
"reconstructed_at": 1717689000,
"value": "{\"theme\":\"light\"}",
"ttl": null
}
const snapshot = await client.sqlite.kvStore.getSnapshot({
key: "session:user:42",
db: "app.db",
op_number: 9012,
});

Reconstruct the entire KV table state as it was at a specific timestamp. Use prefix to narrow the candidate set when the table is large.

NameInTypeRequiredDescription
dbquerystringYesDatabase file path
tablequerystringNoCustom table name. Default: "kv_store"
timestampqueryintegerYesUnix timestamp to reconstruct from
limitqueryintegerNoMaximum number of keys to return. Default: 100
prefixquerystringNoFilter keys by prefix
{
"db": "app.db",
"table": "kv_store",
"timestamp": 1717680000,
"keys": {
"config:feature_flags": "{\"new_checkout\":true}",
"session:user:42": "{}",
"rate_limit:ip:10.0.0.1": "{\"count\":7}"
},
"returned": 3,
"has_gaps": false,
"gap_keys": [],
"candidate_truncated": false
}
const snapshot = await client.sqlite.kvStore.getTableSnapshot({
db: "app.db",
timestamp: 1717680000,
prefix: "session:",
limit: 200,
});

Compare the KV table state between two timestamps to see exactly which keys were created, modified, and deleted in the window.

NameInTypeRequiredDescription
dbquerystringYesDatabase file path
tablequerystringNoCustom table name. Default: "kv_store"
fromqueryintegerYesStarting timestamp (Unix)
toqueryintegerYesEnding timestamp (Unix)
keysquerystringNoComma-separated list of keys to compare (optional)
{
"db": "app.db",
"table": "kv_store",
"from": 1717680000,
"to": 1717691234,
"created": [
{
"key": "session:user:99",
"value": "{}"
}
],
"modified": [
{
"key": "session:user:42",
"from": "{\"theme\":\"light\"}",
"to": "{\"theme\":\"dark\"}"
}
],
"deleted": [
"rate_limit:ip:10.0.0.7"
],
"has_gaps": false,
"gap_keys": [],
"candidate_truncated": false
}
const diff = await client.sqlite.kvStore.compareSnapshots({
db: "app.db",
from: 1717680000,
to: 1717691234,
keys: "session:user:42,session:user:99",
});

Roll back a key to its previous state by undoing the last N operations. Each undo writes a new compensating operation to the history chain.

NameInTypeRequiredDescription
keypathstringYesKey name
dbquerystringYesDatabase file path
tablequerystringNoCustom table name. Default: "kv_store"
stepsqueryintegerNoNumber of operations to rollback. Default: 1
{
"key": "session:user:42",
"db": "app.db",
"table": "kv_store",
"undone_steps": 1,
"new_op_number": 9184,
"restored_value": "{\"theme\":\"light\"}"
}
const result = await client.sqlite.kvStore.rollback({
key: "session:user:42",
db: "app.db",
steps: 1,
});

Roll back the entire KV table to a specific timestamp. Because this is a destructive operation that can delete and overwrite many keys, it requires explicit confirmation.

NameInTypeRequiredDescription
dbquerystringYesDatabase file path
tablequerystringNoCustom table name. Default: "kv_store"
to_timestampqueryintegerYesTarget timestamp to rollback to (Unix)
dry_runquerybooleanNoPreview changes without applying. Default: false
confirmquerystringNoMust be 'yes' to execute actual rollback

This endpoint takes no request body.

{
"db": "app.db",
"table": "kv_store",
"to_timestamp": 1717680000,
"dry_run": false,
"applied": true,
"created": 0,
"modified": 1,
"deleted": 2
}
// Preview first
const preview = await client.sqlite.kvStore.rollbackTable({
db: "app.db",
to_timestamp: 1717680000,
dry_run: true,
data: {},
});
// Apply
const result = await client.sqlite.kvStore.rollbackTable({
db: "app.db",
to_timestamp: 1717680000,
dry_run: false,
confirm: "yes",
data: {},
});