### Getting Started with SqliteDatabase Source: https://github.com/powersync-ja/sqlite_async.dart/blob/main/packages/sqlite_async/README.md Demonstrates basic usage of the sqlite_async package, including defining and running migrations, performing INSERT/UPDATE/DELETE operations with executeBatch, querying data with getAll, and executing multiple statements atomically within a write transaction. ```Dart import 'package:sqlite_async/sqlite_async.dart'; final migrations = SqliteMigrations() ..add(SqliteMigration(1, (tx) async { await tx.execute( 'CREATE TABLE test_data(id INTEGER PRIMARY KEY AUTOINCREMENT, data TEXT)'); })); void main() async { final db = SqliteDatabase(path: 'test.db'); await migrations.migrate(db); // Use execute() or executeBatch() for INSERT/UPDATE/DELETE statements await db.executeBatch('INSERT INTO test_data(data) values(?)', [ ['Test1'], ['Test2'] ]); // Use getAll(), get() or getOptional() for SELECT statements var results = await db.getAll('SELECT * FROM test_data'); print('Results: $results'); // Combine multiple statements into a single write transaction for: // 1. Atomic persistence (all updates are either applied or rolled back). // 2. Improved throughput. await db.writeTransaction((tx) async { await tx.execute('INSERT INTO test_data(data) values(?)', ['Test3']); await tx.execute('INSERT INTO test_data(data) values(?)', ['Test4']); }); await db.close(); } ``` -------------------------------- ### Installing sqlite_async Package Source: https://github.com/powersync-ja/sqlite_async.dart/blob/main/packages/sqlite_async/README.md Add the sqlite_async package to your Dart or Flutter project dependencies using the Dart package manager. ```Shell dart pub add sqlite_async ``` -------------------------------- ### Initializing Drift with SqliteAsyncDriftConnection (Dart) Source: https://github.com/powersync-ja/sqlite_async.dart/blob/main/packages/drift_sqlite_async/README.md This snippet demonstrates how to create a Drift database instance (`AppDatabase`) using an `sqlite_async` database connection (`SqliteConnection`). It shows the class definition extending `_$AppDatabase` and the main function initializing both the `sqlite_async` database and the Drift database. ```Dart @DriftDatabase(tables: [TodoItems]) class AppDatabase extends _$AppDatabase { AppDatabase(SqliteConnection db) : super(SqliteAsyncDriftConnection(db)); @override int get schemaVersion => 1; } Future main() async { // The sqlite_async db final db = SqliteDatabase(path: 'example.db'); // The Drift db final appdb = AppDatabase(db); } ``` -------------------------------- ### Configuring SqliteDatabase for Web Source: https://github.com/powersync-ja/sqlite_async.dart/blob/main/packages/sqlite_async/README.md Shows how to configure the SqliteDatabase for web environments by specifying the URIs for the required sqlite3 WASM file and the web worker Javascript file using SqliteOptions and WebSqliteOptions. ```Dart import 'package:sqlite_async/sqlite_async.dart'; final db = SqliteDatabase( path: 'test.db', options: SqliteOptions( webSqliteOptions: WebSqliteOptions( wasmUri: 'sqlite3.wasm', workerUri: 'db_worker.js'))); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.