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:
|
||||
":api_index":
|
||||
options:
|
||||
packages: ['drift', 'drift_dev', 'sqlite3']
|
||||
packages: ['drift', 'drift_dev', 'sqlite3', 'sqlite3_flutter_libs', 'sqlcipher_flutter_libs']
|
||||
|
||||
additional_public_assets:
|
||||
- "pages/**"
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
import 'dart:io';
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:drift_docs/snippets/isolates.dart';
|
||||
import 'package:sqlite3/sqlite3.dart';
|
||||
|
||||
// #docregion setup
|
||||
import 'dart:ffi';
|
||||
import 'package:sqlite3/open.dart';
|
||||
import 'package:sqlcipher_flutter_libs/sqlcipher_flutter_libs.dart';
|
||||
|
||||
// call this method before using drift
|
||||
void setupSqlCipher() {
|
||||
open.overrideFor(
|
||||
OperatingSystem.android, () => DynamicLibrary.open('libsqlcipher.so'));
|
||||
Future<void> setupSqlCipher() async {
|
||||
await applyWorkaroundToOpenSqlCipherOnOldAndroidVersions();
|
||||
open.overrideFor(OperatingSystem.android, openCipherOnAndroid);
|
||||
}
|
||||
// #enddocregion setup
|
||||
|
||||
|
@ -23,9 +24,13 @@ void databases() {
|
|||
final myDatabaseFile = File('/dev/null');
|
||||
|
||||
// #docregion encrypted1
|
||||
final token = RootIsolateToken.instance;
|
||||
NativeDatabase.createInBackground(
|
||||
myDatabaseFile,
|
||||
isolateSetup: setupSqlCipher,
|
||||
isolateSetup: () async {
|
||||
BackgroundIsolateBinaryMessenger.ensureInitialized(token);
|
||||
await setupSqlCipher();
|
||||
},
|
||||
setup: (rawDb) {
|
||||
rawDb.execute("PRAGMA key = 'passphrase';");
|
||||
},
|
||||
|
@ -35,7 +40,10 @@ void databases() {
|
|||
// #docregion encrypted2
|
||||
NativeDatabase.createInBackground(
|
||||
myDatabaseFile,
|
||||
isolateSetup: setupSqlCipher,
|
||||
isolateSetup: () async {
|
||||
BackgroundIsolateBinaryMessenger.ensureInitialized(token);
|
||||
await setupSqlCipher();
|
||||
},
|
||||
setup: (rawDb) {
|
||||
assert(_debugCheckHasCipher(rawDb));
|
||||
rawDb.execute("PRAGMA key = 'passphrase';");
|
||||
|
|
|
@ -62,7 +62,7 @@ To use `sqlcipher`, add a dependency on `sqlcipher_flutter_libs`:
|
|||
|
||||
```yaml
|
||||
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__.
|
||||
|
@ -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
|
||||
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.
|
||||
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 Windows and Linux, you currently have to include a version of SQLCipher manually when you distribute
|
||||
your app.
|
||||
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.
|
||||
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
|
||||
a dynamically-linked distribution of OpenSSL, see [this](https://github.com/simolus3/sqlite3.dart/issues/186#issuecomment-1742110933)
|
||||
issue comment.
|
||||
|
||||
### Using
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@ dependencies:
|
|||
path: assets/path_provider
|
||||
sqlite3_flutter_libs:
|
||||
path: assets/sqlite3_flutter_libs
|
||||
sqlcipher_flutter_libs:
|
||||
path: assets/sqlcipher_flutter_libs
|
||||
# Used in examples
|
||||
rxdart: ^0.27.3
|
||||
yaml: ^3.1.1
|
||||
|
|
Loading…
Reference in New Issue