Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Tables

Methods to read DB and Loc tables, and their definitions.

Tables are described by their columns as rows see them: colour columns are merged, bitwise columns split and enum columns converted, so each row has one value per column.

table.info

Returns the definition and row count of a table.

Params (GetTableInfo)

NameTypeRequiredDescription
fileFileRefyesThe table.

Result (TableInfo)

NameTypeRequiredDescription
table_namestringyesName of the table, like units_tables, or loc for Loc files.
versionintegeryesVersion of the table’s definition.
columnsarray of FieldyesColumns of the table, in the order row values are, with the schema patches applied.
row_countintegeryesAmount of rows in the table.

table.rows

Returns rows of a table, optionally filtered and with only some columns.

Params (GetTableRows)

NameTypeRequiredDescription
fileFileRefyesThe table.
columnsarray of string or nullnoIf set, only these columns are returned, in this order.
filtersarray of RowFilterno, default []Only rows matching all these filters are returned.
offsetintegerno, default 0Amount of matching rows to skip.
limitinteger or nullnoMaximum amount of rows to return. Defaults to 100.

Result (TableRows)

NameTypeRequiredDescription
columnsarray of stringyesNames of the columns of the values of each row.
rowsarray of TableRowyesThe rows in the page.
totalintegeryesAmount of rows matching the filters, in all pages.

schema.definition

Returns the columns of a table as defined in the schema.

Params (GetTableDefinition)

NameTypeRequiredDescription
table_namestringyesName of the table, like units_tables.
versioninteger or nullnoVersion of the definition. If not set, the version the table has in the game files is used, or the newest one if the game files are not loaded or don’t have the table.

Result (TableDefinition)

NameTypeRequiredDescription
table_namestringyesName of the table.
versionintegeryesVersion of the definition.
columnsarray of FieldyesColumns of the table, in the order row values are, with the schema patches applied.

table.edit

Edits rows of a DB or Loc table in an open pack.

Edits are applied in order, each one on the result of the previous ones. If any of them fails, none is applied.

Params (EditTable)

NameTypeRequiredDescription
packstringyesKey of the pack.
pathstringyesPath of the table in the pack.
editsarray of RowEdityesEdits to apply.

Result (TableEdited)

NameTypeRequiredDescription
row_countintegeryesAmount of rows the table has after the edits.

table.column_values

Returns the distinct values of a column of a table, sorted.

Params (GetColumnValues)

NameTypeRequiredDescription
table_namestringyesName of the table, like factions_tables.
columnstringyesName of the column.
include_packsbooleanno, default trueIf the tables of the open packs are included.
include_dependenciesbooleanno, default trueIf the tables of the game files and the parent packs are included.
prefixstringno, default ""Only values starting with this are returned.
offsetintegerno, default 0Amount of values to skip.
limitinteger or nullnoMaximum amount of values to return. Defaults to 500.

Result (ColumnValues)

NameTypeRequiredDescription
valuesarray of stringyesThe values in the page, sorted.
totalintegeryesAmount of values matching the request, in all pages.

table.unused_numbers

Returns numbers no row uses yet in an integer column of a table, for new rows needing unique ones, like ids.

Params (GetUnusedNumbers)

NameTypeRequiredDescription
table_namestringyesName of the table, like main_units_tables.
columnstringyesName of the integer column, like unique_index.
countintegerno, default 1Amount of numbers to return, up to 10000. Defaults to 1.

Result (UnusedNumbers)

NameTypeRequiredDescription
numbersarray of integeryesThe numbers, from lowest to highest, all above the highest one used in the open packs and the dependencies.

table.merge

Merges tables of the same type of an open pack into a new one.

Params (MergeTables)

NameTypeRequiredDescription
packstringyesKey of the pack.
pathsarray of stringyesPaths of the tables to merge.
merged_pathstringyesPath of the merged table.
delete_sourcesbooleanno, default falseIf the merged tables are deleted afterwards.
deltabooleanno, default falseIf rows are merged by key against the vanilla data, instead of concatenated. Rows that can’t be reconciled automatically are returned as conflicts, and nothing is written.
resolutionsarray of anyno, default []How to resolve the conflicts of a previous delta merge.

Result (TablesMerged)

NameTypeRequiredDescription
mergedstring or nullyesPath of the merged table, if the merge was done.
conflictsarray of anynoRows that couldn’t be reconciled, if the merge wasn’t done. Pass resolutions for them to merge again.

table.upgrade

Updates a table of an open pack to the version it has in the game files.

Params (UpgradeTable)

NameTypeRequiredDescription
packstringyesKey of the pack.
pathstringyesPath of the table.

Result (TableUpgraded)

NameTypeRequiredDescription
old_versionintegeryesVersion the table had.
new_versionintegeryesVersion the table has now.
deleted_columnsarray of stringyesColumns removed by the update.
added_columnsarray of stringyesColumns added by the update, with their default value.

table.rename_key

Changes a value of a key column of a table in every table of an open pack, including the columns referencing it and the loc keys generated from it.

Params (RenameKey)

NameTypeRequiredDescription
packstringyesKey of the pack.
table_namestringyesName of the table the key is from, like factions_tables.
columnstringyesName of the key column.
old_valuestringyesCurrent value.
new_valuestringyesNew value.
versioninteger or nullnoVersion of the table’s definition. Defaults to the version in the game files, or the newest one.

