diff --git a/angel_orm_generator/lib/src/orm_generator.dart b/angel_orm_generator/lib/src/orm_generator.dart index c8cf75f0..60e1649c 100644 --- a/angel_orm_generator/lib/src/orm_generator.dart +++ b/angel_orm_generator/lib/src/orm_generator.dart @@ -15,6 +15,12 @@ Builder ormBuilder(_) { generatedExtension: '.orm.g.dart'); } +TypeReference futureOf(String type) { + return new TypeReference((b) => b + ..symbol = 'Future' + ..types.add(refer(type))); +} + /// Builder that generates `.orm.g.dart`, with an abstract `FooOrm` class. class OrmGenerator extends GeneratorForAnnotation { final bool autoSnakeCaseNames; @@ -54,7 +60,44 @@ class OrmGenerator extends GeneratorForAnnotation { // Next, add method stubs. // * getAll // * getById - // * + // * update + // * query() + + // getAll + clazz.methods.add(new Method((m) { + m + ..name = 'getAll' + ..returns = new TypeReference((b) => b + ..symbol = 'Future' + ..types.add(new TypeReference((b) => b + ..symbol = 'List' + ..types.add(ctx.buildContext.modelClassType)))); + })); + + // getById + clazz.methods.add(new Method((m) { + m + ..name = 'getById' + ..returns = futureOf(ctx.buildContext.modelClassName) + ..requiredParameters.add(new Parameter((b) => b..name = 'id')); + })); + + // update + clazz.methods.add(new Method((m) { + m + ..name = 'update' + ..returns = futureOf(ctx.buildContext.modelClassName) + ..requiredParameters.add(new Parameter((b) => b + ..name = 'model' + ..type = ctx.buildContext.modelClassType)); + })); + + // query() + clazz.methods.add(new Method((m) { + m + ..name = 'query' + ..returns = refer('${rc.pascalCase}Query'); + })); })); // Create `FooQuery` class diff --git a/angel_orm_generator/test/models/author.orm.g.dart b/angel_orm_generator/test/models/author.orm.g.dart index 9345327a..7026215b 100644 --- a/angel_orm_generator/test/models/author.orm.g.dart +++ b/angel_orm_generator/test/models/author.orm.g.dart @@ -7,4 +7,11 @@ import 'dart:async'; import 'author.dart'; -abstract class AuthorOrm {} +abstract class AuthorOrm { + Future> getAll(); + Future getById(id); + Future updateAuthor(Author model); + AuthorQuery query(); +} + +class AuthorQuery {} diff --git a/angel_orm_generator/test/models/car.orm.g.dart b/angel_orm_generator/test/models/car.orm.g.dart index 1f92c31a..6572afad 100644 --- a/angel_orm_generator/test/models/car.orm.g.dart +++ b/angel_orm_generator/test/models/car.orm.g.dart @@ -7,4 +7,11 @@ import 'dart:async'; import 'car.dart'; -abstract class CarOrm {} +abstract class CarOrm { + Future> getAll(); + Future getById(id); + Future updateCar(Car model); + CarQuery query(); +} + +class CarQuery {} diff --git a/angel_orm_generator/test/models/customer.orm.g.dart b/angel_orm_generator/test/models/customer.orm.g.dart index bf95ffc8..4b5e5819 100644 --- a/angel_orm_generator/test/models/customer.orm.g.dart +++ b/angel_orm_generator/test/models/customer.orm.g.dart @@ -7,4 +7,11 @@ import 'dart:async'; import 'customer.dart'; -abstract class CustomerOrm {} +abstract class CustomerOrm { + Future> getAll(); + Future getById(id); + Future updateCustomer(Customer model); + CustomerQuery query(); +} + +class CustomerQuery {} diff --git a/angel_orm_generator/test/models/foot.orm.g.dart b/angel_orm_generator/test/models/foot.orm.g.dart index 7c457b7f..d9d932ae 100644 --- a/angel_orm_generator/test/models/foot.orm.g.dart +++ b/angel_orm_generator/test/models/foot.orm.g.dart @@ -7,4 +7,11 @@ import 'dart:async'; import 'foot.dart'; -abstract class FootOrm {} +abstract class FootOrm { + Future> getAll(); + Future getById(id); + Future updateFoot(Foot model); + FootQuery query(); +} + +class FootQuery {} diff --git a/angel_orm_generator/test/models/fruit.orm.g.dart b/angel_orm_generator/test/models/fruit.orm.g.dart index e943b687..fa06d029 100644 --- a/angel_orm_generator/test/models/fruit.orm.g.dart +++ b/angel_orm_generator/test/models/fruit.orm.g.dart @@ -7,4 +7,11 @@ import 'dart:async'; import 'fruit.dart'; -abstract class FruitOrm {} +abstract class FruitOrm { + Future> getAll(); + Future getById(id); + Future updateFruit(Fruit model); + FruitQuery query(); +} + +class FruitQuery {} diff --git a/angel_orm_generator/test/models/order.orm.g.dart b/angel_orm_generator/test/models/order.orm.g.dart index dcaa0afe..6624f3c7 100644 --- a/angel_orm_generator/test/models/order.orm.g.dart +++ b/angel_orm_generator/test/models/order.orm.g.dart @@ -7,4 +7,11 @@ import 'dart:async'; import 'order.dart'; -abstract class OrderOrm {} +abstract class OrderOrm { + Future> getAll(); + Future getById(id); + Future updateOrder(Order model); + OrderQuery query(); +} + +class OrderQuery {} diff --git a/angel_orm_generator/test/models/role.orm.g.dart b/angel_orm_generator/test/models/role.orm.g.dart index bf936571..4c6c9701 100644 --- a/angel_orm_generator/test/models/role.orm.g.dart +++ b/angel_orm_generator/test/models/role.orm.g.dart @@ -7,4 +7,11 @@ import 'dart:async'; import 'role.dart'; -abstract class RoleOrm {} +abstract class RoleOrm { + Future> getAll(); + Future getById(id); + Future updateRole(Role model); + RoleQuery query(); +} + +class RoleQuery {}