-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsqlite_test.dart
More file actions
50 lines (40 loc) · 1.4 KB
/
sqlite_test.dart
File metadata and controls
50 lines (40 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import 'dart:io';
import 'package:sqlite_async/sqlite_async.dart';
import 'package:path/path.dart' as path;
final migrations = SqliteMigrations()
..add(SqliteMigration(1, (tx) async {
await tx.execute(
'CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, email TEXT)',
);
}));
// ignore: public_member_api_docs
void copyBinaryIfNecessary() {
const libraryName = 'libsqlite3.so';
final systemBinary = File('/lib/$libraryName')..createSync(recursive: true);
final customBinary =
File(path.join(Directory.current.path, 'target', 'debug', libraryName));
customBinary.copySync(systemBinary.path);
}
void main() async {
copyBinaryIfNecessary();
final db = SqliteDatabase(path: 'simple-nubian');
await migrations.migrate(db);
// // Use execute() or executeBatch() for INSERT/UPDATE/DELETE statements
// await db.executeBatch('INSERT INTO users(name, email) values(?, ?)', [
// ['Amen', 'oxy@gmail.com'],
// ['Moron', 'moron@gmail.com']
// ]);
// var results = await db.getAll('SELECT * FROM users');
// print('Results: $results');
// await db.writeTransaction((tx) async {
// await tx.execute(
// 'INSERT INTO users(name, email) values(?, ?)',
// ['Test3', 'test3@example.com'],
// );
// await tx.execute(
// 'INSERT INTO users(name, email) values(?, ?)',
// ['Test4', 'test4@example.com'],
// );
// });
// await db.close();
}