monet v0.0.9 Monet.Query.Select
A simple query builder.
rows = Select.new()
|> Select.columns("u.id, u.name")
|> Select.from("users u")
|> Select.join("roles r on u.role_id = r.id")
|> Select.where("u.power", :gt, 9000)
|> Select.limit(100)
|> Select.exec!() // returns a Monet.Result
|> Monet.rows()
Link to this section Summary
Functions
Columns to select. If not called, will select *.
Can can called multiple times. Can be called with an array, or a string.
This can really be anything and it's best to think of it as the test that
is placed between the select
and the `from.
Table to select from. Can be called multiple times. This essentially becomes what gets placed between the "from" and the "where".
Join tables. There's no magic here. Doesn't know anything about your tables (aka, you need to tell it what to join on)
Link to this section Functions
columns(q, column)
Columns to select. If not called, will select *.
Can can called multiple times. Can be called with an array, or a string.
This can really be anything and it's best to think of it as the test that
is placed between the select
and the `from.
exec(s, pool \\ Monet)
exec!(s, pool \\ Monet)
from(s, from)
Table to select from. Can be called multiple times. This essentially becomes what gets placed between the "from" and the "where".
You could do:
Select.from(s, "users")
# OR
Select.from(s, "(select 1 from another) x")
join(s, table)
Join tables. There's no magic here. Doesn't know anything about your tables (aka, you need to tell it what to join on):
Select.join(s, "table b on a.id = b.id")
This is just a shorthand for from/2
but it injects the word
" [left|right|full]? join " for you