deletions
This commit is contained in:
parent
6073d0ec29
commit
4b374597eb
16 changed files with 108 additions and 0 deletions
|
@ -116,6 +116,7 @@ class OrmGenerator extends GeneratorForAnnotation<Orm> {
|
||||||
// Next, add method stubs.
|
// Next, add method stubs.
|
||||||
// * getAll
|
// * getAll
|
||||||
// * getById
|
// * getById
|
||||||
|
// * deleteById
|
||||||
// * updateX()
|
// * updateX()
|
||||||
// * createX()
|
// * createX()
|
||||||
// * query()
|
// * query()
|
||||||
|
@ -141,6 +142,16 @@ class OrmGenerator extends GeneratorForAnnotation<Orm> {
|
||||||
..type = refer('String')));
|
..type = refer('String')));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// deleteById
|
||||||
|
clazz.methods.add(new Method((m) {
|
||||||
|
m
|
||||||
|
..name = 'deleteById'
|
||||||
|
..returns = futureOf(ctx.buildContext.modelClassName)
|
||||||
|
..requiredParameters.add(new Parameter((b) => b
|
||||||
|
..name = 'id'
|
||||||
|
..type = refer('String')));
|
||||||
|
}));
|
||||||
|
|
||||||
// createX()
|
// createX()
|
||||||
clazz.methods.add(new Method((m) {
|
clazz.methods.add(new Method((m) {
|
||||||
m
|
m
|
||||||
|
|
|
@ -71,6 +71,7 @@ class PostgreSqlOrmGenerator extends GeneratorForAnnotation<Orm> {
|
||||||
}))
|
}))
|
||||||
..methods.add(buildParseRowMethod(ctx))
|
..methods.add(buildParseRowMethod(ctx))
|
||||||
..methods.add(buildGetById(ctx))
|
..methods.add(buildGetById(ctx))
|
||||||
|
..methods.add(buildDeleteById(ctx))
|
||||||
..methods.add(buildGetAll(ctx))
|
..methods.add(buildGetAll(ctx))
|
||||||
..methods.add(buildCreate(ctx))
|
..methods.add(buildCreate(ctx))
|
||||||
..methods.add(buildUpdate(ctx));
|
..methods.add(buildUpdate(ctx));
|
||||||
|
@ -213,6 +214,39 @@ class PostgreSqlOrmGenerator extends GeneratorForAnnotation<Orm> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Method buildDeleteById(OrmBuildContext ctx) {
|
||||||
|
/*
|
||||||
|
@override
|
||||||
|
Future<Author> getById(id) async {
|
||||||
|
var r = await connection.query('');
|
||||||
|
return parseRow(r.first);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
return new Method((m) {
|
||||||
|
m
|
||||||
|
..name = 'deleteById'
|
||||||
|
..annotations.add(refer('override'))
|
||||||
|
..modifier = MethodModifier.async
|
||||||
|
..requiredParameters.add(new Parameter((b) => b
|
||||||
|
..name = 'id'
|
||||||
|
..type = refer('String')))
|
||||||
|
..returns = new TypeReference((b) => b
|
||||||
|
..symbol = 'Future'
|
||||||
|
..types.add(ctx.buildContext.modelClassType))
|
||||||
|
..body = new Block((b) {
|
||||||
|
var fields = buildQuotedFieldString(ctx);
|
||||||
|
var queryString =
|
||||||
|
'DELETE FROM "${ctx.tableName}" WHERE id = @id RETURNING $fields;';
|
||||||
|
applyQueryAndReturnOne(
|
||||||
|
b,
|
||||||
|
queryString,
|
||||||
|
literalMap({
|
||||||
|
'id': refer('int').property('parse').call([refer('id')])
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Method buildGetAll(OrmBuildContext ctx) {
|
Method buildGetAll(OrmBuildContext ctx) {
|
||||||
/*
|
/*
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -15,6 +15,7 @@ abstract class AuthorOrm {
|
||||||
|
|
||||||
Future<List<Author>> getAll();
|
Future<List<Author>> getAll();
|
||||||
Future<Author> getById(String id);
|
Future<Author> getById(String id);
|
||||||
|
Future<Author> deleteById(String id);
|
||||||
Future<Author> createAuthor(Author model);
|
Future<Author> createAuthor(Author model);
|
||||||
Future<Author> updateAuthor(Author model);
|
Future<Author> updateAuthor(Author model);
|
||||||
AuthorQuery query();
|
AuthorQuery query();
|
||||||
|
|
|
@ -27,6 +27,14 @@ class _PostgreSqlAuthorOrmImpl implements AuthorOrm {
|
||||||
return parseRow(r.first);
|
return parseRow(r.first);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Author> deleteById(String id) async {
|
||||||
|
var r = await connection.query(
|
||||||
|
'DELETE FROM "authors" WHERE id = @id RETURNING "id", "name", "created_at", "updated_at";',
|
||||||
|
substitutionValues: {'id': int.parse(id)});
|
||||||
|
return parseRow(r.first);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<Author>> getAll() async {
|
Future<List<Author>> getAll() async {
|
||||||
var r = await connection
|
var r = await connection
|
||||||
|
|
|
@ -15,6 +15,7 @@ abstract class CarOrm {
|
||||||
|
|
||||||
Future<List<Car>> getAll();
|
Future<List<Car>> getAll();
|
||||||
Future<Car> getById(String id);
|
Future<Car> getById(String id);
|
||||||
|
Future<Car> deleteById(String id);
|
||||||
Future<Car> createCar(Car model);
|
Future<Car> createCar(Car model);
|
||||||
Future<Car> updateCar(Car model);
|
Future<Car> updateCar(Car model);
|
||||||
CarQuery query();
|
CarQuery query();
|
||||||
|
|
|
@ -30,6 +30,14 @@ class _PostgreSqlCarOrmImpl implements CarOrm {
|
||||||
return parseRow(r.first);
|
return parseRow(r.first);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Car> deleteById(String id) async {
|
||||||
|
var r = await connection.query(
|
||||||
|
'DELETE FROM "cars" WHERE id = @id RETURNING "id", "make", "description", "family_friendly", "recalled_at", "created_at", "updated_at";',
|
||||||
|
substitutionValues: {'id': int.parse(id)});
|
||||||
|
return parseRow(r.first);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<Car>> getAll() async {
|
Future<List<Car>> getAll() async {
|
||||||
var r = await connection.query(
|
var r = await connection.query(
|
||||||
|
|
|
@ -15,6 +15,7 @@ abstract class CustomerOrm {
|
||||||
|
|
||||||
Future<List<Customer>> getAll();
|
Future<List<Customer>> getAll();
|
||||||
Future<Customer> getById(String id);
|
Future<Customer> getById(String id);
|
||||||
|
Future<Customer> deleteById(String id);
|
||||||
Future<Customer> createCustomer(Customer model);
|
Future<Customer> createCustomer(Customer model);
|
||||||
Future<Customer> updateCustomer(Customer model);
|
Future<Customer> updateCustomer(Customer model);
|
||||||
CustomerQuery query();
|
CustomerQuery query();
|
||||||
|
|
|
@ -26,6 +26,14 @@ class _PostgreSqlCustomerOrmImpl implements CustomerOrm {
|
||||||
return parseRow(r.first);
|
return parseRow(r.first);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Customer> deleteById(String id) async {
|
||||||
|
var r = await connection.query(
|
||||||
|
'DELETE FROM "customers" WHERE id = @id RETURNING "id", "created_at", "updated_at";',
|
||||||
|
substitutionValues: {'id': int.parse(id)});
|
||||||
|
return parseRow(r.first);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<Customer>> getAll() async {
|
Future<List<Customer>> getAll() async {
|
||||||
var r = await connection
|
var r = await connection
|
||||||
|
|
|
@ -15,6 +15,7 @@ abstract class FootOrm {
|
||||||
|
|
||||||
Future<List<Foot>> getAll();
|
Future<List<Foot>> getAll();
|
||||||
Future<Foot> getById(String id);
|
Future<Foot> getById(String id);
|
||||||
|
Future<Foot> deleteById(String id);
|
||||||
Future<Foot> createFoot(Foot model);
|
Future<Foot> createFoot(Foot model);
|
||||||
Future<Foot> updateFoot(Foot model);
|
Future<Foot> updateFoot(Foot model);
|
||||||
FootQuery query();
|
FootQuery query();
|
||||||
|
|
|
@ -28,6 +28,14 @@ class _PostgreSqlFootOrmImpl implements FootOrm {
|
||||||
return parseRow(r.first);
|
return parseRow(r.first);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Foot> deleteById(String id) async {
|
||||||
|
var r = await connection.query(
|
||||||
|
'DELETE FROM "foots" WHERE id = @id RETURNING "id", "leg_id", "n_toes", "created_at", "updated_at";',
|
||||||
|
substitutionValues: {'id': int.parse(id)});
|
||||||
|
return parseRow(r.first);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<Foot>> getAll() async {
|
Future<List<Foot>> getAll() async {
|
||||||
var r = await connection.query(
|
var r = await connection.query(
|
||||||
|
|
|
@ -15,6 +15,7 @@ abstract class FruitOrm {
|
||||||
|
|
||||||
Future<List<Fruit>> getAll();
|
Future<List<Fruit>> getAll();
|
||||||
Future<Fruit> getById(String id);
|
Future<Fruit> getById(String id);
|
||||||
|
Future<Fruit> deleteById(String id);
|
||||||
Future<Fruit> createFruit(Fruit model);
|
Future<Fruit> createFruit(Fruit model);
|
||||||
Future<Fruit> updateFruit(Fruit model);
|
Future<Fruit> updateFruit(Fruit model);
|
||||||
FruitQuery query();
|
FruitQuery query();
|
||||||
|
|
|
@ -28,6 +28,14 @@ class _PostgreSqlFruitOrmImpl implements FruitOrm {
|
||||||
return parseRow(r.first);
|
return parseRow(r.first);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Fruit> deleteById(String id) async {
|
||||||
|
var r = await connection.query(
|
||||||
|
'DELETE FROM "fruits" WHERE id = @id RETURNING "id", "tree_id", "common_name", "created_at", "updated_at";',
|
||||||
|
substitutionValues: {'id': int.parse(id)});
|
||||||
|
return parseRow(r.first);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<Fruit>> getAll() async {
|
Future<List<Fruit>> getAll() async {
|
||||||
var r = await connection.query(
|
var r = await connection.query(
|
||||||
|
|
|
@ -15,6 +15,7 @@ abstract class OrderOrm {
|
||||||
|
|
||||||
Future<List<Order>> getAll();
|
Future<List<Order>> getAll();
|
||||||
Future<Order> getById(String id);
|
Future<Order> getById(String id);
|
||||||
|
Future<Order> deleteById(String id);
|
||||||
Future<Order> createOrder(Order model);
|
Future<Order> createOrder(Order model);
|
||||||
Future<Order> updateOrder(Order model);
|
Future<Order> updateOrder(Order model);
|
||||||
OrderQuery query();
|
OrderQuery query();
|
||||||
|
|
|
@ -30,6 +30,14 @@ class _PostgreSqlOrderOrmImpl implements OrderOrm {
|
||||||
return parseRow(r.first);
|
return parseRow(r.first);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Order> deleteById(String id) async {
|
||||||
|
var r = await connection.query(
|
||||||
|
'DELETE FROM "orders" WHERE id = @id RETURNING "id", "customer_id", "employee_id", "order_date", "shipper_id", "created_at", "updated_at";',
|
||||||
|
substitutionValues: {'id': int.parse(id)});
|
||||||
|
return parseRow(r.first);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<Order>> getAll() async {
|
Future<List<Order>> getAll() async {
|
||||||
var r = await connection.query(
|
var r = await connection.query(
|
||||||
|
|
|
@ -15,6 +15,7 @@ abstract class RoleOrm {
|
||||||
|
|
||||||
Future<List<Role>> getAll();
|
Future<List<Role>> getAll();
|
||||||
Future<Role> getById(String id);
|
Future<Role> getById(String id);
|
||||||
|
Future<Role> deleteById(String id);
|
||||||
Future<Role> createRole(Role model);
|
Future<Role> createRole(Role model);
|
||||||
Future<Role> updateRole(Role model);
|
Future<Role> updateRole(Role model);
|
||||||
RoleQuery query();
|
RoleQuery query();
|
||||||
|
|
|
@ -27,6 +27,14 @@ class _PostgreSqlRoleOrmImpl implements RoleOrm {
|
||||||
return parseRow(r.first);
|
return parseRow(r.first);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Role> deleteById(String id) async {
|
||||||
|
var r = await connection.query(
|
||||||
|
'DELETE FROM "roles" WHERE id = @id RETURNING "id", "name", "created_at", "updated_at";',
|
||||||
|
substitutionValues: {'id': int.parse(id)});
|
||||||
|
return parseRow(r.first);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<Role>> getAll() async {
|
Future<List<Role>> getAll() async {
|
||||||
var r = await connection
|
var r = await connection
|
||||||
|
|
Loading…
Reference in a new issue