sqlparser

Extensible SQL Lexer and Parser in MoonBit

sql
parser
lexer
moon add moonbit-community/sqlparser@0.5.0
Download zip
Version
0.5.0
License
Apache-2.0
Last updated
4 months ago
Downloads
20

Dependencies

README

#Extensible SQL Lexer and Parser for MoonBit

A comprehensive SQL parser library for MoonBit that supports multiple SQL dialects and all major SQL language categories.

#Example Usage

// Parse a simple SELECT statement let sql = "SELECT name, age FROM users WHERE age > 18" let statements = parse_sql(sql) let pretty_output = statements.stmts[0] |> pretty_print println(pretty_output) // Parse complex queries with CTEs let complex_sql = """ WITH sales AS ( SELECT user_id, SUM(amount) as total FROM orders WHERE date > '2023-01-01' GROUP BY user_id ) SELECT u.name, s.total FROM users u JOIN sales s ON u.id = s.user_id ORDER BY s.total DESC LIMIT 10 """ let result = parse_sql(complex_sql) // Parse transaction control statements let tcl_sql = "BEGIN TRANSACTION; INSERT INTO users VALUES ('Alice'); COMMIT;" let tcl_statements = parse_sql(tcl_sql) // Parse data control statements let dcl_sql = "GRANT SELECT, INSERT ON users TO alice WITH GRANT OPTION" let dcl_result = parse_sql(dcl_sql) // Dialect-specific parsing let mysql_sql = "SHOW TABLES LIKE 'user%'" let mysql_result = parse_sql(dialect=MySQL::{}, mysql_sql)

#Architecture

The parser follows a modular design:

  • Lexer (lexer.mbt): Tokenizes SQL input with dialect-aware keyword recognition
  • Parser (parser.mbt): Main parsing logic with statement dispatching
  • AST (ast.mbt): Complete Abstract Syntax Tree definitions with pretty printing
  • Dialect Modules: Separate modules for each SQL dialect (mysql.mbt, postgres.mbt, etc.)
  • Language Modules:
    • dml.mbt: Data Manipulation Language parsing
    • ddl.mbt: Data Definition Language parsing
    • tcl.mbt: Transaction Control Language parsing
    • dcl.mbt: Data Control Language parsing

#Testing

The library includes comprehensive test coverage with 284+ tests covering:

  • All SQL statement types across all language categories
  • Dialect-specific features and syntax variations
  • Complex expressions and nested queries
  • Edge cases and error handling
  • Pretty printing accuracy

Run tests with:
moon test

#Contributing

The parser is designed for extensibility. To add new SQL features:

  1. Add keywords to keyword.mbt and lexer.mbt
  2. Define AST structures in ast.mbt
  3. Implement parsing logic in appropriate language module
  4. Add statement cases to parser.mbt

#Contributing

The parser is designed for extensibility. To add new SQL features:

  1. Add keywords to keyword.mbt and lexer.mbt
  2. Define AST structures in ast.mbt
  3. Implement parsing logic in appropriate language module
  4. Add statement cases to parser.mbt
  5. Write comprehensive tests

See ROADMAP.md for planned features and implementation priorities.

#License

This project is licensed under the Apache 2.0 License.

#
Dialect

pub trait Dialect {
supports_string_literal_backslash_escape(Self) -> Bool
supports_boolean_literals(Self) -> Bool
supports_filter_during_aggregation(Self) -> Bool
supports_within_after_array_aggregation(Self) -> Bool
requires_column_types_in_create_table(Self) -> Bool
supports_if_not_exists(Self) -> Bool
supports_double_quoted_identifiers(Self) -> Bool
supports_array_syntax(Self) -> Bool
supports_named_parameters(Self) -> Bool
parse_expr(Self, tokens : ArrayView[Token]) -> (Expr, ArrayView[Token])? raise ParserError
parse_statement(Self, parser : Parser, tokens : ArrayView[Token]) -> (Statement, ArrayView[Token])? raise ParserError
read_keyword(Self, word : String) -> Keyword?
}

