blanton v0.2.2 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

Extract records from Bigquery API response

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)

Extract records from Bigquery API response

example

iex(1)> %GoogleApi.BigQuery.V2.Model.QueryResponse{ rows: [

%GoogleApi.BigQuery.V2.Model.TableRow{
  f: [
    %GoogleApi.BigQuery.V2.Model.TableCell{v: "桜坂しずく"},
    %GoogleApi.BigQuery.V2.Model.TableCell{v: "shizuku@nijigaku.com"}
  ]
},
%GoogleApi.BigQuery.V2.Model.TableRow{
  f: [
    %GoogleApi.BigQuery.V2.Model.TableCell{v: "中須かすみ"},
    %GoogleApi.BigQuery.V2.Model.TableCell{v: "kasmin@nijigaku.com"}
  ]
}

], schema: %GoogleApi.BigQuery.V2.Model.TableSchema{

fields: [
  %GoogleApi.BigQuery.V2.Model.TableFieldSchema{name: "id"},
  %GoogleApi.BigQuery.V2.Model.TableFieldSchema{name: "email"}
]

} } |> Blanton.Query.to_records()

[ %{"email" => "shizuku@nijigaku.com", "id" => "桜坂しずく"}, %{"email" => "kasmin@nijigaku.com", "id" => "中須かすみ"} ]

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