Document how to use moor/ffi.dart

This commit is contained in:
Simon Binder 2020-07-18 18:08:38 +02:00
parent 270a29164f
commit ebb7448d1b
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
4 changed files with 35 additions and 24 deletions

View File

@ -13,14 +13,13 @@ how to get started. You can watch it [here](https://youtu.be/zpWsedYMczM).
## Adding the dependency
First, lets add moor to your project's `pubspec.yaml`.
At the moment, the current version of `moor` is [![Moor version](https://img.shields.io/pub/v/moor.svg)](https://pub.dartlang.org/packages/moor),
`moor_ffi` is at [![Moor version](https://img.shields.io/pub/v/moor_ffi.svg)](https://pub.dartlang.org/packages/moor_ffi)
At the moment, the current version of `moor` is [![Moor version](https://img.shields.io/pub/v/moor.svg)](https://pub.dartlang.org/packages/moor)
and the latest version of `moor_generator` is [![Generator version](https://img.shields.io/pub/v/moor_generator.svg)](https://pub.dartlang.org/packages/moor_generator)
```yaml
dependencies:
moor: # use the latest version
moor_ffi: # use the latest version
sqlite3_flutter_libs: # Also use the latest version.
path_provider:
path:
@ -32,7 +31,7 @@ dev_dependencies:
If you're wondering why so many packages are necessary, here's a quick overview over what each package does:
- `moor`: This is the core package defining most apis
- `moor_ffi`: Contains code that will run the actual queries
- `sqlite3_flutter_libs`: Ships the latest `sqlite3` version with your Android or iOS app.
- `path_provider` and `path`: Used to find a suitable location to store the database. Maintained by the Flutter and Dart team
- `moor_generator`: Generates query code based on your tables
- `build_runner`: Common tool for code-generation, maintained by the Dart team
@ -89,7 +88,7 @@ database and data classes for your entities. To use it, change the `MyDatabase`
follows:
```dart
// These imports are only needed to open the database
import 'package:moor_ffi/moor_ffi.dart';
import 'package:moor/ffi.dart';
import 'package:path_provider/path_provider.dart';
import 'package:path/path.dart' as p;
import 'package:moor/moor.dart';

View File

@ -9,14 +9,13 @@ declaring both tables and queries in Dart. This version will focus on how to use
## Adding the dependency
First, lets add moor to your project's `pubspec.yaml`.
At the moment, the current version of `moor` is [![Moor version](https://img.shields.io/pub/v/moor.svg)](https://pub.dartlang.org/packages/moor),
`moor_ffi` is at [![Moor version](https://img.shields.io/pub/v/moor_ffi.svg)](https://pub.dartlang.org/packages/moor_ffi)
At the moment, the current version of `moor` is [![Moor version](https://img.shields.io/pub/v/moor.svg)](https://pub.dartlang.org/packages/moor)
and the latest version of `moor_generator` is [![Generator version](https://img.shields.io/pub/v/moor_generator.svg)](https://pub.dartlang.org/packages/moor_generator)
```yaml
dependencies:
moor: # use the latest version
moor_ffi: # use the latest version
sqlite3_flutter_libs: # Also use the latest version.
path_provider:
path:
@ -28,7 +27,7 @@ dev_dependencies:
If you're wondering why so many packages are necessary, here's a quick overview over what each package does:
- `moor`: This is the core package defining most apis
- `moor_ffi`: Contains code that will run the actual queries
- `sqlite3_flutter_libs`: Ships the latest `sqlite3` version with your Android or iOS app.
- `path_provider` and `path`: Used to find a suitable location to store the database. Maintained by the Flutter and Dart team
- `moor_generator`: Generates Dart apis for the sql queries and tables you wrote
- `build_runner`: Common tool for code-generation, maintained by the Dart team
@ -95,7 +94,7 @@ import 'dart:io';
import 'package:moor/moor.dart';
// These imports are only needed to open the database
import 'package:moor_ffi/moor_ffi.dart';
import 'package:moor/ffi.dart';
import 'package:path_provider/path_provider.dart';
import 'package:path/path.dart' as p;

View File

@ -1,11 +1,12 @@
---
title: moor_ffi (Desktop support)
title: moor ffi (Desktop support)
description: Run moor on both mobile and desktop
---
## Supported versions
At the moment, `moor_ffi` supports iOS, macOS and Android out of the box. Most Linux
The `moor/ffi.dart` library uses the `sqlite3` package to send queries.
At the moment, that package supports iOS, macOS and Android out of the box. Most Linux
Distros have sqlite available as a shared library, those are supported as well.
If you're shipping apps for Windows and Linux, it is recommended that you bundle a
@ -15,14 +16,14 @@ support your setup by running this code before opening the database:
```dart
import 'dart:ffi';
import 'dart:io';
import 'package:moor_ffi/database.dart';
import 'package:moor_ffi/open_helper.dart';
import 'package:sqlite3/sqlite3.dart';
import 'package:sqlite3/open.dart';
void main() {
open.overrideFor(OperatingSystem.linux, _openOnLinux);
final db = Database.memory();
db.close();
final db = sqlite3.openInMemory();
db.dispose();
}
DynamicLibrary _openOnLinux() {
@ -34,24 +35,24 @@ DynamicLibrary _openOnLinux() {
```
## Migrating from moor_flutter to moor_ffi
## Migrating from moor_flutter to moor ffi
First, adapt your `pubspec.yaml`: You can remove the `moor_flutter` dependency and instead
add both the `moor` and `moor_ffi` dependencies:
add both the `moor` and `sqlite3_flutter_libs` dependencies:
```yaml
dependencies:
moor: ^2.0.0
moor_ffi: ^0.2.0
moor: ^3.0.0
sqlite3_flutter_libs:
sqflite: ^1.1.7 # Still used to obtain the database location
dev_dependencies:
moor_generator: ^2.0.0
moor_generator: ^3.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`.
with `package:moor/ffi.dart`.
- In all other files where you might have imported `moor_flutter`, just import `package:moor/moor.dart`.
Replace the executor. This code:
```dart
@ -75,7 +76,7 @@ Please be aware that `FlutterQueryExecutor.inDatabaseFolder` might yield a diffe
`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.
## Using moor_ffi 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
changes are required.

View File

@ -1,3 +1,15 @@
## 0.8.0
This package is now deprecated.
Moor users should use the new `package:moor/ffi.dart` library.
To migrate,
- replace imports of `moor_ffi` with `package:moor/ffi.dart`
- when using Flutter, add a dependency on `sqlite3_flutter_libs`
Users of this package that don't use moor should use the new [sqlite3](https://pub.dev/packages/sqlite3)
package.
## 0.7.0
- Throw an error when using an unsupported datatype as argument