Documentation Index
Fetch the complete documentation index at: https://docs.pocketsync.dev/llms.txt
Use this file to discover all available pages before exploring further.
PocketSyncDatabase is initialized with PocketSync instance. You can access it via PocketSync.instance.database.
final db = PocketSync.instance.database;
Database Options
PocketSyncDatabase requires configuration options to properly initialize and manage your SQLite database.
| Parameter | Description | Required | Default |
|---|
version | The database version number | No | 1 |
dbPath | Path to the SQLite database file | Yes | - |
onCreate | Callback function called when database is first created | Yes | - |
onConfigure | Callback function to configure the database | No | null |
onUpgrade | Callback function to handle database version upgrades | No | null |
onDowngrade | Callback function to handle database version downgrades | No | null |
onOpen | Callback function called when database is opened | No | null |
schema | Database schema | No | null |
Example
final todosTable = TableSchema(
name: 'todos',
columns: [
TableColumn.primaryKey(
name: 'id',
type: ColumnType.integer,
isAutoIncrement: true,
),
TableColumn.text(
name: 'title',
isNullable: false,
),
TableColumn.boolean(
name: 'completed',
defaultValue: false,
),
TableColumn.datetime(
name: 'created_at',
isNullable: false,
),
TableColumn.foreignKey(
name: 'user_id',
type: ColumnType.integer,
references: TableReference(
table: 'users',
column: 'id',
onDelete: 'CASCADE',
),
isNullable: false,
),
],
indexes: [
Index(
name: 'idx_todos_title',
columns: ['title'],
),
],
);
final db = PocketSync.initialize(
options: PocketSyncOptions(
projectId: 'your-project-id',
authToken: 'your-auth-token',
serverUrl: 'https://api.pocketsync.dev',
),
databaseOptions: DatabaseOptions(
version: 1,
dbPath: 'path/to/database.db',
schema: DatabaseSchema(
tables: [todosTable],
),
onCreate: (db, version) {
// Create tables
},
onUpgrade: (db, oldVersion, newVersion) {
// Handle database upgrade
},
onDowngrade: (db, oldVersion, newVersion) {
// Handle database downgrade
},
onOpen: (db) {
// Handle database open
},
),
);