From 5d73f1fd165bbe893e92c759ea7b7170c6b5e874 Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Sat, 21 Nov 2026 07:31:37 +0000 Subject: [PATCH] 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. --- docs/web-tests/ts/table_delta_docs.ts | 64 ++++++++++++++++++++++++++ docs/web/management/table.mdx | 14 ++++-- docs/web/snippets/table_delta_docs.mdx | 2 + 3 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 docs/web-tests/ts/table_delta_docs.ts diff --git a/docs/web-tests/ts/table_delta_docs.ts b/docs/web-tests/ts/table_delta_docs.ts new file mode 100644 index 000000000..8182ca88e --- /dev/null +++ b/docs/web-tests/ts/table_delta_docs.ts @@ -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 { + // --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] +} diff --git a/docs/web/management/table.mdx b/docs/web/management/table.mdx index e09369dbd..0beb9836b 100644 --- a/docs/web/management/table.mdx +++ b/docs/web/management/table.mdx @@ -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} + + {TsVersioningCheckpointDelta} + + {RsVersioningCheckpointDelta} diff --git a/docs/web/snippets/table_delta_docs.mdx b/docs/web/snippets/table_delta_docs.mdx index a1beb901b..89f5b8305 100644 --- a/docs/web/snippets/table_delta_docs.mdx +++ b/docs/web/snippets/table_delta_docs.mdx @@ -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";