Skip to content
Verified

Table

The definition of one data entity, its columns and its indexes, stored through a pluggable database driver.

A Table defines one data entity: its columns, the indexes used to look rows up, and which database driver stores it. Unlike a program, a Table carries no workflow, no events and no UI, its schema is the whole contract. Every read and write in a Xuda app eventually points at a Table through a Get Data, Set Data, Batch or Component datasource.

Properties

The table sits under studio_meta.parentId: "database" (or a folder nested under it).

tableFields

Prefix columns with a table code

A table named "ORD - Orders" prefixes every column: ORD_Id, ORD_Total, ORD_Status. It keeps field names unambiguous once several tables sit in the same expression, and it is the convention every existing table in a project follows.

tableIndexes

A table needs at least one field before it can carry an index. An index itself is only mandatory for tables on a non-native database driver, the platform's own engine (@xuda.io/xuda-dbs-plugin-xuda) accepts a table with zero indexes, though in practice every table that a Component or a set_data program can bind to a single record needs a unique <TBL>_Id index to do it.

Using a table

  • Read or write a row: a Get Data, Set Data or Batch program's progDataSource.dataSourceTableId names this table's _id.
  • Bind a Component directly: the same dataSourceTableId / dataSourceIndexId pair, embedded on the Component instead of a separate program.
  • From a script: xu.dbs_create, xu.dbs_read, xu.dbs_update, xu.dbs_delete, called with the table's _id, never its name.

Worked example

Model the columns

One table per entity, one 3-letter prefix per table: STU_Student_Id, STU_Full_Name.

Add a unique index on the id

Give every table a unique index on its <TBL>_Id field. Components that bind a single record by key, and set_data programs in update or delete mode, resolve the target row through this index.

Point a datasource at it

A Get Data or Set Data program's dataSourceTableId names this table's _id; dataSourceIndexId names one of the ids in tableIndexes.

Under Database in the Studio tree, add a table, then add rows to its Fields grid (id, type, mandatory) and its Indexes grid (name, keys, unique). The Data tab on the same node shows and edits rows directly.

json
{
  "id": "student_profiles_table",
  "menuTitle": "Student Profiles Table",
  "fields": [
    { "field_id": "student_id", "type": "string" },
    { "field_id": "full_name", "type": "string" },
    { "field_id": "campus", "type": "string" }
  ],
  "indexes": [
    { "id": "student_idx", "name": "Student", "keys": ["student_id"] },
    { "id": "campus_idx", "name": "Campus", "keys": ["campus"] }
  ]
}

A table has no .xu source form, xuda-cli projects declare it as a .table.json5 file instead (this is that file, shown as JSON).

json
{
  "properties": {
    "menuType": "table",
    "menuName": "STU - Students",
    "databaseSocket": "@xuda.io/xuda-dbs-plugin-xuda"
  },
  "tableFields": [
    { "id": "b2c3d4e5-…", "data": { "field_id": "STU_Student_Id" }, "props": { "fieldType": "string", "mandatory": true } },
    { "id": "c3d4e5f6-…", "data": { "field_id": "STU_Full_Name" }, "props": { "fieldType": "string", "mandatory": true } }
  ],
  "tableIndexes": [
    { "id": "a1b2c3d4-…", "data": { "name": "Index_0", "unique": true, "keys": ["STU_Student_Id"] } }
  ]
}