View Source Arke.QueryManager (Arke v1.1.33)

Module to manage the CRUD operations to create the below elements and also manage the query to get the elements from db.

arke

arke

operators

operators

  • eq => equal => =
  • contains => contains a value (Case sensitive) => LIKE %word%
  • icontains => contains a value (Not case sensitive) => LIKE %word%
  • startswith => starts with the given value (Case sensitive) => LIKE %word
  • istartswith => starts with the given value (Not case sensitive) => LIKE %word
  • endswith => ends with the given value (Case sensitive) => LIKE word%
  • iendswith => ends with the given value (Not case sensitive) => LIKE word%
  • lte => less than or equal => <=
  • lt => less than => <
  • gt => greater than => >
  • gte => greater than or equal => >=
  • in => value is in a collection => IN

Link to this section Summary

Functions

Return all the results from a query

Add an :and logic to a query

Return the count of the element returned from a query

Function to create an element

Function to delete a given unit

Filter of the query

Function to get all the element which match the given criteria

Function to get a single element identified by the opts. Use Arke.QueryManager.filter_by if more than one element is returned

Set the limit of the element to be returned from a query

Create a new topology query

Set the offset of the query

Return the first result of a query

Add an :or logic to a query

Define a criteria to order the element returned from a query

Return a string which represent the query itself

Create a new query

Return the query as a string

Function to update an element

Create query with specific options

Link to this section Types

@type func_return() :: {:ok, Arke.Core.Unit.t()} | Error.t()
@type operator() ::
  :eq
  | :contains
  | :icontains
  | :startswith
  | :istartswith
  | :endswith
  | :iendswith
  | :lte
  | :lt
  | :gt
  | :gte
  | :in
  | :isnull

Link to this section Functions

@spec all(query :: Arke.Core.Query.t()) :: [Arke.Core.Unit.t()] | []

Return all the results from a query

parameter

Parameter

Link to this function

and_(query, negate, filters)

View Source
@spec and_(query :: Arke.Core.Query.t(), negate :: boolean(), filters :: list()) ::
  Arke.Core.Query.t()

Add an :and logic to a query

parameter

Parameter

  • query => refer to query/1
  • negate => boolean => used to figure out whether the condition is to be denied
  • filters => refer to condition/3 | conditions/1

example

Example

iex> query = QueryManager.query(arke: nil, project: :arke_system)
...> query = QueryManager.and_(query, false, QueryManager.conditions(parameter__eq: "value"))

return

Return

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

condition(parameter, operator, value, negate \\ false)

View Source
@spec condition(
  parameter :: Arke.Core.Arke.t() | atom(),
  negate :: boolean(),
  value :: String.t() | boolean() | nil,
  negate :: boolean()
) :: Arke.Core.Query.BaseFilter.t()

Create a Arke.Core.Query.BaseFilter

parameters

Parameters

  • parameter => :atom | %Arke.Core.Arke{} => the parameter where to check the condition

  • operator => :atom => refer to operators
  • value => string | boolean | nil => the value the parameter and operator must check

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

example

Example

iex> QueryManager.condition(:string, :eq, "test")

return

Return

%Arke.Core.Query.BaseFilter{}
@spec conditions(opts :: list()) :: [Arke.Core.Query.BaseFilter.t()]

Create a list of Arke.Core.Query.BaseFilter

parameter

Parameter

  • opts => %{map} || [keyword: value] || key1: value1, key2: value2 => the condtions used to create the BaseFilters

example

Example

iex>  QueryManager.conditions(parameter__eq: "test", string__contains: "t")

return

Return

[ %Arke.Core.Query.BaseFilter{}, ...]
@spec count(query :: Arke.Core.Query.t()) :: integer()

Return the count of the element returned from a query

parameter

Parameter

Link to this function

create(project, arke, args)

View Source
@spec create(project :: atom(), arke :: Arke.Core.Arke.t(), args :: list()) ::
  func_return()

