mirror of https://github.com/AMT-Cheif/drift.git
commit
f84d90a2e7
|
@ -71,7 +71,7 @@ fields from that date:
|
|||
select(users)..where((u) => u.birthDate.year.isLessThan(1950))
|
||||
```
|
||||
|
||||
The individual fileds like `year`, `month` and so on are expressions themselves. This means
|
||||
The individual fields like `year`, `month` and so on are expressions themselves. This means
|
||||
that you can use operators and comparisons on them.
|
||||
To obtain the current date or the current time as an expression, use the `currentDate`
|
||||
and `currentDateAndTime` constants provided by moor.
|
||||
|
|
|
@ -92,7 +92,7 @@ Future<MoorIsolate> _createMoorIsolate() async {
|
|||
}
|
||||
|
||||
void _startBackground(_IsolateStartRequest request) {
|
||||
// this is the entrypoint from the background isolate! Let's create
|
||||
// this is the entry point from the background isolate! Let's create
|
||||
// the database from the path we received
|
||||
final executor = VmDatabase(File(request.targetPath));
|
||||
// we're using MoorIsolate.inCurrent here as this method already runs on a
|
||||
|
@ -105,7 +105,7 @@ void _startBackground(_IsolateStartRequest request) {
|
|||
request.sendMoorIsolate.send(moorIsolate);
|
||||
}
|
||||
|
||||
// used to bundle the SendPort and the target path, since isolate entrypoint
|
||||
// used to bundle the SendPort and the target path, since isolate entry point
|
||||
// functions can only take one parameter.
|
||||
class _IsolateStartRequest {
|
||||
final SendPort sendMoorIsolate;
|
||||
|
|
|
@ -158,7 +158,7 @@ comes from multiple rows. Common questions include
|
|||
- what's the average length of a todo entry?
|
||||
|
||||
What these queries have in common is that data from multiple rows needs to be combined into a single
|
||||
row. In sql, this can be achieved with "aggregate functins", for which moor has
|
||||
row. In sql, this can be achieved with "aggregate functions", for which moor has
|
||||
[builtin support]({{< relref "expressions.md#aggregate" >}}).
|
||||
|
||||
_Additional info_: A good tutorial for group by in sql is available [here](https://www.sqlitetutorial.net/sqlite-group-by/).
|
||||
|
|
|
@ -87,5 +87,5 @@ yet. You can just delete your apps' data and reinstall the app - the database wi
|
|||
will be created again. Please note that uninstalling is not enough sometimes - Android might have backed up
|
||||
the database file and will re-create it when installing the app again.
|
||||
|
||||
You can also delete and re-create all tables everytime your app is opened, see [this comment](https://github.com/simolus3/moor/issues/188#issuecomment-542682912)
|
||||
You can also delete and re-create all tables every time your app is opened, see [this comment](https://github.com/simolus3/moor/issues/188#issuecomment-542682912)
|
||||
on how that can be achieved.
|
|
@ -53,7 +53,7 @@ INFO: test/fake_db.dart has moor databases or daos: TodoDb, SomeDao
|
|||
### Export
|
||||
|
||||
This subcommand expects two paths, a Dart file and a target. The Dart file should contain
|
||||
excactly one class annotated with `@UseMoor`. Running the following command will export
|
||||
exactly one class annotated with `@UseMoor`. Running the following command will export
|
||||
the database schema to json.
|
||||
|
||||
```
|
||||
|
@ -68,4 +68,4 @@ The generated file (`schema.json` in this case) contains information about all
|
|||
- `@create`-queries from included moor files
|
||||
- dependecies thereof
|
||||
|
||||
The schema format is still work-in-progress and might change in the future.
|
||||
The schema format is still a work-in-progress and might change in the future.
|
||||
|
|
|
@ -87,7 +87,7 @@ Future<CartWithItems> createEmptyCart() async {
|
|||
```
|
||||
|
||||
## Selecting a cart
|
||||
As our `CartWithItems` class consists of multiple compontents that are separated in the
|
||||
As our `CartWithItems` class consists of multiple components that are separated in the
|
||||
database (information about the cart, and information about the added items), we'll have
|
||||
to merge two streams together. The `rxdart` library helps here by providing the
|
||||
`combineLatest2` method, allowing us to write
|
||||
|
|
|
@ -83,7 +83,7 @@ examples. Otherwise, the generator won't be able to know what's going on.
|
|||
## Generating the code
|
||||
Moor integrates with Dart's `build` system, so you can generate all the code needed with
|
||||
`flutter packages pub run build_runner build`. If you want to continuously rebuild the generated code
|
||||
whever you change your code, run `flutter packages pub run build_runner watch` instead.
|
||||
where you change your code, run `flutter packages pub run build_runner watch` instead.
|
||||
After running either command once, the moor generator will have created a class for your
|
||||
database and data classes for your entities. To use it, change the `MyDatabase` class as
|
||||
follows:
|
||||
|
|
|
@ -93,4 +93,4 @@ class Users extends Table {
|
|||
Don't know when to use which? Prefer to use `withDefault` when the default value is constant, or something
|
||||
simple like `currentDate`. For more complicated values, like a randomly generated id, you need to use
|
||||
`clientDefault`. Internally, `withDefault` writes the default value into the `CREATE TABLE` statement. This
|
||||
can be more efficient, but doesn't suppport dynamic values.
|
||||
can be more efficient, but doesn't support dynamic values.
|
|
@ -47,6 +47,12 @@ details on expressions, see [this guide]({{< relref "expressions.md" >}}).
|
|||
### Limit
|
||||
You can limit the amount of results returned by calling `limit` on queries. The method accepts
|
||||
the amount of rows to return and an optional offset.
|
||||
```dart
|
||||
Future<List<Todo>> limitTodos(int limit, {int offset}) {
|
||||
return (select(todos)..limit(limit, offset: offset)).get();
|
||||
}
|
||||
```
|
||||
|
||||
### Ordering
|
||||
You can use the `orderBy` method on the select statement. It expects a list of functions that extract the individual
|
||||
ordering terms from the table.
|
||||
|
|
|
@ -26,4 +26,4 @@ Finally, you can replace `FlutterQueryExecutor` with an `EncryptedExecutor`.
|
|||
|
||||
Some extra steps may have to be taken in your project so that SQLCipher works correctly. For example, the ProGuard configuration on Android for apps built for release.
|
||||
|
||||
[Read instructions](https://pub.dev/packages/sqflite_sqlcipher) (Usage and instrallation instructions of the package can be ignored, as that is handled internally by `moor`)
|
||||
[Read instructions](https://pub.dev/packages/sqflite_sqlcipher) (Usage and installation instructions of the package can be ignored, as that is handled internally by `moor`)
|
||||
|
|
|
@ -103,7 +103,7 @@ LazyDatabase(() async {
|
|||
## Used compile options on Android
|
||||
|
||||
Note: Android is the only platform where moor_ffi will compile sqlite. The sqlite3 library from the system
|
||||
is used on all other platforms. The choosen options help reduce binary size by removing features not used by
|
||||
is used on all other platforms. The chosen options help reduce binary size by removing features not used by
|
||||
moor. Important options are marked in bold.
|
||||
|
||||
- We use the `-O3` performance option
|
||||
|
|
|
@ -13,10 +13,10 @@ be supported, moor files will get better tooling support in the future and we re
|
|||
migrate. See [their api]({{%relref "moor_files.md"%}}) for details.
|
||||
{{% /alert %}}
|
||||
|
||||
Altough moor includes a fluent api that can be used to model most statements, advanced
|
||||
Although moor includes a fluent api that can be used to model most statements, advanced
|
||||
features like `GROUP BY` statements or window functions are not yet supported. You can
|
||||
use these features with custom statements. You don't have to miss out on other benefits
|
||||
moor brings, though: Moor helps you parse the result rows and qustom queries also
|
||||
moor brings, though: Moor helps you parse the result rows and custom queries also
|
||||
support auto-updating streams.
|
||||
|
||||
## Statements with a generated api
|
||||
|
|
|
@ -75,13 +75,13 @@ what we got:
|
|||
`todos` and the description of the associated category.
|
||||
|
||||
## Variables
|
||||
We support regular variables (`?`), explictly indexed variables (`?123`)
|
||||
We support regular variables (`?`), explicitly indexed variables (`?123`)
|
||||
and colon-named variables (`:id`). We don't support variables declared
|
||||
with @ or $. The compiler will attempt to infer the variable's type by
|
||||
looking at its context. This lets moor generate typesafe apis for your
|
||||
queries, the variables will be written as parameters to your method.
|
||||
|
||||
When it's ambigous, the analyzer might be unable to resolve the type of
|
||||
When it's ambiguous, the analyzer might be unable to resolve the type of
|
||||
a variable. For those scenarios, you can also denote the explicit type
|
||||
of a variable:
|
||||
```sql
|
||||
|
|
|
@ -9,7 +9,7 @@ description: Welcome to the moor documentation. This site shows you what moor ca
|
|||
---
|
||||
|
||||
## So what's moor?
|
||||
Moor is a reactive persistence library for Dart and Flutter applications. It's built ontop
|
||||
Moor is a reactive persistence library for Dart and Flutter applications. It's built on top
|
||||
of database libraries like [sqflite](https://pub.dev/packages/sqflite) or [sql.js](https://github.com/kripken/sql.js/)
|
||||
and provides additional features, like:
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ dev_dependencies:
|
|||
|
||||
For this guide, we're going to test a very simple database that stores user names. The only important change from a regular moor
|
||||
database is the constructor: We make the `QueryExecutor` argument explicit instead of having a no-args constructor that passes
|
||||
a `FlutterQueryExector` to the superclass.
|
||||
a `FlutterQueryExecutor` to the superclass.
|
||||
```dart
|
||||
import 'package:moor/moor.dart';
|
||||
|
||||
|
|
|
@ -44,12 +44,12 @@ they behave.
|
|||
Query streams that have been created outside a transaction work nicely together with
|
||||
updates made in a transaction: All changes to tables will only be reported after the
|
||||
transaction completes. Updates inside a transaction don't have an immediate effect on
|
||||
streams, so your data will always be consistent and there aren't any uneccessary updates.
|
||||
streams, so your data will always be consistent and there aren't any unnecessary updates.
|
||||
|
||||
With streams created _inside_ a `transaction` block (or a nested call in there), it's
|
||||
a different story. Notably, they
|
||||
|
||||
- reflect on changes made in the transaction immediatly
|
||||
- reflect on changes made in the transaction immediately
|
||||
- complete when the transaction completes
|
||||
|
||||
This behavior is useful if you're collapsing streams inside a transaction, for instance by
|
||||
|
|
Loading…
Reference in New Issue