View Source Dequel.Preloads (Dequel v0.7.0)

Extracts required preloads from a Dequel query.

Walks the AST and collects all relation references (dot notation and block syntax), returning an Ecto-compatible preload list.

Examples

Dot notation:

iex> Dequel.preloads("author.name:Tolkien")
[:author]

Nested dot notation:

iex> Dequel.preloads("author.publisher.name:Penguin")
[author: :publisher]

Block syntax:

iex> Dequel.preloads("tags{name:fiction}")
[:tags]

Summary

Functions

Extracts preloads from a query string or parsed AST.

Functions

@spec extract(binary() | tuple()) :: list()

Extracts preloads from a query string or parsed AST.

Returns a list of preloads in Ecto-compatible format.

Examples

iex> Dequel.Preloads.extract("author.name:Tolkien")
[:author]

iex> Dequel.Preloads.extract("author.publisher.name:Penguin")
[author: :publisher]

iex> Dequel.Preloads.extract("tags{name:fiction}")
[:tags]

iex> Dequel.Preloads.extract("title:Rings")
[]

iex> Dequel.Preloads.extract("")
[]