Skip to content

Database

This starter template creates a local database based on SQLite. For this, the Capacitor SQLite plugin is used.

Migrations

Database migrations are performed using the Upgrade Database Version feature of the Capacitor SQLite plugin. Here, all available upgrade statements are registered when the app is started. The Capacitor SQLite plugin then checks which database version is currently active and executes the corresponding upgrade statements.

This is an example for tasks database:

import { CapacitorSQLite } from '@capacitor-community/sqlite';

await CapacitorSQLite.addUpgradeStatement({
  database: 'tasks',
  upgrade: [
    {
      toVersion: 1,
      statements: [
        `CREATE TABLE tasks (id TEXT PRIMARY KEY, title TEXT, description TEXT, dueDate TEXT, createdAt TEXT, updateAt TEXT)`,
      ],
    },
  ],
});