Updating tables
Once a table is loaded into DuckDB, updateTable lets you replace its contents or update existing records without creating a new table name. Unlike the loading methods described in Loading data, updating does not create a new table. Instead, it modifies a table that already exists in the current workspace.
Returned metadata
Every table manipulation call returns the updated table metadata.
Operates on a table that already exists in the current workspace. In practice, this means you should make sure the intended workspace is active before updating a table.
Replace a table
Use the replace strategy when the entire dataset should be swapped with a new one. Internally, autk-db drops the previous table and recreates it from the new data. This is the simplest strategy when the full dataset has changed and you want the table to keep the same name while replacing all of its contents.
Replacing layer data
For renderable vector tables, pass a GeoJSON FeatureCollection as data.
In this example, the neighborhoods table is first loaded from GeoJSON, then rewritten after adding a highlighted property to the features. Because the strategy is replace, the old table contents are discarded and the new FeatureCollection becomes the full table.
Replacing tabular data
For JSON or CSV-style tables, pass an array of plain objects.
This pattern is useful when a non-spatial dataset is loaded from a file, edited in JavaScript, and then written back in one step. Because the whole table is recreated, rows can be added, removed, or reordered freely.
When to prefer replace
Use replace when you already have the full next version of the dataset in memory. It is often the most predictable option because the final table is determined entirely by the new input.
Update records
Use the update strategy to match incoming rows by ID. Layer tables update matching records only; plain CSV/JSON tables replace matching rows and also insert unmatched incoming rows. In this mode, idColumn is required so autk-db knows how to match incoming records with stored ones.
In the example above, rows whose key values match existing records in the noise table are replaced. Because this is a tabular table, incoming rows with new keys are also inserted; existing rows not included in updates remain unchanged.
Notice that updates contains full rows, not partial patches. For tabular tables, the update strategy expects each replacement row to include the same columns as the target table.
The idColumn value may refer to:
- a direct column such as
id - a nested GeoJSON property path such as
properties.building_id
GeoJSON updates require feature IDs
When data is a GeoJSON FeatureCollection and strategy is update, every incoming feature must have a Feature.id. Autark preserves a string or numeric ID separately from its internal row ID; missing IDs are rejected. Use an idColumn such as properties.building_id when that is the field used to match stored rows.
Layer updates and tabular updates differ
For layer tables, update only modifies matching existing rows; unmatched incoming features are not inserted. For plain CSV/JSON tables, matching rows are deleted and all incoming rows are inserted, including new IDs. These are full-row replacements, not partial patches.
List of updateTable parameters
| Option | Type | Description |
|---|---|---|
tableName | string | Name of the table to update. |
data | FeatureCollection | Record<string, unknown>[] | Replacement or update payload. Use GeoJSON for layer tables and plain object arrays for JSON or CSV-style tables. |
strategy | "replace" | "update" | Update mode. replace recreates the whole table; update matches rows by ID: layers update existing rows only; plain tables replace matching rows and insert new ones. |
idColumn | string | Required when strategy is "update". Used to match incoming records with existing rows. |
Remove a table
removeLayer drops a table from the active workspace.
After removal, the table no longer appears in getTablesMetadata() or getLayersMetadata(). This is useful when a table is no longer needed, when you want to free the workspace from intermediate results, or when a temporary layer should not remain available to later analysis steps.
List of removeLayer parameters
| Option | Type | Description |
|---|---|---|
tableName | string | Name of the table to remove. |