June 2018
Intermediate to advanced
310 pages
6h 32m
English
In this section, we'll define a simple DSL-for-SQL language. We won't define the format or grammar for it, but only an example of what it should look like:
val sql = select("name, age", { from("users", { where("age > 25") }) // Closes from }) // Closes selectprintln(sql) // "SELECT name, age FROM users WHERE age > 25"
The goal of our language is to improve readability and prevent some common SQL mistakes, such as typos (like FORM instead of FROM). We'll get compile time validations and autocompletion along the way.
We'll start with the easiest part—select:
fun select(columns: String, from: SelectClause.()->Unit): SelectClause { return SelectClause(columns).apply(from)}
Read now
Unlock full access