35 lines
862 B
Dart
35 lines
862 B
Dart
import 'dart:ffi';
|
|
import 'dart:io';
|
|
|
|
import 'package:jadb/search.dart';
|
|
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
|
|
import 'package:sqlite3/open.dart';
|
|
|
|
Future<JaDBConnection> setup_database_connection() async {
|
|
final lib_sqlite_path = Platform.environment['LIBSQLITE_PATH'];
|
|
final jadb_path = Platform.environment['JADB_PATH'];
|
|
|
|
if (lib_sqlite_path == null) {
|
|
throw Exception("LIBSQLITE_PATH is not set");
|
|
}
|
|
|
|
if (jadb_path == null) {
|
|
throw Exception("JADB_PATH is not set");
|
|
}
|
|
|
|
final db_connection = createDatabaseFactoryFfi(ffiInit: () {
|
|
open.overrideForAll(
|
|
() => DynamicLibrary.open(lib_sqlite_path),
|
|
);
|
|
}).openDatabase(
|
|
jadb_path,
|
|
options: OpenDatabaseOptions(
|
|
onOpen: (db) {
|
|
db.execute("PRAGMA foreign_keys = ON");
|
|
},
|
|
),
|
|
);
|
|
|
|
return JaDBConnection(await db_connection);
|
|
}
|