gen@2.0.1

This commit is contained in:
Tobe O 2019-04-20 18:01:42 -04:00
parent 51457cb846
commit fcdc1afa78
6 changed files with 14 additions and 9 deletions

View file

@ -1,5 +1,6 @@
# 2.0.1 # 2.0.1
* Gracefully handle `null` in enum fields. * Gracefully handle `null` in enum fields.
* Add `take` to wherever `skip` is used.
# 2.0.0+2 # 2.0.0+2
* Widen `analyzer` dependency range. * Widen `analyzer` dependency range.

View file

@ -80,6 +80,8 @@ Future<OrmBuildContext> buildOrmContext(
clazz, annotation, buildStep, resolver, autoSnakeCaseNames, clazz, annotation, buildStep, resolver, autoSnakeCaseNames,
heedExclude: heedExclude); heedExclude: heedExclude);
var ormAnnotation = reviveORMAnnotation(annotation); var ormAnnotation = reviveORMAnnotation(annotation);
// print(
// 'tableName (${annotation.objectValue.type.name}) => ${ormAnnotation.tableName} from ${clazz.name} (${annotation.revive().namedArguments})');
var ctx = new OrmBuildContext( var ctx = new OrmBuildContext(
buildCtx, buildCtx,
ormAnnotation, ormAnnotation,
@ -164,7 +166,7 @@ Future<OrmBuildContext> buildOrmContext(
foreign = await buildOrmContext( foreign = await buildOrmContext(
modelType.element as ClassElement, modelType.element as ClassElement,
new ConstantReader(const TypeChecker.fromRuntime(Serializable) new ConstantReader(const TypeChecker.fromRuntime(Orm)
.firstAnnotationOf(modelType.element)), .firstAnnotationOf(modelType.element)),
buildStep, buildStep,
resolver, resolver,

View file

@ -8,7 +8,9 @@ import 'orm_build_context.dart';
const TypeChecker columnTypeChecker = const TypeChecker.fromRuntime(Column); const TypeChecker columnTypeChecker = const TypeChecker.fromRuntime(Column);
Orm reviveORMAnnotation(ConstantReader reader) { Orm reviveORMAnnotation(ConstantReader reader) {
return Orm(tableName: reader.peek('tableName')?.stringValue); return Orm(
tableName: reader.peek('tableName')?.stringValue,
generateMigrations: reader.peek('generateMigrations')?.boolValue ?? true);
} }
class ColumnReader { class ColumnReader {

View file

@ -1,5 +1,5 @@
name: angel_orm_generator name: angel_orm_generator
version: 2.0.0+2 version: 2.0.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

@ -68,7 +68,7 @@ class HasCarQuery extends Query<HasCar, HasCarQueryWhere> {
if (row.every((x) => x == null)) return null; if (row.every((x) => x == null)) return null;
var model = HasCar( var model = HasCar(
id: row[0].toString(), id: row[0].toString(),
type: CarType.values[(row[1] as int)], type: row[1] == null ? null : CarType.values[(row[1] as int)],
createdAt: (row[2] as DateTime), createdAt: (row[2] as DateTime),
updatedAt: (row[3] as DateTime)); updatedAt: (row[3] as DateTime));
return model; return model;
@ -116,7 +116,7 @@ class HasCarQueryValues extends MapQueryValues {
return CarType.values[(values['type'] as int)]; return CarType.values[(values['type'] as int)];
} }
set type(CarType value) => values['type'] = value.index; set type(CarType value) => values['type'] = value?.index;
DateTime get createdAt { DateTime get createdAt {
return (values['created_at'] as DateTime); return (values['created_at'] as DateTime);
} }

View file

@ -26,7 +26,7 @@ class LegMigration extends Migration {
class FootMigration extends Migration { class FootMigration extends Migration {
@override @override
up(Schema schema) { up(Schema schema) {
schema.create('foots', (table) { schema.create('feet', (table) {
table.serial('id')..primaryKey(); table.serial('id')..primaryKey();
table.integer('leg_id'); table.integer('leg_id');
table.declare('n_toes', ColumnType('decimal')); table.declare('n_toes', ColumnType('decimal'));
@ -37,7 +37,7 @@ class FootMigration extends Migration {
@override @override
down(Schema schema) { down(Schema schema) {
schema.drop('foots'); schema.drop('feet');
} }
} }
@ -50,7 +50,7 @@ class LegQuery extends Query<Leg, LegQueryWhere> {
trampoline ??= Set(); trampoline ??= Set();
trampoline.add(tableName); trampoline.add(tableName);
_where = LegQueryWhere(this); _where = LegQueryWhere(this);
leftJoin('foots', 'id', 'leg_id', leftJoin('feet', 'id', 'leg_id',
additionalFields: const [ additionalFields: const [
'id', 'id',
'leg_id', 'leg_id',
@ -184,7 +184,7 @@ class FootQuery extends Query<Foot, FootQueryWhere> {
@override @override
get tableName { get tableName {
return 'foots'; return 'feet';
} }
@override @override