mirror of https://github.com/AMT-Cheif/drift.git
Moved generateToCompanion option to ExistingRowClass
This commit is contained in:
parent
610acfad61
commit
9b4f25718d
|
@ -15,8 +15,12 @@ class FoundDartClass {
|
|||
FoundDartClass(this.classElement, this.instantiation);
|
||||
}
|
||||
|
||||
ExistingRowClass? validateExistingClass(Iterable<MoorColumn> columns,
|
||||
FoundDartClass dartClass, String constructor, ErrorSink errors) {
|
||||
ExistingRowClass? validateExistingClass(
|
||||
Iterable<MoorColumn> columns,
|
||||
FoundDartClass dartClass,
|
||||
String constructor,
|
||||
bool generateToCompanion,
|
||||
ErrorSink errors) {
|
||||
final desiredClass = dartClass.classElement;
|
||||
ConstructorElement? ctor;
|
||||
|
||||
|
@ -63,7 +67,8 @@ ExistingRowClass? validateExistingClass(Iterable<MoorColumn> columns,
|
|||
}
|
||||
}
|
||||
|
||||
return ExistingRowClass(desiredClass, ctor, columnsToParameter,
|
||||
return ExistingRowClass(
|
||||
desiredClass, ctor, columnsToParameter, generateToCompanion,
|
||||
typeInstantiation: dartClass.instantiation ?? const []);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ class TableParser {
|
|||
sqlName: escapeIfNeeded(sqlName),
|
||||
dartTypeName: dataClassInfo.enforcedName,
|
||||
existingRowClass: dataClassInfo.existingClass,
|
||||
generateToCompanion: dataClassInfo.generateToCompanion,
|
||||
primaryKey: primaryKey,
|
||||
overrideWithoutRowId: await _overrideWithoutRowId(element),
|
||||
declaration: DartTableDeclaration(element, base.step.file),
|
||||
|
@ -71,7 +70,7 @@ class TableParser {
|
|||
String name;
|
||||
FoundDartClass? existingClass;
|
||||
String? constructorInExistingClass;
|
||||
var generateToCompanion = false;
|
||||
bool? generateToCompanion;
|
||||
|
||||
if (dataClassName != null) {
|
||||
name = dataClassName.getField('name')!.toStringValue()!;
|
||||
|
@ -99,9 +98,13 @@ class TableParser {
|
|||
|
||||
final verified = existingClass == null
|
||||
? null
|
||||
: validateExistingClass(columns, existingClass,
|
||||
constructorInExistingClass!, base.step.errors);
|
||||
return _DataClassInformation(name, verified, generateToCompanion);
|
||||
: validateExistingClass(
|
||||
columns,
|
||||
existingClass,
|
||||
constructorInExistingClass!,
|
||||
generateToCompanion!,
|
||||
base.step.errors);
|
||||
return _DataClassInformation(name, verified);
|
||||
}
|
||||
|
||||
Future<String?> _parseTableName(ClassElement element) async {
|
||||
|
@ -230,10 +233,8 @@ class TableParser {
|
|||
class _DataClassInformation {
|
||||
final String enforcedName;
|
||||
final ExistingRowClass? existingClass;
|
||||
final bool generateToCompanion;
|
||||
|
||||
_DataClassInformation(
|
||||
this.enforcedName, this.existingClass, this.generateToCompanion);
|
||||
_DataClassInformation(this.enforcedName, this.existingClass);
|
||||
}
|
||||
|
||||
extension on Element {
|
||||
|
|
|
@ -181,7 +181,7 @@ class CreateTableReader {
|
|||
));
|
||||
} else {
|
||||
existingRowClass = validateExistingClass(
|
||||
foundColumns.values, clazz, '', step.errors);
|
||||
foundColumns.values, clazz, '', false, step.errors);
|
||||
dataClassName = existingRowClass?.targetClass.name;
|
||||
}
|
||||
} else if (overriddenNames.contains('/')) {
|
||||
|
|
|
@ -64,7 +64,7 @@ class ViewAnalyzer extends BaseAnalyzer {
|
|||
));
|
||||
} else {
|
||||
final rowClass = view.existingRowClass =
|
||||
validateExistingClass(columns, clazz, '', step.errors);
|
||||
validateExistingClass(columns, clazz, '', false, step.errors);
|
||||
final newName = rowClass?.targetClass.name;
|
||||
if (newName != null) {
|
||||
view.dartTypeName = rowClass!.targetClass.name;
|
||||
|
|
|
@ -69,7 +69,11 @@ class ExistingRowClass {
|
|||
final ConstructorElement constructor;
|
||||
final Map<MoorColumn, ParameterElement> mapping;
|
||||
|
||||
/// Generate toCompanion for data class
|
||||
final bool generateToCompanion;
|
||||
|
||||
ExistingRowClass(this.targetClass, this.constructor, this.mapping,
|
||||
this.generateToCompanion,
|
||||
{this.typeInstantiation = const []});
|
||||
|
||||
String dartType([GenerationOptions options = const GenerationOptions()]) {
|
||||
|
|
|
@ -51,9 +51,6 @@ class MoorTable extends MoorEntityWithResultSet {
|
|||
@override
|
||||
final String dartTypeName;
|
||||
|
||||
/// Generate toCompanion for data class
|
||||
final bool generateToCompanion;
|
||||
|
||||
/// The getter name used for this table in a generated database or dao class.
|
||||
@override
|
||||
String get dbGetterName => dbFieldName(_baseName);
|
||||
|
@ -141,7 +138,6 @@ class MoorTable extends MoorEntityWithResultSet {
|
|||
this.columns = const [],
|
||||
required this.sqlName,
|
||||
required this.dartTypeName,
|
||||
this.generateToCompanion = false,
|
||||
this.primaryKey,
|
||||
String? overriddenName,
|
||||
this.overrideWithoutRowId,
|
||||
|
|
|
@ -30,7 +30,7 @@ class UpdateCompanionWriter {
|
|||
|
||||
_buffer.write('}\n');
|
||||
|
||||
if (table.generateToCompanion) {
|
||||
if (table.existingRowClass?.generateToCompanion ?? false) {
|
||||
_writeToCompanionExtension();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue