dust_db_sqlite3 0.1.0
dust_db_sqlite3: ^0.1.0 copied to clipboard
SQLite runtime support for generated Database code.
dust_db_sqlite3 #
SQLite runtime for generated Database code.
You focus on product. We focus on performance.
Status #
0.1.0is the first public SQLite driver release for Database.- The package provides a SQLite-backed
Executorfor generated DAO code frompackage:dust_dart/db.dart. - Database is raw SQL first. It is not an ORM and does not provide a query builder.
- Publish order matters: publish
dust_dartbefore this package.
Install #
Add the SQLite driver next to dust_dart:
dependencies:
dust_dart: ^0.1.0
dust_db_sqlite3: ^0.1.0
Open A Database #
import 'package:dust_db_sqlite3/dust_db_sqlite3.dart';
final pool = Sqlite3Pool.open('app.db');
Pass the pool to generated DAO/database code that expects
package:dust_dart/db.dart Executor.
Migrations #
Migrations run once in key order during open:
final pool = Sqlite3Pool.open(
'app.db',
migrations: const {
'0001_create_users.sql': '''
CREATE TABLE users (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL
);
''',
},
);
Applied migration names are stored in __dust_schema_migrations.
Transactions #
Use the shared Database transaction contract:
final result = await pool.transaction((tx) {
return tx.execute(
'INSERT INTO users (name) VALUES (?)',
['Ada'],
);
});
Transactions commit on Ok and roll back on Err or thrown exceptions.
Raw SQL #
Generated DAOs use typed executor methods. Handwritten escape hatches can use
raw:
final rows = await pool.raw.fetch(
'SELECT id, name FROM users WHERE id = ?',
[1],
);
Exports #
Sqlite3DriverSqlitePoolSqlite3ExecutorSqlite3Row