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.
This commit is contained in:
Xuanwo
2026-11-21 07:31:37 +00:00
parent 9358ed02c6
commit 5d73f1fd16
3 changed files with 76 additions and 4 deletions
+64
View File
@@ -0,0 +1,64 @@
// 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]
}
+10 -4
View File
@@ -89,6 +89,7 @@ import {
} from '/snippets/tables.mdx';
import {
PyVersioningCheckpointDelta as VersioningCheckpointDelta,
TsVersioningCheckpointDelta as TsVersioningCheckpointDelta,
RsVersioningCheckpointDelta as RsVersioningCheckpointDelta,
} from '/snippets/table_delta_docs.mdx';
import {
@@ -1786,10 +1787,11 @@ with stable row IDs enabled, as shown below. If a table does not have them, the
row-level readers explain how to recreate it with the option. `list_transactions()`
reports the transactions in the range and works without stable row IDs.
This preview supports Python and Rust for LanceDB Embedded. TypeScript support
is a follow-up. The API accepts versions and tags on the current branch only,
and rejects tags that belong to another branch. LanceDB Enterprise tables do
not support row-level deltas.
This preview supports Python, TypeScript, and Rust for LanceDB Embedded. The
API accepts versions and tags on the current branch only, and rejects tags that
belong to another branch. TypeScript exposes endpoint and transaction
`readVersion` values as `bigint`, and reader schemas are available before
streaming. LanceDB Enterprise tables do not support row-level deltas.
A `Restore` can reintroduce rows with older row-version metadata that the delta
readers do not report as changed. For that reason, the row-level readers reject
@@ -1804,6 +1806,10 @@ range. Branch-vs-main summaries remain a separate `branches.diff()` API.
{VersioningCheckpointDelta}
</CodeBlock>
<CodeBlock filename="TypeScript" language="TypeScript" icon="square-js">
{TsVersioningCheckpointDelta}
</CodeBlock>
<CodeBlock filename="Rust" language="Rust" icon="rust">
{RsVersioningCheckpointDelta}
</CodeBlock>
+2
View File
@@ -2,4 +2,6 @@
export const PyVersioningCheckpointDelta = "table = db.create_table(\n \"checkpoint_delta_example\",\n [\n {\"id\": 1, \"author\": \"Richard\", \"quote\": \"Wubba Lubba Dub Dub!\"},\n {\"id\": 2, \"author\": \"Morty\", \"quote\": \"Rick, what's going on?\"},\n ],\n storage_options={\"new_table_enable_stable_row_ids\": \"true\"},\n mode=\"overwrite\",\n)\ntable.tags.create(\"baseline\", table.version)\ntable.add([{\"id\": 3, \"author\": \"Summer\", \"quote\": \"Whatever, Grandpa\"}])\ntable.update(where=\"id = 2\", values={\"quote\": \"Aww geez, Rick!\"})\ntable.delete(\"id = 1\")\n\ndelta = table.delta(\"baseline\")\nprint(\"inserted:\", delta.inserted_rows().read_all()[\"id\"].to_pylist())\nprint(\"updated:\", delta.updated_rows().read_all()[\"id\"].to_pylist())\nprint(\"deleted:\", delta.deleted_row_ids().read_all()[\"_rowid\"].to_pylist())\nprint(\n \"transactions:\",\n [transaction[\"operation\"] for transaction in delta.list_transactions()],\n)\n";
export const TsVersioningCheckpointDelta = "const table = await db.createTable(\n \"checkpoint_delta_example\",\n [\n { id: 1, author: \"Richard\", quote: \"Wubba Lubba Dub Dub!\" },\n { id: 2, author: \"Morty\", quote: \"Rick, what's going on?\" },\n ],\n {\n mode: \"overwrite\",\n storageOptions: { new_table_enable_stable_row_ids: \"true\" },\n },\n);\nconst tags = await table.tags();\nawait tags.create(\"baseline\", await table.version());\nawait table.add([\n { id: 3, author: \"Summer\", quote: \"Whatever, Grandpa\" },\n]);\nawait table.update({\n where: \"id = 2\",\n values: { quote: \"Aww geez, Rick!\" },\n});\nawait table.delete(\"id = 1\");\n\nconst delta = await table.delta(\"baseline\");\nconsole.log(delta.beginVersion, delta.endVersion);\n\nconst inserted = delta.insertedRows();\nconsole.log((await inserted.schema()).fields.map((field) => field.name));\nfor await (const batch of inserted) {\n console.log(\"inserted:\", batch.getChild(\"id\")?.toJSON());\n}\n\nconst updated = delta.updatedRows();\nfor await (const batch of updated) {\n console.log(\"updated:\", batch.getChild(\"id\")?.toJSON());\n}\n\nconst deleted = delta.deletedRowIds();\nfor await (const batch of deleted) {\n console.log(\"deleted row ids:\", batch.getChild(\"_rowid\")?.toJSON());\n}\n\nconsole.log(\n \"transactions:\",\n (await delta.listTransactions()).map(\n (transaction) => transaction.operation,\n ),\n);\n";
export const RsVersioningCheckpointDelta = "use futures::TryStreamExt;\n\nlet table = db\n .create_table(\n \"checkpoint_delta_example\",\n make_quotes_reader(vec![\n (1, \"Richard\", \"Wubba Lubba Dub Dub!\"),\n (2, \"Morty\", \"Rick, what's going on?\"),\n ]),\n )\n .storage_option(\"new_table_enable_stable_row_ids\", \"true\")\n .execute()\n .await?;\n\nlet mut tags = table.tags().await?;\ntags.create(\"baseline\", table.version().await?).await?;\ntable\n .add(make_quotes_reader(vec![(3, \"Summer\", \"Whatever, Grandpa\")]))\n .execute()\n .await?;\ntable\n .update()\n .only_if(\"id = 2\")\n .column(\"quote\", \"'Aww geez, Rick!'\")\n .execute()\n .await?;\ntable.delete(\"id = 1\").await?;\n\nlet delta = table.delta(\"baseline\", None).await?;\nlet mut inserted = delta.inserted_rows().await?;\nwhile let Some(batch) = inserted.try_next().await? {\n println!(\"inserted: {:?}\", batch.column_by_name(\"id\"));\n}\nlet mut deleted = delta.deleted_row_ids().await?;\nwhile let Some(batch) = deleted.try_next().await? {\n println!(\"deleted row ids: {batch:?}\");\n}\nfor transaction in delta.list_transactions().await? {\n println!(\"{}\", transaction.operation.name());\n}\n";