This module provides utility functions for interacting with PocketBase in SE-2, a backend for your next SaaS and Mobile app. It includes functions for authentication, fetching data, and managing collections and items.
- Create a new project with Pocketbase extension:
npx create-eth@latest -e @scobru/pocketbase-extensionImport the functions you need:
import {
initPocketBase,
authenticateAdmin,
fetchCollections,
fetchItems,
createItem,
updateItem,
deleteItem,
createCollection,
deleteCollection,
} from "./utils/pocketbaseHelpers";Initializes a new PocketBase instance.
const pb = initPocketBase("https://your-pocketbase-url.com");Authenticates an admin user.
const authData = await authenticateAdmin(pb, "admin@example.com", "password");Fetches all collection names.
const collections = await fetchCollections(pb);Fetches all items from a specific collection.
const items = await fetchItems(pb, "my_collection");createItem(pb: PocketBase, collectionName: string, item: { [key: string]: any }): Promise<RecordModel>
Creates a new item in a collection.
const newItem = await createItem(pb, "my_collection", {
name: "New Item",
description: "Description",
});updateItem(pb: PocketBase, collectionName: string, itemId: string, item: { [key: string]: any }): Promise<RecordModel>
Updates an existing item in a collection.
const updatedItem = await updateItem(pb, "my_collection", "item_id", {
name: "Updated Item",
});Deletes an item from a collection.
await deleteItem(pb, "my_collection", "item_id");Creates a new collection.
await createCollection(pb, 'admin_token', { name: 'new_collection', schema: [...] });Deletes a collection.
await deleteCollection(pb, "collection_to_delete");