mirror of https://github.com/AMT-Cheif/drift.git
Merge branch 'develop'
This commit is contained in:
commit
27e103aa01
|
@ -192,7 +192,7 @@ with the `separator` argument on `groupConcat`.
|
|||
|
||||
## Mathematical functions and regexp
|
||||
|
||||
When using a `VmDatabase`, a basic set of trigonometric functions will be available.
|
||||
When using a `NativeDatabase`, a basic set of trigonometric functions will be available.
|
||||
It also defines the `REGEXP` function, which allows you to use `a REGEXP b` in sql queries.
|
||||
For more information, see the [list of functions]({{ "../Other engines/vm.md#moor-only-functions" | pageUrl }}) here.
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ Next, re-run the build. You can now add another constructor to the generated dat
|
|||
```dart
|
||||
@DriftDatabase(...)
|
||||
class TodoDb extends _$TodoDb {
|
||||
TodoDb() : super(VmDatabase.memory());
|
||||
TodoDb() : super(NativeDatabase.memory());
|
||||
|
||||
// this is the new constructor
|
||||
TodoDb.connect(DatabaseConnection connection) : super.connect(connection);
|
||||
|
@ -38,11 +38,11 @@ import 'package:drift/isolate.dart';
|
|||
// This needs to be a top-level method because it's run on a background isolate
|
||||
DatabaseConnection _backgroundConnection() {
|
||||
// Construct the database to use. This example uses a non-persistent in-memory database each
|
||||
// time. You can use your existing VmDatabase with a file as well, or a `LazyDatabase` if you
|
||||
// time. You can use your existing NativeDatabase with a file as well, or a `LazyDatabase` if you
|
||||
// need to construct it asynchronously.
|
||||
// When using a Flutter plugin like `path_provider` to determine the path, also see the
|
||||
// "Initialization on the main thread" section below!
|
||||
final database = VmDatabase.memory();
|
||||
final database = NativeDatabase.memory();
|
||||
return DatabaseConnection.fromExecutor(database);
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ LazyDatabase _openConnection() {
|
|||
await file.writeAsBytes(blob);
|
||||
}
|
||||
|
||||
return VmDatabase(file);
|
||||
return NativeDatabase(file);
|
||||
});
|
||||
}
|
||||
```
|
||||
|
|
|
@ -124,7 +124,7 @@ LazyDatabase _openConnection() {
|
|||
// for your app.
|
||||
final dbFolder = await getApplicationDocumentsDirectory();
|
||||
final file = File(p.join(dbFolder.path, 'db.sqlite'));
|
||||
return VmDatabase(file);
|
||||
return NativeDatabase(file);
|
||||
});
|
||||
}
|
||||
```
|
||||
|
|
|
@ -32,7 +32,7 @@ dependencies:
|
|||
Instead of importing `package:moor_flutter/moor_flutter` (or `package:drift/native.dart`) in your apps,
|
||||
you would then import both `package:drift/drift.dart` and `package:encrypted_moor/encrypted_moor.dart`.
|
||||
|
||||
Finally, you can replace `FlutterQueryExecutor` (or an `VmDatabase`) with an `EncryptedExecutor`.
|
||||
Finally, you can replace `FlutterQueryExecutor` (or a `NativeDatabase`) with an `EncryptedExecutor`.
|
||||
|
||||
### Extra setup on Android and iOS
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ import 'package:path/path.dart' as p;
|
|||
LazyDatabase(() async {
|
||||
final dbFolder = await getDatabasesPath();
|
||||
final file = File(p.join(dbFolder, 'db.sqlite'));
|
||||
return VmDatabase(file);
|
||||
return NativeDatabase(file);
|
||||
})
|
||||
```
|
||||
|
||||
|
@ -82,7 +82,7 @@ Please be aware that `FlutterQueryExecutor.inDatabaseFolder` might yield a diffe
|
|||
|
||||
## Using native drift with an existing database {#using-moor-ffi-with-an-existing-database}
|
||||
|
||||
If your existing sqlite database is stored as a file, you can just use `VmDatabase(thatFile)` - no further
|
||||
If your existing sqlite database is stored as a file, you can just use `NativeDatabase(thatFile)` - no further
|
||||
changes are required.
|
||||
|
||||
If you want to load databases from assets or any other source, you can use a `LazyDatabase`.
|
||||
|
|
|
@ -65,7 +65,7 @@ You might have to restart your IDE for the changes to apply.
|
|||
|
||||
## How can I inspect generated SQL?
|
||||
|
||||
All database implementations (`VmDatabase`, `FlutterQueryExecutor`, ...) have a `logStatements` parameter that
|
||||
All database implementations (`NativeDatabase`, `FlutterQueryExecutor`, ...) have a `logStatements` parameter that
|
||||
you can set to `true`. When enabled, drift will print the statements it runs.
|
||||
|
||||
## How do I insert data on the first app start?
|
||||
|
|
|
@ -86,7 +86,7 @@ details.
|
|||
|
||||
### macOS
|
||||
|
||||
This one is easy! Just use the `VmDatabase` from `package:drift/native.dart`. No further setup is
|
||||
This one is easy! Just use the `NativeDatabase` from `package:drift/native.dart`. No further setup is
|
||||
necessary.
|
||||
|
||||
If you need a custom sqlite3 library, or want to make sure that your app will always use a
|
||||
|
|
|
@ -70,7 +70,7 @@ all apps will run with this `PATH` change.
|
|||
## Writing tests
|
||||
|
||||
We can create an in-memory version of the database by using a
|
||||
`VmDatabase.memory()` instead of a `FlutterQueryExecutor`. A good
|
||||
`NativeDatabase.memory()` instead of a `FlutterQueryExecutor` or other implementations. A good
|
||||
place to open the database is the `setUp` and `tearDown` methods from
|
||||
`package:test`:
|
||||
```dart
|
||||
|
@ -83,7 +83,7 @@ void main() {
|
|||
MyDatabase database;
|
||||
|
||||
setUp(() {
|
||||
database = MyDatabase(VmDatabase.memory());
|
||||
database = MyDatabase(NativeDatabase.memory());
|
||||
});
|
||||
tearDown(() async {
|
||||
await database.close();
|
||||
|
|
Loading…
Reference in New Issue