Skip to main content

Plans

Plans are the structured operation format executed by CSDB. Both public query surfaces produce plans:

  • The fluent table API builds plans from chained method calls.
  • SQL text is parsed into plans before execution.

This keeps one execution engine behind both APIs.

Flow

TableQuery API ─┐
├─> QueryPlan ─> Executor ─> rows or mutation result
SQL text ───┘

Plan Kinds

type QueryPlan =
| SelectPlan
| InsertPlan
| UpdatePlan
| DeletePlan
| CreateTablePlan
| DropTablePlan;

Select Rows

Produced by fluent selection methods or SELECT.

{
kind: "select",
table: "workers",
columns: ["id", "email"],
joins: [],
where: expression,
orderBy: [{ column: "id", direction: "asc" }],
limit: 10,
output: "objects"
}
SELECT id, email
FROM workers
WHERE email IS NOT NULL
ORDER BY id ASC
LIMIT 10

Mutate Rows

Produced by fluent mutation methods or INSERT, UPDATE, and DELETE.

{ kind: "insert", table: "workers", rows: [{ id: "w_001" }] }
{ kind: "update", table: "workers", set: { email: "ada@example.com" }, where: expression }
{ kind: "delete", table: "workers", where: expression }
INSERT INTO workers (id, name, email) VALUES (?, ?, ?)
UPDATE workers SET email = ? WHERE id = ?
DELETE FROM workers WHERE id = ?

Change Tables

Produced by database table methods or compact DDL SQL.

{ kind: "create-table", schema }
{ kind: "drop-table", table: "tags" }
CREATE TABLE tags (label text primary key)
DROP TABLE tags

Expressions

Expressions represent literals, identifiers, comparisons, IS NULL, AND, OR, and NOT. They are used in plan where fields and constraint evaluation.