ExSQL.Executor (exsql v0.1.2)

Copy Markdown

Statement execution against an ExSQL.Database.

Where SQLite compiles statements to VDBE bytecode and runs them in a register VM (vdbe.c, 190 opcodes), this first implementation walks the AST directly — the natural functional starting point, and the layer a bytecode compiler can replace later without touching parsing or storage.

Environments

Expressions evaluate inside an environment holding the current row of each table in scope:

  • frames — one frame per FROM source (table or subquery), each with the source's alias, its column order, and the current row. Joins produce envs whose frame list has one entry per joined source.
  • outer — the enclosing query's env, for correlated subqueries; column resolution falls back outward like SQLite's resolveExprStep.
  • group — in aggregate queries, the list of member envs of the current group; aggregate functions consume it, bare columns delegate to the first member.

All functions are pure: they take a database value and return {:ok, result, new_database} or {:error, %ExSQL.Error{}}.

Summary

Functions

Executes a single parsed statement.

Parses and executes every statement in sql, threading the database through. Returns the results in statement order. A failing statement stops execution; effects of prior statements in the same string are kept (as with sqlite3_exec), so the error tuple carries the database too.

Functions

execute(db, stmt)

@spec execute(ExSQL.Database.t(), ExSQL.Parser.statement()) ::
  {:ok, ExSQL.Result.t(), ExSQL.Database.t()} | {:error, ExSQL.Error.t()}

Executes a single parsed statement.

run(db, sql, params \\ [])

@spec run(ExSQL.Database.t(), String.t(), [ExSQL.Value.t()] | map()) ::
  {:ok, [ExSQL.Result.t()], ExSQL.Database.t()}
  | {:error, ExSQL.Error.t(), ExSQL.Database.t()}

Parses and executes every statement in sql, threading the database through. Returns the results in statement order. A failing statement stops execution; effects of prior statements in the same string are kept (as with sqlite3_exec), so the error tuple carries the database too.