Remove dead code
This commit is contained in:
parent
30914cc767
commit
eabd89aff5
1 changed files with 0 additions and 118 deletions
|
@ -344,124 +344,6 @@ class OrmGenerator extends GeneratorForAnnotation<Orm> {
|
|||
}));
|
||||
}
|
||||
|
||||
// TODO: Ultimately remove the insert override
|
||||
if (false && ctx.relations.isNotEmpty) {
|
||||
clazz.methods.add(Method((b) {
|
||||
b
|
||||
..name = 'insert'
|
||||
..annotations.add(refer('override'))
|
||||
..requiredParameters.add(Parameter((b) => b..name = 'executor'))
|
||||
..body = Block((b) {
|
||||
var inTransaction = Method((b) {
|
||||
b
|
||||
..modifier = MethodModifier.async
|
||||
..body = Block((b) {
|
||||
b.addExpression(refer('super')
|
||||
.property('insert')
|
||||
.call([refer('executor')])
|
||||
.awaited
|
||||
.assignVar('result'));
|
||||
|
||||
// Just call getOne() again
|
||||
if (ctx.effectiveFields.any((f) =>
|
||||
isSpecialId(ctx, f) ||
|
||||
(ctx.columns[f.name]?.indexType ==
|
||||
IndexType.primaryKey))) {
|
||||
b.addExpression(refer('where')
|
||||
.property('id')
|
||||
.property('equals')
|
||||
.call([
|
||||
(refer('int')
|
||||
.property('tryParse')
|
||||
.call([refer('result').property('id')]))
|
||||
]));
|
||||
|
||||
b.addExpression(refer('result').assign(
|
||||
refer('getOne').call([refer('executor')]).awaited));
|
||||
}
|
||||
|
||||
// TODO: Remove - Fetch the results of @hasMany
|
||||
// ctx.relations.forEach((name, relation) {
|
||||
// if (relation.type == RelationshipType.hasMany) {
|
||||
// // Call fetchLinked();
|
||||
// var fetchLinked = refer('fetchLinked')
|
||||
// .call([refer('result'), refer('executor')]).awaited;
|
||||
// b.addExpression(refer('result').assign(fetchLinked));
|
||||
// }
|
||||
// });
|
||||
|
||||
b.addExpression(refer('result').returned);
|
||||
});
|
||||
});
|
||||
|
||||
b.addExpression(refer('executor')
|
||||
.property('transaction')
|
||||
.call([inTransaction.closure]).returned);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
// Create a Future<T> fetchLinked(T model, QueryExecutor), if necessary.
|
||||
if (false &&
|
||||
ctx.relations.values.any((r) => r.type == RelationshipType.hasMany)) {
|
||||
clazz.methods.add(Method((b) {
|
||||
b
|
||||
..name = 'fetchLinked'
|
||||
..modifier = MethodModifier.async
|
||||
..returns = TypeReference((b) {
|
||||
b
|
||||
..symbol = 'Future'
|
||||
..types.add(ctx.buildContext.modelClassType);
|
||||
})
|
||||
..requiredParameters.addAll([
|
||||
Parameter((b) => b
|
||||
..name = 'model'
|
||||
..type = ctx.buildContext.modelClassType),
|
||||
Parameter((b) => b
|
||||
..name = 'executor'
|
||||
..type = refer('QueryExecutor')),
|
||||
])
|
||||
..body = Block((b) {
|
||||
var args = <String, Expression>{};
|
||||
|
||||
ctx.relations.forEach((name, relation) {
|
||||
// TODO: Should this be entirely removed?
|
||||
if (relation.type == RelationshipType.hasMany) {
|
||||
// For each hasMany, we need to create a query of
|
||||
// the corresponding type.
|
||||
var foreign = relation.foreign;
|
||||
var queryType = refer(
|
||||
'${foreign.buildContext.modelClassNameRecase.pascalCase}Query');
|
||||
var queryInstance = queryType.newInstance([]);
|
||||
|
||||
// Next, we need to apply a cascade that sets the correct query value.
|
||||
var localField = relation.findLocalField(ctx);
|
||||
var foreignField = relation.findForeignField(ctx);
|
||||
|
||||
var queryValue = (isSpecialId(ctx, localField))
|
||||
? 'int.parse(model.id)'
|
||||
: 'model.${localField.name}';
|
||||
var cascadeText =
|
||||
'..where.${foreignField.name}.equals($queryValue)';
|
||||
var queryText = queryInstance.accept(DartEmitter());
|
||||
var combinedExpr =
|
||||
CodeExpression(Code('($queryText$cascadeText)'));
|
||||
|
||||
// Finally, just call get and await it.
|
||||
var expr = combinedExpr
|
||||
.property('get')
|
||||
.call([refer('executor')]).awaited;
|
||||
args[name] = expr;
|
||||
}
|
||||
});
|
||||
|
||||
// Just return a copyWith
|
||||
b.addExpression(
|
||||
refer('model').property('copyWith').call([], args).returned);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
// Also, if there is a @HasMany, generate overrides for query methods that
|
||||
// execute in a transaction, and invoke fetchLinked.
|
||||
if (ctx.relations.values.any((r) => r.type == RelationshipType.hasMany)) {
|
||||
|
|
Loading…
Reference in a new issue