View Source QueryBuilder (Query Builder v1.4.2)
Summary
Functions
Allows to pass a list of operations through a keyword list.
A join query expression.
A limit query expression. If multiple limit expressions are provided, the last expression is evaluated
Run QueryBuilder.order_by/2
only if given condition is met.
Run QueryBuilder.order_by/3
only if given condition is met.
Run QueryBuilder.where/2
only if given condition is met.
Run QueryBuilder.where/4
only if given condition is met.
A offset query expression. If multiple offset expressions are provided, the last expression is evaluated
An order by query expression.
An order by query expression.
Preloads the associations.
An AND where query expression.
An AND where query expression.
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]
])
A join query expression.
Example:
QueryBuilder.left_join(query, :articles, title@articles: "Foo", or: [title@articles: "Bar"])
A limit query expression. If multiple limit expressions are provided, the last expression is evaluated
Example:
QueryBuilder.limit(query, 10)
Run QueryBuilder.order_by/2
only if given condition is met.
Run QueryBuilder.order_by/3
only if given condition is met.
Run QueryBuilder.where/2
only if given condition is met.
maybe_where(query, condition, assoc_fields, filters, or_filters \\ [])
View SourceRun QueryBuilder.where/4
only if given condition is met.
A offset query expression. If multiple offset expressions are provided, the last expression is evaluated
Example:
QueryBuilder.offset(query, 10)
An order by query expression.
Example:
QueryBuilder.order_by(query, asc: :lastname, asc: :firstname)
An order by query expression.
For more about the second argument, see where/3
.
Example:
QueryBuilder.order_by(query, :articles, asc: :title@articles)
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")
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)
OR clauses may be passed through last argument opts
. For example:
QueryBuilder.where(query, [], [firstname: "John"], or: [firstname: "Alice", lastname: "Doe"], or: [firstname: "Bob"])