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

Link to this function

limit(map, limit)

Specs

limit(Map.t(), String.t()) :: Map.t()
limit(Map.t(), integer()) :: Map.t()

Return the Map for query building.

example

iex(4)> Blanton.Query.limit(%{}, 10) %{limit: 10}

Link to this function

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

Link to this function

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"]}

Link to this function

run(map, project_id \\ Application.get_env(:blanton, :project_id))

Specs

table(String.t()) :: Map.t()

Returns the Map to use when searching

example

table("users")

iex(5)> Query.table("users") %{table: "users"}

Link to this function

to_records(response)

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

Link to this function

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: "優木せつ菜"]}