From 3d05f182325cb5779e931c6689dbf1a20db2bc52 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Fri, 24 Aug 2018 10:40:41 -0400 Subject: [PATCH] Gen "part x.mongo.dart" --- angel_orm_generator/lib/src/orm_generator.dart | 16 ++++++++++++++++ angel_orm_generator/lib/src/readers.dart | 5 ++++- angel_orm_generator/test/models/author.dart | 2 +- angel_orm_generator/test/models/book.dart | 2 +- angel_orm_generator/test/models/car.dart | 2 +- angel_orm_generator/test/models/car.orm.g.dart | 4 ++++ angel_orm_generator/test/models/customer.dart | 2 +- angel_orm_generator/test/models/foot.dart | 2 +- angel_orm_generator/test/models/fruit.dart | 2 +- angel_orm_generator/test/models/leg.dart | 2 +- angel_orm_generator/test/models/order.dart | 2 +- angel_orm_generator/test/models/role.dart | 2 +- angel_orm_generator/test/models/tree.dart | 2 +- angel_orm_generator/test/models/user.dart | 2 +- 14 files changed, 35 insertions(+), 12 deletions(-) diff --git a/angel_orm_generator/lib/src/orm_generator.dart b/angel_orm_generator/lib/src/orm_generator.dart index a30d3fb8..48e45d7a 100644 --- a/angel_orm_generator/lib/src/orm_generator.dart +++ b/angel_orm_generator/lib/src/orm_generator.dart @@ -49,6 +49,22 @@ class OrmGenerator extends GeneratorForAnnotation { new Directive.import(p.basename(inputId.uri.path)), ]); + // Add the corresponding `part` + String dbExtension; + + switch (ctx.ormAnnotation.type) { + case OrmType.mongoDB: + dbExtension = 'mongo'; + break; + default: + throw 'Unsupported ORM type: ${ctx.ormAnnotation.type}'; + } + + var dbFile = + p.setExtension(p.basename(inputId.uri.path), '.$dbExtension.dart'); + + lib.body.add(new Code("part '$dbFile';")); + // Create `FooOrm` abstract class var rc = new ReCase(ctx.buildContext.modelClassName); diff --git a/angel_orm_generator/lib/src/readers.dart b/angel_orm_generator/lib/src/readers.dart index 687249e0..555763c3 100644 --- a/angel_orm_generator/lib/src/readers.dart +++ b/angel_orm_generator/lib/src/readers.dart @@ -5,7 +5,10 @@ import 'package:source_gen/source_gen.dart'; const TypeChecker columnTypeChecker = const TypeChecker.fromRuntime(Column); Orm reviveORMAnnotation(ConstantReader reader) { - return Orm(reader.peek('tableName')?.stringValue); + return Orm( + OrmType.values[reader.read('type').intValue], + tableName: reader.peek('tableName')?.stringValue, + ); } class ColumnReader { diff --git a/angel_orm_generator/test/models/author.dart b/angel_orm_generator/test/models/author.dart index ed045366..bb103d0c 100644 --- a/angel_orm_generator/test/models/author.dart +++ b/angel_orm_generator/test/models/author.dart @@ -9,7 +9,7 @@ part 'author.g.dart'; part 'author.serializer.g.dart'; @serializable -@orm +@postgreSqlOrm class _Author extends Model { @Column(length: 255, indexType: IndexType.unique, defaultValue: 'Tobe Osakwe') String name; diff --git a/angel_orm_generator/test/models/book.dart b/angel_orm_generator/test/models/book.dart index fa675b3c..4180471a 100644 --- a/angel_orm_generator/test/models/book.dart +++ b/angel_orm_generator/test/models/book.dart @@ -8,7 +8,7 @@ part 'book.g.dart'; part 'book.serializer.g.dart'; @serializable -@orm +@postgreSqlOrm class _Book extends Model { @belongsTo Author author; diff --git a/angel_orm_generator/test/models/car.dart b/angel_orm_generator/test/models/car.dart index 3cf1a7b8..714be540 100644 --- a/angel_orm_generator/test/models/car.dart +++ b/angel_orm_generator/test/models/car.dart @@ -7,7 +7,7 @@ part 'car.g.dart'; part 'car.serializer.g.dart'; @serializable -@orm +@postgreSqlOrm class _Car extends Model { String make; String description; diff --git a/angel_orm_generator/test/models/car.orm.g.dart b/angel_orm_generator/test/models/car.orm.g.dart index 10eeed7c..c06f47ae 100644 --- a/angel_orm_generator/test/models/car.orm.g.dart +++ b/angel_orm_generator/test/models/car.orm.g.dart @@ -5,12 +5,16 @@ // ************************************************************************** import 'dart:async'; + import 'car.dart'; abstract class CarOrm { Future> getAll(); + Future getById(id); + Future update(Car model); + CarQuery query(); } diff --git a/angel_orm_generator/test/models/customer.dart b/angel_orm_generator/test/models/customer.dart index 0808bdfa..1c25c441 100644 --- a/angel_orm_generator/test/models/customer.dart +++ b/angel_orm_generator/test/models/customer.dart @@ -6,7 +6,7 @@ import 'package:angel_serialize/angel_serialize.dart'; part 'customer.g.dart'; part 'customer.serializer.g.dart'; -@orm +@postgreSqlOrm @serializable class _Customer extends Model { } \ No newline at end of file diff --git a/angel_orm_generator/test/models/foot.dart b/angel_orm_generator/test/models/foot.dart index 39c57947..6199a134 100644 --- a/angel_orm_generator/test/models/foot.dart +++ b/angel_orm_generator/test/models/foot.dart @@ -7,7 +7,7 @@ part 'foot.g.dart'; part 'foot.serializer.g.dart'; @serializable -@orm +@postgreSqlOrm class _Foot extends Model { int legId, nToes; } \ No newline at end of file diff --git a/angel_orm_generator/test/models/fruit.dart b/angel_orm_generator/test/models/fruit.dart index 3af538ed..f9d812ac 100644 --- a/angel_orm_generator/test/models/fruit.dart +++ b/angel_orm_generator/test/models/fruit.dart @@ -7,7 +7,7 @@ part 'fruit.g.dart'; part 'fruit.serializer.g.dart'; @serializable -@orm +@postgreSqlOrm class _Fruit extends Model { int treeId; String commonName; diff --git a/angel_orm_generator/test/models/leg.dart b/angel_orm_generator/test/models/leg.dart index 365fa357..f20e8815 100644 --- a/angel_orm_generator/test/models/leg.dart +++ b/angel_orm_generator/test/models/leg.dart @@ -8,7 +8,7 @@ part 'leg.g.dart'; part 'leg.serializer.g.dart'; @serializable -@orm +@postgreSqlOrm class _Leg extends Model { @hasOne Foot foot; diff --git a/angel_orm_generator/test/models/order.dart b/angel_orm_generator/test/models/order.dart index 7b529062..76600c2b 100644 --- a/angel_orm_generator/test/models/order.dart +++ b/angel_orm_generator/test/models/order.dart @@ -7,7 +7,7 @@ import 'customer.dart'; part 'order.g.dart'; part 'order.serializer.g.dart'; -@orm +@postgreSqlOrm @serializable class _Order extends Model { @CanJoin(Customer, 'id') diff --git a/angel_orm_generator/test/models/role.dart b/angel_orm_generator/test/models/role.dart index ae27ec7a..dcef4bc4 100644 --- a/angel_orm_generator/test/models/role.dart +++ b/angel_orm_generator/test/models/role.dart @@ -7,7 +7,7 @@ part 'role.g.dart'; part 'role.serializer.g.dart'; @serializable -@orm +@postgreSqlOrm class _Role extends Model { String name; } \ No newline at end of file diff --git a/angel_orm_generator/test/models/tree.dart b/angel_orm_generator/test/models/tree.dart index ceb93600..be77b171 100644 --- a/angel_orm_generator/test/models/tree.dart +++ b/angel_orm_generator/test/models/tree.dart @@ -8,7 +8,7 @@ part 'tree.g.dart'; part 'tree.serializer.g.dart'; @serializable -@orm +@postgreSqlOrm class _Tree extends Model { @Column(indexType: IndexType.unique, type: ColumnType.smallInt) int rings; diff --git a/angel_orm_generator/test/models/user.dart b/angel_orm_generator/test/models/user.dart index 7588cf62..33ba9beb 100644 --- a/angel_orm_generator/test/models/user.dart +++ b/angel_orm_generator/test/models/user.dart @@ -8,7 +8,7 @@ part 'user.g.dart'; part 'user.serializer.g.dart'; @serializable -@orm +@postgreSqlOrm class _User extends Model { String username, password, email;