Query Builder v0.5.0 QueryBuilder View Source

Link to this section Summary

Functions

Allows to pass a list of operations through a keyword list.

A join query expression.

An order by query expression.

An order by query expression.

Preloads the associations.

An AND where query expression.

An AND where query expression.

Link to this section Functions

Allows to pass a list of operations through a keyword list.

Example:

QueryBuilder.from_list(query, [
  where: [name: "John", city: "Anytown"],
  preload: [articles: :comments]
])
Link to this function

join(query, assoc_fields, type)

View Source

A join query expression.

Third argument type may be passed one of the possible values for Ecto.Query.join/5's qualifier argument.

Example:

QueryBuilder.join(query, :articles, :left)

An order by query expression.

Example:

QueryBuilder.order_by(query, lastname: :asc, firstname: :asc)
Link to this function

order_by(query, assoc_fields, value)

View Source

An order by query expression.

For more about the second argument, see where/3.

Example:

QueryBuilder.order_by(query, :articles, title@articles: :asc)
Link to this function

preload(query, assoc_fields)

View Source

Preloads the associations.

Bindings are automatically set if joins have been made, or if it is preferable to join (i.e. one-to-one associations are preferable to include into the query result rather than emitting separate DB queries).

Example:

QueryBuilder.preload(query, [role: :permissions, articles: [:stars, comments: :user]])

An AND where query expression.

Example:

QueryBuilder.where(query, firstname: "John")
Link to this function

where(query, assoc_fields, filters)

View Source

An AND where query expression.

Associations are passed in second argument; fields from these associations can then be referenced by writing the field name, followed by the "@" character and the association name, as an atom. For example: :name@users.

Example:

QueryBuilder.where(query, [role: :permissions], name@permissions: :write)