Skip ShimFieldImpl check

This commit is contained in:
Tobe O 2019-07-04 17:08:20 -04:00
parent 76016f2062
commit c2a117396f
12 changed files with 958 additions and 928 deletions

View file

@ -1,3 +1,7 @@
# 2.0.5
* Remove `ShimFieldImpl` check, which broke relations.
*
# 2.0.4 # 2.0.4
* Fix `reviveColumn` and element finding to properly detect all annotations now. * Fix `reviveColumn` and element finding to properly detect all annotations now.

View file

@ -11,12 +11,12 @@ class EmployeeMigration extends Migration {
up(Schema schema) { up(Schema schema) {
schema.create('employees', (table) { schema.create('employees', (table) {
table.serial('id')..primaryKey(); table.serial('id')..primaryKey();
table.varChar('unique_id')..unique(); table.timeStamp('created_at');
table.timeStamp('updated_at');
table.varChar('unique_id');
table.varChar('first_name'); table.varChar('first_name');
table.varChar('last_name'); table.varChar('last_name');
table.declare('salary', ColumnType('decimal')); table.declare('salary', ColumnType('decimal'));
table.timeStamp('created_at');
table.timeStamp('updated_at');
}); });
} }
@ -56,12 +56,12 @@ class EmployeeQuery extends Query<Employee, EmployeeQueryWhere> {
get fields { get fields {
return const [ return const [
'id', 'id',
'created_at',
'updated_at',
'unique_id', 'unique_id',
'first_name', 'first_name',
'last_name', 'last_name',
'salary', 'salary'
'created_at',
'updated_at'
]; ];
} }
@ -78,13 +78,13 @@ class EmployeeQuery extends Query<Employee, EmployeeQueryWhere> {
static Employee parseRow(List row) { static Employee parseRow(List row) {
if (row.every((x) => x == null)) return null; if (row.every((x) => x == null)) return null;
var model = Employee( var model = Employee(
id: row[0].toString(), id: (row[0] as String),
uniqueId: (row[1] as String), createdAt: (row[1] as DateTime),
firstName: (row[2] as String), updatedAt: (row[2] as DateTime),
lastName: (row[3] as String), uniqueId: (row[3] as String),
salary: double.tryParse(row[4].toString()), firstName: (row[4] as String),
createdAt: (row[5] as DateTime), lastName: (row[5] as String),
updatedAt: (row[6] as DateTime)); salary: double.tryParse(row[6].toString()));
return model; return model;
} }
@ -96,15 +96,19 @@ class EmployeeQuery extends Query<Employee, EmployeeQueryWhere> {
class EmployeeQueryWhere extends QueryWhere { class EmployeeQueryWhere extends QueryWhere {
EmployeeQueryWhere(EmployeeQuery query) EmployeeQueryWhere(EmployeeQuery query)
: id = NumericSqlExpressionBuilder<int>(query, 'id'), : id = StringSqlExpressionBuilder(query, 'id'),
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
uniqueId = StringSqlExpressionBuilder(query, 'unique_id'), uniqueId = StringSqlExpressionBuilder(query, 'unique_id'),
firstName = StringSqlExpressionBuilder(query, 'first_name'), firstName = StringSqlExpressionBuilder(query, 'first_name'),
lastName = StringSqlExpressionBuilder(query, 'last_name'), lastName = StringSqlExpressionBuilder(query, 'last_name'),
salary = NumericSqlExpressionBuilder<double>(query, 'salary'), salary = NumericSqlExpressionBuilder<double>(query, 'salary');
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
final NumericSqlExpressionBuilder<int> id; final StringSqlExpressionBuilder id;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
final StringSqlExpressionBuilder uniqueId; final StringSqlExpressionBuilder uniqueId;
@ -114,13 +118,9 @@ class EmployeeQueryWhere extends QueryWhere {
final NumericSqlExpressionBuilder<double> salary; final NumericSqlExpressionBuilder<double> salary;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
@override @override
get expressionBuilders { get expressionBuilders {
return [id, uniqueId, firstName, lastName, salary, createdAt, updatedAt]; return [id, createdAt, updatedAt, uniqueId, firstName, lastName, salary];
} }
} }
@ -135,6 +135,16 @@ class EmployeeQueryValues extends MapQueryValues {
} }
set id(String value) => values['id'] = value; 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;
String get uniqueId { String get uniqueId {
return (values['unique_id'] as String); return (values['unique_id'] as String);
} }
@ -155,23 +165,14 @@ class EmployeeQueryValues extends MapQueryValues {
} }
set salary(double value) => values['salary'] = value.toString(); set salary(double value) => values['salary'] = value.toString();
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;
void copyFrom(Employee model) { void copyFrom(Employee model) {
id = model.id;
createdAt = model.createdAt;
updatedAt = model.updatedAt;
uniqueId = model.uniqueId; uniqueId = model.uniqueId;
firstName = model.firstName; firstName = model.firstName;
lastName = model.lastName; lastName = model.lastName;
salary = model.salary; salary = model.salary;
createdAt = model.createdAt;
updatedAt = model.updatedAt;
} }
} }
@ -183,18 +184,27 @@ class EmployeeQueryValues extends MapQueryValues {
class Employee extends _Employee { class Employee extends _Employee {
Employee( Employee(
{this.id, {this.id,
this.createdAt,
this.updatedAt,
this.uniqueId, this.uniqueId,
this.firstName, this.firstName,
this.lastName, this.lastName,
this.salary, this.salary});
this.createdAt,
this.updatedAt}); /// A unique identifier corresponding to this item.
@override
String id;
/// The time at which this item was created.
@override
DateTime createdAt;
/// The last time at which this item was updated.
@override
DateTime updatedAt;
@override @override
final String id; String uniqueId;
@override
final String uniqueId;
@override @override
final String firstName; final String firstName;
@ -205,50 +215,44 @@ class Employee extends _Employee {
@override @override
final double salary; final double salary;
@override
final DateTime createdAt;
@override
final DateTime updatedAt;
Employee copyWith( Employee copyWith(
{String id, {String id,
DateTime createdAt,
DateTime updatedAt,
String uniqueId, String uniqueId,
String firstName, String firstName,
String lastName, String lastName,
double salary, double salary}) {
DateTime createdAt, return Employee(
DateTime updatedAt}) {
return new Employee(
id: id ?? this.id, id: id ?? this.id,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
uniqueId: uniqueId ?? this.uniqueId, uniqueId: uniqueId ?? this.uniqueId,
firstName: firstName ?? this.firstName, firstName: firstName ?? this.firstName,
lastName: lastName ?? this.lastName, lastName: lastName ?? this.lastName,
salary: salary ?? this.salary, salary: salary ?? this.salary);
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt);
} }
bool operator ==(other) { bool operator ==(other) {
return other is _Employee && return other is _Employee &&
other.id == id && other.id == id &&
other.createdAt == createdAt &&
other.updatedAt == updatedAt &&
other.uniqueId == uniqueId && other.uniqueId == uniqueId &&
other.firstName == firstName && other.firstName == firstName &&
other.lastName == lastName && other.lastName == lastName &&
other.salary == salary && other.salary == salary;
other.createdAt == createdAt &&
other.updatedAt == updatedAt;
} }
@override @override
int get hashCode { int get hashCode {
return hashObjects( return hashObjects(
[id, uniqueId, firstName, lastName, salary, createdAt, updatedAt]); [id, createdAt, updatedAt, uniqueId, firstName, lastName, salary]);
} }
@override @override
String toString() { String toString() {
return "Employee(id=$id, uniqueId=$uniqueId, firstName=$firstName, lastName=$lastName, salary=$salary, createdAt=$createdAt, updatedAt=$updatedAt)"; return "Employee(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, uniqueId=$uniqueId, firstName=$firstName, lastName=$lastName, salary=$salary)";
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
@ -260,7 +264,7 @@ class Employee extends _Employee {
// SerializerGenerator // SerializerGenerator
// ************************************************************************** // **************************************************************************
const EmployeeSerializer employeeSerializer = const EmployeeSerializer(); const EmployeeSerializer employeeSerializer = EmployeeSerializer();
class EmployeeEncoder extends Converter<Employee, Map> { class EmployeeEncoder extends Converter<Employee, Map> {
const EmployeeEncoder(); const EmployeeEncoder();
@ -284,12 +288,8 @@ class EmployeeSerializer extends Codec<Employee, Map> {
@override @override
get decoder => const EmployeeDecoder(); get decoder => const EmployeeDecoder();
static Employee fromMap(Map map) { static Employee fromMap(Map map) {
return new Employee( return Employee(
id: map['id'] as String, id: map['id'] as String,
uniqueId: map['unique_id'] as String,
firstName: map['first_name'] as String,
lastName: map['last_name'] as String,
salary: map['salary'] as double,
createdAt: map['created_at'] != null createdAt: map['created_at'] != null
? (map['created_at'] is DateTime ? (map['created_at'] is DateTime
? (map['created_at'] as DateTime) ? (map['created_at'] as DateTime)
@ -299,7 +299,11 @@ class EmployeeSerializer extends Codec<Employee, Map> {
? (map['updated_at'] is DateTime ? (map['updated_at'] is DateTime
? (map['updated_at'] as DateTime) ? (map['updated_at'] as DateTime)
: DateTime.parse(map['updated_at'].toString())) : DateTime.parse(map['updated_at'].toString()))
: null); : null,
uniqueId: map['unique_id'] as String,
firstName: map['first_name'] as String,
lastName: map['last_name'] as String,
salary: map['salary'] as double);
} }
static Map<String, dynamic> toMap(_Employee model) { static Map<String, dynamic> toMap(_Employee model) {
@ -308,12 +312,12 @@ class EmployeeSerializer extends Codec<Employee, Map> {
} }
return { return {
'id': model.id, 'id': model.id,
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String(),
'unique_id': model.uniqueId, 'unique_id': model.uniqueId,
'first_name': model.firstName, 'first_name': model.firstName,
'last_name': model.lastName, 'last_name': model.lastName,
'salary': model.salary, 'salary': model.salary
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String()
}; };
} }
} }
@ -321,16 +325,20 @@ class EmployeeSerializer extends Codec<Employee, Map> {
abstract class EmployeeFields { abstract class EmployeeFields {
static const List<String> allFields = <String>[ static const List<String> allFields = <String>[
id, id,
createdAt,
updatedAt,
uniqueId, uniqueId,
firstName, firstName,
lastName, lastName,
salary, salary
createdAt,
updatedAt
]; ];
static const String id = 'id'; static const String id = 'id';
static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at';
static const String uniqueId = 'unique_id'; static const String uniqueId = 'unique_id';
static const String firstName = 'first_name'; static const String firstName = 'first_name';
@ -338,8 +346,4 @@ abstract class EmployeeFields {
static const String lastName = 'last_name'; static const String lastName = 'last_name';
static const String salary = 'salary'; static const String salary = 'salary';
static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at';
} }

View file

@ -20,7 +20,8 @@ bool isHasRelation(Relationship r) =>
r.type == RelationshipType.hasOne || r.type == RelationshipType.hasMany; r.type == RelationshipType.hasOne || r.type == RelationshipType.hasMany;
bool isSpecialId(OrmBuildContext ctx, FieldElement field) { bool isSpecialId(OrmBuildContext ctx, FieldElement field) {
return field is ShimFieldImpl && return
// field is ShimFieldImpl &&
field is! RelationFieldImpl && field is! RelationFieldImpl &&
(field.name == 'id' && (field.name == 'id' &&
const TypeChecker.fromRuntime(Model) const TypeChecker.fromRuntime(Model)

View file

@ -11,9 +11,9 @@ class BookMigration extends Migration {
up(Schema schema) { up(Schema schema) {
schema.create('books', (table) { schema.create('books', (table) {
table.serial('id')..primaryKey(); table.serial('id')..primaryKey();
table.varChar('name');
table.timeStamp('created_at'); table.timeStamp('created_at');
table.timeStamp('updated_at'); table.timeStamp('updated_at');
table.varChar('name');
table.integer('author_id').references('authors', 'id'); table.integer('author_id').references('authors', 'id');
table.integer('partner_author_id').references('authors', 'id'); table.integer('partner_author_id').references('authors', 'id');
}); });
@ -30,9 +30,9 @@ class AuthorMigration extends Migration {
up(Schema schema) { up(Schema schema) {
schema.create('authors', (table) { schema.create('authors', (table) {
table.serial('id')..primaryKey(); table.serial('id')..primaryKey();
table.varChar('name', length: 255)..defaultsTo('Tobe Osakwe');
table.timeStamp('created_at'); table.timeStamp('created_at');
table.timeStamp('updated_at'); table.timeStamp('updated_at');
table.varChar('name', length: 255)..defaultsTo('Tobe Osakwe');
}); });
} }
@ -52,10 +52,10 @@ class BookQuery extends Query<Book, BookQueryWhere> {
trampoline.add(tableName); trampoline.add(tableName);
_where = BookQueryWhere(this); _where = BookQueryWhere(this);
leftJoin('authors', 'author_id', 'id', leftJoin('authors', 'author_id', 'id',
additionalFields: const ['id', 'name', 'created_at', 'updated_at'], additionalFields: const ['id', 'created_at', 'updated_at', 'name'],
trampoline: trampoline); trampoline: trampoline);
leftJoin('authors', 'partner_author_id', 'id', leftJoin('authors', 'partner_author_id', 'id',
additionalFields: const ['id', 'name', 'created_at', 'updated_at'], additionalFields: const ['id', 'created_at', 'updated_at', 'name'],
trampoline: trampoline); trampoline: trampoline);
} }
@ -78,11 +78,11 @@ class BookQuery extends Query<Book, BookQueryWhere> {
get fields { get fields {
return const [ return const [
'id', 'id',
'created_at',
'updated_at',
'author_id', 'author_id',
'partner_author_id', 'partner_author_id',
'name', 'name'
'created_at',
'updated_at'
]; ];
} }
@ -100,9 +100,9 @@ class BookQuery extends Query<Book, BookQueryWhere> {
if (row.every((x) => x == null)) return null; if (row.every((x) => x == null)) return null;
var model = Book( var model = Book(
id: row[0].toString(), id: row[0].toString(),
name: (row[3] as String), createdAt: (row[1] as DateTime),
createdAt: (row[4] as DateTime), updatedAt: (row[2] as DateTime),
updatedAt: (row[5] as DateTime)); name: (row[5] as String));
if (row.length > 6) { if (row.length > 6) {
model = model.copyWith( model = model.copyWith(
author: AuthorQuery.parseRow(row.skip(6).take(4).toList())); author: AuthorQuery.parseRow(row.skip(6).take(4).toList()));
@ -123,28 +123,28 @@ class BookQuery extends Query<Book, BookQueryWhere> {
class BookQueryWhere extends QueryWhere { class BookQueryWhere extends QueryWhere {
BookQueryWhere(BookQuery query) BookQueryWhere(BookQuery query)
: id = NumericSqlExpressionBuilder<int>(query, 'id'), : id = NumericSqlExpressionBuilder<int>(query, 'id'),
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
authorId = NumericSqlExpressionBuilder<int>(query, 'author_id'), authorId = NumericSqlExpressionBuilder<int>(query, 'author_id'),
partnerAuthorId = partnerAuthorId =
NumericSqlExpressionBuilder<int>(query, 'partner_author_id'), NumericSqlExpressionBuilder<int>(query, 'partner_author_id'),
name = StringSqlExpressionBuilder(query, 'name'), name = StringSqlExpressionBuilder(query, 'name');
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
final NumericSqlExpressionBuilder<int> id; final NumericSqlExpressionBuilder<int> id;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
final NumericSqlExpressionBuilder<int> authorId; final NumericSqlExpressionBuilder<int> authorId;
final NumericSqlExpressionBuilder<int> partnerAuthorId; final NumericSqlExpressionBuilder<int> partnerAuthorId;
final StringSqlExpressionBuilder name; final StringSqlExpressionBuilder name;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
@override @override
get expressionBuilders { get expressionBuilders {
return [id, authorId, partnerAuthorId, name, createdAt, updatedAt]; return [id, createdAt, updatedAt, authorId, partnerAuthorId, name];
} }
} }
@ -159,6 +159,16 @@ class BookQueryValues extends MapQueryValues {
} }
set id(String value) => values['id'] = value; 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;
int get authorId { int get authorId {
return (values['author_id'] as int); return (values['author_id'] as int);
} }
@ -174,20 +184,10 @@ class BookQueryValues extends MapQueryValues {
} }
set name(String value) => values['name'] = value; set name(String value) => values['name'] = 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;
void copyFrom(Book model) { void copyFrom(Book model) {
name = model.name;
createdAt = model.createdAt; createdAt = model.createdAt;
updatedAt = model.updatedAt; updatedAt = model.updatedAt;
name = model.name;
if (model.author != null) { if (model.author != null) {
values['author_id'] = model.author.id; values['author_id'] = model.author.id;
} }
@ -221,7 +221,7 @@ class AuthorQuery extends Query<Author, AuthorQueryWhere> {
@override @override
get fields { get fields {
return const ['id', 'name', 'created_at', 'updated_at']; return const ['id', 'created_at', 'updated_at', 'name'];
} }
@override @override
@ -238,9 +238,9 @@ class AuthorQuery extends Query<Author, AuthorQueryWhere> {
if (row.every((x) => x == null)) return null; if (row.every((x) => x == null)) return null;
var model = Author( var model = Author(
id: row[0].toString(), id: row[0].toString(),
name: (row[1] as String), createdAt: (row[1] as DateTime),
createdAt: (row[2] as DateTime), updatedAt: (row[2] as DateTime),
updatedAt: (row[3] as DateTime)); name: (row[3] as String));
return model; return model;
} }
@ -253,21 +253,21 @@ class AuthorQuery extends Query<Author, AuthorQueryWhere> {
class AuthorQueryWhere extends QueryWhere { class AuthorQueryWhere extends QueryWhere {
AuthorQueryWhere(AuthorQuery query) AuthorQueryWhere(AuthorQuery query)
: id = NumericSqlExpressionBuilder<int>(query, 'id'), : id = NumericSqlExpressionBuilder<int>(query, 'id'),
name = StringSqlExpressionBuilder(query, 'name'),
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'); updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
name = StringSqlExpressionBuilder(query, 'name');
final NumericSqlExpressionBuilder<int> id; final NumericSqlExpressionBuilder<int> id;
final StringSqlExpressionBuilder name;
final DateTimeSqlExpressionBuilder createdAt; final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt; final DateTimeSqlExpressionBuilder updatedAt;
final StringSqlExpressionBuilder name;
@override @override
get expressionBuilders { get expressionBuilders {
return [id, name, createdAt, updatedAt]; return [id, createdAt, updatedAt, name];
} }
} }
@ -282,11 +282,6 @@ class AuthorQueryValues extends MapQueryValues {
} }
set id(String value) => values['id'] = value; set id(String value) => values['id'] = value;
String get name {
return (values['name'] as String);
}
set name(String value) => values['name'] = value;
DateTime get createdAt { DateTime get createdAt {
return (values['created_at'] as DateTime); return (values['created_at'] as DateTime);
} }
@ -297,10 +292,15 @@ class AuthorQueryValues extends MapQueryValues {
} }
set updatedAt(DateTime value) => values['updated_at'] = value; set updatedAt(DateTime value) => values['updated_at'] = value;
String get name {
return (values['name'] as String);
}
set name(String value) => values['name'] = value;
void copyFrom(Author model) { void copyFrom(Author model) {
name = model.name;
createdAt = model.createdAt; createdAt = model.createdAt;
updatedAt = model.updatedAt; updatedAt = model.updatedAt;
name = model.name;
} }
} }
@ -312,64 +312,67 @@ class AuthorQueryValues extends MapQueryValues {
class Book extends _Book { class Book extends _Book {
Book( Book(
{this.id, {this.id,
this.createdAt,
this.updatedAt,
this.author, this.author,
this.partnerAuthor, this.partnerAuthor,
this.name, this.name});
this.createdAt,
this.updatedAt}); /// A unique identifier corresponding to this item.
@override
String id;
/// The time at which this item was created.
@override
DateTime createdAt;
/// The last time at which this item was updated.
@override
DateTime updatedAt;
@override @override
final String id; _Author author;
@override @override
final _Author author; _Author partnerAuthor;
@override @override
final _Author partnerAuthor; String name;
@override
final String name;
@override
final DateTime createdAt;
@override
final DateTime updatedAt;
Book copyWith( Book copyWith(
{String id, {String id,
DateTime createdAt,
DateTime updatedAt,
_Author author, _Author author,
_Author partnerAuthor, _Author partnerAuthor,
String name, String name}) {
DateTime createdAt, return Book(
DateTime updatedAt}) {
return new Book(
id: id ?? this.id, id: id ?? this.id,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
author: author ?? this.author, author: author ?? this.author,
partnerAuthor: partnerAuthor ?? this.partnerAuthor, partnerAuthor: partnerAuthor ?? this.partnerAuthor,
name: name ?? this.name, name: name ?? this.name);
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt);
} }
bool operator ==(other) { bool operator ==(other) {
return other is _Book && return other is _Book &&
other.id == id && other.id == id &&
other.createdAt == createdAt &&
other.updatedAt == updatedAt &&
other.author == author && other.author == author &&
other.partnerAuthor == partnerAuthor && other.partnerAuthor == partnerAuthor &&
other.name == name && other.name == name;
other.createdAt == createdAt &&
other.updatedAt == updatedAt;
} }
@override @override
int get hashCode { int get hashCode {
return hashObjects([id, author, partnerAuthor, name, createdAt, updatedAt]); return hashObjects([id, createdAt, updatedAt, author, partnerAuthor, name]);
} }
@override @override
String toString() { String toString() {
return "Book(id=$id, author=$author, partnerAuthor=$partnerAuthor, name=$name, createdAt=$createdAt, updatedAt=$updatedAt)"; return "Book(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, author=$author, partnerAuthor=$partnerAuthor, name=$name)";
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
@ -379,45 +382,48 @@ class Book extends _Book {
@generatedSerializable @generatedSerializable
class Author extends _Author { class Author extends _Author {
Author({this.id, this.name = 'Tobe Osakwe', this.createdAt, this.updatedAt}); Author({this.id, this.createdAt, this.updatedAt, this.name = 'Tobe Osakwe'});
/// A unique identifier corresponding to this item.
@override @override
final String id; String id;
/// The time at which this item was created.
@override
DateTime createdAt;
/// The last time at which this item was updated.
@override
DateTime updatedAt;
@override @override
final String name; final String name;
@override
final DateTime createdAt;
@override
final DateTime updatedAt;
Author copyWith( Author copyWith(
{String id, String name, DateTime createdAt, DateTime updatedAt}) { {String id, DateTime createdAt, DateTime updatedAt, String name}) {
return new Author( return Author(
id: id ?? this.id, id: id ?? this.id,
name: name ?? this.name,
createdAt: createdAt ?? this.createdAt, createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt); updatedAt: updatedAt ?? this.updatedAt,
name: name ?? this.name);
} }
bool operator ==(other) { bool operator ==(other) {
return other is _Author && return other is _Author &&
other.id == id && other.id == id &&
other.name == name &&
other.createdAt == createdAt && other.createdAt == createdAt &&
other.updatedAt == updatedAt; other.updatedAt == updatedAt &&
other.name == name;
} }
@override @override
int get hashCode { int get hashCode {
return hashObjects([id, name, createdAt, updatedAt]); return hashObjects([id, createdAt, updatedAt, name]);
} }
@override @override
String toString() { String toString() {
return "Author(id=$id, name=$name, createdAt=$createdAt, updatedAt=$updatedAt)"; return "Author(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, name=$name)";
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
@ -429,7 +435,7 @@ class Author extends _Author {
// SerializerGenerator // SerializerGenerator
// ************************************************************************** // **************************************************************************
const BookSerializer bookSerializer = const BookSerializer(); const BookSerializer bookSerializer = BookSerializer();
class BookEncoder extends Converter<Book, Map> { class BookEncoder extends Converter<Book, Map> {
const BookEncoder(); const BookEncoder();
@ -453,15 +459,8 @@ class BookSerializer extends Codec<Book, Map> {
@override @override
get decoder => const BookDecoder(); get decoder => const BookDecoder();
static Book fromMap(Map map) { static Book fromMap(Map map) {
return new Book( return Book(
id: map['id'] as String, id: map['id'] as String,
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,
createdAt: map['created_at'] != null createdAt: map['created_at'] != null
? (map['created_at'] is DateTime ? (map['created_at'] is DateTime
? (map['created_at'] as DateTime) ? (map['created_at'] as DateTime)
@ -471,7 +470,14 @@ class BookSerializer extends Codec<Book, Map> {
? (map['updated_at'] is DateTime ? (map['updated_at'] is DateTime
? (map['updated_at'] as DateTime) ? (map['updated_at'] as DateTime)
: DateTime.parse(map['updated_at'].toString())) : DateTime.parse(map['updated_at'].toString()))
: null); : 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);
} }
static Map<String, dynamic> toMap(_Book model) { static Map<String, dynamic> toMap(_Book model) {
@ -480,11 +486,11 @@ class BookSerializer extends Codec<Book, Map> {
} }
return { return {
'id': model.id, 'id': model.id,
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String(),
'author': AuthorSerializer.toMap(model.author), 'author': AuthorSerializer.toMap(model.author),
'partner_author': AuthorSerializer.toMap(model.partnerAuthor), 'partner_author': AuthorSerializer.toMap(model.partnerAuthor),
'name': model.name, 'name': model.name
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String()
}; };
} }
} }
@ -492,27 +498,27 @@ class BookSerializer extends Codec<Book, Map> {
abstract class BookFields { abstract class BookFields {
static const List<String> allFields = <String>[ static const List<String> allFields = <String>[
id, id,
createdAt,
updatedAt,
author, author,
partnerAuthor, partnerAuthor,
name, name
createdAt,
updatedAt
]; ];
static const String id = 'id'; static const String id = 'id';
static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at';
static const String author = 'author'; static const String author = 'author';
static const String partnerAuthor = 'partner_author'; static const String partnerAuthor = 'partner_author';
static const String name = 'name'; static const String name = 'name';
static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at';
} }
const AuthorSerializer authorSerializer = const AuthorSerializer(); const AuthorSerializer authorSerializer = AuthorSerializer();
class AuthorEncoder extends Converter<Author, Map> { class AuthorEncoder extends Converter<Author, Map> {
const AuthorEncoder(); const AuthorEncoder();
@ -536,9 +542,8 @@ class AuthorSerializer extends Codec<Author, Map> {
@override @override
get decoder => const AuthorDecoder(); get decoder => const AuthorDecoder();
static Author fromMap(Map map) { static Author fromMap(Map map) {
return new Author( return Author(
id: map['id'] as String, id: map['id'] as String,
name: map['name'] as String ?? 'Tobe Osakwe',
createdAt: map['created_at'] != null createdAt: map['created_at'] != null
? (map['created_at'] is DateTime ? (map['created_at'] is DateTime
? (map['created_at'] as DateTime) ? (map['created_at'] as DateTime)
@ -548,7 +553,8 @@ class AuthorSerializer extends Codec<Author, Map> {
? (map['updated_at'] is DateTime ? (map['updated_at'] is DateTime
? (map['updated_at'] as DateTime) ? (map['updated_at'] as DateTime)
: DateTime.parse(map['updated_at'].toString())) : DateTime.parse(map['updated_at'].toString()))
: null); : null,
name: map['name'] as String ?? 'Tobe Osakwe');
} }
static Map<String, dynamic> toMap(_Author model) { static Map<String, dynamic> toMap(_Author model) {
@ -557,9 +563,9 @@ class AuthorSerializer extends Codec<Author, Map> {
} }
return { return {
'id': model.id, 'id': model.id,
'name': model.name,
'created_at': model.createdAt?.toIso8601String(), 'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String() 'updated_at': model.updatedAt?.toIso8601String(),
'name': model.name
}; };
} }
} }
@ -567,16 +573,16 @@ class AuthorSerializer extends Codec<Author, Map> {
abstract class AuthorFields { abstract class AuthorFields {
static const List<String> allFields = <String>[ static const List<String> allFields = <String>[
id, id,
name,
createdAt, createdAt,
updatedAt updatedAt,
name
]; ];
static const String id = 'id'; static const String id = 'id';
static const String name = 'name';
static const String createdAt = 'created_at'; static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at'; static const String updatedAt = 'updated_at';
static const String name = 'name';
} }

View file

@ -11,12 +11,12 @@ class CarMigration extends Migration {
up(Schema schema) { up(Schema schema) {
schema.create('cars', (table) { schema.create('cars', (table) {
table.serial('id')..primaryKey(); table.serial('id')..primaryKey();
table.timeStamp('created_at');
table.timeStamp('updated_at');
table.varChar('make'); table.varChar('make');
table.varChar('description'); table.varChar('description');
table.boolean('family_friendly'); table.boolean('family_friendly');
table.timeStamp('recalled_at'); table.timeStamp('recalled_at');
table.timeStamp('created_at');
table.timeStamp('updated_at');
}); });
} }
@ -56,12 +56,12 @@ class CarQuery extends Query<Car, CarQueryWhere> {
get fields { get fields {
return const [ return const [
'id', 'id',
'created_at',
'updated_at',
'make', 'make',
'description', 'description',
'family_friendly', 'family_friendly',
'recalled_at', 'recalled_at'
'created_at',
'updated_at'
]; ];
} }
@ -79,12 +79,12 @@ class CarQuery extends Query<Car, CarQueryWhere> {
if (row.every((x) => x == null)) return null; if (row.every((x) => x == null)) return null;
var model = Car( var model = Car(
id: row[0].toString(), id: row[0].toString(),
make: (row[1] as String), createdAt: (row[1] as DateTime),
description: (row[2] as String), updatedAt: (row[2] as DateTime),
familyFriendly: (row[3] as bool), make: (row[3] as String),
recalledAt: (row[4] as DateTime), description: (row[4] as String),
createdAt: (row[5] as DateTime), familyFriendly: (row[5] as bool),
updatedAt: (row[6] as DateTime)); recalledAt: (row[6] as DateTime));
return model; return model;
} }
@ -97,15 +97,19 @@ class CarQuery extends Query<Car, CarQueryWhere> {
class CarQueryWhere extends QueryWhere { class CarQueryWhere extends QueryWhere {
CarQueryWhere(CarQuery query) CarQueryWhere(CarQuery query)
: id = NumericSqlExpressionBuilder<int>(query, 'id'), : id = NumericSqlExpressionBuilder<int>(query, 'id'),
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
make = StringSqlExpressionBuilder(query, 'make'), make = StringSqlExpressionBuilder(query, 'make'),
description = StringSqlExpressionBuilder(query, 'description'), description = StringSqlExpressionBuilder(query, 'description'),
familyFriendly = BooleanSqlExpressionBuilder(query, 'family_friendly'), familyFriendly = BooleanSqlExpressionBuilder(query, 'family_friendly'),
recalledAt = DateTimeSqlExpressionBuilder(query, 'recalled_at'), recalledAt = DateTimeSqlExpressionBuilder(query, 'recalled_at');
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
final NumericSqlExpressionBuilder<int> id; final NumericSqlExpressionBuilder<int> id;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
final StringSqlExpressionBuilder make; final StringSqlExpressionBuilder make;
final StringSqlExpressionBuilder description; final StringSqlExpressionBuilder description;
@ -114,20 +118,16 @@ class CarQueryWhere extends QueryWhere {
final DateTimeSqlExpressionBuilder recalledAt; final DateTimeSqlExpressionBuilder recalledAt;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
@override @override
get expressionBuilders { get expressionBuilders {
return [ return [
id, id,
createdAt,
updatedAt,
make, make,
description, description,
familyFriendly, familyFriendly,
recalledAt, recalledAt
createdAt,
updatedAt
]; ];
} }
} }
@ -143,6 +143,16 @@ class CarQueryValues extends MapQueryValues {
} }
set id(String value) => values['id'] = value; 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;
String get make { String get make {
return (values['make'] as String); return (values['make'] as String);
} }
@ -163,23 +173,13 @@ class CarQueryValues extends MapQueryValues {
} }
set recalledAt(DateTime value) => values['recalled_at'] = value; set recalledAt(DateTime value) => values['recalled_at'] = 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;
void copyFrom(Car model) { void copyFrom(Car model) {
createdAt = model.createdAt;
updatedAt = model.updatedAt;
make = model.make; make = model.make;
description = model.description; description = model.description;
familyFriendly = model.familyFriendly; familyFriendly = model.familyFriendly;
recalledAt = model.recalledAt; recalledAt = model.recalledAt;
createdAt = model.createdAt;
updatedAt = model.updatedAt;
} }
} }
@ -191,79 +191,82 @@ class CarQueryValues extends MapQueryValues {
class Car extends _Car { class Car extends _Car {
Car( Car(
{this.id, {this.id,
this.createdAt,
this.updatedAt,
this.make, this.make,
this.description, this.description,
this.familyFriendly, this.familyFriendly,
this.recalledAt, this.recalledAt});
this.createdAt,
this.updatedAt}); /// A unique identifier corresponding to this item.
@override
String id;
/// The time at which this item was created.
@override
DateTime createdAt;
/// The last time at which this item was updated.
@override
DateTime updatedAt;
@override @override
final String id; String make;
@override @override
final String make; String description;
@override @override
final String description; bool familyFriendly;
@override @override
final bool familyFriendly; DateTime recalledAt;
@override
final DateTime recalledAt;
@override
final DateTime createdAt;
@override
final DateTime updatedAt;
Car copyWith( Car copyWith(
{String id, {String id,
DateTime createdAt,
DateTime updatedAt,
String make, String make,
String description, String description,
bool familyFriendly, bool familyFriendly,
DateTime recalledAt, DateTime recalledAt}) {
DateTime createdAt, return Car(
DateTime updatedAt}) {
return new Car(
id: id ?? this.id, id: id ?? this.id,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
make: make ?? this.make, make: make ?? this.make,
description: description ?? this.description, description: description ?? this.description,
familyFriendly: familyFriendly ?? this.familyFriendly, familyFriendly: familyFriendly ?? this.familyFriendly,
recalledAt: recalledAt ?? this.recalledAt, recalledAt: recalledAt ?? this.recalledAt);
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt);
} }
bool operator ==(other) { bool operator ==(other) {
return other is _Car && return other is _Car &&
other.id == id && other.id == id &&
other.createdAt == createdAt &&
other.updatedAt == updatedAt &&
other.make == make && other.make == make &&
other.description == description && other.description == description &&
other.familyFriendly == familyFriendly && other.familyFriendly == familyFriendly &&
other.recalledAt == recalledAt && other.recalledAt == recalledAt;
other.createdAt == createdAt &&
other.updatedAt == updatedAt;
} }
@override @override
int get hashCode { int get hashCode {
return hashObjects([ return hashObjects([
id, id,
createdAt,
updatedAt,
make, make,
description, description,
familyFriendly, familyFriendly,
recalledAt, recalledAt
createdAt,
updatedAt
]); ]);
} }
@override @override
String toString() { String toString() {
return "Car(id=$id, make=$make, description=$description, familyFriendly=$familyFriendly, recalledAt=$recalledAt, createdAt=$createdAt, updatedAt=$updatedAt)"; return "Car(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, make=$make, description=$description, familyFriendly=$familyFriendly, recalledAt=$recalledAt)";
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
@ -275,7 +278,7 @@ class Car extends _Car {
// SerializerGenerator // SerializerGenerator
// ************************************************************************** // **************************************************************************
const CarSerializer carSerializer = const CarSerializer(); const CarSerializer carSerializer = CarSerializer();
class CarEncoder extends Converter<Car, Map> { class CarEncoder extends Converter<Car, Map> {
const CarEncoder(); const CarEncoder();
@ -299,16 +302,8 @@ class CarSerializer extends Codec<Car, Map> {
@override @override
get decoder => const CarDecoder(); get decoder => const CarDecoder();
static Car fromMap(Map map) { static Car fromMap(Map map) {
return new Car( return Car(
id: map['id'] as String, id: map['id'] as String,
make: map['make'] as String,
description: map['description'] as String,
familyFriendly: map['family_friendly'] as bool,
recalledAt: map['recalled_at'] != null
? (map['recalled_at'] is DateTime
? (map['recalled_at'] as DateTime)
: DateTime.parse(map['recalled_at'].toString()))
: null,
createdAt: map['created_at'] != null createdAt: map['created_at'] != null
? (map['created_at'] is DateTime ? (map['created_at'] is DateTime
? (map['created_at'] as DateTime) ? (map['created_at'] as DateTime)
@ -318,6 +313,14 @@ class CarSerializer extends Codec<Car, Map> {
? (map['updated_at'] is DateTime ? (map['updated_at'] is DateTime
? (map['updated_at'] as DateTime) ? (map['updated_at'] as DateTime)
: DateTime.parse(map['updated_at'].toString())) : DateTime.parse(map['updated_at'].toString()))
: null,
make: map['make'] as String,
description: map['description'] as String,
familyFriendly: map['family_friendly'] as bool,
recalledAt: map['recalled_at'] != null
? (map['recalled_at'] is DateTime
? (map['recalled_at'] as DateTime)
: DateTime.parse(map['recalled_at'].toString()))
: null); : null);
} }
@ -327,12 +330,12 @@ class CarSerializer extends Codec<Car, Map> {
} }
return { return {
'id': model.id, 'id': model.id,
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String(),
'make': model.make, 'make': model.make,
'description': model.description, 'description': model.description,
'family_friendly': model.familyFriendly, 'family_friendly': model.familyFriendly,
'recalled_at': model.recalledAt?.toIso8601String(), 'recalled_at': model.recalledAt?.toIso8601String()
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String()
}; };
} }
} }
@ -340,16 +343,20 @@ class CarSerializer extends Codec<Car, Map> {
abstract class CarFields { abstract class CarFields {
static const List<String> allFields = <String>[ static const List<String> allFields = <String>[
id, id,
createdAt,
updatedAt,
make, make,
description, description,
familyFriendly, familyFriendly,
recalledAt, recalledAt
createdAt,
updatedAt
]; ];
static const String id = 'id'; static const String id = 'id';
static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at';
static const String make = 'make'; static const String make = 'make';
static const String description = 'description'; static const String description = 'description';
@ -357,8 +364,4 @@ abstract class CarFields {
static const String familyFriendly = 'family_friendly'; static const String familyFriendly = 'family_friendly';
static const String recalledAt = 'recalled_at'; static const String recalledAt = 'recalled_at';
static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at';
} }

View file

@ -11,9 +11,9 @@ class HasCarMigration extends Migration {
up(Schema schema) { up(Schema schema) {
schema.create('has_cars', (table) { schema.create('has_cars', (table) {
table.serial('id')..primaryKey(); table.serial('id')..primaryKey();
table.integer('type');
table.timeStamp('created_at'); table.timeStamp('created_at');
table.timeStamp('updated_at'); table.timeStamp('updated_at');
table.integer('type');
}); });
} }
@ -51,7 +51,7 @@ class HasCarQuery extends Query<HasCar, HasCarQueryWhere> {
@override @override
get fields { get fields {
return const ['id', 'type', 'created_at', 'updated_at']; return const ['id', 'created_at', 'updated_at', 'type'];
} }
@override @override
@ -68,9 +68,9 @@ class HasCarQuery extends Query<HasCar, HasCarQueryWhere> {
if (row.every((x) => x == null)) return null; if (row.every((x) => x == null)) return null;
var model = HasCar( var model = HasCar(
id: row[0].toString(), id: row[0].toString(),
type: row[1] == null ? null : CarType.values[(row[1] as int)], createdAt: (row[1] as DateTime),
createdAt: (row[2] as DateTime), updatedAt: (row[2] as DateTime),
updatedAt: (row[3] as DateTime)); type: row[3] == null ? null : CarType.values[(row[3] as int)]);
return model; return model;
} }
@ -83,21 +83,21 @@ class HasCarQuery extends Query<HasCar, HasCarQueryWhere> {
class HasCarQueryWhere extends QueryWhere { class HasCarQueryWhere extends QueryWhere {
HasCarQueryWhere(HasCarQuery query) HasCarQueryWhere(HasCarQuery query)
: id = NumericSqlExpressionBuilder<int>(query, 'id'), : id = NumericSqlExpressionBuilder<int>(query, 'id'),
type = EnumSqlExpressionBuilder<CarType>(query, 'type', (v) => v.index),
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'); updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
type = EnumSqlExpressionBuilder<CarType>(query, 'type', (v) => v.index);
final NumericSqlExpressionBuilder<int> id; final NumericSqlExpressionBuilder<int> id;
final EnumSqlExpressionBuilder<CarType> type;
final DateTimeSqlExpressionBuilder createdAt; final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt; final DateTimeSqlExpressionBuilder updatedAt;
final EnumSqlExpressionBuilder<CarType> type;
@override @override
get expressionBuilders { get expressionBuilders {
return [id, type, createdAt, updatedAt]; return [id, createdAt, updatedAt, type];
} }
} }
@ -112,11 +112,6 @@ class HasCarQueryValues extends MapQueryValues {
} }
set id(String value) => values['id'] = value; set id(String value) => values['id'] = value;
CarType get type {
return CarType.values[(values['type'] as int)];
}
set type(CarType value) => values['type'] = value?.index;
DateTime get createdAt { DateTime get createdAt {
return (values['created_at'] as DateTime); return (values['created_at'] as DateTime);
} }
@ -127,10 +122,15 @@ class HasCarQueryValues extends MapQueryValues {
} }
set updatedAt(DateTime value) => values['updated_at'] = value; set updatedAt(DateTime value) => values['updated_at'] = value;
CarType get type {
return CarType.values[(values['type'] as int)];
}
set type(CarType value) => values['type'] = value?.index;
void copyFrom(HasCar model) { void copyFrom(HasCar model) {
type = model.type;
createdAt = model.createdAt; createdAt = model.createdAt;
updatedAt = model.updatedAt; updatedAt = model.updatedAt;
type = model.type;
} }
} }
@ -140,45 +140,48 @@ class HasCarQueryValues extends MapQueryValues {
@generatedSerializable @generatedSerializable
class HasCar extends _HasCar { class HasCar extends _HasCar {
HasCar({this.id, this.type = CarType.sedan, this.createdAt, this.updatedAt}); HasCar({this.id, this.createdAt, this.updatedAt, this.type = CarType.sedan});
/// A unique identifier corresponding to this item.
@override @override
final String id; String id;
/// The time at which this item was created.
@override
DateTime createdAt;
/// The last time at which this item was updated.
@override
DateTime updatedAt;
@override @override
final CarType type; final CarType type;
@override
final DateTime createdAt;
@override
final DateTime updatedAt;
HasCar copyWith( HasCar copyWith(
{String id, CarType type, DateTime createdAt, DateTime updatedAt}) { {String id, DateTime createdAt, DateTime updatedAt, CarType type}) {
return new HasCar( return HasCar(
id: id ?? this.id, id: id ?? this.id,
type: type ?? this.type,
createdAt: createdAt ?? this.createdAt, createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt); updatedAt: updatedAt ?? this.updatedAt,
type: type ?? this.type);
} }
bool operator ==(other) { bool operator ==(other) {
return other is _HasCar && return other is _HasCar &&
other.id == id && other.id == id &&
other.type == type &&
other.createdAt == createdAt && other.createdAt == createdAt &&
other.updatedAt == updatedAt; other.updatedAt == updatedAt &&
other.type == type;
} }
@override @override
int get hashCode { int get hashCode {
return hashObjects([id, type, createdAt, updatedAt]); return hashObjects([id, createdAt, updatedAt, type]);
} }
@override @override
String toString() { String toString() {
return "HasCar(id=$id, type=$type, createdAt=$createdAt, updatedAt=$updatedAt)"; return "HasCar(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, type=$type)";
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
@ -190,7 +193,7 @@ class HasCar extends _HasCar {
// SerializerGenerator // SerializerGenerator
// ************************************************************************** // **************************************************************************
const HasCarSerializer hasCarSerializer = const HasCarSerializer(); const HasCarSerializer hasCarSerializer = HasCarSerializer();
class HasCarEncoder extends Converter<HasCar, Map> { class HasCarEncoder extends Converter<HasCar, Map> {
const HasCarEncoder(); const HasCarEncoder();
@ -215,16 +218,11 @@ class HasCarSerializer extends Codec<HasCar, Map> {
get decoder => const HasCarDecoder(); get decoder => const HasCarDecoder();
static HasCar fromMap(Map map) { static HasCar fromMap(Map map) {
if (map['type'] == null) { if (map['type'] == null) {
throw new FormatException("Missing required field 'type' on HasCar."); throw FormatException("Missing required field 'type' on HasCar.");
} }
return new HasCar( return HasCar(
id: map['id'] as String, id: map['id'] as String,
type: map['type'] is CarType
? (map['type'] as CarType)
: (map['type'] is int
? CarType.values[map['type'] as int]
: CarType.sedan),
createdAt: map['created_at'] != null createdAt: map['created_at'] != null
? (map['created_at'] is DateTime ? (map['created_at'] is DateTime
? (map['created_at'] as DateTime) ? (map['created_at'] as DateTime)
@ -234,7 +232,12 @@ class HasCarSerializer extends Codec<HasCar, Map> {
? (map['updated_at'] is DateTime ? (map['updated_at'] is DateTime
? (map['updated_at'] as DateTime) ? (map['updated_at'] as DateTime)
: DateTime.parse(map['updated_at'].toString())) : DateTime.parse(map['updated_at'].toString()))
: null); : null,
type: map['type'] is CarType
? (map['type'] as CarType)
: (map['type'] is int
? CarType.values[map['type'] as int]
: CarType.sedan));
} }
static Map<String, dynamic> toMap(_HasCar model) { static Map<String, dynamic> toMap(_HasCar model) {
@ -242,14 +245,14 @@ class HasCarSerializer extends Codec<HasCar, Map> {
return null; return null;
} }
if (model.type == null) { if (model.type == null) {
throw new FormatException("Missing required field 'type' on HasCar."); throw FormatException("Missing required field 'type' on HasCar.");
} }
return { return {
'id': model.id, 'id': model.id,
'type': model.type == null ? null : CarType.values.indexOf(model.type),
'created_at': model.createdAt?.toIso8601String(), 'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String() 'updated_at': model.updatedAt?.toIso8601String(),
'type': model.type == null ? null : CarType.values.indexOf(model.type)
}; };
} }
} }
@ -257,16 +260,16 @@ class HasCarSerializer extends Codec<HasCar, Map> {
abstract class HasCarFields { abstract class HasCarFields {
static const List<String> allFields = <String>[ static const List<String> allFields = <String>[
id, id,
type,
createdAt, createdAt,
updatedAt updatedAt,
type
]; ];
static const String id = 'id'; static const String id = 'id';
static const String type = 'type';
static const String createdAt = 'created_at'; static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at'; static const String updatedAt = 'updated_at';
static const String type = 'type';
} }

View file

@ -119,7 +119,7 @@ class HasMapQueryValues extends MapQueryValues {
@generatedSerializable @generatedSerializable
class HasMap implements _HasMap { class HasMap implements _HasMap {
const HasMap({Map<dynamic, dynamic> this.value, List<dynamic> this.list}); const HasMap({this.value, this.list});
@override @override
final Map<dynamic, dynamic> value; final Map<dynamic, dynamic> value;
@ -128,16 +128,15 @@ class HasMap implements _HasMap {
final List<dynamic> list; final List<dynamic> list;
HasMap copyWith({Map<dynamic, dynamic> value, List<dynamic> list}) { HasMap copyWith({Map<dynamic, dynamic> value, List<dynamic> list}) {
return new HasMap(value: value ?? this.value, list: list ?? this.list); return HasMap(value: value ?? this.value, list: list ?? this.list);
} }
bool operator ==(other) { bool operator ==(other) {
return other is _HasMap && return other is _HasMap &&
const MapEquality<dynamic, dynamic>( MapEquality<dynamic, dynamic>(
keys: const DefaultEquality(), values: const DefaultEquality()) keys: DefaultEquality(), values: DefaultEquality())
.equals(other.value, value) && .equals(other.value, value) &&
const ListEquality<dynamic>(const DefaultEquality()) ListEquality<dynamic>(DefaultEquality()).equals(other.list, list);
.equals(other.list, list);
} }
@override @override
@ -159,7 +158,7 @@ class HasMap implements _HasMap {
// SerializerGenerator // SerializerGenerator
// ************************************************************************** // **************************************************************************
const HasMapSerializer hasMapSerializer = const HasMapSerializer(); const HasMapSerializer hasMapSerializer = HasMapSerializer();
class HasMapEncoder extends Converter<HasMap, Map> { class HasMapEncoder extends Converter<HasMap, Map> {
const HasMapEncoder(); const HasMapEncoder();
@ -183,7 +182,7 @@ class HasMapSerializer extends Codec<HasMap, Map> {
@override @override
get decoder => const HasMapDecoder(); get decoder => const HasMapDecoder();
static HasMap fromMap(Map map) { static HasMap fromMap(Map map) {
return new HasMap( return HasMap(
value: map['value'] is Map value: map['value'] is Map
? (map['value'] as Map).cast<dynamic, dynamic>() ? (map['value'] as Map).cast<dynamic, dynamic>()
: null, : null,

View file

@ -11,9 +11,9 @@ class LegMigration extends Migration {
up(Schema schema) { up(Schema schema) {
schema.create('legs', (table) { schema.create('legs', (table) {
table.serial('id')..primaryKey(); table.serial('id')..primaryKey();
table.varChar('name');
table.timeStamp('created_at'); table.timeStamp('created_at');
table.timeStamp('updated_at'); table.timeStamp('updated_at');
table.varChar('name');
}); });
} }
@ -28,10 +28,10 @@ class FootMigration extends Migration {
up(Schema schema) { up(Schema schema) {
schema.create('feet', (table) { schema.create('feet', (table) {
table.serial('id')..primaryKey(); table.serial('id')..primaryKey();
table.integer('leg_id');
table.declare('n_toes', ColumnType('decimal'));
table.timeStamp('created_at'); table.timeStamp('created_at');
table.timeStamp('updated_at'); table.timeStamp('updated_at');
table.integer('leg_id');
table.declare('n_toes', ColumnType('decimal'));
}); });
} }
@ -53,10 +53,10 @@ class LegQuery extends Query<Leg, LegQueryWhere> {
leftJoin('feet', 'id', 'leg_id', leftJoin('feet', 'id', 'leg_id',
additionalFields: const [ additionalFields: const [
'id', 'id',
'leg_id',
'n_toes',
'created_at', 'created_at',
'updated_at' 'updated_at',
'leg_id',
'n_toes'
], ],
trampoline: trampoline); trampoline: trampoline);
} }
@ -78,7 +78,7 @@ class LegQuery extends Query<Leg, LegQueryWhere> {
@override @override
get fields { get fields {
return const ['id', 'name', 'created_at', 'updated_at']; return const ['id', 'created_at', 'updated_at', 'name'];
} }
@override @override
@ -95,9 +95,9 @@ class LegQuery extends Query<Leg, LegQueryWhere> {
if (row.every((x) => x == null)) return null; if (row.every((x) => x == null)) return null;
var model = Leg( var model = Leg(
id: row[0].toString(), id: row[0].toString(),
name: (row[1] as String), createdAt: (row[1] as DateTime),
createdAt: (row[2] as DateTime), updatedAt: (row[2] as DateTime),
updatedAt: (row[3] as DateTime)); name: (row[3] as String));
if (row.length > 4) { if (row.length > 4) {
model = model.copyWith( model = model.copyWith(
foot: FootQuery.parseRow(row.skip(4).take(5).toList())); foot: FootQuery.parseRow(row.skip(4).take(5).toList()));
@ -114,21 +114,21 @@ class LegQuery extends Query<Leg, LegQueryWhere> {
class LegQueryWhere extends QueryWhere { class LegQueryWhere extends QueryWhere {
LegQueryWhere(LegQuery query) LegQueryWhere(LegQuery query)
: id = NumericSqlExpressionBuilder<int>(query, 'id'), : id = NumericSqlExpressionBuilder<int>(query, 'id'),
name = StringSqlExpressionBuilder(query, 'name'),
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'); updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
name = StringSqlExpressionBuilder(query, 'name');
final NumericSqlExpressionBuilder<int> id; final NumericSqlExpressionBuilder<int> id;
final StringSqlExpressionBuilder name;
final DateTimeSqlExpressionBuilder createdAt; final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt; final DateTimeSqlExpressionBuilder updatedAt;
final StringSqlExpressionBuilder name;
@override @override
get expressionBuilders { get expressionBuilders {
return [id, name, createdAt, updatedAt]; return [id, createdAt, updatedAt, name];
} }
} }
@ -143,11 +143,6 @@ class LegQueryValues extends MapQueryValues {
} }
set id(String value) => values['id'] = value; set id(String value) => values['id'] = value;
String get name {
return (values['name'] as String);
}
set name(String value) => values['name'] = value;
DateTime get createdAt { DateTime get createdAt {
return (values['created_at'] as DateTime); return (values['created_at'] as DateTime);
} }
@ -158,10 +153,15 @@ class LegQueryValues extends MapQueryValues {
} }
set updatedAt(DateTime value) => values['updated_at'] = value; set updatedAt(DateTime value) => values['updated_at'] = value;
String get name {
return (values['name'] as String);
}
set name(String value) => values['name'] = value;
void copyFrom(Leg model) { void copyFrom(Leg model) {
name = model.name;
createdAt = model.createdAt; createdAt = model.createdAt;
updatedAt = model.updatedAt; updatedAt = model.updatedAt;
name = model.name;
} }
} }
@ -189,7 +189,7 @@ class FootQuery extends Query<Foot, FootQueryWhere> {
@override @override
get fields { get fields {
return const ['id', 'leg_id', 'n_toes', 'created_at', 'updated_at']; return const ['id', 'created_at', 'updated_at', 'leg_id', 'n_toes'];
} }
@override @override
@ -206,10 +206,10 @@ class FootQuery extends Query<Foot, FootQueryWhere> {
if (row.every((x) => x == null)) return null; if (row.every((x) => x == null)) return null;
var model = Foot( var model = Foot(
id: row[0].toString(), id: row[0].toString(),
legId: (row[1] as int), createdAt: (row[1] as DateTime),
nToes: double.tryParse(row[2].toString()), updatedAt: (row[2] as DateTime),
createdAt: (row[3] as DateTime), legId: (row[3] as int),
updatedAt: (row[4] as DateTime)); nToes: double.tryParse(row[4].toString()));
return model; return model;
} }
@ -222,24 +222,24 @@ class FootQuery extends Query<Foot, FootQueryWhere> {
class FootQueryWhere extends QueryWhere { class FootQueryWhere extends QueryWhere {
FootQueryWhere(FootQuery query) FootQueryWhere(FootQuery query)
: id = NumericSqlExpressionBuilder<int>(query, 'id'), : id = NumericSqlExpressionBuilder<int>(query, 'id'),
legId = NumericSqlExpressionBuilder<int>(query, 'leg_id'),
nToes = NumericSqlExpressionBuilder<double>(query, 'n_toes'),
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'); updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
legId = NumericSqlExpressionBuilder<int>(query, 'leg_id'),
nToes = NumericSqlExpressionBuilder<double>(query, 'n_toes');
final NumericSqlExpressionBuilder<int> id; final NumericSqlExpressionBuilder<int> id;
final NumericSqlExpressionBuilder<int> legId;
final NumericSqlExpressionBuilder<double> nToes;
final DateTimeSqlExpressionBuilder createdAt; final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt; final DateTimeSqlExpressionBuilder updatedAt;
final NumericSqlExpressionBuilder<int> legId;
final NumericSqlExpressionBuilder<double> nToes;
@override @override
get expressionBuilders { get expressionBuilders {
return [id, legId, nToes, createdAt, updatedAt]; return [id, createdAt, updatedAt, legId, nToes];
} }
} }
@ -254,16 +254,6 @@ class FootQueryValues extends MapQueryValues {
} }
set id(String value) => values['id'] = value; set id(String value) => values['id'] = value;
int get legId {
return (values['leg_id'] as int);
}
set legId(int value) => values['leg_id'] = value;
double get nToes {
return double.tryParse((values['n_toes'] as String));
}
set nToes(double value) => values['n_toes'] = value.toString();
DateTime get createdAt { DateTime get createdAt {
return (values['created_at'] as DateTime); return (values['created_at'] as DateTime);
} }
@ -274,11 +264,21 @@ class FootQueryValues extends MapQueryValues {
} }
set updatedAt(DateTime value) => values['updated_at'] = value; set updatedAt(DateTime value) => values['updated_at'] = value;
int get legId {
return (values['leg_id'] as int);
}
set legId(int value) => values['leg_id'] = value;
double get nToes {
return double.tryParse((values['n_toes'] as String));
}
set nToes(double value) => values['n_toes'] = value.toString();
void copyFrom(Foot model) { void copyFrom(Foot model) {
legId = model.legId;
nToes = model.nToes;
createdAt = model.createdAt; createdAt = model.createdAt;
updatedAt = model.updatedAt; updatedAt = model.updatedAt;
legId = model.legId;
nToes = model.nToes;
} }
} }
@ -288,54 +288,57 @@ class FootQueryValues extends MapQueryValues {
@generatedSerializable @generatedSerializable
class Leg extends _Leg { class Leg extends _Leg {
Leg({this.id, this.foot, this.name, this.createdAt, this.updatedAt}); Leg({this.id, this.createdAt, this.updatedAt, this.foot, this.name});
/// A unique identifier corresponding to this item.
@override
String id;
/// The time at which this item was created.
@override
DateTime createdAt;
/// The last time at which this item was updated.
@override
DateTime updatedAt;
@override @override
final String id; _Foot foot;
@override @override
final _Foot foot; String name;
@override
final String name;
@override
final DateTime createdAt;
@override
final DateTime updatedAt;
Leg copyWith( Leg copyWith(
{String id, {String id,
_Foot foot,
String name,
DateTime createdAt, DateTime createdAt,
DateTime updatedAt}) { DateTime updatedAt,
return new Leg( _Foot foot,
String name}) {
return Leg(
id: id ?? this.id, id: id ?? this.id,
foot: foot ?? this.foot,
name: name ?? this.name,
createdAt: createdAt ?? this.createdAt, createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt); updatedAt: updatedAt ?? this.updatedAt,
foot: foot ?? this.foot,
name: name ?? this.name);
} }
bool operator ==(other) { bool operator ==(other) {
return other is _Leg && return other is _Leg &&
other.id == id && other.id == id &&
other.foot == foot &&
other.name == name &&
other.createdAt == createdAt && other.createdAt == createdAt &&
other.updatedAt == updatedAt; other.updatedAt == updatedAt &&
other.foot == foot &&
other.name == name;
} }
@override @override
int get hashCode { int get hashCode {
return hashObjects([id, foot, name, createdAt, updatedAt]); return hashObjects([id, createdAt, updatedAt, foot, name]);
} }
@override @override
String toString() { String toString() {
return "Leg(id=$id, foot=$foot, name=$name, createdAt=$createdAt, updatedAt=$updatedAt)"; return "Leg(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, foot=$foot, name=$name)";
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
@ -345,54 +348,57 @@ class Leg extends _Leg {
@generatedSerializable @generatedSerializable
class Foot extends _Foot { class Foot extends _Foot {
Foot({this.id, this.legId, this.nToes, this.createdAt, this.updatedAt}); Foot({this.id, this.createdAt, this.updatedAt, this.legId, this.nToes});
/// A unique identifier corresponding to this item.
@override
String id;
/// The time at which this item was created.
@override
DateTime createdAt;
/// The last time at which this item was updated.
@override
DateTime updatedAt;
@override @override
final String id; int legId;
@override @override
final int legId; double nToes;
@override
final double nToes;
@override
final DateTime createdAt;
@override
final DateTime updatedAt;
Foot copyWith( Foot copyWith(
{String id, {String id,
int legId,
double nToes,
DateTime createdAt, DateTime createdAt,
DateTime updatedAt}) { DateTime updatedAt,
return new Foot( int legId,
double nToes}) {
return Foot(
id: id ?? this.id, id: id ?? this.id,
legId: legId ?? this.legId,
nToes: nToes ?? this.nToes,
createdAt: createdAt ?? this.createdAt, createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt); updatedAt: updatedAt ?? this.updatedAt,
legId: legId ?? this.legId,
nToes: nToes ?? this.nToes);
} }
bool operator ==(other) { bool operator ==(other) {
return other is _Foot && return other is _Foot &&
other.id == id && other.id == id &&
other.legId == legId &&
other.nToes == nToes &&
other.createdAt == createdAt && other.createdAt == createdAt &&
other.updatedAt == updatedAt; other.updatedAt == updatedAt &&
other.legId == legId &&
other.nToes == nToes;
} }
@override @override
int get hashCode { int get hashCode {
return hashObjects([id, legId, nToes, createdAt, updatedAt]); return hashObjects([id, createdAt, updatedAt, legId, nToes]);
} }
@override @override
String toString() { String toString() {
return "Foot(id=$id, legId=$legId, nToes=$nToes, createdAt=$createdAt, updatedAt=$updatedAt)"; return "Foot(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, legId=$legId, nToes=$nToes)";
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
@ -404,7 +410,7 @@ class Foot extends _Foot {
// SerializerGenerator // SerializerGenerator
// ************************************************************************** // **************************************************************************
const LegSerializer legSerializer = const LegSerializer(); const LegSerializer legSerializer = LegSerializer();
class LegEncoder extends Converter<Leg, Map> { class LegEncoder extends Converter<Leg, Map> {
const LegEncoder(); const LegEncoder();
@ -428,12 +434,8 @@ class LegSerializer extends Codec<Leg, Map> {
@override @override
get decoder => const LegDecoder(); get decoder => const LegDecoder();
static Leg fromMap(Map map) { static Leg fromMap(Map map) {
return new Leg( return Leg(
id: map['id'] as String, id: map['id'] as String,
foot: map['foot'] != null
? FootSerializer.fromMap(map['foot'] as Map)
: null,
name: map['name'] as String,
createdAt: map['created_at'] != null createdAt: map['created_at'] != null
? (map['created_at'] is DateTime ? (map['created_at'] is DateTime
? (map['created_at'] as DateTime) ? (map['created_at'] as DateTime)
@ -443,7 +445,11 @@ class LegSerializer extends Codec<Leg, Map> {
? (map['updated_at'] is DateTime ? (map['updated_at'] is DateTime
? (map['updated_at'] as DateTime) ? (map['updated_at'] as DateTime)
: DateTime.parse(map['updated_at'].toString())) : DateTime.parse(map['updated_at'].toString()))
: null); : null,
foot: map['foot'] != null
? FootSerializer.fromMap(map['foot'] as Map)
: null,
name: map['name'] as String);
} }
static Map<String, dynamic> toMap(_Leg model) { static Map<String, dynamic> toMap(_Leg model) {
@ -452,10 +458,10 @@ class LegSerializer extends Codec<Leg, Map> {
} }
return { return {
'id': model.id, 'id': model.id,
'foot': FootSerializer.toMap(model.foot),
'name': model.name,
'created_at': model.createdAt?.toIso8601String(), 'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String() 'updated_at': model.updatedAt?.toIso8601String(),
'foot': FootSerializer.toMap(model.foot),
'name': model.name
}; };
} }
} }
@ -463,24 +469,24 @@ class LegSerializer extends Codec<Leg, Map> {
abstract class LegFields { abstract class LegFields {
static const List<String> allFields = <String>[ static const List<String> allFields = <String>[
id, id,
foot,
name,
createdAt, createdAt,
updatedAt updatedAt,
foot,
name
]; ];
static const String id = 'id'; static const String id = 'id';
static const String foot = 'foot';
static const String name = 'name';
static const String createdAt = 'created_at'; static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at'; static const String updatedAt = 'updated_at';
static const String foot = 'foot';
static const String name = 'name';
} }
const FootSerializer footSerializer = const FootSerializer(); const FootSerializer footSerializer = FootSerializer();
class FootEncoder extends Converter<Foot, Map> { class FootEncoder extends Converter<Foot, Map> {
const FootEncoder(); const FootEncoder();
@ -504,10 +510,8 @@ class FootSerializer extends Codec<Foot, Map> {
@override @override
get decoder => const FootDecoder(); get decoder => const FootDecoder();
static Foot fromMap(Map map) { static Foot fromMap(Map map) {
return new Foot( return Foot(
id: map['id'] as String, id: map['id'] as String,
legId: map['leg_id'] as int,
nToes: map['n_toes'] as double,
createdAt: map['created_at'] != null createdAt: map['created_at'] != null
? (map['created_at'] is DateTime ? (map['created_at'] is DateTime
? (map['created_at'] as DateTime) ? (map['created_at'] as DateTime)
@ -517,7 +521,9 @@ class FootSerializer extends Codec<Foot, Map> {
? (map['updated_at'] is DateTime ? (map['updated_at'] is DateTime
? (map['updated_at'] as DateTime) ? (map['updated_at'] as DateTime)
: DateTime.parse(map['updated_at'].toString())) : DateTime.parse(map['updated_at'].toString()))
: null); : null,
legId: map['leg_id'] as int,
nToes: map['n_toes'] as double);
} }
static Map<String, dynamic> toMap(_Foot model) { static Map<String, dynamic> toMap(_Foot model) {
@ -526,10 +532,10 @@ class FootSerializer extends Codec<Foot, Map> {
} }
return { return {
'id': model.id, 'id': model.id,
'leg_id': model.legId,
'n_toes': model.nToes,
'created_at': model.createdAt?.toIso8601String(), 'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String() 'updated_at': model.updatedAt?.toIso8601String(),
'leg_id': model.legId,
'n_toes': model.nToes
}; };
} }
} }
@ -537,19 +543,19 @@ class FootSerializer extends Codec<Foot, Map> {
abstract class FootFields { abstract class FootFields {
static const List<String> allFields = <String>[ static const List<String> allFields = <String>[
id, id,
legId,
nToes,
createdAt, createdAt,
updatedAt updatedAt,
legId,
nToes
]; ];
static const String id = 'id'; static const String id = 'id';
static const String legId = 'leg_id';
static const String nToes = 'n_toes';
static const String createdAt = 'created_at'; static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at'; static const String updatedAt = 'updated_at';
static const String legId = 'leg_id';
static const String nToes = 'n_toes';
} }

View file

@ -11,11 +11,11 @@ class OrderMigration extends Migration {
up(Schema schema) { up(Schema schema) {
schema.create('orders', (table) { schema.create('orders', (table) {
table.serial('id')..primaryKey(); table.serial('id')..primaryKey();
table.timeStamp('created_at');
table.timeStamp('updated_at');
table.integer('employee_id'); table.integer('employee_id');
table.timeStamp('order_date'); table.timeStamp('order_date');
table.integer('shipper_id'); table.integer('shipper_id');
table.timeStamp('created_at');
table.timeStamp('updated_at');
table.integer('customer_id').references('customers', 'id'); table.integer('customer_id').references('customers', 'id');
}); });
} }
@ -75,12 +75,12 @@ class OrderQuery extends Query<Order, OrderQueryWhere> {
get fields { get fields {
return const [ return const [
'id', 'id',
'created_at',
'updated_at',
'customer_id', 'customer_id',
'employee_id', 'employee_id',
'order_date', 'order_date',
'shipper_id', 'shipper_id'
'created_at',
'updated_at'
]; ];
} }
@ -98,11 +98,11 @@ class OrderQuery extends Query<Order, OrderQueryWhere> {
if (row.every((x) => x == null)) return null; if (row.every((x) => x == null)) return null;
var model = Order( var model = Order(
id: row[0].toString(), id: row[0].toString(),
employeeId: (row[2] as int), createdAt: (row[1] as DateTime),
orderDate: (row[3] as DateTime), updatedAt: (row[2] as DateTime),
shipperId: (row[4] as int), employeeId: (row[4] as int),
createdAt: (row[5] as DateTime), orderDate: (row[5] as DateTime),
updatedAt: (row[6] as DateTime)); shipperId: (row[6] as int));
if (row.length > 7) { if (row.length > 7) {
model = model.copyWith( model = model.copyWith(
customer: CustomerQuery.parseRow(row.skip(7).take(3).toList())); customer: CustomerQuery.parseRow(row.skip(7).take(3).toList()));
@ -119,15 +119,19 @@ class OrderQuery extends Query<Order, OrderQueryWhere> {
class OrderQueryWhere extends QueryWhere { class OrderQueryWhere extends QueryWhere {
OrderQueryWhere(OrderQuery query) OrderQueryWhere(OrderQuery query)
: id = NumericSqlExpressionBuilder<int>(query, 'id'), : id = NumericSqlExpressionBuilder<int>(query, 'id'),
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
customerId = NumericSqlExpressionBuilder<int>(query, 'customer_id'), customerId = NumericSqlExpressionBuilder<int>(query, 'customer_id'),
employeeId = NumericSqlExpressionBuilder<int>(query, 'employee_id'), employeeId = NumericSqlExpressionBuilder<int>(query, 'employee_id'),
orderDate = DateTimeSqlExpressionBuilder(query, 'order_date'), orderDate = DateTimeSqlExpressionBuilder(query, 'order_date'),
shipperId = NumericSqlExpressionBuilder<int>(query, 'shipper_id'), shipperId = NumericSqlExpressionBuilder<int>(query, 'shipper_id');
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
final NumericSqlExpressionBuilder<int> id; final NumericSqlExpressionBuilder<int> id;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
final NumericSqlExpressionBuilder<int> customerId; final NumericSqlExpressionBuilder<int> customerId;
final NumericSqlExpressionBuilder<int> employeeId; final NumericSqlExpressionBuilder<int> employeeId;
@ -136,20 +140,16 @@ class OrderQueryWhere extends QueryWhere {
final NumericSqlExpressionBuilder<int> shipperId; final NumericSqlExpressionBuilder<int> shipperId;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
@override @override
get expressionBuilders { get expressionBuilders {
return [ return [
id, id,
createdAt,
updatedAt,
customerId, customerId,
employeeId, employeeId,
orderDate, orderDate,
shipperId, shipperId
createdAt,
updatedAt
]; ];
} }
} }
@ -165,6 +165,16 @@ class OrderQueryValues extends MapQueryValues {
} }
set id(String value) => values['id'] = value; 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;
int get customerId { int get customerId {
return (values['customer_id'] as int); return (values['customer_id'] as int);
} }
@ -185,22 +195,12 @@ class OrderQueryValues extends MapQueryValues {
} }
set shipperId(int value) => values['shipper_id'] = value; set shipperId(int value) => values['shipper_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;
void copyFrom(Order model) { void copyFrom(Order model) {
createdAt = model.createdAt;
updatedAt = model.updatedAt;
employeeId = model.employeeId; employeeId = model.employeeId;
orderDate = model.orderDate; orderDate = model.orderDate;
shipperId = model.shipperId; shipperId = model.shipperId;
createdAt = model.createdAt;
updatedAt = model.updatedAt;
if (model.customer != null) { if (model.customer != null) {
values['customer_id'] = model.customer.id; values['customer_id'] = model.customer.id;
} }
@ -312,15 +312,24 @@ class CustomerQueryValues extends MapQueryValues {
class Order extends _Order { class Order extends _Order {
Order( Order(
{this.id, {this.id,
this.createdAt,
this.updatedAt,
this.customer, this.customer,
this.employeeId, this.employeeId,
this.orderDate, this.orderDate,
this.shipperId, this.shipperId});
this.createdAt,
this.updatedAt});
/// A unique identifier corresponding to this item.
@override @override
final String id; String id;
/// The time at which this item was created.
@override
DateTime createdAt;
/// The last time at which this item was updated.
@override
DateTime updatedAt;
@override @override
final _Customer customer; final _Customer customer;
@ -334,50 +343,44 @@ class Order extends _Order {
@override @override
final int shipperId; final int shipperId;
@override
final DateTime createdAt;
@override
final DateTime updatedAt;
Order copyWith( Order copyWith(
{String id, {String id,
DateTime createdAt,
DateTime updatedAt,
_Customer customer, _Customer customer,
int employeeId, int employeeId,
DateTime orderDate, DateTime orderDate,
int shipperId, int shipperId}) {
DateTime createdAt, return Order(
DateTime updatedAt}) {
return new Order(
id: id ?? this.id, id: id ?? this.id,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
customer: customer ?? this.customer, customer: customer ?? this.customer,
employeeId: employeeId ?? this.employeeId, employeeId: employeeId ?? this.employeeId,
orderDate: orderDate ?? this.orderDate, orderDate: orderDate ?? this.orderDate,
shipperId: shipperId ?? this.shipperId, shipperId: shipperId ?? this.shipperId);
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt);
} }
bool operator ==(other) { bool operator ==(other) {
return other is _Order && return other is _Order &&
other.id == id && other.id == id &&
other.createdAt == createdAt &&
other.updatedAt == updatedAt &&
other.customer == customer && other.customer == customer &&
other.employeeId == employeeId && other.employeeId == employeeId &&
other.orderDate == orderDate && other.orderDate == orderDate &&
other.shipperId == shipperId && other.shipperId == shipperId;
other.createdAt == createdAt &&
other.updatedAt == updatedAt;
} }
@override @override
int get hashCode { int get hashCode {
return hashObjects( return hashObjects(
[id, customer, employeeId, orderDate, shipperId, createdAt, updatedAt]); [id, createdAt, updatedAt, customer, employeeId, orderDate, shipperId]);
} }
@override @override
String toString() { String toString() {
return "Order(id=$id, customer=$customer, employeeId=$employeeId, orderDate=$orderDate, shipperId=$shipperId, createdAt=$createdAt, updatedAt=$updatedAt)"; return "Order(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, customer=$customer, employeeId=$employeeId, orderDate=$orderDate, shipperId=$shipperId)";
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
@ -389,17 +392,20 @@ class Order extends _Order {
class Customer extends _Customer { class Customer extends _Customer {
Customer({this.id, this.createdAt, this.updatedAt}); Customer({this.id, this.createdAt, this.updatedAt});
/// A unique identifier corresponding to this item.
@override @override
final String id; String id;
/// The time at which this item was created.
@override @override
final DateTime createdAt; DateTime createdAt;
/// The last time at which this item was updated.
@override @override
final DateTime updatedAt; DateTime updatedAt;
Customer copyWith({String id, DateTime createdAt, DateTime updatedAt}) { Customer copyWith({String id, DateTime createdAt, DateTime updatedAt}) {
return new Customer( return Customer(
id: id ?? this.id, id: id ?? this.id,
createdAt: createdAt ?? this.createdAt, createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt); updatedAt: updatedAt ?? this.updatedAt);
@ -431,7 +437,7 @@ class Customer extends _Customer {
// SerializerGenerator // SerializerGenerator
// ************************************************************************** // **************************************************************************
const OrderSerializer orderSerializer = const OrderSerializer(); const OrderSerializer orderSerializer = OrderSerializer();
class OrderEncoder extends Converter<Order, Map> { class OrderEncoder extends Converter<Order, Map> {
const OrderEncoder(); const OrderEncoder();
@ -455,18 +461,8 @@ class OrderSerializer extends Codec<Order, Map> {
@override @override
get decoder => const OrderDecoder(); get decoder => const OrderDecoder();
static Order fromMap(Map map) { static Order fromMap(Map map) {
return new Order( return Order(
id: map['id'] as String, id: map['id'] as String,
customer: map['customer'] != null
? CustomerSerializer.fromMap(map['customer'] as Map)
: null,
employeeId: map['employee_id'] as int,
orderDate: map['order_date'] != null
? (map['order_date'] is DateTime
? (map['order_date'] as DateTime)
: DateTime.parse(map['order_date'].toString()))
: null,
shipperId: map['shipper_id'] as int,
createdAt: map['created_at'] != null createdAt: map['created_at'] != null
? (map['created_at'] is DateTime ? (map['created_at'] is DateTime
? (map['created_at'] as DateTime) ? (map['created_at'] as DateTime)
@ -476,7 +472,17 @@ class OrderSerializer extends Codec<Order, Map> {
? (map['updated_at'] is DateTime ? (map['updated_at'] is DateTime
? (map['updated_at'] as DateTime) ? (map['updated_at'] as DateTime)
: DateTime.parse(map['updated_at'].toString())) : DateTime.parse(map['updated_at'].toString()))
: null); : null,
customer: map['customer'] != null
? CustomerSerializer.fromMap(map['customer'] as Map)
: null,
employeeId: map['employee_id'] as int,
orderDate: map['order_date'] != null
? (map['order_date'] is DateTime
? (map['order_date'] as DateTime)
: DateTime.parse(map['order_date'].toString()))
: null,
shipperId: map['shipper_id'] as int);
} }
static Map<String, dynamic> toMap(_Order model) { static Map<String, dynamic> toMap(_Order model) {
@ -485,12 +491,12 @@ class OrderSerializer extends Codec<Order, Map> {
} }
return { return {
'id': model.id, 'id': model.id,
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String(),
'customer': CustomerSerializer.toMap(model.customer), 'customer': CustomerSerializer.toMap(model.customer),
'employee_id': model.employeeId, 'employee_id': model.employeeId,
'order_date': model.orderDate?.toIso8601String(), 'order_date': model.orderDate?.toIso8601String(),
'shipper_id': model.shipperId, 'shipper_id': model.shipperId
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String()
}; };
} }
} }
@ -498,16 +504,20 @@ class OrderSerializer extends Codec<Order, Map> {
abstract class OrderFields { abstract class OrderFields {
static const List<String> allFields = <String>[ static const List<String> allFields = <String>[
id, id,
createdAt,
updatedAt,
customer, customer,
employeeId, employeeId,
orderDate, orderDate,
shipperId, shipperId
createdAt,
updatedAt
]; ];
static const String id = 'id'; static const String id = 'id';
static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at';
static const String customer = 'customer'; static const String customer = 'customer';
static const String employeeId = 'employee_id'; static const String employeeId = 'employee_id';
@ -515,13 +525,9 @@ abstract class OrderFields {
static const String orderDate = 'order_date'; static const String orderDate = 'order_date';
static const String shipperId = 'shipper_id'; static const String shipperId = 'shipper_id';
static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at';
} }
const CustomerSerializer customerSerializer = const CustomerSerializer(); const CustomerSerializer customerSerializer = CustomerSerializer();
class CustomerEncoder extends Converter<Customer, Map> { class CustomerEncoder extends Converter<Customer, Map> {
const CustomerEncoder(); const CustomerEncoder();
@ -545,7 +551,7 @@ class CustomerSerializer extends Codec<Customer, Map> {
@override @override
get decoder => const CustomerDecoder(); get decoder => const CustomerDecoder();
static Customer fromMap(Map map) { static Customer fromMap(Map map) {
return new Customer( return Customer(
id: map['id'] as String, id: map['id'] as String,
createdAt: map['created_at'] != null createdAt: map['created_at'] != null
? (map['created_at'] is DateTime ? (map['created_at'] is DateTime

View file

@ -11,9 +11,9 @@ class TreeMigration extends Migration {
up(Schema schema) { up(Schema schema) {
schema.create('trees', (table) { schema.create('trees', (table) {
table.serial('id')..primaryKey(); table.serial('id')..primaryKey();
table.declare('rings', ColumnType('smallint'));
table.timeStamp('created_at'); table.timeStamp('created_at');
table.timeStamp('updated_at'); table.timeStamp('updated_at');
table.declare('rings', ColumnType('smallint'));
}); });
} }
@ -28,10 +28,10 @@ class FruitMigration extends Migration {
up(Schema schema) { up(Schema schema) {
schema.create('fruits', (table) { schema.create('fruits', (table) {
table.serial('id')..primaryKey(); table.serial('id')..primaryKey();
table.integer('tree_id');
table.varChar('common_name');
table.timeStamp('created_at'); table.timeStamp('created_at');
table.timeStamp('updated_at'); table.timeStamp('updated_at');
table.integer('tree_id');
table.varChar('common_name');
}); });
} }
@ -53,10 +53,10 @@ class TreeQuery extends Query<Tree, TreeQueryWhere> {
leftJoin(FruitQuery(trampoline: trampoline), 'id', 'tree_id', leftJoin(FruitQuery(trampoline: trampoline), 'id', 'tree_id',
additionalFields: const [ additionalFields: const [
'id', 'id',
'tree_id',
'common_name',
'created_at', 'created_at',
'updated_at' 'updated_at',
'tree_id',
'common_name'
], ],
trampoline: trampoline); trampoline: trampoline);
} }
@ -78,7 +78,7 @@ class TreeQuery extends Query<Tree, TreeQueryWhere> {
@override @override
get fields { get fields {
return const ['id', 'rings', 'created_at', 'updated_at']; return const ['id', 'created_at', 'updated_at', 'rings'];
} }
@override @override
@ -95,9 +95,9 @@ class TreeQuery extends Query<Tree, TreeQueryWhere> {
if (row.every((x) => x == null)) return null; if (row.every((x) => x == null)) return null;
var model = Tree( var model = Tree(
id: row[0].toString(), id: row[0].toString(),
rings: (row[1] as int), createdAt: (row[1] as DateTime),
createdAt: (row[2] as DateTime), updatedAt: (row[2] as DateTime),
updatedAt: (row[3] as DateTime)); rings: (row[3] as int));
if (row.length > 4) { if (row.length > 4) {
model = model.copyWith( model = model.copyWith(
fruits: [FruitQuery.parseRow(row.skip(4).take(5).toList())] fruits: [FruitQuery.parseRow(row.skip(4).take(5).toList())]
@ -173,21 +173,21 @@ class TreeQuery extends Query<Tree, TreeQueryWhere> {
class TreeQueryWhere extends QueryWhere { class TreeQueryWhere extends QueryWhere {
TreeQueryWhere(TreeQuery query) TreeQueryWhere(TreeQuery query)
: id = NumericSqlExpressionBuilder<int>(query, 'id'), : id = NumericSqlExpressionBuilder<int>(query, 'id'),
rings = NumericSqlExpressionBuilder<int>(query, 'rings'),
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'); updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
rings = NumericSqlExpressionBuilder<int>(query, 'rings');
final NumericSqlExpressionBuilder<int> id; final NumericSqlExpressionBuilder<int> id;
final NumericSqlExpressionBuilder<int> rings;
final DateTimeSqlExpressionBuilder createdAt; final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt; final DateTimeSqlExpressionBuilder updatedAt;
final NumericSqlExpressionBuilder<int> rings;
@override @override
get expressionBuilders { get expressionBuilders {
return [id, rings, createdAt, updatedAt]; return [id, createdAt, updatedAt, rings];
} }
} }
@ -202,11 +202,6 @@ class TreeQueryValues extends MapQueryValues {
} }
set id(String value) => values['id'] = value; set id(String value) => values['id'] = value;
int get rings {
return (values['rings'] as int);
}
set rings(int value) => values['rings'] = value;
DateTime get createdAt { DateTime get createdAt {
return (values['created_at'] as DateTime); return (values['created_at'] as DateTime);
} }
@ -217,10 +212,15 @@ class TreeQueryValues extends MapQueryValues {
} }
set updatedAt(DateTime value) => values['updated_at'] = value; set updatedAt(DateTime value) => values['updated_at'] = value;
int get rings {
return (values['rings'] as int);
}
set rings(int value) => values['rings'] = value;
void copyFrom(Tree model) { void copyFrom(Tree model) {
rings = model.rings;
createdAt = model.createdAt; createdAt = model.createdAt;
updatedAt = model.updatedAt; updatedAt = model.updatedAt;
rings = model.rings;
} }
} }
@ -248,7 +248,7 @@ class FruitQuery extends Query<Fruit, FruitQueryWhere> {
@override @override
get fields { get fields {
return const ['id', 'tree_id', 'common_name', 'created_at', 'updated_at']; return const ['id', 'created_at', 'updated_at', 'tree_id', 'common_name'];
} }
@override @override
@ -265,10 +265,10 @@ class FruitQuery extends Query<Fruit, FruitQueryWhere> {
if (row.every((x) => x == null)) return null; if (row.every((x) => x == null)) return null;
var model = Fruit( var model = Fruit(
id: row[0].toString(), id: row[0].toString(),
treeId: (row[1] as int), createdAt: (row[1] as DateTime),
commonName: (row[2] as String), updatedAt: (row[2] as DateTime),
createdAt: (row[3] as DateTime), treeId: (row[3] as int),
updatedAt: (row[4] as DateTime)); commonName: (row[4] as String));
return model; return model;
} }
@ -281,24 +281,24 @@ class FruitQuery extends Query<Fruit, FruitQueryWhere> {
class FruitQueryWhere extends QueryWhere { class FruitQueryWhere extends QueryWhere {
FruitQueryWhere(FruitQuery query) FruitQueryWhere(FruitQuery query)
: id = NumericSqlExpressionBuilder<int>(query, 'id'), : id = NumericSqlExpressionBuilder<int>(query, 'id'),
treeId = NumericSqlExpressionBuilder<int>(query, 'tree_id'),
commonName = StringSqlExpressionBuilder(query, 'common_name'),
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'); updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
treeId = NumericSqlExpressionBuilder<int>(query, 'tree_id'),
commonName = StringSqlExpressionBuilder(query, 'common_name');
final NumericSqlExpressionBuilder<int> id; final NumericSqlExpressionBuilder<int> id;
final NumericSqlExpressionBuilder<int> treeId;
final StringSqlExpressionBuilder commonName;
final DateTimeSqlExpressionBuilder createdAt; final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt; final DateTimeSqlExpressionBuilder updatedAt;
final NumericSqlExpressionBuilder<int> treeId;
final StringSqlExpressionBuilder commonName;
@override @override
get expressionBuilders { get expressionBuilders {
return [id, treeId, commonName, createdAt, updatedAt]; return [id, createdAt, updatedAt, treeId, commonName];
} }
} }
@ -313,16 +313,6 @@ class FruitQueryValues extends MapQueryValues {
} }
set id(String value) => values['id'] = value; set id(String value) => values['id'] = value;
int get treeId {
return (values['tree_id'] as int);
}
set treeId(int value) => values['tree_id'] = value;
String get commonName {
return (values['common_name'] as String);
}
set commonName(String value) => values['common_name'] = value;
DateTime get createdAt { DateTime get createdAt {
return (values['created_at'] as DateTime); return (values['created_at'] as DateTime);
} }
@ -333,11 +323,21 @@ class FruitQueryValues extends MapQueryValues {
} }
set updatedAt(DateTime value) => values['updated_at'] = value; set updatedAt(DateTime value) => values['updated_at'] = value;
int get treeId {
return (values['tree_id'] as int);
}
set treeId(int value) => values['tree_id'] = value;
String get commonName {
return (values['common_name'] as String);
}
set commonName(String value) => values['common_name'] = value;
void copyFrom(Fruit model) { void copyFrom(Fruit model) {
treeId = model.treeId;
commonName = model.commonName;
createdAt = model.createdAt; createdAt = model.createdAt;
updatedAt = model.updatedAt; updatedAt = model.updatedAt;
treeId = model.treeId;
commonName = model.commonName;
} }
} }
@ -349,59 +349,62 @@ class FruitQueryValues extends MapQueryValues {
class Tree extends _Tree { class Tree extends _Tree {
Tree( Tree(
{this.id, {this.id,
this.rings,
List<_Fruit> fruits,
this.createdAt, this.createdAt,
this.updatedAt}) this.updatedAt,
: this.fruits = new List.unmodifiable(fruits ?? []); this.rings,
List<_Fruit> fruits})
: this.fruits = List.unmodifiable(fruits ?? []);
/// A unique identifier corresponding to this item.
@override
String id;
/// The time at which this item was created.
@override
DateTime createdAt;
/// The last time at which this item was updated.
@override
DateTime updatedAt;
@override @override
final String id; int rings;
@override @override
final int rings; List<_Fruit> fruits;
@override
final List<_Fruit> fruits;
@override
final DateTime createdAt;
@override
final DateTime updatedAt;
Tree copyWith( Tree copyWith(
{String id, {String id,
int rings,
List<_Fruit> fruits,
DateTime createdAt, DateTime createdAt,
DateTime updatedAt}) { DateTime updatedAt,
return new Tree( int rings,
List<_Fruit> fruits}) {
return Tree(
id: id ?? this.id, id: id ?? this.id,
rings: rings ?? this.rings,
fruits: fruits ?? this.fruits,
createdAt: createdAt ?? this.createdAt, createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt); updatedAt: updatedAt ?? this.updatedAt,
rings: rings ?? this.rings,
fruits: fruits ?? this.fruits);
} }
bool operator ==(other) { bool operator ==(other) {
return other is _Tree && return other is _Tree &&
other.id == id && other.id == id &&
other.rings == rings &&
const ListEquality<_Fruit>(const DefaultEquality<_Fruit>())
.equals(other.fruits, fruits) &&
other.createdAt == createdAt && other.createdAt == createdAt &&
other.updatedAt == updatedAt; other.updatedAt == updatedAt &&
other.rings == rings &&
ListEquality<_Fruit>(DefaultEquality<_Fruit>())
.equals(other.fruits, fruits);
} }
@override @override
int get hashCode { int get hashCode {
return hashObjects([id, rings, fruits, createdAt, updatedAt]); return hashObjects([id, createdAt, updatedAt, rings, fruits]);
} }
@override @override
String toString() { String toString() {
return "Tree(id=$id, rings=$rings, fruits=$fruits, createdAt=$createdAt, updatedAt=$updatedAt)"; return "Tree(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, rings=$rings, fruits=$fruits)";
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
@ -412,54 +415,57 @@ class Tree extends _Tree {
@generatedSerializable @generatedSerializable
class Fruit extends _Fruit { class Fruit extends _Fruit {
Fruit( Fruit(
{this.id, this.treeId, this.commonName, this.createdAt, this.updatedAt}); {this.id, this.createdAt, this.updatedAt, this.treeId, this.commonName});
/// A unique identifier corresponding to this item.
@override
String id;
/// The time at which this item was created.
@override
DateTime createdAt;
/// The last time at which this item was updated.
@override
DateTime updatedAt;
@override @override
final String id; int treeId;
@override @override
final int treeId; String commonName;
@override
final String commonName;
@override
final DateTime createdAt;
@override
final DateTime updatedAt;
Fruit copyWith( Fruit copyWith(
{String id, {String id,
int treeId,
String commonName,
DateTime createdAt, DateTime createdAt,
DateTime updatedAt}) { DateTime updatedAt,
return new Fruit( int treeId,
String commonName}) {
return Fruit(
id: id ?? this.id, id: id ?? this.id,
treeId: treeId ?? this.treeId,
commonName: commonName ?? this.commonName,
createdAt: createdAt ?? this.createdAt, createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt); updatedAt: updatedAt ?? this.updatedAt,
treeId: treeId ?? this.treeId,
commonName: commonName ?? this.commonName);
} }
bool operator ==(other) { bool operator ==(other) {
return other is _Fruit && return other is _Fruit &&
other.id == id && other.id == id &&
other.treeId == treeId &&
other.commonName == commonName &&
other.createdAt == createdAt && other.createdAt == createdAt &&
other.updatedAt == updatedAt; other.updatedAt == updatedAt &&
other.treeId == treeId &&
other.commonName == commonName;
} }
@override @override
int get hashCode { int get hashCode {
return hashObjects([id, treeId, commonName, createdAt, updatedAt]); return hashObjects([id, createdAt, updatedAt, treeId, commonName]);
} }
@override @override
String toString() { String toString() {
return "Fruit(id=$id, treeId=$treeId, commonName=$commonName, createdAt=$createdAt, updatedAt=$updatedAt)"; return "Fruit(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, treeId=$treeId, commonName=$commonName)";
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
@ -471,7 +477,7 @@ class Fruit extends _Fruit {
// SerializerGenerator // SerializerGenerator
// ************************************************************************** // **************************************************************************
const TreeSerializer treeSerializer = const TreeSerializer(); const TreeSerializer treeSerializer = TreeSerializer();
class TreeEncoder extends Converter<Tree, Map> { class TreeEncoder extends Converter<Tree, Map> {
const TreeEncoder(); const TreeEncoder();
@ -495,15 +501,8 @@ class TreeSerializer extends Codec<Tree, Map> {
@override @override
get decoder => const TreeDecoder(); get decoder => const TreeDecoder();
static Tree fromMap(Map map) { static Tree fromMap(Map map) {
return new Tree( return Tree(
id: map['id'] as String, 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))
.cast<Map>()
.map(FruitSerializer.fromMap))
: null,
createdAt: map['created_at'] != null createdAt: map['created_at'] != null
? (map['created_at'] is DateTime ? (map['created_at'] is DateTime
? (map['created_at'] as DateTime) ? (map['created_at'] as DateTime)
@ -513,6 +512,11 @@ class TreeSerializer extends Codec<Tree, Map> {
? (map['updated_at'] is DateTime ? (map['updated_at'] is DateTime
? (map['updated_at'] as DateTime) ? (map['updated_at'] as DateTime)
: DateTime.parse(map['updated_at'].toString())) : DateTime.parse(map['updated_at'].toString()))
: null,
rings: map['rings'] as int,
fruits: map['fruits'] is Iterable
? List.unmodifiable(((map['fruits'] as Iterable).whereType<Map>())
.map(FruitSerializer.fromMap))
: null); : null);
} }
@ -522,10 +526,10 @@ class TreeSerializer extends Codec<Tree, Map> {
} }
return { return {
'id': model.id, 'id': model.id,
'rings': model.rings,
'fruits': model.fruits?.map((m) => FruitSerializer.toMap(m))?.toList(),
'created_at': model.createdAt?.toIso8601String(), 'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String() 'updated_at': model.updatedAt?.toIso8601String(),
'rings': model.rings,
'fruits': model.fruits?.map((m) => FruitSerializer.toMap(m))?.toList()
}; };
} }
} }
@ -533,24 +537,24 @@ class TreeSerializer extends Codec<Tree, Map> {
abstract class TreeFields { abstract class TreeFields {
static const List<String> allFields = <String>[ static const List<String> allFields = <String>[
id, id,
rings,
fruits,
createdAt, createdAt,
updatedAt updatedAt,
rings,
fruits
]; ];
static const String id = 'id'; static const String id = 'id';
static const String rings = 'rings';
static const String fruits = 'fruits';
static const String createdAt = 'created_at'; static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at'; static const String updatedAt = 'updated_at';
static const String rings = 'rings';
static const String fruits = 'fruits';
} }
const FruitSerializer fruitSerializer = const FruitSerializer(); const FruitSerializer fruitSerializer = FruitSerializer();
class FruitEncoder extends Converter<Fruit, Map> { class FruitEncoder extends Converter<Fruit, Map> {
const FruitEncoder(); const FruitEncoder();
@ -574,10 +578,8 @@ class FruitSerializer extends Codec<Fruit, Map> {
@override @override
get decoder => const FruitDecoder(); get decoder => const FruitDecoder();
static Fruit fromMap(Map map) { static Fruit fromMap(Map map) {
return new Fruit( return Fruit(
id: map['id'] as String, id: map['id'] as String,
treeId: map['tree_id'] as int,
commonName: map['common_name'] as String,
createdAt: map['created_at'] != null createdAt: map['created_at'] != null
? (map['created_at'] is DateTime ? (map['created_at'] is DateTime
? (map['created_at'] as DateTime) ? (map['created_at'] as DateTime)
@ -587,7 +589,9 @@ class FruitSerializer extends Codec<Fruit, Map> {
? (map['updated_at'] is DateTime ? (map['updated_at'] is DateTime
? (map['updated_at'] as DateTime) ? (map['updated_at'] as DateTime)
: DateTime.parse(map['updated_at'].toString())) : DateTime.parse(map['updated_at'].toString()))
: null); : null,
treeId: map['tree_id'] as int,
commonName: map['common_name'] as String);
} }
static Map<String, dynamic> toMap(_Fruit model) { static Map<String, dynamic> toMap(_Fruit model) {
@ -596,10 +600,10 @@ class FruitSerializer extends Codec<Fruit, Map> {
} }
return { return {
'id': model.id, 'id': model.id,
'tree_id': model.treeId,
'common_name': model.commonName,
'created_at': model.createdAt?.toIso8601String(), 'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String() 'updated_at': model.updatedAt?.toIso8601String(),
'tree_id': model.treeId,
'common_name': model.commonName
}; };
} }
} }
@ -607,19 +611,19 @@ class FruitSerializer extends Codec<Fruit, Map> {
abstract class FruitFields { abstract class FruitFields {
static const List<String> allFields = <String>[ static const List<String> allFields = <String>[
id, id,
treeId,
commonName,
createdAt, createdAt,
updatedAt updatedAt,
treeId,
commonName
]; ];
static const String id = 'id'; static const String id = 'id';
static const String treeId = 'tree_id';
static const String commonName = 'common_name';
static const String createdAt = 'created_at'; static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at'; static const String updatedAt = 'updated_at';
static const String treeId = 'tree_id';
static const String commonName = 'common_name';
} }

View file

@ -39,10 +39,10 @@ class SongMigration extends Migration {
up(Schema schema) { up(Schema schema) {
schema.create('songs', (table) { schema.create('songs', (table) {
table.serial('id')..primaryKey(); table.serial('id')..primaryKey();
table.integer('weird_join_id');
table.varChar('title');
table.timeStamp('created_at'); table.timeStamp('created_at');
table.timeStamp('updated_at'); table.timeStamp('updated_at');
table.integer('weird_join_id');
table.varChar('title');
}); });
} }
@ -185,10 +185,10 @@ class WeirdJoinQuery extends Query<WeirdJoin, WeirdJoinQueryWhere> {
leftJoin('songs', 'id', 'weird_join_id', leftJoin('songs', 'id', 'weird_join_id',
additionalFields: const [ additionalFields: const [
'id', 'id',
'weird_join_id',
'title',
'created_at', 'created_at',
'updated_at' 'updated_at',
'weird_join_id',
'title'
], ],
trampoline: trampoline); trampoline: trampoline);
leftJoin(NumbaQuery(trampoline: trampoline), 'id', 'parent', leftJoin(NumbaQuery(trampoline: trampoline), 'id', 'parent',
@ -388,7 +388,7 @@ class SongQuery extends Query<Song, SongQueryWhere> {
@override @override
get fields { get fields {
return const ['id', 'weird_join_id', 'title', 'created_at', 'updated_at']; return const ['id', 'created_at', 'updated_at', 'weird_join_id', 'title'];
} }
@override @override
@ -405,10 +405,10 @@ class SongQuery extends Query<Song, SongQueryWhere> {
if (row.every((x) => x == null)) return null; if (row.every((x) => x == null)) return null;
var model = Song( var model = Song(
id: row[0].toString(), id: row[0].toString(),
weirdJoinId: (row[1] as int), createdAt: (row[1] as DateTime),
title: (row[2] as String), updatedAt: (row[2] as DateTime),
createdAt: (row[3] as DateTime), weirdJoinId: (row[3] as int),
updatedAt: (row[4] as DateTime)); title: (row[4] as String));
return model; return model;
} }
@ -421,24 +421,24 @@ class SongQuery extends Query<Song, SongQueryWhere> {
class SongQueryWhere extends QueryWhere { class SongQueryWhere extends QueryWhere {
SongQueryWhere(SongQuery query) SongQueryWhere(SongQuery query)
: id = NumericSqlExpressionBuilder<int>(query, 'id'), : id = NumericSqlExpressionBuilder<int>(query, 'id'),
weirdJoinId = NumericSqlExpressionBuilder<int>(query, 'weird_join_id'),
title = StringSqlExpressionBuilder(query, 'title'),
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'); updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
weirdJoinId = NumericSqlExpressionBuilder<int>(query, 'weird_join_id'),
title = StringSqlExpressionBuilder(query, 'title');
final NumericSqlExpressionBuilder<int> id; final NumericSqlExpressionBuilder<int> id;
final NumericSqlExpressionBuilder<int> weirdJoinId;
final StringSqlExpressionBuilder title;
final DateTimeSqlExpressionBuilder createdAt; final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt; final DateTimeSqlExpressionBuilder updatedAt;
final NumericSqlExpressionBuilder<int> weirdJoinId;
final StringSqlExpressionBuilder title;
@override @override
get expressionBuilders { get expressionBuilders {
return [id, weirdJoinId, title, createdAt, updatedAt]; return [id, createdAt, updatedAt, weirdJoinId, title];
} }
} }
@ -453,16 +453,6 @@ class SongQueryValues extends MapQueryValues {
} }
set id(String value) => values['id'] = value; set id(String value) => values['id'] = value;
int get weirdJoinId {
return (values['weird_join_id'] as int);
}
set weirdJoinId(int value) => values['weird_join_id'] = value;
String get title {
return (values['title'] as String);
}
set title(String value) => values['title'] = value;
DateTime get createdAt { DateTime get createdAt {
return (values['created_at'] as DateTime); return (values['created_at'] as DateTime);
} }
@ -473,11 +463,21 @@ class SongQueryValues extends MapQueryValues {
} }
set updatedAt(DateTime value) => values['updated_at'] = value; set updatedAt(DateTime value) => values['updated_at'] = value;
int get weirdJoinId {
return (values['weird_join_id'] as int);
}
set weirdJoinId(int value) => values['weird_join_id'] = value;
String get title {
return (values['title'] as String);
}
set title(String value) => values['title'] = value;
void copyFrom(Song model) { void copyFrom(Song model) {
weirdJoinId = model.weirdJoinId;
title = model.title;
createdAt = model.createdAt; createdAt = model.createdAt;
updatedAt = model.updatedAt; updatedAt = model.updatedAt;
weirdJoinId = model.weirdJoinId;
title = model.title;
} }
} }
@ -829,7 +829,7 @@ class Unorthodox implements _Unorthodox {
final String name; final String name;
Unorthodox copyWith({String name}) { Unorthodox copyWith({String name}) {
return new Unorthodox(name: name ?? this.name); return Unorthodox(name: name ?? this.name);
} }
bool operator ==(other) { bool operator ==(other) {
@ -854,11 +854,7 @@ class Unorthodox implements _Unorthodox {
@generatedSerializable @generatedSerializable
class WeirdJoin implements _WeirdJoin { class WeirdJoin implements _WeirdJoin {
const WeirdJoin( const WeirdJoin(
{this.id, {this.id, this.unorthodox, this.song, this.numbas, this.foos});
this.unorthodox,
this.song,
List<_Numba> this.numbas,
List<_Foo> this.foos});
@override @override
final int id; final int id;
@ -881,7 +877,7 @@ class WeirdJoin implements _WeirdJoin {
_Song song, _Song song,
List<_Numba> numbas, List<_Numba> numbas,
List<_Foo> foos}) { List<_Foo> foos}) {
return new WeirdJoin( return WeirdJoin(
id: id ?? this.id, id: id ?? this.id,
unorthodox: unorthodox ?? this.unorthodox, unorthodox: unorthodox ?? this.unorthodox,
song: song ?? this.song, song: song ?? this.song,
@ -894,10 +890,9 @@ class WeirdJoin implements _WeirdJoin {
other.id == id && other.id == id &&
other.unorthodox == unorthodox && other.unorthodox == unorthodox &&
other.song == song && other.song == song &&
const ListEquality<_Numba>(const DefaultEquality<_Numba>()) ListEquality<_Numba>(DefaultEquality<_Numba>())
.equals(other.numbas, numbas) && .equals(other.numbas, numbas) &&
const ListEquality<_Foo>(const DefaultEquality<_Foo>()) ListEquality<_Foo>(DefaultEquality<_Foo>()).equals(other.foos, foos);
.equals(other.foos, foos);
} }
@override @override
@ -917,10 +912,19 @@ class WeirdJoin implements _WeirdJoin {
@generatedSerializable @generatedSerializable
class Song extends _Song { class Song extends _Song {
Song({this.id, this.weirdJoinId, this.title, this.createdAt, this.updatedAt}); Song({this.id, this.createdAt, this.updatedAt, this.weirdJoinId, this.title});
/// A unique identifier corresponding to this item.
@override @override
final String id; String id;
/// The time at which this item was created.
@override
DateTime createdAt;
/// The last time at which this item was updated.
@override
DateTime updatedAt;
@override @override
final int weirdJoinId; final int weirdJoinId;
@ -928,43 +932,37 @@ class Song extends _Song {
@override @override
final String title; final String title;
@override
final DateTime createdAt;
@override
final DateTime updatedAt;
Song copyWith( Song copyWith(
{String id, {String id,
int weirdJoinId,
String title,
DateTime createdAt, DateTime createdAt,
DateTime updatedAt}) { DateTime updatedAt,
return new Song( int weirdJoinId,
String title}) {
return Song(
id: id ?? this.id, id: id ?? this.id,
weirdJoinId: weirdJoinId ?? this.weirdJoinId,
title: title ?? this.title,
createdAt: createdAt ?? this.createdAt, createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt); updatedAt: updatedAt ?? this.updatedAt,
weirdJoinId: weirdJoinId ?? this.weirdJoinId,
title: title ?? this.title);
} }
bool operator ==(other) { bool operator ==(other) {
return other is _Song && return other is _Song &&
other.id == id && other.id == id &&
other.weirdJoinId == weirdJoinId &&
other.title == title &&
other.createdAt == createdAt && other.createdAt == createdAt &&
other.updatedAt == updatedAt; other.updatedAt == updatedAt &&
other.weirdJoinId == weirdJoinId &&
other.title == title;
} }
@override @override
int get hashCode { int get hashCode {
return hashObjects([id, weirdJoinId, title, createdAt, updatedAt]); return hashObjects([id, createdAt, updatedAt, weirdJoinId, title]);
} }
@override @override
String toString() { String toString() {
return "Song(id=$id, weirdJoinId=$weirdJoinId, title=$title, createdAt=$createdAt, updatedAt=$updatedAt)"; return "Song(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, weirdJoinId=$weirdJoinId, title=$title)";
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
@ -977,13 +975,13 @@ class Numba extends _Numba {
Numba({this.i, this.parent}); Numba({this.i, this.parent});
@override @override
final int i; int i;
@override @override
final int parent; int parent;
Numba copyWith({int i, int parent}) { Numba copyWith({int i, int parent}) {
return new Numba(i: i ?? this.i, parent: parent ?? this.parent); return Numba(i: i ?? this.i, parent: parent ?? this.parent);
} }
bool operator ==(other) { bool operator ==(other) {
@ -1007,7 +1005,7 @@ class Numba extends _Numba {
@generatedSerializable @generatedSerializable
class Foo implements _Foo { class Foo implements _Foo {
const Foo({this.bar, List<_WeirdJoin> this.weirdJoins}); const Foo({this.bar, this.weirdJoins});
@override @override
final String bar; final String bar;
@ -1016,14 +1014,13 @@ class Foo implements _Foo {
final List<_WeirdJoin> weirdJoins; final List<_WeirdJoin> weirdJoins;
Foo copyWith({String bar, List<_WeirdJoin> weirdJoins}) { Foo copyWith({String bar, List<_WeirdJoin> weirdJoins}) {
return new Foo( return Foo(bar: bar ?? this.bar, weirdJoins: weirdJoins ?? this.weirdJoins);
bar: bar ?? this.bar, weirdJoins: weirdJoins ?? this.weirdJoins);
} }
bool operator ==(other) { bool operator ==(other) {
return other is _Foo && return other is _Foo &&
other.bar == bar && other.bar == bar &&
const ListEquality<_WeirdJoin>(const DefaultEquality<_WeirdJoin>()) ListEquality<_WeirdJoin>(DefaultEquality<_WeirdJoin>())
.equals(other.weirdJoins, weirdJoins); .equals(other.weirdJoins, weirdJoins);
} }
@ -1053,7 +1050,7 @@ class FooPivot implements _FooPivot {
final _Foo foo; final _Foo foo;
FooPivot copyWith({_WeirdJoin weirdJoin, _Foo foo}) { FooPivot copyWith({_WeirdJoin weirdJoin, _Foo foo}) {
return new FooPivot( return FooPivot(
weirdJoin: weirdJoin ?? this.weirdJoin, foo: foo ?? this.foo); weirdJoin: weirdJoin ?? this.weirdJoin, foo: foo ?? this.foo);
} }
@ -1082,7 +1079,7 @@ class FooPivot implements _FooPivot {
// SerializerGenerator // SerializerGenerator
// ************************************************************************** // **************************************************************************
const UnorthodoxSerializer unorthodoxSerializer = const UnorthodoxSerializer(); const UnorthodoxSerializer unorthodoxSerializer = UnorthodoxSerializer();
class UnorthodoxEncoder extends Converter<Unorthodox, Map> { class UnorthodoxEncoder extends Converter<Unorthodox, Map> {
const UnorthodoxEncoder(); const UnorthodoxEncoder();
@ -1106,7 +1103,7 @@ class UnorthodoxSerializer extends Codec<Unorthodox, Map> {
@override @override
get decoder => const UnorthodoxDecoder(); get decoder => const UnorthodoxDecoder();
static Unorthodox fromMap(Map map) { static Unorthodox fromMap(Map map) {
return new Unorthodox(name: map['name'] as String); return Unorthodox(name: map['name'] as String);
} }
static Map<String, dynamic> toMap(_Unorthodox model) { static Map<String, dynamic> toMap(_Unorthodox model) {
@ -1123,7 +1120,7 @@ abstract class UnorthodoxFields {
static const String name = 'name'; static const String name = 'name';
} }
const WeirdJoinSerializer weirdJoinSerializer = const WeirdJoinSerializer(); const WeirdJoinSerializer weirdJoinSerializer = WeirdJoinSerializer();
class WeirdJoinEncoder extends Converter<WeirdJoin, Map> { class WeirdJoinEncoder extends Converter<WeirdJoin, Map> {
const WeirdJoinEncoder(); const WeirdJoinEncoder();
@ -1147,7 +1144,7 @@ class WeirdJoinSerializer extends Codec<WeirdJoin, Map> {
@override @override
get decoder => const WeirdJoinDecoder(); get decoder => const WeirdJoinDecoder();
static WeirdJoin fromMap(Map map) { static WeirdJoin fromMap(Map map) {
return new WeirdJoin( return WeirdJoin(
id: map['id'] as int, id: map['id'] as int,
unorthodox: map['unorthodox'] != null unorthodox: map['unorthodox'] != null
? UnorthodoxSerializer.fromMap(map['unorthodox'] as Map) ? UnorthodoxSerializer.fromMap(map['unorthodox'] as Map)
@ -1156,15 +1153,11 @@ class WeirdJoinSerializer extends Codec<WeirdJoin, Map> {
? SongSerializer.fromMap(map['song'] as Map) ? SongSerializer.fromMap(map['song'] as Map)
: null, : null,
numbas: map['numbas'] is Iterable numbas: map['numbas'] is Iterable
? new List.unmodifiable( ? List.unmodifiable(((map['numbas'] as Iterable).whereType<Map>())
((map['numbas'] as Iterable).where((x) => x is Map))
.cast<Map>()
.map(NumbaSerializer.fromMap)) .map(NumbaSerializer.fromMap))
: null, : null,
foos: map['foos'] is Iterable foos: map['foos'] is Iterable
? new List.unmodifiable( ? List.unmodifiable(((map['foos'] as Iterable).whereType<Map>())
((map['foos'] as Iterable).where((x) => x is Map))
.cast<Map>()
.map(FooSerializer.fromMap)) .map(FooSerializer.fromMap))
: null); : null);
} }
@ -1203,7 +1196,7 @@ abstract class WeirdJoinFields {
static const String foos = 'foos'; static const String foos = 'foos';
} }
const SongSerializer songSerializer = const SongSerializer(); const SongSerializer songSerializer = SongSerializer();
class SongEncoder extends Converter<Song, Map> { class SongEncoder extends Converter<Song, Map> {
const SongEncoder(); const SongEncoder();
@ -1227,10 +1220,8 @@ class SongSerializer extends Codec<Song, Map> {
@override @override
get decoder => const SongDecoder(); get decoder => const SongDecoder();
static Song fromMap(Map map) { static Song fromMap(Map map) {
return new Song( return Song(
id: map['id'] as String, id: map['id'] as String,
weirdJoinId: map['weird_join_id'] as int,
title: map['title'] as String,
createdAt: map['created_at'] != null createdAt: map['created_at'] != null
? (map['created_at'] is DateTime ? (map['created_at'] is DateTime
? (map['created_at'] as DateTime) ? (map['created_at'] as DateTime)
@ -1240,7 +1231,9 @@ class SongSerializer extends Codec<Song, Map> {
? (map['updated_at'] is DateTime ? (map['updated_at'] is DateTime
? (map['updated_at'] as DateTime) ? (map['updated_at'] as DateTime)
: DateTime.parse(map['updated_at'].toString())) : DateTime.parse(map['updated_at'].toString()))
: null); : null,
weirdJoinId: map['weird_join_id'] as int,
title: map['title'] as String);
} }
static Map<String, dynamic> toMap(_Song model) { static Map<String, dynamic> toMap(_Song model) {
@ -1249,10 +1242,10 @@ class SongSerializer extends Codec<Song, Map> {
} }
return { return {
'id': model.id, 'id': model.id,
'weird_join_id': model.weirdJoinId,
'title': model.title,
'created_at': model.createdAt?.toIso8601String(), 'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String() 'updated_at': model.updatedAt?.toIso8601String(),
'weird_join_id': model.weirdJoinId,
'title': model.title
}; };
} }
} }
@ -1260,24 +1253,24 @@ class SongSerializer extends Codec<Song, Map> {
abstract class SongFields { abstract class SongFields {
static const List<String> allFields = <String>[ static const List<String> allFields = <String>[
id, id,
weirdJoinId,
title,
createdAt, createdAt,
updatedAt updatedAt,
weirdJoinId,
title
]; ];
static const String id = 'id'; static const String id = 'id';
static const String weirdJoinId = 'weird_join_id';
static const String title = 'title';
static const String createdAt = 'created_at'; static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at'; static const String updatedAt = 'updated_at';
static const String weirdJoinId = 'weird_join_id';
static const String title = 'title';
} }
const NumbaSerializer numbaSerializer = const NumbaSerializer(); const NumbaSerializer numbaSerializer = NumbaSerializer();
class NumbaEncoder extends Converter<Numba, Map> { class NumbaEncoder extends Converter<Numba, Map> {
const NumbaEncoder(); const NumbaEncoder();
@ -1301,7 +1294,7 @@ class NumbaSerializer extends Codec<Numba, Map> {
@override @override
get decoder => const NumbaDecoder(); get decoder => const NumbaDecoder();
static Numba fromMap(Map map) { static Numba fromMap(Map map) {
return new Numba(i: map['i'] as int, parent: map['parent'] as int); return Numba(i: map['i'] as int, parent: map['parent'] as int);
} }
static Map<String, dynamic> toMap(_Numba model) { static Map<String, dynamic> toMap(_Numba model) {
@ -1320,7 +1313,7 @@ abstract class NumbaFields {
static const String parent = 'parent'; static const String parent = 'parent';
} }
const FooSerializer fooSerializer = const FooSerializer(); const FooSerializer fooSerializer = FooSerializer();
class FooEncoder extends Converter<Foo, Map> { class FooEncoder extends Converter<Foo, Map> {
const FooEncoder(); const FooEncoder();
@ -1344,12 +1337,11 @@ class FooSerializer extends Codec<Foo, Map> {
@override @override
get decoder => const FooDecoder(); get decoder => const FooDecoder();
static Foo fromMap(Map map) { static Foo fromMap(Map map) {
return new Foo( return Foo(
bar: map['bar'] as String, bar: map['bar'] as String,
weirdJoins: map['weird_joins'] is Iterable weirdJoins: map['weird_joins'] is Iterable
? new List.unmodifiable( ? List.unmodifiable(
((map['weird_joins'] as Iterable).where((x) => x is Map)) ((map['weird_joins'] as Iterable).whereType<Map>())
.cast<Map>()
.map(WeirdJoinSerializer.fromMap)) .map(WeirdJoinSerializer.fromMap))
: null); : null);
} }
@ -1374,7 +1366,7 @@ abstract class FooFields {
static const String weirdJoins = 'weird_joins'; static const String weirdJoins = 'weird_joins';
} }
const FooPivotSerializer fooPivotSerializer = const FooPivotSerializer(); const FooPivotSerializer fooPivotSerializer = FooPivotSerializer();
class FooPivotEncoder extends Converter<FooPivot, Map> { class FooPivotEncoder extends Converter<FooPivot, Map> {
const FooPivotEncoder(); const FooPivotEncoder();
@ -1398,7 +1390,7 @@ class FooPivotSerializer extends Codec<FooPivot, Map> {
@override @override
get decoder => const FooPivotDecoder(); get decoder => const FooPivotDecoder();
static FooPivot fromMap(Map map) { static FooPivot fromMap(Map map) {
return new FooPivot( return FooPivot(
weirdJoin: map['weird_join'] != null weirdJoin: map['weird_join'] != null
? WeirdJoinSerializer.fromMap(map['weird_join'] as Map) ? WeirdJoinSerializer.fromMap(map['weird_join'] as Map)
: null, : null,

View file

@ -11,11 +11,11 @@ class UserMigration extends Migration {
up(Schema schema) { up(Schema schema) {
schema.create('users', (table) { schema.create('users', (table) {
table.serial('id')..primaryKey(); table.serial('id')..primaryKey();
table.timeStamp('created_at');
table.timeStamp('updated_at');
table.varChar('username'); table.varChar('username');
table.varChar('password'); table.varChar('password');
table.varChar('email'); table.varChar('email');
table.timeStamp('created_at');
table.timeStamp('updated_at');
}); });
} }
@ -45,9 +45,9 @@ class RoleMigration extends Migration {
up(Schema schema) { up(Schema schema) {
schema.create('roles', (table) { schema.create('roles', (table) {
table.serial('id')..primaryKey(); table.serial('id')..primaryKey();
table.varChar('name');
table.timeStamp('created_at'); table.timeStamp('created_at');
table.timeStamp('updated_at'); table.timeStamp('updated_at');
table.varChar('name');
}); });
} }
@ -67,7 +67,7 @@ class UserQuery extends Query<User, UserQueryWhere> {
trampoline.add(tableName); trampoline.add(tableName);
_where = UserQueryWhere(this); _where = UserQueryWhere(this);
leftJoin(RoleUserQuery(trampoline: trampoline), 'id', 'user_id', leftJoin(RoleUserQuery(trampoline: trampoline), 'id', 'user_id',
additionalFields: const ['id', 'name', 'created_at', 'updated_at'], additionalFields: const ['id', 'created_at', 'updated_at', 'name'],
trampoline: trampoline); trampoline: trampoline);
} }
@ -90,11 +90,11 @@ class UserQuery extends Query<User, UserQueryWhere> {
get fields { get fields {
return const [ return const [
'id', 'id',
'created_at',
'updated_at',
'username', 'username',
'password', 'password',
'email', 'email'
'created_at',
'updated_at'
]; ];
} }
@ -112,11 +112,11 @@ class UserQuery extends Query<User, UserQueryWhere> {
if (row.every((x) => x == null)) return null; if (row.every((x) => x == null)) return null;
var model = User( var model = User(
id: row[0].toString(), id: row[0].toString(),
username: (row[1] as String), createdAt: (row[1] as DateTime),
password: (row[2] as String), updatedAt: (row[2] as DateTime),
email: (row[3] as String), username: (row[3] as String),
createdAt: (row[4] as DateTime), password: (row[4] as String),
updatedAt: (row[5] as DateTime)); email: (row[5] as String));
if (row.length > 6) { if (row.length > 6) {
model = model.copyWith( model = model.copyWith(
roles: [RoleQuery.parseRow(row.skip(6).take(4).toList())] roles: [RoleQuery.parseRow(row.skip(6).take(4).toList())]
@ -198,27 +198,27 @@ class UserQuery extends Query<User, UserQueryWhere> {
class UserQueryWhere extends QueryWhere { class UserQueryWhere extends QueryWhere {
UserQueryWhere(UserQuery query) UserQueryWhere(UserQuery query)
: id = NumericSqlExpressionBuilder<int>(query, 'id'), : id = NumericSqlExpressionBuilder<int>(query, 'id'),
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
username = StringSqlExpressionBuilder(query, 'username'), username = StringSqlExpressionBuilder(query, 'username'),
password = StringSqlExpressionBuilder(query, 'password'), password = StringSqlExpressionBuilder(query, 'password'),
email = StringSqlExpressionBuilder(query, 'email'), email = StringSqlExpressionBuilder(query, 'email');
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
final NumericSqlExpressionBuilder<int> id; final NumericSqlExpressionBuilder<int> id;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
final StringSqlExpressionBuilder username; final StringSqlExpressionBuilder username;
final StringSqlExpressionBuilder password; final StringSqlExpressionBuilder password;
final StringSqlExpressionBuilder email; final StringSqlExpressionBuilder email;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
@override @override
get expressionBuilders { get expressionBuilders {
return [id, username, password, email, createdAt, updatedAt]; return [id, createdAt, updatedAt, username, password, email];
} }
} }
@ -233,6 +233,16 @@ class UserQueryValues extends MapQueryValues {
} }
set id(String value) => values['id'] = value; 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;
String get username { String get username {
return (values['username'] as String); return (values['username'] as String);
} }
@ -248,22 +258,12 @@ class UserQueryValues extends MapQueryValues {
} }
set email(String value) => values['email'] = value; set email(String value) => values['email'] = 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;
void copyFrom(User model) { void copyFrom(User model) {
createdAt = model.createdAt;
updatedAt = model.updatedAt;
username = model.username; username = model.username;
password = model.password; password = model.password;
email = model.email; email = model.email;
createdAt = model.createdAt;
updatedAt = model.updatedAt;
} }
} }
@ -273,16 +273,16 @@ class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
trampoline.add(tableName); trampoline.add(tableName);
_where = RoleUserQueryWhere(this); _where = RoleUserQueryWhere(this);
leftJoin('roles', 'role_id', 'id', leftJoin('roles', 'role_id', 'id',
additionalFields: const ['id', 'name', 'created_at', 'updated_at'], additionalFields: const ['id', 'created_at', 'updated_at', 'name'],
trampoline: trampoline); trampoline: trampoline);
leftJoin('users', 'user_id', 'id', leftJoin('users', 'user_id', 'id',
additionalFields: const [ additionalFields: const [
'id', 'id',
'created_at',
'updated_at',
'username', 'username',
'password', 'password',
'email', 'email'
'created_at',
'updated_at'
], ],
trampoline: trampoline); trampoline: trampoline);
} }
@ -386,11 +386,11 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
leftJoin(RoleUserQuery(trampoline: trampoline), 'id', 'role_id', leftJoin(RoleUserQuery(trampoline: trampoline), 'id', 'role_id',
additionalFields: const [ additionalFields: const [
'id', 'id',
'created_at',
'updated_at',
'username', 'username',
'password', 'password',
'email', 'email'
'created_at',
'updated_at'
], ],
trampoline: trampoline); trampoline: trampoline);
} }
@ -412,7 +412,7 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
@override @override
get fields { get fields {
return const ['id', 'name', 'created_at', 'updated_at']; return const ['id', 'created_at', 'updated_at', 'name'];
} }
@override @override
@ -429,9 +429,9 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
if (row.every((x) => x == null)) return null; if (row.every((x) => x == null)) return null;
var model = Role( var model = Role(
id: row[0].toString(), id: row[0].toString(),
name: (row[1] as String), createdAt: (row[1] as DateTime),
createdAt: (row[2] as DateTime), updatedAt: (row[2] as DateTime),
updatedAt: (row[3] as DateTime)); name: (row[3] as String));
if (row.length > 4) { if (row.length > 4) {
model = model.copyWith( model = model.copyWith(
users: [UserQuery.parseRow(row.skip(4).take(6).toList())] users: [UserQuery.parseRow(row.skip(4).take(6).toList())]
@ -513,21 +513,21 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
class RoleQueryWhere extends QueryWhere { class RoleQueryWhere extends QueryWhere {
RoleQueryWhere(RoleQuery query) RoleQueryWhere(RoleQuery query)
: id = NumericSqlExpressionBuilder<int>(query, 'id'), : id = NumericSqlExpressionBuilder<int>(query, 'id'),
name = StringSqlExpressionBuilder(query, 'name'),
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'); updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
name = StringSqlExpressionBuilder(query, 'name');
final NumericSqlExpressionBuilder<int> id; final NumericSqlExpressionBuilder<int> id;
final StringSqlExpressionBuilder name;
final DateTimeSqlExpressionBuilder createdAt; final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt; final DateTimeSqlExpressionBuilder updatedAt;
final StringSqlExpressionBuilder name;
@override @override
get expressionBuilders { get expressionBuilders {
return [id, name, createdAt, updatedAt]; return [id, createdAt, updatedAt, name];
} }
} }
@ -542,11 +542,6 @@ class RoleQueryValues extends MapQueryValues {
} }
set id(String value) => values['id'] = value; set id(String value) => values['id'] = value;
String get name {
return (values['name'] as String);
}
set name(String value) => values['name'] = value;
DateTime get createdAt { DateTime get createdAt {
return (values['created_at'] as DateTime); return (values['created_at'] as DateTime);
} }
@ -557,10 +552,15 @@ class RoleQueryValues extends MapQueryValues {
} }
set updatedAt(DateTime value) => values['updated_at'] = value; set updatedAt(DateTime value) => values['updated_at'] = value;
String get name {
return (values['name'] as String);
}
set name(String value) => values['name'] = value;
void copyFrom(Role model) { void copyFrom(Role model) {
name = model.name;
createdAt = model.createdAt; createdAt = model.createdAt;
updatedAt = model.updatedAt; updatedAt = model.updatedAt;
name = model.name;
} }
} }
@ -572,16 +572,25 @@ class RoleQueryValues extends MapQueryValues {
class User extends _User { class User extends _User {
User( User(
{this.id, {this.id,
this.createdAt,
this.updatedAt,
this.username, this.username,
this.password, this.password,
this.email, this.email,
List<_Role> roles, List<_Role> roles})
this.createdAt, : this.roles = List.unmodifiable(roles ?? []);
this.updatedAt})
: this.roles = new List.unmodifiable(roles ?? []);
/// A unique identifier corresponding to this item.
@override @override
final String id; String id;
/// The time at which this item was created.
@override
DateTime createdAt;
/// The last time at which this item was updated.
@override
DateTime updatedAt;
@override @override
final String username; final String username;
@ -595,51 +604,45 @@ class User extends _User {
@override @override
final List<_Role> roles; final List<_Role> roles;
@override
final DateTime createdAt;
@override
final DateTime updatedAt;
User copyWith( User copyWith(
{String id, {String id,
DateTime createdAt,
DateTime updatedAt,
String username, String username,
String password, String password,
String email, String email,
List<_Role> roles, List<_Role> roles}) {
DateTime createdAt, return User(
DateTime updatedAt}) {
return new User(
id: id ?? this.id, id: id ?? this.id,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
username: username ?? this.username, username: username ?? this.username,
password: password ?? this.password, password: password ?? this.password,
email: email ?? this.email, email: email ?? this.email,
roles: roles ?? this.roles, roles: roles ?? this.roles);
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt);
} }
bool operator ==(other) { bool operator ==(other) {
return other is _User && return other is _User &&
other.id == id && other.id == id &&
other.createdAt == createdAt &&
other.updatedAt == updatedAt &&
other.username == username && other.username == username &&
other.password == password && other.password == password &&
other.email == email && other.email == email &&
const ListEquality<_Role>(const DefaultEquality<_Role>()) ListEquality<_Role>(DefaultEquality<_Role>())
.equals(other.roles, roles) && .equals(other.roles, roles);
other.createdAt == createdAt &&
other.updatedAt == updatedAt;
} }
@override @override
int get hashCode { int get hashCode {
return hashObjects( return hashObjects(
[id, username, password, email, roles, createdAt, updatedAt]); [id, createdAt, updatedAt, username, password, email, roles]);
} }
@override @override
String toString() { String toString() {
return "User(id=$id, username=$username, password=$password, email=$email, roles=$roles, createdAt=$createdAt, updatedAt=$updatedAt)"; return "User(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, username=$username, password=$password, email=$email, roles=$roles)";
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
@ -658,7 +661,7 @@ class RoleUser implements _RoleUser {
final _User user; final _User user;
RoleUser copyWith({_Role role, _User user}) { RoleUser copyWith({_Role role, _User user}) {
return new RoleUser(role: role ?? this.role, user: user ?? this.user); return RoleUser(role: role ?? this.role, user: user ?? this.user);
} }
bool operator ==(other) { bool operator ==(other) {
@ -682,56 +685,59 @@ class RoleUser implements _RoleUser {
@generatedSerializable @generatedSerializable
class Role extends _Role { class Role extends _Role {
Role({this.id, this.name, List<_User> users, this.createdAt, this.updatedAt}) Role({this.id, this.createdAt, this.updatedAt, this.name, List<_User> users})
: this.users = new List.unmodifiable(users ?? []); : this.users = List.unmodifiable(users ?? []);
/// A unique identifier corresponding to this item.
@override
String id;
/// The time at which this item was created.
@override
DateTime createdAt;
/// The last time at which this item was updated.
@override
DateTime updatedAt;
@override @override
final String id; String name;
@override
final String name;
@override @override
final List<_User> users; final List<_User> users;
@override
final DateTime createdAt;
@override
final DateTime updatedAt;
Role copyWith( Role copyWith(
{String id, {String id,
String name,
List<_User> users,
DateTime createdAt, DateTime createdAt,
DateTime updatedAt}) { DateTime updatedAt,
return new Role( String name,
List<_User> users}) {
return Role(
id: id ?? this.id, id: id ?? this.id,
name: name ?? this.name,
users: users ?? this.users,
createdAt: createdAt ?? this.createdAt, createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt); updatedAt: updatedAt ?? this.updatedAt,
name: name ?? this.name,
users: users ?? this.users);
} }
bool operator ==(other) { bool operator ==(other) {
return other is _Role && return other is _Role &&
other.id == id && other.id == id &&
other.name == name &&
const ListEquality<_User>(const DefaultEquality<_User>())
.equals(other.users, users) &&
other.createdAt == createdAt && other.createdAt == createdAt &&
other.updatedAt == updatedAt; other.updatedAt == updatedAt &&
other.name == name &&
ListEquality<_User>(DefaultEquality<_User>())
.equals(other.users, users);
} }
@override @override
int get hashCode { int get hashCode {
return hashObjects([id, name, users, createdAt, updatedAt]); return hashObjects([id, createdAt, updatedAt, name, users]);
} }
@override @override
String toString() { String toString() {
return "Role(id=$id, name=$name, users=$users, createdAt=$createdAt, updatedAt=$updatedAt)"; return "Role(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, name=$name, users=$users)";
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
@ -743,7 +749,7 @@ class Role extends _Role {
// SerializerGenerator // SerializerGenerator
// ************************************************************************** // **************************************************************************
const UserSerializer userSerializer = const UserSerializer(); const UserSerializer userSerializer = UserSerializer();
class UserEncoder extends Converter<User, Map> { class UserEncoder extends Converter<User, Map> {
const UserEncoder(); const UserEncoder();
@ -767,17 +773,8 @@ class UserSerializer extends Codec<User, Map> {
@override @override
get decoder => const UserDecoder(); get decoder => const UserDecoder();
static User fromMap(Map map) { static User fromMap(Map map) {
return new User( return User(
id: map['id'] as String, id: map['id'] as String,
username: map['username'] as String,
password: map['password'] as String,
email: map['email'] as String,
roles: map['roles'] is Iterable
? new List.unmodifiable(
((map['roles'] as Iterable).where((x) => x is Map))
.cast<Map>()
.map(RoleSerializer.fromMap))
: null,
createdAt: map['created_at'] != null createdAt: map['created_at'] != null
? (map['created_at'] is DateTime ? (map['created_at'] is DateTime
? (map['created_at'] as DateTime) ? (map['created_at'] as DateTime)
@ -787,6 +784,13 @@ class UserSerializer extends Codec<User, Map> {
? (map['updated_at'] is DateTime ? (map['updated_at'] is DateTime
? (map['updated_at'] as DateTime) ? (map['updated_at'] as DateTime)
: DateTime.parse(map['updated_at'].toString())) : DateTime.parse(map['updated_at'].toString()))
: null,
username: map['username'] as String,
password: map['password'] as String,
email: map['email'] as String,
roles: map['roles'] is Iterable
? List.unmodifiable(((map['roles'] as Iterable).whereType<Map>())
.map(RoleSerializer.fromMap))
: null); : null);
} }
@ -796,12 +800,12 @@ class UserSerializer extends Codec<User, Map> {
} }
return { return {
'id': model.id, 'id': model.id,
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String(),
'username': model.username, 'username': model.username,
'password': model.password, 'password': model.password,
'email': model.email, 'email': model.email,
'roles': model.roles?.map((m) => RoleSerializer.toMap(m))?.toList(), 'roles': model.roles?.map((m) => RoleSerializer.toMap(m))?.toList()
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String()
}; };
} }
} }
@ -809,16 +813,20 @@ class UserSerializer extends Codec<User, Map> {
abstract class UserFields { abstract class UserFields {
static const List<String> allFields = <String>[ static const List<String> allFields = <String>[
id, id,
createdAt,
updatedAt,
username, username,
password, password,
email, email,
roles, roles
createdAt,
updatedAt
]; ];
static const String id = 'id'; static const String id = 'id';
static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at';
static const String username = 'username'; static const String username = 'username';
static const String password = 'password'; static const String password = 'password';
@ -826,13 +834,9 @@ abstract class UserFields {
static const String email = 'email'; static const String email = 'email';
static const String roles = 'roles'; static const String roles = 'roles';
static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at';
} }
const RoleUserSerializer roleUserSerializer = const RoleUserSerializer(); const RoleUserSerializer roleUserSerializer = RoleUserSerializer();
class RoleUserEncoder extends Converter<RoleUser, Map> { class RoleUserEncoder extends Converter<RoleUser, Map> {
const RoleUserEncoder(); const RoleUserEncoder();
@ -856,7 +860,7 @@ class RoleUserSerializer extends Codec<RoleUser, Map> {
@override @override
get decoder => const RoleUserDecoder(); get decoder => const RoleUserDecoder();
static RoleUser fromMap(Map map) { static RoleUser fromMap(Map map) {
return new RoleUser( return RoleUser(
role: map['role'] != null role: map['role'] != null
? RoleSerializer.fromMap(map['role'] as Map) ? RoleSerializer.fromMap(map['role'] as Map)
: null, : null,
@ -884,7 +888,7 @@ abstract class RoleUserFields {
static const String user = 'user'; static const String user = 'user';
} }
const RoleSerializer roleSerializer = const RoleSerializer(); const RoleSerializer roleSerializer = RoleSerializer();
class RoleEncoder extends Converter<Role, Map> { class RoleEncoder extends Converter<Role, Map> {
const RoleEncoder(); const RoleEncoder();
@ -908,15 +912,8 @@ class RoleSerializer extends Codec<Role, Map> {
@override @override
get decoder => const RoleDecoder(); get decoder => const RoleDecoder();
static Role fromMap(Map map) { static Role fromMap(Map map) {
return new Role( return Role(
id: map['id'] as String, id: map['id'] as String,
name: map['name'] as String,
users: map['users'] is Iterable
? new List.unmodifiable(
((map['users'] as Iterable).where((x) => x is Map))
.cast<Map>()
.map(UserSerializer.fromMap))
: null,
createdAt: map['created_at'] != null createdAt: map['created_at'] != null
? (map['created_at'] is DateTime ? (map['created_at'] is DateTime
? (map['created_at'] as DateTime) ? (map['created_at'] as DateTime)
@ -926,6 +923,11 @@ class RoleSerializer extends Codec<Role, Map> {
? (map['updated_at'] is DateTime ? (map['updated_at'] is DateTime
? (map['updated_at'] as DateTime) ? (map['updated_at'] as DateTime)
: DateTime.parse(map['updated_at'].toString())) : DateTime.parse(map['updated_at'].toString()))
: null,
name: map['name'] as String,
users: map['users'] is Iterable
? List.unmodifiable(((map['users'] as Iterable).whereType<Map>())
.map(UserSerializer.fromMap))
: null); : null);
} }
@ -935,10 +937,10 @@ class RoleSerializer extends Codec<Role, Map> {
} }
return { return {
'id': model.id, 'id': model.id,
'name': model.name,
'users': model.users?.map((m) => UserSerializer.toMap(m))?.toList(),
'created_at': model.createdAt?.toIso8601String(), 'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String() 'updated_at': model.updatedAt?.toIso8601String(),
'name': model.name,
'users': model.users?.map((m) => UserSerializer.toMap(m))?.toList()
}; };
} }
} }
@ -946,19 +948,19 @@ class RoleSerializer extends Codec<Role, Map> {
abstract class RoleFields { abstract class RoleFields {
static const List<String> allFields = <String>[ static const List<String> allFields = <String>[
id, id,
name,
users,
createdAt, createdAt,
updatedAt updatedAt,
name,
users
]; ];
static const String id = 'id'; static const String id = 'id';
static const String name = 'name';
static const String users = 'users';
static const String createdAt = 'created_at'; static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at'; static const String updatedAt = 'updated_at';
static const String name = 'name';
static const String users = 'users';
} }