Creatio.OData.Query (creatio v0.3.1)

Copy Markdown

Composable query builder for Creatio OData 4 requests.

Supports $select, $filter, $orderby, $top, $skip, $expand, and $count. Provides chainable filter helpers for standard OData functions and operators (eq, ne, gt, ge, lt, le, contains, startswith, endswith, day, length, not, in).

Examples

query =
  Creatio.OData.Query.new("Contact")
  |> Creatio.OData.Query.select(["Id", "Name", "Email"])
  |> Creatio.OData.Query.filter_eq("Active", true)
  |> Creatio.OData.Query.filter_contains("Name", "Smith")
  |> Creatio.OData.Query.order_by("Name asc")
  |> Creatio.OData.Query.top(25)
  |> Creatio.OData.Query.skip(50)
  |> Creatio.OData.Query.expand("Account")
  |> Creatio.OData.Query.count()

{:ok, records} = Creatio.OData.execute(client, query)

Summary

Functions

Combines an additional filter expression with and.

Toggles whether to request total inline count ($count=true).

Specifies navigation properties to expand ($expand). Can be called multiple times to accumulate properties.

Specifies or replaces the filter expression ($filter).

Adds an OData 4 string contains condition (contains({field}, '{value}')).

Adds an OData day date function condition (day({field}) {op} {value}).

Adds an OData string endswith condition (endswith({field}, '{value}')).

Adds an equality condition ({field} eq {value}). Literals (numbers, booleans, null) are formatted automatically without quotes. Pass quoted: false for unquoted GUIDs / IDs.

Adds a greater-than-or-equal condition ({field} ge {value}).

Adds a greater-than condition ({field} gt {value}).

Adds a GUID equality condition ({field} eq {guid}). In OData 4, GUIDs are unquoted literals. In OData 3 (pass protocol: :odata3 or odata3: true), GUIDs are formatted as guid'{guid}'.

Builds an OData filter condition checking if a field equals any of a list of values. Since Creatio OData 4 does not support the in operator, this constructs (Field eq 'v1' or Field eq 'v2').

Builds an OData filter condition for a list of UUID / GUID primary keys. Since GUIDs in OData 4 are unquoted literals, this formats as (Id eq uuid1 or Id eq uuid2).

Adds a less-than-or-equal condition ({field} le {value}).

Adds an OData length string function condition (length({field}) {op} {value}).

Adds a less-than condition ({field} lt {value}).

Adds an inequality condition ({field} ne {value}).

Negates the current filter (not ({current})) or an explicitly provided expression.

Adds an OData string startswith condition (startswith({field}, '{value}')).

Initializes a new query for an entity collection.

Combines an additional filter expression with or.

Adds an OData 4 string contains condition combined with or.

Adds an OData day date function condition combined with or (day({field}) {op} {value}).

Adds an OData string endswith condition combined with or.

Adds an equality condition combined with or ({field} eq {value}).

Adds a greater-than-or-equal condition combined with or ({field} ge {value}).

Adds a greater-than condition combined with or ({field} gt {value}).

Adds a GUID equality condition combined with or ({field} eq {guid}).

Builds an OData filter condition checking if a field equals any of a list of values, combined with or.

Adds a less-than-or-equal condition combined with or ({field} le {value}).

Adds an OData length string function condition combined with or (length({field}) {op} {value}).

Adds a less-than-or-equal condition combined with or ({field} lt {value}).

Adds an inequality condition combined with or ({field} ne {value}).

Adds an OData string startswith condition combined with or.

Combines an additional filter expression with or. Alias for or_filter/2.

Specifies the ordering clause ($orderby). Accepts a string, atom, keyword list (e.g. [Name: :asc, CreatedOn: :desc]), or list of strings. Can be called multiple times to append ordering clauses.

Specifies the ordering clause with a field and direction (e.g. order_by(query, :Name, :asc)).

Adds an arbitrary custom query parameter.

Specifies the fields to retrieve ($select). Can be called multiple times to accumulate fields.

Specifies number of records to skip ($skip).

Serializes the query into a map of query parameters ready for the HTTP request.

Returns the URL query string representation for the query.

Specifies maximum records to return ($top).

Combines an additional filter expression with and. Alias for and_filter/2.

Types

t()

