Add parseRow to postgres
This commit is contained in:
parent
4fad5a2c97
commit
5971b94e44
22 changed files with 100 additions and 86 deletions
|
@ -3,7 +3,7 @@ builders:
|
|||
import: "package:angel_orm_generator/angel_orm_generator.dart"
|
||||
builder_factories:
|
||||
- ormBuilder
|
||||
- mongoDBOrmBuilder
|
||||
#- mongoDBOrmBuilder
|
||||
- postgreSqlOrmBuilder
|
||||
auto_apply: root_package
|
||||
build_to: source
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
export 'src/mongodb_orm_generator.dart';
|
||||
//export 'src/mongodb_orm_generator.dart';
|
||||
export 'src/orm_build_context.dart';
|
||||
export 'src/orm_generator.dart';
|
||||
export 'src/postgresql_orm_generator.dart';
|
||||
|
|
|
@ -48,9 +48,9 @@ class OrmGenerator extends GeneratorForAnnotation<Orm> {
|
|||
['dart:async', p.basename(inputId.uri.path)]);
|
||||
|
||||
switch (ctx.ormAnnotation.type) {
|
||||
case OrmType.mongoDB:
|
||||
imports.add('package:mongo_dart/mongo_dart.dart');
|
||||
break;
|
||||
// case OrmType.mongoDB:
|
||||
// imports.add('package:mongo_dart/mongo_dart.dart');
|
||||
// break;
|
||||
case OrmType.postgreSql:
|
||||
imports.add('package:postgres/postgres.dart');
|
||||
break;
|
||||
|
@ -64,9 +64,9 @@ class OrmGenerator extends GeneratorForAnnotation<Orm> {
|
|||
String dbExtension;
|
||||
|
||||
switch (ctx.ormAnnotation.type) {
|
||||
case OrmType.mongoDB:
|
||||
dbExtension = 'mongodb';
|
||||
break;
|
||||
// case OrmType.mongoDB:
|
||||
// dbExtension = 'mongodb';
|
||||
// break;
|
||||
case OrmType.rethinkDB:
|
||||
dbExtension = 'rethinkdb';
|
||||
break;
|
||||
|
|
|
@ -2,6 +2,7 @@ import 'dart:async';
|
|||
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:angel_orm/angel_orm.dart';
|
||||
import 'package:angel_serialize_generator/angel_serialize_generator.dart';
|
||||
import 'package:build/build.dart';
|
||||
import 'package:code_builder/code_builder.dart' hide LibraryBuilder;
|
||||
import 'package:path/path.dart' as p;
|
||||
|
@ -66,7 +67,34 @@ class PostgreSqlOrmGenerator extends GeneratorForAnnotation<Orm> {
|
|||
..requiredParameters.add(new Parameter((b) => b
|
||||
..name = 'connection'
|
||||
..toThis = true));
|
||||
}));
|
||||
}))
|
||||
..methods.add(buildParseRowMethod(ctx));
|
||||
});
|
||||
}
|
||||
|
||||
Method buildParseRowMethod(OrmBuildContext ctx) {
|
||||
return new Method((m) {
|
||||
m
|
||||
..name = 'parseRow'
|
||||
..static = true
|
||||
..returns = ctx.buildContext.modelClassType
|
||||
..requiredParameters.add(new Parameter((b) => b
|
||||
..name = 'row'
|
||||
..type = refer('List')))
|
||||
..body = new Block((b) {
|
||||
var args = <String, Expression>{};
|
||||
|
||||
for (int i = 0; i < ctx.buildContext.fields.length; i++) {
|
||||
var field = ctx.buildContext.fields[i];
|
||||
args[field.name] = refer('row')
|
||||
.index(literalNum(i))
|
||||
.asA(convertTypeReference(field.type));
|
||||
}
|
||||
|
||||
var returnValue =
|
||||
ctx.buildContext.modelClassType.newInstance([], args);
|
||||
b.addExpression(returnValue.returned);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
// **************************************************************************
|
||||
// MongoDBOrmGenerator
|
||||
// **************************************************************************
|
||||
|
||||
part of 'author.orm.g.dart';
|
|
@ -10,4 +10,12 @@ class _PostgreSqlAuthorOrmImpl implements AuthorOrm {
|
|||
_PostgreSqlAuthorOrmImpl(this.connection);
|
||||
|
||||
final PostgreSQLConnection connection;
|
||||
|
||||
static Author parseRow(List row) {
|
||||
return new Author(
|
||||
id: (row[0] as String),
|
||||
name: (row[1] as String),
|
||||
createdAt: (row[2] as DateTime),
|
||||
updatedAt: (row[3] as DateTime));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
// **************************************************************************
|
||||
// MongoDBOrmGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// Error: Cannot infer SQL column type for field "author" with type "Author".
|
|
@ -1,7 +0,0 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
// **************************************************************************
|
||||
// MongoDBOrmGenerator
|
||||
// **************************************************************************
|
||||
|
||||
part of 'car.orm.g.dart';
|
|
@ -10,4 +10,15 @@ class _PostgreSqlCarOrmImpl implements CarOrm {
|
|||
_PostgreSqlCarOrmImpl(this.connection);
|
||||
|
||||
final PostgreSQLConnection connection;
|
||||
|
||||
static Car parseRow(List row) {
|
||||
return new Car(
|
||||
id: (row[0] as String),
|
||||
make: (row[1] as String),
|
||||
description: (row[2] as String),
|
||||
familyFriendly: (row[3] as bool),
|
||||
recalledAt: (row[4] as DateTime),
|
||||
createdAt: (row[5] as DateTime),
|
||||
updatedAt: (row[6] as DateTime));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
// **************************************************************************
|
||||
// MongoDBOrmGenerator
|
||||
// **************************************************************************
|
||||
|
||||
part of 'customer.orm.g.dart';
|
|
@ -10,4 +10,11 @@ class _PostgreSqlCustomerOrmImpl implements CustomerOrm {
|
|||
_PostgreSqlCustomerOrmImpl(this.connection);
|
||||
|
||||
final PostgreSQLConnection connection;
|
||||
|
||||
static Customer parseRow(List row) {
|
||||
return new Customer(
|
||||
id: (row[0] as String),
|
||||
createdAt: (row[1] as DateTime),
|
||||
updatedAt: (row[2] as DateTime));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
// **************************************************************************
|
||||
// MongoDBOrmGenerator
|
||||
// **************************************************************************
|
||||
|
||||
part of 'foot.orm.g.dart';
|
|
@ -10,4 +10,13 @@ class _PostgreSqlFootOrmImpl implements FootOrm {
|
|||
_PostgreSqlFootOrmImpl(this.connection);
|
||||
|
||||
final PostgreSQLConnection connection;
|
||||
|
||||
static Foot parseRow(List row) {
|
||||
return new Foot(
|
||||
id: (row[0] as String),
|
||||
legId: (row[1] as int),
|
||||
nToes: (row[2] as int),
|
||||
createdAt: (row[3] as DateTime),
|
||||
updatedAt: (row[4] as DateTime));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
// **************************************************************************
|
||||
// MongoDBOrmGenerator
|
||||
// **************************************************************************
|
||||
|
||||
part of 'fruit.orm.g.dart';
|
|
@ -10,4 +10,13 @@ class _PostgreSqlFruitOrmImpl implements FruitOrm {
|
|||
_PostgreSqlFruitOrmImpl(this.connection);
|
||||
|
||||
final PostgreSQLConnection connection;
|
||||
|
||||
static Fruit parseRow(List row) {
|
||||
return new Fruit(
|
||||
id: (row[0] as String),
|
||||
treeId: (row[1] as int),
|
||||
commonName: (row[2] as String),
|
||||
createdAt: (row[3] as DateTime),
|
||||
updatedAt: (row[4] as DateTime));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
// **************************************************************************
|
||||
// MongoDBOrmGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// Error: Cannot infer SQL column type for field "foot" with type "Foot".
|
|
@ -1,7 +0,0 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
// **************************************************************************
|
||||
// MongoDBOrmGenerator
|
||||
// **************************************************************************
|
||||
|
||||
part of 'order.orm.g.dart';
|
|
@ -10,4 +10,15 @@ class _PostgreSqlOrderOrmImpl implements OrderOrm {
|
|||
_PostgreSqlOrderOrmImpl(this.connection);
|
||||
|
||||
final PostgreSQLConnection connection;
|
||||
|
||||
static Order parseRow(List row) {
|
||||
return new Order(
|
||||
id: (row[0] as String),
|
||||
customerId: (row[1] as int),
|
||||
employeeId: (row[2] as int),
|
||||
orderDate: (row[3] as DateTime),
|
||||
shipperId: (row[4] as int),
|
||||
createdAt: (row[5] as DateTime),
|
||||
updatedAt: (row[6] as DateTime));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
// **************************************************************************
|
||||
// MongoDBOrmGenerator
|
||||
// **************************************************************************
|
||||
|
||||
part of 'role.orm.g.dart';
|
|
@ -10,4 +10,12 @@ class _PostgreSqlRoleOrmImpl implements RoleOrm {
|
|||
_PostgreSqlRoleOrmImpl(this.connection);
|
||||
|
||||
final PostgreSQLConnection connection;
|
||||
|
||||
static Role parseRow(List row) {
|
||||
return new Role(
|
||||
id: (row[0] as String),
|
||||
name: (row[1] as String),
|
||||
createdAt: (row[2] as DateTime),
|
||||
updatedAt: (row[3] as DateTime));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
// **************************************************************************
|
||||
// MongoDBOrmGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// Error: Cannot infer SQL column type for field "fruits" with type "List".
|
|
@ -1,7 +0,0 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
// **************************************************************************
|
||||
// MongoDBOrmGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// Error: Cannot infer SQL column type for field "roles" with type "List".
|
Loading…
Reference in a new issue