platform/angel_orm_generator/test/models/tree.g.dart

287 lines
7.2 KiB
Dart
Raw Normal View History

2018-08-24 13:42:09 +00:00
// GENERATED CODE - DO NOT MODIFY BY HAND
part of angel_orm_generator.test.models.tree;
2018-12-09 17:44:16 +00:00
// **************************************************************************
// MigrationGenerator
// **************************************************************************
class TreeMigration extends Migration {
@override
up(Schema schema) {
schema.create('trees', (table) {
table.serial('id')..primaryKey();
table.declare('rings', new ColumnType('smallint'));
table.timeStamp('created_at');
table.timeStamp('updated_at');
});
}
@override
down(Schema schema) {
schema.drop('trees');
}
}
2018-12-08 04:13:49 +00:00
// **************************************************************************
// OrmGenerator
// **************************************************************************
class TreeQuery extends Query<Tree, TreeQueryWhere> {
2018-12-31 12:22:05 +00:00
TreeQuery() {
_where = new TreeQueryWhere(this);
}
2018-12-08 04:13:49 +00:00
@override
final TreeQueryValues values = new TreeQueryValues();
2018-12-31 12:22:05 +00:00
TreeQueryWhere _where;
2018-12-08 04:13:49 +00:00
@override
get tableName {
return 'trees';
}
@override
get fields {
return const ['id', 'rings', 'created_at', 'updated_at'];
}
2018-12-31 12:22:05 +00:00
@override
TreeQueryWhere get where {
return _where;
}
2018-12-08 04:13:49 +00:00
@override
TreeQueryWhere newWhereClause() {
2018-12-31 12:22:05 +00:00
return new TreeQueryWhere(this);
2018-12-08 04:13:49 +00:00
}
static Tree parseRow(List row) {
if (row.every((x) => x == null)) return null;
var model = new Tree(
id: row[0].toString(),
rings: (row[1] as int),
createdAt: (row[2] as DateTime),
updatedAt: (row[3] as DateTime));
return model;
}
@override
deserialize(List row) {
return parseRow(row);
}
@override
insert(executor) {
return executor.transaction(() async {
var result = await super.insert(executor);
where.id.equals(int.parse(result.id));
result = await getOne(executor);
result = await fetchLinked(result, executor);
return result;
});
}
Future<Tree> fetchLinked(Tree model, QueryExecutor executor) async {
return model.copyWith(
fruits: await (new FruitQuery()
..where.treeId.equals(int.parse(model.id)))
.get(executor));
}
@override
get(QueryExecutor executor) {
return executor.transaction(() async {
var result = await super.get(executor);
return await Future.wait(result.map((m) => fetchLinked(m, executor)));
});
}
@override
update(QueryExecutor executor) {
return executor.transaction(() async {
var result = await super.update(executor);
return await Future.wait(result.map((m) => fetchLinked(m, executor)));
});
}
@override
delete(QueryExecutor executor) {
return executor.transaction(() async {
var result = await super.delete(executor);
return await Future.wait(result.map((m) => fetchLinked(m, executor)));
});
}
}
class TreeQueryWhere extends QueryWhere {
2018-12-31 12:22:05 +00:00
TreeQueryWhere(TreeQuery query)
: id = new NumericSqlExpressionBuilder<int>(query, 'id'),
rings = new NumericSqlExpressionBuilder<int>(query, 'rings'),
createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at');
final NumericSqlExpressionBuilder<int> id;
2018-12-08 04:13:49 +00:00
2018-12-31 12:22:05 +00:00
final NumericSqlExpressionBuilder<int> rings;
2018-12-08 04:13:49 +00:00
2018-12-31 12:22:05 +00:00
final DateTimeSqlExpressionBuilder createdAt;
2018-12-08 04:13:49 +00:00
2018-12-31 12:22:05 +00:00
final DateTimeSqlExpressionBuilder updatedAt;
2018-12-08 04:13:49 +00:00
@override
get expressionBuilders {
return [id, rings, createdAt, updatedAt];
}
}
class TreeQueryValues extends MapQueryValues {
int get id {
return (values['id'] as int);
}
2018-12-31 12:22:05 +00:00
set id(int value) => values['id'] = value;
2018-12-08 04:13:49 +00:00
int get rings {
return (values['rings'] as int);
}
2018-12-31 12:22:05 +00:00
set rings(int value) => values['rings'] = value;
2018-12-08 04:13:49 +00:00
DateTime get createdAt {
return (values['created_at'] as DateTime);
}
2018-12-31 12:22:05 +00:00
set createdAt(DateTime value) => values['created_at'] = value;
2018-12-08 04:13:49 +00:00
DateTime get updatedAt {
return (values['updated_at'] as DateTime);
}
2018-12-31 12:22:05 +00:00
set updatedAt(DateTime value) => values['updated_at'] = value;
2018-12-08 04:13:49 +00:00
void copyFrom(Tree model) {
values.addAll({
'rings': model.rings,
'created_at': model.createdAt,
'updated_at': model.updatedAt
});
}
}
2018-08-24 13:42:09 +00:00
// **************************************************************************
// JsonModelGenerator
// **************************************************************************
@generatedSerializable
class Tree extends _Tree {
Tree(
2018-12-03 13:41:14 +00:00
{this.id, this.rings, List<Fruit> fruits, this.createdAt, this.updatedAt})
2018-08-24 13:42:09 +00:00
: this.fruits = new List.unmodifiable(fruits ?? []);
@override
final String id;
@override
final int rings;
@override
2018-12-03 13:41:14 +00:00
final List<Fruit> fruits;
2018-08-24 13:42:09 +00:00
@override
final DateTime createdAt;
@override
final DateTime updatedAt;
Tree copyWith(
{String id,
int rings,
2018-12-03 13:41:14 +00:00
List<Fruit> fruits,
2018-08-24 13:42:09 +00:00
DateTime createdAt,
DateTime updatedAt}) {
return new Tree(
id: id ?? this.id,
rings: rings ?? this.rings,
fruits: fruits ?? this.fruits,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt);
}
bool operator ==(other) {
return other is _Tree &&
other.id == id &&
other.rings == rings &&
2018-12-03 13:41:14 +00:00
const ListEquality<Fruit>(const DefaultEquality<Fruit>())
2018-08-24 13:42:09 +00:00
.equals(other.fruits, fruits) &&
other.createdAt == createdAt &&
other.updatedAt == updatedAt;
}
2018-12-01 19:03:43 +00:00
@override
int get hashCode {
return hashObjects([id, rings, fruits, createdAt, updatedAt]);
}
2018-08-24 13:42:09 +00:00
Map<String, dynamic> toJson() {
return TreeSerializer.toMap(this);
}
}
2018-12-08 21:00:31 +00:00
// **************************************************************************
// SerializerGenerator
// **************************************************************************
abstract class TreeSerializer {
static Tree fromMap(Map map) {
return new Tree(
id: map['id'] as String,
rings: map['rings'] as int,
fruits: map['fruits'] is Iterable
? new List.unmodifiable(((map['fruits'] as Iterable)
.where((x) => x is Map) as Iterable<Map>)
.map(FruitSerializer.fromMap))
: null,
createdAt: map['created_at'] != null
? (map['created_at'] is DateTime
? (map['created_at'] as DateTime)
: DateTime.parse(map['created_at'].toString()))
: null,
updatedAt: map['updated_at'] != null
? (map['updated_at'] is DateTime
? (map['updated_at'] as DateTime)
: DateTime.parse(map['updated_at'].toString()))
: null);
}
2018-12-08 22:51:27 +00:00
static Map<String, dynamic> toMap(_Tree model) {
2018-12-08 21:00:31 +00:00
if (model == null) {
return null;
}
return {
'id': model.id,
'rings': model.rings,
2018-12-08 22:51:27 +00:00
'fruits': model.fruits?.map((m) => FruitSerializer.toMap(m))?.toList(),
2018-12-08 21:00:31 +00:00
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String()
};
}
}
abstract class TreeFields {
static const List<String> allFields = const <String>[
id,
rings,
fruits,
createdAt,
updatedAt
];
static const String id = 'id';
static const String rings = 'rings';
static const String fruits = 'fruits';
static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at';
}