Result (FilesEdited)

NameTypeRequiredDescription
editedarray of stringyesPaths of the edited files.

table.add_key_deletes

Adds rows to a key deletes table of an open pack, to delete keys of a table in the game.

Params (AddKeyDeletes)

NameTypeRequiredDescription
packstringyesKey of the pack.
file_namestringyesFile name of the key deletes table, under db/twad_key_deletes_tables/.
table_namestringyesName of the table the keys belong to, like units_tables.
keysarray of stringyesKeys to delete.

Result (FilesEdited)

NameTypeRequiredDescription
editedarray of stringyesPaths of the edited files.

table.export_tsv

Writes a table to a TSV file.

Params (ExportTsv)

NameTypeRequiredDescription
fileFileRefyesThe table. Assembly Kit tables can’t be exported.
destinationstringyesPath of the TSV file to write.
tsv_keys_firstboolean or nullnoIf the TSV uses the old column order, with keys first. Defaults to the server’s setting.

Result (Done)

Empty object: {}.

table.import_tsv

Replaces a table of an open pack with the contents of a TSV file, keeping its GUID.

Params (ImportTsv)

NameTypeRequiredDescription
packstringyesKey of the pack.
pathstringyesPath of the table in the pack.
tsv_pathstringyesPath of the TSV file to read.

Result (TableEdited)

NameTypeRequiredDescription
row_countintegeryesAmount of rows the table has after the edits.

Types

Type Field

A column of a table, as the schema describes it.

NameTypeRequiredDescription
namestringyesName of the column.
field_typeanyyesType of the values of the column, like StringU8, I32, F32, Boolean or ColourRGB. Sequences are an object with the definition of their rows, like { "SequenceU32": definition }.
is_keybooleanyesIf the column is part of the key of the table.
default_valuestring or nullyesValue of the column in new rows, if it has one.
is_filenamebooleanyesIf the column holds paths of files.
filename_relative_pathstring or nullyesFolders the files of the column are in, separated by ;. A % in them stands for the value of the column.
is_reference[string, string] or nullyesTable and column the values of this column must exist in, like ["factions", "key"]. The table name has no _tables suffix.
lookuparray of string or nullyesColumns of the referenced table shown next to the values of this one, to identify them.
descriptionstringyesDescription of the column. Empty if it has none.
ca_orderintegeryesPosition of the column in the Assembly Kit, or -1 if unknown.
is_bitwiseintegeryesIf more than 1, the column is one of the boolean columns a bitwise column was split into, named <column>_1 to <column>_<is_bitwise>.
enum_valuesmap of stringyesNames of the values of a column converted from an integer one, by value.
is_part_of_colourinteger or nullyesGroup of the colour columns merged into this one, if it’s a merged colour column.
unusedbooleanyesIf the game doesn’t use the column.

Type FileRef

A file in one of the sources.

NameTypeRequiredDescription
sourceFileSourceyesWhere the file is.
pathstringyesPath of the file in its source.

Type FileSource

Where a file is.

One of:

  • { "pack": … }: An open pack, by key.
    • pack (string, yes)
  • "game_files": The vanilla files of the selected game.
  • "parent_files": The files of the parent packs of the open packs.
  • "assembly_kit": The tables of the selected game’s Assembly Kit. Their paths are db/<table_name>/ak_data.

Type RowEdit

An edit of the rows of a table.

Values are given by column name, as booleans, numbers or strings, and converted to the type of their column.

One of:

  • { "op": "insert", "copy_from"?: …, "index"?: …, "values"?: … }: Adds a row. Columns not set get the value of the copied row, or their default value.
    • copy_from (RowRef or null, no): Row to copy, from any table with columns of the same names, like the vanilla one. Columns it doesn’t have get their default value.
    • index (integer or null, no): Position of the new row. If not set, it’s added at the end.
    • values (map of any, no, default {}): Values of the new row, by column name. They replace the ones of the copied row.
  • { "op": "update", "index": …, "values": … }: Changes values of a row.
    • index (integer, yes): Position of the row.
    • values (map of any, yes): New values, by column name. Columns not set keep their value.
  • { "op": "delete", "indexes": … }: Removes rows.
    • indexes (array of integer, yes): Positions of the rows to remove, as they’re before this edit.

Type RowFilter

A condition on the value of a column, compared as text.

NameTypeRequiredDescription
columnstringyesName of the column.
opFilterOpyesHow the value is compared.
valuestringyesValue to compare with.
ignore_casebooleanno, default falseIf the comparison ignores case.

Type FilterOp

Comparison of a row filter.

One of:

  • "equals": The value is the same as the filter’s.
  • "not_equals": The value is not the same as the filter’s.
  • "contains": The value contains the filter’s.
  • "starts_with": The value starts with the filter’s.
  • "ends_with": The value ends with the filter’s.

Type RowRef

A row of a table, in any source.

NameTypeRequiredDescription
fileFileRefyesThe table.
indexintegeryesIndex of the row in the table.

Type TableRow

A row of a table.

NameTypeRequiredDescription
indexintegeryesPosition of the row in the table. Used to edit it.
valuesarray of anyyesValues of the row, one per returned column: booleans, numbers or strings.