@type t() :: %Creatio.OData.Query{
  count: boolean(),
  custom_params: map(),
  entity: String.t(),
  expand: [String.t()] | String.t() | nil,
  filter: String.t() | nil,
  orderby: [String.t()] | String.t() | nil,
  select: [String.t()] | String.t() | nil,
  skip: integer() | nil,
  top: integer() | nil
}

Functions

and_filter(query, filter_expr)

@spec and_filter(t(), String.t()) :: t()

Combines an additional filter expression with and.

count(query, enabled? \\ true)

@spec count(t(), boolean()) :: t()

Toggles whether to request total inline count ($count=true).

expand(query, nav_props)

@spec expand(t(), [String.t() | atom()] | String.t() | atom()) :: t()

Specifies navigation properties to expand ($expand). Can be called multiple times to accumulate properties.

filter(query, filter_expr)

@spec filter(t(), String.t()) :: t()

Specifies or replaces the filter expression ($filter).

filter_contains(query, field, value)

@spec filter_contains(t(), String.t() | atom(), any()) :: t()

Adds an OData 4 string contains condition (contains({field}, '{value}')).

filter_day(query, field, day_value, op \\ "eq")

@spec filter_day(t(), String.t() | atom(), any(), String.t()) :: t()

Adds an OData day date function condition (day({field}) {op} {value}).

filter_endswith(query, field, value)

@spec filter_endswith(t(), String.t() | atom(), any()) :: t()

Adds an OData string endswith condition (endswith({field}, '{value}')).

filter_eq(query, field, value, opts \\ [])

@spec filter_eq(t(), String.t() | atom(), any(), keyword()) :: t()

Adds an equality condition ({field} eq {value}). Literals (numbers, booleans, null) are formatted automatically without quotes. Pass quoted: false for unquoted GUIDs / IDs.

filter_ge(query, field, value, opts \\ [])

@spec filter_ge(t(), String.t() | atom(), any(), keyword()) :: t()

Adds a greater-than-or-equal condition ({field} ge {value}).

filter_gt(query, field, value, opts \\ [])

@spec filter_gt(t(), String.t() | atom(), any(), keyword()) :: t()

Adds a greater-than condition ({field} gt {value}).

filter_guid(query, field, guid, opts \\ [])

@spec filter_guid(t(), String.t() | atom(), any(), keyword()) :: t()

Adds a GUID equality condition ({field} eq {guid}). In OData 4, GUIDs are unquoted literals. In OData 3 (pass protocol: :odata3 or odata3: true), GUIDs are formatted as guid'{guid}'.

filter_in(query, field, values, opts \\ [])

@spec filter_in(t(), String.t() | atom(), [any()], keyword()) :: t()

Builds an OData filter condition checking if a field equals any of a list of values. Since Creatio OData 4 does not support the in operator, this constructs (Field eq 'v1' or Field eq 'v2').

Options

  • :quoted - boolean indicating whether to wrap values in single quotes (default true).

filter_in_ids(query, field, ids)

@spec filter_in_ids(t(), String.t() | atom(), [any()]) :: t()

Builds an OData filter condition for a list of UUID / GUID primary keys. Since GUIDs in OData 4 are unquoted literals, this formats as (Id eq uuid1 or Id eq uuid2).

filter_le(query, field, value, opts \\ [])

@spec filter_le(t(), String.t() | atom(), any(), keyword()) :: t()

Adds a less-than-or-equal condition ({field} le {value}).

filter_length(query, field, len_value, op \\ "eq")

@spec filter_length(t(), String.t() | atom(), any(), String.t()) :: t()

Adds an OData length string function condition (length({field}) {op} {value}).

filter_lt(query, field, value, opts \\ [])

@spec filter_lt(t(), String.t() | atom(), any(), keyword()) :: t()

Adds a less-than condition ({field} lt {value}).

filter_ne(query, field, value, opts \\ [])

@spec filter_ne(t(), String.t() | atom(), any(), keyword()) :: t()

Adds an inequality condition ({field} ne {value}).

filter_not(query, expr \\ nil)

@spec filter_not(t(), String.t() | nil) :: t()

Negates the current filter (not ({current})) or an explicitly provided expression.

filter_startswith(query, field, value)

@spec filter_startswith(t(), String.t() | atom(), any()) :: t()

Adds an OData string startswith condition (startswith({field}, '{value}')).

new(entity)

@spec new(String.t()) :: t()

Initializes a new query for an entity collection.

or_filter(query, filter_expr)

