Query Builder
The query builder makes SQL for you. You chain methods, and Dox runs the query with bound values. It works on Postgres, MySQL/MariaDB and SQLite.
- Set up the database first: see Database.
- For transactions, see Transactions.
Good to know
- Table and column names are quoted. On Postgres,
userIdanduseridare two names. orderBythrows anArgumentErrorwhen the direction is notascordesc.toSql()wraps the where part in brackets.count()ignoreslimit,offsetandorderBy. WithgroupByit returns the number of groups.
create
insert
Info
insert works with any primary key type, for example a uuid string.
insertMultiple uses the keys from all rows. When a row does not have a key,
that column gets its default value.
update
count
Info
count() does not use limit, offset and orderBy.
With groupBy, count() returns the number of groups.
find
getFirst
all
get
toSql
delete
forceDelete
Info
This is for models with softDeletes. It also deletes rows that are already
soft deleted, so you do not need withTrash().
withTrash
Info
This work only with softDeletes. On a model without softDeletes it does nothing.
select
whereIn
Info
Each value is sent as a bound parameter.
An empty list matches no rows for whereIn, and all rows for whereNotIn.
whereNull
where
orWhere
whereRaw
orWhereRaw
limit, take, offset
Info
Limit and take are the same function.
groupBy
orderBy
Info
The direction must be asc or desc. Any other value throws an ArgumentError.
The column name is quoted, but a name with ( is kept as it is.
Do not pass user input as the column name.