Skip to content

Schemas and models

Barq stores objects. A schema tells Barq the object name, primary key, and field types.

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 },
},
};
}
struct Dog {
std::string name;
int64_t age;
};
BARQ_SCHEMA(Dog, name, age)
  • Define the schema before first open.
  • Bump schemaVersion when changing a local schema.
  • Use migrations for local files that already exist.
  • Synced schemas must match what the synced clients and server expect.