#
LexerError

type LexerError derive(Show)

#
ParserError

type ParserError derive(Show)

#
SqlParserError

pub suberror SqlParserError {
LexerError(LexerError)
ParserError(ParserError)
} derive(Show)

#
ANSI

pub(all) struct ANSI {
}

ANSI SQL dialect - adheres to ANSI SQL standards
impl Dialect for ANSI

#
AccessExpr

pub(all) enum AccessExpr {
Dot(Expr)
Subscript(Subscript)
} derive(Eq, Show)

Access expression for array indexing, slicing, and field access

#
AlterIndexOperation

pub(all) enum AlterIndexOperation {
RenameTo(String)
SetTablespace(String)
Reset(Array[String])
Set(Array[IndexParameter])
} derive(Eq, Show)

#
AlterIndexStmt

pub(all) struct AlterIndexStmt {
name : String
if_exists : Bool
operation : AlterIndexOperation
} derive(Eq, Show)

ALTER INDEX statement

#
AlterTableOperation

pub(all) enum AlterTableOperation {
DropColumn(String, Bool)
} derive(Eq, Show)

#
AlterTableStmt

pub(all) struct AlterTableStmt {
table_name : ObjectName
if_exists : Bool
operation : AlterTableOperation
} derive(Eq, Show)

#
ArrayExpr

pub(all) struct ArrayExpr {
elem : Array[Expr]
named : Bool
} derive(Eq, Show)

PostgreSQL array expression

#
Assignment

pub(all) struct Assignment {
column : String
value : Expr
} derive(Eq, Show)

#
BeginStmt

pub(all) struct BeginStmt {
work : Bool
transaction : Bool
} derive(Eq, Show)

#
BigQuery

pub(all) struct BigQuery {
}

BigQuery dialect - supports Google BigQuery specific syntax
impl Dialect for BigQuery

#
BinaryOperator

pub(all) enum BinaryOperator {
Eq
Neq
Lt
Gt
LtEq
GtEq
Spaceship
Plus
Minus
Mul
Div
IntegerDiv
Mod
And
Or
JsonExtract
JsonExtractText
JsonExtractPath
JsonExtractPathText
JsonContains
JsonContainedIn
} derive(Eq, Show)

#
BinaryOperator::get_precedence

fn BinaryOperator::get_precedence(self : BinaryOperator) -> Precedence

#
CaseExpr

pub(all) struct CaseExpr {
operand : Expr?
when_then_clauses : Array[(Expr, Expr)]
else_expr : Expr?
} derive(Eq, Show)

CASE [operand] WHEN THEN [...] [ELSE ] END

#
ClickHouse

pub(all) struct ClickHouse {
}

ClickHouse dialect - supports ClickHouse specific syntax

#
ColumnDef

pub(all) struct ColumnDef {
name : String
data_type : DataType
options : Array[ColumnDefOption]
} derive(Eq, Show)

#
ColumnDefOption

pub(all) enum ColumnDefOption {
NotNull
Unique
Default(Expr)
PrimaryKey
} derive(Eq, Show)

#
CommitStmt

pub(all) struct CommitStmt {
work : Bool
transaction : Bool
} derive(Eq, Show)

#
ConflictAction

pub(all) enum ConflictAction {
DoNothing
DoUpdate(Array[Assignment], Expr?)
} derive(Eq, Show)

Action to take when conflict occurs

#
ConflictTarget

pub(all) enum ConflictTarget {
Columns(Array[String])
OnConstraint(String)
OnExpression(Expr, Expr?)
} derive(Eq, Show)

Conflict target specification

#
CopyDirection

pub(all) enum CopyDirection {
To
From
} derive(Eq, Show)

Direction of COPY operation

#
CopyForceQuote

pub(all) enum CopyForceQuote {
All
Columns(Array[String])
} derive(Eq, Show)

FORCE_QUOTE specification

