gen 2.1.0-beta.1

This commit is contained in:
Tobe O 2019-10-09 15:39:25 -04:00
parent e99e040a50
commit c14a283861
8 changed files with 20 additions and 14 deletions

View file

@ -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 # 2.1.0-beta
* Relationships have always generated subqueries; now these subqueries are * Relationships have always generated subqueries; now these subqueries are
available as `Query` objects on generated classes. available as `Query` objects on generated classes.

View file

@ -43,7 +43,7 @@ class MigrationGenerator extends GeneratorForAnnotation<Orm> {
} }
var resolver = await buildStep.resolver; 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); buildStep, resolver, autoSnakeCaseNames != false);
var lib = generateMigrationLibrary( var lib = generateMigrationLibrary(
ctx, element as ClassElement, resolver, buildStep); ctx, element as ClassElement, resolver, buildStep);

View file

@ -58,9 +58,8 @@ FieldElement findPrimaryFieldInList(
return specialId; return specialId;
} }
final Map<String, OrmBuildContext> _cache = {};
Future<OrmBuildContext> buildOrmContext( Future<OrmBuildContext> buildOrmContext(
Map<String, OrmBuildContext> cache,
ClassElement clazz, ClassElement clazz,
ConstantReader annotation, ConstantReader annotation,
BuildStep buildStep, BuildStep buildStep,
@ -79,8 +78,8 @@ Future<OrmBuildContext> buildOrmContext(
} }
var id = clazz.location.components.join('-'); var id = clazz.location.components.join('-');
if (_cache.containsKey(id)) { if (cache.containsKey(id)) {
return _cache[id]; return cache[id];
} }
var buildCtx = await buildContext( var buildCtx = await buildContext(
clazz, annotation, buildStep, resolver, autoSnakeCaseNames, clazz, annotation, buildStep, resolver, autoSnakeCaseNames,
@ -94,7 +93,7 @@ Future<OrmBuildContext> buildOrmContext(
(ormAnnotation.tableName?.isNotEmpty == true) (ormAnnotation.tableName?.isNotEmpty == true)
? ormAnnotation.tableName ? ormAnnotation.tableName
: pluralize(ReCase(clazz.name).snakeCase)); : pluralize(ReCase(clazz.name).snakeCase));
_cache[id] = ctx; cache[id] = ctx;
// Read all fields // Read all fields
for (var field in buildCtx.fields) { for (var field in buildCtx.fields) {
@ -173,6 +172,7 @@ Future<OrmBuildContext> buildOrmContext(
var modelType = firstModelAncestor(refType) ?? refType; var modelType = firstModelAncestor(refType) ?? refType;
foreign = await buildOrmContext( foreign = await buildOrmContext(
cache,
modelType.element as ClassElement, modelType.element as ClassElement,
ConstantReader(const TypeChecker.fromRuntime(Orm) ConstantReader(const TypeChecker.fromRuntime(Orm)
.firstAnnotationOf(modelType.element)), .firstAnnotationOf(modelType.element)),
@ -183,6 +183,7 @@ Future<OrmBuildContext> buildOrmContext(
// Resolve throughType as well // Resolve throughType as well
if (through != null && through is InterfaceType) { if (through != null && through is InterfaceType) {
throughContext = await buildOrmContext( throughContext = await buildOrmContext(
cache,
through.element, through.element,
ConstantReader(const TypeChecker.fromRuntime(Serializable) ConstantReader(const TypeChecker.fromRuntime(Serializable)
.firstAnnotationOf(modelType.element)), .firstAnnotationOf(modelType.element)),

View file

@ -39,7 +39,7 @@ class OrmGenerator extends GeneratorForAnnotation<Orm> {
Future<String> generateForAnnotatedElement( Future<String> generateForAnnotatedElement(
Element element, ConstantReader annotation, BuildStep buildStep) async { Element element, ConstantReader annotation, BuildStep buildStep) async {
if (element is ClassElement) { if (element is ClassElement) {
var ctx = await buildOrmContext(element, annotation, buildStep, var ctx = await buildOrmContext({}, element, annotation, buildStep,
buildStep.resolver, autoSnakeCaseNames); buildStep.resolver, autoSnakeCaseNames);
var lib = buildOrmLibrary(buildStep.inputId, ctx); var lib = buildOrmLibrary(buildStep.inputId, ctx);
return lib.accept(DartEmitter()).toString(); return lib.accept(DartEmitter()).toString();

View file

@ -1,5 +1,5 @@
name: angel_orm_generator 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. description: Code generators for Angel's ORM. Generates query builder classes.
author: Tobe O <thosakwe@gmail.com> author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/orm homepage: https://github.com/angel-dart/orm

View file

@ -65,7 +65,7 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
trampoline.add(tableName); trampoline.add(tableName);
_where = RoleQueryWhere(this); _where = RoleQueryWhere(this);
leftJoin( 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_role', 'role_role',
additionalFields: const ['email', 'name', 'password'], additionalFields: const ['email', 'name', 'password'],
@ -335,7 +335,7 @@ class UserQuery extends Query<User, UserQueryWhere> {
trampoline.add(tableName); trampoline.add(tableName);
_where = UserQueryWhere(this); _where = UserQueryWhere(this);
leftJoin( 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', 'email',
'user_email', 'user_email',
additionalFields: const ['role'], additionalFields: const ['role'],

View file

@ -209,7 +209,7 @@ class WeirdJoinQuery extends Query<WeirdJoin, WeirdJoinQueryWhere> {
'parent', 'parent',
additionalFields: const ['i', 'parent'], trampoline: trampoline); additionalFields: const ['i', 'parent'], trampoline: trampoline);
leftJoin( 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', 'id',
'weird_join_id', 'weird_join_id',
additionalFields: const ['bar'], additionalFields: const ['bar'],
@ -610,7 +610,7 @@ class FooQuery extends Query<Foo, FooQueryWhere> {
trampoline.add(tableName); trampoline.add(tableName);
_where = FooQueryWhere(this); _where = FooQueryWhere(this);
leftJoin( 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', 'bar',
'foo_bar', 'foo_bar',
additionalFields: const ['id', 'join_name'], additionalFields: const ['id', 'join_name'],

View file

@ -67,7 +67,7 @@ class UserQuery extends Query<User, UserQueryWhere> {
trampoline.add(tableName); trampoline.add(tableName);
_where = UserQueryWhere(this); _where = UserQueryWhere(this);
leftJoin( 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', 'id',
'user_id', 'user_id',
additionalFields: const ['id', 'created_at', 'updated_at', 'name'], additionalFields: const ['id', 'created_at', 'updated_at', 'name'],
@ -402,7 +402,7 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
trampoline.add(tableName); trampoline.add(tableName);
_where = RoleQueryWhere(this); _where = RoleQueryWhere(this);
leftJoin( 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', 'id',
'role_id', 'role_id',
additionalFields: const [ additionalFields: const [