Gen "part x.mongo.dart"
This commit is contained in:
parent
b1c0ae7f72
commit
3d05f18232
14 changed files with 35 additions and 12 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -8,7 +8,7 @@ part 'book.g.dart';
|
|||
part 'book.serializer.g.dart';
|
||||
|
||||
@serializable
|
||||
@orm
|
||||
@postgreSqlOrm
|
||||
class _Book extends Model {
|
||||
@belongsTo
|
||||
Author author;
|
||||
|
|
|
@ -7,7 +7,7 @@ part 'car.g.dart';
|
|||
part 'car.serializer.g.dart';
|
||||
|
||||
@serializable
|
||||
@orm
|
||||
@postgreSqlOrm
|
||||
class _Car extends Model {
|
||||
String make;
|
||||
String description;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
}
|
|
@ -7,7 +7,7 @@ part 'foot.g.dart';
|
|||
part 'foot.serializer.g.dart';
|
||||
|
||||
@serializable
|
||||
@orm
|
||||
@postgreSqlOrm
|
||||
class _Foot extends Model {
|
||||
int legId, nToes;
|
||||
}
|
|
@ -7,7 +7,7 @@ part 'fruit.g.dart';
|
|||
part 'fruit.serializer.g.dart';
|
||||
|
||||
@serializable
|
||||
@orm
|
||||
@postgreSqlOrm
|
||||
class _Fruit extends Model {
|
||||
int treeId;
|
||||
String commonName;
|
||||
|
|
|
@ -8,7 +8,7 @@ part 'leg.g.dart';
|
|||
part 'leg.serializer.g.dart';
|
||||
|
||||
@serializable
|
||||
@orm
|
||||
@postgreSqlOrm
|
||||
class _Leg extends Model {
|
||||
@hasOne
|
||||
Foot foot;
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -7,7 +7,7 @@ part 'role.g.dart';
|
|||
part 'role.serializer.g.dart';
|
||||
|
||||
@serializable
|
||||
@orm
|
||||
@postgreSqlOrm
|
||||
class _Role extends Model {
|
||||
String name;
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -8,7 +8,7 @@ part 'user.g.dart';
|
|||
part 'user.serializer.g.dart';
|
||||
|
||||
@serializable
|
||||
@orm
|
||||
@postgreSqlOrm
|
||||
class _User extends Model {
|
||||
String username, password, email;
|
||||
|
||||
|
|
Loading…
Reference in a new issue