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
|
# 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.
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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)),
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue