Query Builder Methods
include
- Arguments:
(...args)
- Returns:
self
Eager load relationships.
await Model.include('user', 'category')
append
- Arguments:
(...args)
- Returns:
self
Append attributes.
await Model.include('likes')
select
- Arguments:
(...fields)
- Returns:
self
Set the columns to be selected.
Single entity:
await Model.select(['title', 'content'])
Related entities:
await Post.select({
posts: ['title', 'content'],
user: ['age', 'firstName']
})
where
- Arguments:
(field, value)
- Returns:
self
Add a basic where clause to the query.
await Model.where('status', 'active')
whereIn
- Arguments:
(field, array)
- Returns:
self
Add a "where in" clause to the query.
await Model.whereIn('id', [1, 2, 3])
orderBy
- Arguments:
(...args)
- Returns:
self
Add an "order by" clause to the query.
await Model.orderBy('-created_at', 'category_id')
page
- Arguments:
(value)
- Returns:
self
Set the current page.
await Model.page(1)
limit
- Arguments:
(value)
- Returns:
self
Set the page limit.
await Model.limit(20)
params
- Arguments:
(payload)
- Returns:
self
Add custom parameters to the query.
await Model.params({
foo: 'bar',
baz: true
})
GET /resource?foo=bar&baz=true
custom
- Arguments:
(...args)
- Returns:
self
Build custom endpoints.
await Post.custom('posts/latest')
GET /posts/latest
const user = new User({ id: 1 })
const post = new Post()
await Post.custom(user, post, 'latest')
GET /users/1/posts/latest
get
- Returns:
Collection | { data: Collection }
Execute the query as a "select" statement.
await Model.get()
first
- Returns:
Model | { data: Model }
Execute the query and get the first result.
await Model.first()
find
- Arguments:
(identifier)
- Returns:
Model | { data: Model }
Find a model by its primary key.
await Model.find(1)
$get
- Returns:
Collection
Execute the query as a "select" statement.
These $
-prefixed convenience methods always return the requested content as JSON
.
await Model.$get()
These
$
-prefixed convenience methods always return the requested content.
They handle and unwrap responses within "data".
$first
- Returns:
Model
Execute the query and get the first result.
await Model.$first()
These
$
-prefixed convenience methods always return the requested content.
They handle and unwrap responses within "data".
$find
- Arguments:
(identifier)
- Returns:
Model
Find a model by its primary key.
await Model.$find(1)
These
$
-prefixed convenience methods always return the requested content.
They handle and unwrap responses within "data".