Exact.Query (exact_online v0.1.0)

Copy Markdown View Source

Builds the OData query parameters Exact Online understands.

The high level functions accept these options and translate them into the $-prefixed parameters:

  • :select - a list of field names or a string
  • :filter - an OData filter string, see the escaping helpers below
  • :top - maximum number of records in the page
  • :skip - number of records to skip
  • :orderby - a list of field names or a string
  • :expand - a list of navigation properties or a string
  • :inlinecount - set to "allpages" to get a __count in the response
  • :params - extra parameters merged as-is

$filter is picky about literals. Use the helpers instead of interpolating:

iex> Exact.Query.string("O'Brien & co")
"'O''Brien & co'"

iex> Exact.Query.guid("11111111-2222-3333-4444-555555555555")
"guid'11111111-2222-3333-4444-555555555555'"

iex> Exact.Query.datetime(~U[2026-01-31 12:00:00Z])
"datetime'2026-01-31T12:00:00'"

Summary

Functions

Formats a datetime literal for use in $filter.

Turns query options into a keyword list of request parameters.

Formats a GUID literal for use in $filter or a key predicate.

Escapes a string literal for use in $filter.

Functions

datetime(date)

@spec datetime(DateTime.t() | NaiveDateTime.t() | Date.t()) :: String.t()

Formats a datetime literal for use in $filter.

Exact Online expects a naive, second precision timestamp without a zone suffix, so the value is converted to UTC and truncated.

encode(opts)

@spec encode(keyword()) :: keyword()

Turns query options into a keyword list of request parameters.

Unknown options are ignored so the same option list can be passed straight through from a resource function.

iex> Exact.Query.encode(select: ["ID", "Name"], top: 10)
[{:"$select", "ID,Name"}, {:"$top", 10}]

guid(value)

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

Formats a GUID literal for use in $filter or a key predicate.

string(value)

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

Escapes a string literal for use in $filter.

Single quotes are doubled, which is how OData escapes them.