Skip to main content

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.
ParameterDescriptionRequiredDefault
versionThe database version numberNo1
dbPathPath to the SQLite database fileYes-
onCreateCallback function called when database is first createdYes-
onConfigureCallback function to configure the databaseNonull
onUpgradeCallback function to handle database version upgradesNonull
onDowngradeCallback function to handle database version downgradesNonull
onOpenCallback function called when database is openedNonull
schemaDatabase schemaNonull

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
    },
  ),
);