platform/angel_orm_test/lib/src/models/book.g.dart

593 lines
14 KiB
Dart
Raw Normal View History

2019-02-07 03:38:34 +00:00
// GENERATED CODE - DO NOT MODIFY BY HAND
part of angel_orm.generator.models.book;
2019-02-08 03:38:45 +00:00
// **************************************************************************
// MigrationGenerator
// **************************************************************************
class BookMigration extends Migration {
@override
up(Schema schema) {
schema.create('books', (table) {
table.serial('id')..primaryKey();
table.timeStamp('created_at');
table.timeStamp('updated_at');
2019-07-04 21:08:20 +00:00
table.varChar('name');
2019-07-04 21:26:39 +00:00
table
.declare('author_id', ColumnType('serial'))
.references('authors', 'id');
table
.declare('partner_author_id', ColumnType('serial'))
.references('authors', 'id');
2019-02-08 03:38:45 +00:00
});
}
@override
down(Schema schema) {
schema.drop('books');
}
}
2019-04-20 18:45:41 +00:00
class AuthorMigration extends Migration {
@override
up(Schema schema) {
schema.create('authors', (table) {
table.serial('id')..primaryKey();
table.timeStamp('created_at');
table.timeStamp('updated_at');
2019-07-04 21:08:20 +00:00
table.varChar('name', length: 255)..defaultsTo('Tobe Osakwe');
2019-04-20 18:45:41 +00:00
});
}
@override
down(Schema schema) {
schema.drop('authors');
}
}
2019-02-07 03:38:34 +00:00
// **************************************************************************
// OrmGenerator
// **************************************************************************
class BookQuery extends Query<Book, BookQueryWhere> {
BookQuery({Set<String> trampoline}) {
trampoline ??= Set();
trampoline.add(tableName);
_where = BookQueryWhere(this);
2019-02-08 03:38:45 +00:00
leftJoin('authors', 'author_id', 'id',
2019-07-04 21:08:20 +00:00
additionalFields: const ['id', 'created_at', 'updated_at', 'name'],
2019-04-02 23:05:13 +00:00
trampoline: trampoline);
2019-02-08 03:38:45 +00:00
leftJoin('authors', 'partner_author_id', 'id',
2019-07-04 21:08:20 +00:00
additionalFields: const ['id', 'created_at', 'updated_at', 'name'],
2019-04-02 23:05:13 +00:00
trampoline: trampoline);
2019-02-07 03:38:34 +00:00
}
@override
final BookQueryValues values = BookQueryValues();
BookQueryWhere _where;
@override
get casts {
return {};
}
@override
get tableName {
return 'books';
}
@override
get fields {
2019-02-08 03:38:45 +00:00
return const [
'id',
2019-07-04 21:08:20 +00:00
'created_at',
'updated_at',
2019-02-08 03:38:45 +00:00
'author_id',
'partner_author_id',
2019-07-04 21:08:20 +00:00
'name'
2019-02-08 03:38:45 +00:00
];
2019-02-07 03:38:34 +00:00
}
@override
BookQueryWhere get where {
return _where;
}
@override
BookQueryWhere newWhereClause() {
return BookQueryWhere(this);
}
static Book parseRow(List row) {
if (row.every((x) => x == null)) return null;
2019-02-08 03:38:45 +00:00
var model = Book(
id: row[0].toString(),
2019-07-04 21:08:20 +00:00
createdAt: (row[1] as DateTime),
updatedAt: (row[2] as DateTime),
name: (row[5] as String));
2019-02-08 03:38:45 +00:00
if (row.length > 6) {
2019-04-20 18:45:41 +00:00
model = model.copyWith(
author: AuthorQuery.parseRow(row.skip(6).take(4).toList()));
2019-02-08 03:38:45 +00:00
}
if (row.length > 10) {
model = model.copyWith(
2019-04-20 18:45:41 +00:00
partnerAuthor: AuthorQuery.parseRow(row.skip(10).take(4).toList()));
2019-02-08 03:38:45 +00:00
}
2019-02-07 03:38:34 +00:00
return model;
}
@override
deserialize(List row) {
return parseRow(row);
}
}
class BookQueryWhere extends QueryWhere {
BookQueryWhere(BookQuery query)
2019-02-08 03:38:45 +00:00
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
2019-07-04 21:08:20 +00:00
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
2019-02-08 03:38:45 +00:00
authorId = NumericSqlExpressionBuilder<int>(query, 'author_id'),
partnerAuthorId =
NumericSqlExpressionBuilder<int>(query, 'partner_author_id'),
2019-07-04 21:08:20 +00:00
name = StringSqlExpressionBuilder(query, 'name');
2019-02-07 03:38:34 +00:00
final NumericSqlExpressionBuilder<int> id;
2019-07-04 21:08:20 +00:00
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
2019-02-08 03:38:45 +00:00
final NumericSqlExpressionBuilder<int> authorId;
final NumericSqlExpressionBuilder<int> partnerAuthorId;
final StringSqlExpressionBuilder name;
2019-02-07 03:38:34 +00:00
@override
get expressionBuilders {
2019-07-04 21:08:20 +00:00
return [id, createdAt, updatedAt, authorId, partnerAuthorId, name];
2019-02-07 03:38:34 +00:00
}
}
class BookQueryValues 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-07-04 21:08:20 +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-08 03:38:45 +00:00
int get authorId {
return (values['author_id'] as int);
}
set authorId(int value) => values['author_id'] = value;
int get partnerAuthorId {
return (values['partner_author_id'] as int);
}
set partnerAuthorId(int value) => values['partner_author_id'] = value;
String get name {
return (values['name'] as String);
}
set name(String value) => values['name'] = value;
void copyFrom(Book model) {
createdAt = model.createdAt;
updatedAt = model.updatedAt;
2019-07-04 21:08:20 +00:00
name = model.name;
2019-02-08 03:38:45 +00:00
if (model.author != null) {
2019-04-03 09:57:27 +00:00
values['author_id'] = model.author.id;
2019-02-08 03:38:45 +00:00
}
if (model.partnerAuthor != null) {
2019-04-03 09:57:27 +00:00
values['partner_author_id'] = model.partnerAuthor.id;
2019-02-08 03:38:45 +00:00
}
}
2019-02-07 03:38:34 +00:00
}
2019-04-20 18:45:41 +00:00
class AuthorQuery extends Query<Author, AuthorQueryWhere> {
AuthorQuery({Set<String> trampoline}) {
trampoline ??= Set();
trampoline.add(tableName);
_where = AuthorQueryWhere(this);
}
@override
final AuthorQueryValues values = AuthorQueryValues();
AuthorQueryWhere _where;
@override
get casts {
return {};
}
@override
get tableName {
return 'authors';
}
@override
get fields {
2019-07-04 21:08:20 +00:00
return const ['id', 'created_at', 'updated_at', 'name'];
2019-04-20 18:45:41 +00:00
}
@override
AuthorQueryWhere get where {
return _where;
}
@override
AuthorQueryWhere newWhereClause() {
return AuthorQueryWhere(this);
}
static Author parseRow(List row) {
if (row.every((x) => x == null)) return null;
var model = Author(
id: row[0].toString(),
2019-07-04 21:08:20 +00:00
createdAt: (row[1] as DateTime),
updatedAt: (row[2] as DateTime),
name: (row[3] as String));
2019-04-20 18:45:41 +00:00
return model;
}
@override
deserialize(List row) {
return parseRow(row);
}
}
class AuthorQueryWhere extends QueryWhere {
AuthorQueryWhere(AuthorQuery query)
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
2019-07-04 21:08:20 +00:00
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
name = StringSqlExpressionBuilder(query, 'name');
2019-04-20 18:45:41 +00:00
final NumericSqlExpressionBuilder<int> id;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
2019-07-04 21:08:20 +00:00
final StringSqlExpressionBuilder name;
2019-04-20 18:45:41 +00:00
@override
get expressionBuilders {
2019-07-04 21:08:20 +00:00
return [id, createdAt, updatedAt, name];
2019-04-20 18:45:41 +00:00
}
}
class AuthorQueryValues extends MapQueryValues {
@override
get casts {
return {};
}
String get id {
return (values['id'] as String);
}
set id(String value) => values['id'] = value;
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-07-04 21:08:20 +00:00
String get name {
return (values['name'] as String);
}
set name(String value) => values['name'] = value;
2019-04-20 18:45:41 +00:00
void copyFrom(Author model) {
createdAt = model.createdAt;
updatedAt = model.updatedAt;
2019-07-04 21:08:20 +00:00
name = model.name;
2019-04-20 18:45:41 +00:00
}
}
2019-02-07 03:38:34 +00:00
// **************************************************************************
// JsonModelGenerator
// **************************************************************************
@generatedSerializable
class Book extends _Book {
Book(
{this.id,
2019-07-04 21:08:20 +00:00
this.createdAt,
this.updatedAt,
2019-04-08 15:06:06 +00:00
this.author,
this.partnerAuthor,
2019-07-04 21:08:20 +00:00
this.name});
2019-02-07 03:38:34 +00:00
2019-07-04 21:08:20 +00:00
/// A unique identifier corresponding to this item.
2019-02-07 03:38:34 +00:00
@override
2019-07-04 21:08:20 +00:00
String id;
2019-02-07 03:38:34 +00:00
2019-07-04 21:08:20 +00:00
/// The time at which this item was created.
2019-02-07 03:38:34 +00:00
@override
2019-07-04 21:08:20 +00:00
DateTime createdAt;
2019-02-07 03:38:34 +00:00
2019-07-04 21:08:20 +00:00
/// The last time at which this item was updated.
2019-02-07 03:38:34 +00:00
@override
2019-07-04 21:08:20 +00:00
DateTime updatedAt;
2019-02-07 03:38:34 +00:00
@override
2019-07-04 21:08:20 +00:00
_Author author;
2019-02-07 03:38:34 +00:00
@override
2019-07-04 21:08:20 +00:00
_Author partnerAuthor;
2019-02-07 03:38:34 +00:00
@override
2019-07-04 21:08:20 +00:00
String name;
2019-02-07 03:38:34 +00:00
Book copyWith(
{String id,
2019-07-04 21:08:20 +00:00
DateTime createdAt,
DateTime updatedAt,
2019-04-20 18:45:41 +00:00
_Author author,
_Author partnerAuthor,
2019-07-04 21:08:20 +00:00
String name}) {
return Book(
2019-02-07 03:38:34 +00:00
id: id ?? this.id,
2019-07-04 21:08:20 +00:00
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
2019-02-07 03:38:34 +00:00
author: author ?? this.author,
partnerAuthor: partnerAuthor ?? this.partnerAuthor,
2019-07-04 21:08:20 +00:00
name: name ?? this.name);
2019-02-07 03:38:34 +00:00
}
bool operator ==(other) {
return other is _Book &&
other.id == id &&
2019-07-04 21:08:20 +00:00
other.createdAt == createdAt &&
other.updatedAt == updatedAt &&
2019-02-07 03:38:34 +00:00
other.author == author &&
other.partnerAuthor == partnerAuthor &&
2019-07-04 21:08:20 +00:00
other.name == name;
2019-02-07 03:38:34 +00:00
}
@override
int get hashCode {
2019-07-04 21:08:20 +00:00
return hashObjects([id, createdAt, updatedAt, author, partnerAuthor, name]);
2019-02-07 03:38:34 +00:00
}
2019-04-08 19:02:27 +00:00
@override
String toString() {
2019-07-04 21:08:20 +00:00
return "Book(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, author=$author, partnerAuthor=$partnerAuthor, name=$name)";
2019-04-08 19:02:27 +00:00
}
2019-02-07 03:38:34 +00:00
Map<String, dynamic> toJson() {
return BookSerializer.toMap(this);
}
}
2019-04-20 18:45:41 +00:00
@generatedSerializable
class Author extends _Author {
2019-07-04 21:08:20 +00:00
Author({this.id, this.createdAt, this.updatedAt, this.name = 'Tobe Osakwe'});
2019-04-20 18:45:41 +00:00
2019-07-04 21:08:20 +00:00
/// A unique identifier corresponding to this item.
2019-04-20 18:45:41 +00:00
@override
2019-07-04 21:08:20 +00:00
String id;
2019-04-20 18:45:41 +00:00
2019-07-04 21:08:20 +00:00
/// The time at which this item was created.
2019-04-20 18:45:41 +00:00
@override
2019-07-04 21:08:20 +00:00
DateTime createdAt;
2019-04-20 18:45:41 +00:00
2019-07-04 21:08:20 +00:00
/// The last time at which this item was updated.
2019-04-20 18:45:41 +00:00
@override
2019-07-04 21:08:20 +00:00
DateTime updatedAt;
2019-04-20 18:45:41 +00:00
@override
2019-07-04 21:08:20 +00:00
final String name;
2019-04-20 18:45:41 +00:00
Author copyWith(
2019-07-04 21:08:20 +00:00
{String id, DateTime createdAt, DateTime updatedAt, String name}) {
return Author(
2019-04-20 18:45:41 +00:00
id: id ?? this.id,
createdAt: createdAt ?? this.createdAt,
2019-07-04 21:08:20 +00:00
updatedAt: updatedAt ?? this.updatedAt,
name: name ?? this.name);
2019-04-20 18:45:41 +00:00
}
bool operator ==(other) {
return other is _Author &&
other.id == id &&
other.createdAt == createdAt &&
2019-07-04 21:08:20 +00:00
other.updatedAt == updatedAt &&
other.name == name;
2019-04-20 18:45:41 +00:00
}
@override
int get hashCode {
2019-07-04 21:08:20 +00:00
return hashObjects([id, createdAt, updatedAt, name]);
2019-04-20 18:45:41 +00:00
}
@override
String toString() {
2019-07-04 21:08:20 +00:00
return "Author(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, name=$name)";
2019-04-20 18:45:41 +00:00
}
Map<String, dynamic> toJson() {
return AuthorSerializer.toMap(this);
}
}
2019-02-07 03:38:34 +00:00
// **************************************************************************
// SerializerGenerator
// **************************************************************************
2019-07-04 21:08:20 +00:00
const BookSerializer bookSerializer = BookSerializer();
2019-04-08 19:02:27 +00:00
class BookEncoder extends Converter<Book, Map> {
const BookEncoder();
@override
Map convert(Book model) => BookSerializer.toMap(model);
}
class BookDecoder extends Converter<Map, Book> {
const BookDecoder();
@override
Book convert(Map map) => BookSerializer.fromMap(map);
}
class BookSerializer extends Codec<Book, Map> {
const BookSerializer();
@override
get encoder => const BookEncoder();
@override
get decoder => const BookDecoder();
2019-02-07 03:38:34 +00:00
static Book fromMap(Map map) {
2019-07-04 21:08:20 +00:00
return Book(
2019-02-07 03:38:34 +00:00
id: map['id'] as String,
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()))
2019-07-04 21:08:20 +00:00
: null,
author: map['author'] != null
? AuthorSerializer.fromMap(map['author'] as Map)
: null,
partnerAuthor: map['partner_author'] != null
? AuthorSerializer.fromMap(map['partner_author'] as Map)
: null,
name: map['name'] as String);
2019-02-07 03:38:34 +00:00
}
static Map<String, dynamic> toMap(_Book model) {
if (model == null) {
return null;
}
return {
'id': model.id,
2019-07-04 21:08:20 +00:00
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String(),
2019-02-08 03:38:45 +00:00
'author': AuthorSerializer.toMap(model.author),
'partner_author': AuthorSerializer.toMap(model.partnerAuthor),
2019-07-04 21:08:20 +00:00
'name': model.name
2019-02-07 03:38:34 +00:00
};
}
}
abstract class BookFields {
static const List<String> allFields = <String>[
id,
2019-07-04 21:08:20 +00:00
createdAt,
updatedAt,
2019-02-07 03:38:34 +00:00
author,
partnerAuthor,
2019-07-04 21:08:20 +00:00
name
2019-02-07 03:38:34 +00:00
];
static const String id = 'id';
2019-07-04 21:08:20 +00:00
static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at';
2019-02-07 03:38:34 +00:00
static const String author = 'author';
static const String partnerAuthor = 'partner_author';
static const String name = 'name';
}
2019-04-20 18:45:41 +00:00
2019-07-04 21:08:20 +00:00
const AuthorSerializer authorSerializer = AuthorSerializer();
2019-04-20 18:45:41 +00:00
class AuthorEncoder extends Converter<Author, Map> {
const AuthorEncoder();
@override
Map convert(Author model) => AuthorSerializer.toMap(model);
}
class AuthorDecoder extends Converter<Map, Author> {
const AuthorDecoder();
@override
Author convert(Map map) => AuthorSerializer.fromMap(map);
}
class AuthorSerializer extends Codec<Author, Map> {
const AuthorSerializer();
@override
get encoder => const AuthorEncoder();
@override
get decoder => const AuthorDecoder();
static Author fromMap(Map map) {
2019-07-04 21:08:20 +00:00
return Author(
2019-04-20 18:45:41 +00:00
id: map['id'] as String,
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()))
2019-07-04 21:08:20 +00:00
: null,
name: map['name'] as String ?? 'Tobe Osakwe');
2019-04-20 18:45:41 +00:00
}
static Map<String, dynamic> toMap(_Author model) {
if (model == null) {
return null;
}
return {
'id': model.id,
'created_at': model.createdAt?.toIso8601String(),
2019-07-04 21:08:20 +00:00
'updated_at': model.updatedAt?.toIso8601String(),
'name': model.name
2019-04-20 18:45:41 +00:00
};
}
}
abstract class AuthorFields {
static const List<String> allFields = <String>[
id,
createdAt,
2019-07-04 21:08:20 +00:00
updatedAt,
name
2019-04-20 18:45:41 +00:00
];
static const String id = 'id';
static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at';
2019-07-04 21:08:20 +00:00
static const String name = 'name';
2019-04-20 18:45:41 +00:00
}