Internal database

1 min read

The script library provides methods for all CRUD actions on the internal database (as defined in the data section). Methods are available in the db global variable. The available methods are dependent on your data definition. All methods are type checked and visible in the code autocomplete.

Example:

const {count, items} = await db.listUser({
  name: 'John',
  $limit: 10
});

This call selects only users that have the name "John". It is also limited to 10 records. The dollar sign is used to separate functional properties from column names. We may also have a column named "limit", and we can filter on it by providing limit without the dollar sign. You can also use the operators "ne" (not equal) and "lt", "lte", "gt", and "gte" (less / greater than / or equal). Example:

const {count, items} = await db.listUser({
  age$gte: 18
});

Note that these examples require the "name" and "age" fields to be indexed.