First JS app
This example opens a local Barq database, creates a schema, and writes one object.
import Barq from '@barq/barq';
class Task extends Barq.Object<Task> { _id!: Barq.Types.ObjectId; description!: string; done = false;
static schema: Barq.ObjectSchema = { name: 'Task', primaryKey: '_id', properties: { _id: 'objectId', description: 'string', done: { type: 'bool', default: false }, }, };}
const barq = await Barq.open({ schema: [Task] });
barq.write(() => { barq.create(Task, { _id: new Barq.Types.ObjectId(), description: 'Ship Barq', });});
const tasks = barq.objects(Task);console.log(tasks.length);What Happens
Section titled “What Happens”Barq.open()opens or creates the local database file.schematells Barq which object types can be stored.barq.write()wraps changes in a write transaction.barq.objects(Task)returns live results for that object type.
Add Sync Later
Section titled “Add Sync Later”Local database code does not need sync. To add sync, create a Barq.User from an access token and pass a sync config to Barq.open().