sqlite3
3.9.1, released 12 days ago by simonbinder.eu
Lightweight and convenient SQLite bindings for Dart using dart:ffi
Rock solid
What it does
Provides direct and synchronous access to SQLite databases on native platforms and the web. It bundles SQLite using hooks, avoiding external build configurations for most apps, and supports virtual file systems on the web.
AI-written summary of version 3.9.1, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need direct, low-level SQL database operations in Dart or Flutter.
- You want cross-platform SQLite support including native platforms and the web.
Skip it when
- You prefer an ORM or type-safe query builders.
- You need an asynchronous database driver out-of-the-box without manual isolate management.
Strengths
- Bundles SQLite using hooks so no external dependencies are needed.
- Supports web through WebAssembly and virtual file systems.
- Provides both native and web APIs as well as a common shared interface.
Weaknesses
- Operates synchronously on the main thread by default, requiring manual background isolates for optimal performance in large apps.
- Web setup requires downloading and hosting a separate WebAssembly module.
Setup
- Kind
- FFI (native library)
- Effort
- Low
- Code generation
- Yes (build_runner)
- Direct dependencies
- 10
Simply add the dependency via pub. For web usage, a sqlite3.wasm file must be provided and loaded manually.
import 'package:sqlite3/sqlite3.dart';
void main() {
final db = sqlite3.open('test.db');
db.execute('CREATE TABLE users (id INTEGER NOT NULL PRIMARY KEY, name TEXT) STRICT');
db.execute('INSERT INTO users (name) VALUES (?)', ['SQLite user']);
print(db.select('SELECT * FROM users'));
}Alternatives
Packages that do the same job and could replace sqlite3.
Works with
Packages commonly used together with sqlite3: ones it builds on, ones built on it, and its own family.
- cryptosqlite3 depends on itProvides SHA, MD5, and HMAC hashing functions for Dart.
- websqlite3 depends on itLightweight bindings for browser APIs via JS interop
- hookssqlite3 depends on itDart API for the JSON-based protocol for package build and link hooks.
- code_assetssqlite3 depends on itProvides the hook protocol specification for bundling native code with Dart packages.
- ffisqlite3 depends on itUtilities for working with Foreign Function Interface (FFI) code in Dart.
- typed_datasqlite3 depends on itUtility functions and classes for easier work with dart:typed_data lists.
- native_toolchain_csqlite3 depends on itInvoke the native C compiler installed on the host machine.
- sqlite3_flutter_libsSame familyObsolete package that once bundled native SQLite libraries for Flutter; now contains no code.