Files
lancedb/docs/web-tests/ts/table_delta_docs.ts
T
Xuanwo 6a7a2c4ec0 feat(nodejs): add table delta streams (#5149)
Adds the Embedded `Table.delta` API to the Node.js bindings, matching
the Rust/Python contract from #5135. `Table.delta(fromVersion,
toVersion?)` accepts a positive safe-integer number, a positive lossless
u64 `bigint`, or a same-branch tag string. `TableDelta` exposes
`beginVersion`/`endVersion` as `bigint`, streaming `insertedRows()`,
`updatedRows()`, `upsertedRows()`, `deletedRowIds()`, and
`listTransactions()` with `readVersion` as `bigint`.

Readers reuse the existing native Arrow IPC iterator adapter. They are
lazy, single-use, serialize pulls, capture/cache the schema before
polling, and release the native stream on completion, break, or error.
Row readers retain the Rust contract: equal endpoints return empty
streams with schemas, invalid/reversed/missing endpoints and
cross-branch tags are rejected, and Restore or incomplete transaction
history fail closed with full-rescan and range-end checkpoint guidance.
Enterprise tables remain unsupported through the native Rust default.

The abstract `Table` keeps a concrete unsupported `delta` default for
custom subclasses; `LocalTable` overrides it. TypeDoc API docs and
focused Node tests cover pinned targets, typed bigint values,
transaction listing, lazy rejected readers, schema/decode failures,
aliasing, and early drop.

Refs OSS-2860
2026-11-21 15:43:16 +08:00

65 lines
1.9 KiB
TypeScript

// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright The LanceDB Authors
import type { Connection } from "@lancedb/lancedb";
/**
* Draft checkpoint-delta example for the Versioning guide.
*
* This file is snippet source only. The published documentation test package is
* pinned to an older npm release, so it is not part of the Jest test glob.
*/
export async function versioningCheckpointDeltaExample(
db: Connection,
): Promise<void> {
// --8<-- [start:versioning_checkpoint_delta]
const table = await db.createTable(
"checkpoint_delta_example",
[
{ id: 1, author: "Richard", quote: "Wubba Lubba Dub Dub!" },
{ id: 2, author: "Morty", quote: "Rick, what's going on?" },
],
{
mode: "overwrite",
storageOptions: { new_table_enable_stable_row_ids: "true" },
},
);
const tags = await table.tags();
await tags.create("baseline", await table.version());
await table.add([
{ id: 3, author: "Summer", quote: "Whatever, Grandpa" },
]);
await table.update({
where: "id = 2",
values: { quote: "Aww geez, Rick!" },
});
await table.delete("id = 1");
const delta = await table.delta("baseline");
console.log(delta.beginVersion, delta.endVersion);
const inserted = delta.insertedRows();
console.log((await inserted.schema()).fields.map((field) => field.name));
for await (const batch of inserted) {
console.log("inserted:", batch.getChild("id")?.toJSON());
}
const updated = delta.updatedRows();
for await (const batch of updated) {
console.log("updated:", batch.getChild("id")?.toJSON());
}
const deleted = delta.deletedRowIds();
for await (const batch of deleted) {
console.log("deleted row ids:", batch.getChild("_rowid")?.toJSON());
}
console.log(
"transactions:",
(await delta.listTransactions()).map(
(transaction) => transaction.operation,
),
);
// --8<-- [end:versioning_checkpoint_delta]
}