-
Notifications
You must be signed in to change notification settings - Fork 209
Shorthand Comparators
Mitch Conquer edited this page Nov 12, 2017
·
2 revisions
These compators may be appended with a double underscore, '__', to field names in query parameters in a URL or inside a query.
For example when querying
Users.query()
.where({age__gte: 21})
end((err, users) => {
// process results
});
Or in as a query parameter
http://www.website.com/v1/users?phone__is_null=true
The following is a breakdown of their SQL equivelants.
is: field => `${field} = __VAR__`
not: field => `${field} <> __VAR__`
lt: field => `${field} < __VAR__`
lte: field => `${field} <= __VAR__`
gt: field => `${field} > __VAR__`
gte: field => `${field} >= __VAR__`
contains: field => `${field} LIKE '%' || __VAR__ || '%'`
icontains: field => `${field} ILIKE '%' || __VAR__ || '%'`
startswith: field => `${field} LIKE __VAR__ || '%'`
istartswith: field => `${field} ILIKE __VAR__ || '%'`
endswith: field => `${field} LIKE '%' || __VAR__`
iendswith: field => `${field} ILIKE '%' || __VAR__`
like: field => `${field} LIKE __VAR__`
ilike: field => `${field} ILIKE __VAR__`
is_null: field => `${field} IS NULL`
is_true: field => `${field} IS TRUE`
is_false: field => `${field} IS FALSE`
not_null: field => `${field} IS NOT NULL`
not_true: field => `${field} IS NOT TRUE`
not_false: field => `${field} IS NOT FALSE`
in: field => `ARRAY[${field}] <@ __VAR__`
not_in: field => `NOT (ARRAY[${field}] <@ __VAR__)`