View Source Arke.Core.Query (Arke v1.1.33)

Struct which defines a Query

Link to this section Summary

Functions

Add a filter to a query

Get the query result ordered by specific criteria

Create a new Query

Define the limit of the query

Define the offset of the query

Link to this section Types

@type t() :: %Arke.Core.Query{
  arke: term(),
  filters: term(),
  limit: term(),
  link: term(),
  offset: term(),
  orders: term(),
  persistence: term(),
  project: term()
}

Link to this section Functions

Link to this function

add_filter(query, filter)

View Source

Add a filter to a query

parameters

Parameters

example

Example

iex> person = Arke.Core.Arke.new(id: :person, label: "Person")
...> query = Arke.Core.Query.new(person, :arke_system)
...> parameter = Arke.Boundary.ParameterManager.get(:id,:arke_system)
...> filter = Arke.Core.Query.new_filter(parameter,:eq, "name", false)
...> Arke.Core.Query.add_filter(query, filter)

return

Return

%Arke.Core.Query{... filters: [ %Arke.Core.Query.Filter{} ] ... }
Link to this function

add_filter(query, logic, negate, base_filters)

View Source

Add a filter to a query

parameters

Parameters

  • query => refer to new/1
  • logic => :and | :or => the logic of the filter

  • negate => boolean => used to figure out whether the condition is to be denied
  • base_filters

example

Example

iex> person = Arke.new(id: :person, label: "Person")
...> query = Arke.Core.Query.new(person, :arke_system)
...> parameter = Arke.Core.ParameterManager.get(:id,:arke_system)
...> Arke.Core.Query.add_filter(query, parameter, :eq, "name", false)

return

Return

 %Arke.Core.Query{... filters: [ %Arke.Core.Query.Filter{} ] ... }
Link to this function

add_filter(query, parameter, operator, value, negate)

View Source

Add a filter to a query

parameters

Parameters

  • query => refer to new/1
  • parameter
  • operator
  • value
  • negate

example

Example

iex> person = Arke.Core.Arke.new(id: :person, label: "Person")
...> query = Arke.Core.Query.new(person, :arke_system)
...> parameter = Arke.Boundary.ParameterManager.get(:id,:arke_system)
...> base_filter = Arke.Core.Query.new_base_filter(parameter, :eq, "name", false)
...> Arke.Core.Query.add_filter(query, :and, false, base_filter)

return

Return

 %Arke.Core.Query{... filters: [ %Arke.Core.Query.Filter{} ] ... }
Link to this function

add_order(query, parameter, direction)

View Source

Get the query result ordered by specific criteria

parameters

Parameters

  • query => refer to refer to new/1
  • parameter => %Arke.Core.Parameter.ParameterType => refer to Arke.Core.Parameter
  • direction => "child" | "parent" => the direction the query will use to search

example

Example

iex> person = Arke.Core.Arke.new(id: "person", label: "Person")
...> query = Arke.Core.Query.new(person, :arke_system)
...> parameter = Arke.Boundary.ParameterManager.get(:id,:arke_system)
...> Arke.Core.Query.add_order(query, parameter, :asc)

return

Return

%Arke.Core.Query{ ... orders: [ %Arke.Core.Query.Order{} ] ... }
@spec new(
  arke :: %Arke.Core.Arke{
    active: term(),
    id: term(),
    label: term(),
    parameters: term(),
    type: term()
  },
  project :: atom()
) :: t()

Create a new Query

parameters

Parameters

  • arke => %Arke.Core.{arke_struct}{} => the arke_struct of the unit which we want to filter on. See Arke.Struct
  • project => :atom => identify the Arke.Core.Project

example

Example

iex> person = Arke.Core.Arke.new(id: "person", label: "Person")
...> Arke.Core.Query.new(person, :default)

return

Return

%Arke.Core.Query{}
Link to this function

new_base_filter(parameter, operator, value, negate)

View Source

Create a new base filter

parameters

Parameters

  • parameter => %Arke.Core.Parameter.ParameterType => refer to Arke.Core.Parameter
  • operator => refer to operators
  • value => any => the value that the query will search for
  • negate => boolean => used to figure out whether the condition is to be denied

example

Example

iex> parameter = Arke.Boundary.ParameterManager.get(:id,:arke_system)
...> Arke.Core.Query.new_base_filter(parameter, :eq, "name", false)

return

Return

%Arke.Core.Query.BaseFilter{}
Link to this function

new_filter(logic, negate, base_filters)

View Source

Create a new filter

parameters

Parameters

  • logic => :and | :or => the logic of the filter

  • negate => boolean => used to figure out whether the condition is to be denied
  • base_filters => refer to Arke.Core.Query.BaseFilter

example

Example

iex> base_filter = Arke.Core.Query.new_base_filter(parameter, :eq, "name", false)
...> Arke.Core.Query.new_filter(:and, false, base_filter)

return

Return

%Arke.Core.Query.Filter{base_filters: [ %Arke.Core.Query.BaseFilter{} ]}
Link to this function

new_filter(parameter, operator, value, negate)

View Source

Create a new filter

parameters

Parameters

  • parameter => %Arke.Core.Parameter.ParameterType => refer to Arke.Core.Parameter
  • operator => refer to operators
  • value => any => the value that the query will search for
  • negate => boolean => used to figure out whether the condition is to be denied

example

Example

iex> parameter = Arke.Boundary.ParameterManager.get(:id,:arke_system)
...> Arke.Core.Query.new_filter(parameter,:eq, "name", false)

return

Return

%Arke.Core.Query.Filter{base_filters: [ %Arke.Core.Query.BaseFilter{} ]}
Link to this function

set_limit(query, offset)

View Source

Define the limit of the query

parameters

Parameters

  • query => refer to new/1
  • limit => integer => set the results limit of the query

example

Example

iex> person = Arke.Core.Arke.new(id: :person, label: "Person")
...> query = Arke.Core.Query.new(person, :arke_system)
...> Arke.Core.Query.set_limit(query, 100)

return

Return

%Arke.Core.Query{... limit: value ...}
Link to this function

set_offset(query, offset)

View Source

Define the offset of the query

parameters

Parameters

  • query => refer to new/1
  • offset => integer => define the offset of the query

example

Example

iex> person = Arke.Core.Arke.new(id: :person, label: "Person")
...> query = Arke.Core.Query.new(person, :arke_system)
...> Arke.Core.Query.set_offset(query, 5)

return

Return

%Arke.Core.Query{... offset: value ...}