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

Link to this function

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.

Link to this function

exec(s, pool \\ Monet)

Link to this function

exec!(s, pool \\ Monet)

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 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

Link to this function

join(s, atom, table)

Link to this function

limit(s, limit)

Link to this function

offset(s, offset)

Link to this function

order(s, order)

Link to this function

order(s, order, bool)

Link to this function

where(q, column, atom, value)

Link to this macro

where_and(q, fun)

(macro)
Link to this function

where_ignore_nil(q, column, op, value)

Link to this macro

where_or(q, fun)

(macro)