Socrata v2.0.0 Socrata.Query View Source

Queries are the building blocks for finding the data you need in Socrata. This module provides you with a simple struct to define SODA queries.

All of the filters and query operators defined in the Socrata filter docs and in the Socrata SoQL docs are implemented here. Each function composes a base query.

Link to this section Summary

Functions

Adds a SoQL $$bom=true directive to the query

Adds a simple field filter to the query

Adds a SoQL $group filter to the query

Adds a SoQL $having filter to the query

Adds a SoQL $limit filter to the query

Creates a new query struct from a keywrod list

Creates a new query struct from positional fourby and domain arguments

Adds a SoQL $offset filter to the query

Adds a SoQL $order filter to the query

Adds a SoQL $q filter to the query

Adds a SoQL $query filter to the query

Adds a SoQL $select filter to the query

Adds a SoQL $where filter to the query

Link to this section Types

Link to this type t() View Source
t() :: %Socrata.Query{domain: String.t(), fourby: String.t(), state: map()}

Link to this section Functions

Adds a SoQL $$bom=true directive to the query.

See the general Socrata SoQL docs and the bom specific docs for more info.

Example

iex> alias Socrata.Query, as: Q
iex> Q.new("asdf-asdf", "example.com") |> Q.ensure_bom()
%Socrata.Query{fourby: "asdf-asdf", domain: "example.com", state: %{"$$bom" => true}}

Adds a simple field filter to the query.

See the Socrata simple filters docs for more info.

Example

iex> alias Socrata.Query, as: Q
iex> Q.new("asdf-asdf", "example.com") |> Q.filter("name", "whatever")
%Socrata.Query{fourby: "asdf-asdf", domain: "example.com", state: %{"name" => "whatever"}}

Adds a SoQL $group filter to the query.

See the general Socrata SoQL docs and the group specific docs for more info.

Example

iex> alias Socrata.Query, as: Q
iex> Q.new("asdf-asdf", "example.com") |> Q.select(["location", "SUM(attendees)"]) |> Q.group("location")
%Socrata.Query{fourby: "asdf-asdf", domain: "example.com", state: %{"$select" => "location, SUM(attendees)", "$group" => "location"}}

Adds a SoQL $having filter to the query.

See the general Socrata SoQL docs and the having specific docs for more info.

Example

iex> alias Socrata.Query, as: Q
iex> Q.new("asdf-asdf", "example.com") |> Q.select(["location", "SUM(attendees) as count"]) |> Q.group("location") |> Q.having("count > 500")
%Socrata.Query{fourby: "asdf-asdf", domain: "example.com", state: %{"$select" => "location, SUM(attendees) as count", "$group" => "location", "$having" => "count > 500"}}

Adds a SoQL $limit filter to the query.

See the general Socrata SoQL docs and the limit specific docs for more info.

Example

iex> alias Socrata.Query, as: Q
iex> Q.new("asdf-asdf", "example.com") |> Q.limit(10)
%Socrata.Query{fourby: "asdf-asdf", domain: "example.com", state: %{"$limit" => 10}}

Creates a new query struct from a keywrod list.

Example

iex> alias Socrata.Query, as: Q
iex> Q.new(fourby: "asdf-asdf", domain: "example.com")
%Socrata.Query{fourby: "asdf-asdf", domain: "example.com", state: %{}}

Creates a new query struct from positional fourby and domain arguments.

Example

iex> alias Socrata.Query, as: Q
iex> Q.new("asdf-asdf", "example.com")
%Socrata.Query{fourby: "asdf-asdf", domain: "example.com", state: %{}}

Adds a SoQL $offset filter to the query.

See the general Socrata SoQL docs and the offset specific docs for more info.

Example

iex> alias Socrata.Query, as: Q
iex> Q.new("asdf-asdf", "example.com") |> Q.limit(5) |> Q.offset(10)
%Socrata.Query{fourby: "asdf-asdf", domain: "example.com", state: %{"$limit" => 5, "$offset" => 10}}

Adds a SoQL $order filter to the query.

See the general Socrata SoQL docs and the order specific docs for more info.

Example

iex> alias Socrata.Query, as: Q
iex> Q.new("asdf-asdf", "example.com") |> Q.order("name ASC")
%Socrata.Query{fourby: "asdf-asdf", domain: "example.com", state: %{"$order" => "name ASC"}}

Adds a SoQL $q filter to the query.

See the general Socrata SoQL docs and the q specific docs for more info.

Example

iex> alias Socrata.Query, as: Q
iex> Q.new("asdf-asdf", "example.com") |> Q.q("a bag of words")
%Socrata.Query{fourby: "asdf-asdf", domain: "example.com", state: %{"$q" => "a bag of words"}}

Adds a SoQL $query filter to the query.

See the general Socrata SoQL docs and the query specific docs for more info.

Example

iex> alias Socrata.Query, as: Q
iex> Q.new("asdf-asdf", "example.com") |> Q.query("SELECT name, location, SUM(attendees) as count GROUP BY location HAVING count > 500")
%Socrata.Query{fourby: "asdf-asdf", domain: "example.com", state: %{"$query" => "SELECT name, location, SUM(attendees) as count GROUP BY location HAVING count > 500"}}

Adds a SoQL $select filter to the query.

See the general Socrata SoQL docs and the select specific docs for more info.

Example

iex> alias Socrata.Query, as: Q
iex> Q.new("asdf-asdf", "example.com") |> Q.select(~w|name location|)
%Socrata.Query{fourby: "asdf-asdf", domain: "example.com", state: %{"$select" => "name, location"}}

Adds a SoQL $where filter to the query.

See the general Socrata SoQL docs and the where specific docs for more info.

Example

iex> alias Socrata.Query, as: Q
iex> Q.new("asdf-asdf", "example.com") |> Q.where("height >= 1000")
%Socrata.Query{fourby: "asdf-asdf", domain: "example.com", state: %{"$where" => "height >= 1000"}}