1.0.2 • Published 9 months ago

@asaidimu/remote-store-pocketbase v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

@asaidimu/remote-store-pocketbase

A PocketBase adapter for the remote-store library that provides a consistent interface for working with PocketBase collections.

Installation

npm install @asaidimu/remote-store-pocketbase pocketbase

Usage

import PocketBase from 'pocketbase';
import { createPocketBaseStore } from '@asaidimu/remote-store-pocketbase';

// Initialize PocketBase client
const pb = new PocketBase('http://127.0.0.1:8090');

// Define your record type
interface User extends RemoteStoreRecord {
  name: string;
  email: string;
  avatar?: string;
}

// Create a store instance
const userStore = createPocketBaseStore<User>({
  collection: 'users',
  pb,
});

// Use the store
async function example() {
  // Create a user
  const user = await userStore.create({
    data: {
      name: 'John Doe',
      email: 'john@example.com',
    }
  });

  // Upload an avatar
  const avatarFile = new File([''], 'avatar.png');
  await userStore.upload({
    id: user.id,
    field: 'avatar',
    file: avatarFile
  });

  // List users with pagination
  const users = await userStore.list({
    page: 1,
    pageSize: 20,
    filter: 'name="John Doe"',
    select: ['name', 'email'],
    include: ['profile']
  });
}

API

createPocketBaseStore(options)

Creates a new store instance for interacting with a PocketBase collection.

Options

  • collection: string - The name of the PocketBase collection
  • pb: PocketBase - An initialized PocketBase client instance

Returns

Returns a BaseStore<T> instance with the following methods:

  • find({ filter, options? }) - Find first record matching the filter
  • read({ id, options? }) - Read a record by ID
  • list({ filter?, page?, pageSize?, ...options }) - List records with pagination
  • create({ data }) - Create a new record
  • update({ id, data }) - Update an existing record
  • delete({ id }) - Delete a record
  • upload({ id, field, file }) - Upload a file for a record

License

MIT

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago