Updated ORM

This commit is contained in:
thomashii 2021-07-25 21:16:50 +08:00
parent 7f74187e22
commit 5a6992bb16
4 changed files with 21 additions and 6 deletions

View file

@ -1,5 +1,9 @@
# Change Log # Change Log
## 4.0.0
* Updated `Optional` package
## 4.0.0-beta.4 ## 4.0.0-beta.4
* Added `hasSize` to `ColumnType` * Added `hasSize` to `ColumnType`

View file

@ -1,5 +1,5 @@
name: angel3_orm name: angel3_orm
version: 4.0.0-beta.4 version: 4.0.0
description: Runtime support for Angel3 ORM. Includes base classes for queries. description: Runtime support for Angel3 ORM. Includes base classes for queries.
homepage: https://angel3-framework.web.app/ homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/angel3/packages/orm/angel_orm repository: https://github.com/dukefirehawk/angel/tree/angel3/packages/orm/angel_orm
@ -10,7 +10,7 @@ dependencies:
intl: ^0.17.0 intl: ^0.17.0
meta: ^1.3.0 meta: ^1.3.0
string_scanner: ^1.1.0 string_scanner: ^1.1.0
optional: ^6.0.0-nullsafety.2 optional: ^6.0.0
dev_dependencies: dev_dependencies:
angel3_model: ^3.0.0 angel3_model: ^3.0.0
angel3_serialize: ^4.0.0 angel3_serialize: ^4.0.0

View file

@ -12,11 +12,14 @@ import 'package:angel3_serialize_generator/context.dart';
import 'package:build/build.dart'; import 'package:build/build.dart';
import 'package:collection/collection.dart' show IterableExtension; import 'package:collection/collection.dart' show IterableExtension;
import 'package:inflection3/inflection3.dart'; import 'package:inflection3/inflection3.dart';
import 'package:logging/logging.dart';
import 'package:recase/recase.dart'; import 'package:recase/recase.dart';
import 'package:source_gen/source_gen.dart'; import 'package:source_gen/source_gen.dart';
import 'readers.dart'; import 'readers.dart';
var _log = Logger('orm_build_context');
bool isHasRelation(Relationship r) => bool isHasRelation(Relationship r) =>
r.type == RelationshipType.hasOne || r.type == RelationshipType.hasMany; r.type == RelationshipType.hasOne || r.type == RelationshipType.hasMany;
@ -74,19 +77,26 @@ Future<OrmBuildContext?> buildOrmContext(
const TypeChecker.fromRuntime(GeneratedSerializable) const TypeChecker.fromRuntime(GeneratedSerializable)
.firstAnnotationOf(clazz)) != .firstAnnotationOf(clazz)) !=
null) { null) {
clazz = clazz.supertype!.element; if (clazz.supertype != null) {
clazz = clazz.supertype!.element;
}
} }
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!,
heedExclude: heedExclude) as FutureOr<BuildContext>); heedExclude: heedExclude);
var ormAnnotation = reviveORMAnnotation(annotation); var ormAnnotation = reviveORMAnnotation(annotation);
// print( // print(
// 'tableName (${annotation.objectValue.type.name}) => ${ormAnnotation.tableName} from ${clazz.name} (${annotation.revive().namedArguments})'); // 'tableName (${annotation.objectValue.type.name}) => ${ormAnnotation.tableName} from ${clazz.name} (${annotation.revive().namedArguments})');
if (buildCtx == null) {
_log.severe('BuildContext is null');
return null;
}
var ctx = OrmBuildContext( var ctx = OrmBuildContext(
buildCtx, buildCtx,
ormAnnotation, ormAnnotation,

View file

@ -21,6 +21,7 @@ dependencies:
recase: ^4.0.0 recase: ^4.0.0
source_gen: ^1.0.0 source_gen: ^1.0.0
collection: ^1.15.0 collection: ^1.15.0
logging: ^1.0.0
dev_dependencies: dev_dependencies:
angel3_framework: ^4.0.0 angel3_framework: ^4.0.0
angel3_migration: ^4.0.0-beta.1 angel3_migration: ^4.0.0-beta.1