2019-02-07 03:38:34 +00:00
|
|
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
|
|
|
|
|
|
|
part of angel_orm_generator.test.models.tree;
|
|
|
|
|
2019-02-08 03:38:45 +00:00
|
|
|
// **************************************************************************
|
|
|
|
// MigrationGenerator
|
|
|
|
// **************************************************************************
|
|
|
|
|
|
|
|
class TreeMigration extends Migration {
|
|
|
|
@override
|
|
|
|
up(Schema schema) {
|
|
|
|
schema.create('trees', (table) {
|
|
|
|
table.serial('id')..primaryKey();
|
2019-04-03 09:57:27 +00:00
|
|
|
table.integer('rings');
|
2019-02-08 03:38:45 +00:00
|
|
|
table.timeStamp('created_at');
|
|
|
|
table.timeStamp('updated_at');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
down(Schema schema) {
|
2019-04-08 04:03:41 +00:00
|
|
|
schema.drop('trees', cascade: true);
|
2019-02-08 03:38:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-07 03:38:34 +00:00
|
|
|
// **************************************************************************
|
|
|
|
// OrmGenerator
|
|
|
|
// **************************************************************************
|
|
|
|
|
|
|
|
class TreeQuery extends Query<Tree, TreeQueryWhere> {
|
|
|
|
TreeQuery({Set<String> trampoline}) {
|
|
|
|
trampoline ??= Set();
|
|
|
|
trampoline.add(tableName);
|
|
|
|
_where = TreeQueryWhere(this);
|
2019-02-08 03:38:45 +00:00
|
|
|
leftJoin(FruitQuery(trampoline: trampoline), 'id', 'tree_id',
|
|
|
|
additionalFields: const [
|
|
|
|
'id',
|
|
|
|
'tree_id',
|
|
|
|
'common_name',
|
|
|
|
'created_at',
|
|
|
|
'updated_at'
|
2019-04-02 23:05:13 +00:00
|
|
|
],
|
|
|
|
trampoline: trampoline);
|
2019-02-07 03:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
final TreeQueryValues values = TreeQueryValues();
|
|
|
|
|
|
|
|
TreeQueryWhere _where;
|
|
|
|
|
|
|
|
@override
|
|
|
|
get casts {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
get tableName {
|
|
|
|
return 'trees';
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
get fields {
|
2019-02-08 03:38:45 +00:00
|
|
|
return const ['id', 'rings', 'created_at', 'updated_at'];
|
2019-02-07 03:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
TreeQueryWhere get where {
|
|
|
|
return _where;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
TreeQueryWhere newWhereClause() {
|
|
|
|
return TreeQueryWhere(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Tree parseRow(List row) {
|
|
|
|
if (row.every((x) => x == null)) return null;
|
2019-02-08 03:38:45 +00:00
|
|
|
var model = Tree(
|
|
|
|
id: row[0].toString(),
|
|
|
|
rings: (row[1] as int),
|
|
|
|
createdAt: (row[2] as DateTime),
|
|
|
|
updatedAt: (row[3] as DateTime));
|
|
|
|
if (row.length > 4) {
|
|
|
|
model = model.copyWith(
|
|
|
|
fruits: [FruitQuery.parseRow(row.skip(4).toList())]
|
|
|
|
.where((x) => x != null)
|
|
|
|
.toList());
|
|
|
|
}
|
2019-02-07 03:38:34 +00:00
|
|
|
return model;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
deserialize(List row) {
|
|
|
|
return parseRow(row);
|
|
|
|
}
|
2019-02-08 03:38:45 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
get(QueryExecutor executor) {
|
|
|
|
return super.get(executor).then((result) {
|
|
|
|
return result.fold<List<Tree>>([], (out, model) {
|
|
|
|
var idx = out.indexWhere((m) => m.id == model.id);
|
|
|
|
|
|
|
|
if (idx == -1) {
|
|
|
|
return out..add(model);
|
|
|
|
} else {
|
|
|
|
var l = out[idx];
|
|
|
|
return out
|
|
|
|
..[idx] = l.copyWith(
|
|
|
|
fruits: List<Fruit>.from(l.fruits ?? [])
|
|
|
|
..addAll(model.fruits ?? []));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
update(QueryExecutor executor) {
|
|
|
|
return super.update(executor).then((result) {
|
|
|
|
return result.fold<List<Tree>>([], (out, model) {
|
|
|
|
var idx = out.indexWhere((m) => m.id == model.id);
|
|
|
|
|
|
|
|
if (idx == -1) {
|
|
|
|
return out..add(model);
|
|
|
|
} else {
|
|
|
|
var l = out[idx];
|
|
|
|
return out
|
|
|
|
..[idx] = l.copyWith(
|
|
|
|
fruits: List<Fruit>.from(l.fruits ?? [])
|
|
|
|
..addAll(model.fruits ?? []));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
delete(QueryExecutor executor) {
|
|
|
|
return super.delete(executor).then((result) {
|
|
|
|
return result.fold<List<Tree>>([], (out, model) {
|
|
|
|
var idx = out.indexWhere((m) => m.id == model.id);
|
|
|
|
|
|
|
|
if (idx == -1) {
|
|
|
|
return out..add(model);
|
|
|
|
} else {
|
|
|
|
var l = out[idx];
|
|
|
|
return out
|
|
|
|
..[idx] = l.copyWith(
|
|
|
|
fruits: List<Fruit>.from(l.fruits ?? [])
|
|
|
|
..addAll(model.fruits ?? []));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2019-02-07 03:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class TreeQueryWhere extends QueryWhere {
|
|
|
|
TreeQueryWhere(TreeQuery query)
|
|
|
|
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
|
2019-02-08 03:38:45 +00:00
|
|
|
rings = NumericSqlExpressionBuilder<int>(query, 'rings'),
|
|
|
|
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
|
|
|
|
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
|
2019-02-07 03:38:34 +00:00
|
|
|
|
|
|
|
final NumericSqlExpressionBuilder<int> id;
|
|
|
|
|
|
|
|
final NumericSqlExpressionBuilder<int> rings;
|
|
|
|
|
2019-02-08 03:38:45 +00:00
|
|
|
final DateTimeSqlExpressionBuilder createdAt;
|
|
|
|
|
|
|
|
final DateTimeSqlExpressionBuilder updatedAt;
|
|
|
|
|
2019-02-07 03:38:34 +00:00
|
|
|
@override
|
|
|
|
get expressionBuilders {
|
2019-02-08 03:38:45 +00:00
|
|
|
return [id, rings, createdAt, updatedAt];
|
2019-02-07 03:38:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class TreeQueryValues extends MapQueryValues {
|
|
|
|
@override
|
|
|
|
get casts {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-04-03 09:57:27 +00:00
|
|
|
String get id {
|
|
|
|
return (values['id'] as String);
|
2019-02-07 03:38:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-03 09:57:27 +00:00
|
|
|
set id(String value) => values['id'] = value;
|
2019-02-07 03:38:34 +00:00
|
|
|
int get rings {
|
|
|
|
return (values['rings'] as int);
|
|
|
|
}
|
|
|
|
|
|
|
|
set rings(int value) => values['rings'] = value;
|
2019-02-08 03:38:45 +00:00
|
|
|
DateTime get createdAt {
|
|
|
|
return (values['created_at'] as DateTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
set createdAt(DateTime value) => values['created_at'] = value;
|
|
|
|
DateTime get updatedAt {
|
|
|
|
return (values['updated_at'] as DateTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
set updatedAt(DateTime value) => values['updated_at'] = value;
|
2019-02-07 03:38:34 +00:00
|
|
|
void copyFrom(Tree model) {
|
|
|
|
rings = model.rings;
|
2019-02-08 03:38:45 +00:00
|
|
|
createdAt = model.createdAt;
|
|
|
|
updatedAt = model.updatedAt;
|
2019-02-07 03:38:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// **************************************************************************
|
|
|
|
// JsonModelGenerator
|
|
|
|
// **************************************************************************
|
|
|
|
|
|
|
|
@generatedSerializable
|
|
|
|
class Tree extends _Tree {
|
|
|
|
Tree(
|
2019-04-08 04:03:41 +00:00
|
|
|
{this.id,
|
|
|
|
@required this.rings,
|
|
|
|
@required List<Fruit> fruits,
|
|
|
|
this.createdAt,
|
|
|
|
this.updatedAt})
|
2019-02-07 03:38:34 +00:00
|
|
|
: this.fruits = new List.unmodifiable(fruits ?? []);
|
|
|
|
|
|
|
|
@override
|
|
|
|
final String id;
|
|
|
|
|
|
|
|
@override
|
|
|
|
final int rings;
|
|
|
|
|
|
|
|
@override
|
2019-02-08 03:38:45 +00:00
|
|
|
final List<Fruit> fruits;
|
2019-02-07 03:38:34 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
final DateTime createdAt;
|
|
|
|
|
|
|
|
@override
|
|
|
|
final DateTime updatedAt;
|
|
|
|
|
|
|
|
Tree copyWith(
|
|
|
|
{String id,
|
|
|
|
int rings,
|
2019-02-08 03:38:45 +00:00
|
|
|
List<Fruit> fruits,
|
2019-02-07 03:38:34 +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 &&
|
2019-02-08 03:38:45 +00:00
|
|
|
const ListEquality<Fruit>(const DefaultEquality<Fruit>())
|
2019-02-07 03:38:34 +00:00
|
|
|
.equals(other.fruits, fruits) &&
|
|
|
|
other.createdAt == createdAt &&
|
|
|
|
other.updatedAt == updatedAt;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
int get hashCode {
|
|
|
|
return hashObjects([id, rings, fruits, createdAt, updatedAt]);
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<String, dynamic> toJson() {
|
|
|
|
return TreeSerializer.toMap(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// **************************************************************************
|
|
|
|
// SerializerGenerator
|
|
|
|
// **************************************************************************
|
|
|
|
|
|
|
|
abstract class TreeSerializer {
|
|
|
|
static Tree fromMap(Map map) {
|
2019-04-08 04:03:41 +00:00
|
|
|
if (map['rings'] == null) {
|
|
|
|
throw new FormatException("Missing required field 'rings' on Tree.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (map['fruits'] == null) {
|
|
|
|
throw new FormatException("Missing required field 'fruits' on Tree.");
|
|
|
|
}
|
|
|
|
|
2019-02-07 03:38:34 +00:00
|
|
|
return new Tree(
|
|
|
|
id: map['id'] as String,
|
|
|
|
rings: map['rings'] as int,
|
|
|
|
fruits: map['fruits'] is Iterable
|
2019-02-08 03:38:45 +00:00
|
|
|
? new List.unmodifiable(
|
|
|
|
((map['fruits'] as Iterable).where((x) => x is Map))
|
|
|
|
.cast<Map>()
|
|
|
|
.map(FruitSerializer.fromMap))
|
2019-02-07 03:38:34 +00:00
|
|
|
: 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Map<String, dynamic> toMap(_Tree model) {
|
|
|
|
if (model == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2019-04-08 04:03:41 +00:00
|
|
|
if (model.rings == null) {
|
|
|
|
throw new FormatException("Missing required field 'rings' on Tree.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (model.fruits == null) {
|
|
|
|
throw new FormatException("Missing required field 'fruits' on Tree.");
|
|
|
|
}
|
|
|
|
|
2019-02-07 03:38:34 +00:00
|
|
|
return {
|
|
|
|
'id': model.id,
|
|
|
|
'rings': model.rings,
|
2019-02-08 03:38:45 +00:00
|
|
|
'fruits': model.fruits?.map((m) => FruitSerializer.toMap(m))?.toList(),
|
2019-02-07 03:38:34 +00:00
|
|
|
'created_at': model.createdAt?.toIso8601String(),
|
|
|
|
'updated_at': model.updatedAt?.toIso8601String()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract class TreeFields {
|
|
|
|
static const List<String> allFields = <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';
|
|
|
|
}
|