#
CopyFormat

pub(all) enum CopyFormat {
Csv
Text
Binary
} derive(Eq, Show)

COPY format specification

#
CopyOption

pub(all) enum CopyOption {
Format(CopyFormat)
Delimiter(String)
Null(String)
Header(Bool?)
Quote(String)
Escape(String)
ForceQuote(CopyForceQuote)
ForceNotNull(Array[String])
ForceNull(Array[String])
Encoding(String)
} derive(Eq, Show)

COPY statement options

#
CopySource

pub(all) enum CopySource {
Table(ObjectName, Array[String]?)
Query(QueryStmt)
} derive(Eq, Show)

Source specification for COPY statement

#
CopyStmt

pub(all) struct CopyStmt {
source : CopySource
direction : CopyDirection
target : CopyTarget
format_options : Array[CopyOption]
} derive(Eq, Show)

COPY statement for bulk data import/export operations

#
CopyTarget

pub(all) enum CopyTarget {
File(String)
Stdin
Stdout
Program(String)
} derive(Eq, Show)

Target specification for COPY statement

#
CreateDatabaseStmt

pub(all) struct CreateDatabaseStmt {
name : String
if_not_exists : Bool
character_set : String?
collate : String?
} derive(Eq, Show)

#
CreateFunctionStmt

pub(all) struct CreateFunctionStmt {
name : String
parameters : Array[FunctionParameter]
return_type : DataType?
language : String?
body : String?
deterministic : Bool
if_not_exists : Bool
} derive(Eq, Show)

#
CreateIndexStmt

pub(all) struct CreateIndexStmt {
unique : Bool
concurrently : Bool
if_not_exists : Bool
name : String
table_name : ObjectName
index_method : IndexMethod?
columns : Array[IndexColumn]
where_clause : Expr?
} derive(Eq, Show)

CREATE INDEX statement

#
CreateProcedureStmt

pub(all) struct CreateProcedureStmt {
name : String
parameters : Array[FunctionParameter]
language : String?
body : String?
if_not_exists : Bool
} derive(Eq, Show)

#
CreateSchemaStmt

pub(all) struct CreateSchemaStmt {
name : String
if_not_exists : Bool
authorization : String?
} derive(Eq, Show)

CREATE SCHEMA statement (synonym for CREATE DATABASE in many dialects)

#
CreateSequenceStmt

pub(all) struct CreateSequenceStmt {
name : String
if_not_exists : Bool
temporary : Bool
increment : Int?
minvalue : SequenceLimit?
maxvalue : SequenceLimit?
start_with : Int?
cache : Int?
cycle : Bool?
owned_by : SequenceOwnedBy?
} derive(Eq, Show)

#
CreateTableDefinition

pub(all) enum CreateTableDefinition {
Columns(Array[ColumnDef], Array[TableConstraint])
AsQuery(QueryStmt)
} derive(Eq, Show)

#
CreateTableStmt

pub(all) struct CreateTableStmt {
name : String
if_not_exists : Bool
definition : CreateTableDefinition
} derive(Eq, Show)

#
CreateViewStmt

type CreateViewStmt derive(Eq, Show)

#
Cte

pub(all) struct Cte {
name : String
query : QueryStmt
columns : Array[String]?
} derive(Eq, Show)

Common Table Expression (CTE) for WITH clauses

#
DataType

pub(all) enum DataType {
Integer
Smallint
Bigint
Float(Int?)
Real
Double
Char(Int)
Varchar(Int)
Text
Boolean
Timestamp
Blob
} derive(Eq, Show)

#
DatetimeUnit

pub(all) enum DatetimeUnit {
Year
Month
Day
Hour
Minute
Second
} derive(Eq, Show)

#
DeallocateStmt

pub(all) struct DeallocateStmt {
name : String
prepare : Bool
} derive(Eq, Show)

DEALLOCATE statement Syntax: DEALLOCATE [PREPARE] name

#
DeleteStmt

