sqflite-open-database

Open, migrate, and manage SQLite databases in Flutter apps with sqflite.

3.0k|555|Updated May 22, 2017
One-click install
npx skills add https://github.com/tekartik/sqflite --skill sqflite-open-database-tekartik
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: sqflite-open-database
Source: https://github.com/tekartik/sqflite/tree/main/sqflite/skills/sqflite-open-database
Command: npx skills add https://github.com/tekartik/sqflite --skill sqflite-open-database-tekartik

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Opening and evolving a SQLite database in a Flutter app involves versioned migrations, per-connection pragmas, single-instance semantics, and platform differences that cause subtle bugs like "database is locked" errors or lost schema changes. This Skill provides the correct patterns for opening, configuring, migrating, closing, and deleting databases with package:sqflite. ## Core Features & Use Cases - Versioned migrations: Use openDatabase with version, onCreate, onUpgrade, onDowngrade, and onDatabaseDowngradeDelete, with batch-based migration chains that upgrade any old version to the newest schema. - Connection configuration: Apply PRAGMA foreign_keys, WAL journal mode, and Android locale settings in onConfigure so they are re-applied at every open. - Instance and file lifecycle: Share one Database instance across the app, copy bundled asset databases, delete databases safely with deleteDatabase, and open read-only or in-memory databases. - Use Case: You ship a Flutter app with a pre-populated catalog.db asset. Copy it to the databases path on first launch with databaseFactory.writeDatabaseBytes, then open it read-only so no migration callbacks run. ## Quick Start Ask the AI to write the code that opens a versioned sqflite database with foreign keys enabled and a migration chain for your Flutter app.

Frequently Asked Questions about sqflite-open-database

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I open and migrate a SQLite database in Flutter with sqflite?▼

Call openDatabase with a path built using join and getDatabasesPath, pass a version number, and provide onCreate and onUpgrade callbacks. Write migrations as a chain of if (oldVersion < n) blocks using a Batch, since the callbacks already run inside a transaction.

How do I ship a pre-populated SQLite database asset in a Flutter app?▼

Load the asset with rootBundle, create the target directory, and write the bytes with databaseFactory.writeDatabaseBytes to a path under getDatabasesPath. Then open it with openReadOnlyDatabase so no migration callbacks run on the shipped data.

Does sqflite work on Linux, Windows, or web?▼

No, sqflite only supports Android, iOS, and macOS. For Linux, Windows, and the Dart VM use sqflite_common_ffi, and for web use sqflite_common_ffi_web, both plugged in by assigning databaseFactory before opening.

Why do I get "database is locked (code 5)" in sqflite?▼

This happens when the same file is opened twice with singleInstance: false, creating competing connections. Keep the default singleInstance: true, store one Future<Database> for the app, and reuse that instance instead of reopening.

Where should PRAGMA foreign_keys and WAL mode be set in sqflite?▼

Set them in the onConfigure callback, because pragmas are per-connection and must be re-applied every time the database opens. Putting them in onCreate only applies them on the first creation, not on subsequent opens.

Why does onCreate not run after I delete the database file manually?▼

Deleting the file with dart:io File.delete leaves the plugin's open instance and hot-restart state intact, so sqflite does not treat it as a fresh database. Always use deleteDatabase(path), which closes the instance and removes -wal, -shm, and -journal side files.