Files
lucent-laravel/docs/Queries.md
T
2023-10-31 23:21:29 +02:00

1.5 KiB

Table of Contents

Queries

Graph or Tree

Queries can return results in 2 formats. A graph or a tree.

Graphs results are a collection of records (nodes) and a collection of edges. This format is more useful for network visualization.

The tree format is more straightforward as it returns a collection of records. Each record has a _children and a _parents field and the tree can continue upwards or downwards according to the depth you have requested.

For example to request records with their children and their children's children:

$query->childrenDepth(2);

Maybe you only want to get a specific type of relationship:

$query->childrenDepth(2)->childrenFields(["categories"]);

Filters

You can filter your query with the following format:

$query->filter(["field_operator" => "value"]);

// example:

$query->filter(["date_lt" => "2020-09-15"]);

Or filters are also available:

$query
    ->filter(["price_eqn" => 10])
    ->orFilter(["title_regex" => "search", "slug_regex" => "search"])
    ;

Operator List

  • regex
  • eq
  • ne
  • eqnum
  • neqnum
  • filter
  • eqtrue
  • eqfalse
  • netrue
  • nefalse
  • in:
  • innum
  • nin
  • ninnum
  • lt
  • lte
  • gt
  • gte
  • null
  • nnull
  • exists
  • nexists

Example

Get 10 posts from the sports category as a tree

$posts = $query
    ->filter([
        "schema" => "posts",
        "children.categories.data.slug" => "sports",
       ]
    )
    ->childrenDepth(1)
    ->limit(10)
    ->tree();

$posts->map(...)->toArray();