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

@asaidimu/query-pocketbase

v1.0.0

Published

Pocketbase Query Executor

Readme

@asaidimu/query-pocketbase

A PocketBase executor for @asaidimu/query, providing a flexible and type-safe way to build and execute complex queries against PocketBase collections.

Features

  • 🎯 Type-safe: Full TypeScript support with generic types for your data models
  • 🔄 Query Builder Integration: Seamless integration with @asaidimu/query's QueryBuilder
  • 🚀 Advanced Querying: Support for complex filters, sorting, pagination, and more
  • 📊 Data Processing: Built-in support for aggregations, window functions, and computed fields
  • 🔍 Smart Caching: Automatic caching of subquery results for better performance
  • 🛠️ Extended Functions: Simulated support for additional functions not natively available in PocketBase

Installation

# Using npm
npm install @asaidimu/query @asaidimu/query-pocketbase pocketbase

# Using yarn
yarn add @asaidimu/query @asaidimu/query-pocketbase pocketbase

# Using pnpm
pnpm add @asaidimu/query @asaidimu/query-pocketbase pocketbase

Quick Start

import PocketBase from 'pocketbase';
import { QueryBuilder } from '@asaidimu/query';
import { PocketBaseQueryExecutor } from '@asaidimu/query-pocketbase';

// Define your data model
interface User {
  id: string;
  name: string;
  email: string;
  age: number;
  status: 'active' | 'inactive';
}

// Initialize PocketBase client and executor
const pb = new PocketBase('http://127.0.0.1:8090');
const executor = new PocketBaseQueryExecutor<User>(pb, 'users');

// Build and execute a query
async function getActiveAdultUsers() {
  const query = new QueryBuilder<User>()
    .where({
      operator: 'and',
      conditions: [
        { field: 'age', operator: 'gte', value: 18 },
        { field: 'status', operator: 'eq', value: 'active' }
      ]
    })
    .orderBy('name', 'asc')
    .offset(0, 10)
    .include(['id', 'name', 'email'])
    .build();

  const result = await executor.execute(query);
  return result;
}

Supported Operations

Filtering

// Simple filter
.where({ field: 'age', operator: 'gte', value: 18 })

// Complex conditions
.where({
  operator: 'and',
  conditions: [
    { field: 'age', operator: 'gte', value: 18 },
    {
      operator: 'or',
      conditions: [
        { field: 'status', operator: 'eq', value: 'active' },
        { field: 'role', operator: 'eq', value: 'admin' }
      ]
    }
  ]
})

Sorting

.orderBy('name', 'asc')

Pagination

// Offset-based
.offset(0, 10)

// Cursor-based
.cursor('last_id', 10, 'forward')

Projections

// Include specific fields
.include(['id', 'name', 'email'])

// Exclude fields
.exclude(['password', 'secretKey'])

// Computed fields
.computed({
  function: 'CONCAT',
  arguments: [
    { type: 'field', field: 'firstName' },
    ' ',
    { type: 'field', field: 'lastName' }
  ]
}, 'fullName')

Aggregations

.aggregate(['department'], [
  { operation: 'sum', field: 'salary', alias: 'totalSalary' },
  { operation: 'avg', field: 'age', alias: 'averageAge' }
])

Supported Functions

  • String Operations:

    • CONCAT: Concatenate multiple strings
    • UPPER: Convert to uppercase
    • LOWER: Convert to lowercase
    • LENGTH: Get string length
  • Numeric Operations:

    • ROUND: Round to nearest integer
  • Date Operations:

    • NOW: Current timestamp
    • DATE_FORMAT: Format date strings
  • Utility Functions:

    • COALESCE: Return first non-null value

PocketBase-Specific Considerations

Limitations

  1. Subqueries: Not natively supported by PocketBase. The executor simulates them using multiple queries.
  2. Complex Joins: Limited by PocketBase's capabilities. Implemented as separate queries.
  3. Window Functions: Simulated in memory as PocketBase doesn't support them natively.

Performance Tips

  1. Use Indexes: Ensure fields used in filters and sorts are indexed in PocketBase.
  2. Limit Results: Always use pagination to limit result sets.
  3. Optimize Projections: Only request needed fields to reduce data transfer.

Error Handling

The executor provides detailed error messages for common issues:

try {
  const result = await executor.execute(query);
} catch (error) {
  if (error.message.includes('Query execution failed')) {
    // Handle query execution errors
  }
}

TypeScript Support

The executor is fully typed and provides type inference:

interface MyModel {
  id: string;
  name: string;
  // ... other fields
}

const executor = new PocketBaseQueryExecutor<MyModel>(pb, 'collection');
// Now all queries will be type-checked against MyModel

Contributing

Contributions are welcome! Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.

License

MIT License - see the LICENSE file for details.