The SQL section provides a dedicated SQLite database for each project. You can create tables, indexes, and views, edit data manually, write any queries, and access the database directly from your workflow. It is full-featured SQLite with unrestricted syntax: anything supported by SQLite works here as well.

The SQL database is stored separately from the tables in the Tables section. Changes made in one do not affect the other.

How to open it

Project → Tables → click SQL to the right of Add Table.

To return to the list of tables, click the arrow in the page header.

The SQL section is available to team members with permission to edit tables. Users with view-only access can see the database structure, but cannot access its data or queries.

Database structure

The database tree is displayed on the right. It contains tables with their columns and indexes, followed by views. Each column shows its data type, primary key columns are marked with a key icon, and indexes display the UNIQUE attribute and their associated columns.

All structure-related actions are available from the node menu: right-click a node, click the icon that appears on hover, or use the + button above the tree.

Node Actions
Database create table, create view, refresh, download database
Table open, add column, add index, rename, DDL, refresh, delete
Column rename, delete
Index DDL, delete
View open, DDL, delete

Create a table. Specify the table name and columns: name, type, default value, PK, and NOT NULL. You can select a data type from the suggestions or enter your own. If you mark multiple columns as PK, they will form a composite primary key.

DDL displays the object's CREATE statement in the console. This is useful for copying its structure or recreating it in another project.

The buttons above the tree let you create objects, refresh the database, show or hide the console, view the DDL of the selected table, download the database, or clear the database.

Table data

Click a table in the database tree to open its data. The grid works much like a sheet in the Tables section:

  • Edit a cell by double-clicking it. Press Enter to save or Esc to cancel. The value is written to the database immediately.
  • Rows. Click + to add an empty row or to delete selected rows. Click a row number in the first column to select it. Use Shift or Cmd/Ctrl to select multiple rows.
  • NULL values are displayed as NULL. Clearing a cell writes an empty string to the database. To write a NULL value, use a query.
  • WHERE and ORDER BY fields above the grid accept SQL conditions and sorting expressions. Enter an expression and press Enter. The ORDER BY field takes precedence over sorting applied through the column menu.
  • Column menu (the icon in the column header): sort ascending or descending, or filter by substring.
  • Data is loaded as you scroll, in batches of 100 rows. The counter on the right shows the current range and the total number of rows.
  • Views are read-only.

Console

Click the </> button above the database tree to open the console, which includes a syntax-highlighted query editor and query results.

  • Run a query using the button or Ctrl+Enter (Cmd+Enter on Mac).
  • You can run multiple queries separated by ;. The result displays the rows returned by the last query that produced data, along with the total number of affected rows.
  • SQLite errors are displayed as-is. When running multiple queries, the query number is added to the error message: [2] no such table: ....
  • Favorites. Click Add to Favorites to save the current query under a name. Saved queries appear as chips above the editor: click one to load the query or click the cross to delete it. Favorites are stored in your browser separately for each project.
  • The text of your last query is preserved between sessions.

Downloading and clearing the database

Download database downloads the entire database as project_<id>_sql.sqlite3. You can open it with any SQLite-compatible application, transfer it to another project, or use it outside Mavibot.

Clear database deletes all tables and data from the SQL section. This action cannot be undone and requires you to enter a confirmation word. Tables in the Tables section are not affected.

Calculator functions

Two calculator functions let you access the SQL database from your workflow. Both are available in the editor suggestions and are recognized by the assistant.

sql(query, params=null, strict=true)

Executes a query.

Query Return value
Query with a result (SELECT, RETURNING, PRAGMA) JSON list of rows, with each row represented as an object: [{"id": 1, "name": "Anna"}, ...]
Query without a result (INSERT, UPDATE, DELETE) number of affected rows
CREATE, DROP, and other schema changes 0
Error string ERROR: <SQLite error message>

Example:

rows = sql("SELECT name, phone FROM clients WHERE city = ?", [city])
n = sql("UPDATE clients SET status = :s WHERE id = :id", {"s": "vip", "id": client_id})

sql_value(query, params=null, strict=true)

Works like sql, but returns a single value: the first column of the first row in the result.

If there are no rows, no result, or the value is NULL, it returns an empty string.

total = sql_value("SELECT count(*) FROM clients")
name = sql_value("SELECT name FROM clients WHERE id = ?", [client_id])

Parameters

params passes values to the query separately from the query text: use a JSON array for ? placeholders or a JSON object for :name placeholders. Inside [...] and {...}, variables are written as plain variable names:

[client_id], not [#{client_id}].

Pass any values received from a customer through params, such as their name, phone number, or message text. A value concatenated directly into the query text could modify the query itself.

Strict mode

By default, strict=true: the function accepts exactly one query and does not allow comments in the query text. This prevents a value received from a customer message from appending a second query or truncating the rest of the original query.

Set strict=false to remove this restriction, for example when running multiple queries separated by ;.

Limits

Limit Value
Execution time for a single query or query batch 5 seconds
Rows returned up to 1,000; additional rows are not returned
Query text length 64 KB
Database size 200 MB; once exceeded, only reading and deleting data are available

The only commands prohibited are those that access resources outside the project's database: ATTACH with a file path and VACUUM INTO.

Everything else, including standard VACUUM, PRAGMA, and transactions, is supported.