Skip to content

Database ​

Luna Park ships a SQL database inside the editor. No server, no setup: you create tables, store rows, and query them from the graph.

PostgreSQL everywhere

In the editor, the database is a PGlite instance (PostgreSQL compiled to WebAssembly) running in your browser. In the exported app, the same tables run on a real PostgreSQL server, set with the DATABASE_URL variable (see Self-hosting). The rows you create in the editor are inserted as initial data on first launch.

Tables ​

Each Database file is a table. Create one in the Explorer with New > Database, then open it to:

  • define its columns (name and type) in the Columns section of the Inspector;
  • add, edit, delete, and search rows;
  • inspect the contents in real time.

The id, created_at, and updated_at columns are added automatically to every table. id is a UUID.

Database editor showing a table with its columns

Column types ​

TypeStored as
Texttext
Numbernumeric
Booleanbool
Datetimestamptz
Objectjsonb
Arraya PostgreSQL array
Reference to another tableuuid (foreign key)

Constraints ​

The Constraints section of the Inspector sets, for each column:

ConstraintEffect
RequiredThe column can't be empty.
UniqueTwo rows can't share the same value.
IndexSpeeds up searches and sorting on this column.

A column that references another table also defines what happens when the referenced row is deleted: Block (default), Restrict, Delete rows too, or Set to empty.

Querying the database ​

Database nodes are used inside backend logic: routes, crons, and backend scripts. The interface calls a route, which runs the query and returns the result.

Specialized nodes ​

Luna Park provides one node per common operation. Configuration is visual (table, parameters, filters), and the SQL is generated behind the scenes.

CategoryNodes
ReadDB Find, DB Find By Id
WriteDB Insert, DB Update, DB Update By Id
DeleteDB Delete, DB Delete By Id
TransactionDB Transaction

Parameters plug into the input anchors: an id coming from a variable, a filter value coming from an input, etc.

DB Find node configured on a table, with its parameters and output anchor

DB Transaction runs the operations wired to its Run output all at once: if one fails, none is saved. Then runs after the changes are saved.

Build a query ​

For more precise queries, Luna Park provides nodes that chain together: each node adds a SQL clause and exposes a Query output that the next one consumes.

The starting point is always DB From, which selects the table. You then plug in the nodes you need, and finish with an execution node.

NodeRole
DB FromSelects the source table.
DB SelectChooses the returned columns (all by default).
DB WhereFilters rows with one or more conditions.
DB Where ConditionCompares a column with a value or another column.
DB Where ConditionsCombines conditions with AND or OR.
DB Join / DB Join ConditionJoins another table (inner, left, right, full).
DB Order / DB Order DirectionSorts the results.
DB Group ByGroups rows by value.
DB AggregateComputes count, sum, avg, min, or max, optionally on distinct values.

Execution nodes:

NodeRole
DB Query SelectRuns the query and returns the rows.
DB Query UpdateUpdates the matching rows.
DB Query DeleteDeletes the matching rows.
DB Query ExplainShows how PostgreSQL plans to run the query.

Available comparisons: equals, not equals, greater/less than (or equal), in, is null, like, ilike, contains.

For example, to fetch users under 30: a DB From points to the table, a DB Where Condition defines age < 30, a DB Where receives the query and the condition, and a DB Query Select runs the whole thing.

Graph with DB From, DB Where Condition, DB Where, and DB Query Select chained together

Query preview

To see the SQL that actually runs, select the DB Query Select node and click Preview in its config.

Preparing the articles table ​

To follow the guided example on the Routes page, create an articles table:

  1. Create a Database file named articles.
  2. Add a title column (text).
  3. Insert a few test rows.
articles table with its columns and a few example rows

The rest (exposing these articles through a route and rendering them in the interface) is covered on the Routes page.