diff --git a/angel_orm_generator/build.yaml b/angel_orm_generator/build.yaml index bede8b25..18ab94b4 100644 --- a/angel_orm_generator/build.yaml +++ b/angel_orm_generator/build.yaml @@ -3,7 +3,7 @@ builders: import: "package:angel_orm_generator/angel_orm_generator.dart" builder_factories: - ormBuilder - - mongoDBOrmBuilder + #- mongoDBOrmBuilder - postgreSqlOrmBuilder auto_apply: root_package build_to: source diff --git a/angel_orm_generator/lib/angel_orm_generator.dart b/angel_orm_generator/lib/angel_orm_generator.dart index ae114848..f00f5914 100644 --- a/angel_orm_generator/lib/angel_orm_generator.dart +++ b/angel_orm_generator/lib/angel_orm_generator.dart @@ -1,4 +1,4 @@ -export 'src/mongodb_orm_generator.dart'; +//export 'src/mongodb_orm_generator.dart'; export 'src/orm_build_context.dart'; export 'src/orm_generator.dart'; export 'src/postgresql_orm_generator.dart'; diff --git a/angel_orm_generator/lib/src/orm_generator.dart b/angel_orm_generator/lib/src/orm_generator.dart index 5c20ecb8..a0ba59ba 100644 --- a/angel_orm_generator/lib/src/orm_generator.dart +++ b/angel_orm_generator/lib/src/orm_generator.dart @@ -48,9 +48,9 @@ class OrmGenerator extends GeneratorForAnnotation { ['dart:async', p.basename(inputId.uri.path)]); switch (ctx.ormAnnotation.type) { - case OrmType.mongoDB: - imports.add('package:mongo_dart/mongo_dart.dart'); - break; +// case OrmType.mongoDB: +// imports.add('package:mongo_dart/mongo_dart.dart'); +// break; case OrmType.postgreSql: imports.add('package:postgres/postgres.dart'); break; @@ -64,9 +64,9 @@ class OrmGenerator extends GeneratorForAnnotation { String dbExtension; switch (ctx.ormAnnotation.type) { - case OrmType.mongoDB: - dbExtension = 'mongodb'; - break; +// case OrmType.mongoDB: +// dbExtension = 'mongodb'; +// break; case OrmType.rethinkDB: dbExtension = 'rethinkdb'; break; diff --git a/angel_orm_generator/lib/src/postgresql_orm_generator.dart b/angel_orm_generator/lib/src/postgresql_orm_generator.dart index 7bdedf4f..7004f946 100644 --- a/angel_orm_generator/lib/src/postgresql_orm_generator.dart +++ b/angel_orm_generator/lib/src/postgresql_orm_generator.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'package:analyzer/dart/element/element.dart'; import 'package:angel_orm/angel_orm.dart'; +import 'package:angel_serialize_generator/angel_serialize_generator.dart'; import 'package:build/build.dart'; import 'package:code_builder/code_builder.dart' hide LibraryBuilder; import 'package:path/path.dart' as p; @@ -66,7 +67,34 @@ class PostgreSqlOrmGenerator extends GeneratorForAnnotation { ..requiredParameters.add(new Parameter((b) => b ..name = 'connection' ..toThis = true)); - })); + })) + ..methods.add(buildParseRowMethod(ctx)); + }); + } + + Method buildParseRowMethod(OrmBuildContext ctx) { + return new Method((m) { + m + ..name = 'parseRow' + ..static = true + ..returns = ctx.buildContext.modelClassType + ..requiredParameters.add(new Parameter((b) => b + ..name = 'row' + ..type = refer('List'))) + ..body = new Block((b) { + var args = {}; + + for (int i = 0; i < ctx.buildContext.fields.length; i++) { + var field = ctx.buildContext.fields[i]; + args[field.name] = refer('row') + .index(literalNum(i)) + .asA(convertTypeReference(field.type)); + } + + var returnValue = + ctx.buildContext.modelClassType.newInstance([], args); + b.addExpression(returnValue.returned); + }); }); } } diff --git a/angel_orm_generator/test/models/author.mongodb.orm.g.dart b/angel_orm_generator/test/models/author.mongodb.orm.g.dart deleted file mode 100644 index 40a03a91..00000000 --- a/angel_orm_generator/test/models/author.mongodb.orm.g.dart +++ /dev/null @@ -1,7 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// MongoDBOrmGenerator -// ************************************************************************** - -part of 'author.orm.g.dart'; diff --git a/angel_orm_generator/test/models/author.postgresql.orm.g.dart b/angel_orm_generator/test/models/author.postgresql.orm.g.dart index 2e2cf53d..9c6ae65d 100644 --- a/angel_orm_generator/test/models/author.postgresql.orm.g.dart +++ b/angel_orm_generator/test/models/author.postgresql.orm.g.dart @@ -10,4 +10,12 @@ class _PostgreSqlAuthorOrmImpl implements AuthorOrm { _PostgreSqlAuthorOrmImpl(this.connection); final PostgreSQLConnection connection; + + static Author parseRow(List row) { + return new Author( + id: (row[0] as String), + name: (row[1] as String), + createdAt: (row[2] as DateTime), + updatedAt: (row[3] as DateTime)); + } } diff --git a/angel_orm_generator/test/models/book.mongodb.orm.g.dart b/angel_orm_generator/test/models/book.mongodb.orm.g.dart deleted file mode 100644 index 14e7cc37..00000000 --- a/angel_orm_generator/test/models/book.mongodb.orm.g.dart +++ /dev/null @@ -1,7 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// MongoDBOrmGenerator -// ************************************************************************** - -// Error: Cannot infer SQL column type for field "author" with type "Author". diff --git a/angel_orm_generator/test/models/car.mongodb.orm.g.dart b/angel_orm_generator/test/models/car.mongodb.orm.g.dart deleted file mode 100644 index 416298da..00000000 --- a/angel_orm_generator/test/models/car.mongodb.orm.g.dart +++ /dev/null @@ -1,7 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// MongoDBOrmGenerator -// ************************************************************************** - -part of 'car.orm.g.dart'; diff --git a/angel_orm_generator/test/models/car.postgresql.orm.g.dart b/angel_orm_generator/test/models/car.postgresql.orm.g.dart index dbfcba26..2df1892e 100644 --- a/angel_orm_generator/test/models/car.postgresql.orm.g.dart +++ b/angel_orm_generator/test/models/car.postgresql.orm.g.dart @@ -10,4 +10,15 @@ class _PostgreSqlCarOrmImpl implements CarOrm { _PostgreSqlCarOrmImpl(this.connection); final PostgreSQLConnection connection; + + static Car parseRow(List row) { + return new Car( + id: (row[0] as String), + make: (row[1] as String), + description: (row[2] as String), + familyFriendly: (row[3] as bool), + recalledAt: (row[4] as DateTime), + createdAt: (row[5] as DateTime), + updatedAt: (row[6] as DateTime)); + } } diff --git a/angel_orm_generator/test/models/customer.mongodb.orm.g.dart b/angel_orm_generator/test/models/customer.mongodb.orm.g.dart deleted file mode 100644 index 5e87e1a9..00000000 --- a/angel_orm_generator/test/models/customer.mongodb.orm.g.dart +++ /dev/null @@ -1,7 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// MongoDBOrmGenerator -// ************************************************************************** - -part of 'customer.orm.g.dart'; diff --git a/angel_orm_generator/test/models/customer.postgresql.orm.g.dart b/angel_orm_generator/test/models/customer.postgresql.orm.g.dart index eebc7d63..7e942c4e 100644 --- a/angel_orm_generator/test/models/customer.postgresql.orm.g.dart +++ b/angel_orm_generator/test/models/customer.postgresql.orm.g.dart @@ -10,4 +10,11 @@ class _PostgreSqlCustomerOrmImpl implements CustomerOrm { _PostgreSqlCustomerOrmImpl(this.connection); final PostgreSQLConnection connection; + + static Customer parseRow(List row) { + return new Customer( + id: (row[0] as String), + createdAt: (row[1] as DateTime), + updatedAt: (row[2] as DateTime)); + } } diff --git a/angel_orm_generator/test/models/foot.mongodb.orm.g.dart b/angel_orm_generator/test/models/foot.mongodb.orm.g.dart deleted file mode 100644 index c3cdb85a..00000000 --- a/angel_orm_generator/test/models/foot.mongodb.orm.g.dart +++ /dev/null @@ -1,7 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// MongoDBOrmGenerator -// ************************************************************************** - -part of 'foot.orm.g.dart'; diff --git a/angel_orm_generator/test/models/foot.postgresql.orm.g.dart b/angel_orm_generator/test/models/foot.postgresql.orm.g.dart index 34518882..a066378f 100644 --- a/angel_orm_generator/test/models/foot.postgresql.orm.g.dart +++ b/angel_orm_generator/test/models/foot.postgresql.orm.g.dart @@ -10,4 +10,13 @@ class _PostgreSqlFootOrmImpl implements FootOrm { _PostgreSqlFootOrmImpl(this.connection); final PostgreSQLConnection connection; + + static Foot parseRow(List row) { + return new Foot( + id: (row[0] as String), + legId: (row[1] as int), + nToes: (row[2] as int), + createdAt: (row[3] as DateTime), + updatedAt: (row[4] as DateTime)); + } } diff --git a/angel_orm_generator/test/models/fruit.mongodb.orm.g.dart b/angel_orm_generator/test/models/fruit.mongodb.orm.g.dart deleted file mode 100644 index 6958cc16..00000000 --- a/angel_orm_generator/test/models/fruit.mongodb.orm.g.dart +++ /dev/null @@ -1,7 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// MongoDBOrmGenerator -// ************************************************************************** - -part of 'fruit.orm.g.dart'; diff --git a/angel_orm_generator/test/models/fruit.postgresql.orm.g.dart b/angel_orm_generator/test/models/fruit.postgresql.orm.g.dart index 3448a9f7..5caafe91 100644 --- a/angel_orm_generator/test/models/fruit.postgresql.orm.g.dart +++ b/angel_orm_generator/test/models/fruit.postgresql.orm.g.dart @@ -10,4 +10,13 @@ class _PostgreSqlFruitOrmImpl implements FruitOrm { _PostgreSqlFruitOrmImpl(this.connection); final PostgreSQLConnection connection; + + static Fruit parseRow(List row) { + return new Fruit( + id: (row[0] as String), + treeId: (row[1] as int), + commonName: (row[2] as String), + createdAt: (row[3] as DateTime), + updatedAt: (row[4] as DateTime)); + } } diff --git a/angel_orm_generator/test/models/leg.mongodb.orm.g.dart b/angel_orm_generator/test/models/leg.mongodb.orm.g.dart deleted file mode 100644 index e5122312..00000000 --- a/angel_orm_generator/test/models/leg.mongodb.orm.g.dart +++ /dev/null @@ -1,7 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// MongoDBOrmGenerator -// ************************************************************************** - -// Error: Cannot infer SQL column type for field "foot" with type "Foot". diff --git a/angel_orm_generator/test/models/order.mongodb.orm.g.dart b/angel_orm_generator/test/models/order.mongodb.orm.g.dart deleted file mode 100644 index 9103d177..00000000 --- a/angel_orm_generator/test/models/order.mongodb.orm.g.dart +++ /dev/null @@ -1,7 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// MongoDBOrmGenerator -// ************************************************************************** - -part of 'order.orm.g.dart'; diff --git a/angel_orm_generator/test/models/order.postgresql.orm.g.dart b/angel_orm_generator/test/models/order.postgresql.orm.g.dart index d1e03bdd..cb08e80b 100644 --- a/angel_orm_generator/test/models/order.postgresql.orm.g.dart +++ b/angel_orm_generator/test/models/order.postgresql.orm.g.dart @@ -10,4 +10,15 @@ class _PostgreSqlOrderOrmImpl implements OrderOrm { _PostgreSqlOrderOrmImpl(this.connection); final PostgreSQLConnection connection; + + static Order parseRow(List row) { + return new Order( + id: (row[0] as String), + customerId: (row[1] as int), + employeeId: (row[2] as int), + orderDate: (row[3] as DateTime), + shipperId: (row[4] as int), + createdAt: (row[5] as DateTime), + updatedAt: (row[6] as DateTime)); + } } diff --git a/angel_orm_generator/test/models/role.mongodb.orm.g.dart b/angel_orm_generator/test/models/role.mongodb.orm.g.dart deleted file mode 100644 index 8dcf6298..00000000 --- a/angel_orm_generator/test/models/role.mongodb.orm.g.dart +++ /dev/null @@ -1,7 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// MongoDBOrmGenerator -// ************************************************************************** - -part of 'role.orm.g.dart'; diff --git a/angel_orm_generator/test/models/role.postgresql.orm.g.dart b/angel_orm_generator/test/models/role.postgresql.orm.g.dart index f8a8bcef..2b3aaddc 100644 --- a/angel_orm_generator/test/models/role.postgresql.orm.g.dart +++ b/angel_orm_generator/test/models/role.postgresql.orm.g.dart @@ -10,4 +10,12 @@ class _PostgreSqlRoleOrmImpl implements RoleOrm { _PostgreSqlRoleOrmImpl(this.connection); final PostgreSQLConnection connection; + + static Role parseRow(List row) { + return new Role( + id: (row[0] as String), + name: (row[1] as String), + createdAt: (row[2] as DateTime), + updatedAt: (row[3] as DateTime)); + } } diff --git a/angel_orm_generator/test/models/tree.mongodb.orm.g.dart b/angel_orm_generator/test/models/tree.mongodb.orm.g.dart deleted file mode 100644 index bfcfb0bd..00000000 --- a/angel_orm_generator/test/models/tree.mongodb.orm.g.dart +++ /dev/null @@ -1,7 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// MongoDBOrmGenerator -// ************************************************************************** - -// Error: Cannot infer SQL column type for field "fruits" with type "List". diff --git a/angel_orm_generator/test/models/user.mongodb.orm.g.dart b/angel_orm_generator/test/models/user.mongodb.orm.g.dart deleted file mode 100644 index 8d7bc6d9..00000000 --- a/angel_orm_generator/test/models/user.mongodb.orm.g.dart +++ /dev/null @@ -1,7 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// MongoDBOrmGenerator -// ************************************************************************** - -// Error: Cannot infer SQL column type for field "roles" with type "List".