From e87c92a48b4f3975c299346184bcb1a7f0a3ec45 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Wed, 6 Feb 2019 22:27:47 -0500 Subject: [PATCH] ORM deps broken --- angel_orm/lib/src/query.dart | 7 +- angel_orm_generator/build.yaml | 2 +- .../lib/src/orm_build_context.dart | 15 +- .../lib/src/orm_generator.dart | 2 +- angel_orm_generator/pubspec.yaml | 6 +- angel_orm_generator/test/has_one_test.dart | 1 + angel_orm_generator/test/models/author.g.dart | 32 ++-- angel_orm_generator/test/models/book.g.dart | 135 ++-------------- angel_orm_generator/test/models/car.g.dart | 25 ++- .../test/models/customer.g.dart | 20 +-- angel_orm_generator/test/models/foot.g.dart | 22 +-- angel_orm_generator/test/models/fruit.g.dart | 20 +-- .../test/models/has_car.g.dart | 19 ++- .../test/models/has_map.g.dart | 18 +-- angel_orm_generator/test/models/leg.g.dart | 90 ++--------- angel_orm_generator/test/models/order.g.dart | 137 ++-------------- angel_orm_generator/test/models/tree.g.dart | 149 +++--------------- angel_orm_generator/test/models/user.g.dart | 77 ++++----- 18 files changed, 201 insertions(+), 576 deletions(-) diff --git a/angel_orm/lib/src/query.dart b/angel_orm/lib/src/query.dart index 8295049a..48f28bd4 100644 --- a/angel_orm/lib/src/query.dart +++ b/angel_orm/lib/src/query.dart @@ -280,9 +280,10 @@ abstract class Query extends QueryBase { return ss; })); _joins.forEach((j) { - f - ..add(j.fieldName) - ..addAll(j.additionalFields.map((s) => j.nameFor(s))); + var additional = j.additionalFields.map((s) => j.nameFor(s)).toList(); + // if (!additional.contains(j.fieldName)) + // additional.insert(0, j.fieldName); + f.addAll(additional); }); } if (withFields) b.write(f.join(', ')); diff --git a/angel_orm_generator/build.yaml b/angel_orm_generator/build.yaml index 97b7656b..914e012a 100644 --- a/angel_orm_generator/build.yaml +++ b/angel_orm_generator/build.yaml @@ -30,7 +30,7 @@ targets: - test/models/role.dart $default: dependencies: - - :_standalone + - angel_orm:_standalone sources: - test/models/book.dart - test/models/has_car.dart diff --git a/angel_orm_generator/lib/src/orm_build_context.dart b/angel_orm_generator/lib/src/orm_build_context.dart index 5d39823d..aa9606f0 100644 --- a/angel_orm_generator/lib/src/orm_build_context.dart +++ b/angel_orm_generator/lib/src/orm_build_context.dart @@ -177,13 +177,14 @@ Future buildOrmContext( ctx.buildContext.aliases[name] = relation.localKey; if (!ctx.effectiveFields.any((f) => f.name == field.name)) { - if (field.name != 'id' || - !const TypeChecker.fromRuntime(Model) - .isAssignableFromType(ctx.buildContext.clazz.type)) { - var rf = new RelationFieldImpl(name, - field.type.element.context.typeProvider.intType, field.name); - ctx.effectiveFields.add(rf); - } + // TODO: Consequences of allowing ID to be a relation? (should be none) + // if (field.name != 'id' || + // !const TypeChecker.fromRuntime(Model) + // .isAssignableFromType(ctx.buildContext.clazz.type)) { + var rf = new RelationFieldImpl(name, + field.type.element.context.typeProvider.intType, field.name); + ctx.effectiveFields.add(rf); + // } } } diff --git a/angel_orm_generator/lib/src/orm_generator.dart b/angel_orm_generator/lib/src/orm_generator.dart index a31fb3c0..2ec8b95d 100644 --- a/angel_orm_generator/lib/src/orm_generator.dart +++ b/angel_orm_generator/lib/src/orm_generator.dart @@ -281,7 +281,7 @@ class OrmGenerator extends GeneratorForAnnotation { relation.type == RelationshipType.hasMany) { var foreign = ctx.relationTypes[relation]; var additionalFields = foreign.effectiveFields - .where((f) => f.name != 'id' || !isSpecialId(ctx, f)) + // .where((f) => f.name != 'id' || !isSpecialId(ctx, f)) .map((f) => literalString( foreign.buildContext.resolveFieldName(f.name))); var joinArgs = [relation.localKey, relation.foreignKey] diff --git a/angel_orm_generator/pubspec.yaml b/angel_orm_generator/pubspec.yaml index 45823504..93620732 100644 --- a/angel_orm_generator/pubspec.yaml +++ b/angel_orm_generator/pubspec.yaml @@ -34,6 +34,6 @@ dev_dependencies: collection: ^1.0.0 postgres: ^1.0.0 test: ^1.0.0 -# dependency_overrides: -# angel_orm: -# path: ../angel_orm +dependency_overrides: + angel_orm: + path: ../angel_orm diff --git a/angel_orm_generator/test/has_one_test.dart b/angel_orm_generator/test/has_one_test.dart index cd05c064..a1ecec57 100644 --- a/angel_orm_generator/test/has_one_test.dart +++ b/angel_orm_generator/test/has_one_test.dart @@ -17,6 +17,7 @@ main() { }); test('sets to null if no child', () async { + print(LegQuery().compile(Set())); var query = new LegQuery()..where.id.equals(int.parse(originalLeg.id)); var leg = await query.getOne(executor); print(leg.toJson()); diff --git a/angel_orm_generator/test/models/author.g.dart b/angel_orm_generator/test/models/author.g.dart index 36ed24eb..1442aa04 100644 --- a/angel_orm_generator/test/models/author.g.dart +++ b/angel_orm_generator/test/models/author.g.dart @@ -31,11 +31,11 @@ class AuthorQuery extends Query { AuthorQuery({Set trampoline}) { trampoline ??= Set(); trampoline.add(tableName); - _where = new AuthorQueryWhere(this); + _where = AuthorQueryWhere(this); } @override - final AuthorQueryValues values = new AuthorQueryValues(); + final AuthorQueryValues values = AuthorQueryValues(); AuthorQueryWhere _where; @@ -61,12 +61,12 @@ class AuthorQuery extends Query { @override AuthorQueryWhere newWhereClause() { - return new AuthorQueryWhere(this); + return AuthorQueryWhere(this); } static Author parseRow(List row) { if (row.every((x) => x == null)) return null; - var model = new Author( + var model = Author( id: row[0].toString(), name: (row[1] as String), createdAt: (row[2] as DateTime), @@ -82,10 +82,10 @@ class AuthorQuery extends Query { class AuthorQueryWhere extends QueryWhere { AuthorQueryWhere(AuthorQuery query) - : id = new NumericSqlExpressionBuilder(query, 'id'), - name = new StringSqlExpressionBuilder(query, 'name'), - createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at'); + : id = NumericSqlExpressionBuilder(query, 'id'), + name = StringSqlExpressionBuilder(query, 'name'), + createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), + updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'); final NumericSqlExpressionBuilder id; @@ -140,7 +140,11 @@ class AuthorQueryValues extends MapQueryValues { @generatedSerializable 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 final String id; @@ -187,6 +191,10 @@ class Author extends _Author { abstract class AuthorSerializer { static Author fromMap(Map map) { + if (map['name'] == null) { + throw new FormatException("Missing required field 'name' on Author."); + } + return new Author( id: map['id'] as String, name: map['name'] as String ?? 'Tobe Osakwe', @@ -206,6 +214,10 @@ abstract class AuthorSerializer { if (model == null) { return null; } + if (model.name == null) { + throw new FormatException("Missing required field 'name' on Author."); + } + return { 'id': model.id, 'name': model.name, @@ -216,7 +228,7 @@ abstract class AuthorSerializer { } abstract class AuthorFields { - static const List allFields = const [ + static const List allFields = [ id, name, createdAt, diff --git a/angel_orm_generator/test/models/book.g.dart b/angel_orm_generator/test/models/book.g.dart index 4d96c22f..176d6ef0 100644 --- a/angel_orm_generator/test/models/book.g.dart +++ b/angel_orm_generator/test/models/book.g.dart @@ -2,29 +2,6 @@ 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 // ************************************************************************** @@ -33,15 +10,11 @@ class BookQuery extends Query { BookQuery({Set trampoline}) { trampoline ??= Set(); trampoline.add(tableName); - _where = new 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']); + _where = BookQueryWhere(this); } @override - final BookQueryValues values = new BookQueryValues(); + final BookQueryValues values = BookQueryValues(); BookQueryWhere _where; @@ -57,14 +30,7 @@ class BookQuery extends Query { @override get fields { - return const [ - 'id', - 'author_id', - 'partner_author_id', - 'name', - 'created_at', - 'updated_at' - ]; + return const ['id']; } @override @@ -74,24 +40,12 @@ class BookQuery extends Query { @override BookQueryWhere newWhereClause() { - return new BookQueryWhere(this); + return BookQueryWhere(this); } static Book parseRow(List row) { if (row.every((x) => x == null)) return null; - var model = new Book( - 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())); - } + var model = Book(id: row[0].toString()); return model; } @@ -103,29 +57,13 @@ class BookQuery extends Query { class BookQueryWhere extends QueryWhere { BookQueryWhere(BookQuery query) - : id = new NumericSqlExpressionBuilder(query, 'id'), - authorId = new NumericSqlExpressionBuilder(query, 'author_id'), - partnerAuthorId = - new NumericSqlExpressionBuilder(query, 'partner_author_id'), - name = new StringSqlExpressionBuilder(query, 'name'), - createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at'); + : id = NumericSqlExpressionBuilder(query, 'id'); final NumericSqlExpressionBuilder id; - final NumericSqlExpressionBuilder authorId; - - final NumericSqlExpressionBuilder partnerAuthorId; - - final StringSqlExpressionBuilder name; - - final DateTimeSqlExpressionBuilder createdAt; - - final DateTimeSqlExpressionBuilder updatedAt; - @override 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; - int get authorId { - return (values['author_id'] as int); - } - - set authorId(int value) => values['author_id'] = value; - int get partnerAuthorId { - return (values['partner_author_id'] as int); - } - - set partnerAuthorId(int value) => values['partner_author_id'] = value; - String get name { - return (values['name'] as String); - } - - set name(String value) => values['name'] = value; - 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); - } - } + void copyFrom(Book model) {} } // ************************************************************************** @@ -196,10 +99,10 @@ class Book extends _Book { final String id; @override - final Author author; + final dynamic author; @override - final Author partnerAuthor; + final dynamic partnerAuthor; @override final String name; @@ -212,8 +115,8 @@ class Book extends _Book { Book copyWith( {String id, - Author author, - Author partnerAuthor, + dynamic author, + dynamic partnerAuthor, String name, DateTime createdAt, DateTime updatedAt}) { @@ -254,12 +157,8 @@ abstract class BookSerializer { static Book fromMap(Map map) { return new 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, + author: map['author'] as dynamic, + partnerAuthor: map['partner_author'] as dynamic, name: map['name'] as String, createdAt: map['created_at'] != null ? (map['created_at'] is DateTime @@ -279,8 +178,8 @@ abstract class BookSerializer { } return { 'id': model.id, - 'author': AuthorSerializer.toMap(model.author), - 'partner_author': AuthorSerializer.toMap(model.partnerAuthor), + 'author': model.author, + 'partner_author': model.partnerAuthor, 'name': model.name, 'created_at': model.createdAt?.toIso8601String(), 'updated_at': model.updatedAt?.toIso8601String() @@ -289,7 +188,7 @@ abstract class BookSerializer { } abstract class BookFields { - static const List allFields = const [ + static const List allFields = [ id, author, partnerAuthor, diff --git a/angel_orm_generator/test/models/car.g.dart b/angel_orm_generator/test/models/car.g.dart index de8cefc5..bda68199 100644 --- a/angel_orm_generator/test/models/car.g.dart +++ b/angel_orm_generator/test/models/car.g.dart @@ -34,11 +34,11 @@ class CarQuery extends Query { CarQuery({Set trampoline}) { trampoline ??= Set(); trampoline.add(tableName); - _where = new CarQueryWhere(this); + _where = CarQueryWhere(this); } @override - final CarQueryValues values = new CarQueryValues(); + final CarQueryValues values = CarQueryValues(); CarQueryWhere _where; @@ -72,12 +72,12 @@ class CarQuery extends Query { @override CarQueryWhere newWhereClause() { - return new CarQueryWhere(this); + return CarQueryWhere(this); } static Car parseRow(List row) { if (row.every((x) => x == null)) return null; - var model = new Car( + var model = Car( id: row[0].toString(), make: (row[1] as String), description: (row[2] as String), @@ -96,14 +96,13 @@ class CarQuery extends Query { class CarQueryWhere extends QueryWhere { CarQueryWhere(CarQuery query) - : id = new NumericSqlExpressionBuilder(query, 'id'), - make = new StringSqlExpressionBuilder(query, 'make'), - description = new StringSqlExpressionBuilder(query, 'description'), - familyFriendly = - new BooleanSqlExpressionBuilder(query, 'family_friendly'), - recalledAt = new DateTimeSqlExpressionBuilder(query, 'recalled_at'), - createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at'); + : id = NumericSqlExpressionBuilder(query, 'id'), + 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'); final NumericSqlExpressionBuilder id; @@ -312,7 +311,7 @@ abstract class CarSerializer { } abstract class CarFields { - static const List allFields = const [ + static const List allFields = [ id, make, description, diff --git a/angel_orm_generator/test/models/customer.g.dart b/angel_orm_generator/test/models/customer.g.dart index 06101def..80962d9b 100644 --- a/angel_orm_generator/test/models/customer.g.dart +++ b/angel_orm_generator/test/models/customer.g.dart @@ -30,11 +30,11 @@ class CustomerQuery extends Query { CustomerQuery({Set trampoline}) { trampoline ??= Set(); trampoline.add(tableName); - _where = new CustomerQueryWhere(this); + _where = CustomerQueryWhere(this); } @override - final CustomerQueryValues values = new CustomerQueryValues(); + final CustomerQueryValues values = CustomerQueryValues(); CustomerQueryWhere _where; @@ -60,12 +60,12 @@ class CustomerQuery extends Query { @override CustomerQueryWhere newWhereClause() { - return new CustomerQueryWhere(this); + return CustomerQueryWhere(this); } static Customer parseRow(List row) { if (row.every((x) => x == null)) return null; - var model = new Customer( + var model = Customer( id: row[0].toString(), createdAt: (row[1] as DateTime), updatedAt: (row[2] as DateTime)); @@ -80,9 +80,9 @@ class CustomerQuery extends Query { class CustomerQueryWhere extends QueryWhere { CustomerQueryWhere(CustomerQuery query) - : id = new NumericSqlExpressionBuilder(query, 'id'), - createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at'); + : id = NumericSqlExpressionBuilder(query, 'id'), + createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), + updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'); final NumericSqlExpressionBuilder id; @@ -197,11 +197,7 @@ abstract class CustomerSerializer { } abstract class CustomerFields { - static const List allFields = const [ - id, - createdAt, - updatedAt - ]; + static const List allFields = [id, createdAt, updatedAt]; static const String id = 'id'; diff --git a/angel_orm_generator/test/models/foot.g.dart b/angel_orm_generator/test/models/foot.g.dart index 3fbda325..5f8d050e 100644 --- a/angel_orm_generator/test/models/foot.g.dart +++ b/angel_orm_generator/test/models/foot.g.dart @@ -12,7 +12,7 @@ class FootMigration extends Migration { schema.create('feet', (table) { table.serial('id')..primaryKey(); table.integer('leg_id'); - table.declare('n_toes', new ColumnType('decimal')); + table.declare('n_toes', ColumnType('decimal')); table.timeStamp('created_at'); table.timeStamp('updated_at'); }); @@ -32,11 +32,11 @@ class FootQuery extends Query { FootQuery({Set trampoline}) { trampoline ??= Set(); trampoline.add(tableName); - _where = new FootQueryWhere(this); + _where = FootQueryWhere(this); } @override - final FootQueryValues values = new FootQueryValues(); + final FootQueryValues values = FootQueryValues(); FootQueryWhere _where; @@ -62,12 +62,12 @@ class FootQuery extends Query { @override FootQueryWhere newWhereClause() { - return new FootQueryWhere(this); + return FootQueryWhere(this); } static Foot parseRow(List row) { if (row.every((x) => x == null)) return null; - var model = new Foot( + var model = Foot( id: row[0].toString(), legId: (row[1] as int), nToes: double.parse(row[2].toString()), @@ -84,11 +84,11 @@ class FootQuery extends Query { class FootQueryWhere extends QueryWhere { FootQueryWhere(FootQuery query) - : id = new NumericSqlExpressionBuilder(query, 'id'), - legId = new NumericSqlExpressionBuilder(query, 'leg_id'), - nToes = new NumericSqlExpressionBuilder(query, 'n_toes'), - createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at'); + : id = NumericSqlExpressionBuilder(query, 'id'), + legId = NumericSqlExpressionBuilder(query, 'leg_id'), + nToes = NumericSqlExpressionBuilder(query, 'n_toes'), + createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), + updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'); final NumericSqlExpressionBuilder id; @@ -238,7 +238,7 @@ abstract class FootSerializer { } abstract class FootFields { - static const List allFields = const [ + static const List allFields = [ id, legId, nToes, diff --git a/angel_orm_generator/test/models/fruit.g.dart b/angel_orm_generator/test/models/fruit.g.dart index dce35760..11f16b4a 100644 --- a/angel_orm_generator/test/models/fruit.g.dart +++ b/angel_orm_generator/test/models/fruit.g.dart @@ -32,11 +32,11 @@ class FruitQuery extends Query { FruitQuery({Set trampoline}) { trampoline ??= Set(); trampoline.add(tableName); - _where = new FruitQueryWhere(this); + _where = FruitQueryWhere(this); } @override - final FruitQueryValues values = new FruitQueryValues(); + final FruitQueryValues values = FruitQueryValues(); FruitQueryWhere _where; @@ -62,12 +62,12 @@ class FruitQuery extends Query { @override FruitQueryWhere newWhereClause() { - return new FruitQueryWhere(this); + return FruitQueryWhere(this); } static Fruit parseRow(List row) { if (row.every((x) => x == null)) return null; - var model = new Fruit( + var model = Fruit( id: row[0].toString(), treeId: (row[1] as int), commonName: (row[2] as String), @@ -84,11 +84,11 @@ class FruitQuery extends Query { class FruitQueryWhere extends QueryWhere { FruitQueryWhere(FruitQuery query) - : id = new NumericSqlExpressionBuilder(query, 'id'), - treeId = new NumericSqlExpressionBuilder(query, 'tree_id'), - commonName = new StringSqlExpressionBuilder(query, 'common_name'), - createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at'); + : id = NumericSqlExpressionBuilder(query, 'id'), + treeId = NumericSqlExpressionBuilder(query, 'tree_id'), + commonName = StringSqlExpressionBuilder(query, 'common_name'), + createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), + updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'); final NumericSqlExpressionBuilder id; @@ -239,7 +239,7 @@ abstract class FruitSerializer { } abstract class FruitFields { - static const List allFields = const [ + static const List allFields = [ id, treeId, commonName, diff --git a/angel_orm_generator/test/models/has_car.g.dart b/angel_orm_generator/test/models/has_car.g.dart index 12ba1172..8b0c4d70 100644 --- a/angel_orm_generator/test/models/has_car.g.dart +++ b/angel_orm_generator/test/models/has_car.g.dart @@ -31,11 +31,11 @@ class HasCarQuery extends Query { HasCarQuery({Set trampoline}) { trampoline ??= Set(); trampoline.add(tableName); - _where = new HasCarQueryWhere(this); + _where = HasCarQueryWhere(this); } @override - final HasCarQueryValues values = new HasCarQueryValues(); + final HasCarQueryValues values = HasCarQueryValues(); HasCarQueryWhere _where; @@ -61,12 +61,12 @@ class HasCarQuery extends Query { @override HasCarQueryWhere newWhereClause() { - return new HasCarQueryWhere(this); + return HasCarQueryWhere(this); } static HasCar parseRow(List row) { if (row.every((x) => x == null)) return null; - var model = new HasCar( + var model = HasCar( id: row[0].toString(), type: CarType.values[(row[1] as int)], createdAt: (row[2] as DateTime), @@ -82,11 +82,10 @@ class HasCarQuery extends Query { class HasCarQueryWhere extends QueryWhere { HasCarQueryWhere(HasCarQuery query) - : id = new NumericSqlExpressionBuilder(query, 'id'), - type = new EnumSqlExpressionBuilder( - query, 'type', (v) => v.index), - createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at'); + : id = NumericSqlExpressionBuilder(query, 'id'), + type = EnumSqlExpressionBuilder(query, 'type', (v) => v.index), + createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), + updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'); final NumericSqlExpressionBuilder id; @@ -227,7 +226,7 @@ abstract class HasCarSerializer { } abstract class HasCarFields { - static const List allFields = const [ + static const List allFields = [ id, type, createdAt, diff --git a/angel_orm_generator/test/models/has_map.g.dart b/angel_orm_generator/test/models/has_map.g.dart index e96923f2..0a662e5d 100644 --- a/angel_orm_generator/test/models/has_map.g.dart +++ b/angel_orm_generator/test/models/has_map.g.dart @@ -10,8 +10,8 @@ class HasMapMigration extends Migration { @override up(Schema schema) { schema.create('has_maps', (table) { - table.declare('value', new ColumnType('jsonb')); - table.declare('list', new ColumnType('jsonb')); + table.declare('value', ColumnType('jsonb')); + table.declare('list', ColumnType('jsonb')); }); } @@ -29,11 +29,11 @@ class HasMapQuery extends Query { HasMapQuery({Set trampoline}) { trampoline ??= Set(); trampoline.add(tableName); - _where = new HasMapQueryWhere(this); + _where = HasMapQueryWhere(this); } @override - final HasMapQueryValues values = new HasMapQueryValues(); + final HasMapQueryValues values = HasMapQueryValues(); HasMapQueryWhere _where; @@ -59,12 +59,12 @@ class HasMapQuery extends Query { @override HasMapQueryWhere newWhereClause() { - return new HasMapQueryWhere(this); + return HasMapQueryWhere(this); } static HasMap parseRow(List row) { if (row.every((x) => x == null)) return null; - var model = new HasMap( + var model = HasMap( value: (row[0] as Map), list: (row[1] as List)); return model; @@ -78,8 +78,8 @@ class HasMapQuery extends Query { class HasMapQueryWhere extends QueryWhere { HasMapQueryWhere(HasMapQuery query) - : value = new MapSqlExpressionBuilder(query, 'value'), - list = new ListSqlExpressionBuilder(query, 'list'); + : value = MapSqlExpressionBuilder(query, 'value'), + list = ListSqlExpressionBuilder(query, 'list'); final MapSqlExpressionBuilder value; @@ -174,7 +174,7 @@ abstract class HasMapSerializer { } abstract class HasMapFields { - static const List allFields = const [value, list]; + static const List allFields = [value, list]; static const String value = 'value'; diff --git a/angel_orm_generator/test/models/leg.g.dart b/angel_orm_generator/test/models/leg.g.dart index e522c81b..36cc27c4 100644 --- a/angel_orm_generator/test/models/leg.g.dart +++ b/angel_orm_generator/test/models/leg.g.dart @@ -2,27 +2,6 @@ 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 // ************************************************************************** @@ -31,17 +10,11 @@ class LegQuery extends Query { LegQuery({Set trampoline}) { trampoline ??= Set(); trampoline.add(tableName); - _where = new LegQueryWhere(this); - leftJoin('feet', 'id', 'leg_id', additionalFields: const [ - 'leg_id', - 'n_toes', - 'created_at', - 'updated_at' - ]); + _where = LegQueryWhere(this); } @override - final LegQueryValues values = new LegQueryValues(); + final LegQueryValues values = LegQueryValues(); LegQueryWhere _where; @@ -57,7 +30,7 @@ class LegQuery extends Query { @override get fields { - return const ['id', 'name', 'created_at', 'updated_at']; + return const ['id']; } @override @@ -67,19 +40,12 @@ class LegQuery extends Query { @override LegQueryWhere newWhereClause() { - return new LegQueryWhere(this); + return LegQueryWhere(this); } static Leg parseRow(List row) { if (row.every((x) => x == null)) return null; - var model = new Leg( - 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())); - } + var model = Leg(id: row[0].toString()); return model; } @@ -91,22 +57,13 @@ class LegQuery extends Query { class LegQueryWhere extends QueryWhere { LegQueryWhere(LegQuery query) - : id = new NumericSqlExpressionBuilder(query, 'id'), - name = new StringSqlExpressionBuilder(query, 'name'), - createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at'); + : id = NumericSqlExpressionBuilder(query, 'id'); final NumericSqlExpressionBuilder id; - final StringSqlExpressionBuilder name; - - final DateTimeSqlExpressionBuilder createdAt; - - final DateTimeSqlExpressionBuilder updatedAt; - @override get expressionBuilders { - return [id, name, createdAt, updatedAt]; + return [id]; } } @@ -121,26 +78,7 @@ class LegQueryValues extends MapQueryValues { } set id(int 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); - } - - 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; - } + void copyFrom(Leg model) {} } // ************************************************************************** @@ -155,7 +93,7 @@ class Leg extends _Leg { final String id; @override - final Foot foot; + final dynamic foot; @override final String name; @@ -168,7 +106,7 @@ class Leg extends _Leg { Leg copyWith( {String id, - Foot foot, + dynamic foot, String name, DateTime createdAt, DateTime updatedAt}) { @@ -207,9 +145,7 @@ abstract class LegSerializer { static Leg fromMap(Map map) { return new Leg( id: map['id'] as String, - foot: map['foot'] != null - ? FootSerializer.fromMap(map['foot'] as Map) - : null, + foot: map['foot'] as dynamic, name: map['name'] as String, createdAt: map['created_at'] != null ? (map['created_at'] is DateTime @@ -229,7 +165,7 @@ abstract class LegSerializer { } return { 'id': model.id, - 'foot': FootSerializer.toMap(model.foot), + 'foot': model.foot, 'name': model.name, 'created_at': model.createdAt?.toIso8601String(), 'updated_at': model.updatedAt?.toIso8601String() @@ -238,7 +174,7 @@ abstract class LegSerializer { } abstract class LegFields { - static const List allFields = const [ + static const List allFields = [ id, foot, name, diff --git a/angel_orm_generator/test/models/order.g.dart b/angel_orm_generator/test/models/order.g.dart index 5008ef06..e009f8de 100644 --- a/angel_orm_generator/test/models/order.g.dart +++ b/angel_orm_generator/test/models/order.g.dart @@ -2,30 +2,6 @@ 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 // ************************************************************************** @@ -34,13 +10,11 @@ class OrderQuery extends Query { OrderQuery({Set trampoline}) { trampoline ??= Set(); trampoline.add(tableName); - _where = new OrderQueryWhere(this); - leftJoin('customers', 'customer_id', 'id', - additionalFields: const ['created_at', 'updated_at']); + _where = OrderQueryWhere(this); } @override - final OrderQueryValues values = new OrderQueryValues(); + final OrderQueryValues values = OrderQueryValues(); OrderQueryWhere _where; @@ -56,15 +30,7 @@ class OrderQuery extends Query { @override get fields { - return const [ - 'id', - 'customer_id', - 'employee_id', - 'order_date', - 'shipper_id', - 'created_at', - 'updated_at' - ]; + return const ['id']; } @override @@ -74,22 +40,12 @@ class OrderQuery extends Query { @override OrderQueryWhere newWhereClause() { - return new OrderQueryWhere(this); + return OrderQueryWhere(this); } static Order parseRow(List row) { if (row.every((x) => x == null)) return null; - var model = new 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)); - if (row.length > 7) { - model = model.copyWith( - customer: CustomerQuery.parseRow(row.skip(7).toList())); - } + var model = Order(id: row[0].toString()); return model; } @@ -101,39 +57,13 @@ class OrderQuery extends Query { class OrderQueryWhere extends QueryWhere { OrderQueryWhere(OrderQuery query) - : id = new NumericSqlExpressionBuilder(query, 'id'), - customerId = new NumericSqlExpressionBuilder(query, 'customer_id'), - employeeId = new NumericSqlExpressionBuilder(query, 'employee_id'), - orderDate = new DateTimeSqlExpressionBuilder(query, 'order_date'), - shipperId = new NumericSqlExpressionBuilder(query, 'shipper_id'), - createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at'); + : id = NumericSqlExpressionBuilder(query, 'id'); final NumericSqlExpressionBuilder id; - final NumericSqlExpressionBuilder customerId; - - final NumericSqlExpressionBuilder employeeId; - - final DateTimeSqlExpressionBuilder orderDate; - - final NumericSqlExpressionBuilder shipperId; - - final DateTimeSqlExpressionBuilder createdAt; - - final DateTimeSqlExpressionBuilder updatedAt; - @override get expressionBuilders { - return [ - id, - customerId, - employeeId, - orderDate, - shipperId, - createdAt, - updatedAt - ]; + return [id]; } } @@ -148,46 +78,7 @@ class OrderQueryValues extends MapQueryValues { } set id(int value) => values['id'] = value; - int get customerId { - 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); - } - } + void copyFrom(Order model) {} } // ************************************************************************** @@ -209,7 +100,7 @@ class Order extends _Order { final String id; @override - final Customer customer; + final dynamic customer; @override final int employeeId; @@ -228,7 +119,7 @@ class Order extends _Order { Order copyWith( {String id, - Customer customer, + dynamic customer, int employeeId, DateTime orderDate, int shipperId, @@ -274,9 +165,7 @@ abstract class OrderSerializer { static Order fromMap(Map map) { return new Order( id: map['id'] as String, - customer: map['customer'] != null - ? CustomerSerializer.fromMap(map['customer'] as Map) - : null, + customer: map['customer'] as dynamic, employeeId: map['employee_id'] as int, orderDate: map['order_date'] != null ? (map['order_date'] is DateTime @@ -302,7 +191,7 @@ abstract class OrderSerializer { } return { 'id': model.id, - 'customer': CustomerSerializer.toMap(model.customer), + 'customer': model.customer, 'employee_id': model.employeeId, 'order_date': model.orderDate?.toIso8601String(), 'shipper_id': model.shipperId, @@ -313,7 +202,7 @@ abstract class OrderSerializer { } abstract class OrderFields { - static const List allFields = const [ + static const List allFields = [ id, customer, employeeId, diff --git a/angel_orm_generator/test/models/tree.g.dart b/angel_orm_generator/test/models/tree.g.dart index 2ce3e14b..4de935c7 100644 --- a/angel_orm_generator/test/models/tree.g.dart +++ b/angel_orm_generator/test/models/tree.g.dart @@ -2,27 +2,6 @@ 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 // ************************************************************************** @@ -31,18 +10,11 @@ class TreeQuery extends Query { TreeQuery({Set trampoline}) { trampoline ??= Set(); trampoline.add(tableName); - _where = new TreeQueryWhere(this); - leftJoin(new FruitQuery(trampoline: trampoline), 'id', 'tree_id', - additionalFields: const [ - 'tree_id', - 'common_name', - 'created_at', - 'updated_at' - ]); + _where = TreeQueryWhere(this); } @override - final TreeQueryValues values = new TreeQueryValues(); + final TreeQueryValues values = TreeQueryValues(); TreeQueryWhere _where; @@ -58,7 +30,7 @@ class TreeQuery extends Query { @override get fields { - return const ['id', 'rings', 'created_at', 'updated_at']; + return const ['id', 'rings']; } @override @@ -68,22 +40,12 @@ class TreeQuery extends Query { @override TreeQueryWhere newWhereClause() { - return new TreeQueryWhere(this); + return TreeQueryWhere(this); } static Tree parseRow(List row) { if (row.every((x) => x == null)) return null; - var model = new Tree( - 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()); - } + var model = Tree(id: row[0].toString(), rings: (row[1] as int)); return model; } @@ -91,83 +53,20 @@ class TreeQuery extends Query { deserialize(List row) { return parseRow(row); } - - @override - get(QueryExecutor executor) { - return super.get(executor).then((result) { - return result.fold>([], (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.from(l.fruits ?? []) - ..addAll(model.fruits ?? [])); - } - }); - }); - } - - @override - update(QueryExecutor executor) { - return super.update(executor).then((result) { - return result.fold>([], (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.from(l.fruits ?? []) - ..addAll(model.fruits ?? [])); - } - }); - }); - } - - @override - delete(QueryExecutor executor) { - return super.delete(executor).then((result) { - return result.fold>([], (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.from(l.fruits ?? []) - ..addAll(model.fruits ?? [])); - } - }); - }); - } } class TreeQueryWhere extends QueryWhere { TreeQueryWhere(TreeQuery query) - : id = new NumericSqlExpressionBuilder(query, 'id'), - rings = new NumericSqlExpressionBuilder(query, 'rings'), - createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at'); + : id = NumericSqlExpressionBuilder(query, 'id'), + rings = NumericSqlExpressionBuilder(query, 'rings'); final NumericSqlExpressionBuilder id; final NumericSqlExpressionBuilder rings; - final DateTimeSqlExpressionBuilder createdAt; - - final DateTimeSqlExpressionBuilder updatedAt; - @override 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; - 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) { rings = model.rings; - createdAt = model.createdAt; - updatedAt = model.updatedAt; } } @@ -211,7 +98,11 @@ class TreeQueryValues extends MapQueryValues { @generatedSerializable class Tree extends _Tree { Tree( - {this.id, this.rings, List fruits, this.createdAt, this.updatedAt}) + {this.id, + this.rings, + List fruits, + this.createdAt, + this.updatedAt}) : this.fruits = new List.unmodifiable(fruits ?? []); @override @@ -221,7 +112,7 @@ class Tree extends _Tree { final int rings; @override - final List fruits; + final List fruits; @override final DateTime createdAt; @@ -232,7 +123,7 @@ class Tree extends _Tree { Tree copyWith( {String id, int rings, - List fruits, + List fruits, DateTime createdAt, DateTime updatedAt}) { return new Tree( @@ -247,7 +138,7 @@ class Tree extends _Tree { return other is _Tree && other.id == id && other.rings == rings && - const ListEquality(const DefaultEquality()) + const ListEquality(const DefaultEquality()) .equals(other.fruits, fruits) && other.createdAt == createdAt && other.updatedAt == updatedAt; @@ -273,9 +164,7 @@ abstract class TreeSerializer { 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) as Iterable) - .map(FruitSerializer.fromMap)) + ? (map['fruits'] as Iterable).cast().toList() : null, createdAt: map['created_at'] != null ? (map['created_at'] is DateTime @@ -296,7 +185,7 @@ abstract class TreeSerializer { return { 'id': model.id, 'rings': model.rings, - 'fruits': model.fruits?.map((m) => FruitSerializer.toMap(m))?.toList(), + 'fruits': model.fruits, 'created_at': model.createdAt?.toIso8601String(), 'updated_at': model.updatedAt?.toIso8601String() }; @@ -304,7 +193,7 @@ abstract class TreeSerializer { } abstract class TreeFields { - static const List allFields = const [ + static const List allFields = [ id, rings, fruits, diff --git a/angel_orm_generator/test/models/user.g.dart b/angel_orm_generator/test/models/user.g.dart index eeddb98b..ed008722 100644 --- a/angel_orm_generator/test/models/user.g.dart +++ b/angel_orm_generator/test/models/user.g.dart @@ -68,11 +68,11 @@ class UserQuery extends Query { UserQuery({Set trampoline}) { trampoline ??= Set(); trampoline.add(tableName); - _where = new UserQueryWhere(this); + _where = UserQueryWhere(this); } @override - final UserQueryValues values = new UserQueryValues(); + final UserQueryValues values = UserQueryValues(); UserQueryWhere _where; @@ -105,12 +105,12 @@ class UserQuery extends Query { @override UserQueryWhere newWhereClause() { - return new UserQueryWhere(this); + return UserQueryWhere(this); } static User parseRow(List row) { if (row.every((x) => x == null)) return null; - var model = new User( + var model = User( id: row[0].toString(), username: (row[1] as String), password: (row[2] as String), @@ -128,12 +128,12 @@ class UserQuery extends Query { class UserQueryWhere extends QueryWhere { UserQueryWhere(UserQuery query) - : id = new NumericSqlExpressionBuilder(query, 'id'), - username = new StringSqlExpressionBuilder(query, 'username'), - password = new StringSqlExpressionBuilder(query, 'password'), - email = new StringSqlExpressionBuilder(query, 'email'), - createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at'); + : id = NumericSqlExpressionBuilder(query, 'id'), + username = StringSqlExpressionBuilder(query, 'username'), + password = StringSqlExpressionBuilder(query, 'password'), + email = StringSqlExpressionBuilder(query, 'email'), + createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), + updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'); final NumericSqlExpressionBuilder id; @@ -202,10 +202,11 @@ class RoleUserQuery extends Query { RoleUserQuery({Set trampoline}) { trampoline ??= Set(); trampoline.add(tableName); - _where = new RoleUserQueryWhere(this); + _where = RoleUserQueryWhere(this); 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 [ + 'id', 'username', 'password', 'email', @@ -215,7 +216,7 @@ class RoleUserQuery extends Query { } @override - final RoleUserQueryValues values = new RoleUserQueryValues(); + final RoleUserQueryValues values = RoleUserQueryValues(); RoleUserQueryWhere _where; @@ -241,12 +242,12 @@ class RoleUserQuery extends Query { @override RoleUserQueryWhere newWhereClause() { - return new RoleUserQueryWhere(this); + return RoleUserQueryWhere(this); } static RoleUser parseRow(List row) { if (row.every((x) => x == null)) return null; - var model = new RoleUser( + var model = RoleUser( id: row[0].toString(), createdAt: (row[3] as DateTime), updatedAt: (row[4] as DateTime)); @@ -267,11 +268,11 @@ class RoleUserQuery extends Query { class RoleUserQueryWhere extends QueryWhere { RoleUserQueryWhere(RoleUserQuery query) - : id = new NumericSqlExpressionBuilder(query, 'id'), - roleId = new NumericSqlExpressionBuilder(query, 'role_id'), - userId = new NumericSqlExpressionBuilder(query, 'user_id'), - createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at'); + : id = NumericSqlExpressionBuilder(query, 'id'), + roleId = NumericSqlExpressionBuilder(query, 'role_id'), + userId = NumericSqlExpressionBuilder(query, 'user_id'), + createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), + updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'); final NumericSqlExpressionBuilder id; @@ -336,11 +337,11 @@ class RoleQuery extends Query { RoleQuery({Set trampoline}) { trampoline ??= Set(); trampoline.add(tableName); - _where = new RoleQueryWhere(this); + _where = RoleQueryWhere(this); } @override - final RoleQueryValues values = new RoleQueryValues(); + final RoleQueryValues values = RoleQueryValues(); RoleQueryWhere _where; @@ -366,12 +367,12 @@ class RoleQuery extends Query { @override RoleQueryWhere newWhereClause() { - return new RoleQueryWhere(this); + return RoleQueryWhere(this); } static Role parseRow(List row) { if (row.every((x) => x == null)) return null; - var model = new Role( + var model = Role( id: row[0].toString(), name: (row[1] as String), createdAt: (row[2] as DateTime), @@ -387,10 +388,10 @@ class RoleQuery extends Query { class RoleQueryWhere extends QueryWhere { RoleQueryWhere(RoleQuery query) - : id = new NumericSqlExpressionBuilder(query, 'id'), - name = new StringSqlExpressionBuilder(query, 'name'), - createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at'); + : id = NumericSqlExpressionBuilder(query, 'id'), + name = StringSqlExpressionBuilder(query, 'name'), + createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), + updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'); final NumericSqlExpressionBuilder id; @@ -635,9 +636,10 @@ abstract class UserSerializer { 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) as Iterable) - .map(RoleSerializer.fromMap)) + ? new List.unmodifiable( + ((map['roles'] as Iterable).where((x) => x is Map)) + .cast() + .map(RoleSerializer.fromMap)) : null, createdAt: map['created_at'] != null ? (map['created_at'] is DateTime @@ -668,7 +670,7 @@ abstract class UserSerializer { } abstract class UserFields { - static const List allFields = const [ + static const List allFields = [ id, username, password, @@ -730,7 +732,7 @@ abstract class RoleUserSerializer { } abstract class RoleUserFields { - static const List allFields = const [ + static const List allFields = [ id, role, user, @@ -755,9 +757,10 @@ abstract class RoleSerializer { 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) as Iterable) - .map(UserSerializer.fromMap)) + ? new List.unmodifiable( + ((map['users'] as Iterable).where((x) => x is Map)) + .cast() + .map(UserSerializer.fromMap)) : null, createdAt: map['created_at'] != null ? (map['created_at'] is DateTime @@ -786,7 +789,7 @@ abstract class RoleSerializer { } abstract class RoleFields { - static const List allFields = const [ + static const List allFields = [ id, name, users,