11import 'dart:io' ;
22
3- import 'package:sqlite3/sqlite3 .dart' ;
3+ import 'package:sqlite_async/sqlite_async .dart' ;
44import 'package:path/path.dart' as path;
55
6+ final migrations = SqliteMigrations ()
7+ ..add (SqliteMigration (1 , (tx) async {
8+ await tx.execute (
9+ 'CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, email TEXT)' ,
10+ );
11+ }));
12+
613// ignore: public_member_api_docs
714void copyBinaryIfNecessary () {
815 const libraryName = 'libsqlite3.so' ;
@@ -13,24 +20,31 @@ void copyBinaryIfNecessary() {
1320 customBinary.copySync (systemBinary.path);
1421}
1522
16- void main () {
23+ void main () async {
1724 copyBinaryIfNecessary ();
18-
19- const commmands = [
20- 'CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT, email TEXT)' ,
21- // "INSERT INTO users (name, email) VALUES ('Alice', '[email protected] ')", 22- ];
23-
24- final db = sqlite3.open ('untrue-necklace' );
25- for (final command in commmands) db.execute (command);
26-
27- // fetch data
28- final result = db.select ("SELECT * FROM users" );
29- for (final row in result) {
30- stdout.writeln (
31- 'Artist[id: ${row ['id' ]}, name: ${row ['name' ]}, email: ${row ['email' ]}]' ,
32- );
33- }
34-
35- db.dispose ();
25+ final db = SqliteDatabase (path: 'simple-nubian' );
26+
27+ await migrations.migrate (db);
28+
29+ // // Use execute() or executeBatch() for INSERT/UPDATE/DELETE statements
30+ // await db.executeBatch('INSERT INTO users(name, email) values(?, ?)', [
31+ 32+ 33+ // ]);
34+
35+ // var results = await db.getAll('SELECT * FROM users');
36+ // print('Results: $results');
37+
38+ // await db.writeTransaction((tx) async {
39+ // await tx.execute(
40+ // 'INSERT INTO users(name, email) values(?, ?)',
41+ // ['Test3', '[email protected] '], 42+ // );
43+ // await tx.execute(
44+ // 'INSERT INTO users(name, email) values(?, ?)',
45+ // ['Test4', '[email protected] '], 46+ // );
47+ // });
48+
49+ // await db.close();
3650}
0 commit comments