Returning Values

Filter

Filters results using operators.
There is no .filter() function, you construct it using operators.

By default, we don't filter your query. Using .build() returns the unfiltered query and values separately. This is useful if you want to use pb-query inside PocketBase Hooks, you can see how in the tutorial.

const { filter } = pbQuery<Post>()
  .like('content', 'Top Secret%')
  .build();

console.log(filter);
// {
//   raw: 'content~{:content1}',
//   values: { content1: 'Top Secret%' }
// }

If you want to use pb-query in your app (this is the main usecase of pb-query), you need to filter it. We expose a filter function, but we recommend using the native pb.filter() function instead.

import PocketBase from 'pocketbase';

// PocketBase instance
const pb = new PocketBase("https://example.com");

const { filter } = pbQuery<Post>()
  .like('content', 'Top Secret%')
  .build(pb.filter); // use PocketBase's filter function

console.log(filter);
// "content~'Top Secret%'"
You can see a full example in the tutorial.