From c14a2838612b55fb15beab30a776c0d605d95a14 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Wed, 9 Oct 2019 15:39:25 -0400 Subject: [PATCH] gen 2.1.0-beta.1 --- angel_orm_generator/CHANGELOG.md | 5 +++++ angel_orm_generator/lib/src/migration_generator.dart | 2 +- angel_orm_generator/lib/src/orm_build_context.dart | 11 ++++++----- angel_orm_generator/lib/src/orm_generator.dart | 2 +- angel_orm_generator/pubspec.yaml | 2 +- angel_orm_test/lib/src/models/email_indexed.g.dart | 4 ++-- angel_orm_test/lib/src/models/unorthodox.g.dart | 4 ++-- angel_orm_test/lib/src/models/user.g.dart | 4 ++-- 8 files changed, 20 insertions(+), 14 deletions(-) diff --git a/angel_orm_generator/CHANGELOG.md b/angel_orm_generator/CHANGELOG.md index f34dd29a..4feb0230 100644 --- a/angel_orm_generator/CHANGELOG.md +++ b/angel_orm_generator/CHANGELOG.md @@ -1,3 +1,8 @@ +# 2.1.0-beta.1 +* `OrmBuildContext` caching is now local to a `Builder`, so `watch` +*should* finally always run when required. Should resolve +[#85](https://github.com/angel-dart/orm/issues/85). + # 2.1.0-beta * Relationships have always generated subqueries; now these subqueries are available as `Query` objects on generated classes. diff --git a/angel_orm_generator/lib/src/migration_generator.dart b/angel_orm_generator/lib/src/migration_generator.dart index eb629f2b..d54f0cba 100644 --- a/angel_orm_generator/lib/src/migration_generator.dart +++ b/angel_orm_generator/lib/src/migration_generator.dart @@ -43,7 +43,7 @@ class MigrationGenerator extends GeneratorForAnnotation { } var resolver = await buildStep.resolver; - var ctx = await buildOrmContext(element as ClassElement, annotation, + var ctx = await buildOrmContext({}, element as ClassElement, annotation, buildStep, resolver, autoSnakeCaseNames != false); var lib = generateMigrationLibrary( ctx, element as ClassElement, resolver, buildStep); diff --git a/angel_orm_generator/lib/src/orm_build_context.dart b/angel_orm_generator/lib/src/orm_build_context.dart index 6013c63f..4ceea5a0 100644 --- a/angel_orm_generator/lib/src/orm_build_context.dart +++ b/angel_orm_generator/lib/src/orm_build_context.dart @@ -58,9 +58,8 @@ FieldElement findPrimaryFieldInList( return specialId; } -final Map _cache = {}; - Future buildOrmContext( + Map cache, ClassElement clazz, ConstantReader annotation, BuildStep buildStep, @@ -79,8 +78,8 @@ Future buildOrmContext( } var id = clazz.location.components.join('-'); - if (_cache.containsKey(id)) { - return _cache[id]; + if (cache.containsKey(id)) { + return cache[id]; } var buildCtx = await buildContext( clazz, annotation, buildStep, resolver, autoSnakeCaseNames, @@ -94,7 +93,7 @@ Future buildOrmContext( (ormAnnotation.tableName?.isNotEmpty == true) ? ormAnnotation.tableName : pluralize(ReCase(clazz.name).snakeCase)); - _cache[id] = ctx; + cache[id] = ctx; // Read all fields for (var field in buildCtx.fields) { @@ -173,6 +172,7 @@ Future buildOrmContext( var modelType = firstModelAncestor(refType) ?? refType; foreign = await buildOrmContext( + cache, modelType.element as ClassElement, ConstantReader(const TypeChecker.fromRuntime(Orm) .firstAnnotationOf(modelType.element)), @@ -183,6 +183,7 @@ Future buildOrmContext( // Resolve throughType as well if (through != null && through is InterfaceType) { throughContext = await buildOrmContext( + cache, through.element, ConstantReader(const TypeChecker.fromRuntime(Serializable) .firstAnnotationOf(modelType.element)), diff --git a/angel_orm_generator/lib/src/orm_generator.dart b/angel_orm_generator/lib/src/orm_generator.dart index b7f7dc93..d2e13637 100644 --- a/angel_orm_generator/lib/src/orm_generator.dart +++ b/angel_orm_generator/lib/src/orm_generator.dart @@ -39,7 +39,7 @@ class OrmGenerator extends GeneratorForAnnotation { Future generateForAnnotatedElement( Element element, ConstantReader annotation, BuildStep buildStep) async { if (element is ClassElement) { - var ctx = await buildOrmContext(element, annotation, buildStep, + var ctx = await buildOrmContext({}, element, annotation, buildStep, buildStep.resolver, autoSnakeCaseNames); var lib = buildOrmLibrary(buildStep.inputId, ctx); return lib.accept(DartEmitter()).toString(); diff --git a/angel_orm_generator/pubspec.yaml b/angel_orm_generator/pubspec.yaml index f86f6027..75f33075 100644 --- a/angel_orm_generator/pubspec.yaml +++ b/angel_orm_generator/pubspec.yaml @@ -1,5 +1,5 @@ name: angel_orm_generator -version: 2.1.0-beta +version: 2.1.0-beta.1 description: Code generators for Angel's ORM. Generates query builder classes. author: Tobe O homepage: https://github.com/angel-dart/orm diff --git a/angel_orm_test/lib/src/models/email_indexed.g.dart b/angel_orm_test/lib/src/models/email_indexed.g.dart index 42c387fe..4933ad99 100644 --- a/angel_orm_test/lib/src/models/email_indexed.g.dart +++ b/angel_orm_test/lib/src/models/email_indexed.g.dart @@ -65,7 +65,7 @@ class RoleQuery extends Query { trampoline.add(tableName); _where = RoleQueryWhere(this); leftJoin( - '(SELECT role_users.role_role , users.email, users.name, users.password FROM users LEFT JOIN role_users ON role_users.user_email=users.email)', + '(SELECT role_users.role_role, users.email, users.name, users.password FROM users LEFT JOIN role_users ON role_users.user_email=users.email)', 'role', 'role_role', additionalFields: const ['email', 'name', 'password'], @@ -335,7 +335,7 @@ class UserQuery extends Query { trampoline.add(tableName); _where = UserQueryWhere(this); leftJoin( - '(SELECT role_users.user_email , roles.role FROM roles LEFT JOIN role_users ON role_users.role_role=roles.role)', + '(SELECT role_users.user_email, roles.role FROM roles LEFT JOIN role_users ON role_users.role_role=roles.role)', 'email', 'user_email', additionalFields: const ['role'], diff --git a/angel_orm_test/lib/src/models/unorthodox.g.dart b/angel_orm_test/lib/src/models/unorthodox.g.dart index 976ced94..7a803db9 100644 --- a/angel_orm_test/lib/src/models/unorthodox.g.dart +++ b/angel_orm_test/lib/src/models/unorthodox.g.dart @@ -209,7 +209,7 @@ class WeirdJoinQuery extends Query { 'parent', additionalFields: const ['i', 'parent'], trampoline: trampoline); leftJoin( - '(SELECT foo_pivots.weird_join_id , foos.bar FROM foos LEFT JOIN foo_pivots ON foo_pivots.foo_bar=foos.bar)', + '(SELECT foo_pivots.weird_join_id, foos.bar FROM foos LEFT JOIN foo_pivots ON foo_pivots.foo_bar=foos.bar)', 'id', 'weird_join_id', additionalFields: const ['bar'], @@ -610,7 +610,7 @@ class FooQuery extends Query { trampoline.add(tableName); _where = FooQueryWhere(this); leftJoin( - '(SELECT foo_pivots.foo_bar , weird_joins.id, weird_joins.join_name FROM weird_joins LEFT JOIN foo_pivots ON foo_pivots.weird_join_id=weird_joins.id)', + '(SELECT foo_pivots.foo_bar, weird_joins.id, weird_joins.join_name FROM weird_joins LEFT JOIN foo_pivots ON foo_pivots.weird_join_id=weird_joins.id)', 'bar', 'foo_bar', additionalFields: const ['id', 'join_name'], diff --git a/angel_orm_test/lib/src/models/user.g.dart b/angel_orm_test/lib/src/models/user.g.dart index 2e113ab5..d8ecab33 100644 --- a/angel_orm_test/lib/src/models/user.g.dart +++ b/angel_orm_test/lib/src/models/user.g.dart @@ -67,7 +67,7 @@ class UserQuery extends Query { trampoline.add(tableName); _where = UserQueryWhere(this); leftJoin( - '(SELECT role_users.user_id , roles.id, roles.created_at, roles.updated_at, roles.name FROM roles LEFT JOIN role_users ON role_users.role_id=roles.id)', + '(SELECT role_users.user_id, roles.id, roles.created_at, roles.updated_at, roles.name FROM roles LEFT JOIN role_users ON role_users.role_id=roles.id)', 'id', 'user_id', additionalFields: const ['id', 'created_at', 'updated_at', 'name'], @@ -402,7 +402,7 @@ class RoleQuery extends Query { trampoline.add(tableName); _where = RoleQueryWhere(this); leftJoin( - '(SELECT role_users.role_id , users.id, users.created_at, users.updated_at, users.username, users.password, users.email FROM users LEFT JOIN role_users ON role_users.user_id=users.id)', + '(SELECT role_users.role_id, users.id, users.created_at, users.updated_at, users.username, users.password, users.email FROM users LEFT JOIN role_users ON role_users.user_id=users.id)', 'id', 'role_id', additionalFields: const [