Files
lancedb/docs/web-tests/ts/table_delta_docs.ts
T
Xuanwo 5d73f1fd16 docs: add TypeScript checkpoint delta example
Document Python, TypeScript, and Rust support in the draft checkpoint section and add a matching TypeScript streaming example with bigint endpoints, schema, transaction, and range-end checkpoint semantics. Keep the section inside the existing MDX draft comment until release.
2026-11-21 07:31:37 +00: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]
}