Update changelog and docs for new features

This commit is contained in:
Simon Binder 2021-06-04 18:43:45 +02:00
parent eb362effe8
commit 52487f2447
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
5 changed files with 32 additions and 3 deletions

View File

@ -8,9 +8,13 @@ aliases:
- "options/"
---
The `moor_generator` package has some options that control how the
code is generated. Note that, in most cases, the default settings
should be sufficient. See the section on recommended settings below.
The `moor_generator` package supports a range of options that control how code
is generated.
In most cases, the default settings should be sufficient. But if you want to
try out new features faster or configure how moor-generated code looks like,
you can use the available options listed below.
You can also see the section on [recommended options](#recommended-options) for
advice on which options to use.
To use the options, create a `build.yaml` file in the root of your project (e.g. next
to your `pubspec.yaml`):
@ -75,6 +79,9 @@ At the moment, moor supports these options:
* `new_sql_code_generation`: Generates SQL statements from the parsed AST instead of replacing substrings. This will also remove
unecessary whitespace and comments.
If enabling this option breaks your queries, please file an issue!
* `scoped_dart_components`: Generates a function parameter for [Dart placeholders]({{ '../Using SQL/moor_files.md#dart-components-in-sql' | pageUrl }}) in SQL.
The function has a parameter for each table that is available in the query, making it easier to get aliases right when using
Dart placeholders.
## Assumed sqlite environment
@ -139,6 +146,7 @@ At the moment, they're opt-in to not break existing users. These options are:
- `apply_converters_on_variables`
- `generate_values_in_copy_with`
- `new_sql_code_generation`
- `scoped_dart_components`
We recommend enabling these options.

View File

@ -294,6 +294,17 @@ Future<List<Route>> routesByStart(int startPointId) {
return findRoutes(start.id.equals(startPointId));
}
```
Since moor 4.4, you can enable the `scoped_dart_components` [build option]({{ '../Advanced Features/builder_options.md' | pageUrl }})
and let the generator help you here.
When the option is enabled, moor would generate a `Expression<bool> Function(Routes r, Points start, Points end)` as a parameter, which
makes this a lot easier:
```dart
Future<List<Route>> routesByStart(int startPointId) {
return findRoutes((r, start, end) => start.id.equals(startPointId));
}
```
{% endblock %}
### Type converters

View File

@ -3,6 +3,9 @@
- Add `Value.ofNullable` constructor to easily wrap nullable values
- Support selecting views declared in a moor file in Dart (with `select`,
`join` and similar methods)
- Add the `scoped_dart_components` builder option to generate a function for
[Dart components in SQL](https://moor.simonbinder.eu/docs/using-sql/moor_files/#dart-components-in-sql).
The function's parameters reflect tables that are in scope.
## 4.3.2

View File

@ -1,3 +1,9 @@
## 4.4.0
- Support the `scoped_dart_components` build option
- Improve nullability analysis for SQL result sets
- Generate data classes for views
## 4.3.2
- Support the latest analyzer version

View File

@ -362,6 +362,7 @@ class QueryWriter {
if (i != 0) buffer.write(', ');
buffer..write(arg.argumentType)..write(' ')..write('_' * (i + 1));
i++;
}
buffer..write(') => ')..write(defaultCode)..write(';');