option to make all named parameters required

This commit is contained in:
Pavel 2021-04-10 01:19:26 +03:00
parent 58fdda482f
commit e1f3242850
3 changed files with 12 additions and 1 deletions

View File

@ -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;
@ -107,6 +110,7 @@ class MoorOptions {
this.applyConvertersOnVariables = false,
this.generateValuesInCopyWith = false,
this.generateNamedParameters = false,
this.namedParametersAlwaysRequired = false,
this.newSqlCodeGeneration = false,
this.modules = const [],
this.sqliteAnalysisOptions,
@ -127,6 +131,7 @@ class MoorOptions {
required this.applyConvertersOnVariables,
required this.generateValuesInCopyWith,
required this.generateNamedParameters,
required this.namedParametersAlwaysRequired,
required this.newSqlCodeGeneration,
required this.modules,
required this.sqliteAnalysisOptions,

View File

@ -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'
]);
final val = MoorOptions(
@ -70,6 +71,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,
@ -101,6 +105,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',
'modules': 'sqlite_modules',
'sqliteAnalysisOptions': 'sqlite'

View File

@ -309,7 +309,8 @@ class QueryWriter {
// No default value, this element is required if it's not nullable
final isNullable = optional is FoundVariable && optional.nullableInDart;
final isRequired = !isNullable && defaultCode == null;
final isRequired = !isNullable && defaultCode == null ||
options.namedParametersAlwaysRequired;
if (isRequired) {
_buffer..write(scope.required)..write(' ');
}