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
* Fix `reviveColumn` and element finding to properly detect all annotations now.

View file

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

View file

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

View file

@ -11,9 +11,9 @@ class BookMigration extends Migration {
up(Schema schema) {
schema.create('books', (table) {
table.serial('id')..primaryKey();
table.varChar('name');
table.timeStamp('created_at');
table.timeStamp('updated_at');
table.varChar('name');
table.integer('author_id').references('authors', 'id');
table.integer('partner_author_id').references('authors', 'id');
});
@ -30,9 +30,9 @@ class AuthorMigration extends Migration {
up(Schema schema) {
schema.create('authors', (table) {
table.serial('id')..primaryKey();
table.varChar('name', length: 255)..defaultsTo('Tobe Osakwe');
table.timeStamp('created_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);
_where = BookQueryWhere(this);
leftJoin('authors', 'author_id', 'id',
additionalFields: const ['id', 'name', 'created_at', 'updated_at'],
additionalFields: const ['id', 'created_at', 'updated_at', 'name'],
trampoline: trampoline);
leftJoin('authors', 'partner_author_id', 'id',
additionalFields: const ['id', 'name', 'created_at', 'updated_at'],
additionalFields: const ['id', 'created_at', 'updated_at', 'name'],
trampoline: trampoline);
}
@ -78,11 +78,11 @@ class BookQuery extends Query<Book, BookQueryWhere> {
get fields {
return const [
'id',
'created_at',
'updated_at',
'author_id',
'partner_author_id',
'name',
'created_at',
'updated_at'
'name'
];
}
@ -100,9 +100,9 @@ class BookQuery extends Query<Book, BookQueryWhere> {
if (row.every((x) => x == null)) return null;
var model = Book(
id: row[0].toString(),
name: (row[3] as String),
createdAt: (row[4] as DateTime),
updatedAt: (row[5] as DateTime));
createdAt: (row[1] as DateTime),
updatedAt: (row[2] as DateTime),
name: (row[5] as String));
if (row.length > 6) {
model = model.copyWith(
author: AuthorQuery.parseRow(row.skip(6).take(4).toList()));
@ -123,28 +123,28 @@ class BookQuery extends Query<Book, BookQueryWhere> {
class BookQueryWhere extends QueryWhere {
BookQueryWhere(BookQuery query)
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
authorId = NumericSqlExpressionBuilder<int>(query, 'author_id'),
partnerAuthorId =
NumericSqlExpressionBuilder<int>(query, 'partner_author_id'),
name = StringSqlExpressionBuilder(query, 'name'),
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
name = StringSqlExpressionBuilder(query, 'name');
final NumericSqlExpressionBuilder<int> id;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
final NumericSqlExpressionBuilder<int> authorId;
final NumericSqlExpressionBuilder<int> partnerAuthorId;
final StringSqlExpressionBuilder name;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
@override
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;
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 {
return (values['author_id'] as int);
}
@ -174,20 +184,10 @@ class BookQueryValues extends MapQueryValues {
}
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) {
name = model.name;
createdAt = model.createdAt;
updatedAt = model.updatedAt;
name = model.name;
if (model.author != null) {
values['author_id'] = model.author.id;
}
@ -221,7 +221,7 @@ class AuthorQuery extends Query<Author, AuthorQueryWhere> {
@override
get fields {
return const ['id', 'name', 'created_at', 'updated_at'];
return const ['id', 'created_at', 'updated_at', 'name'];
}
@override
@ -238,9 +238,9 @@ class AuthorQuery extends Query<Author, AuthorQueryWhere> {
if (row.every((x) => x == null)) return null;
var model = Author(
id: row[0].toString(),
name: (row[1] as String),
createdAt: (row[2] as DateTime),
updatedAt: (row[3] as DateTime));
createdAt: (row[1] as DateTime),
updatedAt: (row[2] as DateTime),
name: (row[3] as String));
return model;
}
@ -253,21 +253,21 @@ class AuthorQuery extends Query<Author, AuthorQueryWhere> {
class AuthorQueryWhere extends QueryWhere {
AuthorQueryWhere(AuthorQuery query)
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
name = StringSqlExpressionBuilder(query, 'name'),
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
name = StringSqlExpressionBuilder(query, 'name');
final NumericSqlExpressionBuilder<int> id;
final StringSqlExpressionBuilder name;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
final StringSqlExpressionBuilder name;
@override
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;
String get name {
return (values['name'] as String);
}
set name(String value) => values['name'] = value;
DateTime get createdAt {
return (values['created_at'] as DateTime);
}
@ -297,10 +292,15 @@ class AuthorQueryValues extends MapQueryValues {
}
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) {
name = model.name;
createdAt = model.createdAt;
updatedAt = model.updatedAt;
name = model.name;
}
}
@ -312,64 +312,67 @@ class AuthorQueryValues extends MapQueryValues {
class Book extends _Book {
Book(
{this.id,
this.createdAt,
this.updatedAt,
this.author,
this.partnerAuthor,
this.name,
this.createdAt,
this.updatedAt});
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
final String id;
_Author author;
@override
final _Author author;
_Author partnerAuthor;
@override
final _Author partnerAuthor;
@override
final String name;
@override
final DateTime createdAt;
@override
final DateTime updatedAt;
String name;
Book copyWith(
{String id,
DateTime createdAt,
DateTime updatedAt,
_Author author,
_Author partnerAuthor,
String name,
DateTime createdAt,
DateTime updatedAt}) {
return new Book(
String name}) {
return Book(
id: id ?? this.id,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
author: author ?? this.author,
partnerAuthor: partnerAuthor ?? this.partnerAuthor,
name: name ?? this.name,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt);
name: name ?? this.name);
}
bool operator ==(other) {
return other is _Book &&
other.id == id &&
other.createdAt == createdAt &&
other.updatedAt == updatedAt &&
other.author == author &&
other.partnerAuthor == partnerAuthor &&
other.name == name &&
other.createdAt == createdAt &&
other.updatedAt == updatedAt;
other.name == name;
}
@override
int get hashCode {
return hashObjects([id, author, partnerAuthor, name, createdAt, updatedAt]);
return hashObjects([id, createdAt, updatedAt, author, partnerAuthor, name]);
}
@override
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() {
@ -379,45 +382,48 @@ class Book extends _Book {
@generatedSerializable
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
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
final String name;
@override
final DateTime createdAt;
@override
final DateTime updatedAt;
Author copyWith(
{String id, String name, DateTime createdAt, DateTime updatedAt}) {
return new Author(
{String id, DateTime createdAt, DateTime updatedAt, String name}) {
return Author(
id: id ?? this.id,
name: name ?? this.name,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt);
updatedAt: updatedAt ?? this.updatedAt,
name: name ?? this.name);
}
bool operator ==(other) {
return other is _Author &&
other.id == id &&
other.name == name &&
other.createdAt == createdAt &&
other.updatedAt == updatedAt;
other.updatedAt == updatedAt &&
other.name == name;
}
@override
int get hashCode {
return hashObjects([id, name, createdAt, updatedAt]);
return hashObjects([id, createdAt, updatedAt, name]);
}
@override
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() {
@ -429,7 +435,7 @@ class Author extends _Author {
// SerializerGenerator
// **************************************************************************
const BookSerializer bookSerializer = const BookSerializer();
const BookSerializer bookSerializer = BookSerializer();
class BookEncoder extends Converter<Book, Map> {
const BookEncoder();
@ -453,15 +459,8 @@ class BookSerializer extends Codec<Book, Map> {
@override
get decoder => const BookDecoder();
static Book fromMap(Map map) {
return new Book(
return Book(
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
? (map['created_at'] is DateTime
? (map['created_at'] as DateTime)
@ -471,7 +470,14 @@ class BookSerializer extends Codec<Book, Map> {
? (map['updated_at'] is DateTime
? (map['updated_at'] as DateTime)
: 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) {
@ -480,11 +486,11 @@ class BookSerializer extends Codec<Book, Map> {
}
return {
'id': model.id,
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String(),
'author': AuthorSerializer.toMap(model.author),
'partner_author': AuthorSerializer.toMap(model.partnerAuthor),
'name': model.name,
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String()
'name': model.name
};
}
}
@ -492,27 +498,27 @@ class BookSerializer extends Codec<Book, Map> {
abstract class BookFields {
static const List<String> allFields = <String>[
id,
createdAt,
updatedAt,
author,
partnerAuthor,
name,
createdAt,
updatedAt
name
];
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 partnerAuthor = 'partner_author';
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> {
const AuthorEncoder();
@ -536,9 +542,8 @@ class AuthorSerializer extends Codec<Author, Map> {
@override
get decoder => const AuthorDecoder();
static Author fromMap(Map map) {
return new Author(
return Author(
id: map['id'] as String,
name: map['name'] as String ?? 'Tobe Osakwe',
createdAt: map['created_at'] != null
? (map['created_at'] is DateTime
? (map['created_at'] as DateTime)
@ -548,7 +553,8 @@ class AuthorSerializer extends Codec<Author, Map> {
? (map['updated_at'] is DateTime
? (map['updated_at'] as DateTime)
: DateTime.parse(map['updated_at'].toString()))
: null);
: null,
name: map['name'] as String ?? 'Tobe Osakwe');
}
static Map<String, dynamic> toMap(_Author model) {
@ -557,9 +563,9 @@ class AuthorSerializer extends Codec<Author, Map> {
}
return {
'id': model.id,
'name': model.name,
'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 {
static const List<String> allFields = <String>[
id,
name,
createdAt,
updatedAt
updatedAt,
name
];
static const String id = 'id';
static const String name = 'name';
static const String createdAt = 'created_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) {
schema.create('cars', (table) {
table.serial('id')..primaryKey();
table.timeStamp('created_at');
table.timeStamp('updated_at');
table.varChar('make');
table.varChar('description');
table.boolean('family_friendly');
table.timeStamp('recalled_at');
table.timeStamp('created_at');
table.timeStamp('updated_at');
});
}
@ -56,12 +56,12 @@ class CarQuery extends Query<Car, CarQueryWhere> {
get fields {
return const [
'id',
'created_at',
'updated_at',
'make',
'description',
'family_friendly',
'recalled_at',
'created_at',
'updated_at'
'recalled_at'
];
}
@ -79,12 +79,12 @@ class CarQuery extends Query<Car, CarQueryWhere> {
if (row.every((x) => x == null)) return null;
var model = Car(
id: row[0].toString(),
make: (row[1] as String),
description: (row[2] as String),
familyFriendly: (row[3] as bool),
recalledAt: (row[4] as DateTime),
createdAt: (row[5] as DateTime),
updatedAt: (row[6] as DateTime));
createdAt: (row[1] as DateTime),
updatedAt: (row[2] as DateTime),
make: (row[3] as String),
description: (row[4] as String),
familyFriendly: (row[5] as bool),
recalledAt: (row[6] as DateTime));
return model;
}
@ -97,15 +97,19 @@ class CarQuery extends Query<Car, CarQueryWhere> {
class CarQueryWhere extends QueryWhere {
CarQueryWhere(CarQuery query)
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
make = StringSqlExpressionBuilder(query, 'make'),
description = StringSqlExpressionBuilder(query, 'description'),
familyFriendly = BooleanSqlExpressionBuilder(query, 'family_friendly'),
recalledAt = DateTimeSqlExpressionBuilder(query, 'recalled_at'),
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
recalledAt = DateTimeSqlExpressionBuilder(query, 'recalled_at');
final NumericSqlExpressionBuilder<int> id;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
final StringSqlExpressionBuilder make;
final StringSqlExpressionBuilder description;
@ -114,20 +118,16 @@ class CarQueryWhere extends QueryWhere {
final DateTimeSqlExpressionBuilder recalledAt;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
@override
get expressionBuilders {
return [
id,
createdAt,
updatedAt,
make,
description,
familyFriendly,
recalledAt,
createdAt,
updatedAt
recalledAt
];
}
}
@ -143,6 +143,16 @@ class CarQueryValues extends MapQueryValues {
}
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 {
return (values['make'] as String);
}
@ -163,23 +173,13 @@ class CarQueryValues extends MapQueryValues {
}
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) {
createdAt = model.createdAt;
updatedAt = model.updatedAt;
make = model.make;
description = model.description;
familyFriendly = model.familyFriendly;
recalledAt = model.recalledAt;
createdAt = model.createdAt;
updatedAt = model.updatedAt;
}
}
@ -191,79 +191,82 @@ class CarQueryValues extends MapQueryValues {
class Car extends _Car {
Car(
{this.id,
this.createdAt,
this.updatedAt,
this.make,
this.description,
this.familyFriendly,
this.recalledAt,
this.createdAt,
this.updatedAt});
this.recalledAt});
/// 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
final String id;
String make;
@override
final String make;
String description;
@override
final String description;
bool familyFriendly;
@override
final bool familyFriendly;
@override
final DateTime recalledAt;
@override
final DateTime createdAt;
@override
final DateTime updatedAt;
DateTime recalledAt;
Car copyWith(
{String id,
DateTime createdAt,
DateTime updatedAt,
String make,
String description,
bool familyFriendly,
DateTime recalledAt,
DateTime createdAt,
DateTime updatedAt}) {
return new Car(
DateTime recalledAt}) {
return Car(
id: id ?? this.id,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
make: make ?? this.make,
description: description ?? this.description,
familyFriendly: familyFriendly ?? this.familyFriendly,
recalledAt: recalledAt ?? this.recalledAt,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt);
recalledAt: recalledAt ?? this.recalledAt);
}
bool operator ==(other) {
return other is _Car &&
other.id == id &&
other.createdAt == createdAt &&
other.updatedAt == updatedAt &&
other.make == make &&
other.description == description &&
other.familyFriendly == familyFriendly &&
other.recalledAt == recalledAt &&
other.createdAt == createdAt &&
other.updatedAt == updatedAt;
other.recalledAt == recalledAt;
}
@override
int get hashCode {
return hashObjects([
id,
createdAt,
updatedAt,
make,
description,
familyFriendly,
recalledAt,
createdAt,
updatedAt
recalledAt
]);
}
@override
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() {
@ -275,7 +278,7 @@ class Car extends _Car {
// SerializerGenerator
// **************************************************************************
const CarSerializer carSerializer = const CarSerializer();
const CarSerializer carSerializer = CarSerializer();
class CarEncoder extends Converter<Car, Map> {
const CarEncoder();
@ -299,16 +302,8 @@ class CarSerializer extends Codec<Car, Map> {
@override
get decoder => const CarDecoder();
static Car fromMap(Map map) {
return new Car(
return Car(
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
? (map['created_at'] is DateTime
? (map['created_at'] as DateTime)
@ -318,6 +313,14 @@ class CarSerializer extends Codec<Car, Map> {
? (map['updated_at'] is DateTime
? (map['updated_at'] as DateTime)
: 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);
}
@ -327,12 +330,12 @@ class CarSerializer extends Codec<Car, Map> {
}
return {
'id': model.id,
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String(),
'make': model.make,
'description': model.description,
'family_friendly': model.familyFriendly,
'recalled_at': model.recalledAt?.toIso8601String(),
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String()
'recalled_at': model.recalledAt?.toIso8601String()
};
}
}
@ -340,16 +343,20 @@ class CarSerializer extends Codec<Car, Map> {
abstract class CarFields {
static const List<String> allFields = <String>[
id,
createdAt,
updatedAt,
make,
description,
familyFriendly,
recalledAt,
createdAt,
updatedAt
recalledAt
];
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 description = 'description';
@ -357,8 +364,4 @@ abstract class CarFields {
static const String familyFriendly = 'family_friendly';
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) {
schema.create('has_cars', (table) {
table.serial('id')..primaryKey();
table.integer('type');
table.timeStamp('created_at');
table.timeStamp('updated_at');
table.integer('type');
});
}
@ -51,7 +51,7 @@ class HasCarQuery extends Query<HasCar, HasCarQueryWhere> {
@override
get fields {
return const ['id', 'type', 'created_at', 'updated_at'];
return const ['id', 'created_at', 'updated_at', 'type'];
}
@override
@ -68,9 +68,9 @@ class HasCarQuery extends Query<HasCar, HasCarQueryWhere> {
if (row.every((x) => x == null)) return null;
var model = HasCar(
id: row[0].toString(),
type: row[1] == null ? null : CarType.values[(row[1] as int)],
createdAt: (row[2] as DateTime),
updatedAt: (row[3] as DateTime));
createdAt: (row[1] as DateTime),
updatedAt: (row[2] as DateTime),
type: row[3] == null ? null : CarType.values[(row[3] as int)]);
return model;
}
@ -83,21 +83,21 @@ class HasCarQuery extends Query<HasCar, HasCarQueryWhere> {
class HasCarQueryWhere extends QueryWhere {
HasCarQueryWhere(HasCarQuery query)
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
type = EnumSqlExpressionBuilder<CarType>(query, 'type', (v) => v.index),
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 EnumSqlExpressionBuilder<CarType> type;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
final EnumSqlExpressionBuilder<CarType> type;
@override
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;
CarType get type {
return CarType.values[(values['type'] as int)];
}
set type(CarType value) => values['type'] = value?.index;
DateTime get createdAt {
return (values['created_at'] as DateTime);
}
@ -127,10 +122,15 @@ class HasCarQueryValues extends MapQueryValues {
}
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) {
type = model.type;
createdAt = model.createdAt;
updatedAt = model.updatedAt;
type = model.type;
}
}
@ -140,45 +140,48 @@ class HasCarQueryValues extends MapQueryValues {
@generatedSerializable
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
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
final CarType type;
@override
final DateTime createdAt;
@override
final DateTime updatedAt;
HasCar copyWith(
{String id, CarType type, DateTime createdAt, DateTime updatedAt}) {
return new HasCar(
{String id, DateTime createdAt, DateTime updatedAt, CarType type}) {
return HasCar(
id: id ?? this.id,
type: type ?? this.type,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt);
updatedAt: updatedAt ?? this.updatedAt,
type: type ?? this.type);
}
bool operator ==(other) {
return other is _HasCar &&
other.id == id &&
other.type == type &&
other.createdAt == createdAt &&
other.updatedAt == updatedAt;
other.updatedAt == updatedAt &&
other.type == type;
}
@override
int get hashCode {
return hashObjects([id, type, createdAt, updatedAt]);
return hashObjects([id, createdAt, updatedAt, type]);
}
@override
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() {
@ -190,7 +193,7 @@ class HasCar extends _HasCar {
// SerializerGenerator
// **************************************************************************
const HasCarSerializer hasCarSerializer = const HasCarSerializer();
const HasCarSerializer hasCarSerializer = HasCarSerializer();
class HasCarEncoder extends Converter<HasCar, Map> {
const HasCarEncoder();
@ -215,16 +218,11 @@ class HasCarSerializer extends Codec<HasCar, Map> {
get decoder => const HasCarDecoder();
static HasCar fromMap(Map map) {
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,
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
? (map['created_at'] is DateTime
? (map['created_at'] as DateTime)
@ -234,7 +232,12 @@ class HasCarSerializer extends Codec<HasCar, Map> {
? (map['updated_at'] is DateTime
? (map['updated_at'] as DateTime)
: 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) {
@ -242,14 +245,14 @@ class HasCarSerializer extends Codec<HasCar, Map> {
return null;
}
if (model.type == null) {
throw new FormatException("Missing required field 'type' on HasCar.");
throw FormatException("Missing required field 'type' on HasCar.");
}
return {
'id': model.id,
'type': model.type == null ? null : CarType.values.indexOf(model.type),
'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 {
static const List<String> allFields = <String>[
id,
type,
createdAt,
updatedAt
updatedAt,
type
];
static const String id = 'id';
static const String type = 'type';
static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at';
static const String type = 'type';
}

View file

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

View file

@ -11,9 +11,9 @@ class LegMigration extends Migration {
up(Schema schema) {
schema.create('legs', (table) {
table.serial('id')..primaryKey();
table.varChar('name');
table.timeStamp('created_at');
table.timeStamp('updated_at');
table.varChar('name');
});
}
@ -28,10 +28,10 @@ class FootMigration extends Migration {
up(Schema schema) {
schema.create('feet', (table) {
table.serial('id')..primaryKey();
table.integer('leg_id');
table.declare('n_toes', ColumnType('decimal'));
table.timeStamp('created_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',
additionalFields: const [
'id',
'leg_id',
'n_toes',
'created_at',
'updated_at'
'updated_at',
'leg_id',
'n_toes'
],
trampoline: trampoline);
}
@ -78,7 +78,7 @@ class LegQuery extends Query<Leg, LegQueryWhere> {
@override
get fields {
return const ['id', 'name', 'created_at', 'updated_at'];
return const ['id', 'created_at', 'updated_at', 'name'];
}
@override
@ -95,9 +95,9 @@ class LegQuery extends Query<Leg, LegQueryWhere> {
if (row.every((x) => x == null)) return null;
var model = Leg(
id: row[0].toString(),
name: (row[1] as String),
createdAt: (row[2] as DateTime),
updatedAt: (row[3] as DateTime));
createdAt: (row[1] as DateTime),
updatedAt: (row[2] as DateTime),
name: (row[3] as String));
if (row.length > 4) {
model = model.copyWith(
foot: FootQuery.parseRow(row.skip(4).take(5).toList()));
@ -114,21 +114,21 @@ class LegQuery extends Query<Leg, LegQueryWhere> {
class LegQueryWhere extends QueryWhere {
LegQueryWhere(LegQuery query)
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
name = StringSqlExpressionBuilder(query, 'name'),
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
name = StringSqlExpressionBuilder(query, 'name');
final NumericSqlExpressionBuilder<int> id;
final StringSqlExpressionBuilder name;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
final StringSqlExpressionBuilder name;
@override
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;
String get name {
return (values['name'] as String);
}
set name(String value) => values['name'] = value;
DateTime get createdAt {
return (values['created_at'] as DateTime);
}
@ -158,10 +153,15 @@ class LegQueryValues extends MapQueryValues {
}
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) {
name = model.name;
createdAt = model.createdAt;
updatedAt = model.updatedAt;
name = model.name;
}
}
@ -189,7 +189,7 @@ class FootQuery extends Query<Foot, FootQueryWhere> {
@override
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
@ -206,10 +206,10 @@ class FootQuery extends Query<Foot, FootQueryWhere> {
if (row.every((x) => x == null)) return null;
var model = Foot(
id: row[0].toString(),
legId: (row[1] as int),
nToes: double.tryParse(row[2].toString()),
createdAt: (row[3] as DateTime),
updatedAt: (row[4] as DateTime));
createdAt: (row[1] as DateTime),
updatedAt: (row[2] as DateTime),
legId: (row[3] as int),
nToes: double.tryParse(row[4].toString()));
return model;
}
@ -222,24 +222,24 @@ class FootQuery extends Query<Foot, FootQueryWhere> {
class FootQueryWhere extends QueryWhere {
FootQueryWhere(FootQuery query)
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
legId = NumericSqlExpressionBuilder<int>(query, 'leg_id'),
nToes = NumericSqlExpressionBuilder<double>(query, 'n_toes'),
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> legId;
final NumericSqlExpressionBuilder<double> nToes;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
final NumericSqlExpressionBuilder<int> legId;
final NumericSqlExpressionBuilder<double> nToes;
@override
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;
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 {
return (values['created_at'] as DateTime);
}
@ -274,11 +264,21 @@ class FootQueryValues extends MapQueryValues {
}
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) {
legId = model.legId;
nToes = model.nToes;
createdAt = model.createdAt;
updatedAt = model.updatedAt;
legId = model.legId;
nToes = model.nToes;
}
}
@ -288,54 +288,57 @@ class FootQueryValues extends MapQueryValues {
@generatedSerializable
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
final String id;
_Foot foot;
@override
final _Foot foot;
@override
final String name;
@override
final DateTime createdAt;
@override
final DateTime updatedAt;
String name;
Leg copyWith(
{String id,
_Foot foot,
String name,
DateTime createdAt,
DateTime updatedAt}) {
return new Leg(
DateTime updatedAt,
_Foot foot,
String name}) {
return Leg(
id: id ?? this.id,
foot: foot ?? this.foot,
name: name ?? this.name,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt);
updatedAt: updatedAt ?? this.updatedAt,
foot: foot ?? this.foot,
name: name ?? this.name);
}
bool operator ==(other) {
return other is _Leg &&
other.id == id &&
other.foot == foot &&
other.name == name &&
other.createdAt == createdAt &&
other.updatedAt == updatedAt;
other.updatedAt == updatedAt &&
other.foot == foot &&
other.name == name;
}
@override
int get hashCode {
return hashObjects([id, foot, name, createdAt, updatedAt]);
return hashObjects([id, createdAt, updatedAt, foot, name]);
}
@override
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() {
@ -345,54 +348,57 @@ class Leg extends _Leg {
@generatedSerializable
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
final String id;
int legId;
@override
final int legId;
@override
final double nToes;
@override
final DateTime createdAt;
@override
final DateTime updatedAt;
double nToes;
Foot copyWith(
{String id,
int legId,
double nToes,
DateTime createdAt,
DateTime updatedAt}) {
return new Foot(
DateTime updatedAt,
int legId,
double nToes}) {
return Foot(
id: id ?? this.id,
legId: legId ?? this.legId,
nToes: nToes ?? this.nToes,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt);
updatedAt: updatedAt ?? this.updatedAt,
legId: legId ?? this.legId,
nToes: nToes ?? this.nToes);
}
bool operator ==(other) {
return other is _Foot &&
other.id == id &&
other.legId == legId &&
other.nToes == nToes &&
other.createdAt == createdAt &&
other.updatedAt == updatedAt;
other.updatedAt == updatedAt &&
other.legId == legId &&
other.nToes == nToes;
}
@override
int get hashCode {
return hashObjects([id, legId, nToes, createdAt, updatedAt]);
return hashObjects([id, createdAt, updatedAt, legId, nToes]);
}
@override
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() {
@ -404,7 +410,7 @@ class Foot extends _Foot {
// SerializerGenerator
// **************************************************************************
const LegSerializer legSerializer = const LegSerializer();
const LegSerializer legSerializer = LegSerializer();
class LegEncoder extends Converter<Leg, Map> {
const LegEncoder();
@ -428,12 +434,8 @@ class LegSerializer extends Codec<Leg, Map> {
@override
get decoder => const LegDecoder();
static Leg fromMap(Map map) {
return new Leg(
return Leg(
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
? (map['created_at'] is DateTime
? (map['created_at'] as DateTime)
@ -443,7 +445,11 @@ class LegSerializer extends Codec<Leg, Map> {
? (map['updated_at'] is DateTime
? (map['updated_at'] as DateTime)
: 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) {
@ -452,10 +458,10 @@ class LegSerializer extends Codec<Leg, Map> {
}
return {
'id': model.id,
'foot': FootSerializer.toMap(model.foot),
'name': model.name,
'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 {
static const List<String> allFields = <String>[
id,
foot,
name,
createdAt,
updatedAt
updatedAt,
foot,
name
];
static const String id = 'id';
static const String foot = 'foot';
static const String name = 'name';
static const String createdAt = 'created_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> {
const FootEncoder();
@ -504,10 +510,8 @@ class FootSerializer extends Codec<Foot, Map> {
@override
get decoder => const FootDecoder();
static Foot fromMap(Map map) {
return new Foot(
return Foot(
id: map['id'] as String,
legId: map['leg_id'] as int,
nToes: map['n_toes'] as double,
createdAt: map['created_at'] != null
? (map['created_at'] is DateTime
? (map['created_at'] as DateTime)
@ -517,7 +521,9 @@ class FootSerializer extends Codec<Foot, Map> {
? (map['updated_at'] is DateTime
? (map['updated_at'] as DateTime)
: 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) {
@ -526,10 +532,10 @@ class FootSerializer extends Codec<Foot, Map> {
}
return {
'id': model.id,
'leg_id': model.legId,
'n_toes': model.nToes,
'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 {
static const List<String> allFields = <String>[
id,
legId,
nToes,
createdAt,
updatedAt
updatedAt,
legId,
nToes
];
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 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) {
schema.create('orders', (table) {
table.serial('id')..primaryKey();
table.timeStamp('created_at');
table.timeStamp('updated_at');
table.integer('employee_id');
table.timeStamp('order_date');
table.integer('shipper_id');
table.timeStamp('created_at');
table.timeStamp('updated_at');
table.integer('customer_id').references('customers', 'id');
});
}
@ -75,12 +75,12 @@ class OrderQuery extends Query<Order, OrderQueryWhere> {
get fields {
return const [
'id',
'created_at',
'updated_at',
'customer_id',
'employee_id',
'order_date',
'shipper_id',
'created_at',
'updated_at'
'shipper_id'
];
}
@ -98,11 +98,11 @@ class OrderQuery extends Query<Order, OrderQueryWhere> {
if (row.every((x) => x == null)) return null;
var model = Order(
id: row[0].toString(),
employeeId: (row[2] as int),
orderDate: (row[3] as DateTime),
shipperId: (row[4] as int),
createdAt: (row[5] as DateTime),
updatedAt: (row[6] as DateTime));
createdAt: (row[1] as DateTime),
updatedAt: (row[2] as DateTime),
employeeId: (row[4] as int),
orderDate: (row[5] as DateTime),
shipperId: (row[6] as int));
if (row.length > 7) {
model = model.copyWith(
customer: CustomerQuery.parseRow(row.skip(7).take(3).toList()));
@ -119,15 +119,19 @@ class OrderQuery extends Query<Order, OrderQueryWhere> {
class OrderQueryWhere extends QueryWhere {
OrderQueryWhere(OrderQuery query)
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
customerId = NumericSqlExpressionBuilder<int>(query, 'customer_id'),
employeeId = NumericSqlExpressionBuilder<int>(query, 'employee_id'),
orderDate = DateTimeSqlExpressionBuilder(query, 'order_date'),
shipperId = NumericSqlExpressionBuilder<int>(query, 'shipper_id'),
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
shipperId = NumericSqlExpressionBuilder<int>(query, 'shipper_id');
final NumericSqlExpressionBuilder<int> id;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
final NumericSqlExpressionBuilder<int> customerId;
final NumericSqlExpressionBuilder<int> employeeId;
@ -136,20 +140,16 @@ class OrderQueryWhere extends QueryWhere {
final NumericSqlExpressionBuilder<int> shipperId;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
@override
get expressionBuilders {
return [
id,
createdAt,
updatedAt,
customerId,
employeeId,
orderDate,
shipperId,
createdAt,
updatedAt
shipperId
];
}
}
@ -165,6 +165,16 @@ class OrderQueryValues extends MapQueryValues {
}
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 {
return (values['customer_id'] as int);
}
@ -185,22 +195,12 @@ class OrderQueryValues extends MapQueryValues {
}
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) {
createdAt = model.createdAt;
updatedAt = model.updatedAt;
employeeId = model.employeeId;
orderDate = model.orderDate;
shipperId = model.shipperId;
createdAt = model.createdAt;
updatedAt = model.updatedAt;
if (model.customer != null) {
values['customer_id'] = model.customer.id;
}
@ -312,15 +312,24 @@ class CustomerQueryValues extends MapQueryValues {
class Order extends _Order {
Order(
{this.id,
this.createdAt,
this.updatedAt,
this.customer,
this.employeeId,
this.orderDate,
this.shipperId,
this.createdAt,
this.updatedAt});
this.shipperId});
/// A unique identifier corresponding to this item.
@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
final _Customer customer;
@ -334,50 +343,44 @@ class Order extends _Order {
@override
final int shipperId;
@override
final DateTime createdAt;
@override
final DateTime updatedAt;
Order copyWith(
{String id,
DateTime createdAt,
DateTime updatedAt,
_Customer customer,
int employeeId,
DateTime orderDate,
int shipperId,
DateTime createdAt,
DateTime updatedAt}) {
return new Order(
int shipperId}) {
return Order(
id: id ?? this.id,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
customer: customer ?? this.customer,
employeeId: employeeId ?? this.employeeId,
orderDate: orderDate ?? this.orderDate,
shipperId: shipperId ?? this.shipperId,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt);
shipperId: shipperId ?? this.shipperId);
}
bool operator ==(other) {
return other is _Order &&
other.id == id &&
other.createdAt == createdAt &&
other.updatedAt == updatedAt &&
other.customer == customer &&
other.employeeId == employeeId &&
other.orderDate == orderDate &&
other.shipperId == shipperId &&
other.createdAt == createdAt &&
other.updatedAt == updatedAt;
other.shipperId == shipperId;
}
@override
int get hashCode {
return hashObjects(
[id, customer, employeeId, orderDate, shipperId, createdAt, updatedAt]);
[id, createdAt, updatedAt, customer, employeeId, orderDate, shipperId]);
}
@override
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() {
@ -389,17 +392,20 @@ class Order extends _Order {
class Customer extends _Customer {
Customer({this.id, this.createdAt, this.updatedAt});
/// A unique identifier corresponding to this item.
@override
final String id;
String id;
/// The time at which this item was created.
@override
final DateTime createdAt;
DateTime createdAt;
/// The last time at which this item was updated.
@override
final DateTime updatedAt;
DateTime updatedAt;
Customer copyWith({String id, DateTime createdAt, DateTime updatedAt}) {
return new Customer(
return Customer(
id: id ?? this.id,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt);
@ -431,7 +437,7 @@ class Customer extends _Customer {
// SerializerGenerator
// **************************************************************************
const OrderSerializer orderSerializer = const OrderSerializer();
const OrderSerializer orderSerializer = OrderSerializer();
class OrderEncoder extends Converter<Order, Map> {
const OrderEncoder();
@ -455,18 +461,8 @@ class OrderSerializer extends Codec<Order, Map> {
@override
get decoder => const OrderDecoder();
static Order fromMap(Map map) {
return new Order(
return Order(
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
? (map['created_at'] is DateTime
? (map['created_at'] as DateTime)
@ -476,7 +472,17 @@ class OrderSerializer extends Codec<Order, Map> {
? (map['updated_at'] is DateTime
? (map['updated_at'] as DateTime)
: 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) {
@ -485,12 +491,12 @@ class OrderSerializer extends Codec<Order, Map> {
}
return {
'id': model.id,
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String(),
'customer': CustomerSerializer.toMap(model.customer),
'employee_id': model.employeeId,
'order_date': model.orderDate?.toIso8601String(),
'shipper_id': model.shipperId,
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String()
'shipper_id': model.shipperId
};
}
}
@ -498,16 +504,20 @@ class OrderSerializer extends Codec<Order, Map> {
abstract class OrderFields {
static const List<String> allFields = <String>[
id,
createdAt,
updatedAt,
customer,
employeeId,
orderDate,
shipperId,
createdAt,
updatedAt
shipperId
];
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 employeeId = 'employee_id';
@ -515,13 +525,9 @@ abstract class OrderFields {
static const String orderDate = 'order_date';
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> {
const CustomerEncoder();
@ -545,7 +551,7 @@ class CustomerSerializer extends Codec<Customer, Map> {
@override
get decoder => const CustomerDecoder();
static Customer fromMap(Map map) {
return new Customer(
return Customer(
id: map['id'] as String,
createdAt: map['created_at'] != null
? (map['created_at'] is DateTime

View file

@ -11,9 +11,9 @@ class TreeMigration extends Migration {
up(Schema schema) {
schema.create('trees', (table) {
table.serial('id')..primaryKey();
table.declare('rings', ColumnType('smallint'));
table.timeStamp('created_at');
table.timeStamp('updated_at');
table.declare('rings', ColumnType('smallint'));
});
}
@ -28,10 +28,10 @@ class FruitMigration extends Migration {
up(Schema schema) {
schema.create('fruits', (table) {
table.serial('id')..primaryKey();
table.integer('tree_id');
table.varChar('common_name');
table.timeStamp('created_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',
additionalFields: const [
'id',
'tree_id',
'common_name',
'created_at',
'updated_at'
'updated_at',
'tree_id',
'common_name'
],
trampoline: trampoline);
}
@ -78,7 +78,7 @@ class TreeQuery extends Query<Tree, TreeQueryWhere> {
@override
get fields {
return const ['id', 'rings', 'created_at', 'updated_at'];
return const ['id', 'created_at', 'updated_at', 'rings'];
}
@override
@ -95,9 +95,9 @@ class TreeQuery extends Query<Tree, TreeQueryWhere> {
if (row.every((x) => x == null)) return null;
var model = Tree(
id: row[0].toString(),
rings: (row[1] as int),
createdAt: (row[2] as DateTime),
updatedAt: (row[3] as DateTime));
createdAt: (row[1] as DateTime),
updatedAt: (row[2] as DateTime),
rings: (row[3] as int));
if (row.length > 4) {
model = model.copyWith(
fruits: [FruitQuery.parseRow(row.skip(4).take(5).toList())]
@ -173,21 +173,21 @@ class TreeQuery extends Query<Tree, TreeQueryWhere> {
class TreeQueryWhere extends QueryWhere {
TreeQueryWhere(TreeQuery query)
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
rings = NumericSqlExpressionBuilder<int>(query, 'rings'),
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> rings;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
final NumericSqlExpressionBuilder<int> rings;
@override
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;
int get rings {
return (values['rings'] as int);
}
set rings(int value) => values['rings'] = value;
DateTime get createdAt {
return (values['created_at'] as DateTime);
}
@ -217,10 +212,15 @@ class TreeQueryValues extends MapQueryValues {
}
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) {
rings = model.rings;
createdAt = model.createdAt;
updatedAt = model.updatedAt;
rings = model.rings;
}
}
@ -248,7 +248,7 @@ class FruitQuery extends Query<Fruit, FruitQueryWhere> {
@override
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
@ -265,10 +265,10 @@ class FruitQuery extends Query<Fruit, FruitQueryWhere> {
if (row.every((x) => x == null)) return null;
var model = Fruit(
id: row[0].toString(),
treeId: (row[1] as int),
commonName: (row[2] as String),
createdAt: (row[3] as DateTime),
updatedAt: (row[4] as DateTime));
createdAt: (row[1] as DateTime),
updatedAt: (row[2] as DateTime),
treeId: (row[3] as int),
commonName: (row[4] as String));
return model;
}
@ -281,24 +281,24 @@ class FruitQuery extends Query<Fruit, FruitQueryWhere> {
class FruitQueryWhere extends QueryWhere {
FruitQueryWhere(FruitQuery query)
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
treeId = NumericSqlExpressionBuilder<int>(query, 'tree_id'),
commonName = StringSqlExpressionBuilder(query, 'common_name'),
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> treeId;
final StringSqlExpressionBuilder commonName;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
final NumericSqlExpressionBuilder<int> treeId;
final StringSqlExpressionBuilder commonName;
@override
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;
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 {
return (values['created_at'] as DateTime);
}
@ -333,11 +323,21 @@ class FruitQueryValues extends MapQueryValues {
}
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) {
treeId = model.treeId;
commonName = model.commonName;
createdAt = model.createdAt;
updatedAt = model.updatedAt;
treeId = model.treeId;
commonName = model.commonName;
}
}
@ -349,59 +349,62 @@ class FruitQueryValues extends MapQueryValues {
class Tree extends _Tree {
Tree(
{this.id,
this.rings,
List<_Fruit> fruits,
this.createdAt,
this.updatedAt})
: this.fruits = new List.unmodifiable(fruits ?? []);
this.updatedAt,
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
final String id;
int rings;
@override
final int rings;
@override
final List<_Fruit> fruits;
@override
final DateTime createdAt;
@override
final DateTime updatedAt;
List<_Fruit> fruits;
Tree copyWith(
{String id,
int rings,
List<_Fruit> fruits,
DateTime createdAt,
DateTime updatedAt}) {
return new Tree(
DateTime updatedAt,
int rings,
List<_Fruit> fruits}) {
return Tree(
id: id ?? this.id,
rings: rings ?? this.rings,
fruits: fruits ?? this.fruits,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt);
updatedAt: updatedAt ?? this.updatedAt,
rings: rings ?? this.rings,
fruits: fruits ?? this.fruits);
}
bool operator ==(other) {
return other is _Tree &&
other.id == id &&
other.rings == rings &&
const ListEquality<_Fruit>(const DefaultEquality<_Fruit>())
.equals(other.fruits, fruits) &&
other.createdAt == createdAt &&
other.updatedAt == updatedAt;
other.updatedAt == updatedAt &&
other.rings == rings &&
ListEquality<_Fruit>(DefaultEquality<_Fruit>())
.equals(other.fruits, fruits);
}
@override
int get hashCode {
return hashObjects([id, rings, fruits, createdAt, updatedAt]);
return hashObjects([id, createdAt, updatedAt, rings, fruits]);
}
@override
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() {
@ -412,54 +415,57 @@ class Tree extends _Tree {
@generatedSerializable
class Fruit extends _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
final String id;
int treeId;
@override
final int treeId;
@override
final String commonName;
@override
final DateTime createdAt;
@override
final DateTime updatedAt;
String commonName;
Fruit copyWith(
{String id,
int treeId,
String commonName,
DateTime createdAt,
DateTime updatedAt}) {
return new Fruit(
DateTime updatedAt,
int treeId,
String commonName}) {
return Fruit(
id: id ?? this.id,
treeId: treeId ?? this.treeId,
commonName: commonName ?? this.commonName,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt);
updatedAt: updatedAt ?? this.updatedAt,
treeId: treeId ?? this.treeId,
commonName: commonName ?? this.commonName);
}
bool operator ==(other) {
return other is _Fruit &&
other.id == id &&
other.treeId == treeId &&
other.commonName == commonName &&
other.createdAt == createdAt &&
other.updatedAt == updatedAt;
other.updatedAt == updatedAt &&
other.treeId == treeId &&
other.commonName == commonName;
}
@override
int get hashCode {
return hashObjects([id, treeId, commonName, createdAt, updatedAt]);
return hashObjects([id, createdAt, updatedAt, treeId, commonName]);
}
@override
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() {
@ -471,7 +477,7 @@ class Fruit extends _Fruit {
// SerializerGenerator
// **************************************************************************
const TreeSerializer treeSerializer = const TreeSerializer();
const TreeSerializer treeSerializer = TreeSerializer();
class TreeEncoder extends Converter<Tree, Map> {
const TreeEncoder();
@ -495,15 +501,8 @@ class TreeSerializer extends Codec<Tree, Map> {
@override
get decoder => const TreeDecoder();
static Tree fromMap(Map map) {
return new Tree(
return Tree(
id: map['id'] as String,
rings: map['rings'] as int,
fruits: map['fruits'] is Iterable
? new List.unmodifiable(
((map['fruits'] as Iterable).where((x) => x is Map))
.cast<Map>()
.map(FruitSerializer.fromMap))
: null,
createdAt: map['created_at'] != null
? (map['created_at'] is DateTime
? (map['created_at'] as DateTime)
@ -513,6 +512,11 @@ class TreeSerializer extends Codec<Tree, Map> {
? (map['updated_at'] is DateTime
? (map['updated_at'] as DateTime)
: 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);
}
@ -522,10 +526,10 @@ class TreeSerializer extends Codec<Tree, Map> {
}
return {
'id': model.id,
'rings': model.rings,
'fruits': model.fruits?.map((m) => FruitSerializer.toMap(m))?.toList(),
'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 {
static const List<String> allFields = <String>[
id,
rings,
fruits,
createdAt,
updatedAt
updatedAt,
rings,
fruits
];
static const String id = 'id';
static const String rings = 'rings';
static const String fruits = 'fruits';
static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at';
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> {
const FruitEncoder();
@ -574,10 +578,8 @@ class FruitSerializer extends Codec<Fruit, Map> {
@override
get decoder => const FruitDecoder();
static Fruit fromMap(Map map) {
return new Fruit(
return Fruit(
id: map['id'] as String,
treeId: map['tree_id'] as int,
commonName: map['common_name'] as String,
createdAt: map['created_at'] != null
? (map['created_at'] is DateTime
? (map['created_at'] as DateTime)
@ -587,7 +589,9 @@ class FruitSerializer extends Codec<Fruit, Map> {
? (map['updated_at'] is DateTime
? (map['updated_at'] as DateTime)
: 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) {
@ -596,10 +600,10 @@ class FruitSerializer extends Codec<Fruit, Map> {
}
return {
'id': model.id,
'tree_id': model.treeId,
'common_name': model.commonName,
'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 {
static const List<String> allFields = <String>[
id,
treeId,
commonName,
createdAt,
updatedAt
updatedAt,
treeId,
commonName
];
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 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) {
schema.create('songs', (table) {
table.serial('id')..primaryKey();
table.integer('weird_join_id');
table.varChar('title');
table.timeStamp('created_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',
additionalFields: const [
'id',
'weird_join_id',
'title',
'created_at',
'updated_at'
'updated_at',
'weird_join_id',
'title'
],
trampoline: trampoline);
leftJoin(NumbaQuery(trampoline: trampoline), 'id', 'parent',
@ -388,7 +388,7 @@ class SongQuery extends Query<Song, SongQueryWhere> {
@override
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
@ -405,10 +405,10 @@ class SongQuery extends Query<Song, SongQueryWhere> {
if (row.every((x) => x == null)) return null;
var model = Song(
id: row[0].toString(),
weirdJoinId: (row[1] as int),
title: (row[2] as String),
createdAt: (row[3] as DateTime),
updatedAt: (row[4] as DateTime));
createdAt: (row[1] as DateTime),
updatedAt: (row[2] as DateTime),
weirdJoinId: (row[3] as int),
title: (row[4] as String));
return model;
}
@ -421,24 +421,24 @@ class SongQuery extends Query<Song, SongQueryWhere> {
class SongQueryWhere extends QueryWhere {
SongQueryWhere(SongQuery query)
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
weirdJoinId = NumericSqlExpressionBuilder<int>(query, 'weird_join_id'),
title = StringSqlExpressionBuilder(query, 'title'),
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> weirdJoinId;
final StringSqlExpressionBuilder title;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
final NumericSqlExpressionBuilder<int> weirdJoinId;
final StringSqlExpressionBuilder title;
@override
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;
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 {
return (values['created_at'] as DateTime);
}
@ -473,11 +463,21 @@ class SongQueryValues extends MapQueryValues {
}
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) {
weirdJoinId = model.weirdJoinId;
title = model.title;
createdAt = model.createdAt;
updatedAt = model.updatedAt;
weirdJoinId = model.weirdJoinId;
title = model.title;
}
}
@ -829,7 +829,7 @@ class Unorthodox implements _Unorthodox {
final String name;
Unorthodox copyWith({String name}) {
return new Unorthodox(name: name ?? this.name);
return Unorthodox(name: name ?? this.name);
}
bool operator ==(other) {
@ -854,11 +854,7 @@ class Unorthodox implements _Unorthodox {
@generatedSerializable
class WeirdJoin implements _WeirdJoin {
const WeirdJoin(
{this.id,
this.unorthodox,
this.song,
List<_Numba> this.numbas,
List<_Foo> this.foos});
{this.id, this.unorthodox, this.song, this.numbas, this.foos});
@override
final int id;
@ -881,7 +877,7 @@ class WeirdJoin implements _WeirdJoin {
_Song song,
List<_Numba> numbas,
List<_Foo> foos}) {
return new WeirdJoin(
return WeirdJoin(
id: id ?? this.id,
unorthodox: unorthodox ?? this.unorthodox,
song: song ?? this.song,
@ -894,10 +890,9 @@ class WeirdJoin implements _WeirdJoin {
other.id == id &&
other.unorthodox == unorthodox &&
other.song == song &&
const ListEquality<_Numba>(const DefaultEquality<_Numba>())
ListEquality<_Numba>(DefaultEquality<_Numba>())
.equals(other.numbas, numbas) &&
const ListEquality<_Foo>(const DefaultEquality<_Foo>())
.equals(other.foos, foos);
ListEquality<_Foo>(DefaultEquality<_Foo>()).equals(other.foos, foos);
}
@override
@ -917,10 +912,19 @@ class WeirdJoin implements _WeirdJoin {
@generatedSerializable
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
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
final int weirdJoinId;
@ -928,43 +932,37 @@ class Song extends _Song {
@override
final String title;
@override
final DateTime createdAt;
@override
final DateTime updatedAt;
Song copyWith(
{String id,
int weirdJoinId,
String title,
DateTime createdAt,
DateTime updatedAt}) {
return new Song(
DateTime updatedAt,
int weirdJoinId,
String title}) {
return Song(
id: id ?? this.id,
weirdJoinId: weirdJoinId ?? this.weirdJoinId,
title: title ?? this.title,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt);
updatedAt: updatedAt ?? this.updatedAt,
weirdJoinId: weirdJoinId ?? this.weirdJoinId,
title: title ?? this.title);
}
bool operator ==(other) {
return other is _Song &&
other.id == id &&
other.weirdJoinId == weirdJoinId &&
other.title == title &&
other.createdAt == createdAt &&
other.updatedAt == updatedAt;
other.updatedAt == updatedAt &&
other.weirdJoinId == weirdJoinId &&
other.title == title;
}
@override
int get hashCode {
return hashObjects([id, weirdJoinId, title, createdAt, updatedAt]);
return hashObjects([id, createdAt, updatedAt, weirdJoinId, title]);
}
@override
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() {
@ -977,13 +975,13 @@ class Numba extends _Numba {
Numba({this.i, this.parent});
@override
final int i;
int i;
@override
final int parent;
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) {
@ -1007,7 +1005,7 @@ class Numba extends _Numba {
@generatedSerializable
class Foo implements _Foo {
const Foo({this.bar, List<_WeirdJoin> this.weirdJoins});
const Foo({this.bar, this.weirdJoins});
@override
final String bar;
@ -1016,14 +1014,13 @@ class Foo implements _Foo {
final List<_WeirdJoin> weirdJoins;
Foo copyWith({String bar, List<_WeirdJoin> weirdJoins}) {
return new Foo(
bar: bar ?? this.bar, weirdJoins: weirdJoins ?? this.weirdJoins);
return Foo(bar: bar ?? this.bar, weirdJoins: weirdJoins ?? this.weirdJoins);
}
bool operator ==(other) {
return other is _Foo &&
other.bar == bar &&
const ListEquality<_WeirdJoin>(const DefaultEquality<_WeirdJoin>())
ListEquality<_WeirdJoin>(DefaultEquality<_WeirdJoin>())
.equals(other.weirdJoins, weirdJoins);
}
@ -1053,7 +1050,7 @@ class FooPivot implements _FooPivot {
final _Foo foo;
FooPivot copyWith({_WeirdJoin weirdJoin, _Foo foo}) {
return new FooPivot(
return FooPivot(
weirdJoin: weirdJoin ?? this.weirdJoin, foo: foo ?? this.foo);
}
@ -1082,7 +1079,7 @@ class FooPivot implements _FooPivot {
// SerializerGenerator
// **************************************************************************
const UnorthodoxSerializer unorthodoxSerializer = const UnorthodoxSerializer();
const UnorthodoxSerializer unorthodoxSerializer = UnorthodoxSerializer();
class UnorthodoxEncoder extends Converter<Unorthodox, Map> {
const UnorthodoxEncoder();
@ -1106,7 +1103,7 @@ class UnorthodoxSerializer extends Codec<Unorthodox, Map> {
@override
get decoder => const UnorthodoxDecoder();
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) {
@ -1123,7 +1120,7 @@ abstract class UnorthodoxFields {
static const String name = 'name';
}
const WeirdJoinSerializer weirdJoinSerializer = const WeirdJoinSerializer();
const WeirdJoinSerializer weirdJoinSerializer = WeirdJoinSerializer();
class WeirdJoinEncoder extends Converter<WeirdJoin, Map> {
const WeirdJoinEncoder();
@ -1147,7 +1144,7 @@ class WeirdJoinSerializer extends Codec<WeirdJoin, Map> {
@override
get decoder => const WeirdJoinDecoder();
static WeirdJoin fromMap(Map map) {
return new WeirdJoin(
return WeirdJoin(
id: map['id'] as int,
unorthodox: map['unorthodox'] != null
? UnorthodoxSerializer.fromMap(map['unorthodox'] as Map)
@ -1156,16 +1153,12 @@ class WeirdJoinSerializer extends Codec<WeirdJoin, Map> {
? SongSerializer.fromMap(map['song'] as Map)
: null,
numbas: map['numbas'] is Iterable
? new List.unmodifiable(
((map['numbas'] as Iterable).where((x) => x is Map))
.cast<Map>()
.map(NumbaSerializer.fromMap))
? List.unmodifiable(((map['numbas'] as Iterable).whereType<Map>())
.map(NumbaSerializer.fromMap))
: null,
foos: map['foos'] is Iterable
? new List.unmodifiable(
((map['foos'] as Iterable).where((x) => x is Map))
.cast<Map>()
.map(FooSerializer.fromMap))
? List.unmodifiable(((map['foos'] as Iterable).whereType<Map>())
.map(FooSerializer.fromMap))
: null);
}
@ -1203,7 +1196,7 @@ abstract class WeirdJoinFields {
static const String foos = 'foos';
}
const SongSerializer songSerializer = const SongSerializer();
const SongSerializer songSerializer = SongSerializer();
class SongEncoder extends Converter<Song, Map> {
const SongEncoder();
@ -1227,10 +1220,8 @@ class SongSerializer extends Codec<Song, Map> {
@override
get decoder => const SongDecoder();
static Song fromMap(Map map) {
return new Song(
return Song(
id: map['id'] as String,
weirdJoinId: map['weird_join_id'] as int,
title: map['title'] as String,
createdAt: map['created_at'] != null
? (map['created_at'] is DateTime
? (map['created_at'] as DateTime)
@ -1240,7 +1231,9 @@ class SongSerializer extends Codec<Song, Map> {
? (map['updated_at'] is DateTime
? (map['updated_at'] as DateTime)
: 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) {
@ -1249,10 +1242,10 @@ class SongSerializer extends Codec<Song, Map> {
}
return {
'id': model.id,
'weird_join_id': model.weirdJoinId,
'title': model.title,
'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 {
static const List<String> allFields = <String>[
id,
weirdJoinId,
title,
createdAt,
updatedAt
updatedAt,
weirdJoinId,
title
];
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 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> {
const NumbaEncoder();
@ -1301,7 +1294,7 @@ class NumbaSerializer extends Codec<Numba, Map> {
@override
get decoder => const NumbaDecoder();
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) {
@ -1320,7 +1313,7 @@ abstract class NumbaFields {
static const String parent = 'parent';
}
const FooSerializer fooSerializer = const FooSerializer();
const FooSerializer fooSerializer = FooSerializer();
class FooEncoder extends Converter<Foo, Map> {
const FooEncoder();
@ -1344,12 +1337,11 @@ class FooSerializer extends Codec<Foo, Map> {
@override
get decoder => const FooDecoder();
static Foo fromMap(Map map) {
return new Foo(
return Foo(
bar: map['bar'] as String,
weirdJoins: map['weird_joins'] is Iterable
? new List.unmodifiable(
((map['weird_joins'] as Iterable).where((x) => x is Map))
.cast<Map>()
? List.unmodifiable(
((map['weird_joins'] as Iterable).whereType<Map>())
.map(WeirdJoinSerializer.fromMap))
: null);
}
@ -1374,7 +1366,7 @@ abstract class FooFields {
static const String weirdJoins = 'weird_joins';
}
const FooPivotSerializer fooPivotSerializer = const FooPivotSerializer();
const FooPivotSerializer fooPivotSerializer = FooPivotSerializer();
class FooPivotEncoder extends Converter<FooPivot, Map> {
const FooPivotEncoder();
@ -1398,7 +1390,7 @@ class FooPivotSerializer extends Codec<FooPivot, Map> {
@override
get decoder => const FooPivotDecoder();
static FooPivot fromMap(Map map) {
return new FooPivot(
return FooPivot(
weirdJoin: map['weird_join'] != null
? WeirdJoinSerializer.fromMap(map['weird_join'] as Map)
: null,

View file

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