gen 2.1.0-beta.1
This commit is contained in:
parent
e99e040a50
commit
c14a283861
8 changed files with 20 additions and 14 deletions
|
@ -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.
|
||||
|
|
|
@ -43,7 +43,7 @@ class MigrationGenerator extends GeneratorForAnnotation<Orm> {
|
|||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -58,9 +58,8 @@ FieldElement findPrimaryFieldInList(
|
|||
return specialId;
|
||||
}
|
||||
|
||||
final Map<String, OrmBuildContext> _cache = {};
|
||||
|
||||
Future<OrmBuildContext> buildOrmContext(
|
||||
Map<String, OrmBuildContext> cache,
|
||||
ClassElement clazz,
|
||||
ConstantReader annotation,
|
||||
BuildStep buildStep,
|
||||
|
@ -79,8 +78,8 @@ Future<OrmBuildContext> 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<OrmBuildContext> 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<OrmBuildContext> 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<OrmBuildContext> 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)),
|
||||
|
|
|
@ -39,7 +39,7 @@ class OrmGenerator extends GeneratorForAnnotation<Orm> {
|
|||
Future<String> 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();
|
||||
|
|
|
@ -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 <thosakwe@gmail.com>
|
||||
homepage: https://github.com/angel-dart/orm
|
||||
|
|
|
@ -65,7 +65,7 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
|
|||
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<User, UserQueryWhere> {
|
|||
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'],
|
||||
|
|
|
@ -209,7 +209,7 @@ class WeirdJoinQuery extends Query<WeirdJoin, WeirdJoinQueryWhere> {
|
|||
'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<Foo, FooQueryWhere> {
|
|||
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'],
|
||||
|
|
|
@ -67,7 +67,7 @@ class UserQuery extends Query<User, UserQueryWhere> {
|
|||
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<Role, RoleQueryWhere> {
|
|||
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 [
|
||||
|
|
Loading…
Reference in a new issue