begin postgres
This commit is contained in:
parent
5971b94e44
commit
dd1e6e4d5c
8 changed files with 100 additions and 1 deletions
|
@ -68,7 +68,8 @@ class PostgreSqlOrmGenerator extends GeneratorForAnnotation<Orm> {
|
||||||
..name = 'connection'
|
..name = 'connection'
|
||||||
..toThis = true));
|
..toThis = true));
|
||||||
}))
|
}))
|
||||||
..methods.add(buildParseRowMethod(ctx));
|
..methods.add(buildParseRowMethod(ctx))
|
||||||
|
..methods.add(buildGetById(ctx));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,4 +98,46 @@ class PostgreSqlOrmGenerator extends GeneratorForAnnotation<Orm> {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Method buildGetById(OrmBuildContext ctx) {
|
||||||
|
/*
|
||||||
|
@override
|
||||||
|
Future<Author> getById(id) async {
|
||||||
|
var r = await connection.query('');
|
||||||
|
return parseRow(r.first);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
return new Method((m) {
|
||||||
|
m
|
||||||
|
..name = 'getById'
|
||||||
|
..annotations.add(refer('override'))
|
||||||
|
..modifier = MethodModifier.async
|
||||||
|
..returns = new TypeReference((b) => b
|
||||||
|
..symbol = 'Future'
|
||||||
|
..types.add(ctx.buildContext.modelClassType))
|
||||||
|
..body = new Block((b) {
|
||||||
|
var queryString = new StringBuffer('SELECT');
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
for (var field in ctx.buildContext.fields) {
|
||||||
|
if (i > 0) queryString.write(', ');
|
||||||
|
queryString.write(ctx.buildContext.resolveFieldName(field.name));
|
||||||
|
}
|
||||||
|
|
||||||
|
queryString.write(' FROM "${ctx.tableName}" id = @id;');
|
||||||
|
b.statements.add(refer('connection')
|
||||||
|
.property('query')
|
||||||
|
.call([
|
||||||
|
literalString(queryString.toString())
|
||||||
|
], {
|
||||||
|
'substitutionValues': literalMap({'id': refer('id')})
|
||||||
|
})
|
||||||
|
.awaited
|
||||||
|
.assignVar('r')
|
||||||
|
.statement);
|
||||||
|
b.addExpression(
|
||||||
|
refer('parseRow').call([refer('r').property('first')]));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,4 +18,12 @@ class _PostgreSqlAuthorOrmImpl implements AuthorOrm {
|
||||||
createdAt: (row[2] as DateTime),
|
createdAt: (row[2] as DateTime),
|
||||||
updatedAt: (row[3] as DateTime));
|
updatedAt: (row[3] as DateTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Author> getById(id) async {
|
||||||
|
var r = await connection.query(
|
||||||
|
'SELECTidnamecreated_atupdated_at FROM "authors" id = @id;',
|
||||||
|
substitutionValues: {'id': id});
|
||||||
|
parseRow(r.first);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,4 +21,12 @@ class _PostgreSqlCarOrmImpl implements CarOrm {
|
||||||
createdAt: (row[5] as DateTime),
|
createdAt: (row[5] as DateTime),
|
||||||
updatedAt: (row[6] as DateTime));
|
updatedAt: (row[6] as DateTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Car> getById() async {
|
||||||
|
var r = await connection.query(
|
||||||
|
'SELECTidmakedescriptionfamily_friendlyrecalled_atcreated_atupdated_at FROM "cars" id = @id;',
|
||||||
|
substitutionValues: {'id': id});
|
||||||
|
parseRow(r.first);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,4 +17,12 @@ class _PostgreSqlCustomerOrmImpl implements CustomerOrm {
|
||||||
createdAt: (row[1] as DateTime),
|
createdAt: (row[1] as DateTime),
|
||||||
updatedAt: (row[2] as DateTime));
|
updatedAt: (row[2] as DateTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Customer> getById() async {
|
||||||
|
var r = await connection.query(
|
||||||
|
'SELECTidcreated_atupdated_at FROM "customers" id = @id;',
|
||||||
|
substitutionValues: {'id': id});
|
||||||
|
parseRow(r.first);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,4 +19,12 @@ class _PostgreSqlFootOrmImpl implements FootOrm {
|
||||||
createdAt: (row[3] as DateTime),
|
createdAt: (row[3] as DateTime),
|
||||||
updatedAt: (row[4] as DateTime));
|
updatedAt: (row[4] as DateTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Foot> getById() async {
|
||||||
|
var r = await connection.query(
|
||||||
|
'SELECTidleg_idn_toescreated_atupdated_at FROM "foots" id = @id;',
|
||||||
|
substitutionValues: {'id': id});
|
||||||
|
parseRow(r.first);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,4 +19,12 @@ class _PostgreSqlFruitOrmImpl implements FruitOrm {
|
||||||
createdAt: (row[3] as DateTime),
|
createdAt: (row[3] as DateTime),
|
||||||
updatedAt: (row[4] as DateTime));
|
updatedAt: (row[4] as DateTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Fruit> getById() async {
|
||||||
|
var r = await connection.query(
|
||||||
|
'SELECTidtree_idcommon_namecreated_atupdated_at FROM "fruits" id = @id;',
|
||||||
|
substitutionValues: {'id': id});
|
||||||
|
parseRow(r.first);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,4 +21,12 @@ class _PostgreSqlOrderOrmImpl implements OrderOrm {
|
||||||
createdAt: (row[5] as DateTime),
|
createdAt: (row[5] as DateTime),
|
||||||
updatedAt: (row[6] as DateTime));
|
updatedAt: (row[6] as DateTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Order> getById() async {
|
||||||
|
var r = await connection.query(
|
||||||
|
'SELECTidcustomer_idemployee_idorder_dateshipper_idcreated_atupdated_at FROM "orders" id = @id;',
|
||||||
|
substitutionValues: {'id': id});
|
||||||
|
parseRow(r.first);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,4 +18,12 @@ class _PostgreSqlRoleOrmImpl implements RoleOrm {
|
||||||
createdAt: (row[2] as DateTime),
|
createdAt: (row[2] as DateTime),
|
||||||
updatedAt: (row[3] as DateTime));
|
updatedAt: (row[3] as DateTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Role> getById() async {
|
||||||
|
var r = await connection.query(
|
||||||
|
'SELECTidnamecreated_atupdated_at FROM "roles" id = @id;',
|
||||||
|
substitutionValues: {'id': id});
|
||||||
|
parseRow(r.first);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue