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)),
|
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
|
// Create `FooOrm` abstract class
|
||||||
var rc = new ReCase(ctx.buildContext.modelClassName);
|
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);
|
const TypeChecker columnTypeChecker = const TypeChecker.fromRuntime(Column);
|
||||||
|
|
||||||
Orm reviveORMAnnotation(ConstantReader reader) {
|
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 {
|
class ColumnReader {
|
||||||
|
|
|
@ -9,7 +9,7 @@ part 'author.g.dart';
|
||||||
part 'author.serializer.g.dart';
|
part 'author.serializer.g.dart';
|
||||||
|
|
||||||
@serializable
|
@serializable
|
||||||
@orm
|
@postgreSqlOrm
|
||||||
class _Author extends Model {
|
class _Author extends Model {
|
||||||
@Column(length: 255, indexType: IndexType.unique, defaultValue: 'Tobe Osakwe')
|
@Column(length: 255, indexType: IndexType.unique, defaultValue: 'Tobe Osakwe')
|
||||||
String name;
|
String name;
|
||||||
|
|
|
@ -8,7 +8,7 @@ part 'book.g.dart';
|
||||||
part 'book.serializer.g.dart';
|
part 'book.serializer.g.dart';
|
||||||
|
|
||||||
@serializable
|
@serializable
|
||||||
@orm
|
@postgreSqlOrm
|
||||||
class _Book extends Model {
|
class _Book extends Model {
|
||||||
@belongsTo
|
@belongsTo
|
||||||
Author author;
|
Author author;
|
||||||
|
|
|
@ -7,7 +7,7 @@ part 'car.g.dart';
|
||||||
part 'car.serializer.g.dart';
|
part 'car.serializer.g.dart';
|
||||||
|
|
||||||
@serializable
|
@serializable
|
||||||
@orm
|
@postgreSqlOrm
|
||||||
class _Car extends Model {
|
class _Car extends Model {
|
||||||
String make;
|
String make;
|
||||||
String description;
|
String description;
|
||||||
|
|
|
@ -5,12 +5,16 @@
|
||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'car.dart';
|
import 'car.dart';
|
||||||
|
|
||||||
abstract class CarOrm {
|
abstract class CarOrm {
|
||||||
Future<List<Car>> getAll();
|
Future<List<Car>> getAll();
|
||||||
|
|
||||||
Future<Car> getById(id);
|
Future<Car> getById(id);
|
||||||
|
|
||||||
Future<Car> update(Car model);
|
Future<Car> update(Car model);
|
||||||
|
|
||||||
CarQuery query();
|
CarQuery query();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import 'package:angel_serialize/angel_serialize.dart';
|
||||||
part 'customer.g.dart';
|
part 'customer.g.dart';
|
||||||
part 'customer.serializer.g.dart';
|
part 'customer.serializer.g.dart';
|
||||||
|
|
||||||
@orm
|
@postgreSqlOrm
|
||||||
@serializable
|
@serializable
|
||||||
class _Customer extends Model {
|
class _Customer extends Model {
|
||||||
}
|
}
|
|
@ -7,7 +7,7 @@ part 'foot.g.dart';
|
||||||
part 'foot.serializer.g.dart';
|
part 'foot.serializer.g.dart';
|
||||||
|
|
||||||
@serializable
|
@serializable
|
||||||
@orm
|
@postgreSqlOrm
|
||||||
class _Foot extends Model {
|
class _Foot extends Model {
|
||||||
int legId, nToes;
|
int legId, nToes;
|
||||||
}
|
}
|
|
@ -7,7 +7,7 @@ part 'fruit.g.dart';
|
||||||
part 'fruit.serializer.g.dart';
|
part 'fruit.serializer.g.dart';
|
||||||
|
|
||||||
@serializable
|
@serializable
|
||||||
@orm
|
@postgreSqlOrm
|
||||||
class _Fruit extends Model {
|
class _Fruit extends Model {
|
||||||
int treeId;
|
int treeId;
|
||||||
String commonName;
|
String commonName;
|
||||||
|
|
|
@ -8,7 +8,7 @@ part 'leg.g.dart';
|
||||||
part 'leg.serializer.g.dart';
|
part 'leg.serializer.g.dart';
|
||||||
|
|
||||||
@serializable
|
@serializable
|
||||||
@orm
|
@postgreSqlOrm
|
||||||
class _Leg extends Model {
|
class _Leg extends Model {
|
||||||
@hasOne
|
@hasOne
|
||||||
Foot foot;
|
Foot foot;
|
||||||
|
|
|
@ -7,7 +7,7 @@ import 'customer.dart';
|
||||||
part 'order.g.dart';
|
part 'order.g.dart';
|
||||||
part 'order.serializer.g.dart';
|
part 'order.serializer.g.dart';
|
||||||
|
|
||||||
@orm
|
@postgreSqlOrm
|
||||||
@serializable
|
@serializable
|
||||||
class _Order extends Model {
|
class _Order extends Model {
|
||||||
@CanJoin(Customer, 'id')
|
@CanJoin(Customer, 'id')
|
||||||
|
|
|
@ -7,7 +7,7 @@ part 'role.g.dart';
|
||||||
part 'role.serializer.g.dart';
|
part 'role.serializer.g.dart';
|
||||||
|
|
||||||
@serializable
|
@serializable
|
||||||
@orm
|
@postgreSqlOrm
|
||||||
class _Role extends Model {
|
class _Role extends Model {
|
||||||
String name;
|
String name;
|
||||||
}
|
}
|
|
@ -8,7 +8,7 @@ part 'tree.g.dart';
|
||||||
part 'tree.serializer.g.dart';
|
part 'tree.serializer.g.dart';
|
||||||
|
|
||||||
@serializable
|
@serializable
|
||||||
@orm
|
@postgreSqlOrm
|
||||||
class _Tree extends Model {
|
class _Tree extends Model {
|
||||||
@Column(indexType: IndexType.unique, type: ColumnType.smallInt)
|
@Column(indexType: IndexType.unique, type: ColumnType.smallInt)
|
||||||
int rings;
|
int rings;
|
||||||
|
|
|
@ -8,7 +8,7 @@ part 'user.g.dart';
|
||||||
part 'user.serializer.g.dart';
|
part 'user.serializer.g.dart';
|
||||||
|
|
||||||
@serializable
|
@serializable
|
||||||
@orm
|
@postgreSqlOrm
|
||||||
class _User extends Model {
|
class _User extends Model {
|
||||||
String username, password, email;
|
String username, password, email;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue