I decided a fun little project would be a SQL generator. I found Gleam's type system to be so good.
pub fn main() {
let users = Field("users", _)
let companies = Field("companies", _)
let query =
Query("users", [
Select([
users("id"),
users("name"),
users("first_name"),
users("last_name"),
]),
Where(users("id"), Eq, Value("3")),
Join(users("company_id"), companies("id")),
Offset(0),
Limit(20),
])
io.println(to_sql(query))
}
SELECT users.id, users.name, users.first_name, users.last_name FROM users
WHERE users.id == 3
JOIN users.company_id ON companies.id
WHERE users.company_id = companies.id
OFFSET 0
LIMIT 20
You really hit a homerun on the type system. It's simple but flexible. Love this!