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
|
columns back to null (by using `Value(null)`). Passing `null` was ignored before, making it impossible to set columns
|
||||||
to `null`.
|
to `null`.
|
||||||
* `named_parameters`: Generates named parameters for named variables in SQL queries.
|
* `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
|
* `new_sql_code_generation`: Generates SQL statements from the parsed AST instead of replacing substrings. This will also remove
|
||||||
unecessary whitespace and comments.
|
unecessary whitespace and comments.
|
||||||
If enabling this option breaks your queries, please file an issue!
|
If enabling this option breaks your queries, please file an issue!
|
||||||
|
|
|
@ -88,6 +88,9 @@ class MoorOptions {
|
||||||
@JsonKey(name: 'named_parameters', defaultValue: false)
|
@JsonKey(name: 'named_parameters', defaultValue: false)
|
||||||
final bool generateNamedParameters;
|
final bool generateNamedParameters;
|
||||||
|
|
||||||
|
@JsonKey(name: 'named_parameters_always_required', defaultValue: false)
|
||||||
|
final bool namedParametersAlwaysRequired;
|
||||||
|
|
||||||
@JsonKey(name: 'new_sql_code_generation', defaultValue: false)
|
@JsonKey(name: 'new_sql_code_generation', defaultValue: false)
|
||||||
final bool newSqlCodeGeneration;
|
final bool newSqlCodeGeneration;
|
||||||
|
|
||||||
|
@ -110,6 +113,7 @@ class MoorOptions {
|
||||||
this.applyConvertersOnVariables = false,
|
this.applyConvertersOnVariables = false,
|
||||||
this.generateValuesInCopyWith = false,
|
this.generateValuesInCopyWith = false,
|
||||||
this.generateNamedParameters = false,
|
this.generateNamedParameters = false,
|
||||||
|
this.namedParametersAlwaysRequired = false,
|
||||||
this.newSqlCodeGeneration = false,
|
this.newSqlCodeGeneration = false,
|
||||||
this.scopedDartComponents = false,
|
this.scopedDartComponents = false,
|
||||||
this.modules = const [],
|
this.modules = const [],
|
||||||
|
@ -131,6 +135,7 @@ class MoorOptions {
|
||||||
required this.applyConvertersOnVariables,
|
required this.applyConvertersOnVariables,
|
||||||
required this.generateValuesInCopyWith,
|
required this.generateValuesInCopyWith,
|
||||||
required this.generateNamedParameters,
|
required this.generateNamedParameters,
|
||||||
|
required this.namedParametersAlwaysRequired,
|
||||||
required this.newSqlCodeGeneration,
|
required this.newSqlCodeGeneration,
|
||||||
required this.scopedDartComponents,
|
required this.scopedDartComponents,
|
||||||
required this.modules,
|
required this.modules,
|
||||||
|
|
|
@ -25,6 +25,7 @@ MoorOptions _$MoorOptionsFromJson(Map json) {
|
||||||
'apply_converters_on_variables',
|
'apply_converters_on_variables',
|
||||||
'generate_values_in_copy_with',
|
'generate_values_in_copy_with',
|
||||||
'named_parameters',
|
'named_parameters',
|
||||||
|
'named_parameters_always_required',
|
||||||
'new_sql_code_generation',
|
'new_sql_code_generation',
|
||||||
'scoped_dart_components'
|
'scoped_dart_components'
|
||||||
]);
|
]);
|
||||||
|
@ -71,6 +72,9 @@ MoorOptions _$MoorOptionsFromJson(Map json) {
|
||||||
false,
|
false,
|
||||||
generateNamedParameters:
|
generateNamedParameters:
|
||||||
$checkedConvert(json, 'named_parameters', (v) => v as bool?) ?? false,
|
$checkedConvert(json, 'named_parameters', (v) => v as bool?) ?? false,
|
||||||
|
namedParametersAlwaysRequired: $checkedConvert(
|
||||||
|
json, 'named_parameters_always_required', (v) => v as bool?) ??
|
||||||
|
false,
|
||||||
newSqlCodeGeneration:
|
newSqlCodeGeneration:
|
||||||
$checkedConvert(json, 'new_sql_code_generation', (v) => v as bool?) ??
|
$checkedConvert(json, 'new_sql_code_generation', (v) => v as bool?) ??
|
||||||
false,
|
false,
|
||||||
|
@ -105,6 +109,7 @@ MoorOptions _$MoorOptionsFromJson(Map json) {
|
||||||
'applyConvertersOnVariables': 'apply_converters_on_variables',
|
'applyConvertersOnVariables': 'apply_converters_on_variables',
|
||||||
'generateValuesInCopyWith': 'generate_values_in_copy_with',
|
'generateValuesInCopyWith': 'generate_values_in_copy_with',
|
||||||
'generateNamedParameters': 'named_parameters',
|
'generateNamedParameters': 'named_parameters',
|
||||||
|
'namedParametersAlwaysRequired': 'named_parameters_always_required',
|
||||||
'newSqlCodeGeneration': 'new_sql_code_generation',
|
'newSqlCodeGeneration': 'new_sql_code_generation',
|
||||||
'scopedDartComponents': 'scoped_dart_components',
|
'scopedDartComponents': 'scoped_dart_components',
|
||||||
'modules': 'sqlite_modules',
|
'modules': 'sqlite_modules',
|
||||||
|
|
|
@ -382,7 +382,8 @@ class QueryWriter {
|
||||||
isNullable = optional.nullableInDart;
|
isNullable = optional.nullableInDart;
|
||||||
}
|
}
|
||||||
final isRequired =
|
final isRequired =
|
||||||
(!isNullable || isMarkedAsRequired) && defaultCode == null;
|
(!isNullable || isMarkedAsRequired) && defaultCode == null ||
|
||||||
|
options.namedParametersAlwaysRequired;
|
||||||
if (isRequired) {
|
if (isRequired) {
|
||||||
_buffer..write(scope.required)..write(' ');
|
_buffer..write(scope.required)..write(' ');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue