mirror of https://github.com/AMT-Cheif/drift.git
Refoactor Builder
This commit is contained in:
parent
c7f310e46f
commit
2d470dc660
|
@ -9,21 +9,341 @@ extension on DriftColumn {
|
|||
}
|
||||
}
|
||||
|
||||
class Names {
|
||||
abstract class _Filter {
|
||||
void writeFilter(TextEmitter leaf);
|
||||
}
|
||||
|
||||
class _RegularFilter extends _Filter {
|
||||
final String fieldGetter;
|
||||
final String type;
|
||||
final String filterName;
|
||||
_RegularFilter(this.fieldGetter, this.type, this.filterName);
|
||||
|
||||
@override
|
||||
void writeFilter(TextEmitter leaf) {
|
||||
leaf
|
||||
..writeDriftRef("ColumnFilters")
|
||||
..write("<$type> get $filterName =>")
|
||||
..writeDriftRef("ColumnFilters")
|
||||
..write("(state.table.$fieldGetter);");
|
||||
}
|
||||
}
|
||||
|
||||
class _FilterWithConverter extends _Filter {
|
||||
final String fieldGetter;
|
||||
final String type;
|
||||
final String filterName;
|
||||
final String converterType;
|
||||
_FilterWithConverter(
|
||||
this.fieldGetter, this.type, this.filterName, this.converterType);
|
||||
|
||||
@override
|
||||
void writeFilter(TextEmitter leaf) {
|
||||
leaf
|
||||
..writeDriftRef("ColumnWithTypeConverterFilters")
|
||||
..write("<$converterType,$type> get $filterName =>")
|
||||
..writeDriftRef("ColumnWithTypeConverterFilters")
|
||||
..writeln("(state.table.$fieldGetter);");
|
||||
leaf
|
||||
..writeDriftRef("ColumnFilters")
|
||||
..write("<$type> get ${filterName}Value =>")
|
||||
..writeDriftRef("ColumnFilters")
|
||||
..writeln("(state.table.$fieldGetter);");
|
||||
}
|
||||
}
|
||||
|
||||
class _ReferencedFilter extends _Filter {
|
||||
final String fieldGetter;
|
||||
final String filterName;
|
||||
final _TableNames referencedTable;
|
||||
final _ColumnNames referencedColumn;
|
||||
_ReferencedFilter(this.fieldGetter, this.filterName, this.referencedTable,
|
||||
this.referencedColumn);
|
||||
|
||||
@override
|
||||
void writeFilter(TextEmitter leaf) {
|
||||
leaf
|
||||
..writeDriftRef("ComposableFilter")
|
||||
..write(" $filterName(")
|
||||
..writeDriftRef("ComposableFilter")
|
||||
..writeln(" Function( ${referencedTable.filterComposer} f) f) {")
|
||||
..writeln('''
|
||||
return referenced(
|
||||
referencedTable: state.db.${referencedTable.tableGetterName},
|
||||
getCurrentColumn: (f) => f.$fieldGetter,
|
||||
getReferencedColumn: (f) => f.${referencedColumn.fieldGetter},
|
||||
getReferencedComposer: (db, table) => ${referencedTable.filterComposer}(db, table),
|
||||
builder: f);
|
||||
}''');
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _Ordering {
|
||||
void writeOrdering(TextEmitter leaf);
|
||||
}
|
||||
|
||||
class _RegularOrdering extends _Ordering {
|
||||
final String fieldGetter;
|
||||
final String type;
|
||||
final String orderingName;
|
||||
_RegularOrdering(this.fieldGetter, this.type, this.orderingName);
|
||||
|
||||
@override
|
||||
void writeOrdering(TextEmitter leaf) {
|
||||
leaf
|
||||
..writeDriftRef("ColumnOrderings")
|
||||
..write(" get $orderingName =>")
|
||||
..writeDriftRef("ColumnOrderings")
|
||||
..write("(state.table.$fieldGetter);");
|
||||
}
|
||||
}
|
||||
|
||||
class _ReferencedOrdering extends _Ordering {
|
||||
final String fieldGetter;
|
||||
final String orderingName;
|
||||
final _TableNames referencedTable;
|
||||
final _ColumnNames referencedColumn;
|
||||
_ReferencedOrdering(this.fieldGetter, this.orderingName, this.referencedTable,
|
||||
this.referencedColumn);
|
||||
|
||||
@override
|
||||
void writeOrdering(TextEmitter leaf) {
|
||||
leaf
|
||||
..writeDriftRef("ComposableOrdering")
|
||||
..write(" $orderingName(")
|
||||
..writeDriftRef("ComposableOrdering")
|
||||
..writeln(" Function( ${referencedTable.orderingComposer} o) o) {")
|
||||
..writeln('''
|
||||
return referenced(
|
||||
referencedTable: state.db.${referencedTable.tableGetterName},
|
||||
getCurrentColumn: (f) => f.$fieldGetter,
|
||||
getReferencedColumn: (f) => f.${referencedColumn.fieldGetter},
|
||||
getReferencedComposer: (db, table) => ${referencedTable.orderingComposer}(db, table),
|
||||
builder: o);
|
||||
}''');
|
||||
}
|
||||
}
|
||||
|
||||
class _ColumnNames {
|
||||
/// The getter for the field
|
||||
///
|
||||
/// E.G `id`
|
||||
final String fieldGetter;
|
||||
final List<_Filter> filters;
|
||||
final List<_Ordering> orderings;
|
||||
_ColumnNames(this.fieldGetter, this.filters, this.orderings);
|
||||
}
|
||||
|
||||
class _TableNames {
|
||||
/// The current table
|
||||
final DriftTable table;
|
||||
|
||||
/// The name of the filter composer class
|
||||
///
|
||||
/// E.G `UserFilterComposer`
|
||||
final String filterComposer;
|
||||
|
||||
/// The name of the filter composer class
|
||||
///
|
||||
/// E.G `UserOrderingComposer`
|
||||
final String orderingComposer;
|
||||
|
||||
/// The name of the processed table manager class
|
||||
///
|
||||
/// E.G `UserProcessedTableManager`
|
||||
final String processedTableManager;
|
||||
|
||||
/// The name of the table manager with filtering class
|
||||
///
|
||||
/// E.G `UserTableManagerWithFiltering`
|
||||
final String tableManagerWithFiltering;
|
||||
|
||||
/// The name of the table manager with ordering class
|
||||
///
|
||||
/// E.G `UserTableManagerWithOrdering`
|
||||
final String tableManagerWithOrdering;
|
||||
|
||||
/// The name of the root table manager class
|
||||
///
|
||||
/// E.G `UserTableManager`
|
||||
final String rootTableManager;
|
||||
|
||||
Names(String name)
|
||||
: filterComposer = '${name}FilterComposer',
|
||||
orderingComposer = '${name}OrderingComposer',
|
||||
processedTableManager = '${name}ProcessedTableManager',
|
||||
tableManagerWithFiltering = '${name}TableManagerWithFiltering',
|
||||
tableManagerWithOrdering = '${name}TableManagerWithOrdering',
|
||||
rootTableManager = '${name}TableManager';
|
||||
/// Name of the table class that will be generated
|
||||
///
|
||||
/// E.G `$CategoriesTable`
|
||||
final String tableClassName;
|
||||
|
||||
/// Name of the getter for the table
|
||||
///
|
||||
/// E.G `categories`
|
||||
final String tableGetterName;
|
||||
|
||||
/// Name of the class that cooresponds to a table row
|
||||
///
|
||||
/// E.G `Category`
|
||||
final String rowClassName;
|
||||
|
||||
/// Columns with their names, filters and orderings
|
||||
final List<_ColumnNames> columns;
|
||||
|
||||
final List<_ReferencedFilter> backRefFilters;
|
||||
|
||||
_TableNames(this.table)
|
||||
: filterComposer = '${table.entityInfoName}FilterComposer',
|
||||
orderingComposer = '${table.entityInfoName}OrderingComposer',
|
||||
processedTableManager = '${table.entityInfoName}ProcessedTableManager',
|
||||
tableManagerWithFiltering =
|
||||
'${table.entityInfoName}TableManagerWithFiltering',
|
||||
tableManagerWithOrdering =
|
||||
'${table.entityInfoName}TableManagerWithOrdering',
|
||||
rootTableManager = '${table.entityInfoName}TableManager',
|
||||
rowClassName = table.nameOfRowClass,
|
||||
tableClassName = table.entityInfoName,
|
||||
tableGetterName = table.dbGetterName,
|
||||
backRefFilters = [],
|
||||
columns = [];
|
||||
|
||||
void writeManager(TextEmitter leaf, String dbClassName) {
|
||||
// Write the FilterComposer
|
||||
leaf
|
||||
..write('class $filterComposer extends ')
|
||||
..writeDriftRef('FilterComposer')
|
||||
..writeln('<$dbClassName,$tableClassName> {')
|
||||
..writeln('$filterComposer(super.db, super.table);');
|
||||
for (var c in columns) {
|
||||
for (var f in c.filters) {
|
||||
f.writeFilter(leaf);
|
||||
}
|
||||
}
|
||||
for (var f in backRefFilters) {
|
||||
f.writeFilter(leaf);
|
||||
}
|
||||
leaf.writeln('}');
|
||||
|
||||
// Write the OrderingComposer
|
||||
leaf
|
||||
..write('class $orderingComposer extends ')
|
||||
..writeDriftRef('OrderingComposer')
|
||||
..writeln('<$dbClassName,$tableClassName> {')
|
||||
..writeln('$orderingComposer(super.db, super.table);');
|
||||
for (var c in columns) {
|
||||
for (var o in c.orderings) {
|
||||
o.writeOrdering(leaf);
|
||||
}
|
||||
}
|
||||
leaf.writeln('}');
|
||||
|
||||
// Write the ProcessedTableManager
|
||||
leaf
|
||||
..write('class $processedTableManager extends ')
|
||||
..writeDriftRef('ProcessedTableManager')
|
||||
..writeln(
|
||||
'<$dbClassName,$tableClassName,$rowClassName,$filterComposer,$orderingComposer> {')
|
||||
..writeln('const $processedTableManager(super.state);')
|
||||
..writeln('}');
|
||||
|
||||
// Write the TableManagerWithFiltering
|
||||
leaf
|
||||
..write('class $tableManagerWithFiltering extends ')
|
||||
..writeDriftRef('TableManagerWithFiltering')
|
||||
..writeln(
|
||||
'<$dbClassName,$tableClassName,$rowClassName,$filterComposer,$orderingComposer,$processedTableManager> {')
|
||||
..writeln(
|
||||
'const $tableManagerWithFiltering(super.state,{required super.getChildManager});')
|
||||
..writeln('}');
|
||||
|
||||
// Write the TableManagerWithOrdering
|
||||
leaf
|
||||
..write('class $tableManagerWithOrdering extends ')
|
||||
..writeDriftRef('TableManagerWithOrdering')
|
||||
..writeln(
|
||||
'<$dbClassName,$tableClassName,$rowClassName,$filterComposer,$orderingComposer,$processedTableManager> {')
|
||||
..writeln(
|
||||
'const $tableManagerWithOrdering(super.state,{required super.getChildManager});')
|
||||
..writeln('}');
|
||||
// Write the Root Table Manager
|
||||
leaf
|
||||
..write('class $rootTableManager extends ')
|
||||
..writeDriftRef('RootTableManager')
|
||||
..writeln(
|
||||
'<$dbClassName,$tableClassName,$rowClassName,$filterComposer,$orderingComposer,$processedTableManager,$tableManagerWithFiltering,$tableManagerWithOrdering> {')
|
||||
..writeln('$rootTableManager($dbClassName db, $tableClassName table)')
|
||||
..writeln(": super(")
|
||||
..writeDriftRef("TableManagerState")
|
||||
..write(
|
||||
"""(db: db, table: table, filteringComposer:$filterComposer(db, table),orderingComposer:$orderingComposer(db, table)),
|
||||
getChildManagerWithFiltering: (f) => $tableManagerWithFiltering(f,getChildManager: (f) => $processedTableManager(f)),
|
||||
getChildManagerWithOrdering: (f) => $tableManagerWithOrdering(f,getChildManager: (f) =>$processedTableManager(f)));""")
|
||||
..writeln('}');
|
||||
}
|
||||
|
||||
void addFiltersAndOrderings(List<DriftTable> tables, TextEmitter leaf) {
|
||||
/// First add the filters and orderings for the columns
|
||||
/// of the current table
|
||||
for (var column in table.columns) {
|
||||
final c = _ColumnNames(column.nameInDart, [], []);
|
||||
final innerColumnType =
|
||||
leaf.dartCode(leaf.innerColumnType(column.sqlType));
|
||||
if (column.typeConverter != null) {
|
||||
final mappedType = leaf.dartCode(leaf.writer.dartType(column));
|
||||
c.filters.add(_FilterWithConverter(
|
||||
c.fieldGetter, innerColumnType, c.fieldGetter, mappedType));
|
||||
} else {
|
||||
c.filters
|
||||
.add(_RegularFilter(c.fieldGetter, innerColumnType, c.fieldGetter));
|
||||
}
|
||||
c.orderings
|
||||
.add(_RegularOrdering(c.fieldGetter, innerColumnType, c.fieldGetter));
|
||||
|
||||
final referencedCol = column.constraints
|
||||
.whereType<ForeignKeyReference>()
|
||||
.firstOrNull
|
||||
?.otherColumn;
|
||||
final referencedTable = referencedCol?.owner;
|
||||
if (referencedCol != null && referencedTable is DriftTable) {
|
||||
final referencedTableNames = _TableNames(referencedTable);
|
||||
final referencedColumnNames =
|
||||
_ColumnNames(referencedCol.nameInDart, [], []);
|
||||
c.filters.add(_ReferencedFilter(c.fieldGetter, "${c.fieldGetter}Ref",
|
||||
referencedTableNames, referencedColumnNames));
|
||||
c.orderings.add(_ReferencedOrdering(
|
||||
c.fieldGetter,
|
||||
"${c.fieldGetter}OrderBy",
|
||||
referencedTableNames,
|
||||
referencedColumnNames));
|
||||
}
|
||||
columns.add(c);
|
||||
}
|
||||
for (var otherTable in tables) {
|
||||
final otherTableNames = _TableNames(otherTable);
|
||||
|
||||
/// We are adding backrefs now, skip the current table
|
||||
if (otherTableNames.tableClassName == tableClassName) {
|
||||
continue;
|
||||
}
|
||||
for (var otherColumn in otherTable.columns) {
|
||||
final referencedCol = otherColumn.constraints
|
||||
.whereType<ForeignKeyReference>()
|
||||
.firstOrNull
|
||||
?.otherColumn;
|
||||
final referencedTable = referencedCol?.owner;
|
||||
if (referencedCol != null && referencedTable is DriftTable) {
|
||||
final referencedTableNames = _TableNames(referencedTable);
|
||||
final referencedColumnNames =
|
||||
_ColumnNames(referencedCol.nameInDart, [], []);
|
||||
|
||||
// If we are referencing the current table, add a back ref
|
||||
if (referencedTableNames.tableClassName == tableClassName) {
|
||||
backRefFilters.add(_ReferencedFilter(
|
||||
referencedColumnNames.fieldGetter,
|
||||
"${otherTableNames.tableClassName.camelCase}Refs",
|
||||
otherTableNames,
|
||||
referencedColumnNames));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ManagerWriter {
|
||||
|
@ -33,207 +353,37 @@ class ManagerWriter {
|
|||
|
||||
ManagerWriter(this._scope, this._dbClassName) : _addedTables = [];
|
||||
|
||||
void writeManagers(TextEmitter leaf, DriftTable table) {
|
||||
final names = Names(table.entityInfoName);
|
||||
|
||||
// Write the ProcessedTableManager
|
||||
leaf
|
||||
..write('class ${names.processedTableManager} extends ')
|
||||
..writeDriftRef('ProcessedTableManager')
|
||||
..writeln(
|
||||
'<$_dbClassName,${table.entityInfoName},${table.nameOfRowClass},${names.filterComposer},${names.orderingComposer}> {')
|
||||
..writeln('const ${names.processedTableManager}(super.state);')
|
||||
..writeln('}');
|
||||
|
||||
// Write the TableManagerWithFiltering
|
||||
leaf
|
||||
..write('class ${names.tableManagerWithFiltering} extends ')
|
||||
..writeDriftRef('TableManagerWithFiltering')
|
||||
..writeln(
|
||||
'<$_dbClassName,${table.entityInfoName},${table.nameOfRowClass},${names.filterComposer},${names.orderingComposer},${names.processedTableManager}> {')
|
||||
..writeln(
|
||||
'const ${names.tableManagerWithFiltering}(super.state,{required super.getChildManager});')
|
||||
..writeln('}');
|
||||
|
||||
// Write the TableManagerWithOrdering
|
||||
leaf
|
||||
..write('class ${names.tableManagerWithOrdering} extends ')
|
||||
..writeDriftRef('TableManagerWithOrdering')
|
||||
..writeln(
|
||||
'<$_dbClassName,${table.entityInfoName},${table.nameOfRowClass},${names.filterComposer},${names.orderingComposer},${names.processedTableManager}> {')
|
||||
..writeln(
|
||||
'const ${names.tableManagerWithOrdering}(super.state,{required super.getChildManager});')
|
||||
..writeln('}');
|
||||
// Write the Root Table Manager
|
||||
leaf
|
||||
..write('class ${names.rootTableManager} extends ')
|
||||
..writeDriftRef('RootTableManager')
|
||||
..writeln(
|
||||
'<$_dbClassName,${table.entityInfoName},${table.nameOfRowClass},${names.filterComposer},${names.orderingComposer},${names.processedTableManager},${names.tableManagerWithFiltering},${names.tableManagerWithOrdering}> {')
|
||||
..writeln(
|
||||
'${names.rootTableManager}($_dbClassName db, ${table.entityInfoName} table)')
|
||||
..writeln(": super(")
|
||||
..writeDriftRef("TableManagerState")
|
||||
..write(
|
||||
"""(db: db, table: table, filteringComposer:${names.filterComposer}(db, table),orderingComposer:${names.orderingComposer}(db, table)),
|
||||
getChildManagerWithFiltering: (f) => ${names.tableManagerWithFiltering}(f,getChildManager: (f) => ${names.processedTableManager}(f)),
|
||||
getChildManagerWithOrdering: (f) => ${names.tableManagerWithOrdering}(f,getChildManager: (f) =>${names.processedTableManager}(f)));""")
|
||||
..writeln('}');
|
||||
}
|
||||
|
||||
void _writeTableManagers(DriftTable table, List<DriftTable> otherTables) {
|
||||
final leaf = _scope.leaf();
|
||||
|
||||
final filters = StringBuffer();
|
||||
final orderings = StringBuffer();
|
||||
|
||||
for (var col in table.columns) {
|
||||
final getterName =
|
||||
(col.nameInDart + (col.isForeignKey ? " id" : " ")).camelCase;
|
||||
|
||||
// The type this column stores
|
||||
final innerColumnType = leaf.dartCode(leaf.innerColumnType(col.sqlType));
|
||||
filters.writeln(
|
||||
"ColumnFilters<$innerColumnType> get $getterName => ColumnFilters(state.table.${col.nameInDart});");
|
||||
|
||||
if (col.typeConverter != null) {
|
||||
final mappedType = leaf.dartCode(leaf.writer.dartType(col));
|
||||
filters.writeln(
|
||||
"ColumnWithTypeConverterFilters<$mappedType,$innerColumnType> get ${getterName}Ref => ColumnWithTypeConverterFilters(state.table.${col.nameInDart});");
|
||||
}
|
||||
|
||||
orderings.writeln(
|
||||
"ColumnOrderings get $getterName => ColumnOrderings(state.table.${col.nameInDart});");
|
||||
|
||||
if (col.isForeignKey) {
|
||||
final referencedCol = col.constraints
|
||||
.whereType<ForeignKeyReference>()
|
||||
.firstOrNull
|
||||
?.otherColumn;
|
||||
if (referencedCol != null) {
|
||||
if (referencedCol.owner is DriftTable) {
|
||||
final referencedTableGetter = referencedCol.owner.dbGetterName;
|
||||
final referencedTableName =
|
||||
Names(referencedCol.owner.entityInfoName);
|
||||
|
||||
if (referencedTableGetter != null) {
|
||||
filters.write('''
|
||||
ComposableFilter ${col.nameInDart}Filter(
|
||||
ComposableFilter Function(${referencedTableName.filterComposer} f) f) {
|
||||
return referenced(
|
||||
referencedTable: state.db.$referencedTableGetter,
|
||||
getCurrentColumn: (f) => f.${col.nameInDart},
|
||||
getReferencedColumn: (f) => f.${referencedCol.nameInDart},
|
||||
getReferencedComposer: (db, table) => ${referencedTableName.filterComposer}(db, table),
|
||||
builder: f);
|
||||
}
|
||||
''');
|
||||
|
||||
orderings.write('''
|
||||
ComposableOrdering ${col.nameInDart}OrderBy(
|
||||
ComposableOrdering Function(${referencedTableName.orderingComposer} o) o) {
|
||||
return referenced(
|
||||
referencedTable: state.db.$referencedTableGetter,
|
||||
getCurrentColumn: (f) => f.${col.nameInDart},
|
||||
getReferencedColumn: (f) => f.${referencedCol.nameInDart},
|
||||
getReferencedComposer: (db, table) => ${referencedTableName.orderingComposer}(db, table),
|
||||
builder: o);
|
||||
}
|
||||
''');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Any other table who has a reference to this table should have a back ref created for it
|
||||
for (var otherTable in otherTables) {
|
||||
for (var otherColumn in otherTable.columns) {
|
||||
if (otherColumn.isForeignKey) {
|
||||
final foreignKey = otherColumn.constraints
|
||||
.whereType<ForeignKeyReference>()
|
||||
.firstOrNull;
|
||||
// Check if this is a foreign key
|
||||
if (foreignKey == null) {
|
||||
continue;
|
||||
}
|
||||
// Check if the foreign key references this table
|
||||
final thisColumn = foreignKey.otherColumn;
|
||||
final thisTable = thisColumn.owner;
|
||||
|
||||
final otherColumnName = Names(otherTable.entityInfoName);
|
||||
// Check if the foreign key references this table
|
||||
if (thisTable is DriftTable &&
|
||||
table.schemaName == thisTable.schemaName) {
|
||||
filters.write('''
|
||||
ComposableFilter ${("referenced ${otherTable.dbGetterName} ${otherColumn.nameInDart}").camelCase}(
|
||||
ComposableFilter Function(${otherColumnName.filterComposer} f) f) {
|
||||
return referenced(
|
||||
getCurrentColumn: (f) => f.${thisColumn.nameInDart},
|
||||
referencedTable: state.db.${otherTable.dbGetterName},
|
||||
getReferencedColumn: (f) => f.${otherColumn.nameInDart},
|
||||
getReferencedComposer: (db, table) => ${otherColumnName.filterComposer}(db, table),
|
||||
builder: f);
|
||||
}
|
||||
''');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
final names = Names(table.entityInfoName);
|
||||
|
||||
leaf.write("""
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class ${names.filterComposer}
|
||||
extends FilterComposer<$_dbClassName, ${table.entityInfoName}> {
|
||||
${names.filterComposer}(super.db, super.table);
|
||||
|
||||
$filters
|
||||
|
||||
}
|
||||
|
||||
class ${names.orderingComposer}
|
||||
extends OrderingComposer<$_dbClassName, ${table.entityInfoName}> {
|
||||
${names.orderingComposer}(super.db, super.table);
|
||||
|
||||
$orderings
|
||||
|
||||
|
||||
}""");
|
||||
writeManagers(leaf, table);
|
||||
}
|
||||
|
||||
String get managerGetter {
|
||||
return '''${_dbClassName}Manager get managers => ${_dbClassName}Manager(this);''';
|
||||
return '''$_dbMangerName get managers => $_dbMangerName(this);''';
|
||||
}
|
||||
|
||||
void addTable(DriftTable table) {
|
||||
_addedTables.add(table);
|
||||
}
|
||||
|
||||
String get _dbMangerName => '${_dbClassName}Manager';
|
||||
|
||||
void write() {
|
||||
for (var table in _addedTables) {
|
||||
_writeTableManagers(table, _addedTables);
|
||||
}
|
||||
final leaf = _scope.leaf();
|
||||
final tableNames = <_TableNames>[];
|
||||
for (var table in _addedTables) {
|
||||
final t = _TableNames(table);
|
||||
t.addFiltersAndOrderings(_addedTables, leaf);
|
||||
t.writeManager(leaf, _dbClassName);
|
||||
tableNames.add(t);
|
||||
}
|
||||
final tableManagerGetters = StringBuffer();
|
||||
|
||||
for (var table in _addedTables) {
|
||||
for (var table in tableNames) {
|
||||
tableManagerGetters.writeln(
|
||||
"${table.entityInfoName}TableManager get ${table.dbGetterName} => ${table.entityInfoName}TableManager(_db, _db.${table.dbGetterName});");
|
||||
"${table.rootTableManager} get ${table.tableGetterName} => ${table.rootTableManager}(_db, _db.${table.tableGetterName});");
|
||||
}
|
||||
|
||||
leaf.write("""
|
||||
class ${_dbClassName}Manager {
|
||||
class $_dbMangerName{
|
||||
final $_dbClassName _db;
|
||||
|
||||
${_dbClassName}Manager(this._db);
|
||||
$_dbMangerName(this._db);
|
||||
|
||||
$tableManagerGetters
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue