From 576fdc6d8a56ee64eac2c6fe90eda17cca50cc53 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Tue, 28 Aug 2018 11:18:08 -0400 Subject: [PATCH] Add facory constructor for postgres --- .../lib/src/orm_generator.dart | 22 ++++++++++++++++++- .../lib/src/postgresql_orm_generator.dart | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/angel_orm_generator/lib/src/orm_generator.dart b/angel_orm_generator/lib/src/orm_generator.dart index b4649fb1..5c20ecb8 100644 --- a/angel_orm_generator/lib/src/orm_generator.dart +++ b/angel_orm_generator/lib/src/orm_generator.dart @@ -86,13 +86,33 @@ class OrmGenerator extends GeneratorForAnnotation { lib.body.add(new Code("part '$dbFile';")); // Create `FooOrm` abstract class - var rc = new ReCase(ctx.buildContext.modelClassName); + var rc = ctx.buildContext.modelClassNameRecase; lib.body.add(new Class((clazz) { clazz ..name = '${rc.pascalCase}Orm' ..abstract = true; + // Add factory constructors. + switch (ctx.ormAnnotation.type) { + case OrmType.postgreSql: + clazz.constructors.add(new Constructor((b) { + b + ..name = 'postgreSql' + ..factory = true + ..redirect = refer('_PostgreSql${rc.pascalCase}OrmImpl') + ..requiredParameters.add(new Parameter((b) { + b + ..name = 'connection' + ..type = refer('PostgreSQLConnection'); + })); + })); + dbExtension = 'postgresql'; + break; + default: + break; + } + // Next, add method stubs. // * getAll // * getById diff --git a/angel_orm_generator/lib/src/postgresql_orm_generator.dart b/angel_orm_generator/lib/src/postgresql_orm_generator.dart index 5c075aaa..7bdedf4f 100644 --- a/angel_orm_generator/lib/src/postgresql_orm_generator.dart +++ b/angel_orm_generator/lib/src/postgresql_orm_generator.dart @@ -49,7 +49,7 @@ class PostgreSqlOrmGenerator extends GeneratorForAnnotation { return new Class((clazz) { var rc = ctx.buildContext.modelClassNameRecase; clazz - ..name = '_Postgresql${rc.pascalCase}OrmImpl' + ..name = '_PostgreSql${rc.pascalCase}OrmImpl' ..implements.add(refer('${rc.pascalCase}Orm')) // final PostgreSQLConnection connection;