1- import 'dart:ffi' ;
2-
31import 'package:powersync_core/powersync_core.dart' ;
42import 'package:powersync_core/sqlite3_common.dart' ;
53import 'package:powersync_core/sqlite3_open.dart' as sqlite3_open;
64import 'package:powersync_core/sqlite_async.dart' ;
7- import 'package:powersync_core/sqlite3.dart' as sqlite;
85import 'package:sqlcipher_flutter_libs/sqlcipher_flutter_libs.dart' ;
9- import 'package:universal_io/io.dart' ;
106
117/// A factory for opening a database with SQLCipher encryption.
12- /// An encryption [key] is required
13- class PowerSyncSQLCipherOpenFactory extends AbstractPowerSyncOpenFactory {
14- PowerSyncSQLCipherOpenFactory ({
15- required super .path,
16- required this .key,
17- super .sqliteOptions = powerSyncDefaultSqliteOptions,
18- });
8+ /// An encryption [key] is required to open the database.
9+ class PowerSyncSQLCipherOpenFactory extends PowerSyncOpenFactory {
10+ PowerSyncSQLCipherOpenFactory (
11+ {required super .path, required this .key, super .sqliteOptions});
1912
2013 final String key;
2114
22- @override
23- void enableExtension () {
24- var powersyncLib = _getDynamicLibraryForPlatform ();
25- sqlite.sqlite3.ensureExtensionLoaded (sqlite.SqliteExtension .inLibrary (
26- powersyncLib, 'sqlite3_powersync_init' ));
27- }
28-
29- /// Returns the dynamic library for the current platform.
30- DynamicLibrary _getDynamicLibraryForPlatform () {
31- /// When running tests, we need to load the library for all platforms.
32- if (Platform .environment.containsKey ('FLUTTER_TEST' )) {
33- return DynamicLibrary .open (getLibraryForPlatform ());
34- }
35- return (Platform .isIOS || Platform .isMacOS)
36- ? DynamicLibrary .process ()
37- : DynamicLibrary .open (getLibraryForPlatform ());
38- }
39-
4015 @override
4116 List <String > pragmaStatements (SqliteOpenOptions options) {
4217 final basePragmaStatements = super .pragmaStatements (options);
@@ -53,13 +28,6 @@ class PowerSyncSQLCipherOpenFactory extends AbstractPowerSyncOpenFactory {
5328 sqlite3_open.open
5429 .overrideFor (sqlite3_open.OperatingSystem .android, openCipherOnAndroid);
5530
56- try {
57- enableExtension ();
58- } on PowersyncNotReadyException catch (e) {
59- autoLogger.severe (e.message);
60- rethrow ;
61- }
62-
6331 var db = super .open (options);
6432 final versionRows = db.select ('PRAGMA cipher_version' );
6533 if (versionRows.isEmpty) {
@@ -71,34 +39,4 @@ class PowerSyncSQLCipherOpenFactory extends AbstractPowerSyncOpenFactory {
7139 }
7240 return db;
7341 }
74-
75- @override
76- String getLibraryForPlatform ({String ? path}) {
77- switch (Abi .current ()) {
78- case Abi .androidArm:
79- case Abi .androidArm64:
80- case Abi .androidX64:
81- return 'libpowersync.so' ;
82- case Abi .macosArm64:
83- case Abi .macosX64:
84- return 'libpowersync.dylib' ;
85- case Abi .linuxX64:
86- return 'libpowersync_x64.so' ;
87- case Abi .linuxArm64:
88- return 'libpowersync_aarch64.so' ;
89- case Abi .windowsX64:
90- return 'powersync_x64.dll' ;
91- case Abi .androidIA32:
92- throw PowersyncNotReadyException (
93- 'Unsupported processor architecture. X86 Android emulators are not '
94- 'supported. Please use an x86_64 emulator instead. All physical '
95- 'Android devices are supported including 32bit ARM.' ,
96- );
97- default :
98- throw PowersyncNotReadyException (
99- 'Unsupported processor architecture "${Abi .current ()}". '
100- 'Please open an issue on GitHub to request it.' ,
101- );
102- }
103- }
10442}
0 commit comments