How to use studio?

Queries

Build, run, copy and share agdb queries in the studio query builder

The query page (/studio/query/<owner>/<db>) opens when you click a database on the Databases page. Its heading names the database. The query builder is at the top and the results below it.

The builder writes the same queries as the QueryBuilder of the agdb libraries, one step at a time, so you do not need to know the syntax up front.

Tabs

The builder has three tabs. Each has its own queries and its own undo history.

TabUse it for
execQueries that read the database (select, search).
exec_mutQueries that change the database (insert, remove). The rows are orange and the button reads Run mutation.
contextQueries that load extra elements around the results, e.g. the neighbourhood of the nodes you found. They show only in the graph.

Running runs only the tab you are on.

Build a query

Each row of a tab is one query, a chain of steps such as select → ids → query.

  1. Click into the row and start typing. A list shows the steps that can come next, filtered by what you typed. Pick one with the arrow keys and Enter, or click it.
  2. A step that takes arguments opens an editor below it. Each argument has a type and a value. Close the editor with Esc or Enter. The step then shows a short summary such as (s, foo), (u, 3); click it to change the arguments again.
  3. Go on with the next step. The closing query step is optional.

The type of an argument is picked from a short label:

LabelTypeLabelType
sstrings[] u[] i[] b[] f[]lists of these, comma separated (1, 2, 3)
uunsigned↑ ↓ascending and descending order (in order_by)
isigned
bboolean
ffloat

Ids can be numbers or aliases. Arguments that repeat, like the key-value pairs of values, have + and − buttons to add and remove entries (− when there is more than one).

To fix a step, hover it and click its ×, or focus it and press Delete. Backspace in an empty input removes the step before it. When a step no longer fits the chain, it gets a red outline and the query cannot run until it is fixed.

You can also paste queries written in Rust. Copy QueryBuilder::… code (one query per line, a vec![…] of queries, or a whole db.exec(…) call) and press Ctrl+V in a row. Each query becomes its own row.

Several queries

Click + at the end of the last row to add another query. All the queries of a tab are sent together and run in one transaction. Empty rows are skipped.

The controls of each row (the grip handle and the result index only when the tab has more than one row):

ControlWhat it does
grip handleDrag to reorder the rows, or focus it and use the up and down arrows.
result indexThe row's index in the results (from 0; blank for empty rows). Click to select the row. Ctrl+click adds rows to the selection, Shift+click selects a range.
colour swatchColour of this query's elements in the graph. Not on the context tab or on empty rows.
eraserClears the steps of the row.
copy / pasteCopies the query as Rust code, or pastes a copied query into an empty row or below a filled one.
trashRemoves the row, or all selected rows.

With rows selected, Ctrl+C copies them, Delete removes them and Esc clears the selection.

Next to the rows, when the tab has more than one row:

  • Show queries / Hide queries folds the rows into a one-line summary.
  • The copy button copies all queries of the tab as Rust code, one per line (with at least two queries).
  • The eraser button removes all queries of the tab, after you confirm (Clear all queries).

Undo and Redo at the right of the tabs (Ctrl+Z, Ctrl+Shift+Z or Ctrl+Y, except in a field that has text) step through your edits.

Run a query

Click Run query (Run mutation on the exec_mut tab) or press Ctrl+Enter. While it runs, the button turns into Stop query. If the query fails, the error is shown above the results.

Stopping a mutation only stops waiting for its answer. The changes have already been sent to the server and may still be made.

The queries of all tabs are kept in the address of the page, e.g. /studio/query/alice/shop?exec=select().ids(1). Copy the address from the browser to bookmark a query or send it to someone with access to the database. The link opens the same queries, but does not run them.

Before running mutations that came from a link, the studio shows their code and asks Run queries from a link?, so a link cannot change your data without you seeing it first.

The address holds up to about 6,000 characters. When all the queries together are longer, the address no longer holds any of them and the studio warns Queries too long for the link; use Export query → Query (JSON) or the Rust code to keep them instead. A link longer than that does not open (Link too long). Queries in a link that cannot be read are skipped with the warning Some queries were not opened; if one of them is a mutation, none of the mutations are opened.

The query page keeps nothing else. The results, colours, chart settings and pinned details are gone when you leave the page or reload it. To keep a query with its view, add it to a dashboard.

Export the query

Export query on the page heading downloads the queries of all tabs as Query (JSON) or Rust code (a .rs file with a function per tab that returns its QueryBuilder queries). See Export and print.