mirror of https://github.com/AMT-Cheif/drift.git
Update docs on sqlcipher flutter libs
This commit is contained in:
parent
eb5ff82be1
commit
882aad1e65
|
@ -0,0 +1,9 @@
|
||||||
|
import 'dart:ffi';
|
||||||
|
|
||||||
|
Future<void> applyWorkaroundToOpenSqlCipherOnOldAndroidVersions() async {
|
||||||
|
throw 'stub!';
|
||||||
|
}
|
||||||
|
|
||||||
|
DynamicLibrary openCipherOnAndroid() {
|
||||||
|
throw 'stub';
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
name: sqlcipher_flutter_libs
|
||||||
|
publish_to: none
|
||||||
|
description: Fake "sqlcipher_flutter_libs" package so that we can import it in snippets without depending on Flutter.
|
||||||
|
|
||||||
|
environment:
|
||||||
|
sdk: ^2.16.0
|
|
@ -160,7 +160,7 @@ targets:
|
||||||
global_options:
|
global_options:
|
||||||
":api_index":
|
":api_index":
|
||||||
options:
|
options:
|
||||||
packages: ['drift', 'drift_dev', 'sqlite3']
|
packages: ['drift', 'drift_dev', 'sqlite3', 'sqlite3_flutter_libs', 'sqlcipher_flutter_libs']
|
||||||
|
|
||||||
additional_public_assets:
|
additional_public_assets:
|
||||||
- "pages/**"
|
- "pages/**"
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:drift/native.dart';
|
import 'package:drift/native.dart';
|
||||||
|
import 'package:drift_docs/snippets/isolates.dart';
|
||||||
import 'package:sqlite3/sqlite3.dart';
|
import 'package:sqlite3/sqlite3.dart';
|
||||||
|
|
||||||
// #docregion setup
|
// #docregion setup
|
||||||
import 'dart:ffi';
|
|
||||||
import 'package:sqlite3/open.dart';
|
import 'package:sqlite3/open.dart';
|
||||||
|
import 'package:sqlcipher_flutter_libs/sqlcipher_flutter_libs.dart';
|
||||||
|
|
||||||
// call this method before using drift
|
// call this method before using drift
|
||||||
void setupSqlCipher() {
|
Future<void> setupSqlCipher() async {
|
||||||
open.overrideFor(
|
await applyWorkaroundToOpenSqlCipherOnOldAndroidVersions();
|
||||||
OperatingSystem.android, () => DynamicLibrary.open('libsqlcipher.so'));
|
open.overrideFor(OperatingSystem.android, openCipherOnAndroid);
|
||||||
}
|
}
|
||||||
// #enddocregion setup
|
// #enddocregion setup
|
||||||
|
|
||||||
|
@ -23,9 +24,13 @@ void databases() {
|
||||||
final myDatabaseFile = File('/dev/null');
|
final myDatabaseFile = File('/dev/null');
|
||||||
|
|
||||||
// #docregion encrypted1
|
// #docregion encrypted1
|
||||||
|
final token = RootIsolateToken.instance;
|
||||||
NativeDatabase.createInBackground(
|
NativeDatabase.createInBackground(
|
||||||
myDatabaseFile,
|
myDatabaseFile,
|
||||||
isolateSetup: setupSqlCipher,
|
isolateSetup: () async {
|
||||||
|
BackgroundIsolateBinaryMessenger.ensureInitialized(token);
|
||||||
|
await setupSqlCipher();
|
||||||
|
},
|
||||||
setup: (rawDb) {
|
setup: (rawDb) {
|
||||||
rawDb.execute("PRAGMA key = 'passphrase';");
|
rawDb.execute("PRAGMA key = 'passphrase';");
|
||||||
},
|
},
|
||||||
|
@ -35,7 +40,10 @@ void databases() {
|
||||||
// #docregion encrypted2
|
// #docregion encrypted2
|
||||||
NativeDatabase.createInBackground(
|
NativeDatabase.createInBackground(
|
||||||
myDatabaseFile,
|
myDatabaseFile,
|
||||||
isolateSetup: setupSqlCipher,
|
isolateSetup: () async {
|
||||||
|
BackgroundIsolateBinaryMessenger.ensureInitialized(token);
|
||||||
|
await setupSqlCipher();
|
||||||
|
},
|
||||||
setup: (rawDb) {
|
setup: (rawDb) {
|
||||||
assert(_debugCheckHasCipher(rawDb));
|
assert(_debugCheckHasCipher(rawDb));
|
||||||
rawDb.execute("PRAGMA key = 'passphrase';");
|
rawDb.execute("PRAGMA key = 'passphrase';");
|
||||||
|
|
|
@ -62,7 +62,7 @@ To use `sqlcipher`, add a dependency on `sqlcipher_flutter_libs`:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
dependencies:
|
dependencies:
|
||||||
sqlcipher_flutter_libs: ^0.5.0
|
sqlcipher_flutter_libs: ^0.6.0
|
||||||
```
|
```
|
||||||
|
|
||||||
If you already have a dependency on `sqlite3_flutter_libs`, __drop that dependency__.
|
If you already have a dependency on `sqlite3_flutter_libs`, __drop that dependency__.
|
||||||
|
@ -77,14 +77,13 @@ of the regular `libsqlite3.so`:
|
||||||
When using drift on a background database, you need to call `setupSqlCipher` on the background isolate
|
When using drift on a background database, you need to call `setupSqlCipher` on the background isolate
|
||||||
as well. With `NativeDatabase.createInBackground`, which are using isolates internally, you can use
|
as well. With `NativeDatabase.createInBackground`, which are using isolates internally, you can use
|
||||||
the `setupIsolate` callback to do this - the examples on this page use this as well.
|
the `setupIsolate` callback to do this - the examples on this page use this as well.
|
||||||
|
Since `applyWorkaroundToOpenSqlCipherOnOldAndroidVersions()` invokes a platform channel, one needs
|
||||||
|
to install a `BackgroundIsolateBinaryMessenger` on the isolate as well.
|
||||||
|
|
||||||
On iOS and macOS, no additional setup is necessary - simply depend on `sqlcipher_flutter_libs`.
|
On iOS, macOS and Windows, no additional setup is necessary - simply depend on `sqlcipher_flutter_libs`.
|
||||||
|
For Linux builds, note that OpenSSL is linked statically by default. If you want to compile your app to use
|
||||||
On Windows and Linux, you currently have to include a version of SQLCipher manually when you distribute
|
a dynamically-linked distribution of OpenSSL, see [this](https://github.com/simolus3/sqlite3.dart/issues/186#issuecomment-1742110933)
|
||||||
your app.
|
issue comment.
|
||||||
For more information on this, you can use the documentation [here]({{ '../Platforms/index.md#bundling-sqlite-with-your-app' | pageUrl }}).
|
|
||||||
Instead of including `sqlite3.dll` or `libsqlite3.so`, you'd include the respective versions
|
|
||||||
of SQLCipher.
|
|
||||||
|
|
||||||
### Using
|
### Using
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,8 @@ dependencies:
|
||||||
path: assets/path_provider
|
path: assets/path_provider
|
||||||
sqlite3_flutter_libs:
|
sqlite3_flutter_libs:
|
||||||
path: assets/sqlite3_flutter_libs
|
path: assets/sqlite3_flutter_libs
|
||||||
|
sqlcipher_flutter_libs:
|
||||||
|
path: assets/sqlcipher_flutter_libs
|
||||||
# Used in examples
|
# Used in examples
|
||||||
rxdart: ^0.27.3
|
rxdart: ^0.27.3
|
||||||
yaml: ^3.1.1
|
yaml: ^3.1.1
|
||||||
|
|
Loading…
Reference in New Issue