sqflite-common-api

Write Flutter-free Dart code against the sqflite SQLite API with injected database factories.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Shared Dart packages that need SQLite cannot depend on the Flutter-only sqflite plugin, and developers struggle to write database code that runs identically on mobile, desktop, the Dart VM, tests, and the web. ## Core Features & Use Cases - Flutter-free database layer: Use the full sqflite API (DatabaseFactory, Database, Transaction, Batch, OpenDatabaseOptions) from package:sqflite_common with no Flutter dependency, injecting a factory from sqflite, sqflite_common_ffi, or sqflite_common_ffi_web. - Correct import and semantics guidance: Covers which library exports which types, transaction and batch semantics, cursor-based iteration with queryIterate, prepared SqfliteSqlCommand objects, sandboxed factories, and statement logging via SqfliteDatabaseFactoryLogger. - Use Case: Build a TodoRepository package that depends only on sqflite_common, test it with databaseFactoryFfi and an in-memory database in dart test, then pass the Flutter databaseFactory in the production app without changing repository code. ## Quick Start Ask the AI to write a Flutter-free Dart repository class using sqflite_common that opens a database through an injected DatabaseFactory and runs a transaction.

Frequently Asked Questions about sqflite-common-api

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

FAQPage Schema
How do I use sqflite in Dart tests without Flutter?▼

Depend on sqflite_common in your package and add sqflite_common_ffi as a dev dependency. Call sqfliteFfiInit in setUpAll, then pass databaseFactoryFfi to your code; inMemoryDatabasePath gives an isolated in-memory database per test.

What is the difference between sqflite and sqflite_common?▼

sqflite is the Flutter plugin providing a SQLite engine on Android, iOS, and macOS, while sqflite_common defines the pure-Dart API with no Flutter dependency and no engine. Libraries should depend on sqflite_common and accept a DatabaseFactory from the caller.

Which sqflite_common import should a library use?▼

Libraries should import package:sqflite_common/sqlite_api.dart, which exposes only the types like DatabaseFactory, Database, and Transaction. Importing sqflite.dart additionally reads the global databaseFactory, which forces the consuming app to initialize it.

Why does openDatabase throw StateError databaseFactory not initialized?▼

The global databaseFactory in sqflite.dart throws StateError until an implementation package sets it. The application must assign databaseFactory first, for example databaseFactory = databaseFactoryFfi from sqflite_common_ffi, before calling the global openDatabase.

Can I use db inside a sqflite transaction callback?▼

No, inside db.transaction((txn) async {...}) you must use only the txn object for all operations. The transaction commits when the callback returns and rolls back when it throws; onCreate and onUpgrade callbacks are already inside a transaction.

How do I stream large query results in sqflite?▼

Use queryIterate or rawQueryIterate with a bufferSize (default 100) and an onRow callback, or use queryCursor with moveNext and close. Returning false from onRow stops iteration early.