blanton v0.1.5 Blanton.Query
This module searches records
Usage
Query.table("users") |> Query.pluck(["name", "age"]) |> Query.where([age: 31]) |> Query.limit(10) |> Query.run |> Query.to_records
Link to this section Summary
Functions
Return the Map for query building.
Return the Map for query building.
Return the Map for query building.
Returns the Map to use when searching
Create SQL from Map
Return the Map for query building.
Link to this section Functions
limit(map, limit)
Specs
Return the Map for query building.
example
iex(4)> Blanton.Query.limit(%{}, 10) %{limit: 10}
order(map, order)
Return the Map for query building.
example
iex(1)> Blanton.Query.order(%{}, "age") %{order: "age"}
iex(2)> Blanton.Query.order(%{}, ["age", "name"]) %{order: ["age", "name"]}
iex(3)> Blanton.Query.order(%{}, [age: :DESC]) %{order: [age: :DESC]}
pluck(map, columns)
Specs
pluck(Map.t(), String.t()) :: Map.t()
Return the Map for query building.
example
iex(3)> Blanton.Query.pluck(%{}, ["name", "age"])
%{columns: ["name", "age"]}
run(map, project_id \\ Application.get_env(:blanton, :project_id))
table(table)
Specs
table(String.t()) :: Map.t()
Returns the Map to use when searching
example
table("users")
iex(5)> Query.table("users") %{table: "users"}
to_records(response)
to_sql(map)
Create SQL from Map
example
iex(1)> Blanton.Query.table("users") |> Blanton.Query.pluck(["name", "age"]) |> Blanton.Query.where([age: 31]) |> Blanton.Query.limit(10) |> Blanton.Query.to_sql
SELECT name, age FROM users WHERE age == '31' LIMIT 10""
where(map, where)
Specs
where(Map.t(), String.t()) :: Map.t()
Return the Map for query building.
example
iex(6)> Blanton.Query.where(%{}, [name: "優木せつ菜"])
%{where: [name: "優木せつ菜"]}