Operators

Helpers

Learn useful helper operators in pb-query.

.search(keys, value)

Matches records where any of the keys contain value.

It can be used to perform a full-text search (FTS).

It is case-insensitive, so the :lower modifier is unnecessary.

pbQuery<Post>().search(['title', 'content', 'tags', 'author.name', 'author.surname'], 'Football'); // (title~'Football' || content~'Football' || tags~'Football' || author.name~'Football' || author.surname~'Football')

.in(key, values)

Matches records where key is in values.

pbQuery<Post>().in('id', ['id_1', 'id_2', 'id_3']); // (id='id_1' || id='id_2' || id='id_3')

.notIn(key, values)

Matches records where key is not in values.

pbQuery<User>().notIn('age', [18, 21, 30]); // (age!=18 && age!=21 && age!=30)

Ranges

.between(key, from, to)

Matches records where key is between from and to.

pbQuery<User>().between('age', 18, 30); // (age>=18 && age<=30)
pbQuery<User>().between('created', new Date('2021-01-01'), new Date('2021-12-31')); // (created>='2021-01-01 00:00:00.000Z' && created<='2021-12-31 00:00:00.000Z')

.notBetween(key, from, to)

Matches records where key is not between from and to.

pbQuery<User>().notBetween('age', 18, 30); // (age<18 || age>30)
pbQuery<User>().notBetween('created', new Date('2021-01-01'), new Date('2021-12-31')); // (created<'2021-01-01 00:00:00.000Z' || created>'2021-12-31 00:00:00.000Z')

Null Checks

.isNull(key)

Matches records where key is null.

pbQuery<User>().isNull('name'); // name=''

.isNotNull(key)

Matches records where key is not null.

pbQuery<User>().isNotNull('name'); // name!=''

Custom

.custom(raw)

Executes a custom query.

This helper is safe to use with pb.filter(), but we recommend using .custom() as a last resort.

If you have a special use case that might be useful to other developers, consider opening an issue, and we may implement it as a new helper in the future.

pbQuery<User>().custom(pb.filter('geoDistance(address.lon, address.lat, {:lon}, {:lat}) < {:distance}', { lon: 23.32, lat: 42.69, distance: 25 })); // geoDistance(address.lon, address.lat, 23.32, 42.69) < 25