View Source Ravix.RQL.Query (ravix v0.6.3)
Detructurized Raven Query Language structure
Link to this section Summary
Functions
Adds an negated Ravix.RQL.Tokens.And
operation with a Ravix.RQL.Tokens.Condition
to the query
Adds an Ravix.RQL.Tokens.And
operation with a Ravix.RQL.Tokens.Condition
to the query
Executes the delete query in the informed session
Creates a new query for the informed collection or index
Creates a new query with an alias for the informed collection or index
Adds a Ravix.RQL.Tokens.Group
operation to the query
Adds a Ravix.RQL.Tokens.Limit
operation to the query
Executes the query in the informed session and returns the matched documents
Adds a negated Ravix.RQL.Tokens.Or
operation with a Ravix.RQL.Tokens.Condition
to the query
Adds an Ravix.RQL.Tokens.Or
operation with a Ravix.RQL.Tokens.Condition
to the query
Adds a Ravix.RQL.Tokens.Order
operation to the query
Create a Query using a raw RQL string
Create a Query using a raw RQL string with replaceable placeholders
Adds a select operation to project fields
Adds a select operation to project fields, leveraging the use of RavenDB Functions
Executes the query in the informed session and returns the matched documents
Adds an update operation to the informed query, it supports a
Ravix.RQL.Tokens.Update
token. The token can be created using the following functions
Executes the patch query in the informed session
Adds a where operation with a Ravix.RQL.Tokens.Condition
to the query
Link to this section Types
@type t() :: %Ravix.RQL.Query{ aliases: map(), and_tokens: [Ravix.RQL.Tokens.And.t()], from_token: Ravix.RQL.Tokens.From.t() | nil, group_token: Ravix.RQL.Tokens.Group.t() | nil, is_raw: boolean(), limit_token: Ravix.RQL.Tokens.Limit.t() | nil, or_tokens: [Ravix.RQL.Tokens.Or.t()], order_token: Ravix.RQL.Tokens.Order.t() | nil, params_count: non_neg_integer(), query_params: map(), query_string: String.t(), select_token: Ravix.RQL.Tokens.Select.t() | nil, update_token: Ravix.RQL.Tokens.Update.t() | nil, where_token: Ravix.RQL.Tokens.Where.t() | nil }
Link to this section Functions
@spec and_not(t(), Ravix.RQL.Tokens.Condition.t()) :: t()
Adds an negated Ravix.RQL.Tokens.And
operation with a Ravix.RQL.Tokens.Condition
to the query
Returns a Ravix.RQL.Query
with the and condition
examples
Examples
iex> from = Ravix.RQL.Query.from("cats", "c")
iex> where = Ravix.RQL.Query.where(from, equal_to("cat_name", "Meowvius"))
iex> and_v = Ravix.RQL.Query.and_not(where, equal_to("breed", "Fatto"))
@spec and?(t(), Ravix.RQL.Tokens.Condition.t()) :: t()
Adds an Ravix.RQL.Tokens.And
operation with a Ravix.RQL.Tokens.Condition
to the query
Returns a Ravix.RQL.Query
with the and condition
examples
Examples
iex> from = Ravix.RQL.Query.from("cats", "c")
iex> where = Ravix.RQL.Query.where(from, equal_to("cat_name", "Meowvius"))
iex> and_v = Ravix.RQL.Query.and?(where, equal_to("breed", "Fatto"))
Executes the delete query in the informed session
Returns a RavenDB response map
examples
Examples
iex> from("@all_docs")
|> where(equal_to("cat_name", any_entity.cat_name))
|> delete_for(session_id)
{:ok, %{"OperationId" => 2480, "OperationNodeTag" => "A"}}
Creates a new query for the informed collection or index
Returns a Ravix.RQL.Query
or an {:error, :query_document_must_be_informed}
if no collection/index was informed
examples
Examples
iex> Ravix.RQL.Query.from("test")
Creates a new query with an alias for the informed collection or index
Returns a Ravix.RQL.Query
or an {:error, :query_document_must_be_informed}
if no collection/index was informed
examples
Examples
iex> Ravix.RQL.Query.from("test", "t")
Adds a Ravix.RQL.Tokens.Group
operation to the query
Returns a Ravix.RQL.Query
with the group_by condition
examples
Examples
iex> from = Ravix.RQL.Query.from("cats", "c")
iex> grouped = Ravix.RQL.Query.group_by(from, "breed")
@spec limit(t(), non_neg_integer(), non_neg_integer()) :: t()
Adds a Ravix.RQL.Tokens.Limit
operation to the query
Returns a Ravix.RQL.Query
with the limit condition
examples
Examples
iex> from = Ravix.RQL.Query.from("cats", "c")
iex> limit = Ravix.RQL.Query.limit(from, 5, 10)
Executes the query in the informed session and returns the matched documents
Returns a RavenDB response map
examples
Examples
iex> from("Cats")
|> select("name")
|> where(equal_to("name", cat.name))
|> list_all(session_id)
{:ok, %{
"DurationInMs" => 62,
"IncludedPaths" => nil,
"Includes" => %{},
"IndexName" => "Auto/Cats/By@metadata.@last-modifiedAndidAndname",
"IndexTimestamp" => "2022-04-22T20:03:03.8373804",
"IsStale" => false,
"LastQueryTime" => "2022-04-22T20:03:04.3475275",
"LongTotalResults" => 1,
"NodeTag" => "A",
"ResultEtag" => 6489530344045176783,
"Results" => [
%{
"@metadata" => %{
"@change-vector" => "A:6445-HJrwf2z3c0G/FHJPm3zK3w",
"@id" => "beee79e2-2560-408c-a680-253e9bd7d12e",
"@index-score" => 3.079441547393799,
"@last-modified" => "2022-04-22T20:03:03.7477980Z",
"@projection" => true
},
"name" => "Lily"
}
],
"ScannedResults" => 0,
"SkippedResults" => 0,
"TotalResults" => 1
}
}
@spec or_not(t(), Ravix.RQL.Tokens.Condition.t()) :: t()
Adds a negated Ravix.RQL.Tokens.Or
operation with a Ravix.RQL.Tokens.Condition
to the query
Returns a Ravix.RQL.Query
with the and condition
examples
Examples
iex> from = Ravix.RQL.Query.from("cats", "c")
iex> where = Ravix.RQL.Query.where(from, equal_to("cat_name", "Meowvius"))
iex> or_v = Ravix.RQL.Query.or_not(where, equal_to("breed", "Fatto"))
@spec or?(t(), Ravix.RQL.Tokens.Condition.t()) :: t()
Adds an Ravix.RQL.Tokens.Or
operation with a Ravix.RQL.Tokens.Condition
to the query
Returns a Ravix.RQL.Query
with the and condition
examples
Examples
iex> from = Ravix.RQL.Query.from("cats", "c")
iex> where = Ravix.RQL.Query.where(from, equal_to("cat_name", "Meowvius"))
iex> or_v = Ravix.RQL.Query.or?(where, equal_to("breed", "Fatto"))
@spec order_by( t(), [Ravix.RQL.Tokens.Order.Field.t()] | Ravix.RQL.Tokens.Order.Field.t() ) :: t()
Adds a Ravix.RQL.Tokens.Order
operation to the query
Returns a Ravix.RQL.Query
with the ordering condition
examples
Examples
iex> from = Ravix.RQL.Query.from("cats", "c")
iex> ordered = Ravix.RQL.Query.order_by(from, [%Order.Field{name: "@metadata.@last-modified", order: :desc, type: :number}])
Create a Query using a raw RQL string
Returns a Ravix.RQL.Query
with the raw query
examples
Examples
iex> raw = Ravix.RQL.Query.raw("from @all_docs where cat_name = "Fluffers"")
Create a Query using a raw RQL string with replaceable placeholders
Returns a Ravix.RQL.Query
with the raw query and parameters
examples
Examples
iex> raw = Ravix.RQL.Query.raw("from @all_docs where cat_name = $p1", %{p1: "Fluffers"})
Adds a select operation to project fields
Returns a Ravix.RQL.Query
with the select condition
examples
Examples
iex> from = Ravix.RQL.Query.from("cats", "c")
iex> select = Ravix.RQL.Query.select(from, ["name", "breed"])
Adds a select operation to project fields, leveraging the use of RavenDB Functions
Returns a Ravix.RQL.Query
with the select condition
examples
Examples
iex> from = Ravix.RQL.Query.from("cats", "c")
iex> select = Ravix.RQL.Query.select_function(from, ooga: "c.name")
Executes the query in the informed session and returns the matched documents
Returns a RavenDB response map
examples
Examples
iex> stream = from("Cats")
|> select("name")
|> where(equal_to("name", cat.name))
|> stream_all(session_id)
stream |> Enum.to_list()
[
%{
"@metadata" => %{
"@change-vector" => "A:6445-HJrwf2z3c0G/FHJPm3zK3w",
"@id" => "beee79e2-2560-408c-a680-253e9bd7d12e",
"@index-score" => 3.079441547393799,
"@last-modified" => "2022-04-22T20:03:03.7477980Z",
"@projection" => true
},
"name" => "Lily"
}
]
@spec update(t(), Ravix.RQL.Tokens.Update.t()) :: t()
Adds an update operation to the informed query, it supports a
Ravix.RQL.Tokens.Update
token. The token can be created using the following functions:
Ravix.RQL.Tokens.Update.set(%Update{}, field, new_value)
to set values
Ravix.RQL.Tokens.Update.inc(%Update{}, field, value_to_inc)
to inc values
Ravix.RQL.Tokens.Update.dec(%Update{}, field, value_to_dec)
to dec values
Returns a Ravix.RQL.Query
with the update operation
examples
Examples
iex> from = Ravix.RQL.Query.from("cats", "c")
iex> update = Ravix.RQL.Query.update(from, set(%Update{}, :cat_name, "Fluffer, the hand-ripper"))
Executes the patch query in the informed session
Returns a RavenDB response map
examples
Examples
iex> from("@all_docs", "a")
|> update(set(%Update{}, :cat_name, "Fluffer, the hand-ripper"))
|> where(equal_to("cat_name", any_entity.cat_name))
|> update_for(session_id)
{:ok, %{"OperationId" => 2480, "OperationNodeTag" => "A"}}
@spec where(t(), Ravix.RQL.Tokens.Condition.t()) :: t()
Adds a where operation with a Ravix.RQL.Tokens.Condition
to the query
Returns a Ravix.RQL.Query
with the where condition
examples
Examples
iex> from = Ravix.RQL.Query.from("cats", "c")
iex> where = Ravix.RQL.Query.where(from, equal_to("cat_name", "Meowvius"))