View Source Appwrite.Utils.Query (appwrite v0.2.1)
Builds Appwrite query strings for filtering, sorting, selecting, and paginating database documents.
Every function returns a JSON-encoded string ready to pass in the
queries list of any listing call.
Quick reference
alias Appwrite.Utils.Query
Query.equal("status", "active")
Query.between("age", 18, 65)
Query.order_desc("created_at")
Query.limit(20)
Query.cursor_after("doc_abc")
Query.select(["title", "body"])
# Logical nesting
Query.logical_or([Query.equal("role", "admin"), Query.equal("role", "owner")])or / and are reserved
Elixir reserves or and and as keywords, so the logical combinators are
named logical_or/1 and logical_and/1.
Summary
Functions
Match documents where start_value <= attribute <= end_value (inclusive).
Match documents where attribute contains value (string or array attribute).
Return documents after the given document ID (cursor-based pagination).
Return documents before the given document ID.
Match documents where attribute ends with value.
Match documents where attribute equals value (scalar or list).
Match documents where attribute > value.
Match documents where attribute >= value.
Match documents where attribute < value.
Match documents where attribute <= value.
Return at most limit documents.
Combine queries with logical AND.
Combine queries with logical OR.
Low-level query constructor.
Match documents where attribute is not equal to value.
Match documents where attribute is not null.
Match documents where attribute is null.
Skip the first offset documents.
Sort results by attribute ascending.
Sort results by attribute descending.
Full-text search on attribute for value.
Return only the listed attribute names in each document.
Match documents where attribute starts with value.
Types
Functions
Match documents where start_value <= attribute <= end_value (inclusive).
Match documents where attribute contains value (string or array attribute).
Return documents after the given document ID (cursor-based pagination).
Return documents before the given document ID.
Match documents where attribute ends with value.
@spec equal(String.t(), query_value()) :: t()
Match documents where attribute equals value (scalar or list).
@spec greater_than(String.t(), query_value()) :: t()
Match documents where attribute > value.
@spec greater_than_equal(String.t(), query_value()) :: t()
Match documents where attribute >= value.
@spec less_than(String.t(), query_value()) :: t()
Match documents where attribute < value.
@spec less_than_equal(String.t(), query_value()) :: t()
Match documents where attribute <= value.
@spec limit(non_neg_integer()) :: t()
Return at most limit documents.
Combine queries with logical AND.
Each element must be a query string produced by any function in this module.
Example
Query.logical_and([Query.equal("active", true), Query.greater_than("age", 18)])
Combine queries with logical OR.
Each element must be a query string produced by any function in this module.
Example
Query.logical_or([Query.equal("role", "admin"), Query.equal("role", "owner")])
@spec new(String.t(), String.t() | nil, query_value() | nil) :: t()
Low-level query constructor.
Builds a JSON query string from a method name, an optional attribute, and
optional values. nil fields are omitted from the output so the payload
stays minimal.
Examples
iex> Appwrite.Utils.Query.new("equal", "name", "John")
~s({"method":"equal","attribute":"name","values":["John"]})
iex> Appwrite.Utils.Query.new("limit", nil, 10)
~s({"method":"limit","values":[10]})
iex> Appwrite.Utils.Query.new("isNull", "deletedAt")
~s({"method":"isNull","attribute":"deletedAt"})
@spec not_equal(String.t(), query_value()) :: t()
Match documents where attribute is not equal to value.
Match documents where attribute is not null.
Match documents where attribute is null.
@spec offset(non_neg_integer()) :: t()
Skip the first offset documents.
Sort results by attribute ascending.
Sort results by attribute descending.
Full-text search on attribute for value.
Return only the listed attribute names in each document.
Match documents where attribute starts with value.