Skip to main content

Module sql

Module sql 

Source
Expand description

Minimal SQL parser for halephant’s routing and interception needs.

The module is split into three layers:

  • lexer: chumsky character-level tokenizer — handles nested block comments, dollar-quoted strings, single-quoted strings with '' escapes, and double-quoted identifiers with "" escapes.
  • parser: a tiny hand-written recursive-descent walker over the token slice, producing a Statement AST.
  • ast: the AST — one variant per statement shape halephant cares about, with all relevant fields captured inline so consumers never need a second extraction helper.

Public API is deliberately small: parse to get a Statement, as_boolean to interpret a PostgreSQL boolean literal. Everything else is a method on the AST (see Statement::is_read_only and Statement::is_read_write_override).

Structs§

TransactionOptions
Transaction-mode options gathered from a BEGIN, START TRANSACTION, SET TRANSACTION, or SET SESSION CHARACTERISTICS AS TRANSACTION clause.

Enums§

DeallocateTarget
Target of a DEALLOCATE.
DiscardTarget
Target of a DISCARD. PostgreSQL’s DISCARD ALL is defined as a macro expansion of the other DISCARD variants plus DEALLOCATE ALL, RESET ALL, CLOSE ALL, UNLISTEN *, and pg_advisory_unlock_all(). The distinction matters because halephant’s per-connection pool state tracking needs to react to ALL (clear prepared statements and dirty GUCs) but not to the narrower forms.
ResetTarget
Target of a RESET.
SetScope
Visibility scope of a SET assignment.
SetValue
Value on the right-hand side of a SET parameter (= | TO) ....
Statement
A parsed SQL statement.
UnlistenTarget
Target of an UNLISTEN: a specific channel name or the wildcard.

Functions§

as_boolean
Interpret a lowercased string as a PostgreSQL boolean value.
parse
Parse a SQL string into a Statement.