Query and write app data
Read rows from a Studio table, and add one, from outside the runtime, with the same two methods a running app itself calls.
dbs_read and dbs_create are the same two calls a javascript or api program makes at runtime
through xu.dbs_read(...) and xu.dbs_create(...), reachable directly with an account API key so
your own backend can read and write a project's Studio table without going through the runtime at
all. See JavaScript Framework for the in-project side of the same
methods, and Development platform for the rest of data_module.
table_id is the table node's own _id, never its display name. get_progs with
menu_type: "table" lists every table in a project as {_id, properties: {menuName}} pairs, the
cheapest way to map a name you can read to the id these two methods need.
Methods
DBS Read
Reads records from an app table with optional row range, single-row lookup, sorting, filtering, and archived-record selection.
DBS Create
Creates a new record in the specified app table from the provided key-value table data.
Walkthrough
Read a page of rows
from/to is a row range (from is the offset, to - from is the page size), and both are
optional, omit them and you get the table's default page. Every other filter (row_id, query,
sortModel, archived) is optional too.
2. Add a row
table_data is a plain object keyed by the table's own field ids, the column ids Studio assigned
when the table was built, not generic names. Read a row back with step 1 first if you are not sure
what a given table's fields are called.
The response
dbs_read wraps the table's plugin result and adds the table's own total count on top:
Each row is { id, value }: id is the row's own document id (what row_id on a later call, or
dbs_update/dbs_delete, expects), value is the field data keyed the same way table_data
was sent. total_rows counts this page; total_table_count is the whole table (active rows only,
unless archived: true was sent), the number a "Page 1 of N" control would read.
dbs_create answers with the write, not the row:
Read the new row back with dbs_read (row_id set to data.id) if you need its stored value,
this call does not echo it. Sending an array for table_data instead of one object inserts every
element as its own row in one call, id/rev come back per row in that case rather than once.