Package Exports
- pocketbasesync
- pocketbasesync/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pocketbasesync) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
PocketSync
PocketSync is a TypeScript library that integrates with Pocketbase to provide real-time updates using the realtime API. It simplifies database connections for your frontend and supports CRUD operations.
Usage
- Initialize a PocketSync Collection.
interface Dog {
name: string;
breed: string;
// other fields
}
const pocketbaseURL = 'https://your-pocketbase-url';
const collectionName = 'your-collection-name';
const collection = new PocketSync<Dog>(pocketbaseURL, collectionName);
- List your records with
list()
, if using svelte, you can use auto subscribers. The store returns an object with two properties:{ loading: boolean, items: PocketSyncRecord<T>[] }
<script lang="ts">
import { PocketSync } from 'pocketsync';
import type { Dog } from './path-to-your-types';
const pocketbaseURL = 'https://your-pocketbase-url';
const collectionName = 'your-collection-name';
const collection = new PocketSync<Dog>(pocketbaseURL, collectionName);
let fileStore = collection.list();
</script>
{#each $fileStore.items as file}
<span>{file.record.name}</span>
{/each}
CRUD Operations
- Adding a record.
import { PocketSync } from 'pocketsync';
import type { Dog } from './path-to-your-types';
const pocketbaseURL = 'https://your-pocketbase-url';
const collectionName = 'your-collection-name';
const collection = new PocketSync<Dog>(pocketbaseURL, collectionName);
const fileStore = collection.list();
const newRecord: Partial<Dog> = {
name: 'Kaya'
// other fields
};
fileStore.addRecord(newRecord);
- Deleting a record.
import { PocketSync } from 'pocketsync';
import type { Dog } from './path-to-your-types';
const pocketbaseURL = 'https://your-pocketbase-url';
const collectionName = 'your-collection-name';
const collection = new PocketSync<Dog>(pocketbaseURL, collectionName);
const fileStore = collection.list();
$: singleFile = $fileStore.items[0];
singleFile.delete();
// OR
fileStore.delete(singleFile.id);
- Updating a record.
import { PocketSync } from 'pocketsync';
import type { Dog } from './path-to-your-types';
const pocketbaseURL = 'https://your-pocketbase-url';
const collectionName = 'your-collection-name';
const collection = new PocketSync<Dog>(pocketbaseURL, collectionName);
const fileStore = collection.list();
$: singleFile = $fileStore[0];
const updatedRecord: Partial<Dog> = {
name: 'Updated Record'
// other fields
};
singleFile.update(updatedRecord);