mirror of https://github.com/AMT-Cheif/drift.git
Always generate private watch methods
This commit is contained in:
parent
138652fdc4
commit
e9225cf759
|
@ -18,18 +18,11 @@ targets:
|
|||
builders:
|
||||
moor_generator:
|
||||
options:
|
||||
generate_private_watch_methods: true
|
||||
write_from_json_string_constructor: true
|
||||
```
|
||||
|
||||
At the moment, moor supports these options:
|
||||
|
||||
* `generate_private_watch_methods`: boolean. There was a bug in the generator where
|
||||
[compiled queries]({{<relref "../Using SQL/custom_queries.md">}}) that start with
|
||||
an underscore did generate a watch method that didn't start with an underscore
|
||||
(see [#107](https://github.com/simolus3/moor/issues/107)). Fixing this would be
|
||||
a breaking change, so the fix is opt-in by enabling this option. This flag is
|
||||
available since 1.7 and will be removed in moor 2.0, where this flag will always
|
||||
be enabled.
|
||||
* `write_from_json_string_constructor`: boolean. Adds a `.fromJsonString` factory
|
||||
constructor to generated data classes. By default, we only write a `.fromJson`
|
||||
constructor that takes a `Map<String, dynamic>`.
|
|
@ -30,6 +30,10 @@ TODO: Properly describe these additions when they're finalized:
|
|||
On a similar note, we also removed the `operateOn` parameter from compiled queries.
|
||||
|
||||
- Removed `MigrationStrategy.onFinished`. Use `beforeOpen` instead.
|
||||
- Compiled sql queries starting with an underscore will now generate private match queries.
|
||||
Previously, the query `_allUsers` would generate a `watchAllUsers` method, that has been
|
||||
adopted to `_watchAllUsers`. The `generate_private_watch_methods` builder option, which
|
||||
backported this fix to older versions, has thus been removed.
|
||||
|
||||
## 1.7.2
|
||||
- Fixed a race condition that caused the database to be opened multiple times on slower devices.
|
||||
|
|
|
@ -3,25 +3,14 @@ part of 'moor_builder.dart';
|
|||
class MoorOptions {
|
||||
final bool generateFromJsonStringConstructor;
|
||||
|
||||
/// A bug in the generator generates public watch* methods, even if the query
|
||||
/// name starts with an underscore. Fixing this would be a breaking change, so
|
||||
/// we introduce a flag that will be the default behavior in the next breaking
|
||||
/// moor version.
|
||||
final bool fixPrivateWatchMethods;
|
||||
|
||||
MoorOptions(
|
||||
this.generateFromJsonStringConstructor, this.fixPrivateWatchMethods);
|
||||
MoorOptions(this.generateFromJsonStringConstructor);
|
||||
|
||||
factory MoorOptions.fromBuilder(Map<String, dynamic> config) {
|
||||
final writeFromString =
|
||||
config['write_from_json_string_constructor'] as bool ?? false;
|
||||
final fixWatchMethods =
|
||||
config['generate_private_watch_methods'] as bool ?? false;
|
||||
|
||||
return MoorOptions(writeFromString, fixWatchMethods);
|
||||
return MoorOptions(writeFromString);
|
||||
}
|
||||
|
||||
const MoorOptions.defaults()
|
||||
: generateFromJsonStringConstructor = false,
|
||||
fixPrivateWatchMethods = false;
|
||||
const MoorOptions.defaults() : generateFromJsonStringConstructor = false;
|
||||
}
|
||||
|
|
|
@ -145,9 +145,8 @@ class QueryWriter {
|
|||
|
||||
String methodName;
|
||||
// turning the query name into pascal case will remove underscores, add the
|
||||
// "private" modifier back in if needed
|
||||
if (scope.writer.options.fixPrivateWatchMethods &&
|
||||
query.name.startsWith('_')) {
|
||||
// "private" modifier back in
|
||||
if (query.name.startsWith('_')) {
|
||||
methodName = '_watch$upperQueryName';
|
||||
} else {
|
||||
methodName = 'watch$upperQueryName';
|
||||
|
|
Loading…
Reference in New Issue