Change updateFoo to update

This commit is contained in:
Tobe O 2018-08-24 10:13:00 -04:00
parent bf24371932
commit 19c9095700
8 changed files with 100 additions and 8 deletions

View file

@ -15,6 +15,12 @@ Builder ormBuilder(_) {
generatedExtension: '.orm.g.dart'); 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. /// Builder that generates `.orm.g.dart`, with an abstract `FooOrm` class.
class OrmGenerator extends GeneratorForAnnotation<ORM> { class OrmGenerator extends GeneratorForAnnotation<ORM> {
final bool autoSnakeCaseNames; final bool autoSnakeCaseNames;
@ -54,7 +60,44 @@ class OrmGenerator extends GeneratorForAnnotation<ORM> {
// Next, add method stubs. // Next, add method stubs.
// * getAll // * getAll
// * getById // * 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 // Create `FooQuery` class

View file

@ -7,4 +7,11 @@
import 'dart:async'; import 'dart:async';
import 'author.dart'; import 'author.dart';
abstract class AuthorOrm {} abstract class AuthorOrm {
Future<List<Author>> getAll();
Future<Author> getById(id);
Future<Author> updateAuthor(Author model);
AuthorQuery query();
}
class AuthorQuery {}

View file

@ -7,4 +7,11 @@
import 'dart:async'; import 'dart:async';
import 'car.dart'; import 'car.dart';
abstract class CarOrm {} abstract class CarOrm {
Future<List<Car>> getAll();
Future<Car> getById(id);
Future<Car> updateCar(Car model);
CarQuery query();
}
class CarQuery {}

View file

@ -7,4 +7,11 @@
import 'dart:async'; import 'dart:async';
import 'customer.dart'; import 'customer.dart';
abstract class CustomerOrm {} abstract class CustomerOrm {
Future<List<Customer>> getAll();
Future<Customer> getById(id);
Future<Customer> updateCustomer(Customer model);
CustomerQuery query();
}
class CustomerQuery {}

View file

@ -7,4 +7,11 @@
import 'dart:async'; import 'dart:async';
import 'foot.dart'; import 'foot.dart';
abstract class FootOrm {} abstract class FootOrm {
Future<List<Foot>> getAll();
Future<Foot> getById(id);
Future<Foot> updateFoot(Foot model);
FootQuery query();
}
class FootQuery {}

View file

@ -7,4 +7,11 @@
import 'dart:async'; import 'dart:async';
import 'fruit.dart'; import 'fruit.dart';
abstract class FruitOrm {} abstract class FruitOrm {
Future<List<Fruit>> getAll();
Future<Fruit> getById(id);
Future<Fruit> updateFruit(Fruit model);
FruitQuery query();
}
class FruitQuery {}

View file

@ -7,4 +7,11 @@
import 'dart:async'; import 'dart:async';
import 'order.dart'; import 'order.dart';
abstract class OrderOrm {} abstract class OrderOrm {
Future<List<Order>> getAll();
Future<Order> getById(id);
Future<Order> updateOrder(Order model);
OrderQuery query();
}
class OrderQuery {}

View file

@ -7,4 +7,11 @@
import 'dart:async'; import 'dart:async';
import 'role.dart'; import 'role.dart';
abstract class RoleOrm {} abstract class RoleOrm {
Future<List<Role>> getAll();
Future<Role> getById(id);
Future<Role> updateRole(Role model);
RoleQuery query();
}
class RoleQuery {}