Gen "part x.mongo.dart"

This commit is contained in:
Tobe O 2018-08-24 10:40:41 -04:00
parent b1c0ae7f72
commit 3d05f18232
14 changed files with 35 additions and 12 deletions

View file

@ -49,6 +49,22 @@ class OrmGenerator extends GeneratorForAnnotation<Orm> {
new Directive.import(p.basename(inputId.uri.path)),
]);
// Add the corresponding `part`
String dbExtension;
switch (ctx.ormAnnotation.type) {
case OrmType.mongoDB:
dbExtension = 'mongo';
break;
default:
throw 'Unsupported ORM type: ${ctx.ormAnnotation.type}';
}
var dbFile =
p.setExtension(p.basename(inputId.uri.path), '.$dbExtension.dart');
lib.body.add(new Code("part '$dbFile';"));
// Create `FooOrm` abstract class
var rc = new ReCase(ctx.buildContext.modelClassName);

View file

@ -5,7 +5,10 @@ import 'package:source_gen/source_gen.dart';
const TypeChecker columnTypeChecker = const TypeChecker.fromRuntime(Column);
Orm reviveORMAnnotation(ConstantReader reader) {
return Orm(reader.peek('tableName')?.stringValue);
return Orm(
OrmType.values[reader.read('type').intValue],
tableName: reader.peek('tableName')?.stringValue,
);
}
class ColumnReader {

View file

@ -9,7 +9,7 @@ part 'author.g.dart';
part 'author.serializer.g.dart';
@serializable
@orm
@postgreSqlOrm
class _Author extends Model {
@Column(length: 255, indexType: IndexType.unique, defaultValue: 'Tobe Osakwe')
String name;

View file

@ -8,7 +8,7 @@ part 'book.g.dart';
part 'book.serializer.g.dart';
@serializable
@orm
@postgreSqlOrm
class _Book extends Model {
@belongsTo
Author author;

View file

@ -7,7 +7,7 @@ part 'car.g.dart';
part 'car.serializer.g.dart';
@serializable
@orm
@postgreSqlOrm
class _Car extends Model {
String make;
String description;

View file

@ -5,12 +5,16 @@
// **************************************************************************
import 'dart:async';
import 'car.dart';
abstract class CarOrm {
Future<List<Car>> getAll();
Future<Car> getById(id);
Future<Car> update(Car model);
CarQuery query();
}

View file

@ -6,7 +6,7 @@ import 'package:angel_serialize/angel_serialize.dart';
part 'customer.g.dart';
part 'customer.serializer.g.dart';
@orm
@postgreSqlOrm
@serializable
class _Customer extends Model {
}

View file

@ -7,7 +7,7 @@ part 'foot.g.dart';
part 'foot.serializer.g.dart';
@serializable
@orm
@postgreSqlOrm
class _Foot extends Model {
int legId, nToes;
}

View file

@ -7,7 +7,7 @@ part 'fruit.g.dart';
part 'fruit.serializer.g.dart';
@serializable
@orm
@postgreSqlOrm
class _Fruit extends Model {
int treeId;
String commonName;

View file

@ -8,7 +8,7 @@ part 'leg.g.dart';
part 'leg.serializer.g.dart';
@serializable
@orm
@postgreSqlOrm
class _Leg extends Model {
@hasOne
Foot foot;

View file

@ -7,7 +7,7 @@ import 'customer.dart';
part 'order.g.dart';
part 'order.serializer.g.dart';
@orm
@postgreSqlOrm
@serializable
class _Order extends Model {
@CanJoin(Customer, 'id')

View file

@ -7,7 +7,7 @@ part 'role.g.dart';
part 'role.serializer.g.dart';
@serializable
@orm
@postgreSqlOrm
class _Role extends Model {
String name;
}

View file

@ -8,7 +8,7 @@ part 'tree.g.dart';
part 'tree.serializer.g.dart';
@serializable
@orm
@postgreSqlOrm
class _Tree extends Model {
@Column(indexType: IndexType.unique, type: ColumnType.smallInt)
int rings;

View file

@ -8,7 +8,7 @@ part 'user.g.dart';
part 'user.serializer.g.dart';
@serializable
@orm
@postgreSqlOrm
class _User extends Model {
String username, password, email;