1.0.2 • Published 9 months ago
@asaidimu/remote-store-pocketbase v1.0.2
@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 collectionpb: PocketBase
- An initialized PocketBase client instance
Returns
Returns a BaseStore<T>
instance with the following methods:
find({ filter, options? })
- Find first record matching the filterread({ id, options? })
- Read a record by IDlist({ filter?, page?, pageSize?, ...options })
- List records with paginationcreate({ data })
- Create a new recordupdate({ id, data })
- Update an existing recorddelete({ id })
- Delete a recordupload({ id, field, file })
- Upload a file for a record
License
MIT