Function to create an element

parameters

Parameters

  • project => :atom => identify the Arke.Core.Project
  • arke => {arke_struct} => identify the struct of the element we want to create
  • args => [list] => list of key: value we want to assign to the {arke_struct} above

example

Example

iex> string = ArkeManager.get(:string, :default)
...> Arke.QueryManager.create(:default, string, [id: "name", label: "Nome"])

returns

Returns

{:ok, %Arke.Core.Unit{}}
@spec delete(project :: atom(), Arke.Core.Unit.t()) :: {:ok, any()}

Function to delete a given unit

parameters

Parameters

  • project => :atom => identify the Arke.Core.Project
  • unit => %{arke_struct} => the unit to delete

example

Example

iex> element = Arke.QueryManager.get_by(id: "name")
...> Arke.QueryManager.delete(element)

returns

Returns

{:ok, _}
@spec filter(query :: Arke.Core.Query.t(), filter :: Arke.Core.Query.Filter.t()) ::
  Arke.Core.Query.t()

Filter of the query

parameters

Parameters

example

Example

iex> query = Arke.QueryManager.Query.t
...> parameter = Arke.Boundary.ParameterManager.get(:id,:arke_system)
...> Arke.Core.Query.new_filter(parameter,:equal,"name",false)
...> Arke.Core.Query.filter(query, filter
Link to this function

filter(query, parameter, operator, value, negate \\ false)

View Source
@spec filter(
  query :: Arke.Core.Query.t(),
  parameter :: Arke.Core.Arke.t() | String.t() | atom(),
  operator :: operator(),
  value :: String.t() | boolean() | number(),
  negate :: boolean()
) :: Arke.Core.Query.t()

Filter of the query

parameters

Parameters

  • query => refer to query/1
  • parameter => %{arke_struct} => arke struct of the parameter
  • operator => :atom => refer to operators
  • value => string | boolean | nil => the value the parameter and operator must check

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

example

Example

iex> query = Arke.QueryManager.query()
...> QueryManager.filter(query, Arke.Core.Query.new_filter(Arke.Boundary.ParameterManager.get(:id,:default),:equal,"name",false))

return

Return

%Arke.Core.Query{...}
@spec filter_by(opts :: list()) :: [Arke.Core.Unit.t()] | []

Function to get all the element which match the given criteria

parameters

Parameters

  • opts => %{map} || [keyword: value] || key1: value1, key2: value2 => identify the element to get
  • operator => :atom => refer to operators

example

Example

iex> Arke.QueryManager.filter_by(id: "name")

return

Return

[ Arke.Core.Unit{}, ...]
@spec get_by(opts :: list()) :: Arke.Core.Unit.t() | nil

Function to get a single element identified by the opts. Use Arke.QueryManager.filter_by if more than one element is returned

parameters

Parameters

  • opts => %{map} || [keyword: value] || key1: value1, key2: value2 => identify the element to get

example

Example

iex> Arke.QueryManager.get_by(id: "name")
@spec limit(query :: Arke.Core.Query.t(), limit :: integer()) :: Arke.Core.Query.t()

Set the limit of the element to be returned from a query

parameter

Parameter

  • query => refer to query/1
  • limit => int => number of element to return

example

Example

iex> query = QueryManager..query()
...> QueryManager.where(query, id: "name") |> QueryManager.limit(1)
Link to this function

link(query, unit, opts \\ [])

View Source
@spec link(Arke.Core.Query.t(), unit :: Arke.Core.Unit.t(), opts :: list()) ::
  Arke.Core.Query.t()

Create a new topology query

parameter

Parameter

  • query => refer to query/1
  • unit => %{arke_struct} => struct of the unit used as reference for the query
  • opts => [keyword: value] => KeywordList containing the link conditions
  • depth => int => max depth of the topoplogy
  • direction => :atom => :child/:parent => the direction of the link. From parent to child or viceversa
  • connection_type => string => name of the connection where to search

example

Example

iex> Arke.QueryManager.query(project: :public)
...> unit = QueryManager.get_by([project: :arke_system, id: "test"])
...> QueryManager.link(query, unit)

return

Return

%Arke.Core.Query{}
@spec offset(query :: Arke.Core.Query.t(), offset :: integer()) :: Arke.Core.Query.t()

Set the offset of the query

parameter

Parameter

  • query => refer to query/1
  • offset => int => offset of the query

example

Example

iex> query = QueryManager.query()
...> QueryManager.where(query, id: "name") |> QueryManager.offset(5)
@spec one(query :: Arke.Core.Query.t()) :: Arke.Core.Unit.t() | nil

Return the first result of a query

parameter

Parameter

Link to this function

or_(query, negate, filters)

View Source
@spec or_(query :: Arke.Core.Query.t(), negate :: boolean(), filters :: list()) ::
  Arke.Core.Query.t()

Add an :or logic to a query

parameter

Parameter

  • query => refer to query/1
  • negate => boolean => used to figure out whether the condition is to be denied
  • filters => refer to condition/3 | conditions/1

example

Example

iex> query = QueryManager.query(arke: nil, project: :arke_system)
...> query = QueryManager.or_(query, false, QueryManager.conditions(parameter__eq: "value"))

return

Return

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

order(query, parameter, direction)

View Source
@spec order(
  query :: Arke.Core.Query.t(),
  parameter :: Arke.Core.Arke.t() | String.t() | atom(),
  direction :: atom()
) :: Arke.Core.Query.t()

Define a criteria to order the element returned from a query

parameter

Parameter

  • query => refer to query/1
  • order => int => number of element to return

example

Example

iex> query = QueryManager.query()
...> parameter = Arke.Boundary.ParameterManager.get(:id,:default)
...> QueryManager.order(query, parameter, :asc)
Link to this function

pagination(query, offset, limit)

View Source
@spec pseudo_query(query :: Arke.Core.Query.t()) :: Ecto.Query.t()

Return a string which represent the query itself

parameter

Parameter

example

Example

iex> query = QueryManager.query()
...> QueryManager.where(query, id: "name") |> QueryManager.pseudo_query

return

Return

#Ecto.Query<>
@spec query(list()) :: Arke.Core.Query.t()

Create a new query

parameter

Parameter

  • opts => %{map} || [keyword: value] || key1: value1, key2: value2 => map containing the project and the arke where to apply the query

example

Example

iex> Arke.QueryManager.query(project: :public)
@spec raw(query :: Arke.Core.Query.t()) :: String.t()

Return the query as a string

parameter

Parameter

Link to this function

update(current_unit, args)

View Source
@spec update(Arke.Core.Unit.t(), args :: list()) :: func_return()

Function to update an element

parameters

Parameters

  • project => :atom => identify the Arke.Core.Project
  • unit => %{arke_struct} => unit to update
  • args => [list] => list of key: value to update

example

Example

iex> name = QueryManager.get_by(id: "name")
...> QueryManager.update(:default, name, [max_length: 20])

returns

Returns

{:ok,  %Arke.Core.Unit{} }
{:error, [msg]}
Link to this function

where(query, opts \\ [])

View Source
@spec where(query :: Arke.Core.Query.t(), opts :: list()) :: Arke.Core.Query.t()

Create query with specific options

parameters

Parameters

  • query => refer to query/1
  • opts => %{map} || [keyword: value] || key1: value1, key2: value2 => keyword list containing the filter to apply

example

Example

iex> query = Arke.QueryManager.query()
...> QueryManager.where(query, [id__contains: "me", id__contains: "n"])

return

Return

%Arke.Core.Query{ %Arke.Core.Query.Filter{ ... base_filters: %Arke.Core.Query.BaseFilter{ ... }}}