mirror of https://github.com/AMT-Cheif/drift.git
Merge pull request #1242 from PiN73/named-required
Option to make all named parameters required
This commit is contained in:
commit
760bb1d801
|
@ -76,6 +76,7 @@ At the moment, moor supports these options:
|
|||
columns back to null (by using `Value(null)`). Passing `null` was ignored before, making it impossible to set columns
|
||||
to `null`.
|
||||
* `named_parameters`: Generates named parameters for named variables in SQL queries.
|
||||
* `named_parameters_always_required`: All named parameters (generated if `named_parameters` option is `true`) will be required in Dart.
|
||||
* `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!
|
||||
|
@ -217,4 +218,4 @@ and use the non-shared generator instead.
|
|||
|
||||
Finally, we need to the build system to run moor first, and all the other builders otherwise. This is
|
||||
why we split the builders up into multiple targets. The first target will only run moor, the second
|
||||
target has a dependency on the first one and will run all the other builders.
|
||||
target has a dependency on the first one and will run all the other builders.
|
||||
|
|
|
@ -88,6 +88,9 @@ class MoorOptions {
|
|||
@JsonKey(name: 'named_parameters', defaultValue: false)
|
||||
final bool generateNamedParameters;
|
||||
|
||||
@JsonKey(name: 'named_parameters_always_required', defaultValue: false)
|
||||
final bool namedParametersAlwaysRequired;
|
||||
|
||||
@JsonKey(name: 'new_sql_code_generation', defaultValue: false)
|
||||
final bool newSqlCodeGeneration;
|
||||
|
||||
|
@ -110,6 +113,7 @@ class MoorOptions {
|
|||
this.applyConvertersOnVariables = false,
|
||||
this.generateValuesInCopyWith = false,
|
||||
this.generateNamedParameters = false,
|
||||
this.namedParametersAlwaysRequired = false,
|
||||
this.newSqlCodeGeneration = false,
|
||||
this.scopedDartComponents = false,
|
||||
this.modules = const [],
|
||||
|
@ -131,6 +135,7 @@ class MoorOptions {
|
|||
required this.applyConvertersOnVariables,
|
||||
required this.generateValuesInCopyWith,
|
||||
required this.generateNamedParameters,
|
||||
required this.namedParametersAlwaysRequired,
|
||||
required this.newSqlCodeGeneration,
|
||||
required this.scopedDartComponents,
|
||||
required this.modules,
|
||||
|
|
|
@ -25,6 +25,7 @@ MoorOptions _$MoorOptionsFromJson(Map json) {
|
|||
'apply_converters_on_variables',
|
||||
'generate_values_in_copy_with',
|
||||
'named_parameters',
|
||||
'named_parameters_always_required',
|
||||
'new_sql_code_generation',
|
||||
'scoped_dart_components'
|
||||
]);
|
||||
|
@ -71,6 +72,9 @@ MoorOptions _$MoorOptionsFromJson(Map json) {
|
|||
false,
|
||||
generateNamedParameters:
|
||||
$checkedConvert(json, 'named_parameters', (v) => v as bool?) ?? false,
|
||||
namedParametersAlwaysRequired: $checkedConvert(
|
||||
json, 'named_parameters_always_required', (v) => v as bool?) ??
|
||||
false,
|
||||
newSqlCodeGeneration:
|
||||
$checkedConvert(json, 'new_sql_code_generation', (v) => v as bool?) ??
|
||||
false,
|
||||
|
@ -105,6 +109,7 @@ MoorOptions _$MoorOptionsFromJson(Map json) {
|
|||
'applyConvertersOnVariables': 'apply_converters_on_variables',
|
||||
'generateValuesInCopyWith': 'generate_values_in_copy_with',
|
||||
'generateNamedParameters': 'named_parameters',
|
||||
'namedParametersAlwaysRequired': 'named_parameters_always_required',
|
||||
'newSqlCodeGeneration': 'new_sql_code_generation',
|
||||
'scopedDartComponents': 'scoped_dart_components',
|
||||
'modules': 'sqlite_modules',
|
||||
|
|
|
@ -382,7 +382,8 @@ class QueryWriter {
|
|||
isNullable = optional.nullableInDart;
|
||||
}
|
||||
final isRequired =
|
||||
(!isNullable || isMarkedAsRequired) && defaultCode == null;
|
||||
(!isNullable || isMarkedAsRequired) && defaultCode == null ||
|
||||
options.namedParametersAlwaysRequired;
|
||||
if (isRequired) {
|
||||
_buffer..write(scope.required)..write(' ');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue