Use the filter
or minified flt
key to add a filter to your Jory Query.
The following operators are available for any filter: =
, !=
, <>
, >
, >=
, <
, <=
, <=>
, like
, not_like
, is_null
, not_null
, in
and not_in
.
A basic filter consists of a field
(f
), operator
(o
) and data
(d
) key, the operator
defaults to an "equals" comparison when omitted.
Return only the active users:
axios.get('jory/user', {
params: {
jory: {
filter: {
field: 'is_active',
data: true
}
}
}
});
Return all musicians with first_name
like John
.
axios.get('jory/musician', {
params: {
jory: {
filter: {
field: 'first_name',
operator: 'like',
data: '%John%'
}
}
}
});
Applying multiple filters can be done using the group_and
(and
) or group_or
(or
) key. This key should contain an array of filters, these filters can be single filters or another grouped AND or OR filter if you want to create nested conditions.
Return only the users which are active AND are last modified after 6 dec 2019:
axios.get('jory/user', {
params: {
jory: {
filter: {
group_and: [
{
field: "is_active",
data: true
},
{
field: "modified_at",
operator: ">",
data: "2019-12-06"
}
]
}
}
}
});
Return only the users which are active AND are last modified in 2019 AND have a last_name starting with "Clap":
axios.get('jory/user', {
params: {
jory: {
filter: {
group_and: [
{
field: "is_active",
},
{
group_or: [
{
field: "modified_at",
operator: ">=",
data: "2019-01-01"
},
{
field: "modified_at",
operator: "<",
data: "2020-01-01"
}
]
},
{
field: "last_name",
operator: "like",
data: "Clap%"
}
]
}
}
}
});
{info} The
data
key must contain an array when using thein
ornot_in
operator.
{info} The
data
key may contain objects with key/value pairs when using custom filters in the Jory Resource. These objects will be passed as an associative array to the custom FilterScope.