ORM deps broken

This commit is contained in:
Tobe O 2019-02-06 22:27:47 -05:00
parent 8dfcdc1f5f
commit e87c92a48b
18 changed files with 201 additions and 576 deletions

View file

@ -280,9 +280,10 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
return ss; return ss;
})); }));
_joins.forEach((j) { _joins.forEach((j) {
f var additional = j.additionalFields.map((s) => j.nameFor(s)).toList();
..add(j.fieldName) // if (!additional.contains(j.fieldName))
..addAll(j.additionalFields.map((s) => j.nameFor(s))); // additional.insert(0, j.fieldName);
f.addAll(additional);
}); });
} }
if (withFields) b.write(f.join(', ')); if (withFields) b.write(f.join(', '));

View file

@ -30,7 +30,7 @@ targets:
- test/models/role.dart - test/models/role.dart
$default: $default:
dependencies: dependencies:
- :_standalone - angel_orm:_standalone
sources: sources:
- test/models/book.dart - test/models/book.dart
- test/models/has_car.dart - test/models/has_car.dart

View file

@ -177,13 +177,14 @@ Future<OrmBuildContext> buildOrmContext(
ctx.buildContext.aliases[name] = relation.localKey; ctx.buildContext.aliases[name] = relation.localKey;
if (!ctx.effectiveFields.any((f) => f.name == field.name)) { if (!ctx.effectiveFields.any((f) => f.name == field.name)) {
if (field.name != 'id' || // TODO: Consequences of allowing ID to be a relation? (should be none)
!const TypeChecker.fromRuntime(Model) // if (field.name != 'id' ||
.isAssignableFromType(ctx.buildContext.clazz.type)) { // !const TypeChecker.fromRuntime(Model)
var rf = new RelationFieldImpl(name, // .isAssignableFromType(ctx.buildContext.clazz.type)) {
field.type.element.context.typeProvider.intType, field.name); var rf = new RelationFieldImpl(name,
ctx.effectiveFields.add(rf); field.type.element.context.typeProvider.intType, field.name);
} ctx.effectiveFields.add(rf);
// }
} }
} }

View file