pub(all) struct DeleteStmt {
table_name : ObjectName
where_clause : Expr?
} derive(Eq, Show)

#
DropIndexStmt

pub(all) struct DropIndexStmt {
name : String
if_exists : Bool
concurrently : Bool
table_name : ObjectName?
} derive(Eq, Show)

#
DropTableStmt

pub(all) struct DropTableStmt {
table_name : ObjectName
if_exists : Bool
} derive(Eq, Show)

#
DropViewStmt

pub(all) struct DropViewStmt {
name : String
} derive(Eq, Show)

#
DuckDB

pub(all) struct DuckDB {
}

DuckDB dialect - supports DuckDB specific syntax
impl Dialect for DuckDB

#
DuplicateTreatment

pub(all) enum DuplicateTreatment {
Distinct
All
} derive(Eq, Show)

#
ExecuteStmt

pub(all) struct ExecuteStmt {
name : ObjectName?
parameters : Array[Expr]
has_parentheses : Bool
into : Array[String]
using_exprs : Array[Expr]
} derive(Eq, Show)

EXECUTE statement Syntax: EXECUTE name [(param [, ...])] EXECUTE name USING expr [, ...] EXECUTE IMMEDIATE 'sql_string' [INTO var [, ...]] [USING expr [, ...]]

#
Expr

pub(all) enum Expr {
Identifier(String)
CompoundIdentifier(Array[String])
Literal(Literal)
BinaryOperation(Expr, BinaryOperator, Expr)
UnaryOperation(UnaryOperator, Expr)
FunctionCall(String, DuplicateTreatment?, Array[Expr], Expr?)
Wildcard
Datetime(String)
Interval(String, IntervalQualifier)
Like(Bool, Expr, Expr)
ILike(Bool, Expr, Expr)
SubQuery(QueryStmt)
Exists(Bool, QueryStmt)
Between(Bool, Expr, Expr, Expr)
Extract(PrimaryDatetimeField, Expr)
Case(CaseExpr)
InList(Bool, Expr, Array[Expr])
InSubQuery(Bool, Expr, QueryStmt)
Substring(Expr, Expr?, Expr?)
Placeholder(String)
Array(ArrayExpr)
CompoundFieldAccess(Expr, Array[AccessExpr])
WindowFunction(String, DuplicateTreatment?, Array[Expr], WindowSpec)
} derive(Eq, Show)

#
FunctionParameter

pub(all) struct FunctionParameter {
name : String
param_type : DataType
mode : ParameterMode?
} derive(Eq, Show)

Function parameter definition

#
Generic

pub(all) struct Generic {
}

Generic SQL dialect that supports the union of all other dialects This is the most permissive dialect, useful for parsing various SQL statements from different sources without strict dialect requirements
impl Dialect for Generic

#
GrantStmt

pub(all) struct GrantStmt {
privileges : Array[Privilege]
objects : Array[ObjectName]
grantees : Array[String]
with_grant_option : Bool
} derive(Eq, Show)

#
IndexColumn

pub(all) struct IndexColumn {
name : Expr
asc : Bool?
nulls_first : Bool?
} derive(Eq, Show)

Index column specification

#
IndexMethod

pub(all) enum IndexMethod {
Btree
Hash
Gin
Gist
Spgist
Brin
} derive(Eq, Show)

Index creation method

#
IndexParameter

pub(all) struct IndexParameter {
name : String
value : String
} derive(Eq, Show)

Index parameter for SET operations

#
InsertSource

pub(all) enum InsertSource {
Values(Array[Array[Expr]])
Query(QueryStmt)
} derive(Eq, Show)

#
InsertStmt

pub(all) struct InsertStmt {
table_name : ObjectName
columns : Array[String]
source : InsertSource
or : SqliteOnConflict?
on : OnInsert?
} derive(Eq, Show)

#
IntervalQualifier

pub(all) enum IntervalQualifier {
Single(PrimaryDatetimeField)
Range(PrimaryDatetimeField, PrimaryDatetimeField)
} derive(Eq, Show)

