Skip to content
jonifreeman edited this page Oct 19, 2012 · 16 revisions

Phases

The sqltyped macro is a minicompiler which takes SQL string as an input and outputs Scala AST.

Phases

Phase 1: parse SQL

Compilation starts by parsing a SQL statement. Successful parsing produces Statement[Option[String]]. Statement is internally used data type for SQL AST and is parameterized by type of table references in column definitions. For instance, in a statement SELECT name, p.age from person p column name has a table reference None, and column age has a table reference Some("p").

    SqlParser.parse(sql: String): ?[Statement[Option[String]]

Phase 2: resolve tables

Next phase resolves all table references to point to a concrete table. For instance, in a statement SELECT name, p.age from person p both columns reference a table Table("person").

    Ast.resolveTables(stmt: Statement[Option[String]]): ?[Statement[Table]]

Phase 3: type AST

    Typer.infer(stmt: Ast.Statement[Table], useInputTags: Boolean): ?[TypedStatement]

Phase 4: analyze AST

    Analyzer.refine(stmt: TypedStatement): ?[TypedStatement]

Phase 5: code generation

Dialects

Clone this wiki locally