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 aStatementAST.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§
- Transaction
Options - Transaction-mode options gathered from a
BEGIN,START TRANSACTION,SET TRANSACTION, orSET SESSION CHARACTERISTICS AS TRANSACTIONclause.
Enums§
- Deallocate
Target - Target of a
DEALLOCATE. - Discard
Target - Target of a
DISCARD. PostgreSQL’sDISCARD ALLis defined as a macro expansion of the otherDISCARDvariants plusDEALLOCATE ALL,RESET ALL,CLOSE ALL,UNLISTEN *, andpg_advisory_unlock_all(). The distinction matters because halephant’s per-connection pool state tracking needs to react toALL(clear prepared statements and dirty GUCs) but not to the narrower forms. - Reset
Target - Target of a
RESET. - SetScope
- Visibility scope of a
SETassignment. - SetValue
- Value on the right-hand side of a
SET parameter (= | TO) .... - Statement
- A parsed SQL statement.
- Unlisten
Target - 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.