#
Join

pub(all) struct Join {
table_ref : TableRef
join_operator : JoinOperator
} derive(Eq, Show)

#
JoinConstraint

pub(all) enum JoinConstraint {
On(Expr)
Using(Array[String])
Non
} derive(Eq, Show)

#
JoinOperator

pub(all) enum JoinOperator {
Join(JoinConstraint)
Left(JoinConstraint)
LeftOuter(JoinConstraint)
Right(JoinConstraint)
RightOuter(JoinConstraint)
Full(JoinConstraint)
FullOuter(JoinConstraint)
Inner(JoinConstraint)
Cross
} derive(Eq, Show)

#
Keyword

pub(all) enum Keyword {
Select
From
Where
As
Group
Order
By
Asc
Desc
Nulls
First
Last
Year
Month
Day
Hour
Minute
Second
Date
Interval
To
Like
Not
ILike
Exists
Between
And
Or
Extract
Filter
Case
When
Matched
Target
Then
Else
Having
End
In
Join
Left
Right
Full
Outer
Inner
Cross
On
Using
Limit
Offset
Create
Table
Integer
Int
Smallint
Bigint
Real
Double
Precision
Char
Character
Collate
Authorization
Varchar
Varing
Text
Time
Boolean
Float
Timestamp
Blob
Null
Default
Unique
View
Drop
Distinct
All
Substring
For
Primary
Key
Foreign
References
Check
Union
Intersect
Except
Top
Insert
Into
Values
Merge
If
Delete
Update
Set
Replace
Rollback
Abort
Fail
Ignore
Truncate
Alter
Column
Show
Tables
Columns
Status
Databases
Database
Div
Lock
Unlock
Listen
Notify
Schemas
Schema
Variables
Processlist
Grants
Functions
Function
Extended
Global
Session
Procedure
Returns
Language
Deterministic
Event
Trigger
Duplicate
Conflict
Do
Nothing
Constraint
Array
With
Begin
Start
Transaction
Commit
Savepoint
Release
Work
Grant
Revoke
Privileges
Usage
Use
Execute
Prepare
Deallocate
Immediate
Connect
Temporary
Temp
Option
Restrict
Cascade
Index
Copy
Format
Stdin
Stdout
Program
Header
ForceQuote
ForceNotNull
ForceNull
Encoding
Load
Data
Local
Infile
Fields
Lines
Terminated
Enclosed
Escaped
Starting
Optionally
Rename
Tablespace
Reset
Btree
Hash
Gin
Gist
Spgist
Brin
Concurrently
Over
Window
Partition
Rows
Range
Preceding
Following
Current
Unbounded
Row
Out
InOut
Sequence
Increment
Minvalue
Maxvalue
Cache
Cycle
Owned
No
} derive(Eq, Show)

#
Literal

pub(all) enum Literal {
Integer(Int)
Double(Double)
String(String)
Boolean(Bool)
Null
} derive(Eq, Show)

#
LoadDataDuplicateHandling

pub(all) enum LoadDataDuplicateHandling {
Replace
Ignore
} derive(Eq, Show)

#
LoadDataFieldsOptions

pub(all) struct LoadDataFieldsOptions {
terminated_by : String?
enclosed_by : String?
optionally_enclosed : Bool
escaped_by : String?
} derive(Eq, Show)

#
LoadDataLinesOptions

pub(all) struct LoadDataLinesOptions {
starting_by : String?
terminated_by : String?
} derive(Eq, Show)

#
LoadDataStmt

pub(all) struct LoadDataStmt {
is_local : Bool
filename : String
duplicate_handling : LoadDataDuplicateHandling?
table_name : ObjectName
character_set : String?
fields_options : LoadDataFieldsOptions?
lines_options : LoadDataLinesOptions?
ignore_lines : Int?
columns : Array[String]?
set_assignments : Array[Assignment]?
} derive(Eq, Show)