@spec or_filter(t(), String.t()) :: t()

Combines an additional filter expression with or.

or_filter_contains(query, field, value)

@spec or_filter_contains(t(), String.t() | atom(), any()) :: t()

Adds an OData 4 string contains condition combined with or.

or_filter_day(query, field, day_value, op \\ "eq")

@spec or_filter_day(t(), String.t() | atom(), any(), String.t()) :: t()

Adds an OData day date function condition combined with or (day({field}) {op} {value}).

or_filter_endswith(query, field, value)

@spec or_filter_endswith(t(), String.t() | atom(), any()) :: t()

Adds an OData string endswith condition combined with or.

or_filter_eq(query, field, value, opts \\ [])

@spec or_filter_eq(t(), String.t() | atom(), any(), keyword()) :: t()

Adds an equality condition combined with or ({field} eq {value}).

or_filter_ge(query, field, value, opts \\ [])

@spec or_filter_ge(t(), String.t() | atom(), any(), keyword()) :: t()

Adds a greater-than-or-equal condition combined with or ({field} ge {value}).

or_filter_gt(query, field, value, opts \\ [])

@spec or_filter_gt(t(), String.t() | atom(), any(), keyword()) :: t()

Adds a greater-than condition combined with or ({field} gt {value}).

or_filter_guid(query, field, guid, opts \\ [])

@spec or_filter_guid(t(), String.t() | atom(), any(), keyword()) :: t()

Adds a GUID equality condition combined with or ({field} eq {guid}).

or_filter_in(query, field, values, opts \\ [])

@spec or_filter_in(t(), String.t() | atom(), [any()], keyword()) :: t()

Builds an OData filter condition checking if a field equals any of a list of values, combined with or.

or_filter_le(query, field, value, opts \\ [])

@spec or_filter_le(t(), String.t() | atom(), any(), keyword()) :: t()

Adds a less-than-or-equal condition combined with or ({field} le {value}).

or_filter_length(query, field, len_value, op \\ "eq")

@spec or_filter_length(t(), String.t() | atom(), any(), String.t()) :: t()

Adds an OData length string function condition combined with or (length({field}) {op} {value}).

or_filter_lt(query, field, value, opts \\ [])

@spec or_filter_lt(t(), String.t() | atom(), any(), keyword()) :: t()

Adds a less-than-or-equal condition combined with or ({field} lt {value}).

or_filter_ne(query, field, value, opts \\ [])

@spec or_filter_ne(t(), String.t() | atom(), any(), keyword()) :: t()

Adds an inequality condition combined with or ({field} ne {value}).

or_filter_startswith(query, field, value)

@spec or_filter_startswith(t(), String.t() | atom(), any()) :: t()

Adds an OData string startswith condition combined with or.

or_where(query, filter_expr)

@spec or_where(t(), String.t()) :: t()

Combines an additional filter expression with or. Alias for or_filter/2.

order_by(query, order_expr)

@spec order_by(t(), [String.t() | atom() | tuple()] | String.t() | atom()) :: t()

Specifies the ordering clause ($orderby). Accepts a string, atom, keyword list (e.g. [Name: :asc, CreatedOn: :desc]), or list of strings. Can be called multiple times to append ordering clauses.

order_by(query, field, direction)

@spec order_by(t(), String.t() | atom(), String.t() | atom()) :: t()

Specifies the ordering clause with a field and direction (e.g. order_by(query, :Name, :asc)).

param(query, key, value)

@spec param(t(), String.t() | atom(), any()) :: t()

Adds an arbitrary custom query parameter.

select(query, fields)

@spec select(t(), [String.t() | atom()] | String.t() | atom()) :: t()

Specifies the fields to retrieve ($select). Can be called multiple times to accumulate fields.

skip(query, n)

@spec skip(t(), non_neg_integer()) :: t()

Specifies number of records to skip ($skip).

to_params(query)

@spec to_params(t()) :: map()

Serializes the query into a map of query parameters ready for the HTTP request.

to_query_string(query)

@spec to_query_string(t()) :: String.t()

Returns the URL query string representation for the query.

top(query, n)

@spec top(t(), non_neg_integer()) :: t()

Specifies maximum records to return ($top).

where(query, filter_expr)

@spec where(t(), String.t()) :: t()

Combines an additional filter expression with and. Alias for and_filter/2.

where_eq(query, field, value, opts \\ [])

Alias for filter_eq/4.