Dito.js offers a query builder interface to SQL queries based on
Objection.js' QueryBuilder
,
which in turn is an extension of
Knex.js' Query Builder
.
Any Objection.js query statement is also a valid Dito.js query, so Objection.js' documentation is a valuable source of information.
Dito.js offers a row of query builder extensions as well as short-cuts to them from other classes. This means that Dito.js queries don't always translate back to Objection.js one to one. Please keep that in mind when posting questions on the Objection.js Gitter chat. See Differences to Objection.js for a list of differences between the two.
Listed below are only the Ditos.js extensions to its QueryBuilder
, everything
else remains the same as in the documentation linked to above.
An easy way to play around with and familiarize yourself with queries is to start the Dito.js console:
yarn console
You can use .debug()
on any query to directly log SQL statement to console.
In addition to Objection.js' many database methods, ...:
-
Dito.js models have versions of all common
QueryBuilder
methods as short- cuts that can be called directly on the model class, without having to callModel.query()
first:Model.query().where(…)
simply becomesModel.where(…)
, and everything else carries on normally from there. -
Dito.js models give access to their relations and their queries through special relation accessors. See Model Relations – Relation Accessors for more information about these accessors.