mirror of https://github.com/AMT-Cheif/drift.git
RELEASE
- moor 2.1.0 - moor_generator 2.1.0 - sqlparser 0.4.0 - moor_ffi 0.2.0
This commit is contained in:
parent
3bd2a221a4
commit
598fef750e
|
@ -77,6 +77,7 @@ linter:
|
|||
- unnecessary_getters_setters
|
||||
- unnecessary_lambdas
|
||||
- unnecessary_new
|
||||
- unnecessary_const
|
||||
- unnecessary_null_aware_assignments
|
||||
- unnecessary_statements
|
||||
- unnecessary_this
|
||||
|
|
|
@ -36,36 +36,44 @@ DynamicLibrary _openOnLinux() {
|
|||
|
||||
## Migrating from moor_flutter to moor_ffi
|
||||
|
||||
1. Adapt your `pubspec.yaml`: You can remove the `moor_flutter` dependency and instead
|
||||
add both the `moor` and `moor_ffi` dependencies:
|
||||
```yaml
|
||||
dependencies:
|
||||
moor: ^2.0.0
|
||||
moor_ffi: ^0.2.0
|
||||
dev_dependencies:
|
||||
moor_generator: ^2.0.0
|
||||
```
|
||||
Note: If you were using `FlutterQueryExecutor.inDatabasesFolder`, you should also depend
|
||||
on `path_provider`. For desktop support of that library, see [this readme](https://github.com/google/flutter-desktop-embedding/tree/master/plugins/flutter_plugins).
|
||||
2. Adapt your imports:
|
||||
If you're not running into a limitation that forces you to use `moor_ffi`, be aware
|
||||
that staying on `moor_flutter` is a more stable solution at the moment.
|
||||
|
||||
First, adapt your `pubspec.yaml`: You can remove the `moor_flutter` dependency and instead
|
||||
add both the `moor` and `moor_ffi` dependencies:
|
||||
```yaml
|
||||
dependencies:
|
||||
moor: ^2.0.0
|
||||
moor_ffi: ^0.2.0
|
||||
sqflite: ^1.1.7 # Still used to obtain the database location
|
||||
dev_dependencies:
|
||||
moor_generator: ^2.0.0
|
||||
```
|
||||
|
||||
Adapt your imports:
|
||||
|
||||
- In the file where you created a `FlutterQueryExecutor`, replace the `moor_flutter` import
|
||||
with `package:moor_ffi/moor_ffi.dart`.
|
||||
- In all other files where you might have import `moor_flutter`, just import `package:moor/moor.dart`.
|
||||
3. Replace the executor. This code:
|
||||
```dart
|
||||
FlutterQueryExecutor.inDatabaseFolder(path: 'db.sqlite')
|
||||
```
|
||||
can now be written as
|
||||
```dart
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
Replace the executor. This code:
|
||||
```dart
|
||||
FlutterQueryExecutor.inDatabaseFolder(path: 'db.sqlite')
|
||||
```
|
||||
can now be written as
|
||||
```dart
|
||||
import 'package:sqflite/sqflite.dart' show getDatabasesPath;
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
LazyDatabase(() async {
|
||||
final dbFolder = await getApplicationDocumentsDirectory();
|
||||
final file = File(j.join(dbFolder.path, 'db.sqlite'));
|
||||
return VmDatabase(file);
|
||||
})
|
||||
```
|
||||
__Important warning__: On Android, `FlutterQueryExecutor.inDatabaseFolder` may use a different folder than
|
||||
`getApplicationDocumentsDirectory()` which can cause data loss when migrating.
|
||||
Please create an issue if you need guidance on this soon.
|
||||
LazyDatabase(() async {
|
||||
final dbFolder = await getDatabasesPath();
|
||||
final file = File(j.join(dbFolder, 'db.sqlite'));
|
||||
return VmDatabase(file);
|
||||
})
|
||||
```
|
||||
|
||||
Note: If you haven't shipped a version with `moor_flutter` to your users yet, you can drop the dependency
|
||||
on `sqflite`. Instead, you can use `path_provider` which [works on Desktop](https://github.com/google/flutter-desktop-embedding/tree/master/plugins/flutter_plugins).
|
||||
Please be aware that `FlutterQueryExecutor.inDatabaseFolder` might yield a different folder than
|
||||
`path_provider` on Android. This can cause data loss if you've already shipped a version using
|
||||
`moor_flutter`. In that case, using `getDatabasePath` from sqflite is the suggested solution.
|
|
@ -64,6 +64,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.16.1"
|
||||
ffi:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: ffi
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.1.3"
|
||||
flutter:
|
||||
dependency: "direct main"
|
||||
description: flutter
|
||||
|
@ -152,7 +159,7 @@ packages:
|
|||
name: meta
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.7"
|
||||
version: "1.1.8"
|
||||
mime:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -166,21 +173,21 @@ packages:
|
|||
path: "../../../moor"
|
||||
relative: true
|
||||
source: path
|
||||
version: "1.7.2"
|
||||
version: "2.1.0"
|
||||
moor_ffi:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "../../../moor_ffi"
|
||||
relative: true
|
||||
source: path
|
||||
version: "0.0.1"
|
||||
version: "0.2.0"
|
||||
moor_flutter:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "../../../moor_flutter"
|
||||
relative: true
|
||||
source: path
|
||||
version: "1.7.0"
|
||||
version: "2.0.0"
|
||||
multi_server_socket:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -404,5 +411,5 @@ packages:
|
|||
source: hosted
|
||||
version: "2.2.0"
|
||||
sdks:
|
||||
dart: ">=2.5.0-dev <=2.6.0-dev.1.0.flutter-7c1821c4aa"
|
||||
dart: ">=2.6.0 <3.0.0"
|
||||
flutter: ">=1.2.1 <2.0.0"
|
||||
|
|
|
@ -14,7 +14,7 @@ even have a builtin IDE for SQL!
|
|||
- __🛡️ Safe__: Moor generates typesafe code based on your tables and queries. If you make a mistake in your queries, moor will find it at compile time and
|
||||
provide helpful and descriptive lints.
|
||||
- __⚡ Fast__: Even though moor lets you write powerful queries, it can keep
|
||||
up with the performance of key-value stores like shared preferences and Hive. Moor is the only major persistence library with builtin threading support, allowing you to run database code across isolates with zero additional effort.
|
||||
up with the performance of key-value stores. Moor is the only major persistence library with builtin threading support, allowing you to run database code across isolates with zero additional effort.
|
||||
- __Reactive__: Turn any sql query into an auto-updating stream! This includes complex queries across many tables
|
||||
- __⚙️ Cross-Platform support__: Moor works on Android, iOS, macOS, Windows, Linux and the web. [This template](https://github.com/appleeducate/moor_shared) is a Flutter todo app that works on all platforms
|
||||
- __🗡️ Battle tested and production ready__: Moor is stable and well tested with a wide range of unit and integration tests. It powers production Flutter apps.
|
||||
|
|
|
@ -27,8 +27,8 @@ dev_dependencies:
|
|||
test: ^1.9.0
|
||||
mockito: ^4.1.0
|
||||
|
||||
dependency_overrides:
|
||||
moor_generator:
|
||||
path: ../moor_generator
|
||||
sqlparser:
|
||||
path: ../sqlparser
|
||||
#dependency_overrides:
|
||||
# moor_generator:
|
||||
# path: ../moor_generator
|
||||
# sqlparser:
|
||||
# path: ../sqlparser
|
|
@ -1,18 +1,10 @@
|
|||
# moor_ffi
|
||||
|
||||
Experimental Dart bindings to sqlite by using `dart:ffi`. This library contains utils to make
|
||||
Dart bindings to sqlite by using `dart:ffi`. This library contains utils to make
|
||||
integration with [moor](https://pub.dev/packages/moor) easier, but it can also be used
|
||||
as a standalone package. It also doesn't depend on Flutter, so it can be used on Dart VM
|
||||
applications as well.
|
||||
|
||||
## Warnings
|
||||
At the moment, `dart:ffi` is in preview and there will be breaking changes that this
|
||||
library has to adapt to. This library has been tested on Dart `2.5.0`.
|
||||
If you're using a development Dart version (this can include any Flutter channels that
|
||||
are not `stable`), this library might not work.
|
||||
|
||||
Also, please don't use this library on production apps yet.
|
||||
|
||||
## Supported platforms
|
||||
You can make this library work on any platform that lets you obtain a `DynamicLibrary`
|
||||
in which sqlite's symbols are available (see below).
|
||||
|
@ -24,7 +16,7 @@ Out of the box, this library supports all platforms where `sqlite3` is installed
|
|||
- Windows: Additional setup is required
|
||||
- Android: Yes when used with Flutter
|
||||
|
||||
This library works with and without Flutter.
|
||||
Unless explicitly noted, this library works with and without Flutter.
|
||||
If you're using Flutter, this library will bundle `sqlite3` in your Android app. This
|
||||
requires the Android NDK to be installed (You can get the NDK in the [SDK Manager](https://developer.android.com/studio/intro/update.html#sdk-manager)
|
||||
of Android Studio). Note that the first `flutter run` is going to take a very long time as
|
||||
|
@ -73,27 +65,39 @@ void main() {
|
|||
}
|
||||
```
|
||||
|
||||
You can also use an asynchronous API on a background isolate by using `IsolateDb.openFile`
|
||||
or `IsolateDb.openMemory`, respectively. Be aware that the asynchronous API is much slower,
|
||||
but it moves work out of the UI isolate.
|
||||
|
||||
Be sure to __always__ call `Database.close` to avoid memory leaks!
|
||||
|
||||
## Using with moor
|
||||
Add both `moor` and `moor_ffi` to your pubspec, the `moor_flutter` dependency can be dropped.
|
||||
If you're migrating an existing project using `moor_flutter`, see the
|
||||
[documentation](https://moor.simonbinder.eu/docs/other-engines/vm/#migrating-from-moor-flutter-to-moor-ffi).
|
||||
|
||||
Add both `moor` and `moor_ffi` to your pubspec:
|
||||
```yaml
|
||||
dependencies:
|
||||
moor: ^1.7.0
|
||||
moor_ffi: ^0.0.1
|
||||
moor: ^2.0.0
|
||||
moor_ffi: ^0.2.0
|
||||
dev_dependencies:
|
||||
moor_generator: ^1.7.0
|
||||
moor_generator: ^2.0.0
|
||||
```
|
||||
|
||||
In the file where you created a `FlutterQueryExecutor`, replace the `moor_flutter` import
|
||||
with both `package:moor/moor.dart` and `package:moor_ffi/moor_ffi.dart`.
|
||||
In all other project files that use moor apis (e.g. a `Value` class for companions), just import `package:moor/moor.dart`.
|
||||
You can then use a `VmDatabase` as an executor:
|
||||
```dart
|
||||
@UseMoor(...)
|
||||
class MyDatabase extends _$MyDatabase {
|
||||
|
||||
Finally, replace usages of `FlutterQueryExecutor` with `VmDatabase`.
|
||||
MyDatabase(): super(VmDatabase(File('app.db')));
|
||||
}
|
||||
```
|
||||
If you need to find an appropriate directory for the database file, you can use the `LazyDatabase` wrapper
|
||||
from moor. It can be used to create the inner `VmDatabase` asynchronously:
|
||||
```dart
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
Note that, at the moment, there is no direct counterpart for `FlutterQueryExecutor.inDatabasePath`.
|
||||
// use this instead of VmDatabase(...)
|
||||
LazyDatabase(() async {
|
||||
final dbFolder = await getApplicationDocumentsDirectory();
|
||||
final file = File(p.join(dbFolder.path, 'app.db'));
|
||||
return VmDatabase(file);
|
||||
});
|
||||
```
|
|
@ -1,5 +1,5 @@
|
|||
name: moor_ffi
|
||||
description: "Provides experimental sqlite bindings using dart:ffi, including a moor executor"
|
||||
description: "Provides sqlite bindings using dart:ffi, including a moor executor"
|
||||
version: 0.2.0
|
||||
author: Simon Binder <oss@simonbinder.eu>
|
||||
homepage: https://github.com/simolus3/moor/tree/develop/moor_ffi
|
||||
|
|
|
@ -13,8 +13,6 @@ even have a builtin IDE for SQL!
|
|||
- __📦 Modular__: Thanks to builtin support for daos and `import`s in sql files, moor helps you keep your database code simple.
|
||||
- __🛡️ Safe__: Moor generates typesafe code based on your tables and queries. If you make a mistake in your queries, moor will find it at compile time and
|
||||
provide helpful and descriptive lints.
|
||||
- __⚡ Fast__: Even though moor lets you write powerful queries, it can keep
|
||||
up with the performance of key-value stores like shared preferences and Hive. Moor is the only major persistence library with builtin threading support, allowing you to run database code across isolates with zero additional effort.
|
||||
- __Reactive__: Turn any sql query into an auto-updating stream! This includes complex queries across many tables
|
||||
- __⚙️ Cross-Platform support__: Moor works on Android, iOS, macOS, Windows, Linux and the web. [This template](https://github.com/appleeducate/moor_shared) is a Flutter todo app that works on all platforms
|
||||
- __🗡️ Battle tested and production ready__: Moor is stable and well tested with a wide range of unit and integration tests. It powers production Flutter apps.
|
||||
|
|
|
@ -7,9 +7,9 @@ part of '../steps.dart';
|
|||
///
|
||||
/// Notably, this step does not analyze defined queries.
|
||||
class ParseDartStep extends Step {
|
||||
static const _tableTypeChecker = const TypeChecker.fromRuntime(Table);
|
||||
static const _useMoorChecker = const TypeChecker.fromRuntime(UseMoor);
|
||||
static const _useDaoChecker = const TypeChecker.fromRuntime(UseDao);
|
||||
static const _tableTypeChecker = TypeChecker.fromRuntime(Table);
|
||||
static const _useMoorChecker = TypeChecker.fromRuntime(UseMoor);
|
||||
static const _useDaoChecker = TypeChecker.fromRuntime(UseDao);
|
||||
|
||||
final LibraryElement library;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: moor_generator
|
||||
description: Dev-dependency to generate table and dataclasses together with the moor package.
|
||||
version: 2.0.1
|
||||
version: 2.1.0
|
||||
repository: https://github.com/simolus3/moor
|
||||
homepage: https://moor.simonbinder.eu/
|
||||
issue_tracker: https://github.com/simolus3/moor/issues
|
||||
|
|
|
@ -69,7 +69,6 @@ package to generate type-safe methods from sql.
|
|||
Most on this list is just not supported yet because I didn't found a use case for
|
||||
them yet. If you need them, just leave an issue and I'll try to implement them soon.
|
||||
|
||||
- Common table expressions are not supported
|
||||
- Some advanced expressions, like `CAST`s aren't supported yet.
|
||||
- An `UPSERT` clause is not yet supported on insert statements
|
||||
|
||||
|
|
|
@ -62,8 +62,7 @@ class SchemaFromCreateTable {
|
|||
return const ResolvedType.bool();
|
||||
}
|
||||
if (upper.contains('DATE')) {
|
||||
return const ResolvedType(
|
||||
type: BasicType.int, hint: const IsDateTime());
|
||||
return const ResolvedType(type: BasicType.int, hint: IsDateTime());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,14 +14,14 @@ const _comparisonOperators = [
|
|||
TokenType.more,
|
||||
TokenType.moreEqual,
|
||||
];
|
||||
const _binaryOperators = const [
|
||||
const _binaryOperators = [
|
||||
TokenType.shiftLeft,
|
||||
TokenType.shiftRight,
|
||||
TokenType.ampersand,
|
||||
TokenType.pipe,
|
||||
];
|
||||
|
||||
final _startOperators = const [
|
||||
const _startOperators = [
|
||||
TokenType.natural,
|
||||
TokenType.left,
|
||||
TokenType.inner,
|
||||
|
|
Loading…
Reference in New Issue