LOAD DATA statement for MySQL-style bulk data loading

#
MergeAction

pub(all) enum MergeAction {
Insert(Array[String], Array[Expr])
Update(Array[Assignment])
Delete
} derive(Eq, Show)

Actions that can be performed in MERGE

#
MergeMatchType

pub(all) enum MergeMatchType {
Matched
NotMatched
} derive(Eq, Show)

Match type for WHEN clause

#
MergeSource

pub(all) enum MergeSource {
Table(ObjectName)
Query(QueryStmt)
} derive(Eq, Show)

Source for MERGE statement

#
MergeStmt

pub(all) struct MergeStmt {
target_table : ObjectName
target_alias : String?
source : MergeSource
source_alias : String?
join_condition : Expr
when_clauses : Array[MergeWhenClause]
} derive(Eq, Show)

MERGE statement for conditional INSERT/UPDATE/DELETE operations

#
MergeWhenClause

pub(all) struct MergeWhenClause {
match_type : MergeMatchType
condition : Expr?
action : MergeAction
} derive(Eq, Show)

WHEN clause in MERGE statement

#
MySQL

pub(all) struct MySQL {
}

impl Dialect for MySQL

#
ObjectName

pub(all) struct ObjectName {
parts : Array[String]
} derive(Eq, Show)

#
OnConflictClause

pub(all) struct OnConflictClause {
conflict_target : ConflictTarget?
conflict_action : ConflictAction
} derive(Eq, Show)

PostgreSQL ON CONFLICT clause for advanced conflict resolution Syntax: ON CONFLICT [ conflict_target ] conflict_action

#
OnInsert

pub(all) enum OnInsert {
DuplicateKeyUpdate(Array[Assignment])
OnConflict(OnConflictClause)
} derive(Eq, Show)

MySQL ON DUPLICATE KEY UPDATE or PostgreSQL ON CONFLICT

#
OrderByExpr

pub(all) struct OrderByExpr {
expr : Expr
asc : Bool?
nulls_first : Bool?
} derive(Eq, Show)

#
ParameterMode

pub(all) enum ParameterMode {
In
Out
InOut
} derive(Eq, Show)

Parameter mode for functions/procedures

#
Parser

pub struct Parser {
dialect : &Dialect
}

#
Postgres

pub(all) struct Postgres {
}

impl Dialect for Postgres

#
Precedence

pub(all) enum Precedence {
PlusMinus
MulDivMod
Eq
Like
And
Or
Between
UnaryNot
JsonOperator
}

#
Precedence::value

fn Precedence::value(self : Precedence) -> Int

#
PrepareStmt

pub(all) struct PrepareStmt {
name : String
data_types : Array[DataType]
statement : Statement
} derive(Eq, Show)

PREPARE statement Syntax: PREPARE name [(data_type [, ...])] AS statement

#
PrimaryDatetimeField

type PrimaryDatetimeField derive(Eq, Show)

#
Privilege

pub(all) enum Privilege {
Select(Array[String]?)
Insert(Array[String]?)
Update(Array[String]?)
Delete
References(Array[String]?)
Create
Drop
Alter
Index
All
Usage
Execute
Connect
Temporary
} derive(Eq, Show)

#
Projection

pub(all) enum Projection {
Wildcard
UnamedExpr(Expr)
AliasedExpr(Expr, String)
} derive(Eq, Show)

#
QueryStmt

pub(all) struct QueryStmt {
with_clause : Array[Cte]?
body : SetExpr
order_by : Array[OrderByExpr]
limit : Expr?
offset : Expr?
} derive(Eq, Show)

#
Redshift

pub(all) struct Redshift {
}

Redshift dialect - supports Amazon Redshift specific syntax
impl Dialect for Redshift

#
ReleaseSavepointStmt

pub(all) struct ReleaseSavepointStmt {
savepoint_keyword : Bool
name : String
} derive(Eq, Show)

#
RevokeOption

