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 when you want to modify only records that already exist in the table. In this mode, idColumn is required so autk-db knows how to match incoming records with stored ones.
In the example above, only the rows whose key values match existing records in the noise table are updated.
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
update does not insert new rows
The update strategy only modifies rows that already exist. If an incoming record does not match an existing ID, it is not inserted as a new row.
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 modifies matching existing records only. |
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. |