npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@emresandikci/pocketbase-query

v0.4.1

Published

A pocketbase query builder

Readme

Pocketbase Query

Overview

@emresandikci/pocketbase-query is a TypeScript-based query builder designed to generate complex filter queries for PocketBase. It allows for easy construction of queries using various operators while maintaining a fluent and chainable API.


Installation

This library can be used in any TypeScript/JavaScript project. Simply import it as needed:

npm i @emresandikci/pocketbase-query
import PocketbaseQuery from '@emresandikci/pocketbase-query';

Usage

Creating an Instance

The PocketbaseQuery class follows the singleton pattern. You should use getInstance() to get a query builder instance:

const query = PocketbaseQuery.getInstance<MyType>();

Example

import PocketbaseQuery from '@emresandikci/pocketbase-query';

const query = PocketbaseQuery.getInstance<{ status: string; comments: number }>();

const customFilters = query
  .equal('status', 'active')
  .and()
  .greaterThan('comments', 50)
  .build();

console.log(customFilters); // Outputs: status='active' && comments>50

await pb.collection('posts').getFullList({
	filter: customFilters,
	expand: [{ key: 'comments_via_post' }],
})

API Methods

Operators Enum

OperatorEnum defines a set of operators for use in queries:

enum OperatorEnum {
  Equal = "=",
  NotEqual = "!=",
  GreaterThan = ">",
  GreaterThanOrEqual = ">=",
  LessThan = "<",
  LessThanOrEqual = "<=",
  Like = "~",
  NotLike = "!~",
  AnyEqual = "?=",
  AnyNotEqual = "?!=",
  AnyGreaterThan = "?>",
  AnyGreaterThanOrEqual = "?>=",
  AnyLessThan = "?<",
  AnyLessThanOrEqual = "?<=",
  AnyLike = "?~",
  AnyNotLike = "?!~",
}

Query Builder Methods

equal(field: keyof T, value: string | boolean)

Adds an equality condition to the query.

query.equal("status", "active");

notEqual(field: keyof T, value: string)

Adds a not-equal condition to the query.

query.notEqual("category", "archived");

greaterThan(field: keyof T, value: string)

Adds a greater-than condition.

query.greaterThan("age", "18");

lessThan(field: keyof T, value: string)

Adds a less-than condition.

query.lessThan("price", "100");

like(field: keyof T, value: string)

Adds a LIKE condition (partial match).

query.like("name", "John");

notLike(field: keyof T, value: string)

Adds a NOT LIKE condition.

query.notLike("description", "discount");

anyEqual(field: keyof T, value: string)

Adds an equality condition for array fields.

query.anyEqual("tags", "sale");

in(field: keyof T, values: any[])

Adds an OR condition for multiple values.

query.in("category", ["electronics", "furniture"]);

customFilter(filter: string)

Adds a custom filter string to the query.

query.customFilter("status='active' && price>100");

Logical Operators

and()

Joins multiple conditions with &&.

query.equal("status", "active").and().greaterThan("price", "50");

or()

Joins multiple conditions with ||.

query.equal("status", "active").or().equal("status", "pending");

openBracket() and closeBracket()

Groups conditions using parentheses.

query.openBracket().equal("status", "active").or().equal("status", "pending").closeBracket().and().greaterThan("price", "50");

Query Execution

getQuery()

Returns the current query string.

const queryString = query.getQuery();

build()

Finalizes and returns the query string while clearing the internal state.

const finalQuery = query.build();

Notes

  • The PocketbaseQuery class uses a singleton pattern, meaning a single instance is reused across calls.
  • The .build() method resets the query, so ensure you store the generated string if you need it.
  • The in() method applies OR between multiple values.

License

MIT License