pub(all) enum RevokeOption {
Restrict
Cascade
} derive(Eq, Show)

#
RevokeStmt

pub(all) struct RevokeStmt {
grant_option_for : Bool
privileges : Array[Privilege]
objects : Array[ObjectName]
grantees : Array[String]
cascade : RevokeOption?
} derive(Eq, Show)

#
RollbackStmt

pub(all) struct RollbackStmt {
work : Bool
transaction : Bool
savepoint : String?
} derive(Eq, Show)

#
SQLite

pub(all) struct SQLite {
}

impl Dialect for SQLite

#
SavepointStmt

pub(all) struct SavepointStmt {
name : String
} derive(Eq, Show)

#
SelectStmt

type SelectStmt derive(Eq, Show)

#
SequenceLimit

pub(all) enum SequenceLimit {
Value(Int)
NoLimit
} derive(Eq, Show)

Sequence limit specification

#
SequenceOwnedBy

pub(all) enum SequenceOwnedBy {
Column(ObjectName, String)
ByNone
} derive(Eq, Show)

OWNED BY specification for sequences

#
SetAssignment

pub(all) struct SetAssignment {
variable : String
value : Expr
} derive(Eq, Show)

#
SetExpr

type SetExpr derive(Eq, Show)

#
SetOperator

type SetOperator derive(Eq, Show)

#
SetScope

pub(all) enum SetScope {
Global
Session
UserVar
Local
} derive(Eq, Show)

#
SetStmt

pub(all) struct SetStmt {
scope : SetScope
assignments : Array[SetAssignment]
} derive(Eq, Show)

#
ShowFilter

pub(all) enum ShowFilter {
Like(String)
Where(Expr)
} derive(Eq, Show)

#
ShowStmt

pub(all) struct ShowStmt {
show_type : ShowType
object : ObjectName?
filter : ShowFilter?
extended : Bool
full : Bool
global_scope : Bool
} derive(Eq, Show)

MySQL SHOW statement

#
ShowType

pub(all) enum ShowType {
Tables
Columns
Status
Databases
Schemas
Variables
Processlist
Grants
Functions
CreateTable
CreateView
CreateFunction
CreateProcedure
CreateEvent
CreateTrigger
} derive(Eq, Show)

#
Snowflake

pub(all) struct Snowflake {
}

Snowflake dialect - supports Snowflake specific syntax

#
SqliteOnConflict

pub(all) enum SqliteOnConflict {
Rollback
Abort
Fail
Ignore
Replace
} derive(Eq, Show)

SQLite-style conflict resolution for INSERT statements See: https://sqlite.org/lang_conflict.html

#
Statement

pub(all) enum Statement {
Query(QueryStmt)
CreateTable(CreateTableStmt)
CreateView(CreateViewStmt)
CreateIndex(CreateIndexStmt)
CreateDatabase(CreateDatabaseStmt)
CreateSchema(CreateSchemaStmt)
CreateFunction(CreateFunctionStmt)
CreateProcedure(CreateProcedureStmt)
CreateSequence(CreateSequenceStmt)
DropView(DropViewStmt)
DropTable(DropTableStmt)
DropIndex(DropIndexStmt)
Insert(InsertStmt)
Delete(DeleteStmt)
Update(UpdateStmt)
Merge(MergeStmt)
Truncate(TruncateStmt)
AlterTable(AlterTableStmt)
AlterIndex(AlterIndexStmt)
Show(ShowStmt)
Set(SetStmt)
Use(UseStmt)
Copy(CopyStmt)
LoadData(LoadDataStmt)
Prepare(PrepareStmt)
Execute(ExecuteStmt)
Deallocate(DeallocateStmt)
LockTables(Array[ObjectName])
UnlockTables
Listen(String)
Notify(String, String?)
Begin(BeginStmt)
Commit(CommitStmt)
Rollback(RollbackStmt)
Savepoint(SavepointStmt)
ReleaseSavepoint(ReleaseSavepointStmt)
Grant(GrantStmt)
Revoke(RevokeStmt)
} derive(Eq, Show)

