From eabd89aff50fab6962df1df35ce6b520901285db Mon Sep 17 00:00:00 2001 From: Tobe O Date: Sat, 17 Aug 2019 18:36:16 -0400 Subject: [PATCH] Remove dead code --- .../lib/src/orm_generator.dart | 118 ------------------ 1 file changed, 118 deletions(-) diff --git a/angel_orm_generator/lib/src/orm_generator.dart b/angel_orm_generator/lib/src/orm_generator.dart index e2919a90..2eeb2441 100644 --- a/angel_orm_generator/lib/src/orm_generator.dart +++ b/angel_orm_generator/lib/src/orm_generator.dart @@ -344,124 +344,6 @@ class OrmGenerator extends GeneratorForAnnotation { })); } - // 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 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 = {}; - - 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)) {