Each Flowlet workspace comes with a built-in database. You can define and view its tables on the "Data" page, available from the main menu. Each table is defined using a schema. Each top-level property in the schema becomes a database column. When configuring a property, you can choose to index this column. That makes the column available for filtering and sorting at the expense of additional storage size.
You can create data tables in the Data section accessible from the sidebar. The table structure is provided as a schema. There are a few differences for these schemas compared to schemas used for other purposes:
- The schema is always an object.
- The id property is added by default. You cannot remove or change this property. Its value is automatically set when creating records.
- Fields may be indexed.
Indexing fiels allows you to filter records when using the list operation. This comes at the expense of increased storage size. Indexing is available on numbers, strings with a maximum length of at most 255 characters, and booleans. You cannot index nested properties (inside arrays or objects).
You can access database tables from flows by using their CRUD blocks. Each table gets the following blocks, where the actual table name replaces "Table":
- CreateTable: add a new row to this table.
- ReadTable: retrieve a single record by its id.
- UpdateTable: update a single row in this table.
- DeleteTable: delete a single row in this table.
- FindTable: find a single row based on filter conditions.
- ListTable: list all records or records matching the given filter criteria. You can also specify an offset, limit, and column for sorting.
The same operations are also available in scripts at the global
db object, see the Internal database page for more information.
Calculating storage size
The storage size is calculated per field by counting the length of its JSON representation. Empty fields have the value
null and hence are 4 bytes. Indexed columns are counted twice.
For example, a user table with the fields "id", "name", and "age" (indexed) with the rows:
l2m-gTV_9RYGw2zS Alice 24 mt7aWHbolywYGCg_ Bob 25
Has ids with 16 characters, which is in JSON written as
"l2m-gTV_9RYGw2zS" and hence have size 16. The age number has two digits but is indexed and hence counts as 4. The names have sizes 7 and 5, respectively, summing up to a total table size of 52 bytes.