#
Statements

pub(all) struct Statements {
stmts : Array[Statement]
} derive(Eq, Show)

#
Statements::op_get

fn Statements::op_get(self : Statements, index : Int) -> Statement

#
Subscript

pub(all) enum Subscript {
Index(Expr)
Slice(Expr?, Expr?, Expr?)
} derive(Eq, Show)

Subscript expression for array indexing and slicing

#
TableAlias

pub(all) struct TableAlias {
name : String
columns : Array[String]
} derive(Eq, Show)

#
TableConstraint

pub(all) enum TableConstraint {
Unique(Array[OrderByExpr])
PrimaryKey(Array[OrderByExpr])
ForeignKey(Array[OrderByExpr], ObjectName, Array[String])
Check(Expr)
} derive(Eq, Show)

#
TableFactor

pub(all) enum TableFactor {
Column(ObjectName, TableAlias?)
SubQuery(QueryStmt, TableAlias?)
} derive(Eq, Show)

#
TableRef

pub(all) struct TableRef {
factor : TableFactor
joins : Array[Join]
} derive(Eq, Show)

#
Token

pub(all) enum Token {
Keyword(Keyword)
Identifier(String)
Number(String)
StringLiteral(String)
Boolean(Bool)
Comma
Semicolon
Colon
Eq
DoubleEq
Neq
Lt
Gt
LtEq
GtEq
Spaceship
Plus
Minus
Mul
Div
Mod
LBracket
RBracket
LBrace
RBrace
LParen
RParen
Period
Placeholder(String)
JsonExtract
JsonExtractText
JsonExtractPath
JsonExtractPathText
JsonContains
JsonContainedIn
Unknown(Char)
Eof
} derive(Eq, Show)

#
Top

pub(all) enum Top {
Constant(Int)
Expr(Expr)
} derive(Eq, Show)

#
TruncateStmt

pub(all) struct TruncateStmt {
table_name : ObjectName
} derive(Eq, Show)

#
UnaryOperator

pub(all) enum UnaryOperator {
Plus
Minus
Not
} derive(Eq, Show)

#
UpdateStmt

pub(all) struct UpdateStmt {
table_name : ObjectName
assignments : Array[Assignment]
where_clause : Expr?
} derive(Eq, Show)

#
UseStmt

pub(all) struct UseStmt {
database_name : ObjectName
} derive(Eq, Show)

USE database statement for database switching

#
ViewColumnDef

pub(all) struct ViewColumnDef {
name : String
} derive(Eq, Show)

#
WindowFrameBound

pub(all) enum WindowFrameBound {
UnboundedPreceding
UnboundedFollowing
CurrentRow
Preceding(Expr)
Following(Expr)
} derive(Eq, Show)

#
WindowFrameClause

pub(all) struct WindowFrameClause {
frame_units : WindowFrameUnits
frame_start : WindowFrameBound
frame_end : WindowFrameBound?
} derive(Eq, Show)

#
WindowFrameUnits

pub(all) enum WindowFrameUnits {
Rows
Range
} derive(Eq, Show)

Window frame units

#
WindowSpec

pub(all) struct WindowSpec {
partition_by : Array[Expr]
order_by : Array[OrderByExpr]
frame_clause : WindowFrameClause?
} derive(Eq, Show)

Window function specification: OVER ([PARTITION BY ...] [ORDER BY ...] [frame_clause])

#
parse

fn parse(tokens : ArrayView[Token], dialect? : &Dialect) -> Array[Statement] raise ParserError

#
parse_sql

fn parse_sql(dialect? : &Dialect, input : String) -> Statements raise SqlParserError

#
pretty_print

fn[T :
Pretty
] pretty_print(obj : T) -> String

#
structural_print

fn[T : Show] structural_print(obj : T) -> String

#
tokenize

fn tokenize(dialect? : &Dialect, input : String) -> Array[Token] raise LexerError