@@ -7,7 +7,7 @@ great as an in-app database. However, SQLite is designed for many different use
77some configuration for optimal performance as an in-app database.
88
99The [ sqlite3] ( https://pub.dev/packages/sqlite3 ) Dart bindings are great for direct synchronous access
10- to a SQLite database, but leaves the configuration the developer.
10+ to a SQLite database, but leaves the configuration up to the developer.
1111
1212This library wraps the bindings and configures the database with a good set of defaults, with
1313all database calls being asynchronous to avoid blocking the UI, while still providing direct SQL
@@ -16,6 +16,59 @@ query access.
1616## Features
1717
1818 * All operations are asynchronous by default - does not block the main isolate.
19+ * Watch a query to automatically re-run on changes to the underlying data.
1920 * Concurrent transactions supported by default - one write transaction and many multiple read transactions.
20- * Uses WAL mode with minimal locking .
21+ * Uses WAL mode for fast writes and running read transactions concurrently with a write transaction .
2122 * Direct synchronous access in an isolate is supported for performance-sensitive use cases.
23+ * Automatically convert query args to JSON where applicable, making JSON1 operations simple.
24+ * Direct SQL queries - no wrapper classes or code generation required.
25+
26+ ## Installation
27+
28+ ``` sh
29+ dart pub add sqlite_async
30+ ```
31+
32+ For flutter applications, additionally add ` sqlite3_flutter_libs ` to include the native SQLite
33+ library.
34+
35+ For other platforms, see the [ sqlite3 package docs] ( https://pub.dev/packages/sqlite3#supported-platforms ) .
36+
37+ Web is currently not supported.
38+
39+ ## Getting Started
40+
41+ ``` dart
42+ import 'package:sqlite_async/sqlite_async.dart';
43+
44+ final migrations = SqliteMigrations()
45+ ..add(SqliteMigration(1, (tx) async {
46+ await tx.execute(
47+ 'CREATE TABLE test_data(id INTEGER PRIMARY KEY AUTOINCREMENT, data TEXT)');
48+ }));
49+
50+ void main() async {
51+ final db = SqliteDatabase(path: 'test.db');
52+ await migrations.migrate(db);
53+
54+ // Use execute() or executeBatch() for INSERT/UPDATE/DELETE statements
55+ await db.executeBatch('INSERT INTO test_data(data) values(?)', [
56+ ['Test1'],
57+ ['Test2']
58+ ]);
59+
60+ // Use getAll(), get() or getOptional() for SELECT statements
61+ var results = await db.getAll('SELECT * FROM test_data');
62+ print('Results: $results');
63+
64+ // Combine multiple statements into a single write transaction for:
65+ // 1. Atomic persistence (all updates are either applied or rolled back).
66+ // 2. Improved throughput.
67+ await db.writeTransaction((tx) async {
68+ await db.execute('INSERT INTO test_data(data) values(?)', ['Test3']);
69+ await db.execute('INSERT INTO test_data(data) values(?)', ['Test4']);
70+ });
71+
72+ await db.close();
73+ }
74+ ```
0 commit comments