@ -281,7 +281,7 @@ class OrmGenerator extends GeneratorForAnnotation<Orm> {
relation.type == RelationshipType.hasMany) { relation.type == RelationshipType.hasMany) {
var foreign = ctx.relationTypes[relation]; var foreign = ctx.relationTypes[relation];
var additionalFields = foreign.effectiveFields var additionalFields = foreign.effectiveFields
.where((f) => f.name != 'id' || !isSpecialId(ctx, f)) // .where((f) => f.name != 'id' || !isSpecialId(ctx, f))
.map((f) => literalString( .map((f) => literalString(
foreign.buildContext.resolveFieldName(f.name))); foreign.buildContext.resolveFieldName(f.name)));
var joinArgs = [relation.localKey, relation.foreignKey] var joinArgs = [relation.localKey, relation.foreignKey]

View file

@ -34,6 +34,6 @@ dev_dependencies:
collection: ^1.0.0 collection: ^1.0.0
postgres: ^1.0.0 postgres: ^1.0.0
test: ^1.0.0 test: ^1.0.0
# dependency_overrides: dependency_overrides:
# angel_orm: angel_orm:
# path: ../angel_orm path: ../angel_orm

View file

@ -17,6 +17,7 @@ main() {
}); });
test('sets to null if no child', () async { test('sets to null if no child', () async {
print(LegQuery().compile(Set()));
var query = new LegQuery()..where.id.equals(int.parse(originalLeg.id)); var query = new LegQuery()..where.id.equals(int.parse(originalLeg.id));
var leg = await query.getOne(executor); var leg = await query.getOne(executor);
print(leg.toJson()); print(leg.toJson());

View file

@ -31,11 +31,11 @@ class AuthorQuery extends Query<Author, AuthorQueryWhere> {
AuthorQuery({Set<String> trampoline}) { AuthorQuery({Set<String> trampoline}) {
trampoline ??= Set(); trampoline ??= Set();
trampoline.add(tableName); trampoline.add(tableName);
_where = new AuthorQueryWhere(this); _where = AuthorQueryWhere(this);
} }
@override @override
final AuthorQueryValues values = new AuthorQueryValues(); final AuthorQueryValues values = AuthorQueryValues();
AuthorQueryWhere _where; AuthorQueryWhere _where;
@ -61,12 +61,12 @@ class AuthorQuery extends Query<Author, AuthorQueryWhere> {
@override @override
AuthorQueryWhere newWhereClause() { AuthorQueryWhere newWhereClause() {
return new AuthorQueryWhere(this); return AuthorQueryWhere(this);
} }
static Author parseRow(List row) { static Author parseRow(List row) {
if (row.every((x) => x == null)) return null; if (row.every((x) => x == null)) return null;
var model = new Author( var model = Author(
id: row[0].toString(), id: row[0].toString(),
name: (row[1] as String), name: (row[1] as String),
createdAt: (row[2] as DateTime), createdAt: (row[2] as DateTime),
@ -82,10 +82,10 @@ class AuthorQuery extends Query<Author, AuthorQueryWhere> {
class AuthorQueryWhere extends QueryWhere { class AuthorQueryWhere extends QueryWhere {
AuthorQueryWhere(AuthorQuery query) AuthorQueryWhere(AuthorQuery query)
: id = new NumericSqlExpressionBuilder<int>(query, 'id'), : id = NumericSqlExpressionBuilder<int>(query, 'id'),
name = new StringSqlExpressionBuilder(query, 'name'), name = StringSqlExpressionBuilder(query, 'name'),
createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at'); updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
final NumericSqlExpressionBuilder<int> id; final NumericSqlExpressionBuilder<int> id;
@ -140,7 +140,11 @@ class AuthorQueryValues extends MapQueryValues {
@generatedSerializable @generatedSerializable
class Author extends _Author { class Author extends _Author {
Author({this.id, this.name: 'Tobe Osakwe', this.createdAt, this.updatedAt}); Author(
{this.id,
@required this.name = 'Tobe Osakwe',
this.createdAt,
this.updatedAt});
@override @override
final String id; final String id;
@ -187,6 +191,10 @@ class Author extends _Author {
abstract class AuthorSerializer { abstract class AuthorSerializer {
static Author fromMap(Map map) { static Author fromMap(Map map) {
if (map['name'] == null) {
throw new FormatException("Missing required field 'name' on Author.");
}
return new Author( return new Author(
id: map['id'] as String, id: map['id'] as String,
name: map['name'] as String ?? 'Tobe Osakwe', name: map['name'] as String ?? 'Tobe Osakwe',
@ -206,6 +214,10 @@ abstract class AuthorSerializer {
if (model == null) { if (model == null) {
return null; return null;
} }
if (model.name == null) {
throw new FormatException("Missing required field 'name' on Author.");
}
return { return {
'id': model.id, 'id': model.id,
'name': model.name, 'name': model.name,
@ -216,7 +228,7 @@ abstract class AuthorSerializer {
} }
abstract class AuthorFields { abstract class AuthorFields {
static const List<String> allFields = const <String>[ static const List<String> allFields = <String>[
id, id,
name, name,
createdAt, createdAt,

View file

@ -2,29 +2,6 @@
part of angel_orm.generator.models.book; part of angel_orm.generator.models.book;
// **************************************************************************
// MigrationGenerator
// **************************************************************************
class BookMigration extends Migration {
@override
up(Schema schema) {
schema.create('books', (table) {
table.serial('id')..primaryKey();
table.varChar('name');
table.timeStamp('created_at');
table.timeStamp('updated_at');
table.integer('author_id').references('authors', 'id');
table.integer('partner_author_id').references('authors', 'id');
});
}
@override
down(Schema schema) {
schema.drop('books');
}
}
// ************************************************************************** // **************************************************************************
// OrmGenerator // OrmGenerator
// ************************************************************************** // **************************************************************************
@ -33,15 +10,11 @@ class BookQuery extends Query<Book, BookQueryWhere> {
BookQuery({Set<String> trampoline}) { BookQuery({Set<String> trampoline}) {
trampoline ??= Set(); trampoline ??= Set();
trampoline.add(tableName); trampoline.add(tableName);
_where = new BookQueryWhere(this); _where = BookQueryWhere(this);
leftJoin('authors', 'author_id', 'id',
additionalFields: const ['name', 'created_at', 'updated_at']);
leftJoin('authors', 'partner_author_id', 'id',
additionalFields: const ['name', 'created_at', 'updated_at']);
} }
@override @override
final BookQueryValues values = new BookQueryValues(); final BookQueryValues values = BookQueryValues();
BookQueryWhere _where; BookQueryWhere _where;
@ -57,14 +30,7 @@ class BookQuery extends Query<Book, BookQueryWhere> {
@override @override
get fields { get fields {
return const [ return const ['id'];
'id',
'author_id',
'partner_author_id',
'name',
'created_at',
'updated_at'
];
} }
@override @override
@ -74,24 +40,12 @@ class BookQuery extends Query<Book, BookQueryWhere> {
@override @override
BookQueryWhere newWhereClause() { BookQueryWhere newWhereClause() {
return new BookQueryWhere(this); return BookQueryWhere(this);
} }
static Book parseRow(List row) { static Book parseRow(List row) {
if (row.every((x) => x == null)) return null; if (row.every((x) => x == null)) return null;
var model = new Book( var model = Book(id: row[0].toString());
id: row[0].toString(),
name: (row[3] as String),
createdAt: (row[4] as DateTime),
updatedAt: (row[5] as DateTime));
if (row.length > 6) {
model =
model.copyWith(author: AuthorQuery.parseRow(row.skip(6).toList()));
}
if (row.length > 10) {
model = model.copyWith(
partnerAuthor: AuthorQuery.parseRow(row.skip(10).toList()));
}
return model; return model;
} }
@ -103,29 +57,13 @@ class BookQuery extends Query<Book, BookQueryWhere> {
class BookQueryWhere extends QueryWhere { class BookQueryWhere extends QueryWhere {
BookQueryWhere(BookQuery query) BookQueryWhere(BookQuery query)
: id = new NumericSqlExpressionBuilder<int>(query, 'id'), : id = NumericSqlExpressionBuilder<int>(query, 'id');
authorId = new NumericSqlExpressionBuilder<int>(query, 'author_id'),
partnerAuthorId =
new NumericSqlExpressionBuilder<int>(query, 'partner_author_id'),
name = new StringSqlExpressionBuilder(query, 'name'),
createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at');
final NumericSqlExpressionBuilder<int> id; final NumericSqlExpressionBuilder<int> id;
final NumericSqlExpressionBuilder<int> authorId;
final NumericSqlExpressionBuilder<int> partnerAuthorId;
final StringSqlExpressionBuilder name;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
@override @override
get expressionBuilders { get expressionBuilders {
return [id, authorId, partnerAuthorId, name, createdAt, updatedAt]; return [id];
} }
} }
@ -140,42 +78,7 @@ class BookQueryValues extends MapQueryValues {
} }
set id(int value) => values['id'] = value; set id(int value) => values['id'] = value;
int get authorId { void copyFrom(Book model) {}
return (values['author_id'] as int);
}
set authorId(int value) => values['author_id'] = value;
int get partnerAuthorId {
return (values['partner_author_id'] as int);
}
set partnerAuthorId(int value) => values['partner_author_id'] = value;
String get name {
return (values['name'] as String);
}
set name(String value) => values['name'] = value;
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;
if (model.author != null) {
values['author_id'] = int.parse(model.author.id);
}
if (model.partnerAuthor != null) {
values['partner_author_id'] = int.parse(model.partnerAuthor.id);
}
}
} }
// ************************************************************************** // **************************************************************************
@ -196,10 +99,10 @@ class Book extends _Book {
final String id; final String id;
@override @override
final Author author; final dynamic author;
@override @override
final Author partnerAuthor; final dynamic partnerAuthor;
@override @override
final String name; final String name;
@ -212,8 +115,8 @@ class Book extends _Book {
Book copyWith( Book copyWith(
{String id, {String id,
Author author, dynamic author,
Author partnerAuthor, dynamic partnerAuthor,
String name, String name,
DateTime createdAt, DateTime createdAt,
DateTime updatedAt}) { DateTime updatedAt}) {
@ -254,12 +157,8 @@ abstract class BookSerializer {
static Book fromMap(Map map) { static Book fromMap(Map map) {
return new Book( return new Book(
id: map['id'] as String, id: map['id'] as String,
author: map['author'] != null author: map['author'] as dynamic,
? AuthorSerializer.fromMap(map['author'] as Map) partnerAuthor: map['partner_author'] as dynamic,
: null,
partnerAuthor: map['partner_author'] != null
? AuthorSerializer.fromMap(map['partner_author'] as Map)
: null,
name: map['name'] as String, name: map['name'] as String,
createdAt: map['created_at'] != null createdAt: map['created_at'] != null
? (map['created_at'] is DateTime ? (map['created_at'] is DateTime
@ -279,8 +178,8 @@ abstract class BookSerializer {
} }
return { return {
'id': model.id, 'id': model.id,
'author': AuthorSerializer.toMap(model.author), 'author': model.author,
'partner_author': AuthorSerializer.toMap(model.partnerAuthor), 'partner_author': model.partnerAuthor,
'name': model.name, 'name': model.name,
'created_at': model.createdAt?.toIso8601String(), 'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String() 'updated_at': model.updatedAt?.toIso8601String()
@ -289,7 +188,7 @@ abstract class BookSerializer {
} }
abstract class BookFields { abstract class BookFields {
static const List<String> allFields = const <String>[ static const List<String> allFields = <String>[
id, id,
author, author,
partnerAuthor, partnerAuthor,

View file

@ -34,11 +34,11 @@ class CarQuery extends Query<Car, CarQueryWhere> {
CarQuery({Set<String> trampoline}) { CarQuery({Set<String> trampoline}) {
trampoline ??= Set(); trampoline ??= Set();
trampoline.add(tableName); trampoline.add(tableName);
_where = new CarQueryWhere(this); _where = CarQueryWhere(this);
} }
@override @override
final CarQueryValues values = new CarQueryValues(); final CarQueryValues values = CarQueryValues();
CarQueryWhere _where; CarQueryWhere _where;
@ -72,12 +72,12 @@ class CarQuery extends Query<Car, CarQueryWhere> {
@override @override
CarQueryWhere newWhereClause() { CarQueryWhere newWhereClause() {
return new CarQueryWhere(this); return CarQueryWhere(this);
} }
static Car parseRow(List row) { static Car parseRow(List row) {
if (row.every((x) => x == null)) return null; if (row.every((x) => x == null)) return null;
var model = new Car( var model = Car(
id: row[0].toString(), id: row[0].toString(),
make: (row[1] as String), make: (row[1] as String),
description: (row[2] as String), description: (row[2] as String),
@ -96,14 +96,13 @@ class CarQuery extends Query<Car, CarQueryWhere> {
class CarQueryWhere extends QueryWhere { class CarQueryWhere extends QueryWhere {
CarQueryWhere(CarQuery query) CarQueryWhere(CarQuery query)
: id = new NumericSqlExpressionBuilder<int>(query, 'id'), : id = NumericSqlExpressionBuilder<int>(query, 'id'),
make = new StringSqlExpressionBuilder(query, 'make'), make = StringSqlExpressionBuilder(query, 'make'),
description = new StringSqlExpressionBuilder(query, 'description'), description = StringSqlExpressionBuilder(query, 'description'),
familyFriendly = familyFriendly = BooleanSqlExpressionBuilder(query, 'family_friendly'),
new BooleanSqlExpressionBuilder(query, 'family_friendly'), recalledAt = DateTimeSqlExpressionBuilder(query, 'recalled_at'),
recalledAt = new DateTimeSqlExpressionBuilder(query, 'recalled_at'), createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at');
final NumericSqlExpressionBuilder<int> id; final NumericSqlExpressionBuilder<int> id;
@ -312,7 +311,7 @@ abstract class CarSerializer {
} }
abstract class CarFields { abstract class CarFields {
static const List<String> allFields = const <String>[ static const List<String> allFields = <String>[
id, id,
make, make,
description, description,

View file

@ -30,11 +30,11 @@ class CustomerQuery extends Query<Customer, CustomerQueryWhere> {
CustomerQuery({Set<String> trampoline}) { CustomerQuery({Set<String> trampoline}) {
trampoline ??= Set(); trampoline ??= Set();
trampoline.add(tableName); trampoline.add(tableName);
_where = new CustomerQueryWhere(this); _where = CustomerQueryWhere(this);
} }
@override @override
final CustomerQueryValues values = new CustomerQueryValues(); final CustomerQueryValues values = CustomerQueryValues();
CustomerQueryWhere _where; CustomerQueryWhere _where;
@ -60,12 +60,12 @@ class CustomerQuery extends Query<Customer, CustomerQueryWhere> {
@override @override
CustomerQueryWhere newWhereClause() { CustomerQueryWhere newWhereClause() {
return new CustomerQueryWhere(this); return CustomerQueryWhere(this);
} }
static Customer parseRow(List row) { static Customer parseRow(List row) {
if (row.every((x) => x == null)) return null; if (row.every((x) => x == null)) return null;
var model = new Customer( var model = Customer(
id: row[0].toString(), id: row[0].toString(),
createdAt: (row[1] as DateTime), createdAt: (row[1] as DateTime),
updatedAt: (row[2] as DateTime)); updatedAt: (row[2] as DateTime));
@ -80,9 +80,9 @@ class CustomerQuery extends Query<Customer, CustomerQueryWhere> {
class CustomerQueryWhere extends QueryWhere { class CustomerQueryWhere extends QueryWhere {
CustomerQueryWhere(CustomerQuery query) CustomerQueryWhere(CustomerQuery query)
: id = new NumericSqlExpressionBuilder<int>(query, 'id'), : id = NumericSqlExpressionBuilder<int>(query, 'id'),
createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at'); updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
final NumericSqlExpressionBuilder<int> id; final NumericSqlExpressionBuilder<int> id;
@ -197,11 +197,7 @@ abstract class CustomerSerializer {
} }
abstract class CustomerFields { abstract class CustomerFields {
static const List<String> allFields = const <String>[ static const List<String> allFields = <String>[id, createdAt, updatedAt];
id,
createdAt,
updatedAt
];
static const String id = 'id'; static const String id = 'id';

View file

@ -12,7 +12,7 @@ class FootMigration extends Migration {
schema.create('feet', (table) { schema.create('feet', (table) {
table.serial('id')..primaryKey(); table.serial('id')..primaryKey();
table.integer('leg_id'); table.integer('leg_id');
table.declare('n_toes', new ColumnType('decimal')); table.declare('n_toes', ColumnType('decimal'));
table.timeStamp('created_at'); table.timeStamp('created_at');
table.timeStamp('updated_at'); table.timeStamp('updated_at');
}); });
@ -32,11 +32,11 @@ class FootQuery extends Query<Foot, FootQueryWhere> {
FootQuery({Set<String> trampoline}) { FootQuery({Set<String> trampoline}) {
trampoline ??= Set(); trampoline ??= Set();
trampoline.add(tableName); trampoline.add(tableName);
_where = new FootQueryWhere(this); _where = FootQueryWhere(this);
} }
@override @override
final FootQueryValues values = new FootQueryValues(); final FootQueryValues values = FootQueryValues();
FootQueryWhere _where; FootQueryWhere _where;
@ -62,12 +62,12 @@ class FootQuery extends Query<Foot, FootQueryWhere> {
@override @override
FootQueryWhere newWhereClause() { FootQueryWhere newWhereClause() {
return new FootQueryWhere(this); return FootQueryWhere(this);
} }
static Foot parseRow(List row) { static Foot parseRow(List row) {
if (row.every((x) => x == null)) return null; if (row.every((x) => x == null)) return null;
var model = new Foot( var model = Foot(
id: row[0].toString(), id: row[0].toString(),
legId: (row[1] as int), legId: (row[1] as int),
nToes: double.parse(row[2].toString()), nToes: double.parse(row[2].toString()),
@ -84,11 +84,11 @@ class FootQuery extends Query<Foot, FootQueryWhere> {
class FootQueryWhere extends QueryWhere { class FootQueryWhere extends QueryWhere {
FootQueryWhere(FootQuery query) FootQueryWhere(FootQuery query)
: id = new NumericSqlExpressionBuilder<int>(query, 'id'), : id = NumericSqlExpressionBuilder<int>(query, 'id'),
legId = new NumericSqlExpressionBuilder<int>(query, 'leg_id'), legId = NumericSqlExpressionBuilder<int>(query, 'leg_id'),
nToes = new NumericSqlExpressionBuilder<double>(query, 'n_toes'), nToes = NumericSqlExpressionBuilder<double>(query, 'n_toes'),
createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at'); updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
final NumericSqlExpressionBuilder<int> id; final NumericSqlExpressionBuilder<int> id;
@ -238,7 +238,7 @@ abstract class FootSerializer {
} }
abstract class FootFields { abstract class FootFields {
static const List<String> allFields = const <String>[ static const List<String> allFields = <String>[
id, id,
legId, legId,
nToes, nToes,

View file

@ -32,11 +32,11 @@ class FruitQuery extends Query<Fruit, FruitQueryWhere> {
FruitQuery({Set<String> trampoline}) { FruitQuery({Set<String> trampoline}) {
trampoline ??= Set(); trampoline ??= Set();
trampoline.add(tableName); trampoline.add(tableName);
_where = new FruitQueryWhere(this); _where = FruitQueryWhere(this);
} }
@override @override
final FruitQueryValues values = new FruitQueryValues(); final FruitQueryValues values = FruitQueryValues();
FruitQueryWhere _where; FruitQueryWhere _where;
@ -62,12 +62,12 @@ class FruitQuery extends Query<Fruit, FruitQueryWhere> {
@override @override
FruitQueryWhere newWhereClause() { FruitQueryWhere newWhereClause() {
return new FruitQueryWhere(this); return FruitQueryWhere(this);
} }
static Fruit parseRow(List row) { static Fruit parseRow(List row) {
if (row.every((x) => x == null)) return null; if (row.every((x) => x == null)) return null;
var model = new Fruit( var model = Fruit(
id: row[0].toString(), id: row[0].toString(),
treeId: (row[1] as int), treeId: (row[1] as int),
commonName: (row[2] as String), commonName: (row[2] as String),
@ -84,11 +84,11 @@ class FruitQuery extends Query<Fruit, FruitQueryWhere> {
class FruitQueryWhere extends QueryWhere { class FruitQueryWhere extends QueryWhere {
FruitQueryWhere(FruitQuery query) FruitQueryWhere(FruitQuery query)
: id = new NumericSqlExpressionBuilder<int>(query, 'id'), : id = NumericSqlExpressionBuilder<int>(query, 'id'),
treeId = new NumericSqlExpressionBuilder<int>(query, 'tree_id'), treeId = NumericSqlExpressionBuilder<int>(query, 'tree_id'),
commonName = new StringSqlExpressionBuilder(query, 'common_name'), commonName = StringSqlExpressionBuilder(query, 'common_name'),
createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at'); updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
final NumericSqlExpressionBuilder<int> id; final NumericSqlExpressionBuilder<int> id;
@ -239,7 +239,7 @@ abstract class FruitSerializer {
} }
abstract class FruitFields { abstract class FruitFields {
static const List<String> allFields = const <String>[ static const List<String> allFields = <String>[
id, id,
treeId, treeId,
commonName, commonName,

View file

@ -31,11 +31,11 @@ class HasCarQuery extends Query<HasCar, HasCarQueryWhere> {
HasCarQuery({Set<String> trampoline}) { HasCarQuery({Set<String> trampoline}) {
trampoline ??= Set(); trampoline ??= Set();
trampoline.add(tableName); trampoline.add(tableName);
_where = new HasCarQueryWhere(this); _where = HasCarQueryWhere(this);
} }
@override @override
final HasCarQueryValues values = new HasCarQueryValues(); final HasCarQueryValues values = HasCarQueryValues();
HasCarQueryWhere _where; HasCarQueryWhere _where;
@ -61,12 +61,12 @@ class HasCarQuery extends Query<HasCar, HasCarQueryWhere> {
@override @override
HasCarQueryWhere newWhereClause() { HasCarQueryWhere newWhereClause() {
return new HasCarQueryWhere(this); return HasCarQueryWhere(this);
} }
static HasCar parseRow(List row) { static HasCar parseRow(List row) {
if (row.every((x) => x == null)) return null; if (row.every((x) => x == null)) return null;
var model = new HasCar( var model = HasCar(
id: row[0].toString(), id: row[0].toString(),
type: CarType.values[(row[1] as int)], type: CarType.values[(row[1] as int)],
createdAt: (row[2] as DateTime), createdAt: (row[2] as DateTime),
@ -82,11 +82,10 @@ class HasCarQuery extends Query<HasCar, HasCarQueryWhere> {
class HasCarQueryWhere extends QueryWhere { class HasCarQueryWhere extends QueryWhere {
HasCarQueryWhere(HasCarQuery query) HasCarQueryWhere(HasCarQuery query)
: id = new NumericSqlExpressionBuilder<int>(query, 'id'), : id = NumericSqlExpressionBuilder<int>(query, 'id'),
type = new EnumSqlExpressionBuilder<CarType>( type = EnumSqlExpressionBuilder<CarType>(query, 'type', (v) => v.index),
query, 'type', (v) => v.index), createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at');
final NumericSqlExpressionBuilder<int> id; final NumericSqlExpressionBuilder<int> id;
@ -227,7 +226,7 @@ abstract class HasCarSerializer {
} }
abstract class HasCarFields { abstract class HasCarFields {
static const List<String> allFields = const <String>[ static const List<String> allFields = <String>[
id, id,
type, type,
createdAt, createdAt,

View file

@ -10,8 +10,8 @@ class HasMapMigration extends Migration {
@override @override
up(Schema schema) { up(Schema schema) {
schema.create('has_maps', (table) { schema.create('has_maps', (table) {
table.declare('value', new ColumnType('jsonb')); table.declare('value', ColumnType('jsonb'));
table.declare('list', new ColumnType('jsonb')); table.declare('list', ColumnType('jsonb'));
}); });
} }
@ -29,11 +29,11 @@ class HasMapQuery extends Query<HasMap, HasMapQueryWhere> {
HasMapQuery({Set<String> trampoline}) { HasMapQuery({Set<String> trampoline}) {
trampoline ??= Set(); trampoline ??= Set();
trampoline.add(tableName); trampoline.add(tableName);
_where = new HasMapQueryWhere(this); _where = HasMapQueryWhere(this);
} }
@override @override
final HasMapQueryValues values = new HasMapQueryValues(); final HasMapQueryValues values = HasMapQueryValues();
HasMapQueryWhere _where; HasMapQueryWhere _where;
@ -59,12 +59,12 @@ class HasMapQuery extends Query<HasMap, HasMapQueryWhere> {
@override @override
HasMapQueryWhere newWhereClause() { HasMapQueryWhere newWhereClause() {
return new HasMapQueryWhere(this); return HasMapQueryWhere(this);
} }
static HasMap parseRow(List row) { static HasMap parseRow(List row) {
if (row.every((x) => x == null)) return null; if (row.every((x) => x == null)) return null;
var model = new HasMap( var model = HasMap(
value: (row[0] as Map<dynamic, dynamic>), value: (row[0] as Map<dynamic, dynamic>),
list: (row[1] as List<dynamic>)); list: (row[1] as List<dynamic>));
return model; return model;
@ -78,8 +78,8 @@ class HasMapQuery extends Query<HasMap, HasMapQueryWhere> {
class HasMapQueryWhere extends QueryWhere { class HasMapQueryWhere extends QueryWhere {
HasMapQueryWhere(HasMapQuery query) HasMapQueryWhere(HasMapQuery query)
: value = new MapSqlExpressionBuilder(query, 'value'), : value = MapSqlExpressionBuilder(query, 'value'),
list = new ListSqlExpressionBuilder(query, 'list'); list = ListSqlExpressionBuilder(query, 'list');
final MapSqlExpressionBuilder value; final MapSqlExpressionBuilder value;
@ -174,7 +174,7 @@ abstract class HasMapSerializer {
} }
abstract class HasMapFields { abstract class HasMapFields {
static const List<String> allFields = const <String>[value, list]; static const List<String> allFields = <String>[value, list];
static const String value = 'value'; static const String value = 'value';

View file

@ -2,27 +2,6 @@
part of angel_orm_generator.test.models.leg; part of angel_orm_generator.test.models.leg;
// **************************************************************************
// MigrationGenerator
// **************************************************************************
class LegMigration extends Migration {
@override
up(Schema schema) {
schema.create('legs', (table) {
table.serial('id')..primaryKey();
table.varChar('name');
table.timeStamp('created_at');
table.timeStamp('updated_at');
});
}
@override
down(Schema schema) {
schema.drop('legs');
}
}
// ************************************************************************** // **************************************************************************
// OrmGenerator // OrmGenerator
// ************************************************************************** // **************************************************************************
@ -31,17 +10,11 @@ class LegQuery extends Query<Leg, LegQueryWhere> {
LegQuery({Set<String> trampoline}) { LegQuery({Set<String> trampoline}) {
trampoline ??= Set(); trampoline ??= Set();
trampoline.add(tableName); trampoline.add(tableName);
_where = new LegQueryWhere(this); _where = LegQueryWhere(this);
leftJoin('feet', 'id', 'leg_id', additionalFields: const [
'leg_id',
'n_toes',
'created_at',
'updated_at'
]);
} }
@override @override
final LegQueryValues values = new LegQueryValues(); final LegQueryValues values = LegQueryValues();
LegQueryWhere _where; LegQueryWhere _where;
@ -57,7 +30,7 @@ class LegQuery extends Query<Leg, LegQueryWhere> {
@override @override
get fields { get fields {
return const ['id', 'name', 'created_at', 'updated_at']; return const ['id'];
} }
@override @override
@ -67,19 +40,12 @@ class LegQuery extends Query<Leg, LegQueryWhere> {
@override @override
LegQueryWhere newWhereClause() { LegQueryWhere newWhereClause() {
return new LegQueryWhere(this); return LegQueryWhere(this);
} }
static Leg parseRow(List row) { static Leg parseRow(List row) {
if (row.every((x) => x == null)) return null; if (row.every((x) => x == null)) return null;
var model = new Leg( var model = Leg(id: row[0].toString());
id: row[0].toString(),
name: (row[1] as String),
createdAt: (row[2] as DateTime),
updatedAt: (row[3] as DateTime));
if (row.length > 4) {
model = model.copyWith(foot: FootQuery.parseRow(row.skip(4).toList()));
}
return model; return model;
} }
@ -91,22 +57,13 @@ class LegQuery extends Query<Leg, LegQueryWhere> {
class LegQueryWhere extends QueryWhere { class LegQueryWhere extends QueryWhere {
LegQueryWhere(LegQuery query) LegQueryWhere(LegQuery query)
: id = new NumericSqlExpressionBuilder<int>(query, 'id'), : id = NumericSqlExpressionBuilder<int>(query, 'id');
name = new StringSqlExpressionBuilder(query, 'name'),
createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at');
final NumericSqlExpressionBuilder<int> id; final NumericSqlExpressionBuilder<int> id;
final StringSqlExpressionBuilder name;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
@override @override
get expressionBuilders { get expressionBuilders {
return [id, name, createdAt, updatedAt]; return [id];
} }
} }
@ -121,26 +78,7 @@ class LegQueryValues extends MapQueryValues {
} }
set id(int value) => values['id'] = value; set id(int value) => values['id'] = value;
String get name { void copyFrom(Leg model) {}
return (values['name'] as String);
}
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(Leg model) {
name = model.name;
createdAt = model.createdAt;
updatedAt = model.updatedAt;
}
} }
// ************************************************************************** // **************************************************************************
@ -155,7 +93,7 @@ class Leg extends _Leg {
final String id; final String id;
@override @override
final Foot foot; final dynamic foot;
@override @override
final String name; final String name;
@ -168,7 +106,7 @@ class Leg extends _Leg {
Leg copyWith( Leg copyWith(
{String id, {String id,
Foot foot, dynamic foot,
String name, String name,
DateTime createdAt, DateTime createdAt,
DateTime updatedAt}) { DateTime updatedAt}) {
@ -207,9 +145,7 @@ abstract class LegSerializer {
static Leg fromMap(Map map) { static Leg fromMap(Map map) {
return new Leg( return new Leg(
id: map['id'] as String, id: map['id'] as String,
foot: map['foot'] != null foot: map['foot'] as dynamic,
? FootSerializer.fromMap(map['foot'] as Map)
: null,
name: map['name'] as String, name: map['name'] as String,
createdAt: map['created_at'] != null createdAt: map['created_at'] != null
? (map['created_at'] is DateTime ? (map['created_at'] is DateTime
@ -229,7 +165,7 @@ abstract class LegSerializer {
} }
return { return {
'id': model.id, 'id': model.id,
'foot': FootSerializer.toMap(model.foot), 'foot': model.foot,
'name': model.name, 'name': model.name,
'created_at': model.createdAt?.toIso8601String(), 'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String() 'updated_at': model.updatedAt?.toIso8601String()
@ -238,7 +174,7 @@ abstract class LegSerializer {
} }
abstract class LegFields { abstract class LegFields {
static const List<String> allFields = const <String>[ static const List<String> allFields = <String>[
id, id,
foot, foot,
name, name,

View file

@ -2,30 +2,6 @@
part of angel_orm_generator.test.models.order; part of angel_orm_generator.test.models.order;
// **************************************************************************
// MigrationGenerator
// **************************************************************************
class OrderMigration extends Migration {
@override
up(Schema schema) {
schema.create('orders', (table) {
table.serial('id')..primaryKey();
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');
});
}
@override
down(Schema schema) {
schema.drop('orders');
}
}
// ************************************************************************** // **************************************************************************
// OrmGenerator // OrmGenerator
// ************************************************************************** // **************************************************************************
@ -34,13 +10,11 @@ class OrderQuery extends Query<Order, OrderQueryWhere> {
OrderQuery({Set<String> trampoline}) { OrderQuery({Set<String> trampoline}) {
trampoline ??= Set(); trampoline ??= Set();
trampoline.add(tableName); trampoline.add(tableName);
_where = new OrderQueryWhere(this); _where = OrderQueryWhere(this);
leftJoin('customers', 'customer_id', 'id',
additionalFields: const ['created_at', 'updated_at']);
} }
@override @override
final OrderQueryValues values = new OrderQueryValues(); final OrderQueryValues values = OrderQueryValues();
OrderQueryWhere _where; OrderQueryWhere _where;
@ -56,15 +30,7 @@ class OrderQuery extends Query<Order, OrderQueryWhere> {
@override @override
get fields { get fields {
return const [ return const ['id'];
'id',
'customer_id',
'employee_id',
'order_date',
'shipper_id',
'created_at',
'updated_at'
];
} }
@override @override
@ -74,22 +40,12 @@ class OrderQuery extends Query<Order, OrderQueryWhere> {
@override @override
OrderQueryWhere newWhereClause() { OrderQueryWhere newWhereClause() {
return new OrderQueryWhere(this); return OrderQueryWhere(this);
} }
static Order parseRow(List row) { static Order parseRow(List row) {
if (row.every((x) => x == null)) return null; if (row.every((x) => x == null)) return null;
var model = new Order( var model = Order(id: row[0].toString());
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));
if (row.length > 7) {
model = model.copyWith(
customer: CustomerQuery.parseRow(row.skip(7).toList()));
}
return model; return model;
} }
@ -101,39 +57,13 @@ class OrderQuery extends Query<Order, OrderQueryWhere> {
class OrderQueryWhere extends QueryWhere { class OrderQueryWhere extends QueryWhere {
OrderQueryWhere(OrderQuery query) OrderQueryWhere(OrderQuery query)
: id = new NumericSqlExpressionBuilder<int>(query, 'id'), : id = NumericSqlExpressionBuilder<int>(query, 'id');
customerId = new NumericSqlExpressionBuilder<int>(query, 'customer_id'),
employeeId = new NumericSqlExpressionBuilder<int>(query, 'employee_id'),
orderDate = new DateTimeSqlExpressionBuilder(query, 'order_date'),
shipperId = new NumericSqlExpressionBuilder<int>(query, 'shipper_id'),
createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at');
final NumericSqlExpressionBuilder<int> id; final NumericSqlExpressionBuilder<int> id;
final NumericSqlExpressionBuilder<int> customerId;
final NumericSqlExpressionBuilder<int> employeeId;
final DateTimeSqlExpressionBuilder orderDate;
final NumericSqlExpressionBuilder<int> shipperId;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
@override @override
get expressionBuilders { get expressionBuilders {
return [ return [id];
id,
customerId,
employeeId,
orderDate,
shipperId,
createdAt,
updatedAt
];
} }
} }
@ -148,46 +78,7 @@ class OrderQueryValues extends MapQueryValues {
} }
set id(int value) => values['id'] = value; set id(int value) => values['id'] = value;
int get customerId { void copyFrom(Order model) {}
return (values['customer_id'] as int);
}
set customerId(int value) => values['customer_id'] = value;
int get employeeId {
return (values['employee_id'] as int);
}
set employeeId(int value) => values['employee_id'] = value;
DateTime get orderDate {
return (values['order_date'] as DateTime);
}
set orderDate(DateTime value) => values['order_date'] = value;
int get shipperId {
return (values['shipper_id'] as int);
}
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) {
employeeId = model.employeeId;
orderDate = model.orderDate;
shipperId = model.shipperId;
createdAt = model.createdAt;
updatedAt = model.updatedAt;
if (model.customer != null) {
values['customer_id'] = int.parse(model.customer.id);
}
}
} }
// ************************************************************************** // **************************************************************************
@ -209,7 +100,7 @@ class Order extends _Order {
final String id; final String id;
@override @override
final Customer customer; final dynamic customer;
@override @override
final int employeeId; final int employeeId;
@ -228,7 +119,7 @@ class Order extends _Order {
Order copyWith( Order copyWith(
{String id, {String id,
Customer customer, dynamic customer,
int employeeId, int employeeId,
DateTime orderDate, DateTime orderDate,
int shipperId, int shipperId,
@ -274,9 +165,7 @@ abstract class OrderSerializer {
static Order fromMap(Map map) { static Order fromMap(Map map) {
return new Order( return new Order(
id: map['id'] as String, id: map['id'] as String,
customer: map['customer'] != null customer: map['customer'] as dynamic,
? CustomerSerializer.fromMap(map['customer'] as Map)
: null,
employeeId: map['employee_id'] as int, employeeId: map['employee_id'] as int,
orderDate: map['order_date'] != null orderDate: map['order_date'] != null
? (map['order_date'] is DateTime ? (map['order_date'] is DateTime
@ -302,7 +191,7 @@ abstract class OrderSerializer {
} }
return { return {
'id': model.id, 'id': model.id,
'customer': CustomerSerializer.toMap(model.customer), 'customer': model.customer,
'employee_id': model.employeeId, 'employee_id': model.employeeId,
'order_date': model.orderDate?.toIso8601String(), 'order_date': model.orderDate?.toIso8601String(),
'shipper_id': model.shipperId, 'shipper_id': model.shipperId,
@ -313,7 +202,7 @@ abstract class OrderSerializer {
} }
abstract class OrderFields { abstract class OrderFields {
static const List<String> allFields = const <String>[ static const List<String> allFields = <String>[
id, id,
customer, customer,
employeeId, employeeId,

View file

@ -2,27 +2,6 @@
part of angel_orm_generator.test.models.tree; part of angel_orm_generator.test.models.tree;
// **************************************************************************
// MigrationGenerator
// **************************************************************************
class TreeMigration extends Migration {
@override
up(Schema schema) {
schema.create('trees', (table) {
table.serial('id')..primaryKey();
table.declare('rings', new ColumnType('smallint'));
table.timeStamp('created_at');
table.timeStamp('updated_at');
});
}
@override
down(Schema schema) {
schema.drop('trees');
}
}
// ************************************************************************** // **************************************************************************
// OrmGenerator // OrmGenerator
// ************************************************************************** // **************************************************************************
@ -31,18 +10,11 @@ class TreeQuery extends Query<Tree, TreeQueryWhere> {
TreeQuery({Set<String> trampoline}) { TreeQuery({Set<String> trampoline}) {
trampoline ??= Set(); trampoline ??= Set();
trampoline.add(tableName); trampoline.add(tableName);
_where = new TreeQueryWhere(this); _where = TreeQueryWhere(this);
leftJoin(new FruitQuery(trampoline: trampoline), 'id', 'tree_id',
additionalFields: const [
'tree_id',
'common_name',
'created_at',
'updated_at'
]);
} }
@override @override
final TreeQueryValues values = new TreeQueryValues(); final TreeQueryValues values = TreeQueryValues();
TreeQueryWhere _where; TreeQueryWhere _where;
@ -58,7 +30,7 @@ class TreeQuery extends Query<Tree, TreeQueryWhere> {
@override @override
get fields { get fields {
return const ['id', 'rings', 'created_at', 'updated_at']; return const ['id', 'rings'];
} }
@override @override
@ -68,22 +40,12 @@ class TreeQuery extends Query<Tree, TreeQueryWhere> {
@override @override
TreeQueryWhere newWhereClause() { TreeQueryWhere newWhereClause() {
return new TreeQueryWhere(this); return TreeQueryWhere(this);
} }
static Tree parseRow(List row) { static Tree parseRow(List row) {
if (row.every((x) => x == null)) return null; if (row.every((x) => x == null)) return null;
var model = new Tree( var model = Tree(id: row[0].toString(), rings: (row[1] as int));
id: row[0].toString(),
rings: (row[1] as int),
createdAt: (row[2] as DateTime),
updatedAt: (row[3] as DateTime));
if (row.length > 4) {
model = model.copyWith(
fruits: [FruitQuery.parseRow(row.skip(4).toList())]
.where((x) => x != null)
.toList());
}
return model; return model;
} }
@ -91,83 +53,20 @@ class TreeQuery extends Query<Tree, TreeQueryWhere> {
deserialize(List row) { deserialize(List row) {
return parseRow(row); return parseRow(row);
} }
@override
get(QueryExecutor executor) {
return super.get(executor).then((result) {
return result.fold<List<Tree>>([], (out, model) {
var idx = out.indexWhere((m) => m.id == model.id);
if (idx == -1) {
return out..add(model);
} else {
var l = out[idx];
return out
..[idx] = l.copyWith(
fruits: List<Fruit>.from(l.fruits ?? [])
..addAll(model.fruits ?? []));
}
});
});
}
@override
update(QueryExecutor executor) {
return super.update(executor).then((result) {
return result.fold<List<Tree>>([], (out, model) {
var idx = out.indexWhere((m) => m.id == model.id);
if (idx == -1) {
return out..add(model);
} else {
var l = out[idx];
return out
..[idx] = l.copyWith(
fruits: List<Fruit>.from(l.fruits ?? [])
..addAll(model.fruits ?? []));
}
});
});
}
@override
delete(QueryExecutor executor) {
return super.delete(executor).then((result) {
return result.fold<List<Tree>>([], (out, model) {
var idx = out.indexWhere((m) => m.id == model.id);
if (idx == -1) {
return out..add(model);
} else {
var l = out[idx];
return out
..[idx] = l.copyWith(
fruits: List<Fruit>.from(l.fruits ?? [])
..addAll(model.fruits ?? []));
}
});
});
}
} }
class TreeQueryWhere extends QueryWhere { class TreeQueryWhere extends QueryWhere {
TreeQueryWhere(TreeQuery query) TreeQueryWhere(TreeQuery query)
: id = new NumericSqlExpressionBuilder<int>(query, 'id'), : id = NumericSqlExpressionBuilder<int>(query, 'id'),
rings = new NumericSqlExpressionBuilder<int>(query, 'rings'), rings = NumericSqlExpressionBuilder<int>(query, 'rings');
createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at');
final NumericSqlExpressionBuilder<int> id; final NumericSqlExpressionBuilder<int> id;
final NumericSqlExpressionBuilder<int> rings; final NumericSqlExpressionBuilder<int> rings;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
@override @override
get expressionBuilders { get expressionBuilders {
return [id, rings, createdAt, updatedAt]; return [id, rings];
} }
} }
@ -187,20 +86,8 @@ class TreeQueryValues extends MapQueryValues {
} }
set rings(int value) => values['rings'] = value; set rings(int value) => values['rings'] = 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(Tree model) { void copyFrom(Tree model) {
rings = model.rings; rings = model.rings;
createdAt = model.createdAt;
updatedAt = model.updatedAt;
} }
} }
@ -211,7 +98,11 @@ class TreeQueryValues extends MapQueryValues {
@generatedSerializable @generatedSerializable
class Tree extends _Tree { class Tree extends _Tree {
Tree( Tree(
{this.id, this.rings, List<Fruit> fruits, this.createdAt, this.updatedAt}) {this.id,
this.rings,
List<dynamic> fruits,
this.createdAt,
this.updatedAt})
: this.fruits = new List.unmodifiable(fruits ?? []); : this.fruits = new List.unmodifiable(fruits ?? []);
@override @override
@ -221,7 +112,7 @@ class Tree extends _Tree {
final int rings; final int rings;
@override @override
final List<Fruit> fruits; final List<dynamic> fruits;
@override @override
final DateTime createdAt; final DateTime createdAt;
@ -232,7 +123,7 @@ class Tree extends _Tree {
Tree copyWith( Tree copyWith(
{String id, {String id,
int rings, int rings,
List<Fruit> fruits, List<dynamic> fruits,
DateTime createdAt, DateTime createdAt,
DateTime updatedAt}) { DateTime updatedAt}) {
return new Tree( return new Tree(
@ -247,7 +138,7 @@ class Tree extends _Tree {
return other is _Tree && return other is _Tree &&
other.id == id && other.id == id &&
other.rings == rings && other.rings == rings &&
const ListEquality<Fruit>(const DefaultEquality<Fruit>()) const ListEquality<dynamic>(const DefaultEquality())
.equals(other.fruits, fruits) && .equals(other.fruits, fruits) &&
other.createdAt == createdAt && other.createdAt == createdAt &&
other.updatedAt == updatedAt; other.updatedAt == updatedAt;
@ -273,9 +164,7 @@ abstract class TreeSerializer {
id: map['id'] as String, id: map['id'] as String,
rings: map['rings'] as int, rings: map['rings'] as int,
fruits: map['fruits'] is Iterable fruits: map['fruits'] is Iterable
? new List.unmodifiable(((map['fruits'] as Iterable) ? (map['fruits'] as Iterable).cast<dynamic>().toList()
.where((x) => x is Map) as Iterable<Map>)
.map(FruitSerializer.fromMap))
: null, : null,
createdAt: map['created_at'] != null createdAt: map['created_at'] != null
? (map['created_at'] is DateTime ? (map['created_at'] is DateTime
@ -296,7 +185,7 @@ abstract class TreeSerializer {
return { return {
'id': model.id, 'id': model.id,
'rings': model.rings, 'rings': model.rings,
'fruits': model.fruits?.map((m) => FruitSerializer.toMap(m))?.toList(), 'fruits': model.fruits,
'created_at': model.createdAt?.toIso8601String(), 'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String() 'updated_at': model.updatedAt?.toIso8601String()
}; };
@ -304,7 +193,7 @@ abstract class TreeSerializer {
} }
abstract class TreeFields { abstract class TreeFields {
static const List<String> allFields = const <String>[ static const List<String> allFields = <String>[
id, id,
rings, rings,
fruits, fruits,

View file

@ -68,11 +68,11 @@ class UserQuery extends Query<User, UserQueryWhere> {
UserQuery({Set<String> trampoline}) { UserQuery({Set<String> trampoline}) {
trampoline ??= Set(); trampoline ??= Set();
trampoline.add(tableName); trampoline.add(tableName);
_where = new UserQueryWhere(this); _where = UserQueryWhere(this);
} }
@override @override
final UserQueryValues values = new UserQueryValues(); final UserQueryValues values = UserQueryValues();
UserQueryWhere _where; UserQueryWhere _where;
@ -105,12 +105,12 @@ class UserQuery extends Query<User, UserQueryWhere> {
@override @override
UserQueryWhere newWhereClause() { UserQueryWhere newWhereClause() {
return new UserQueryWhere(this); return UserQueryWhere(this);
} }
static User parseRow(List row) { static User parseRow(List row) {
if (row.every((x) => x == null)) return null; if (row.every((x) => x == null)) return null;
var model = new User( var model = User(
id: row[0].toString(), id: row[0].toString(),
username: (row[1] as String), username: (row[1] as String),
password: (row[2] as String), password: (row[2] as String),
@ -128,12 +128,12 @@ class UserQuery extends Query<User, UserQueryWhere> {
class UserQueryWhere extends QueryWhere { class UserQueryWhere extends QueryWhere {
UserQueryWhere(UserQuery query) UserQueryWhere(UserQuery query)
: id = new NumericSqlExpressionBuilder<int>(query, 'id'), : id = NumericSqlExpressionBuilder<int>(query, 'id'),
username = new StringSqlExpressionBuilder(query, 'username'), username = StringSqlExpressionBuilder(query, 'username'),
password = new StringSqlExpressionBuilder(query, 'password'), password = StringSqlExpressionBuilder(query, 'password'),
email = new StringSqlExpressionBuilder(query, 'email'), email = StringSqlExpressionBuilder(query, 'email'),
createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at'); updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
final NumericSqlExpressionBuilder<int> id; final NumericSqlExpressionBuilder<int> id;
@ -202,10 +202,11 @@ class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
RoleUserQuery({Set<String> trampoline}) { RoleUserQuery({Set<String> trampoline}) {
trampoline ??= Set(); trampoline ??= Set();
trampoline.add(tableName); trampoline.add(tableName);
_where = new RoleUserQueryWhere(this); _where = RoleUserQueryWhere(this);
leftJoin('roles', 'role_id', 'id', leftJoin('roles', 'role_id', 'id',
additionalFields: const ['name', 'created_at', 'updated_at']); additionalFields: const ['id', 'name', 'created_at', 'updated_at']);
leftJoin('users', 'user_id', 'id', additionalFields: const [ leftJoin('users', 'user_id', 'id', additionalFields: const [
'id',
'username', 'username',
'password', 'password',
'email', 'email',
@ -215,7 +216,7 @@ class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
} }
@override @override
final RoleUserQueryValues values = new RoleUserQueryValues(); final RoleUserQueryValues values = RoleUserQueryValues();
RoleUserQueryWhere _where; RoleUserQueryWhere _where;
@ -241,12 +242,12 @@ class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
@override @override
RoleUserQueryWhere newWhereClause() { RoleUserQueryWhere newWhereClause() {
return new RoleUserQueryWhere(this); return RoleUserQueryWhere(this);
} }
static RoleUser parseRow(List row) { static RoleUser parseRow(List row) {
if (row.every((x) => x == null)) return null; if (row.every((x) => x == null)) return null;
var model = new RoleUser( var model = RoleUser(
id: row[0].toString(), id: row[0].toString(),
createdAt: (row[3] as DateTime), createdAt: (row[3] as DateTime),
updatedAt: (row[4] as DateTime)); updatedAt: (row[4] as DateTime));
@ -267,11 +268,11 @@ class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
class RoleUserQueryWhere extends QueryWhere { class RoleUserQueryWhere extends QueryWhere {
RoleUserQueryWhere(RoleUserQuery query) RoleUserQueryWhere(RoleUserQuery query)
: id = new NumericSqlExpressionBuilder<int>(query, 'id'), : id = NumericSqlExpressionBuilder<int>(query, 'id'),
roleId = new NumericSqlExpressionBuilder<int>(query, 'role_id'), roleId = NumericSqlExpressionBuilder<int>(query, 'role_id'),
userId = new NumericSqlExpressionBuilder<int>(query, 'user_id'), userId = NumericSqlExpressionBuilder<int>(query, 'user_id'),
createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at'); updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
final NumericSqlExpressionBuilder<int> id; final NumericSqlExpressionBuilder<int> id;
@ -336,11 +337,11 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
RoleQuery({Set<String> trampoline}) { RoleQuery({Set<String> trampoline}) {
trampoline ??= Set(); trampoline ??= Set();
trampoline.add(tableName); trampoline.add(tableName);
_where = new RoleQueryWhere(this); _where = RoleQueryWhere(this);
} }
@override @override
final RoleQueryValues values = new RoleQueryValues(); final RoleQueryValues values = RoleQueryValues();
RoleQueryWhere _where; RoleQueryWhere _where;
@ -366,12 +367,12 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
@override @override
RoleQueryWhere newWhereClause() { RoleQueryWhere newWhereClause() {
return new RoleQueryWhere(this); return RoleQueryWhere(this);
} }
static Role parseRow(List row) { static Role parseRow(List row) {
if (row.every((x) => x == null)) return null; if (row.every((x) => x == null)) return null;
var model = new Role( var model = Role(
id: row[0].toString(), id: row[0].toString(),
name: (row[1] as String), name: (row[1] as String),
createdAt: (row[2] as DateTime), createdAt: (row[2] as DateTime),
@ -387,10 +388,10 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
class RoleQueryWhere extends QueryWhere { class RoleQueryWhere extends QueryWhere {
RoleQueryWhere(RoleQuery query) RoleQueryWhere(RoleQuery query)
: id = new NumericSqlExpressionBuilder<int>(query, 'id'), : id = NumericSqlExpressionBuilder<int>(query, 'id'),
name = new StringSqlExpressionBuilder(query, 'name'), name = StringSqlExpressionBuilder(query, 'name'),
createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at'); updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
final NumericSqlExpressionBuilder<int> id; final NumericSqlExpressionBuilder<int> id;
@ -635,9 +636,10 @@ abstract class UserSerializer {
password: map['password'] as String, password: map['password'] as String,
email: map['email'] as String, email: map['email'] as String,
roles: map['roles'] is Iterable roles: map['roles'] is Iterable
? new List.unmodifiable(((map['roles'] as Iterable) ? new List.unmodifiable(
.where((x) => x is Map) as Iterable<Map>) ((map['roles'] as Iterable).where((x) => x is Map))
.map(RoleSerializer.fromMap)) .cast<Map>()
.map(RoleSerializer.fromMap))
: null, : null,
createdAt: map['created_at'] != null createdAt: map['created_at'] != null
? (map['created_at'] is DateTime ? (map['created_at'] is DateTime
@ -668,7 +670,7 @@ abstract class UserSerializer {
} }
abstract class UserFields { abstract class UserFields {
static const List<String> allFields = const <String>[ static const List<String> allFields = <String>[
id, id,
username, username,
password, password,
@ -730,7 +732,7 @@ abstract class RoleUserSerializer {
} }
abstract class RoleUserFields { abstract class RoleUserFields {
static const List<String> allFields = const <String>[ static const List<String> allFields = <String>[
id, id,
role, role,
user, user,
@ -755,9 +757,10 @@ abstract class RoleSerializer {
id: map['id'] as String, id: map['id'] as String,
name: map['name'] as String, name: map['name'] as String,
users: map['users'] is Iterable users: map['users'] is Iterable
? new List.unmodifiable(((map['users'] as Iterable) ? new List.unmodifiable(
.where((x) => x is Map) as Iterable<Map>) ((map['users'] as Iterable).where((x) => x is Map))
.map(UserSerializer.fromMap)) .cast<Map>()
.map(UserSerializer.fromMap))
: null, : null,
createdAt: map['created_at'] != null createdAt: map['created_at'] != null
? (map['created_at'] is DateTime ? (map['created_at'] is DateTime
@ -786,7 +789,7 @@ abstract class RoleSerializer {
} }
abstract class RoleFields { abstract class RoleFields {
static const List<String> allFields = const <String>[ static const List<String> allFields = <String>[
id, id,
name, name,
users, users,