platform/angel_orm_service/example/todo.g.dart

299 lines
7 KiB
Dart
Raw Normal View History

2019-02-07 03:38:34 +00:00
// GENERATED CODE - DO NOT MODIFY BY HAND
2019-04-20 18:45:41 +00:00
part of 'todo.dart';
2019-02-07 03:38:34 +00:00
// **************************************************************************
// MigrationGenerator
// **************************************************************************
2019-04-20 18:45:41 +00:00
class TodoMigration extends Migration {
2019-02-07 03:38:34 +00:00
@override
up(Schema schema) {
2019-04-20 18:45:41 +00:00
schema.create('todos', (table) {
2019-02-07 03:38:34 +00:00
table.serial('id')..primaryKey();
2019-04-20 18:45:41 +00:00
table.boolean('is_complete')..defaultsTo(false);
table.varChar('text');
2019-02-07 03:38:34 +00:00
table.timeStamp('created_at');
table.timeStamp('updated_at');
});
}
@override
down(Schema schema) {
2019-04-20 18:45:41 +00:00
schema.drop('todos');
2019-02-07 03:38:34 +00:00
}
}
// **************************************************************************
// OrmGenerator
// **************************************************************************
2019-04-20 18:45:41 +00:00
class TodoQuery extends Query<Todo, TodoQueryWhere> {
TodoQuery({Set<String> trampoline}) {
2019-02-07 03:38:34 +00:00
trampoline ??= Set();
trampoline.add(tableName);
2019-04-20 18:45:41 +00:00
_where = TodoQueryWhere(this);
2019-02-07 03:38:34 +00:00
}
@override
2019-04-20 18:45:41 +00:00
final TodoQueryValues values = TodoQueryValues();
2019-02-07 03:38:34 +00:00
2019-04-20 18:45:41 +00:00
TodoQueryWhere _where;
2019-02-07 03:38:34 +00:00
@override
get casts {
return {};
}
@override
get tableName {
2019-04-20 18:45:41 +00:00
return 'todos';
2019-02-07 03:38:34 +00:00
}
@override
get fields {
2019-04-20 18:45:41 +00:00
return const ['id', 'is_complete', 'text', 'created_at', 'updated_at'];
2019-02-07 03:38:34 +00:00
}
@override
2019-04-20 18:45:41 +00:00
TodoQueryWhere get where {
2019-02-07 03:38:34 +00:00
return _where;
}
@override
2019-04-20 18:45:41 +00:00
TodoQueryWhere newWhereClause() {
return TodoQueryWhere(this);
2019-02-07 03:38:34 +00:00
}
2019-04-20 18:45:41 +00:00
static Todo parseRow(List row) {
2019-02-07 03:38:34 +00:00
if (row.every((x) => x == null)) return null;
2019-04-20 18:45:41 +00:00
var model = Todo(
2019-02-07 03:38:34 +00:00
id: row[0].toString(),
2019-04-20 18:45:41 +00:00
isComplete: (row[1] as bool),
text: (row[2] as String),
2019-02-07 03:38:34 +00:00
createdAt: (row[3] as DateTime),
updatedAt: (row[4] as DateTime));
return model;
}
@override
deserialize(List row) {
return parseRow(row);
}
}
2019-04-20 18:45:41 +00:00
class TodoQueryWhere extends QueryWhere {
TodoQueryWhere(TodoQuery query)
2019-02-07 03:38:34 +00:00
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
2019-04-20 18:45:41 +00:00
isComplete = BooleanSqlExpressionBuilder(query, 'is_complete'),
text = StringSqlExpressionBuilder(query, 'text'),
2019-02-07 03:38:34 +00:00
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
final NumericSqlExpressionBuilder<int> id;
2019-04-20 18:45:41 +00:00
final BooleanSqlExpressionBuilder isComplete;
2019-02-07 03:38:34 +00:00
2019-04-20 18:45:41 +00:00
final StringSqlExpressionBuilder text;
2019-02-07 03:38:34 +00:00
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
@override
get expressionBuilders {
2019-04-20 18:45:41 +00:00
return [id, isComplete, text, createdAt, updatedAt];
2019-02-07 03:38:34 +00:00
}
}
2019-04-20 18:45:41 +00:00
class TodoQueryValues extends MapQueryValues {
2019-02-07 03:38:34 +00:00
@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-04-20 18:45:41 +00:00
bool get isComplete {
return (values['is_complete'] as bool);
2019-02-07 03:38:34 +00:00
}
2019-04-20 18:45:41 +00:00
set isComplete(bool value) => values['is_complete'] = value;
String get text {
return (values['text'] as String);
2019-02-07 03:38:34 +00:00
}
2019-04-20 18:45:41 +00:00
set text(String value) => values['text'] = value;
2019-02-07 03:38:34 +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-04-20 18:45:41 +00:00
void copyFrom(Todo model) {
isComplete = model.isComplete;
text = model.text;
2019-02-07 03:38:34 +00:00
createdAt = model.createdAt;
updatedAt = model.updatedAt;
}
}
// **************************************************************************
// JsonModelGenerator
// **************************************************************************
@generatedSerializable
2019-04-20 18:45:41 +00:00
class Todo extends _Todo {
Todo(
{this.id,
this.isComplete = false,
@required this.text,
this.createdAt,
this.updatedAt});
2019-02-07 03:38:34 +00:00
@override
final String id;
@override
2019-04-20 18:45:41 +00:00
final bool isComplete;
2019-02-07 03:38:34 +00:00
@override
2019-04-20 18:45:41 +00:00
final String text;
2019-02-07 03:38:34 +00:00
@override
final DateTime createdAt;
@override
final DateTime updatedAt;
2019-04-20 18:45:41 +00:00
Todo copyWith(
2019-02-07 03:38:34 +00:00
{String id,
2019-04-20 18:45:41 +00:00
bool isComplete,
String text,
2019-02-07 03:38:34 +00:00
DateTime createdAt,
DateTime updatedAt}) {
2019-10-09 14:28:45 +00:00
return Todo(
2019-02-07 03:38:34 +00:00
id: id ?? this.id,
2019-04-20 18:45:41 +00:00
isComplete: isComplete ?? this.isComplete,
text: text ?? this.text,
2019-02-07 03:38:34 +00:00
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt);
}
bool operator ==(other) {
2019-04-20 18:45:41 +00:00
return other is _Todo &&
2019-02-07 03:38:34 +00:00
other.id == id &&
2019-04-20 18:45:41 +00:00
other.isComplete == isComplete &&
other.text == text &&
2019-02-07 03:38:34 +00:00
other.createdAt == createdAt &&
other.updatedAt == updatedAt;
}
@override
int get hashCode {
2019-04-20 18:45:41 +00:00
return hashObjects([id, isComplete, text, createdAt, updatedAt]);
2019-02-07 03:38:34 +00:00
}
2019-04-08 19:02:27 +00:00
@override
String toString() {
2019-04-20 18:45:41 +00:00
return "Todo(id=$id, isComplete=$isComplete, text=$text, createdAt=$createdAt, updatedAt=$updatedAt)";
2019-04-08 19:02:27 +00:00
}
2019-02-07 03:38:34 +00:00
Map<String, dynamic> toJson() {
2019-04-20 18:45:41 +00:00
return TodoSerializer.toMap(this);
2019-02-07 03:38:34 +00:00
}
}
// **************************************************************************
// SerializerGenerator
// **************************************************************************
2019-10-09 14:28:45 +00:00
const TodoSerializer todoSerializer = TodoSerializer();
2019-04-08 19:02:27 +00:00
2019-04-20 18:45:41 +00:00
class TodoEncoder extends Converter<Todo, Map> {
const TodoEncoder();
2019-04-08 19:02:27 +00:00
@override
2019-04-20 18:45:41 +00:00
Map convert(Todo model) => TodoSerializer.toMap(model);
2019-04-08 19:02:27 +00:00
}
2019-04-20 18:45:41 +00:00
class TodoDecoder extends Converter<Map, Todo> {
const TodoDecoder();
2019-04-08 19:02:27 +00:00
@override
2019-04-20 18:45:41 +00:00
Todo convert(Map map) => TodoSerializer.fromMap(map);
2019-04-08 19:02:27 +00:00
}
2019-04-20 18:45:41 +00:00
class TodoSerializer extends Codec<Todo, Map> {
const TodoSerializer();
2019-04-08 19:02:27 +00:00
@override
2019-04-20 18:45:41 +00:00
get encoder => const TodoEncoder();
2019-04-08 19:02:27 +00:00
@override
2019-04-20 18:45:41 +00:00
get decoder => const TodoDecoder();
static Todo fromMap(Map map) {
if (map['text'] == null) {
2019-10-09 14:28:45 +00:00
throw FormatException("Missing required field 'text' on Todo.");
2019-04-20 18:45:41 +00:00
}
2019-10-09 14:28:45 +00:00
return Todo(
2019-02-07 03:38:34 +00:00
id: map['id'] as String,
2019-04-20 18:45:41 +00:00
isComplete: map['is_complete'] as bool ?? false,
text: map['text'] as String,
2019-02-07 03:38:34 +00:00
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);
}
2019-04-20 18:45:41 +00:00
static Map<String, dynamic> toMap(_Todo model) {
2019-02-07 03:38:34 +00:00
if (model == null) {
return null;
}
2019-04-20 18:45:41 +00:00
if (model.text == null) {
2019-10-09 14:28:45 +00:00
throw FormatException("Missing required field 'text' on Todo.");
2019-04-20 18:45:41 +00:00
}
2019-02-07 03:38:34 +00:00
return {
'id': model.id,
2019-04-20 18:45:41 +00:00
'is_complete': model.isComplete,
'text': model.text,
2019-02-07 03:38:34 +00:00
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String()
};
}
}
2019-04-20 18:45:41 +00:00
abstract class TodoFields {
2019-02-07 03:38:34 +00:00
static const List<String> allFields = <String>[
id,
2019-04-20 18:45:41 +00:00
isComplete,
text,
2019-02-07 03:38:34 +00:00
createdAt,
updatedAt
];
static const String id = 'id';
2019-04-20 18:45:41 +00:00
static const String isComplete = 'is_complete';
2019-02-07 03:38:34 +00:00
2019-04-20 18:45:41 +00:00
static const String text = 'text';
2019-02-07 03:38:34 +00:00
static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at';
}