diff --git a/packages/orm/angel_orm_generator/CHANGELOG.md b/packages/orm/angel_orm_generator/CHANGELOG.md index 99358794..49d9d8fe 100644 --- a/packages/orm/angel_orm_generator/CHANGELOG.md +++ b/packages/orm/angel_orm_generator/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## 7.0.1 + +* Fixed issue #82: Fixed issue #82: Removed casting for numeric fields + ## 7.0.0 * Require Dart >= 2.17 diff --git a/packages/orm/angel_orm_generator/example/main.g.dart b/packages/orm/angel_orm_generator/example/main.g.dart index c9da293d..ee868c9e 100644 --- a/packages/orm/angel_orm_generator/example/main.g.dart +++ b/packages/orm/angel_orm_generator/example/main.g.dart @@ -16,8 +16,7 @@ class EmployeeMigration extends Migration { table.varChar('unique_id', length: 255).unique(); table.varChar('first_name', length: 255); table.varChar('last_name', length: 255); - table.declareColumn( - 'salary', Column(type: ColumnType('decimal'), length: 255)); + table.double('salary'); }); } @@ -93,8 +92,12 @@ class EmployeeQuery extends Query { } var model = Employee( id: fields.contains('id') ? row[0].toString() : null, - createdAt: fields.contains('created_at') ? mapToDateTime(row[1]) : null, - updatedAt: fields.contains('updated_at') ? mapToDateTime(row[2]) : null, + createdAt: fields.contains('created_at') + ? mapToNullableDateTime(row[1]) + : null, + updatedAt: fields.contains('updated_at') + ? mapToNullableDateTime(row[2]) + : null, uniqueId: fields.contains('unique_id') ? (row[3] as String?) : null, firstName: fields.contains('first_name') ? (row[4] as String?) : null, lastName: fields.contains('last_name') ? (row[5] as String?) : null, @@ -141,7 +144,7 @@ class EmployeeQueryWhere extends QueryWhere { class EmployeeQueryValues extends MapQueryValues { @override Map get casts { - return {'salary': 'decimal'}; + return {'salary': 'double precision'}; } String? get id { @@ -175,10 +178,10 @@ class EmployeeQueryValues extends MapQueryValues { set lastName(String? value) => values['last_name'] = value; double? get salary { - return double.tryParse((values['salary'] as String)); + return (values['salary'] as double?) ?? 0.0; } - set salary(double? value) => values['salary'] = value.toString(); + set salary(double? value) => values['salary'] = value; void copyFrom(Employee model) { createdAt = model.createdAt; updatedAt = model.updatedAt; diff --git a/packages/orm/angel_orm_generator/lib/src/orm_generator.dart b/packages/orm/angel_orm_generator/lib/src/orm_generator.dart index f564d88a..82e19664 100644 --- a/packages/orm/angel_orm_generator/lib/src/orm_generator.dart +++ b/packages/orm/angel_orm_generator/lib/src/orm_generator.dart @@ -103,17 +103,19 @@ class OrmGenerator extends GeneratorForAnnotation { ..types.add(refer('String'))) ..type = MethodType.getter ..body = Block((b) { - var args = {}; + var args = {}; + /* Remove casts no numeric values for (var field in ctx.effectiveFields) { var name = ctx.buildContext.resolveFieldName(field.name); var type = ctx.columns[field.name]?.type; if (type == null) continue; if (floatTypes.contains(type)) { //args[name] = literalString('text'); - args[name] = literalString('char'); + args[name!] = literalString('char'); } } + */ b.addExpression(literalMap(args).returned); }); @@ -857,9 +859,11 @@ class OrmGenerator extends GeneratorForAnnotation { if (const TypeChecker.fromRuntime(List) .isAssignableFromType(fType)) { args[name] = literalString(type.name); - } else if (floatTypes.contains(type)) { - args[name] = literalString(type.name); } + + /* else if (floatTypes.contains(type)) { + args[name] = literalString(type.name); + } */ } b.addExpression(literalMap(args).returned); @@ -887,10 +891,14 @@ class OrmGenerator extends GeneratorForAnnotation { .property('cast') .call([]); } else if (floatTypes.contains(ctx.columns[field.name]?.type)) { - value = refer('double') - .property('tryParse') - .call([value.asA(refer('String'))]).ifNullThen( - CodeExpression(Code('0.0'))); + // Skip using casts on double + value = value + .asA(refer('double?')) + .ifNullThen(CodeExpression(Code('0.0'))); + //value = refer('double') + // .property('tryParse') + // .call([value.asA(refer('String'))]).ifNullThen( + // CodeExpression(Code('0.0'))); } else { value = value.asA(type); } @@ -910,10 +918,12 @@ class OrmGenerator extends GeneratorForAnnotation { } else if (const TypeChecker.fromRuntime(List) .isAssignableFromType(fType)) { value = refer('json').property('encode').call([value]); - } else if (floatTypes.contains(ctx.columns[field.name]?.type)) { - value = value.property('toString').call([]); } + /* else if (floatTypes.contains(ctx.columns[field.name]?.type)) { + value = value.property('toString').call([]); + } */ + b ..name = field.name ..type = MethodType.setter diff --git a/packages/orm/angel_orm_generator/pubspec.yaml b/packages/orm/angel_orm_generator/pubspec.yaml index a58b2c47..34c2ea0b 100644 --- a/packages/orm/angel_orm_generator/pubspec.yaml +++ b/packages/orm/angel_orm_generator/pubspec.yaml @@ -1,5 +1,5 @@ name: angel3_orm_generator -version: 7.0.0 +version: 7.0.1 description: Code generators for Angel3 ORM. Generates query builder classes. homepage: https://angel3-framework.web.app/ repository: https://github.com/dukefirehawk/angel/tree/master/packages/orm/angel_orm_generator diff --git a/packages/orm/angel_orm_mysql/test/migrations/foot.sql b/packages/orm/angel_orm_mysql/test/migrations/foot.sql index 308f1df2..2d527e87 100644 --- a/packages/orm/angel_orm_mysql/test/migrations/foot.sql +++ b/packages/orm/angel_orm_mysql/test/migrations/foot.sql @@ -1,7 +1,7 @@ CREATE TABLE IF NOT EXISTS feet ( id serial PRIMARY KEY, leg_id int NOT NULL, - n_toes int NOT NULL, + n_toes double precision NOT NULL, created_at datetime, updated_at datetime ); \ No newline at end of file diff --git a/packages/orm/angel_orm_postgres/pubspec.yaml b/packages/orm/angel_orm_postgres/pubspec.yaml index 2d16865c..21d3ef77 100644 --- a/packages/orm/angel_orm_postgres/pubspec.yaml +++ b/packages/orm/angel_orm_postgres/pubspec.yaml @@ -16,13 +16,13 @@ dev_dependencies: angel3_orm_test: ^7.0.0 test: ^1.21.0 lints: ^2.0.0 -# dependency_overrides: +dependency_overrides: # angel3_serialize: # path: ../../serialize/angel_serialize # angel3_model: # path: ../../model -# angel3_orm_test: -# path: ../angel_orm_test + angel3_orm_test: + path: ../angel_orm_test # angel3_orm: # path: ../angel_orm # angel3_migration: diff --git a/packages/orm/angel_orm_postgres/test/migrations/car.sql b/packages/orm/angel_orm_postgres/test/migrations/car.sql index 239d285d..1ccc3680 100644 --- a/packages/orm/angel_orm_postgres/test/migrations/car.sql +++ b/packages/orm/angel_orm_postgres/test/migrations/car.sql @@ -3,6 +3,7 @@ CREATE TEMPORARY TABLE "cars" ( make varchar(255) NOT NULL, description TEXT NOT NULL, family_friendly BOOLEAN NOT NULL, + price double precision, recalled_at timestamp, created_at timestamp, updated_at timestamp diff --git a/packages/orm/angel_orm_postgres/test/migrations/foot.sql b/packages/orm/angel_orm_postgres/test/migrations/foot.sql index af8bfc1a..586b08db 100644 --- a/packages/orm/angel_orm_postgres/test/migrations/foot.sql +++ b/packages/orm/angel_orm_postgres/test/migrations/foot.sql @@ -1,7 +1,7 @@ CREATE TEMPORARY TABLE "feet" ( id serial PRIMARY KEY, leg_id int NOT NULL, - n_toes int NOT NULL, + n_toes double precision NOT NULL, created_at timestamp, updated_at timestamp ); \ No newline at end of file diff --git a/packages/orm/angel_orm_test/CHANGELOG.md b/packages/orm/angel_orm_test/CHANGELOG.md index f363aaec..374be1f5 100644 --- a/packages/orm/angel_orm_test/CHANGELOG.md +++ b/packages/orm/angel_orm_test/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## 7.0.1 + +* Fixed issue #82: Removed casting for numeric fields + ## 7.0.0 * Require Dart >= 2.17 diff --git a/packages/orm/angel_orm_test/lib/src/models/asset.g.dart b/packages/orm/angel_orm_test/lib/src/models/asset.g.dart index b6fb1813..1d8fc28a 100644 --- a/packages/orm/angel_orm_test/lib/src/models/asset.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/asset.g.dart @@ -9,12 +9,18 @@ part of 'asset.dart'; class ItemMigration extends Migration { @override void up(Schema schema) { - schema.create('items', (table) { - table.serial('id').primaryKey(); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - table.varChar('description', length: 255); - }); + schema.create( + 'items', + (table) { + table.serial('id').primaryKey(); + table.timeStamp('created_at'); + table.timeStamp('updated_at'); + table.varChar( + 'description', + length: 255, + ); + }, + ); } @override @@ -26,19 +32,31 @@ class ItemMigration extends Migration { class AssetMigration extends Migration { @override void up(Schema schema) { - schema.create('assets', (table) { - table.serial('id').primaryKey(); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - table.varChar('description', length: 255); - table.varChar('name', length: 255); - table.double('price'); - }); + schema.create( + 'assets', + (table) { + table.serial('id').primaryKey(); + table.timeStamp('created_at'); + table.timeStamp('updated_at'); + table.varChar( + 'description', + length: 255, + ); + table.varChar( + 'name', + length: 255, + ); + table.double('price'); + }, + ); } @override void down(Schema schema) { - schema.drop('assets', cascade: true); + schema.drop( + 'assets', + cascade: true, + ); } } @@ -47,7 +65,10 @@ class AssetMigration extends Migration { // ************************************************************************** class ItemQuery extends Query { - ItemQuery({Query? parent, Set? trampoline}) : super(parent: parent) { + ItemQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = ItemQueryWhere(this); @@ -72,7 +93,12 @@ class ItemQuery extends Query { @override List get fields { - const _fields = ['id', 'created_at', 'updated_at', 'description']; + const _fields = [ + 'id', + 'created_at', + 'updated_at', + 'description', + ]; return _selectedFields.isEmpty ? _fields : _fields.where((field) => _selectedFields.contains(field)).toList(); @@ -98,14 +124,13 @@ class ItemQuery extends Query { return Optional.empty(); } var model = Item( - id: fields.contains('id') ? row[0].toString() : null, - createdAt: fields.contains('created_at') - ? mapToNullableDateTime(row[1]) - : null, - updatedAt: fields.contains('updated_at') - ? mapToNullableDateTime(row[2]) - : null, - description: fields.contains('description') ? (row[3] as String) : ''); + id: fields.contains('id') ? row[0].toString() : null, + createdAt: + fields.contains('created_at') ? mapToNullableDateTime(row[1]) : null, + updatedAt: + fields.contains('updated_at') ? mapToNullableDateTime(row[2]) : null, + description: fields.contains('description') ? (row[3] as String) : '', + ); return Optional.of(model); } @@ -117,10 +142,22 @@ class ItemQuery extends Query { class ItemQueryWhere extends QueryWhere { ItemQueryWhere(ItemQuery query) - : id = NumericSqlExpressionBuilder(query, 'id'), - createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'), - description = StringSqlExpressionBuilder(query, 'description'); + : id = NumericSqlExpressionBuilder( + query, + 'id', + ), + createdAt = DateTimeSqlExpressionBuilder( + query, + 'created_at', + ), + updatedAt = DateTimeSqlExpressionBuilder( + query, + 'updated_at', + ), + description = StringSqlExpressionBuilder( + query, + 'description', + ); final NumericSqlExpressionBuilder id; @@ -132,7 +169,12 @@ class ItemQueryWhere extends QueryWhere { @override List get expressionBuilders { - return [id, createdAt, updatedAt, description]; + return [ + id, + createdAt, + updatedAt, + description, + ]; } } @@ -170,19 +212,28 @@ class ItemQueryValues extends MapQueryValues { } class AssetQuery extends Query { - AssetQuery({Query? parent, Set? trampoline}) : super(parent: parent) { + AssetQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = AssetQueryWhere(this); - leftJoin(_items = ItemQuery(trampoline: trampoline, parent: this), 'id', - 'asset_id', - additionalFields: const [ - 'id', - 'created_at', - 'updated_at', - 'description' - ], - trampoline: trampoline); + leftJoin( + _items = ItemQuery( + trampoline: trampoline, + parent: this, + ), + 'id', + 'asset_id', + additionalFields: const [ + 'id', + 'created_at', + 'updated_at', + 'description', + ], + trampoline: trampoline, + ); } @override @@ -196,7 +247,7 @@ class AssetQuery extends Query { @override Map get casts { - return {'price': 'char'}; + return {}; } @override @@ -212,7 +263,7 @@ class AssetQuery extends Query { 'updated_at', 'description', 'name', - 'price' + 'price', ]; return _selectedFields.isEmpty ? _fields @@ -239,16 +290,15 @@ class AssetQuery extends Query { return Optional.empty(); } var model = Asset( - id: fields.contains('id') ? row[0].toString() : null, - createdAt: fields.contains('created_at') - ? mapToNullableDateTime(row[1]) - : null, - updatedAt: fields.contains('updated_at') - ? mapToNullableDateTime(row[2]) - : null, - description: fields.contains('description') ? (row[3] as String) : '', - name: fields.contains('name') ? (row[4] as String) : '', - price: fields.contains('price') ? mapToDouble(row[5]) : 0.0); + id: fields.contains('id') ? row[0].toString() : null, + createdAt: + fields.contains('created_at') ? mapToNullableDateTime(row[1]) : null, + updatedAt: + fields.contains('updated_at') ? mapToNullableDateTime(row[2]) : null, + description: fields.contains('description') ? (row[3] as String) : '', + name: fields.contains('name') ? (row[4] as String) : '', + price: fields.contains('price') ? mapToDouble(row[5]) : 0.0, + ); if (row.length > 6) { var modelOpt = ItemQuery().parseRow(row.skip(6).take(4).toList()); modelOpt.ifPresent((m) { @@ -324,12 +374,30 @@ class AssetQuery extends Query { class AssetQueryWhere extends QueryWhere { AssetQueryWhere(AssetQuery query) - : id = NumericSqlExpressionBuilder(query, 'id'), - createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'), - description = StringSqlExpressionBuilder(query, 'description'), - name = StringSqlExpressionBuilder(query, 'name'), - price = NumericSqlExpressionBuilder(query, 'price'); + : id = NumericSqlExpressionBuilder( + query, + 'id', + ), + createdAt = DateTimeSqlExpressionBuilder( + query, + 'created_at', + ), + updatedAt = DateTimeSqlExpressionBuilder( + query, + 'updated_at', + ), + description = StringSqlExpressionBuilder( + query, + 'description', + ), + name = StringSqlExpressionBuilder( + query, + 'name', + ), + price = NumericSqlExpressionBuilder( + query, + 'price', + ); final NumericSqlExpressionBuilder id; @@ -345,14 +413,21 @@ class AssetQueryWhere extends QueryWhere { @override List get expressionBuilders { - return [id, createdAt, updatedAt, description, name, price]; + return [ + id, + createdAt, + updatedAt, + description, + name, + price, + ]; } } class AssetQueryValues extends MapQueryValues { @override Map get casts { - return {'price': 'double precision'}; + return {}; } String? get id { @@ -381,10 +456,10 @@ class AssetQueryValues extends MapQueryValues { set name(String value) => values['name'] = value; double get price { - return double.tryParse((values['price'] as String)) ?? 0.0; + return (values['price'] as double?) ?? 0.0; } - set price(double value) => values['price'] = value.toString(); + set price(double value) => values['price'] = value; void copyFrom(Asset model) { createdAt = model.createdAt; updatedAt = model.updatedAt; @@ -400,7 +475,12 @@ class AssetQueryValues extends MapQueryValues { @generatedSerializable class Item extends _Item { - Item({this.id, this.createdAt, this.updatedAt, required this.description}); + Item({ + this.id, + this.createdAt, + this.updatedAt, + required this.description, + }); /// A unique identifier corresponding to this item. @override @@ -417,11 +497,12 @@ class Item extends _Item { @override String description; - Item copyWith( - {String? id, - DateTime? createdAt, - DateTime? updatedAt, - String? description}) { + Item copyWith({ + String? id, + DateTime? createdAt, + DateTime? updatedAt, + String? description, + }) { return Item( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -440,7 +521,12 @@ class Item extends _Item { @override int get hashCode { - return hashObjects([id, createdAt, updatedAt, description]); + return hashObjects([ + id, + createdAt, + updatedAt, + description, + ]); } @override @@ -455,15 +541,15 @@ class Item extends _Item { @generatedSerializable class Asset extends _Asset { - Asset( - {this.id, - this.createdAt, - this.updatedAt, - required this.description, - required this.name, - required this.price, - List<_Item> items = const []}) - : items = List.unmodifiable(items); + Asset({ + this.id, + this.createdAt, + this.updatedAt, + required this.description, + required this.name, + required this.price, + List<_Item> items = const [], + }) : items = List.unmodifiable(items); /// A unique identifier corresponding to this item. @override @@ -489,14 +575,15 @@ class Asset extends _Asset { @override List<_Item> items; - Asset copyWith( - {String? id, - DateTime? createdAt, - DateTime? updatedAt, - String? description, - String? name, - double? price, - List<_Item>? items}) { + Asset copyWith({ + String? id, + DateTime? createdAt, + DateTime? updatedAt, + String? description, + String? name, + double? price, + List<_Item>? items, + }) { return Asset( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -522,8 +609,15 @@ class Asset extends _Asset { @override int get hashCode { - return hashObjects( - [id, createdAt, updatedAt, description, name, price, items]); + return hashObjects([ + id, + createdAt, + updatedAt, + description, + name, + price, + items, + ]); } @override @@ -597,7 +691,7 @@ abstract class ItemFields { id, createdAt, updatedAt, - description + description, ]; static const String id = 'id'; @@ -678,7 +772,7 @@ abstract class AssetFields { description, name, price, - items + items, ]; static const String id = 'id'; diff --git a/packages/orm/angel_orm_test/lib/src/models/bike.g.dart b/packages/orm/angel_orm_test/lib/src/models/bike.g.dart index db854073..1a2c5e62 100644 --- a/packages/orm/angel_orm_test/lib/src/models/bike.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/bike.g.dart @@ -9,17 +9,26 @@ part of 'bike.dart'; class BikeMigration extends Migration { @override void up(Schema schema) { - schema.create('bikes', (table) { - table.serial('id').primaryKey(); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - table.varChar('make', length: 255); - table.varChar('description', length: 255); - table.boolean('family_friendly'); - table.timeStamp('recalled_at'); - table.double('price'); - table.integer('width'); - }); + schema.create( + 'bikes', + (table) { + table.serial('id').primaryKey(); + table.timeStamp('created_at'); + table.timeStamp('updated_at'); + table.varChar( + 'make', + length: 255, + ); + table.varChar( + 'description', + length: 255, + ); + table.boolean('family_friendly'); + table.timeStamp('recalled_at'); + table.double('price'); + table.integer('width'); + }, + ); } @override @@ -33,7 +42,10 @@ class BikeMigration extends Migration { // ************************************************************************** class BikeQuery extends Query { - BikeQuery({Query? parent, Set? trampoline}) : super(parent: parent) { + BikeQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = BikeQueryWhere(this); @@ -48,7 +60,7 @@ class BikeQuery extends Query { @override Map get casts { - return {'price': 'char'}; + return {}; } @override @@ -67,7 +79,7 @@ class BikeQuery extends Query { 'family_friendly', 'recalled_at', 'price', - 'width' + 'width', ]; return _selectedFields.isEmpty ? _fields @@ -94,22 +106,21 @@ class BikeQuery extends Query { return Optional.empty(); } var model = Bike( - id: fields.contains('id') ? row[0].toString() : null, - createdAt: fields.contains('created_at') - ? mapToNullableDateTime(row[1]) - : null, - updatedAt: fields.contains('updated_at') - ? mapToNullableDateTime(row[2]) - : null, - make: fields.contains('make') ? (row[3] as String) : '', - description: fields.contains('description') ? (row[4] as String) : '', - familyFriendly: - fields.contains('family_friendly') ? mapToBool(row[5]) : false, - recalledAt: fields.contains('recalled_at') - ? mapToDateTime(row[6]) - : DateTime.parse("1970-01-01 00:00:00"), - price: fields.contains('price') ? mapToDouble(row[7]) : 0.0, - width: fields.contains('width') ? (row[8] as int) : 0); + id: fields.contains('id') ? row[0].toString() : null, + createdAt: + fields.contains('created_at') ? mapToNullableDateTime(row[1]) : null, + updatedAt: + fields.contains('updated_at') ? mapToNullableDateTime(row[2]) : null, + make: fields.contains('make') ? (row[3] as String) : '', + description: fields.contains('description') ? (row[4] as String) : '', + familyFriendly: + fields.contains('family_friendly') ? mapToBool(row[5]) : false, + recalledAt: fields.contains('recalled_at') + ? mapToDateTime(row[6]) + : DateTime.parse("1970-01-01 00:00:00"), + price: fields.contains('price') ? mapToDouble(row[7]) : 0.0, + width: fields.contains('width') ? (row[8] as int) : 0, + ); return Optional.of(model); } @@ -121,15 +132,42 @@ class BikeQuery extends Query { class BikeQueryWhere extends QueryWhere { BikeQueryWhere(BikeQuery query) - : id = NumericSqlExpressionBuilder(query, 'id'), - createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'), - make = StringSqlExpressionBuilder(query, 'make'), - description = StringSqlExpressionBuilder(query, 'description'), - familyFriendly = BooleanSqlExpressionBuilder(query, 'family_friendly'), - recalledAt = DateTimeSqlExpressionBuilder(query, 'recalled_at'), - price = NumericSqlExpressionBuilder(query, 'price'), - width = NumericSqlExpressionBuilder(query, 'width'); + : id = NumericSqlExpressionBuilder( + query, + 'id', + ), + createdAt = DateTimeSqlExpressionBuilder( + query, + 'created_at', + ), + updatedAt = DateTimeSqlExpressionBuilder( + query, + 'updated_at', + ), + make = StringSqlExpressionBuilder( + query, + 'make', + ), + description = StringSqlExpressionBuilder( + query, + 'description', + ), + familyFriendly = BooleanSqlExpressionBuilder( + query, + 'family_friendly', + ), + recalledAt = DateTimeSqlExpressionBuilder( + query, + 'recalled_at', + ), + price = NumericSqlExpressionBuilder( + query, + 'price', + ), + width = NumericSqlExpressionBuilder( + query, + 'width', + ); final NumericSqlExpressionBuilder id; @@ -160,7 +198,7 @@ class BikeQueryWhere extends QueryWhere { familyFriendly, recalledAt, price, - width + width, ]; } } @@ -168,7 +206,7 @@ class BikeQueryWhere extends QueryWhere { class BikeQueryValues extends MapQueryValues { @override Map get casts { - return {'price': 'double precision'}; + return {}; } String? get id { @@ -207,10 +245,10 @@ class BikeQueryValues extends MapQueryValues { set recalledAt(DateTime value) => values['recalled_at'] = value; double get price { - return double.tryParse((values['price'] as String)) ?? 0.0; + return (values['price'] as double?) ?? 0.0; } - set price(double value) => values['price'] = value.toString(); + set price(double value) => values['price'] = value; int get width { return (values['width'] as int); } @@ -234,16 +272,17 @@ class BikeQueryValues extends MapQueryValues { @generatedSerializable class Bike extends _Bike { - Bike( - {this.id, - this.createdAt, - this.updatedAt, - required this.make, - required this.description, - required this.familyFriendly, - required this.recalledAt, - required this.price, - required this.width}); + Bike({ + this.id, + this.createdAt, + this.updatedAt, + required this.make, + required this.description, + required this.familyFriendly, + required this.recalledAt, + required this.price, + required this.width, + }); /// A unique identifier corresponding to this item. @override @@ -275,16 +314,17 @@ class Bike extends _Bike { @override int width; - Bike copyWith( - {String? id, - DateTime? createdAt, - DateTime? updatedAt, - String? make, - String? description, - bool? familyFriendly, - DateTime? recalledAt, - double? price, - int? width}) { + Bike copyWith({ + String? id, + DateTime? createdAt, + DateTime? updatedAt, + String? make, + String? description, + bool? familyFriendly, + DateTime? recalledAt, + double? price, + int? width, + }) { return Bike( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -322,7 +362,7 @@ class Bike extends _Bike { familyFriendly, recalledAt, price, - width + width, ]); } @@ -416,7 +456,7 @@ abstract class BikeFields { familyFriendly, recalledAt, price, - width + width, ]; static const String id = 'id'; diff --git a/packages/orm/angel_orm_test/lib/src/models/boat.g.dart b/packages/orm/angel_orm_test/lib/src/models/boat.g.dart index ba5405cf..0572a369 100644 --- a/packages/orm/angel_orm_test/lib/src/models/boat.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/boat.g.dart @@ -9,17 +9,30 @@ part of 'boat.dart'; class BoatMigration extends Migration { @override void up(Schema schema) { - schema.create('boats', (table) { - table.serial('id').primaryKey(); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - table.varChar('make', length: 255).defaultsTo(''); - table.varChar('description', length: 255).defaultsTo('none'); - table.boolean('family_friendly').defaultsTo(false); - table.timeStamp('recalled_at'); - table.double('price').defaultsTo(0.0); - table.integer('width').defaultsTo(0); - }); + schema.create( + 'boats', + (table) { + table.serial('id').primaryKey(); + table.timeStamp('created_at'); + table.timeStamp('updated_at'); + table + .varChar( + 'make', + length: 255, + ) + .defaultsTo(''); + table + .varChar( + 'description', + length: 255, + ) + .defaultsTo('none'); + table.boolean('family_friendly').defaultsTo(false); + table.timeStamp('recalled_at'); + table.double('price').defaultsTo(0.0); + table.integer('width').defaultsTo(0); + }, + ); } @override @@ -33,7 +46,10 @@ class BoatMigration extends Migration { // ************************************************************************** class BoatQuery extends Query { - BoatQuery({Query? parent, Set? trampoline}) : super(parent: parent) { + BoatQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = BoatQueryWhere(this); @@ -48,7 +64,7 @@ class BoatQuery extends Query { @override Map get casts { - return {'price': 'char'}; + return {}; } @override @@ -67,7 +83,7 @@ class BoatQuery extends Query { 'family_friendly', 'recalled_at', 'price', - 'width' + 'width', ]; return _selectedFields.isEmpty ? _fields @@ -94,22 +110,21 @@ class BoatQuery extends Query { return Optional.empty(); } var model = Boat( - id: fields.contains('id') ? row[0].toString() : null, - createdAt: fields.contains('created_at') - ? mapToNullableDateTime(row[1]) - : null, - updatedAt: fields.contains('updated_at') - ? mapToNullableDateTime(row[2]) - : null, - make: fields.contains('make') ? (row[3] as String) : '', - description: fields.contains('description') ? (row[4] as String) : '', - familyFriendly: - fields.contains('family_friendly') ? mapToBool(row[5]) : false, - recalledAt: fields.contains('recalled_at') - ? mapToDateTime(row[6]) - : DateTime.parse("1970-01-01 00:00:00"), - price: fields.contains('price') ? mapToDouble(row[7]) : 0.0, - width: fields.contains('width') ? (row[8] as int) : 0); + id: fields.contains('id') ? row[0].toString() : null, + createdAt: + fields.contains('created_at') ? mapToNullableDateTime(row[1]) : null, + updatedAt: + fields.contains('updated_at') ? mapToNullableDateTime(row[2]) : null, + make: fields.contains('make') ? (row[3] as String) : '', + description: fields.contains('description') ? (row[4] as String) : '', + familyFriendly: + fields.contains('family_friendly') ? mapToBool(row[5]) : false, + recalledAt: fields.contains('recalled_at') + ? mapToDateTime(row[6]) + : DateTime.parse("1970-01-01 00:00:00"), + price: fields.contains('price') ? mapToDouble(row[7]) : 0.0, + width: fields.contains('width') ? (row[8] as int) : 0, + ); return Optional.of(model); } @@ -121,15 +136,42 @@ class BoatQuery extends Query { class BoatQueryWhere extends QueryWhere { BoatQueryWhere(BoatQuery query) - : id = NumericSqlExpressionBuilder(query, 'id'), - createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'), - make = StringSqlExpressionBuilder(query, 'make'), - description = StringSqlExpressionBuilder(query, 'description'), - familyFriendly = BooleanSqlExpressionBuilder(query, 'family_friendly'), - recalledAt = DateTimeSqlExpressionBuilder(query, 'recalled_at'), - price = NumericSqlExpressionBuilder(query, 'price'), - width = NumericSqlExpressionBuilder(query, 'width'); + : id = NumericSqlExpressionBuilder( + query, + 'id', + ), + createdAt = DateTimeSqlExpressionBuilder( + query, + 'created_at', + ), + updatedAt = DateTimeSqlExpressionBuilder( + query, + 'updated_at', + ), + make = StringSqlExpressionBuilder( + query, + 'make', + ), + description = StringSqlExpressionBuilder( + query, + 'description', + ), + familyFriendly = BooleanSqlExpressionBuilder( + query, + 'family_friendly', + ), + recalledAt = DateTimeSqlExpressionBuilder( + query, + 'recalled_at', + ), + price = NumericSqlExpressionBuilder( + query, + 'price', + ), + width = NumericSqlExpressionBuilder( + query, + 'width', + ); final NumericSqlExpressionBuilder id; @@ -160,7 +202,7 @@ class BoatQueryWhere extends QueryWhere { familyFriendly, recalledAt, price, - width + width, ]; } } @@ -168,7 +210,7 @@ class BoatQueryWhere extends QueryWhere { class BoatQueryValues extends MapQueryValues { @override Map get casts { - return {'price': 'double precision'}; + return {}; } String? get id { @@ -207,10 +249,10 @@ class BoatQueryValues extends MapQueryValues { set recalledAt(DateTime value) => values['recalled_at'] = value; double get price { - return double.tryParse((values['price'] as String)) ?? 0.0; + return (values['price'] as double?) ?? 0.0; } - set price(double value) => values['price'] = value.toString(); + set price(double value) => values['price'] = value; int get width { return (values['width'] as int); } @@ -234,16 +276,17 @@ class BoatQueryValues extends MapQueryValues { @generatedSerializable class Boat extends _Boat { - Boat( - {this.id, - this.createdAt, - this.updatedAt, - required this.make, - required this.description, - required this.familyFriendly, - required this.recalledAt, - required this.price, - required this.width}); + Boat({ + this.id, + this.createdAt, + this.updatedAt, + required this.make, + required this.description, + required this.familyFriendly, + required this.recalledAt, + required this.price, + required this.width, + }); /// A unique identifier corresponding to this item. @override @@ -275,16 +318,17 @@ class Boat extends _Boat { @override int width; - Boat copyWith( - {String? id, - DateTime? createdAt, - DateTime? updatedAt, - String? make, - String? description, - bool? familyFriendly, - DateTime? recalledAt, - double? price, - int? width}) { + Boat copyWith({ + String? id, + DateTime? createdAt, + DateTime? updatedAt, + String? make, + String? description, + bool? familyFriendly, + DateTime? recalledAt, + double? price, + int? width, + }) { return Boat( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -322,7 +366,7 @@ class Boat extends _Boat { familyFriendly, recalledAt, price, - width + width, ]); } @@ -416,7 +460,7 @@ abstract class BoatFields { familyFriendly, recalledAt, price, - width + width, ]; static const String id = 'id'; diff --git a/packages/orm/angel_orm_test/lib/src/models/book.g.dart b/packages/orm/angel_orm_test/lib/src/models/book.g.dart index b893f00a..94996bf8 100644 --- a/packages/orm/angel_orm_test/lib/src/models/book.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/book.g.dart @@ -9,16 +9,36 @@ part of angel_orm3.generator.models.book; class BookMigration extends Migration { @override void up(Schema schema) { - schema.create('books', (table) { - table.serial('id').primaryKey(); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - table.varChar('name', length: 255); - table.declare('author_id', ColumnType('int')).references('authors', 'id'); - table - .declare('partner_author_id', ColumnType('int')) - .references('authors', 'id'); - }); + schema.create( + 'books', + (table) { + table.serial('id').primaryKey(); + table.timeStamp('created_at'); + table.timeStamp('updated_at'); + table.varChar( + 'name', + length: 255, + ); + table + .declare( + 'author_id', + ColumnType('int'), + ) + .references( + 'authors', + 'id', + ); + table + .declare( + 'partner_author_id', + ColumnType('int'), + ) + .references( + 'authors', + 'id', + ); + }, + ); } @override @@ -30,14 +50,20 @@ class BookMigration extends Migration { class AuthorMigration extends Migration { @override void up(Schema schema) { - schema.create('authors', (table) { - table.serial('id').primaryKey(); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - table.varChar('name', length: 255) - ..defaultsTo('Tobe Osakwe') - ..unique(); - }); + schema.create( + 'authors', + (table) { + table.serial('id').primaryKey(); + table.timeStamp('created_at'); + table.timeStamp('updated_at'); + table.varChar( + 'name', + length: 255, + ) + ..defaultsTo('Tobe Osakwe') + ..unique(); + }, + ); } @override @@ -51,18 +77,43 @@ class AuthorMigration extends Migration { // ************************************************************************** class BookQuery extends Query { - BookQuery({Query? parent, Set? trampoline}) : super(parent: parent) { + BookQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = BookQueryWhere(this); - join(_author = AuthorQuery(trampoline: trampoline, parent: this), - 'author_id', 'id', - additionalFields: const ['id', 'created_at', 'updated_at', 'name'], - trampoline: trampoline); - join(_partnerAuthor = AuthorQuery(trampoline: trampoline, parent: this), - 'partner_author_id', 'id', - additionalFields: const ['id', 'created_at', 'updated_at', 'name'], - trampoline: trampoline); + join( + _author = AuthorQuery( + trampoline: trampoline, + parent: this, + ), + 'author_id', + 'id', + additionalFields: const [ + 'id', + 'created_at', + 'updated_at', + 'name', + ], + trampoline: trampoline, + ); + join( + _partnerAuthor = AuthorQuery( + trampoline: trampoline, + parent: this, + ), + 'partner_author_id', + 'id', + additionalFields: const [ + 'id', + 'created_at', + 'updated_at', + 'name', + ], + trampoline: trampoline, + ); } @override @@ -94,7 +145,7 @@ class BookQuery extends Query { 'updated_at', 'author_id', 'partner_author_id', - 'name' + 'name', ]; return _selectedFields.isEmpty ? _fields @@ -121,14 +172,13 @@ class BookQuery extends Query { return Optional.empty(); } var model = Book( - id: fields.contains('id') ? row[0].toString() : null, - createdAt: fields.contains('created_at') - ? mapToNullableDateTime(row[1]) - : null, - updatedAt: fields.contains('updated_at') - ? mapToNullableDateTime(row[2]) - : null, - name: fields.contains('name') ? (row[5] as String?) : null); + id: fields.contains('id') ? row[0].toString() : null, + createdAt: + fields.contains('created_at') ? mapToNullableDateTime(row[1]) : null, + updatedAt: + fields.contains('updated_at') ? mapToNullableDateTime(row[2]) : null, + name: fields.contains('name') ? (row[5] as String?) : null, + ); if (row.length > 6) { var modelOpt = AuthorQuery().parseRow(row.skip(6).take(4).toList()); modelOpt.ifPresent((m) { @@ -160,13 +210,30 @@ class BookQuery extends Query { class BookQueryWhere extends QueryWhere { BookQueryWhere(BookQuery query) - : id = NumericSqlExpressionBuilder(query, 'id'), - createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'), - authorId = NumericSqlExpressionBuilder(query, 'author_id'), - partnerAuthorId = - NumericSqlExpressionBuilder(query, 'partner_author_id'), - name = StringSqlExpressionBuilder(query, 'name'); + : id = NumericSqlExpressionBuilder( + query, + 'id', + ), + createdAt = DateTimeSqlExpressionBuilder( + query, + 'created_at', + ), + updatedAt = DateTimeSqlExpressionBuilder( + query, + 'updated_at', + ), + authorId = NumericSqlExpressionBuilder( + query, + 'author_id', + ), + partnerAuthorId = NumericSqlExpressionBuilder( + query, + 'partner_author_id', + ), + name = StringSqlExpressionBuilder( + query, + 'name', + ); final NumericSqlExpressionBuilder id; @@ -182,7 +249,14 @@ class BookQueryWhere extends QueryWhere { @override List get expressionBuilders { - return [id, createdAt, updatedAt, authorId, partnerAuthorId, name]; + return [ + id, + createdAt, + updatedAt, + authorId, + partnerAuthorId, + name, + ]; } } @@ -236,8 +310,10 @@ class BookQueryValues extends MapQueryValues { } class AuthorQuery extends Query { - AuthorQuery({Query? parent, Set? trampoline}) - : super(parent: parent) { + AuthorQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = AuthorQueryWhere(this); @@ -262,7 +338,12 @@ class AuthorQuery extends Query { @override List get fields { - const _fields = ['id', 'created_at', 'updated_at', 'name']; + const _fields = [ + 'id', + 'created_at', + 'updated_at', + 'name', + ]; return _selectedFields.isEmpty ? _fields : _fields.where((field) => _selectedFields.contains(field)).toList(); @@ -288,14 +369,13 @@ class AuthorQuery extends Query { return Optional.empty(); } var model = Author( - id: fields.contains('id') ? row[0].toString() : null, - createdAt: fields.contains('created_at') - ? mapToNullableDateTime(row[1]) - : null, - updatedAt: fields.contains('updated_at') - ? mapToNullableDateTime(row[2]) - : null, - name: fields.contains('name') ? (row[3] as String?) : null); + id: fields.contains('id') ? row[0].toString() : null, + createdAt: + fields.contains('created_at') ? mapToNullableDateTime(row[1]) : null, + updatedAt: + fields.contains('updated_at') ? mapToNullableDateTime(row[2]) : null, + name: fields.contains('name') ? (row[3] as String?) : null, + ); return Optional.of(model); } @@ -307,10 +387,22 @@ class AuthorQuery extends Query { class AuthorQueryWhere extends QueryWhere { AuthorQueryWhere(AuthorQuery query) - : id = NumericSqlExpressionBuilder(query, 'id'), - createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'), - name = StringSqlExpressionBuilder(query, 'name'); + : id = NumericSqlExpressionBuilder( + query, + 'id', + ), + createdAt = DateTimeSqlExpressionBuilder( + query, + 'created_at', + ), + updatedAt = DateTimeSqlExpressionBuilder( + query, + 'updated_at', + ), + name = StringSqlExpressionBuilder( + query, + 'name', + ); final NumericSqlExpressionBuilder id; @@ -322,7 +414,12 @@ class AuthorQueryWhere extends QueryWhere { @override List get expressionBuilders { - return [id, createdAt, updatedAt, name]; + return [ + id, + createdAt, + updatedAt, + name, + ]; } } @@ -365,13 +462,14 @@ class AuthorQueryValues extends MapQueryValues { @generatedSerializable class Book extends _Book { - Book( - {this.id, - this.createdAt, - this.updatedAt, - this.author, - this.partnerAuthor, - this.name}); + Book({ + this.id, + this.createdAt, + this.updatedAt, + this.author, + this.partnerAuthor, + this.name, + }); /// A unique identifier corresponding to this item. @override @@ -394,13 +492,14 @@ class Book extends _Book { @override String? name; - Book copyWith( - {String? id, - DateTime? createdAt, - DateTime? updatedAt, - _Author? author, - _Author? partnerAuthor, - String? name}) { + Book copyWith({ + String? id, + DateTime? createdAt, + DateTime? updatedAt, + _Author? author, + _Author? partnerAuthor, + String? name, + }) { return Book( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -423,7 +522,14 @@ class Book extends _Book { @override int get hashCode { - return hashObjects([id, createdAt, updatedAt, author, partnerAuthor, name]); + return hashObjects([ + id, + createdAt, + updatedAt, + author, + partnerAuthor, + name, + ]); } @override @@ -438,7 +544,12 @@ class Book extends _Book { @generatedSerializable class Author extends _Author { - Author({this.id, this.createdAt, this.updatedAt, this.name = 'Tobe Osakwe'}); + Author({ + this.id, + this.createdAt, + this.updatedAt, + this.name = 'Tobe Osakwe', + }); /// A unique identifier corresponding to this item. @override @@ -455,8 +566,12 @@ class Author extends _Author { @override String? name; - Author copyWith( - {String? id, DateTime? createdAt, DateTime? updatedAt, String? name}) { + Author copyWith({ + String? id, + DateTime? createdAt, + DateTime? updatedAt, + String? name, + }) { return Author( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -475,7 +590,12 @@ class Author extends _Author { @override int get hashCode { - return hashObjects([id, createdAt, updatedAt, name]); + return hashObjects([ + id, + createdAt, + updatedAt, + name, + ]); } @override @@ -559,7 +679,7 @@ abstract class BookFields { updatedAt, author, partnerAuthor, - name + name, ]; static const String id = 'id'; @@ -632,7 +752,7 @@ abstract class AuthorFields { id, createdAt, updatedAt, - name + name, ]; static const String id = 'id'; diff --git a/packages/orm/angel_orm_test/lib/src/models/car.dart b/packages/orm/angel_orm_test/lib/src/models/car.dart index 26e1f148..98a3d21b 100644 --- a/packages/orm/angel_orm_test/lib/src/models/car.dart +++ b/packages/orm/angel_orm_test/lib/src/models/car.dart @@ -13,4 +13,5 @@ class _Car extends Model { String? description; bool? familyFriendly; DateTime? recalledAt; + double? price; } diff --git a/packages/orm/angel_orm_test/lib/src/models/car.g.dart b/packages/orm/angel_orm_test/lib/src/models/car.g.dart index 60edc83f..14c19c2b 100644 --- a/packages/orm/angel_orm_test/lib/src/models/car.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/car.g.dart @@ -9,15 +9,25 @@ part of angel_orm3.generator.models.car; class CarMigration extends Migration { @override void up(Schema schema) { - schema.create('cars', (table) { - table.serial('id').primaryKey(); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - table.varChar('make', length: 255); - table.varChar('description', length: 255); - table.boolean('family_friendly'); - table.timeStamp('recalled_at'); - }); + schema.create( + 'cars', + (table) { + table.serial('id').primaryKey(); + table.timeStamp('created_at'); + table.timeStamp('updated_at'); + table.varChar( + 'make', + length: 255, + ); + table.varChar( + 'description', + length: 255, + ); + table.boolean('family_friendly'); + table.timeStamp('recalled_at'); + table.double('price'); + }, + ); } @override @@ -31,7 +41,10 @@ class CarMigration extends Migration { // ************************************************************************** class CarQuery extends Query { - CarQuery({Query? parent, Set? trampoline}) : super(parent: parent) { + CarQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = CarQueryWhere(this); @@ -63,7 +76,8 @@ class CarQuery extends Query { 'make', 'description', 'family_friendly', - 'recalled_at' + 'recalled_at', + 'price', ]; return _selectedFields.isEmpty ? _fields @@ -90,21 +104,19 @@ class CarQuery extends Query { return Optional.empty(); } var model = Car( - id: fields.contains('id') ? row[0].toString() : null, - createdAt: fields.contains('created_at') - ? mapToNullableDateTime(row[1]) - : null, - updatedAt: fields.contains('updated_at') - ? mapToNullableDateTime(row[2]) - : null, - make: fields.contains('make') ? (row[3] as String?) : null, - description: - fields.contains('description') ? (row[4] as String?) : null, - familyFriendly: - fields.contains('family_friendly') ? mapToBool(row[5]) : null, - recalledAt: fields.contains('recalled_at') - ? mapToNullableDateTime(row[6]) - : null); + id: fields.contains('id') ? row[0].toString() : null, + createdAt: + fields.contains('created_at') ? mapToNullableDateTime(row[1]) : null, + updatedAt: + fields.contains('updated_at') ? mapToNullableDateTime(row[2]) : null, + make: fields.contains('make') ? (row[3] as String?) : null, + description: fields.contains('description') ? (row[4] as String?) : null, + familyFriendly: + fields.contains('family_friendly') ? mapToBool(row[5]) : null, + recalledAt: + fields.contains('recalled_at') ? mapToNullableDateTime(row[6]) : null, + price: fields.contains('price') ? mapToDouble(row[7]) : null, + ); return Optional.of(model); } @@ -116,13 +128,38 @@ class CarQuery extends Query { class CarQueryWhere extends QueryWhere { CarQueryWhere(CarQuery query) - : id = NumericSqlExpressionBuilder(query, 'id'), - createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'), - make = StringSqlExpressionBuilder(query, 'make'), - description = StringSqlExpressionBuilder(query, 'description'), - familyFriendly = BooleanSqlExpressionBuilder(query, 'family_friendly'), - recalledAt = DateTimeSqlExpressionBuilder(query, 'recalled_at'); + : id = NumericSqlExpressionBuilder( + query, + 'id', + ), + createdAt = DateTimeSqlExpressionBuilder( + query, + 'created_at', + ), + updatedAt = DateTimeSqlExpressionBuilder( + query, + 'updated_at', + ), + make = StringSqlExpressionBuilder( + query, + 'make', + ), + description = StringSqlExpressionBuilder( + query, + 'description', + ), + familyFriendly = BooleanSqlExpressionBuilder( + query, + 'family_friendly', + ), + recalledAt = DateTimeSqlExpressionBuilder( + query, + 'recalled_at', + ), + price = NumericSqlExpressionBuilder( + query, + 'price', + ); final NumericSqlExpressionBuilder id; @@ -138,6 +175,8 @@ class CarQueryWhere extends QueryWhere { final DateTimeSqlExpressionBuilder recalledAt; + final NumericSqlExpressionBuilder price; + @override List get expressionBuilders { return [ @@ -147,7 +186,8 @@ class CarQueryWhere extends QueryWhere { make, description, familyFriendly, - recalledAt + recalledAt, + price, ]; } } @@ -193,6 +233,11 @@ class CarQueryValues extends MapQueryValues { } set recalledAt(DateTime? value) => values['recalled_at'] = value; + double? get price { + return (values['price'] as double?) ?? 0.0; + } + + set price(double? value) => values['price'] = value; void copyFrom(Car model) { createdAt = model.createdAt; updatedAt = model.updatedAt; @@ -200,6 +245,7 @@ class CarQueryValues extends MapQueryValues { description = model.description; familyFriendly = model.familyFriendly; recalledAt = model.recalledAt; + price = model.price; } } @@ -209,14 +255,16 @@ class CarQueryValues extends MapQueryValues { @generatedSerializable class Car extends _Car { - Car( - {this.id, - this.createdAt, - this.updatedAt, - this.make, - this.description, - this.familyFriendly, - this.recalledAt}); + Car({ + this.id, + this.createdAt, + this.updatedAt, + this.make, + this.description, + this.familyFriendly, + this.recalledAt, + this.price, + }); /// A unique identifier corresponding to this item. @override @@ -242,14 +290,19 @@ class Car extends _Car { @override DateTime? recalledAt; - Car copyWith( - {String? id, - DateTime? createdAt, - DateTime? updatedAt, - String? make, - String? description, - bool? familyFriendly, - DateTime? recalledAt}) { + @override + double? price; + + Car copyWith({ + String? id, + DateTime? createdAt, + DateTime? updatedAt, + String? make, + String? description, + bool? familyFriendly, + DateTime? recalledAt, + double? price, + }) { return Car( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -257,7 +310,8 @@ class Car extends _Car { make: make ?? this.make, description: description ?? this.description, familyFriendly: familyFriendly ?? this.familyFriendly, - recalledAt: recalledAt ?? this.recalledAt); + recalledAt: recalledAt ?? this.recalledAt, + price: price ?? this.price); } @override @@ -269,7 +323,8 @@ class Car extends _Car { other.make == make && other.description == description && other.familyFriendly == familyFriendly && - other.recalledAt == recalledAt; + other.recalledAt == recalledAt && + other.price == price; } @override @@ -281,13 +336,14 @@ class Car extends _Car { make, description, familyFriendly, - recalledAt + recalledAt, + price, ]); } @override String toString() { - return 'Car(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, make=$make, description=$description, familyFriendly=$familyFriendly, recalledAt=$recalledAt)'; + return 'Car(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, make=$make, description=$description, familyFriendly=$familyFriendly, recalledAt=$recalledAt, price=$price)'; } Map toJson() { @@ -342,7 +398,8 @@ class CarSerializer extends Codec { ? (map['recalled_at'] is DateTime ? (map['recalled_at'] as DateTime) : DateTime.parse(map['recalled_at'].toString())) - : null); + : null, + price: map['price'] as double?); } static Map toMap(_Car? model) { @@ -356,7 +413,8 @@ class CarSerializer extends Codec { 'make': model.make, 'description': model.description, 'family_friendly': model.familyFriendly, - 'recalled_at': model.recalledAt?.toIso8601String() + 'recalled_at': model.recalledAt?.toIso8601String(), + 'price': model.price }; } } @@ -369,7 +427,8 @@ abstract class CarFields { make, description, familyFriendly, - recalledAt + recalledAt, + price, ]; static const String id = 'id'; @@ -385,4 +444,6 @@ abstract class CarFields { static const String familyFriendly = 'family_friendly'; static const String recalledAt = 'recalled_at'; + + static const String price = 'price'; } diff --git a/packages/orm/angel_orm_test/lib/src/models/custom_expr.g.dart b/packages/orm/angel_orm_test/lib/src/models/custom_expr.g.dart index 38134225..4c8dd154 100644 --- a/packages/orm/angel_orm_test/lib/src/models/custom_expr.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/custom_expr.g.dart @@ -9,11 +9,14 @@ part of 'custom_expr.dart'; class NumbersMigration extends Migration { @override void up(Schema schema) { - schema.create('numbers', (table) { - table.serial('id').primaryKey(); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - }); + schema.create( + 'numbers', + (table) { + table.serial('id').primaryKey(); + table.timeStamp('created_at'); + table.timeStamp('updated_at'); + }, + ); } @override @@ -25,15 +28,27 @@ class NumbersMigration extends Migration { class AlphabetMigration extends Migration { @override void up(Schema schema) { - schema.create('alphabets', (table) { - table.serial('id').primaryKey(); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - table.varChar('value', length: 255); - table - .declare('numbers_id', ColumnType('int')) - .references('numbers', 'id'); - }); + schema.create( + 'alphabets', + (table) { + table.serial('id').primaryKey(); + table.timeStamp('created_at'); + table.timeStamp('updated_at'); + table.varChar( + 'value', + length: 255, + ); + table + .declare( + 'numbers_id', + ColumnType('int'), + ) + .references( + 'numbers', + 'id', + ); + }, + ); } @override @@ -47,8 +62,10 @@ class AlphabetMigration extends Migration { // ************************************************************************** class NumbersQuery extends Query { - NumbersQuery({Query? parent, Set? trampoline}) - : super(parent: parent) { + NumbersQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); expressions['two'] = 'SELECT 2'; @@ -74,7 +91,12 @@ class NumbersQuery extends Query { @override List get fields { - const _fields = ['id', 'created_at', 'updated_at', 'two']; + const _fields = [ + 'id', + 'created_at', + 'updated_at', + 'two', + ]; return _selectedFields.isEmpty ? _fields : _fields.where((field) => _selectedFields.contains(field)).toList(); @@ -100,14 +122,13 @@ class NumbersQuery extends Query { return Optional.empty(); } var model = Numbers( - id: fields.contains('id') ? row[0].toString() : null, - createdAt: fields.contains('created_at') - ? mapToNullableDateTime(row[1]) - : null, - updatedAt: fields.contains('updated_at') - ? mapToNullableDateTime(row[2]) - : null, - two: fields.contains('two') ? (row[3] as int?) : null); + id: fields.contains('id') ? row[0].toString() : null, + createdAt: + fields.contains('created_at') ? mapToNullableDateTime(row[1]) : null, + updatedAt: + fields.contains('updated_at') ? mapToNullableDateTime(row[2]) : null, + two: fields.contains('two') ? (row[3] as int?) : null, + ); return Optional.of(model); } @@ -119,9 +140,18 @@ class NumbersQuery extends Query { class NumbersQueryWhere extends QueryWhere { NumbersQueryWhere(NumbersQuery query) - : id = NumericSqlExpressionBuilder(query, 'id'), - createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'); + : id = NumericSqlExpressionBuilder( + query, + 'id', + ), + createdAt = DateTimeSqlExpressionBuilder( + query, + 'created_at', + ), + updatedAt = DateTimeSqlExpressionBuilder( + query, + 'updated_at', + ); final NumericSqlExpressionBuilder id; @@ -131,7 +161,11 @@ class NumbersQueryWhere extends QueryWhere { @override List get expressionBuilders { - return [id, createdAt, updatedAt]; + return [ + id, + createdAt, + updatedAt, + ]; } } @@ -163,15 +197,28 @@ class NumbersQueryValues extends MapQueryValues { } class AlphabetQuery extends Query { - AlphabetQuery({Query? parent, Set? trampoline}) - : super(parent: parent) { + AlphabetQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = AlphabetQueryWhere(this); - leftJoin(_numbers = NumbersQuery(trampoline: trampoline, parent: this), - 'numbers_id', 'id', - additionalFields: const ['id', 'created_at', 'updated_at', 'two'], - trampoline: trampoline); + leftJoin( + _numbers = NumbersQuery( + trampoline: trampoline, + parent: this, + ), + 'numbers_id', + 'id', + additionalFields: const [ + 'id', + 'created_at', + 'updated_at', + 'two', + ], + trampoline: trampoline, + ); } @override @@ -195,7 +242,13 @@ class AlphabetQuery extends Query { @override List get fields { - const _fields = ['id', 'created_at', 'updated_at', 'value', 'numbers_id']; + const _fields = [ + 'id', + 'created_at', + 'updated_at', + 'value', + 'numbers_id', + ]; return _selectedFields.isEmpty ? _fields : _fields.where((field) => _selectedFields.contains(field)).toList(); @@ -221,14 +274,13 @@ class AlphabetQuery extends Query { return Optional.empty(); } var model = Alphabet( - id: fields.contains('id') ? row[0].toString() : null, - createdAt: fields.contains('created_at') - ? mapToNullableDateTime(row[1]) - : null, - updatedAt: fields.contains('updated_at') - ? mapToNullableDateTime(row[2]) - : null, - value: fields.contains('value') ? (row[3] as String?) : null); + id: fields.contains('id') ? row[0].toString() : null, + createdAt: + fields.contains('created_at') ? mapToNullableDateTime(row[1]) : null, + updatedAt: + fields.contains('updated_at') ? mapToNullableDateTime(row[2]) : null, + value: fields.contains('value') ? (row[3] as String?) : null, + ); if (row.length > 5) { var modelOpt = NumbersQuery().parseRow(row.skip(5).take(4).toList()); modelOpt.ifPresent((m) { @@ -250,11 +302,26 @@ class AlphabetQuery extends Query { class AlphabetQueryWhere extends QueryWhere { AlphabetQueryWhere(AlphabetQuery query) - : id = NumericSqlExpressionBuilder(query, 'id'), - createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'), - value = StringSqlExpressionBuilder(query, 'value'), - numbersId = NumericSqlExpressionBuilder(query, 'numbers_id'); + : id = NumericSqlExpressionBuilder( + query, + 'id', + ), + createdAt = DateTimeSqlExpressionBuilder( + query, + 'created_at', + ), + updatedAt = DateTimeSqlExpressionBuilder( + query, + 'updated_at', + ), + value = StringSqlExpressionBuilder( + query, + 'value', + ), + numbersId = NumericSqlExpressionBuilder( + query, + 'numbers_id', + ); final NumericSqlExpressionBuilder id; @@ -268,7 +335,13 @@ class AlphabetQueryWhere extends QueryWhere { @override List get expressionBuilders { - return [id, createdAt, updatedAt, value, numbersId]; + return [ + id, + createdAt, + updatedAt, + value, + numbersId, + ]; } } @@ -319,7 +392,12 @@ class AlphabetQueryValues extends MapQueryValues { @generatedSerializable class Numbers extends _Numbers { - Numbers({this.id, this.createdAt, this.updatedAt, this.two}); + Numbers({ + this.id, + this.createdAt, + this.updatedAt, + this.two, + }); /// A unique identifier corresponding to this item. @override @@ -336,8 +414,12 @@ class Numbers extends _Numbers { @override int? two; - Numbers copyWith( - {String? id, DateTime? createdAt, DateTime? updatedAt, int? two}) { + Numbers copyWith({ + String? id, + DateTime? createdAt, + DateTime? updatedAt, + int? two, + }) { return Numbers( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -356,7 +438,12 @@ class Numbers extends _Numbers { @override int get hashCode { - return hashObjects([id, createdAt, updatedAt, two]); + return hashObjects([ + id, + createdAt, + updatedAt, + two, + ]); } @override @@ -371,7 +458,13 @@ class Numbers extends _Numbers { @generatedSerializable class Alphabet extends _Alphabet { - Alphabet({this.id, this.createdAt, this.updatedAt, this.value, this.numbers}); + Alphabet({ + this.id, + this.createdAt, + this.updatedAt, + this.value, + this.numbers, + }); /// A unique identifier corresponding to this item. @override @@ -391,12 +484,13 @@ class Alphabet extends _Alphabet { @override _Numbers? numbers; - Alphabet copyWith( - {String? id, - DateTime? createdAt, - DateTime? updatedAt, - String? value, - _Numbers? numbers}) { + Alphabet copyWith({ + String? id, + DateTime? createdAt, + DateTime? updatedAt, + String? value, + _Numbers? numbers, + }) { return Alphabet( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -417,7 +511,13 @@ class Alphabet extends _Alphabet { @override int get hashCode { - return hashObjects([id, createdAt, updatedAt, value, numbers]); + return hashObjects([ + id, + createdAt, + updatedAt, + value, + numbers, + ]); } @override @@ -487,7 +587,12 @@ class NumbersSerializer extends Codec { } abstract class NumbersFields { - static const List allFields = [id, createdAt, updatedAt, two]; + static const List allFields = [ + id, + createdAt, + updatedAt, + two, + ]; static const String id = 'id'; @@ -560,7 +665,7 @@ abstract class AlphabetFields { createdAt, updatedAt, value, - numbers + numbers, ]; static const String id = 'id'; diff --git a/packages/orm/angel_orm_test/lib/src/models/email_indexed.g.dart b/packages/orm/angel_orm_test/lib/src/models/email_indexed.g.dart index be558599..8e11187e 100644 --- a/packages/orm/angel_orm_test/lib/src/models/email_indexed.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/email_indexed.g.dart @@ -9,28 +9,54 @@ part of 'email_indexed.dart'; class RoleMigration extends Migration { @override void up(Schema schema) { - schema.create('roles', (table) { - table.varChar('role', length: 255).primaryKey(); - }); + schema.create( + 'roles', + (table) { + table + .varChar( + 'role', + length: 255, + ) + .primaryKey(); + }, + ); } @override void down(Schema schema) { - schema.drop('roles', cascade: true); + schema.drop( + 'roles', + cascade: true, + ); } } class RoleUserMigration extends Migration { @override void up(Schema schema) { - schema.create('role_users', (table) { - table - .declare('role_role', ColumnType('varchar')) - .references('roles', 'role'); - table - .declare('user_email', ColumnType('varchar')) - .references('users', 'email'); - }); + schema.create( + 'role_users', + (table) { + table + .declare( + 'role_role', + ColumnType('varchar'), + ) + .references( + 'roles', + 'role', + ); + table + .declare( + 'user_email', + ColumnType('varchar'), + ) + .references( + 'users', + 'email', + ); + }, + ); } @override @@ -42,16 +68,33 @@ class RoleUserMigration extends Migration { class UserMigration extends Migration { @override void up(Schema schema) { - schema.create('users', (table) { - table.varChar('email', length: 255).primaryKey(); - table.varChar('name', length: 255); - table.varChar('password', length: 255); - }); + schema.create( + 'users', + (table) { + table + .varChar( + 'email', + length: 255, + ) + .primaryKey(); + table.varChar( + 'name', + length: 255, + ); + table.varChar( + 'password', + length: 255, + ); + }, + ); } @override void down(Schema schema) { - schema.drop('users', cascade: true); + schema.drop( + 'users', + cascade: true, + ); } } @@ -60,16 +103,24 @@ class UserMigration extends Migration { // ************************************************************************** class RoleQuery extends Query { - RoleQuery({Query? parent, Set? trampoline}) : super(parent: parent) { + RoleQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = RoleQueryWhere(this); leftJoin( - '(SELECT role_users.role_role, users.email, users.name, users.password FROM users LEFT JOIN role_users ON role_users.user_email=users.email)', - 'role', - 'role_role', - additionalFields: const ['email', 'name', 'password'], - trampoline: trampoline); + '(SELECT role_users.role_role, users.email, users.name, users.password FROM users LEFT JOIN role_users ON role_users.user_email=users.email)', + 'role', + 'role_role', + additionalFields: const [ + 'email', + 'name', + 'password', + ], + trampoline: trampoline, + ); } @override @@ -195,7 +246,10 @@ class RoleQuery extends Query { class RoleQueryWhere extends QueryWhere { RoleQueryWhere(RoleQuery query) - : role = StringSqlExpressionBuilder(query, 'role'); + : role = StringSqlExpressionBuilder( + query, + 'role', + ); final StringSqlExpressionBuilder role; @@ -222,18 +276,37 @@ class RoleQueryValues extends MapQueryValues { } class RoleUserQuery extends Query { - RoleUserQuery({Query? parent, Set? trampoline}) - : super(parent: parent) { + RoleUserQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = RoleUserQueryWhere(this); - leftJoin(_role = RoleQuery(trampoline: trampoline, parent: this), - 'role_role', 'role', - additionalFields: const ['role'], trampoline: trampoline); - leftJoin(_user = UserQuery(trampoline: trampoline, parent: this), - 'user_email', 'email', - additionalFields: const ['email', 'name', 'password'], - trampoline: trampoline); + leftJoin( + _role = RoleQuery( + trampoline: trampoline, + parent: this, + ), + 'role_role', + 'role', + additionalFields: const ['role'], + trampoline: trampoline, + ); + leftJoin( + _user = UserQuery( + trampoline: trampoline, + parent: this, + ), + 'user_email', + 'email', + additionalFields: const [ + 'email', + 'name', + 'password', + ], + trampoline: trampoline, + ); } @override @@ -259,7 +332,10 @@ class RoleUserQuery extends Query { @override List get fields { - const _fields = ['role_role', 'user_email']; + const _fields = [ + 'role_role', + 'user_email', + ]; return _selectedFields.isEmpty ? _fields : _fields.where((field) => _selectedFields.contains(field)).toList(); @@ -316,8 +392,14 @@ class RoleUserQuery extends Query { class RoleUserQueryWhere extends QueryWhere { RoleUserQueryWhere(RoleUserQuery query) - : roleRole = StringSqlExpressionBuilder(query, 'role_role'), - userEmail = StringSqlExpressionBuilder(query, 'user_email'); + : roleRole = StringSqlExpressionBuilder( + query, + 'role_role', + ), + userEmail = StringSqlExpressionBuilder( + query, + 'user_email', + ); final StringSqlExpressionBuilder roleRole; @@ -325,7 +407,10 @@ class RoleUserQueryWhere extends QueryWhere { @override List get expressionBuilders { - return [roleRole, userEmail]; + return [ + roleRole, + userEmail, + ]; } } @@ -356,16 +441,20 @@ class RoleUserQueryValues extends MapQueryValues { } class UserQuery extends Query { - UserQuery({Query? parent, Set? trampoline}) : super(parent: parent) { + UserQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = UserQueryWhere(this); leftJoin( - '(SELECT role_users.user_email, roles.role FROM roles LEFT JOIN role_users ON role_users.role_role=roles.role)', - 'email', - 'user_email', - additionalFields: const ['role'], - trampoline: trampoline); + '(SELECT role_users.user_email, roles.role FROM roles LEFT JOIN role_users ON role_users.role_role=roles.role)', + 'email', + 'user_email', + additionalFields: const ['role'], + trampoline: trampoline, + ); } @override @@ -387,7 +476,11 @@ class UserQuery extends Query { @override List get fields { - const _fields = ['email', 'name', 'password']; + const _fields = [ + 'email', + 'name', + 'password', + ]; return _selectedFields.isEmpty ? _fields : _fields.where((field) => _selectedFields.contains(field)).toList(); @@ -413,9 +506,10 @@ class UserQuery extends Query { return Optional.empty(); } var model = User( - email: fields.contains('email') ? (row[0] as String?) : null, - name: fields.contains('name') ? (row[1] as String?) : null, - password: fields.contains('password') ? (row[2] as String?) : null); + email: fields.contains('email') ? (row[0] as String?) : null, + name: fields.contains('name') ? (row[1] as String?) : null, + password: fields.contains('password') ? (row[2] as String?) : null, + ); if (row.length > 3) { var modelOpt = RoleQuery().parseRow(row.skip(3).take(1).toList()); modelOpt.ifPresent((m) { @@ -493,9 +587,18 @@ class UserQuery extends Query { class UserQueryWhere extends QueryWhere { UserQueryWhere(UserQuery query) - : email = StringSqlExpressionBuilder(query, 'email'), - name = StringSqlExpressionBuilder(query, 'name'), - password = StringSqlExpressionBuilder(query, 'password'); + : email = StringSqlExpressionBuilder( + query, + 'email', + ), + name = StringSqlExpressionBuilder( + query, + 'name', + ), + password = StringSqlExpressionBuilder( + query, + 'password', + ); final StringSqlExpressionBuilder email; @@ -505,7 +608,11 @@ class UserQueryWhere extends QueryWhere { @override List get expressionBuilders { - return [email, name, password]; + return [ + email, + name, + password, + ]; } } @@ -543,7 +650,10 @@ class UserQueryValues extends MapQueryValues { @generatedSerializable class Role implements _Role { - Role({this.role, this.users = const []}); + Role({ + this.role, + this.users = const [], + }); @override String? role; @@ -551,7 +661,10 @@ class Role implements _Role { @override List<_User> users; - Role copyWith({String? role, List<_User>? users}) { + Role copyWith({ + String? role, + List<_User>? users, + }) { return Role(role: role ?? this.role, users: users ?? this.users); } @@ -565,7 +678,10 @@ class Role implements _Role { @override int get hashCode { - return hashObjects([role, users]); + return hashObjects([ + role, + users, + ]); } @override @@ -580,7 +696,10 @@ class Role implements _Role { @generatedSerializable class RoleUser implements _RoleUser { - RoleUser({this.role, this.user}); + RoleUser({ + this.role, + this.user, + }); @override _Role? role; @@ -588,7 +707,10 @@ class RoleUser implements _RoleUser { @override _User? user; - RoleUser copyWith({_Role? role, _User? user}) { + RoleUser copyWith({ + _Role? role, + _User? user, + }) { return RoleUser(role: role ?? this.role, user: user ?? this.user); } @@ -599,7 +721,10 @@ class RoleUser implements _RoleUser { @override int get hashCode { - return hashObjects([role, user]); + return hashObjects([ + role, + user, + ]); } @override @@ -614,7 +739,12 @@ class RoleUser implements _RoleUser { @generatedSerializable class User implements _User { - User({this.email, this.name, this.password, this.roles = const []}); + User({ + this.email, + this.name, + this.password, + this.roles = const [], + }); @override String? email; @@ -628,8 +758,12 @@ class User implements _User { @override List<_Role> roles; - User copyWith( - {String? email, String? name, String? password, List<_Role>? roles}) { + User copyWith({ + String? email, + String? name, + String? password, + List<_Role>? roles, + }) { return User( email: email ?? this.email, name: name ?? this.name, @@ -649,7 +783,12 @@ class User implements _User { @override int get hashCode { - return hashObjects([email, name, password, roles]); + return hashObjects([ + email, + name, + password, + roles, + ]); } @override @@ -710,7 +849,10 @@ class RoleSerializer extends Codec { } abstract class RoleFields { - static const List allFields = [role, users]; + static const List allFields = [ + role, + users, + ]; static const String role = 'role'; @@ -762,7 +904,10 @@ class RoleUserSerializer extends Codec { } abstract class RoleUserFields { - static const List allFields = [role, user]; + static const List allFields = [ + role, + user, + ]; static const String role = 'role'; @@ -817,7 +962,12 @@ class UserSerializer extends Codec { } abstract class UserFields { - static const List allFields = [email, name, password, roles]; + static const List allFields = [ + email, + name, + password, + roles, + ]; static const String email = 'email'; diff --git a/packages/orm/angel_orm_test/lib/src/models/fortune.g.dart b/packages/orm/angel_orm_test/lib/src/models/fortune.g.dart index 6e10b252..8805785e 100644 --- a/packages/orm/angel_orm_test/lib/src/models/fortune.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/fortune.g.dart @@ -9,10 +9,16 @@ part of 'fortune.dart'; class FortuneMigration extends Migration { @override void up(Schema schema) { - schema.create('fortune', (table) { - table.integer('id').primaryKey(); - table.varChar('message', length: 2048); - }); + schema.create( + 'fortune', + (table) { + table.integer('id').primaryKey(); + table.varChar( + 'message', + length: 2048, + ); + }, + ); } @override @@ -26,8 +32,10 @@ class FortuneMigration extends Migration { // ************************************************************************** class FortuneQuery extends Query { - FortuneQuery({Query? parent, Set? trampoline}) - : super(parent: parent) { + FortuneQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = FortuneQueryWhere(this); @@ -52,7 +60,10 @@ class FortuneQuery extends Query { @override List get fields { - const _fields = ['id', 'message']; + const _fields = [ + 'id', + 'message', + ]; return _selectedFields.isEmpty ? _fields : _fields.where((field) => _selectedFields.contains(field)).toList(); @@ -78,8 +89,9 @@ class FortuneQuery extends Query { return Optional.empty(); } var model = Fortune( - id: fields.contains('id') ? (row[0] as int?) : null, - message: fields.contains('message') ? (row[1] as String?) : null); + id: fields.contains('id') ? (row[0] as int?) : null, + message: fields.contains('message') ? (row[1] as String?) : null, + ); return Optional.of(model); } @@ -91,8 +103,14 @@ class FortuneQuery extends Query { class FortuneQueryWhere extends QueryWhere { FortuneQueryWhere(FortuneQuery query) - : id = NumericSqlExpressionBuilder(query, 'id'), - message = StringSqlExpressionBuilder(query, 'message'); + : id = NumericSqlExpressionBuilder( + query, + 'id', + ), + message = StringSqlExpressionBuilder( + query, + 'message', + ); final NumericSqlExpressionBuilder id; @@ -100,7 +118,10 @@ class FortuneQueryWhere extends QueryWhere { @override List get expressionBuilders { - return [id, message]; + return [ + id, + message, + ]; } } @@ -132,7 +153,10 @@ class FortuneQueryValues extends MapQueryValues { @generatedSerializable class Fortune extends _Fortune { - Fortune({this.id, this.message}); + Fortune({ + this.id, + this.message, + }); @override int? id; @@ -140,7 +164,10 @@ class Fortune extends _Fortune { @override String? message; - Fortune copyWith({int? id, String? message}) { + Fortune copyWith({ + int? id, + String? message, + }) { return Fortune(id: id ?? this.id, message: message ?? this.message); } @@ -151,7 +178,10 @@ class Fortune extends _Fortune { @override int get hashCode { - return hashObjects([id, message]); + return hashObjects([ + id, + message, + ]); } @override @@ -204,7 +234,10 @@ class FortuneSerializer extends Codec { } abstract class FortuneFields { - static const List allFields = [id, message]; + static const List allFields = [ + id, + message, + ]; static const String id = 'id'; diff --git a/packages/orm/angel_orm_test/lib/src/models/has_car.g.dart b/packages/orm/angel_orm_test/lib/src/models/has_car.g.dart index c31ca9b2..a015b11d 100644 --- a/packages/orm/angel_orm_test/lib/src/models/has_car.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/has_car.g.dart @@ -9,12 +9,15 @@ part of 'has_car.dart'; class HasCarMigration extends Migration { @override void up(Schema schema) { - schema.create('has_cars', (table) { - table.serial('id').primaryKey(); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - table.integer('type').defaultsTo(0); - }); + schema.create( + 'has_cars', + (table) { + table.serial('id').primaryKey(); + table.timeStamp('created_at'); + table.timeStamp('updated_at'); + table.integer('type').defaultsTo(0); + }, + ); } @override @@ -28,8 +31,10 @@ class HasCarMigration extends Migration { // ************************************************************************** class HasCarQuery extends Query { - HasCarQuery({Query? parent, Set? trampoline}) - : super(parent: parent) { + HasCarQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = HasCarQueryWhere(this); @@ -54,7 +59,12 @@ class HasCarQuery extends Query { @override List get fields { - const _fields = ['id', 'created_at', 'updated_at', 'type']; + const _fields = [ + 'id', + 'created_at', + 'updated_at', + 'type', + ]; return _selectedFields.isEmpty ? _fields : _fields.where((field) => _selectedFields.contains(field)).toList(); @@ -80,18 +90,17 @@ class HasCarQuery extends Query { return Optional.empty(); } var model = HasCar( - id: fields.contains('id') ? row[0].toString() : null, - createdAt: fields.contains('created_at') - ? mapToNullableDateTime(row[1]) - : null, - updatedAt: fields.contains('updated_at') - ? mapToNullableDateTime(row[2]) - : null, - type: fields.contains('type') - ? row[3] == null - ? null - : CarType.values[(row[3] as int)] - : null); + id: fields.contains('id') ? row[0].toString() : null, + createdAt: + fields.contains('created_at') ? mapToNullableDateTime(row[1]) : null, + updatedAt: + fields.contains('updated_at') ? mapToNullableDateTime(row[2]) : null, + type: fields.contains('type') + ? row[3] == null + ? null + : CarType?.values[(row[3] as int)] + : null, + ); return Optional.of(model); } @@ -103,11 +112,23 @@ class HasCarQuery extends Query { class HasCarQueryWhere extends QueryWhere { HasCarQueryWhere(HasCarQuery query) - : id = NumericSqlExpressionBuilder(query, 'id'), - createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'), + : id = NumericSqlExpressionBuilder( + query, + 'id', + ), + createdAt = DateTimeSqlExpressionBuilder( + query, + 'created_at', + ), + updatedAt = DateTimeSqlExpressionBuilder( + query, + 'updated_at', + ), type = EnumSqlExpressionBuilder( - query, 'type', (v) => v?.index as int); + query, + 'type', + (v) => v?.index as int, + ); final NumericSqlExpressionBuilder id; @@ -119,7 +140,12 @@ class HasCarQueryWhere extends QueryWhere { @override List get expressionBuilders { - return [id, createdAt, updatedAt, type]; + return [ + id, + createdAt, + updatedAt, + type, + ]; } } @@ -145,7 +171,7 @@ class HasCarQueryValues extends MapQueryValues { set updatedAt(DateTime? value) => values['updated_at'] = value; CarType? get type { - return CarType.values[(values['type'] as int)]; + return CarType?.values[(values['type'] as int)]; } set type(CarType? value) => values['type'] = value?.index; @@ -162,7 +188,12 @@ class HasCarQueryValues extends MapQueryValues { @generatedSerializable class HasCar extends _HasCar { - HasCar({this.id, this.createdAt, this.updatedAt, this.type = CarType.sedan}); + HasCar({ + this.id, + this.createdAt, + this.updatedAt, + this.type = CarType.sedan, + }); /// A unique identifier corresponding to this item. @override @@ -179,8 +210,12 @@ class HasCar extends _HasCar { @override CarType? type; - HasCar copyWith( - {String? id, DateTime? createdAt, DateTime? updatedAt, CarType? type}) { + HasCar copyWith({ + String? id, + DateTime? createdAt, + DateTime? updatedAt, + CarType? type, + }) { return HasCar( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -199,7 +234,12 @@ class HasCar extends _HasCar { @override int get hashCode { - return hashObjects([id, createdAt, updatedAt, type]); + return hashObjects([ + id, + createdAt, + updatedAt, + type, + ]); } @override @@ -256,11 +296,7 @@ class HasCarSerializer extends Codec { ? (map['updated_at'] as DateTime) : DateTime.parse(map['updated_at'].toString())) : null, - type: map['type'] is CarType? - ? (map['type'] as CarType?) ?? CarType.sedan - : (map['type'] is int - ? CarType.values[map['type'] as int] - : CarType.sedan)); + type: map['type'] as CarType? ?? CarType.sedan); } static Map toMap(_HasCar? model) { @@ -271,7 +307,7 @@ class HasCarSerializer extends Codec { 'id': model.id, 'created_at': model.createdAt?.toIso8601String(), 'updated_at': model.updatedAt?.toIso8601String(), - 'type': model.type != null ? CarType.values.indexOf(model.type!) : null + 'type': model.type }; } } @@ -281,7 +317,7 @@ abstract class HasCarFields { id, createdAt, updatedAt, - type + type, ]; static const String id = 'id'; diff --git a/packages/orm/angel_orm_test/lib/src/models/has_map.g.dart b/packages/orm/angel_orm_test/lib/src/models/has_map.g.dart index 470ec728..9cc978e5 100644 --- a/packages/orm/angel_orm_test/lib/src/models/has_map.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/has_map.g.dart @@ -9,12 +9,25 @@ part of 'has_map.dart'; class HasMapMigration extends Migration { @override void up(Schema schema) { - schema.create('has_maps', (table) { - table.declareColumn( - 'value', Column(type: ColumnType('jsonb'), length: 255)); - table.declareColumn( - 'list', Column(type: ColumnType('jsonb'), length: 255)); - }); + schema.create( + 'has_maps', + (table) { + table.declareColumn( + 'value', + Column( + type: ColumnType('jsonb'), + length: 255, + ), + ); + table.declareColumn( + 'list', + Column( + type: ColumnType('jsonb'), + length: 255, + ), + ); + }, + ); } @override @@ -28,8 +41,10 @@ class HasMapMigration extends Migration { // ************************************************************************** class HasMapQuery extends Query { - HasMapQuery({Query? parent, Set? trampoline}) - : super(parent: parent) { + HasMapQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = HasMapQueryWhere(this); @@ -54,7 +69,10 @@ class HasMapQuery extends Query { @override List get fields { - const _fields = ['value', 'list']; + const _fields = [ + 'value', + 'list', + ]; return _selectedFields.isEmpty ? _fields : _fields.where((field) => _selectedFields.contains(field)).toList(); @@ -80,10 +98,10 @@ class HasMapQuery extends Query { return Optional.empty(); } var model = HasMap( - value: fields.contains('value') - ? (row[0] as Map?) - : null, - list: fields.contains('list') ? (row[1] as List?) : null); + value: + fields.contains('value') ? (row[0] as Map?) : null, + list: fields.contains('list') ? (row[1] as List?) : null, + ); return Optional.of(model); } @@ -95,8 +113,14 @@ class HasMapQuery extends Query { class HasMapQueryWhere extends QueryWhere { HasMapQueryWhere(HasMapQuery query) - : value = MapSqlExpressionBuilder(query, 'value'), - list = ListSqlExpressionBuilder(query, 'list'); + : value = MapSqlExpressionBuilder( + query, + 'value', + ), + list = ListSqlExpressionBuilder( + query, + 'list', + ); final MapSqlExpressionBuilder value; @@ -104,7 +128,10 @@ class HasMapQueryWhere extends QueryWhere { @override List get expressionBuilders { - return [value, list]; + return [ + value, + list, + ]; } } @@ -120,7 +147,7 @@ class HasMapQueryValues extends MapQueryValues { set value(Map? value) => values['value'] = value; List? get list { - return (json.decode((values['list'] as String)) as List); + return json.decode((values['list'] as String)).cast(); } set list(List? value) => values['list'] = json.encode(value); @@ -136,7 +163,10 @@ class HasMapQueryValues extends MapQueryValues { @generatedSerializable class HasMap implements _HasMap { - HasMap({this.value, this.list = const []}); + HasMap({ + this.value, + this.list = const [], + }); @override Map? value; @@ -144,7 +174,10 @@ class HasMap implements _HasMap { @override List? list; - HasMap copyWith({Map? value, List? list}) { + HasMap copyWith({ + Map? value, + List? list, + }) { return HasMap(value: value ?? this.value, list: list ?? this.list); } @@ -159,7 +192,10 @@ class HasMap implements _HasMap { @override int get hashCode { - return hashObjects([value, list]); + return hashObjects([ + value, + list, + ]); } @override @@ -218,7 +254,10 @@ class HasMapSerializer extends Codec { } abstract class HasMapFields { - static const List allFields = [value, list]; + static const List allFields = [ + value, + list, + ]; static const String value = 'value'; diff --git a/packages/orm/angel_orm_test/lib/src/models/leg.g.dart b/packages/orm/angel_orm_test/lib/src/models/leg.g.dart index d01cb636..183c9523 100644 --- a/packages/orm/angel_orm_test/lib/src/models/leg.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/leg.g.dart @@ -9,30 +9,42 @@ part of angel3_orm_generator.test.models.leg; class LegMigration extends Migration { @override void up(Schema schema) { - schema.create('legs', (table) { - table.serial('id').primaryKey(); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - table.varChar('name', length: 255); - }); + schema.create( + 'legs', + (table) { + table.serial('id').primaryKey(); + table.timeStamp('created_at'); + table.timeStamp('updated_at'); + table.varChar( + 'name', + length: 255, + ); + }, + ); } @override void down(Schema schema) { - schema.drop('legs', cascade: true); + schema.drop( + 'legs', + cascade: true, + ); } } class FootMigration extends Migration { @override void up(Schema schema) { - schema.create('feet', (table) { - table.serial('id').primaryKey(); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - table.integer('leg_id'); - table.double('n_toes'); - }); + schema.create( + 'feet', + (table) { + table.serial('id').primaryKey(); + table.timeStamp('created_at'); + table.timeStamp('updated_at'); + table.integer('leg_id'); + table.double('n_toes'); + }, + ); } @override @@ -46,20 +58,29 @@ class FootMigration extends Migration { // ************************************************************************** class LegQuery extends Query { - LegQuery({Query? parent, Set? trampoline}) : super(parent: parent) { + LegQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = LegQueryWhere(this); leftJoin( - _foot = FootQuery(trampoline: trampoline, parent: this), 'id', 'leg_id', - additionalFields: const [ - 'id', - 'created_at', - 'updated_at', - 'leg_id', - 'n_toes' - ], - trampoline: trampoline); + _foot = FootQuery( + trampoline: trampoline, + parent: this, + ), + 'id', + 'leg_id', + additionalFields: const [ + 'id', + 'created_at', + 'updated_at', + 'leg_id', + 'n_toes', + ], + trampoline: trampoline, + ); } @override @@ -83,7 +104,12 @@ class LegQuery extends Query { @override List get fields { - const _fields = ['id', 'created_at', 'updated_at', 'name']; + const _fields = [ + 'id', + 'created_at', + 'updated_at', + 'name', + ]; return _selectedFields.isEmpty ? _fields : _fields.where((field) => _selectedFields.contains(field)).toList(); @@ -109,14 +135,13 @@ class LegQuery extends Query { return Optional.empty(); } var model = Leg( - id: fields.contains('id') ? row[0].toString() : null, - createdAt: fields.contains('created_at') - ? mapToNullableDateTime(row[1]) - : null, - updatedAt: fields.contains('updated_at') - ? mapToNullableDateTime(row[2]) - : null, - name: fields.contains('name') ? (row[3] as String?) : null); + id: fields.contains('id') ? row[0].toString() : null, + createdAt: + fields.contains('created_at') ? mapToNullableDateTime(row[1]) : null, + updatedAt: + fields.contains('updated_at') ? mapToNullableDateTime(row[2]) : null, + name: fields.contains('name') ? (row[3] as String?) : null, + ); if (row.length > 4) { var modelOpt = FootQuery().parseRow(row.skip(4).take(5).toList()); modelOpt.ifPresent((m) { @@ -138,10 +163,22 @@ class LegQuery extends Query { class LegQueryWhere extends QueryWhere { LegQueryWhere(LegQuery query) - : id = NumericSqlExpressionBuilder(query, 'id'), - createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'), - name = StringSqlExpressionBuilder(query, 'name'); + : id = NumericSqlExpressionBuilder( + query, + 'id', + ), + createdAt = DateTimeSqlExpressionBuilder( + query, + 'created_at', + ), + updatedAt = DateTimeSqlExpressionBuilder( + query, + 'updated_at', + ), + name = StringSqlExpressionBuilder( + query, + 'name', + ); final NumericSqlExpressionBuilder id; @@ -153,7 +190,12 @@ class LegQueryWhere extends QueryWhere { @override List get expressionBuilders { - return [id, createdAt, updatedAt, name]; + return [ + id, + createdAt, + updatedAt, + name, + ]; } } @@ -191,7 +233,10 @@ class LegQueryValues extends MapQueryValues { } class FootQuery extends Query { - FootQuery({Query? parent, Set? trampoline}) : super(parent: parent) { + FootQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = FootQueryWhere(this); @@ -206,7 +251,7 @@ class FootQuery extends Query { @override Map get casts { - return {'n_toes': 'char'}; + return {}; } @override @@ -216,7 +261,13 @@ class FootQuery extends Query { @override List get fields { - const _fields = ['id', 'created_at', 'updated_at', 'leg_id', 'n_toes']; + const _fields = [ + 'id', + 'created_at', + 'updated_at', + 'leg_id', + 'n_toes', + ]; return _selectedFields.isEmpty ? _fields : _fields.where((field) => _selectedFields.contains(field)).toList(); @@ -242,15 +293,14 @@ class FootQuery extends Query { return Optional.empty(); } var model = Foot( - id: fields.contains('id') ? row[0].toString() : null, - createdAt: fields.contains('created_at') - ? mapToNullableDateTime(row[1]) - : null, - updatedAt: fields.contains('updated_at') - ? mapToNullableDateTime(row[2]) - : null, - legId: fields.contains('leg_id') ? (row[3] as int?) : null, - nToes: fields.contains('n_toes') ? mapToDouble(row[4]) : null); + id: fields.contains('id') ? row[0].toString() : null, + createdAt: + fields.contains('created_at') ? mapToNullableDateTime(row[1]) : null, + updatedAt: + fields.contains('updated_at') ? mapToNullableDateTime(row[2]) : null, + legId: fields.contains('leg_id') ? (row[3] as int?) : null, + nToes: fields.contains('n_toes') ? mapToDouble(row[4]) : null, + ); return Optional.of(model); } @@ -262,11 +312,26 @@ class FootQuery extends Query { class FootQueryWhere extends QueryWhere { FootQueryWhere(FootQuery query) - : id = NumericSqlExpressionBuilder(query, 'id'), - createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'), - legId = NumericSqlExpressionBuilder(query, 'leg_id'), - nToes = NumericSqlExpressionBuilder(query, 'n_toes'); + : id = NumericSqlExpressionBuilder( + query, + 'id', + ), + createdAt = DateTimeSqlExpressionBuilder( + query, + 'created_at', + ), + updatedAt = DateTimeSqlExpressionBuilder( + query, + 'updated_at', + ), + legId = NumericSqlExpressionBuilder( + query, + 'leg_id', + ), + nToes = NumericSqlExpressionBuilder( + query, + 'n_toes', + ); final NumericSqlExpressionBuilder id; @@ -280,14 +345,20 @@ class FootQueryWhere extends QueryWhere { @override List get expressionBuilders { - return [id, createdAt, updatedAt, legId, nToes]; + return [ + id, + createdAt, + updatedAt, + legId, + nToes, + ]; } } class FootQueryValues extends MapQueryValues { @override Map get casts { - return {'n_toes': 'double precision'}; + return {}; } String? get id { @@ -311,10 +382,10 @@ class FootQueryValues extends MapQueryValues { set legId(int? value) => values['leg_id'] = value; double? get nToes { - return double.tryParse((values['n_toes'] as String)) ?? 0.0; + return (values['n_toes'] as double?) ?? 0.0; } - set nToes(double? value) => values['n_toes'] = value.toString(); + set nToes(double? value) => values['n_toes'] = value; void copyFrom(Foot model) { createdAt = model.createdAt; updatedAt = model.updatedAt; @@ -329,7 +400,13 @@ class FootQueryValues extends MapQueryValues { @generatedSerializable class Leg extends _Leg { - Leg({this.id, this.createdAt, this.updatedAt, this.foot, this.name}); + Leg({ + this.id, + this.createdAt, + this.updatedAt, + this.foot, + this.name, + }); /// A unique identifier corresponding to this item. @override @@ -349,12 +426,13 @@ class Leg extends _Leg { @override String? name; - Leg copyWith( - {String? id, - DateTime? createdAt, - DateTime? updatedAt, - _Foot? foot, - String? name}) { + Leg copyWith({ + String? id, + DateTime? createdAt, + DateTime? updatedAt, + _Foot? foot, + String? name, + }) { return Leg( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -375,7 +453,13 @@ class Leg extends _Leg { @override int get hashCode { - return hashObjects([id, createdAt, updatedAt, foot, name]); + return hashObjects([ + id, + createdAt, + updatedAt, + foot, + name, + ]); } @override @@ -390,7 +474,13 @@ class Leg extends _Leg { @generatedSerializable class Foot extends _Foot { - Foot({this.id, this.createdAt, this.updatedAt, this.legId, this.nToes}); + Foot({ + this.id, + this.createdAt, + this.updatedAt, + this.legId, + this.nToes, + }); /// A unique identifier corresponding to this item. @override @@ -410,12 +500,13 @@ class Foot extends _Foot { @override double? nToes; - Foot copyWith( - {String? id, - DateTime? createdAt, - DateTime? updatedAt, - int? legId, - double? nToes}) { + Foot copyWith({ + String? id, + DateTime? createdAt, + DateTime? updatedAt, + int? legId, + double? nToes, + }) { return Foot( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -436,7 +527,13 @@ class Foot extends _Foot { @override int get hashCode { - return hashObjects([id, createdAt, updatedAt, legId, nToes]); + return hashObjects([ + id, + createdAt, + updatedAt, + legId, + nToes, + ]); } @override @@ -515,7 +612,7 @@ abstract class LegFields { createdAt, updatedAt, foot, - name + name, ]; static const String id = 'id'; @@ -589,7 +686,7 @@ abstract class FootFields { createdAt, updatedAt, legId, - nToes + nToes, ]; static const String id = 'id'; diff --git a/packages/orm/angel_orm_test/lib/src/models/order.g.dart b/packages/orm/angel_orm_test/lib/src/models/order.g.dart index cdf5f1a8..aaa7fdce 100644 --- a/packages/orm/angel_orm_test/lib/src/models/order.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/order.g.dart @@ -9,17 +9,26 @@ part of angel3_orm_generator.test.models.order; class OrderMigration extends Migration { @override void up(Schema schema) { - schema.create('orders', (table) { - table.serial('id').primaryKey(); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - table.integer('employee_id'); - table.timeStamp('order_date'); - table.integer('shipper_id'); - table - .declare('customer_id', ColumnType('int')) - .references('customers', 'id'); - }); + schema.create( + 'orders', + (table) { + table.serial('id').primaryKey(); + table.timeStamp('created_at'); + table.timeStamp('updated_at'); + table.integer('employee_id'); + table.timeStamp('order_date'); + table.integer('shipper_id'); + table + .declare( + 'customer_id', + ColumnType('int'), + ) + .references( + 'customers', + 'id', + ); + }, + ); } @override @@ -31,11 +40,14 @@ class OrderMigration extends Migration { class CustomerMigration extends Migration { @override void up(Schema schema) { - schema.create('customers', (table) { - table.serial('id').primaryKey(); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - }); + schema.create( + 'customers', + (table) { + table.serial('id').primaryKey(); + table.timeStamp('created_at'); + table.timeStamp('updated_at'); + }, + ); } @override @@ -49,14 +61,27 @@ class CustomerMigration extends Migration { // ************************************************************************** class OrderQuery extends Query { - OrderQuery({Query? parent, Set? trampoline}) : super(parent: parent) { + OrderQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = OrderQueryWhere(this); - leftJoin(_customer = CustomerQuery(trampoline: trampoline, parent: this), - 'customer_id', 'id', - additionalFields: const ['id', 'created_at', 'updated_at'], - trampoline: trampoline); + leftJoin( + _customer = CustomerQuery( + trampoline: trampoline, + parent: this, + ), + 'customer_id', + 'id', + additionalFields: const [ + 'id', + 'created_at', + 'updated_at', + ], + trampoline: trampoline, + ); } @override @@ -87,7 +112,7 @@ class OrderQuery extends Query { 'customer_id', 'employee_id', 'order_date', - 'shipper_id' + 'shipper_id', ]; return _selectedFields.isEmpty ? _fields @@ -114,18 +139,16 @@ class OrderQuery extends Query { return Optional.empty(); } var model = Order( - id: fields.contains('id') ? row[0].toString() : null, - createdAt: fields.contains('created_at') - ? mapToNullableDateTime(row[1]) - : null, - updatedAt: fields.contains('updated_at') - ? mapToNullableDateTime(row[2]) - : null, - employeeId: fields.contains('employee_id') ? (row[4] as int?) : null, - orderDate: fields.contains('order_date') - ? mapToNullableDateTime(row[5]) - : null, - shipperId: fields.contains('shipper_id') ? (row[6] as int?) : null); + id: fields.contains('id') ? row[0].toString() : null, + createdAt: + fields.contains('created_at') ? mapToNullableDateTime(row[1]) : null, + updatedAt: + fields.contains('updated_at') ? mapToNullableDateTime(row[2]) : null, + employeeId: fields.contains('employee_id') ? (row[4] as int?) : null, + orderDate: + fields.contains('order_date') ? mapToNullableDateTime(row[5]) : null, + shipperId: fields.contains('shipper_id') ? (row[6] as int?) : null, + ); if (row.length > 7) { var modelOpt = CustomerQuery().parseRow(row.skip(7).take(3).toList()); modelOpt.ifPresent((m) { @@ -147,13 +170,34 @@ class OrderQuery extends Query { class OrderQueryWhere extends QueryWhere { OrderQueryWhere(OrderQuery query) - : id = NumericSqlExpressionBuilder(query, 'id'), - createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'), - customerId = NumericSqlExpressionBuilder(query, 'customer_id'), - employeeId = NumericSqlExpressionBuilder(query, 'employee_id'), - orderDate = DateTimeSqlExpressionBuilder(query, 'order_date'), - shipperId = NumericSqlExpressionBuilder(query, 'shipper_id'); + : id = NumericSqlExpressionBuilder( + query, + 'id', + ), + createdAt = DateTimeSqlExpressionBuilder( + query, + 'created_at', + ), + updatedAt = DateTimeSqlExpressionBuilder( + query, + 'updated_at', + ), + customerId = NumericSqlExpressionBuilder( + query, + 'customer_id', + ), + employeeId = NumericSqlExpressionBuilder( + query, + 'employee_id', + ), + orderDate = DateTimeSqlExpressionBuilder( + query, + 'order_date', + ), + shipperId = NumericSqlExpressionBuilder( + query, + 'shipper_id', + ); final NumericSqlExpressionBuilder id; @@ -178,7 +222,7 @@ class OrderQueryWhere extends QueryWhere { customerId, employeeId, orderDate, - shipperId + shipperId, ]; } } @@ -237,8 +281,10 @@ class OrderQueryValues extends MapQueryValues { } class CustomerQuery extends Query { - CustomerQuery({Query? parent, Set? trampoline}) - : super(parent: parent) { + CustomerQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = CustomerQueryWhere(this); @@ -263,7 +309,11 @@ class CustomerQuery extends Query { @override List get fields { - const _fields = ['id', 'created_at', 'updated_at']; + const _fields = [ + 'id', + 'created_at', + 'updated_at', + ]; return _selectedFields.isEmpty ? _fields : _fields.where((field) => _selectedFields.contains(field)).toList(); @@ -289,13 +339,12 @@ class CustomerQuery extends Query { return Optional.empty(); } var model = Customer( - id: fields.contains('id') ? row[0].toString() : null, - createdAt: fields.contains('created_at') - ? mapToNullableDateTime(row[1]) - : null, - updatedAt: fields.contains('updated_at') - ? mapToNullableDateTime(row[2]) - : null); + id: fields.contains('id') ? row[0].toString() : null, + createdAt: + fields.contains('created_at') ? mapToNullableDateTime(row[1]) : null, + updatedAt: + fields.contains('updated_at') ? mapToNullableDateTime(row[2]) : null, + ); return Optional.of(model); } @@ -307,9 +356,18 @@ class CustomerQuery extends Query { class CustomerQueryWhere extends QueryWhere { CustomerQueryWhere(CustomerQuery query) - : id = NumericSqlExpressionBuilder(query, 'id'), - createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'); + : id = NumericSqlExpressionBuilder( + query, + 'id', + ), + createdAt = DateTimeSqlExpressionBuilder( + query, + 'created_at', + ), + updatedAt = DateTimeSqlExpressionBuilder( + query, + 'updated_at', + ); final NumericSqlExpressionBuilder id; @@ -319,7 +377,11 @@ class CustomerQueryWhere extends QueryWhere { @override List get expressionBuilders { - return [id, createdAt, updatedAt]; + return [ + id, + createdAt, + updatedAt, + ]; } } @@ -356,14 +418,15 @@ class CustomerQueryValues extends MapQueryValues { @generatedSerializable class Order extends _Order { - Order( - {this.id, - this.createdAt, - this.updatedAt, - this.customer, - this.employeeId, - this.orderDate, - this.shipperId}); + Order({ + this.id, + this.createdAt, + this.updatedAt, + this.customer, + this.employeeId, + this.orderDate, + this.shipperId, + }); /// A unique identifier corresponding to this item. @override @@ -389,14 +452,15 @@ class Order extends _Order { @override int? shipperId; - Order copyWith( - {String? id, - DateTime? createdAt, - DateTime? updatedAt, - _Customer? customer, - int? employeeId, - DateTime? orderDate, - int? shipperId}) { + Order copyWith({ + String? id, + DateTime? createdAt, + DateTime? updatedAt, + _Customer? customer, + int? employeeId, + DateTime? orderDate, + int? shipperId, + }) { return Order( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -421,8 +485,15 @@ class Order extends _Order { @override int get hashCode { - return hashObjects( - [id, createdAt, updatedAt, customer, employeeId, orderDate, shipperId]); + return hashObjects([ + id, + createdAt, + updatedAt, + customer, + employeeId, + orderDate, + shipperId, + ]); } @override @@ -437,7 +508,11 @@ class Order extends _Order { @generatedSerializable class Customer extends _Customer { - Customer({this.id, this.createdAt, this.updatedAt}); + Customer({ + this.id, + this.createdAt, + this.updatedAt, + }); /// A unique identifier corresponding to this item. @override @@ -451,7 +526,11 @@ class Customer extends _Customer { @override DateTime? updatedAt; - Customer copyWith({String? id, DateTime? createdAt, DateTime? updatedAt}) { + Customer copyWith({ + String? id, + DateTime? createdAt, + DateTime? updatedAt, + }) { return Customer( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -468,7 +547,11 @@ class Customer extends _Customer { @override int get hashCode { - return hashObjects([id, createdAt, updatedAt]); + return hashObjects([ + id, + createdAt, + updatedAt, + ]); } @override @@ -557,7 +640,7 @@ abstract class OrderFields { customer, employeeId, orderDate, - shipperId + shipperId, ]; static const String id = 'id'; @@ -626,7 +709,11 @@ class CustomerSerializer extends Codec { } abstract class CustomerFields { - static const List allFields = [id, createdAt, updatedAt]; + static const List allFields = [ + id, + createdAt, + updatedAt, + ]; static const String id = 'id'; diff --git a/packages/orm/angel_orm_test/lib/src/models/person.g.dart b/packages/orm/angel_orm_test/lib/src/models/person.g.dart index 55d2a424..2da16de2 100644 --- a/packages/orm/angel_orm_test/lib/src/models/person.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/person.g.dart @@ -9,13 +9,19 @@ part of angel_orm3.generator.models.person; class PersonMigration extends Migration { @override void up(Schema schema) { - schema.create('persons', (table) { - table.serial('id').primaryKey(); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - table.varChar('name', length: 255); - table.integer('age'); - }); + schema.create( + 'persons', + (table) { + table.serial('id').primaryKey(); + table.timeStamp('created_at'); + table.timeStamp('updated_at'); + table.varChar( + 'name', + length: 255, + ); + table.integer('age'); + }, + ); } @override @@ -29,8 +35,10 @@ class PersonMigration extends Migration { // ************************************************************************** class PersonQuery extends Query { - PersonQuery({Query? parent, Set? trampoline}) - : super(parent: parent) { + PersonQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = PersonQueryWhere(this); @@ -55,7 +63,13 @@ class PersonQuery extends Query { @override List get fields { - const _fields = ['id', 'created_at', 'updated_at', 'name', 'age']; + const _fields = [ + 'id', + 'created_at', + 'updated_at', + 'name', + 'age', + ]; return _selectedFields.isEmpty ? _fields : _fields.where((field) => _selectedFields.contains(field)).toList(); @@ -81,15 +95,14 @@ class PersonQuery extends Query { return Optional.empty(); } var model = Person( - id: fields.contains('id') ? row[0].toString() : null, - createdAt: fields.contains('created_at') - ? mapToNullableDateTime(row[1]) - : null, - updatedAt: fields.contains('updated_at') - ? mapToNullableDateTime(row[2]) - : null, - name: fields.contains('name') ? (row[3] as String?) : null, - age: fields.contains('age') ? (row[4] as int?) : null); + id: fields.contains('id') ? row[0].toString() : null, + createdAt: + fields.contains('created_at') ? mapToNullableDateTime(row[1]) : null, + updatedAt: + fields.contains('updated_at') ? mapToNullableDateTime(row[2]) : null, + name: fields.contains('name') ? (row[3] as String?) : null, + age: fields.contains('age') ? (row[4] as int?) : null, + ); return Optional.of(model); } @@ -101,11 +114,26 @@ class PersonQuery extends Query { class PersonQueryWhere extends QueryWhere { PersonQueryWhere(PersonQuery query) - : id = NumericSqlExpressionBuilder(query, 'id'), - createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'), - name = StringSqlExpressionBuilder(query, 'name'), - age = NumericSqlExpressionBuilder(query, 'age'); + : id = NumericSqlExpressionBuilder( + query, + 'id', + ), + createdAt = DateTimeSqlExpressionBuilder( + query, + 'created_at', + ), + updatedAt = DateTimeSqlExpressionBuilder( + query, + 'updated_at', + ), + name = StringSqlExpressionBuilder( + query, + 'name', + ), + age = NumericSqlExpressionBuilder( + query, + 'age', + ); final NumericSqlExpressionBuilder id; @@ -119,7 +147,13 @@ class PersonQueryWhere extends QueryWhere { @override List get expressionBuilders { - return [id, createdAt, updatedAt, name, age]; + return [ + id, + createdAt, + updatedAt, + name, + age, + ]; } } @@ -164,8 +198,10 @@ class PersonQueryValues extends MapQueryValues { class PersonWithLastOrderQuery extends Query { - PersonWithLastOrderQuery({Query? parent, Set? trampoline}) - : super(parent: parent) { + PersonWithLastOrderQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); expressions['last_order_name'] = 'po.name'; @@ -183,7 +219,7 @@ class PersonWithLastOrderQuery @override Map get casts { - return {'last_order_price': 'char'}; + return {}; } @override @@ -193,7 +229,11 @@ class PersonWithLastOrderQuery @override List get fields { - const _fields = ['name', 'last_order_name', 'last_order_price']; + const _fields = [ + 'name', + 'last_order_name', + 'last_order_price', + ]; return _selectedFields.isEmpty ? _fields : _fields.where((field) => _selectedFields.contains(field)).toList(); @@ -219,11 +259,12 @@ class PersonWithLastOrderQuery return Optional.empty(); } var model = PersonWithLastOrder( - name: fields.contains('name') ? (row[0] as String?) : null, - lastOrderName: - fields.contains('last_order_name') ? (row[1] as String?) : null, - lastOrderPrice: - fields.contains('last_order_price') ? mapToDouble(row[2]) : null); + name: fields.contains('name') ? (row[0] as String?) : null, + lastOrderName: + fields.contains('last_order_name') ? (row[1] as String?) : null, + lastOrderPrice: + fields.contains('last_order_price') ? mapToDouble(row[2]) : null, + ); return Optional.of(model); } @@ -235,7 +276,10 @@ class PersonWithLastOrderQuery class PersonWithLastOrderQueryWhere extends QueryWhere { PersonWithLastOrderQueryWhere(PersonWithLastOrderQuery query) - : name = StringSqlExpressionBuilder(query, 'name'); + : name = StringSqlExpressionBuilder( + query, + 'name', + ); final StringSqlExpressionBuilder name; @@ -248,7 +292,7 @@ class PersonWithLastOrderQueryWhere extends QueryWhere { class PersonWithLastOrderQueryValues extends MapQueryValues { @override Map get casts { - return {'last_order_price': 'double precision'}; + return {}; } String? get name { @@ -267,7 +311,13 @@ class PersonWithLastOrderQueryValues extends MapQueryValues { @generatedSerializable class Person extends _Person { - Person({this.id, this.createdAt, this.updatedAt, this.name, this.age}); + Person({ + this.id, + this.createdAt, + this.updatedAt, + this.name, + this.age, + }); /// A unique identifier corresponding to this item. @override @@ -287,12 +337,13 @@ class Person extends _Person { @override int? age; - Person copyWith( - {String? id, - DateTime? createdAt, - DateTime? updatedAt, - String? name, - int? age}) { + Person copyWith({ + String? id, + DateTime? createdAt, + DateTime? updatedAt, + String? name, + int? age, + }) { return Person( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -313,7 +364,13 @@ class Person extends _Person { @override int get hashCode { - return hashObjects([id, createdAt, updatedAt, name, age]); + return hashObjects([ + id, + createdAt, + updatedAt, + name, + age, + ]); } @override @@ -328,7 +385,11 @@ class Person extends _Person { @generatedSerializable class PersonWithLastOrder extends _PersonWithLastOrder { - PersonWithLastOrder({this.name, this.lastOrderName, this.lastOrderPrice}); + PersonWithLastOrder({ + this.name, + this.lastOrderName, + this.lastOrderPrice, + }); @override String? name; @@ -339,8 +400,11 @@ class PersonWithLastOrder extends _PersonWithLastOrder { @override double? lastOrderPrice; - PersonWithLastOrder copyWith( - {String? name, String? lastOrderName, double? lastOrderPrice}) { + PersonWithLastOrder copyWith({ + String? name, + String? lastOrderName, + double? lastOrderPrice, + }) { return PersonWithLastOrder( name: name ?? this.name, lastOrderName: lastOrderName ?? this.lastOrderName, @@ -357,7 +421,11 @@ class PersonWithLastOrder extends _PersonWithLastOrder { @override int get hashCode { - return hashObjects([name, lastOrderName, lastOrderPrice]); + return hashObjects([ + name, + lastOrderName, + lastOrderPrice, + ]); } @override @@ -434,7 +502,7 @@ abstract class PersonFields { createdAt, updatedAt, name, - age + age, ]; static const String id = 'id'; @@ -497,7 +565,7 @@ abstract class PersonWithLastOrderFields { static const List allFields = [ name, lastOrderName, - lastOrderPrice + lastOrderPrice, ]; static const String name = 'name'; diff --git a/packages/orm/angel_orm_test/lib/src/models/person_order.g.dart b/packages/orm/angel_orm_test/lib/src/models/person_order.g.dart index 069b75a2..c04a25d6 100644 --- a/packages/orm/angel_orm_test/lib/src/models/person_order.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/person_order.g.dart @@ -9,15 +9,21 @@ part of angel3_orm_generator.test.models.person_order; class PersonOrderMigration extends Migration { @override void up(Schema schema) { - schema.create('person_orders', (table) { - table.serial('id').primaryKey(); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - table.integer('person_id'); - table.varChar('name', length: 255); - table.double('price'); - table.boolean('deleted'); - }); + schema.create( + 'person_orders', + (table) { + table.serial('id').primaryKey(); + table.timeStamp('created_at'); + table.timeStamp('updated_at'); + table.integer('person_id'); + table.varChar( + 'name', + length: 255, + ); + table.double('price'); + table.boolean('deleted'); + }, + ); } @override @@ -31,8 +37,10 @@ class PersonOrderMigration extends Migration { // ************************************************************************** class PersonOrderQuery extends Query { - PersonOrderQuery({Query? parent, Set? trampoline}) - : super(parent: parent) { + PersonOrderQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = PersonOrderQueryWhere(this); @@ -47,7 +55,7 @@ class PersonOrderQuery extends Query { @override Map get casts { - return {'price': 'char'}; + return {}; } @override @@ -64,7 +72,7 @@ class PersonOrderQuery extends Query { 'person_id', 'name', 'price', - 'deleted' + 'deleted', ]; return _selectedFields.isEmpty ? _fields @@ -91,17 +99,16 @@ class PersonOrderQuery extends Query { return Optional.empty(); } var model = PersonOrder( - id: fields.contains('id') ? row[0].toString() : null, - createdAt: fields.contains('created_at') - ? mapToNullableDateTime(row[1]) - : null, - updatedAt: fields.contains('updated_at') - ? mapToNullableDateTime(row[2]) - : null, - personId: fields.contains('person_id') ? (row[3] as int?) : null, - name: fields.contains('name') ? (row[4] as String?) : null, - price: fields.contains('price') ? mapToDouble(row[5]) : null, - deleted: fields.contains('deleted') ? mapToBool(row[6]) : null); + id: fields.contains('id') ? row[0].toString() : null, + createdAt: + fields.contains('created_at') ? mapToNullableDateTime(row[1]) : null, + updatedAt: + fields.contains('updated_at') ? mapToNullableDateTime(row[2]) : null, + personId: fields.contains('person_id') ? (row[3] as int?) : null, + name: fields.contains('name') ? (row[4] as String?) : null, + price: fields.contains('price') ? mapToDouble(row[5]) : null, + deleted: fields.contains('deleted') ? mapToBool(row[6]) : null, + ); return Optional.of(model); } @@ -113,13 +120,34 @@ class PersonOrderQuery extends Query { class PersonOrderQueryWhere extends QueryWhere { PersonOrderQueryWhere(PersonOrderQuery query) - : id = NumericSqlExpressionBuilder(query, 'id'), - createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'), - personId = NumericSqlExpressionBuilder(query, 'person_id'), - name = StringSqlExpressionBuilder(query, 'name'), - price = NumericSqlExpressionBuilder(query, 'price'), - deleted = BooleanSqlExpressionBuilder(query, 'deleted'); + : id = NumericSqlExpressionBuilder( + query, + 'id', + ), + createdAt = DateTimeSqlExpressionBuilder( + query, + 'created_at', + ), + updatedAt = DateTimeSqlExpressionBuilder( + query, + 'updated_at', + ), + personId = NumericSqlExpressionBuilder( + query, + 'person_id', + ), + name = StringSqlExpressionBuilder( + query, + 'name', + ), + price = NumericSqlExpressionBuilder( + query, + 'price', + ), + deleted = BooleanSqlExpressionBuilder( + query, + 'deleted', + ); final NumericSqlExpressionBuilder id; @@ -137,14 +165,22 @@ class PersonOrderQueryWhere extends QueryWhere { @override List get expressionBuilders { - return [id, createdAt, updatedAt, personId, name, price, deleted]; + return [ + id, + createdAt, + updatedAt, + personId, + name, + price, + deleted, + ]; } } class PersonOrderQueryValues extends MapQueryValues { @override Map get casts { - return {'price': 'double precision'}; + return {}; } String? get id { @@ -173,10 +209,10 @@ class PersonOrderQueryValues extends MapQueryValues { set name(String? value) => values['name'] = value; double? get price { - return double.tryParse((values['price'] as String)) ?? 0.0; + return (values['price'] as double?) ?? 0.0; } - set price(double? value) => values['price'] = value.toString(); + set price(double? value) => values['price'] = value; bool? get deleted { return (values['deleted'] as bool?); } @@ -194,8 +230,10 @@ class PersonOrderQueryValues extends MapQueryValues { class OrderWithPersonInfoQuery extends Query { - OrderWithPersonInfoQuery({Query? parent, Set? trampoline}) - : super(parent: parent) { + OrderWithPersonInfoQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); expressions['person_name'] = 'p.name'; @@ -213,7 +251,7 @@ class OrderWithPersonInfoQuery @override Map get casts { - return {'price': 'char'}; + return {}; } @override @@ -231,7 +269,7 @@ class OrderWithPersonInfoQuery 'price', 'deleted', 'person_name', - 'person_age' + 'person_age', ]; return _selectedFields.isEmpty ? _fields @@ -258,18 +296,17 @@ class OrderWithPersonInfoQuery return Optional.empty(); } var model = OrderWithPersonInfo( - id: fields.contains('id') ? row[0].toString() : null, - createdAt: fields.contains('created_at') - ? mapToNullableDateTime(row[1]) - : null, - updatedAt: fields.contains('updated_at') - ? mapToNullableDateTime(row[2]) - : null, - name: fields.contains('name') ? (row[3] as String?) : null, - price: fields.contains('price') ? mapToDouble(row[4]) : null, - deleted: fields.contains('deleted') ? mapToBool(row[5]) : null, - personName: fields.contains('person_name') ? (row[6] as String?) : null, - personAge: fields.contains('person_age') ? (row[7] as int?) : null); + id: fields.contains('id') ? row[0].toString() : null, + createdAt: + fields.contains('created_at') ? mapToNullableDateTime(row[1]) : null, + updatedAt: + fields.contains('updated_at') ? mapToNullableDateTime(row[2]) : null, + name: fields.contains('name') ? (row[3] as String?) : null, + price: fields.contains('price') ? mapToDouble(row[4]) : null, + deleted: fields.contains('deleted') ? mapToBool(row[5]) : null, + personName: fields.contains('person_name') ? (row[6] as String?) : null, + personAge: fields.contains('person_age') ? (row[7] as int?) : null, + ); return Optional.of(model); } @@ -281,12 +318,30 @@ class OrderWithPersonInfoQuery class OrderWithPersonInfoQueryWhere extends QueryWhere { OrderWithPersonInfoQueryWhere(OrderWithPersonInfoQuery query) - : id = NumericSqlExpressionBuilder(query, 'id'), - createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'), - name = StringSqlExpressionBuilder(query, 'name'), - price = NumericSqlExpressionBuilder(query, 'price'), - deleted = BooleanSqlExpressionBuilder(query, 'deleted'); + : id = NumericSqlExpressionBuilder( + query, + 'id', + ), + createdAt = DateTimeSqlExpressionBuilder( + query, + 'created_at', + ), + updatedAt = DateTimeSqlExpressionBuilder( + query, + 'updated_at', + ), + name = StringSqlExpressionBuilder( + query, + 'name', + ), + price = NumericSqlExpressionBuilder( + query, + 'price', + ), + deleted = BooleanSqlExpressionBuilder( + query, + 'deleted', + ); final NumericSqlExpressionBuilder id; @@ -302,14 +357,21 @@ class OrderWithPersonInfoQueryWhere extends QueryWhere { @override List get expressionBuilders { - return [id, createdAt, updatedAt, name, price, deleted]; + return [ + id, + createdAt, + updatedAt, + name, + price, + deleted, + ]; } } class OrderWithPersonInfoQueryValues extends MapQueryValues { @override Map get casts { - return {'price': 'double precision'}; + return {}; } String? get id { @@ -333,10 +395,10 @@ class OrderWithPersonInfoQueryValues extends MapQueryValues { set name(String? value) => values['name'] = value; double? get price { - return double.tryParse((values['price'] as String)) ?? 0.0; + return (values['price'] as double?) ?? 0.0; } - set price(double? value) => values['price'] = value.toString(); + set price(double? value) => values['price'] = value; bool? get deleted { return (values['deleted'] as bool?); } @@ -357,14 +419,15 @@ class OrderWithPersonInfoQueryValues extends MapQueryValues { @generatedSerializable class PersonOrder extends _PersonOrder { - PersonOrder( - {this.id, - this.createdAt, - this.updatedAt, - this.personId, - this.name, - this.price, - this.deleted}); + PersonOrder({ + this.id, + this.createdAt, + this.updatedAt, + this.personId, + this.name, + this.price, + this.deleted, + }); /// A unique identifier corresponding to this item. @override @@ -390,14 +453,15 @@ class PersonOrder extends _PersonOrder { @override bool? deleted; - PersonOrder copyWith( - {String? id, - DateTime? createdAt, - DateTime? updatedAt, - int? personId, - String? name, - double? price, - bool? deleted}) { + PersonOrder copyWith({ + String? id, + DateTime? createdAt, + DateTime? updatedAt, + int? personId, + String? name, + double? price, + bool? deleted, + }) { return PersonOrder( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -422,8 +486,15 @@ class PersonOrder extends _PersonOrder { @override int get hashCode { - return hashObjects( - [id, createdAt, updatedAt, personId, name, price, deleted]); + return hashObjects([ + id, + createdAt, + updatedAt, + personId, + name, + price, + deleted, + ]); } @override @@ -438,15 +509,16 @@ class PersonOrder extends _PersonOrder { @generatedSerializable class OrderWithPersonInfo extends _OrderWithPersonInfo { - OrderWithPersonInfo( - {this.id, - this.createdAt, - this.updatedAt, - this.name, - this.price, - this.deleted, - this.personName, - this.personAge}); + OrderWithPersonInfo({ + this.id, + this.createdAt, + this.updatedAt, + this.name, + this.price, + this.deleted, + this.personName, + this.personAge, + }); /// A unique identifier corresponding to this item. @override @@ -475,15 +547,16 @@ class OrderWithPersonInfo extends _OrderWithPersonInfo { @override int? personAge; - OrderWithPersonInfo copyWith( - {String? id, - DateTime? createdAt, - DateTime? updatedAt, - String? name, - double? price, - bool? deleted, - String? personName, - int? personAge}) { + OrderWithPersonInfo copyWith({ + String? id, + DateTime? createdAt, + DateTime? updatedAt, + String? name, + double? price, + bool? deleted, + String? personName, + int? personAge, + }) { return OrderWithPersonInfo( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -518,7 +591,7 @@ class OrderWithPersonInfo extends _OrderWithPersonInfo { price, deleted, personName, - personAge + personAge, ]); } @@ -602,7 +675,7 @@ abstract class PersonOrderFields { personId, name, price, - deleted + deleted, ]; static const String id = 'id'; @@ -692,7 +765,7 @@ abstract class OrderWithPersonInfoFields { price, deleted, personName, - personAge + personAge, ]; static const String id = 'id'; diff --git a/packages/orm/angel_orm_test/lib/src/models/tree.g.dart b/packages/orm/angel_orm_test/lib/src/models/tree.g.dart index 1555e35e..ac97a8ae 100644 --- a/packages/orm/angel_orm_test/lib/src/models/tree.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/tree.g.dart @@ -9,30 +9,42 @@ part of angel3_orm_generator.test.models.tree; class TreeMigration extends Migration { @override void up(Schema schema) { - schema.create('trees', (table) { - table.serial('id').primaryKey(); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - table.integer('rings').unique(); - }); + schema.create( + 'trees', + (table) { + table.serial('id').primaryKey(); + table.timeStamp('created_at'); + table.timeStamp('updated_at'); + table.integer('rings').unique(); + }, + ); } @override void down(Schema schema) { - schema.drop('trees', cascade: true); + schema.drop( + 'trees', + cascade: true, + ); } } class FruitMigration extends Migration { @override void up(Schema schema) { - schema.create('fruits', (table) { - table.serial('id').primaryKey(); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - table.integer('tree_id'); - table.varChar('common_name', length: 255); - }); + schema.create( + 'fruits', + (table) { + table.serial('id').primaryKey(); + table.timeStamp('created_at'); + table.timeStamp('updated_at'); + table.integer('tree_id'); + table.varChar( + 'common_name', + length: 255, + ); + }, + ); } @override @@ -46,20 +58,29 @@ class FruitMigration extends Migration { // ************************************************************************** class TreeQuery extends Query { - TreeQuery({Query? parent, Set? trampoline}) : super(parent: parent) { + TreeQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = TreeQueryWhere(this); - leftJoin(_fruits = FruitQuery(trampoline: trampoline, parent: this), 'id', + leftJoin( + _fruits = FruitQuery( + trampoline: trampoline, + parent: this, + ), + 'id', + 'tree_id', + additionalFields: const [ + 'id', + 'created_at', + 'updated_at', 'tree_id', - additionalFields: const [ - 'id', - 'created_at', - 'updated_at', - 'tree_id', - 'common_name' - ], - trampoline: trampoline); + 'common_name', + ], + trampoline: trampoline, + ); } @override @@ -83,7 +104,12 @@ class TreeQuery extends Query { @override List get fields { - const _fields = ['id', 'created_at', 'updated_at', 'rings']; + const _fields = [ + 'id', + 'created_at', + 'updated_at', + 'rings', + ]; return _selectedFields.isEmpty ? _fields : _fields.where((field) => _selectedFields.contains(field)).toList(); @@ -109,14 +135,13 @@ class TreeQuery extends Query { return Optional.empty(); } var model = Tree( - id: fields.contains('id') ? row[0].toString() : null, - createdAt: fields.contains('created_at') - ? mapToNullableDateTime(row[1]) - : null, - updatedAt: fields.contains('updated_at') - ? mapToNullableDateTime(row[2]) - : null, - rings: fields.contains('rings') ? (row[3] as int?) : null); + id: fields.contains('id') ? row[0].toString() : null, + createdAt: + fields.contains('created_at') ? mapToNullableDateTime(row[1]) : null, + updatedAt: + fields.contains('updated_at') ? mapToNullableDateTime(row[2]) : null, + rings: fields.contains('rings') ? (row[3] as int?) : null, + ); if (row.length > 4) { var modelOpt = FruitQuery().parseRow(row.skip(4).take(5).toList()); modelOpt.ifPresent((m) { @@ -192,10 +217,22 @@ class TreeQuery extends Query { class TreeQueryWhere extends QueryWhere { TreeQueryWhere(TreeQuery query) - : id = NumericSqlExpressionBuilder(query, 'id'), - createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'), - rings = NumericSqlExpressionBuilder(query, 'rings'); + : id = NumericSqlExpressionBuilder( + query, + 'id', + ), + createdAt = DateTimeSqlExpressionBuilder( + query, + 'created_at', + ), + updatedAt = DateTimeSqlExpressionBuilder( + query, + 'updated_at', + ), + rings = NumericSqlExpressionBuilder( + query, + 'rings', + ); final NumericSqlExpressionBuilder id; @@ -207,7 +244,12 @@ class TreeQueryWhere extends QueryWhere { @override List get expressionBuilders { - return [id, createdAt, updatedAt, rings]; + return [ + id, + createdAt, + updatedAt, + rings, + ]; } } @@ -245,7 +287,10 @@ class TreeQueryValues extends MapQueryValues { } class FruitQuery extends Query { - FruitQuery({Query? parent, Set? trampoline}) : super(parent: parent) { + FruitQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = FruitQueryWhere(this); @@ -275,7 +320,7 @@ class FruitQuery extends Query { 'created_at', 'updated_at', 'tree_id', - 'common_name' + 'common_name', ]; return _selectedFields.isEmpty ? _fields @@ -302,16 +347,14 @@ class FruitQuery extends Query { return Optional.empty(); } var model = Fruit( - id: fields.contains('id') ? row[0].toString() : null, - createdAt: fields.contains('created_at') - ? mapToNullableDateTime(row[1]) - : null, - updatedAt: fields.contains('updated_at') - ? mapToNullableDateTime(row[2]) - : null, - treeId: fields.contains('tree_id') ? (row[3] as int?) : null, - commonName: - fields.contains('common_name') ? (row[4] as String?) : null); + id: fields.contains('id') ? row[0].toString() : null, + createdAt: + fields.contains('created_at') ? mapToNullableDateTime(row[1]) : null, + updatedAt: + fields.contains('updated_at') ? mapToNullableDateTime(row[2]) : null, + treeId: fields.contains('tree_id') ? (row[3] as int?) : null, + commonName: fields.contains('common_name') ? (row[4] as String?) : null, + ); return Optional.of(model); } @@ -323,11 +366,26 @@ class FruitQuery extends Query { class FruitQueryWhere extends QueryWhere { FruitQueryWhere(FruitQuery query) - : id = NumericSqlExpressionBuilder(query, 'id'), - createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'), - treeId = NumericSqlExpressionBuilder(query, 'tree_id'), - commonName = StringSqlExpressionBuilder(query, 'common_name'); + : id = NumericSqlExpressionBuilder( + query, + 'id', + ), + createdAt = DateTimeSqlExpressionBuilder( + query, + 'created_at', + ), + updatedAt = DateTimeSqlExpressionBuilder( + query, + 'updated_at', + ), + treeId = NumericSqlExpressionBuilder( + query, + 'tree_id', + ), + commonName = StringSqlExpressionBuilder( + query, + 'common_name', + ); final NumericSqlExpressionBuilder id; @@ -341,7 +399,13 @@ class FruitQueryWhere extends QueryWhere { @override List get expressionBuilders { - return [id, createdAt, updatedAt, treeId, commonName]; + return [ + id, + createdAt, + updatedAt, + treeId, + commonName, + ]; } } @@ -390,13 +454,13 @@ class FruitQueryValues extends MapQueryValues { @generatedSerializable class Tree extends _Tree { - Tree( - {this.id, - this.createdAt, - this.updatedAt, - this.rings, - List<_Fruit> fruits = const []}) - : fruits = List.unmodifiable(fruits); + Tree({ + this.id, + this.createdAt, + this.updatedAt, + this.rings, + List<_Fruit> fruits = const [], + }) : fruits = List.unmodifiable(fruits); /// A unique identifier corresponding to this item. @override @@ -416,12 +480,13 @@ class Tree extends _Tree { @override List<_Fruit> fruits; - Tree copyWith( - {String? id, - DateTime? createdAt, - DateTime? updatedAt, - int? rings, - List<_Fruit>? fruits}) { + Tree copyWith({ + String? id, + DateTime? createdAt, + DateTime? updatedAt, + int? rings, + List<_Fruit>? fruits, + }) { return Tree( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -443,7 +508,13 @@ class Tree extends _Tree { @override int get hashCode { - return hashObjects([id, createdAt, updatedAt, rings, fruits]); + return hashObjects([ + id, + createdAt, + updatedAt, + rings, + fruits, + ]); } @override @@ -458,8 +529,13 @@ class Tree extends _Tree { @generatedSerializable class Fruit extends _Fruit { - Fruit( - {this.id, this.createdAt, this.updatedAt, this.treeId, this.commonName}); + Fruit({ + this.id, + this.createdAt, + this.updatedAt, + this.treeId, + this.commonName, + }); /// A unique identifier corresponding to this item. @override @@ -479,12 +555,13 @@ class Fruit extends _Fruit { @override String? commonName; - Fruit copyWith( - {String? id, - DateTime? createdAt, - DateTime? updatedAt, - int? treeId, - String? commonName}) { + Fruit copyWith({ + String? id, + DateTime? createdAt, + DateTime? updatedAt, + int? treeId, + String? commonName, + }) { return Fruit( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -505,7 +582,13 @@ class Fruit extends _Fruit { @override int get hashCode { - return hashObjects([id, createdAt, updatedAt, treeId, commonName]); + return hashObjects([ + id, + createdAt, + updatedAt, + treeId, + commonName, + ]); } @override @@ -585,7 +668,7 @@ abstract class TreeFields { createdAt, updatedAt, rings, - fruits + fruits, ]; static const String id = 'id'; @@ -659,7 +742,7 @@ abstract class FruitFields { createdAt, updatedAt, treeId, - commonName + commonName, ]; static const String id = 'id'; diff --git a/packages/orm/angel_orm_test/lib/src/models/unorthodox.g.dart b/packages/orm/angel_orm_test/lib/src/models/unorthodox.g.dart index cbdfa9bc..6c26cbbd 100644 --- a/packages/orm/angel_orm_test/lib/src/models/unorthodox.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/unorthodox.g.dart @@ -9,9 +9,17 @@ part of 'unorthodox.dart'; class UnorthodoxMigration extends Migration { @override void up(Schema schema) { - schema.create('unorthodoxes', (table) { - table.varChar('name', length: 255).primaryKey(); - }); + schema.create( + 'unorthodoxes', + (table) { + table + .varChar( + 'name', + length: 255, + ) + .primaryKey(); + }, + ); } @override @@ -23,30 +31,48 @@ class UnorthodoxMigration extends Migration { class WeirdJoinMigration extends Migration { @override void up(Schema schema) { - schema.create('weird_joins', (table) { - table.integer('id').primaryKey(); - table - .declare('join_name', ColumnType('varchar')) - .references('unorthodoxes', 'name'); - }); + schema.create( + 'weird_joins', + (table) { + table.integer('id').primaryKey(); + table + .declare( + 'join_name', + ColumnType('varchar'), + ) + .references( + 'unorthodoxes', + 'name', + ); + }, + ); } @override void down(Schema schema) { - schema.drop('weird_joins', cascade: true); + schema.drop( + 'weird_joins', + cascade: true, + ); } } class SongMigration extends Migration { @override void up(Schema schema) { - schema.create('songs', (table) { - table.serial('id').primaryKey(); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - table.integer('weird_join_id'); - table.varChar('title', length: 255); - }); + schema.create( + 'songs', + (table) { + table.serial('id').primaryKey(); + table.timeStamp('created_at'); + table.timeStamp('updated_at'); + table.integer('weird_join_id'); + table.varChar( + 'title', + length: 255, + ); + }, + ); } @override @@ -58,10 +84,13 @@ class SongMigration extends Migration { class NumbaMigration extends Migration { @override void up(Schema schema) { - schema.create('numbas', (table) { - table.integer('i').primaryKey(); - table.integer('parent'); - }); + schema.create( + 'numbas', + (table) { + table.integer('i').primaryKey(); + table.integer('parent'); + }, + ); } @override @@ -73,26 +102,54 @@ class NumbaMigration extends Migration { class FooMigration extends Migration { @override void up(Schema schema) { - schema.create('foos', (table) { - table.varChar('bar', length: 255).primaryKey(); - }); + schema.create( + 'foos', + (table) { + table + .varChar( + 'bar', + length: 255, + ) + .primaryKey(); + }, + ); } @override void down(Schema schema) { - schema.drop('foos', cascade: true); + schema.drop( + 'foos', + cascade: true, + ); } } class FooPivotMigration extends Migration { @override void up(Schema schema) { - schema.create('foo_pivots', (table) { - table - .declare('weird_join_id', ColumnType('int')) - .references('weird_joins', 'id'); - table.declare('foo_bar', ColumnType('varchar')).references('foos', 'bar'); - }); + schema.create( + 'foo_pivots', + (table) { + table + .declare( + 'weird_join_id', + ColumnType('int'), + ) + .references( + 'weird_joins', + 'id', + ); + table + .declare( + 'foo_bar', + ColumnType('varchar'), + ) + .references( + 'foos', + 'bar', + ); + }, + ); } @override @@ -106,8 +163,10 @@ class FooPivotMigration extends Migration { // ************************************************************************** class UnorthodoxQuery extends Query { - UnorthodoxQuery({Query? parent, Set? trampoline}) - : super(parent: parent) { + UnorthodoxQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = UnorthodoxQueryWhere(this); @@ -170,7 +229,10 @@ class UnorthodoxQuery extends Query { class UnorthodoxQueryWhere extends QueryWhere { UnorthodoxQueryWhere(UnorthodoxQuery query) - : name = StringSqlExpressionBuilder(query, 'name'); + : name = StringSqlExpressionBuilder( + query, + 'name', + ); final StringSqlExpressionBuilder name; @@ -197,36 +259,59 @@ class UnorthodoxQueryValues extends MapQueryValues { } class WeirdJoinQuery extends Query { - WeirdJoinQuery({Query? parent, Set? trampoline}) - : super(parent: parent) { + WeirdJoinQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = WeirdJoinQueryWhere(this); leftJoin( - _unorthodox = UnorthodoxQuery(trampoline: trampoline, parent: this), - 'join_name', - 'name', - additionalFields: const ['name'], - trampoline: trampoline); - leftJoin(_song = SongQuery(trampoline: trampoline, parent: this), 'id', - 'weird_join_id', - additionalFields: const [ - 'id', - 'created_at', - 'updated_at', - 'weird_join_id', - 'title' - ], - trampoline: trampoline); - leftJoin(_numbas = NumbaQuery(trampoline: trampoline, parent: this), 'id', - 'parent', - additionalFields: const ['i', 'parent'], trampoline: trampoline); + _unorthodox = UnorthodoxQuery( + trampoline: trampoline, + parent: this, + ), + 'join_name', + 'name', + additionalFields: const ['name'], + trampoline: trampoline, + ); leftJoin( - '(SELECT foo_pivots.weird_join_id, foos.bar FROM foos LEFT JOIN foo_pivots ON foo_pivots.foo_bar=foos.bar)', + _song = SongQuery( + trampoline: trampoline, + parent: this, + ), + 'id', + 'weird_join_id', + additionalFields: const [ 'id', + 'created_at', + 'updated_at', 'weird_join_id', - additionalFields: const ['bar'], - trampoline: trampoline); + 'title', + ], + trampoline: trampoline, + ); + leftJoin( + _numbas = NumbaQuery( + trampoline: trampoline, + parent: this, + ), + 'id', + 'parent', + additionalFields: const [ + 'i', + 'parent', + ], + trampoline: trampoline, + ); + leftJoin( + '(SELECT foo_pivots.weird_join_id, foos.bar FROM foos LEFT JOIN foo_pivots ON foo_pivots.foo_bar=foos.bar)', + 'id', + 'weird_join_id', + additionalFields: const ['bar'], + trampoline: trampoline, + ); } @override @@ -254,7 +339,10 @@ class WeirdJoinQuery extends Query { @override List get fields { - const _fields = ['id', 'join_name']; + const _fields = [ + 'id', + 'join_name', + ]; return _selectedFields.isEmpty ? _fields : _fields.where((field) => _selectedFields.contains(field)).toList(); @@ -390,8 +478,14 @@ class WeirdJoinQuery extends Query { class WeirdJoinQueryWhere extends QueryWhere { WeirdJoinQueryWhere(WeirdJoinQuery query) - : id = NumericSqlExpressionBuilder(query, 'id'), - joinName = StringSqlExpressionBuilder(query, 'join_name'); + : id = NumericSqlExpressionBuilder( + query, + 'id', + ), + joinName = StringSqlExpressionBuilder( + query, + 'join_name', + ); final NumericSqlExpressionBuilder id; @@ -399,7 +493,10 @@ class WeirdJoinQueryWhere extends QueryWhere { @override List get expressionBuilders { - return [id, joinName]; + return [ + id, + joinName, + ]; } } @@ -428,7 +525,10 @@ class WeirdJoinQueryValues extends MapQueryValues { } class SongQuery extends Query { - SongQuery({Query? parent, Set? trampoline}) : super(parent: parent) { + SongQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = SongQueryWhere(this); @@ -458,7 +558,7 @@ class SongQuery extends Query { 'created_at', 'updated_at', 'weird_join_id', - 'title' + 'title', ]; return _selectedFields.isEmpty ? _fields @@ -485,15 +585,14 @@ class SongQuery extends Query { return Optional.empty(); } var model = Song( - id: fields.contains('id') ? row[0].toString() : null, - createdAt: fields.contains('created_at') - ? mapToNullableDateTime(row[1]) - : null, - updatedAt: fields.contains('updated_at') - ? mapToNullableDateTime(row[2]) - : null, - weirdJoinId: fields.contains('weird_join_id') ? (row[3] as int?) : null, - title: fields.contains('title') ? (row[4] as String?) : null); + id: fields.contains('id') ? row[0].toString() : null, + createdAt: + fields.contains('created_at') ? mapToNullableDateTime(row[1]) : null, + updatedAt: + fields.contains('updated_at') ? mapToNullableDateTime(row[2]) : null, + weirdJoinId: fields.contains('weird_join_id') ? (row[3] as int?) : null, + title: fields.contains('title') ? (row[4] as String?) : null, + ); return Optional.of(model); } @@ -505,11 +604,26 @@ class SongQuery extends Query { class SongQueryWhere extends QueryWhere { SongQueryWhere(SongQuery query) - : id = NumericSqlExpressionBuilder(query, 'id'), - createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'), - weirdJoinId = NumericSqlExpressionBuilder(query, 'weird_join_id'), - title = StringSqlExpressionBuilder(query, 'title'); + : id = NumericSqlExpressionBuilder( + query, + 'id', + ), + createdAt = DateTimeSqlExpressionBuilder( + query, + 'created_at', + ), + updatedAt = DateTimeSqlExpressionBuilder( + query, + 'updated_at', + ), + weirdJoinId = NumericSqlExpressionBuilder( + query, + 'weird_join_id', + ), + title = StringSqlExpressionBuilder( + query, + 'title', + ); final NumericSqlExpressionBuilder id; @@ -523,7 +637,13 @@ class SongQueryWhere extends QueryWhere { @override List get expressionBuilders { - return [id, createdAt, updatedAt, weirdJoinId, title]; + return [ + id, + createdAt, + updatedAt, + weirdJoinId, + title, + ]; } } @@ -567,7 +687,10 @@ class SongQueryValues extends MapQueryValues { } class NumbaQuery extends Query { - NumbaQuery({Query? parent, Set? trampoline}) : super(parent: parent) { + NumbaQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = NumbaQueryWhere(this); @@ -592,7 +715,10 @@ class NumbaQuery extends Query { @override List get fields { - const _fields = ['i', 'parent']; + const _fields = [ + 'i', + 'parent', + ]; return _selectedFields.isEmpty ? _fields : _fields.where((field) => _selectedFields.contains(field)).toList(); @@ -618,8 +744,9 @@ class NumbaQuery extends Query { return Optional.empty(); } var model = Numba( - i: fields.contains('i') ? (row[0] as int?) : null, - parent: fields.contains('parent') ? (row[1] as int?) : null); + i: fields.contains('i') ? (row[0] as int?) : null, + parent: fields.contains('parent') ? (row[1] as int?) : null, + ); return Optional.of(model); } @@ -631,8 +758,14 @@ class NumbaQuery extends Query { class NumbaQueryWhere extends QueryWhere { NumbaQueryWhere(NumbaQuery query) - : i = NumericSqlExpressionBuilder(query, 'i'), - parent = NumericSqlExpressionBuilder(query, 'parent'); + : i = NumericSqlExpressionBuilder( + query, + 'i', + ), + parent = NumericSqlExpressionBuilder( + query, + 'parent', + ); final NumericSqlExpressionBuilder i; @@ -640,7 +773,10 @@ class NumbaQueryWhere extends QueryWhere { @override List get expressionBuilders { - return [i, parent]; + return [ + i, + parent, + ]; } } @@ -667,16 +803,23 @@ class NumbaQueryValues extends MapQueryValues { } class FooQuery extends Query { - FooQuery({Query? parent, Set? trampoline}) : super(parent: parent) { + FooQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = FooQueryWhere(this); leftJoin( - '(SELECT foo_pivots.foo_bar, weird_joins.id, weird_joins.join_name FROM weird_joins LEFT JOIN foo_pivots ON foo_pivots.weird_join_id=weird_joins.id)', - 'bar', - 'foo_bar', - additionalFields: const ['id', 'join_name'], - trampoline: trampoline); + '(SELECT foo_pivots.foo_bar, weird_joins.id, weird_joins.join_name FROM weird_joins LEFT JOIN foo_pivots ON foo_pivots.weird_join_id=weird_joins.id)', + 'bar', + 'foo_bar', + additionalFields: const [ + 'id', + 'join_name', + ], + trampoline: trampoline, + ); } @override @@ -804,7 +947,10 @@ class FooQuery extends Query { class FooQueryWhere extends QueryWhere { FooQueryWhere(FooQuery query) - : bar = StringSqlExpressionBuilder(query, 'bar'); + : bar = StringSqlExpressionBuilder( + query, + 'bar', + ); final StringSqlExpressionBuilder bar; @@ -831,17 +977,36 @@ class FooQueryValues extends MapQueryValues { } class FooPivotQuery extends Query { - FooPivotQuery({Query? parent, Set? trampoline}) - : super(parent: parent) { + FooPivotQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = FooPivotQueryWhere(this); - leftJoin(_weirdJoin = WeirdJoinQuery(trampoline: trampoline, parent: this), - 'weird_join_id', 'id', - additionalFields: const ['id', 'join_name'], trampoline: trampoline); leftJoin( - _foo = FooQuery(trampoline: trampoline, parent: this), 'foo_bar', 'bar', - additionalFields: const ['bar'], trampoline: trampoline); + _weirdJoin = WeirdJoinQuery( + trampoline: trampoline, + parent: this, + ), + 'weird_join_id', + 'id', + additionalFields: const [ + 'id', + 'join_name', + ], + trampoline: trampoline, + ); + leftJoin( + _foo = FooQuery( + trampoline: trampoline, + parent: this, + ), + 'foo_bar', + 'bar', + additionalFields: const ['bar'], + trampoline: trampoline, + ); } @override @@ -867,7 +1032,10 @@ class FooPivotQuery extends Query { @override List get fields { - const _fields = ['weird_join_id', 'foo_bar']; + const _fields = [ + 'weird_join_id', + 'foo_bar', + ]; return _selectedFields.isEmpty ? _fields : _fields.where((field) => _selectedFields.contains(field)).toList(); @@ -924,8 +1092,14 @@ class FooPivotQuery extends Query { class FooPivotQueryWhere extends QueryWhere { FooPivotQueryWhere(FooPivotQuery query) - : weirdJoinId = NumericSqlExpressionBuilder(query, 'weird_join_id'), - fooBar = StringSqlExpressionBuilder(query, 'foo_bar'); + : weirdJoinId = NumericSqlExpressionBuilder( + query, + 'weird_join_id', + ), + fooBar = StringSqlExpressionBuilder( + query, + 'foo_bar', + ); final NumericSqlExpressionBuilder weirdJoinId; @@ -933,7 +1107,10 @@ class FooPivotQueryWhere extends QueryWhere { @override List get expressionBuilders { - return [weirdJoinId, fooBar]; + return [ + weirdJoinId, + fooBar, + ]; } } @@ -1000,12 +1177,13 @@ class Unorthodox implements _Unorthodox { @generatedSerializable class WeirdJoin implements _WeirdJoin { - WeirdJoin( - {this.id, - this.unorthodox, - this.song, - this.numbas = const [], - this.foos = const []}); + WeirdJoin({ + this.id, + this.unorthodox, + this.song, + this.numbas = const [], + this.foos = const [], + }); @override int? id; @@ -1022,12 +1200,13 @@ class WeirdJoin implements _WeirdJoin { @override List<_Foo> foos; - WeirdJoin copyWith( - {int? id, - _Unorthodox? unorthodox, - _Song? song, - List<_Numba>? numbas, - List<_Foo>? foos}) { + WeirdJoin copyWith({ + int? id, + _Unorthodox? unorthodox, + _Song? song, + List<_Numba>? numbas, + List<_Foo>? foos, + }) { return WeirdJoin( id: id ?? this.id, unorthodox: unorthodox ?? this.unorthodox, @@ -1049,7 +1228,13 @@ class WeirdJoin implements _WeirdJoin { @override int get hashCode { - return hashObjects([id, unorthodox, song, numbas, foos]); + return hashObjects([ + id, + unorthodox, + song, + numbas, + foos, + ]); } @override @@ -1064,7 +1249,13 @@ class WeirdJoin implements _WeirdJoin { @generatedSerializable class Song extends _Song { - Song({this.id, this.createdAt, this.updatedAt, this.weirdJoinId, this.title}); + Song({ + this.id, + this.createdAt, + this.updatedAt, + this.weirdJoinId, + this.title, + }); /// A unique identifier corresponding to this item. @override @@ -1084,12 +1275,13 @@ class Song extends _Song { @override String? title; - Song copyWith( - {String? id, - DateTime? createdAt, - DateTime? updatedAt, - int? weirdJoinId, - String? title}) { + Song copyWith({ + String? id, + DateTime? createdAt, + DateTime? updatedAt, + int? weirdJoinId, + String? title, + }) { return Song( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -1110,7 +1302,13 @@ class Song extends _Song { @override int get hashCode { - return hashObjects([id, createdAt, updatedAt, weirdJoinId, title]); + return hashObjects([ + id, + createdAt, + updatedAt, + weirdJoinId, + title, + ]); } @override @@ -1125,7 +1323,10 @@ class Song extends _Song { @generatedSerializable class Numba extends _Numba { - Numba({this.i, this.parent}); + Numba({ + this.i, + this.parent, + }); @override int? i; @@ -1133,7 +1334,10 @@ class Numba extends _Numba { @override int? parent; - Numba copyWith({int? i, int? parent}) { + Numba copyWith({ + int? i, + int? parent, + }) { return Numba(i: i ?? this.i, parent: parent ?? this.parent); } @@ -1144,7 +1348,10 @@ class Numba extends _Numba { @override int get hashCode { - return hashObjects([i, parent]); + return hashObjects([ + i, + parent, + ]); } @override @@ -1159,7 +1366,10 @@ class Numba extends _Numba { @generatedSerializable class Foo implements _Foo { - Foo({this.bar, this.weirdJoins = const []}); + Foo({ + this.bar, + this.weirdJoins = const [], + }); @override String? bar; @@ -1167,7 +1377,10 @@ class Foo implements _Foo { @override List<_WeirdJoin> weirdJoins; - Foo copyWith({String? bar, List<_WeirdJoin>? weirdJoins}) { + Foo copyWith({ + String? bar, + List<_WeirdJoin>? weirdJoins, + }) { return Foo(bar: bar ?? this.bar, weirdJoins: weirdJoins ?? this.weirdJoins); } @@ -1181,7 +1394,10 @@ class Foo implements _Foo { @override int get hashCode { - return hashObjects([bar, weirdJoins]); + return hashObjects([ + bar, + weirdJoins, + ]); } @override @@ -1196,7 +1412,10 @@ class Foo implements _Foo { @generatedSerializable class FooPivot implements _FooPivot { - FooPivot({this.weirdJoin, this.foo}); + FooPivot({ + this.weirdJoin, + this.foo, + }); @override _WeirdJoin? weirdJoin; @@ -1204,7 +1423,10 @@ class FooPivot implements _FooPivot { @override _Foo? foo; - FooPivot copyWith({_WeirdJoin? weirdJoin, _Foo? foo}) { + FooPivot copyWith({ + _WeirdJoin? weirdJoin, + _Foo? foo, + }) { return FooPivot( weirdJoin: weirdJoin ?? this.weirdJoin, foo: foo ?? this.foo); } @@ -1218,7 +1440,10 @@ class FooPivot implements _FooPivot { @override int get hashCode { - return hashObjects([weirdJoin, foo]); + return hashObjects([ + weirdJoin, + foo, + ]); } @override @@ -1338,7 +1563,7 @@ abstract class WeirdJoinFields { unorthodox, song, numbas, - foos + foos, ]; static const String id = 'id'; @@ -1412,7 +1637,7 @@ abstract class SongFields { createdAt, updatedAt, weirdJoinId, - title + title, ]; static const String id = 'id'; @@ -1462,7 +1687,10 @@ class NumbaSerializer extends Codec { } abstract class NumbaFields { - static const List allFields = [i, parent]; + static const List allFields = [ + i, + parent, + ]; static const String i = 'i'; @@ -1515,7 +1743,10 @@ class FooSerializer extends Codec { } abstract class FooFields { - static const List allFields = [bar, weirdJoins]; + static const List allFields = [ + bar, + weirdJoins, + ]; static const String bar = 'bar'; @@ -1567,7 +1798,10 @@ class FooPivotSerializer extends Codec { } abstract class FooPivotFields { - static const List allFields = [weirdJoin, foo]; + static const List allFields = [ + weirdJoin, + foo, + ]; static const String weirdJoin = 'weird_join'; diff --git a/packages/orm/angel_orm_test/lib/src/models/user.g.dart b/packages/orm/angel_orm_test/lib/src/models/user.g.dart index d9bc91a4..b6bff054 100644 --- a/packages/orm/angel_orm_test/lib/src/models/user.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/user.g.dart @@ -9,29 +9,63 @@ part of angel3_orm_generator.test.models.user; class UserMigration extends Migration { @override void up(Schema schema) { - schema.create('users', (table) { - table.serial('id').primaryKey(); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - table.varChar('username', length: 255); - table.varChar('password', length: 255); - table.varChar('email', length: 255); - }); + schema.create( + 'users', + (table) { + table.serial('id').primaryKey(); + table.timeStamp('created_at'); + table.timeStamp('updated_at'); + table.varChar( + 'username', + length: 255, + ); + table.varChar( + 'password', + length: 255, + ); + table.varChar( + 'email', + length: 255, + ); + }, + ); } @override void down(Schema schema) { - schema.drop('users', cascade: true); + schema.drop( + 'users', + cascade: true, + ); } } class RoleUserMigration extends Migration { @override void up(Schema schema) { - schema.create('role_users', (table) { - table.declare('role_id', ColumnType('int')).references('roles', 'id'); - table.declare('user_id', ColumnType('int')).references('users', 'id'); - }); + schema.create( + 'role_users', + (table) { + table + .declare( + 'role_id', + ColumnType('int'), + ) + .references( + 'roles', + 'id', + ); + table + .declare( + 'user_id', + ColumnType('int'), + ) + .references( + 'users', + 'id', + ); + }, + ); } @override @@ -43,17 +77,26 @@ class RoleUserMigration extends Migration { class RoleMigration extends Migration { @override void up(Schema schema) { - schema.create('roles', (table) { - table.serial('id').primaryKey(); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - table.varChar('name', length: 255); - }); + schema.create( + 'roles', + (table) { + table.serial('id').primaryKey(); + table.timeStamp('created_at'); + table.timeStamp('updated_at'); + table.varChar( + 'name', + length: 255, + ); + }, + ); } @override void down(Schema schema) { - schema.drop('roles', cascade: true); + schema.drop( + 'roles', + cascade: true, + ); } } @@ -62,16 +105,25 @@ class RoleMigration extends Migration { // ************************************************************************** class UserQuery extends Query { - UserQuery({Query? parent, Set? trampoline}) : super(parent: parent) { + UserQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = UserQueryWhere(this); leftJoin( - '(SELECT role_users.user_id, roles.id, roles.created_at, roles.updated_at, roles.name FROM roles LEFT JOIN role_users ON role_users.role_id=roles.id)', + '(SELECT role_users.user_id, roles.id, roles.created_at, roles.updated_at, roles.name FROM roles LEFT JOIN role_users ON role_users.role_id=roles.id)', + 'id', + 'user_id', + additionalFields: const [ 'id', - 'user_id', - additionalFields: const ['id', 'created_at', 'updated_at', 'name'], - trampoline: trampoline); + 'created_at', + 'updated_at', + 'name', + ], + trampoline: trampoline, + ); } @override @@ -99,7 +151,7 @@ class UserQuery extends Query { 'updated_at', 'username', 'password', - 'email' + 'email', ]; return _selectedFields.isEmpty ? _fields @@ -126,16 +178,15 @@ class UserQuery extends Query { return Optional.empty(); } var model = User( - id: fields.contains('id') ? row[0].toString() : null, - createdAt: fields.contains('created_at') - ? mapToNullableDateTime(row[1]) - : null, - updatedAt: fields.contains('updated_at') - ? mapToNullableDateTime(row[2]) - : null, - username: fields.contains('username') ? (row[3] as String?) : null, - password: fields.contains('password') ? (row[4] as String?) : null, - email: fields.contains('email') ? (row[5] as String?) : null); + id: fields.contains('id') ? row[0].toString() : null, + createdAt: + fields.contains('created_at') ? mapToNullableDateTime(row[1]) : null, + updatedAt: + fields.contains('updated_at') ? mapToNullableDateTime(row[2]) : null, + username: fields.contains('username') ? (row[3] as String?) : null, + password: fields.contains('password') ? (row[4] as String?) : null, + email: fields.contains('email') ? (row[5] as String?) : null, + ); if (row.length > 6) { var modelOpt = RoleQuery().parseRow(row.skip(6).take(4).toList()); modelOpt.ifPresent((m) { @@ -213,12 +264,30 @@ class UserQuery extends Query { class UserQueryWhere extends QueryWhere { UserQueryWhere(UserQuery query) - : id = NumericSqlExpressionBuilder(query, 'id'), - createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'), - username = StringSqlExpressionBuilder(query, 'username'), - password = StringSqlExpressionBuilder(query, 'password'), - email = StringSqlExpressionBuilder(query, 'email'); + : id = NumericSqlExpressionBuilder( + query, + 'id', + ), + createdAt = DateTimeSqlExpressionBuilder( + query, + 'created_at', + ), + updatedAt = DateTimeSqlExpressionBuilder( + query, + 'updated_at', + ), + username = StringSqlExpressionBuilder( + query, + 'username', + ), + password = StringSqlExpressionBuilder( + query, + 'password', + ), + email = StringSqlExpressionBuilder( + query, + 'email', + ); final NumericSqlExpressionBuilder id; @@ -234,7 +303,14 @@ class UserQueryWhere extends QueryWhere { @override List get expressionBuilders { - return [id, createdAt, updatedAt, username, password, email]; + return [ + id, + createdAt, + updatedAt, + username, + password, + email, + ]; } } @@ -284,26 +360,45 @@ class UserQueryValues extends MapQueryValues { } class RoleUserQuery extends Query { - RoleUserQuery({Query? parent, Set? trampoline}) - : super(parent: parent) { + RoleUserQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = RoleUserQueryWhere(this); - leftJoin(_role = RoleQuery(trampoline: trampoline, parent: this), 'role_id', + leftJoin( + _role = RoleQuery( + trampoline: trampoline, + parent: this, + ), + 'role_id', + 'id', + additionalFields: const [ 'id', - additionalFields: const ['id', 'created_at', 'updated_at', 'name'], - trampoline: trampoline); - leftJoin(_user = UserQuery(trampoline: trampoline, parent: this), 'user_id', + 'created_at', + 'updated_at', + 'name', + ], + trampoline: trampoline, + ); + leftJoin( + _user = UserQuery( + trampoline: trampoline, + parent: this, + ), + 'user_id', + 'id', + additionalFields: const [ 'id', - additionalFields: const [ - 'id', - 'created_at', - 'updated_at', - 'username', - 'password', - 'email' - ], - trampoline: trampoline); + 'created_at', + 'updated_at', + 'username', + 'password', + 'email', + ], + trampoline: trampoline, + ); } @override @@ -329,7 +424,10 @@ class RoleUserQuery extends Query { @override List get fields { - const _fields = ['role_id', 'user_id']; + const _fields = [ + 'role_id', + 'user_id', + ]; return _selectedFields.isEmpty ? _fields : _fields.where((field) => _selectedFields.contains(field)).toList(); @@ -386,8 +484,14 @@ class RoleUserQuery extends Query { class RoleUserQueryWhere extends QueryWhere { RoleUserQueryWhere(RoleUserQuery query) - : roleId = NumericSqlExpressionBuilder(query, 'role_id'), - userId = NumericSqlExpressionBuilder(query, 'user_id'); + : roleId = NumericSqlExpressionBuilder( + query, + 'role_id', + ), + userId = NumericSqlExpressionBuilder( + query, + 'user_id', + ); final NumericSqlExpressionBuilder roleId; @@ -395,7 +499,10 @@ class RoleUserQueryWhere extends QueryWhere { @override List get expressionBuilders { - return [roleId, userId]; + return [ + roleId, + userId, + ]; } } @@ -426,23 +533,27 @@ class RoleUserQueryValues extends MapQueryValues { } class RoleQuery extends Query { - RoleQuery({Query? parent, Set? trampoline}) : super(parent: parent) { + RoleQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = RoleQueryWhere(this); leftJoin( - '(SELECT role_users.role_id, users.id, users.created_at, users.updated_at, users.username, users.password, users.email FROM users LEFT JOIN role_users ON role_users.user_id=users.id)', + '(SELECT role_users.role_id, users.id, users.created_at, users.updated_at, users.username, users.password, users.email FROM users LEFT JOIN role_users ON role_users.user_id=users.id)', + 'id', + 'role_id', + additionalFields: const [ 'id', - 'role_id', - additionalFields: const [ - 'id', - 'created_at', - 'updated_at', - 'username', - 'password', - 'email' - ], - trampoline: trampoline); + 'created_at', + 'updated_at', + 'username', + 'password', + 'email', + ], + trampoline: trampoline, + ); } @override @@ -464,7 +575,12 @@ class RoleQuery extends Query { @override List get fields { - const _fields = ['id', 'created_at', 'updated_at', 'name']; + const _fields = [ + 'id', + 'created_at', + 'updated_at', + 'name', + ]; return _selectedFields.isEmpty ? _fields : _fields.where((field) => _selectedFields.contains(field)).toList(); @@ -490,14 +606,13 @@ class RoleQuery extends Query { return Optional.empty(); } var model = Role( - id: fields.contains('id') ? row[0].toString() : null, - createdAt: fields.contains('created_at') - ? mapToNullableDateTime(row[1]) - : null, - updatedAt: fields.contains('updated_at') - ? mapToNullableDateTime(row[2]) - : null, - name: fields.contains('name') ? (row[3] as String?) : null); + id: fields.contains('id') ? row[0].toString() : null, + createdAt: + fields.contains('created_at') ? mapToNullableDateTime(row[1]) : null, + updatedAt: + fields.contains('updated_at') ? mapToNullableDateTime(row[2]) : null, + name: fields.contains('name') ? (row[3] as String?) : null, + ); if (row.length > 4) { var modelOpt = UserQuery().parseRow(row.skip(4).take(6).toList()); modelOpt.ifPresent((m) { @@ -575,10 +690,22 @@ class RoleQuery extends Query { class RoleQueryWhere extends QueryWhere { RoleQueryWhere(RoleQuery query) - : id = NumericSqlExpressionBuilder(query, 'id'), - createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), - updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'), - name = StringSqlExpressionBuilder(query, 'name'); + : id = NumericSqlExpressionBuilder( + query, + 'id', + ), + createdAt = DateTimeSqlExpressionBuilder( + query, + 'created_at', + ), + updatedAt = DateTimeSqlExpressionBuilder( + query, + 'updated_at', + ), + name = StringSqlExpressionBuilder( + query, + 'name', + ); final NumericSqlExpressionBuilder id; @@ -590,7 +717,12 @@ class RoleQueryWhere extends QueryWhere { @override List get expressionBuilders { - return [id, createdAt, updatedAt, name]; + return [ + id, + createdAt, + updatedAt, + name, + ]; } } @@ -633,15 +765,15 @@ class RoleQueryValues extends MapQueryValues { @generatedSerializable class User extends _User { - User( - {this.id, - this.createdAt, - this.updatedAt, - this.username, - this.password, - this.email, - List<_Role> roles = const []}) - : roles = List.unmodifiable(roles); + User({ + this.id, + this.createdAt, + this.updatedAt, + this.username, + this.password, + this.email, + List<_Role> roles = const [], + }) : roles = List.unmodifiable(roles); /// A unique identifier corresponding to this item. @override @@ -667,14 +799,15 @@ class User extends _User { @override List<_Role> roles; - User copyWith( - {String? id, - DateTime? createdAt, - DateTime? updatedAt, - String? username, - String? password, - String? email, - List<_Role>? roles}) { + User copyWith({ + String? id, + DateTime? createdAt, + DateTime? updatedAt, + String? username, + String? password, + String? email, + List<_Role>? roles, + }) { return User( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -700,8 +833,15 @@ class User extends _User { @override int get hashCode { - return hashObjects( - [id, createdAt, updatedAt, username, password, email, roles]); + return hashObjects([ + id, + createdAt, + updatedAt, + username, + password, + email, + roles, + ]); } @override @@ -716,7 +856,10 @@ class User extends _User { @generatedSerializable class RoleUser implements _RoleUser { - RoleUser({this.role, this.user}); + RoleUser({ + this.role, + this.user, + }); @override _Role? role; @@ -724,7 +867,10 @@ class RoleUser implements _RoleUser { @override _User? user; - RoleUser copyWith({_Role? role, _User? user}) { + RoleUser copyWith({ + _Role? role, + _User? user, + }) { return RoleUser(role: role ?? this.role, user: user ?? this.user); } @@ -735,7 +881,10 @@ class RoleUser implements _RoleUser { @override int get hashCode { - return hashObjects([role, user]); + return hashObjects([ + role, + user, + ]); } @override @@ -750,13 +899,13 @@ class RoleUser implements _RoleUser { @generatedSerializable class Role extends _Role { - Role( - {this.id, - this.createdAt, - this.updatedAt, - this.name, - List<_User> users = const []}) - : users = List.unmodifiable(users); + Role({ + this.id, + this.createdAt, + this.updatedAt, + this.name, + List<_User> users = const [], + }) : users = List.unmodifiable(users); /// A unique identifier corresponding to this item. @override @@ -776,12 +925,13 @@ class Role extends _Role { @override List<_User> users; - Role copyWith( - {String? id, - DateTime? createdAt, - DateTime? updatedAt, - String? name, - List<_User>? users}) { + Role copyWith({ + String? id, + DateTime? createdAt, + DateTime? updatedAt, + String? name, + List<_User>? users, + }) { return Role( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -803,7 +953,13 @@ class Role extends _Role { @override int get hashCode { - return hashObjects([id, createdAt, updatedAt, name, users]); + return hashObjects([ + id, + createdAt, + updatedAt, + name, + users, + ]); } @override @@ -889,7 +1045,7 @@ abstract class UserFields { username, password, email, - roles + roles, ]; static const String id = 'id'; @@ -952,7 +1108,10 @@ class RoleUserSerializer extends Codec { } abstract class RoleUserFields { - static const List allFields = [role, user]; + static const List allFields = [ + role, + user, + ]; static const String role = 'role'; @@ -1022,7 +1181,7 @@ abstract class RoleFields { createdAt, updatedAt, name, - users + users, ]; static const String id = 'id'; diff --git a/packages/orm/angel_orm_test/lib/src/models/world.g.dart b/packages/orm/angel_orm_test/lib/src/models/world.g.dart index 5a0e29f7..3b162ffe 100644 --- a/packages/orm/angel_orm_test/lib/src/models/world.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/world.g.dart @@ -9,10 +9,13 @@ part of 'world.dart'; class WorldMigration extends Migration { @override void up(Schema schema) { - schema.create('world', (table) { - table.integer('id').primaryKey(); - table.integer('random_number'); - }); + schema.create( + 'world', + (table) { + table.integer('id').primaryKey(); + table.integer('random_number'); + }, + ); } @override @@ -26,7 +29,10 @@ class WorldMigration extends Migration { // ************************************************************************** class WorldQuery extends Query { - WorldQuery({Query? parent, Set? trampoline}) : super(parent: parent) { + WorldQuery({ + Query? parent, + Set? trampoline, + }) : super(parent: parent) { trampoline ??= {}; trampoline.add(tableName); _where = WorldQueryWhere(this); @@ -51,7 +57,10 @@ class WorldQuery extends Query { @override List get fields { - const _fields = ['id', 'random_number']; + const _fields = [ + 'id', + 'random_number', + ]; return _selectedFields.isEmpty ? _fields : _fields.where((field) => _selectedFields.contains(field)).toList(); @@ -77,9 +86,9 @@ class WorldQuery extends Query { return Optional.empty(); } var model = World( - id: fields.contains('id') ? (row[0] as int?) : null, - randomNumber: - fields.contains('random_number') ? (row[1] as int?) : null); + id: fields.contains('id') ? (row[0] as int?) : null, + randomNumber: fields.contains('random_number') ? (row[1] as int?) : null, + ); return Optional.of(model); } @@ -91,8 +100,14 @@ class WorldQuery extends Query { class WorldQueryWhere extends QueryWhere { WorldQueryWhere(WorldQuery query) - : id = NumericSqlExpressionBuilder(query, 'id'), - randomNumber = NumericSqlExpressionBuilder(query, 'random_number'); + : id = NumericSqlExpressionBuilder( + query, + 'id', + ), + randomNumber = NumericSqlExpressionBuilder( + query, + 'random_number', + ); final NumericSqlExpressionBuilder id; @@ -100,7 +115,10 @@ class WorldQueryWhere extends QueryWhere { @override List get expressionBuilders { - return [id, randomNumber]; + return [ + id, + randomNumber, + ]; } } @@ -132,7 +150,10 @@ class WorldQueryValues extends MapQueryValues { @generatedSerializable class World extends _World { - World({this.id, this.randomNumber}); + World({ + this.id, + this.randomNumber, + }); @override int? id; @@ -140,7 +161,10 @@ class World extends _World { @override int? randomNumber; - World copyWith({int? id, int? randomNumber}) { + World copyWith({ + int? id, + int? randomNumber, + }) { return World( id: id ?? this.id, randomNumber: randomNumber ?? this.randomNumber); } @@ -154,7 +178,10 @@ class World extends _World { @override int get hashCode { - return hashObjects([id, randomNumber]); + return hashObjects([ + id, + randomNumber, + ]); } @override @@ -208,7 +235,10 @@ class WorldSerializer extends Codec { } abstract class WorldFields { - static const List allFields = [id, randomNumber]; + static const List allFields = [ + id, + randomNumber, + ]; static const String id = 'id'; diff --git a/packages/orm/angel_orm_test/lib/src/standalone_test.dart b/packages/orm/angel_orm_test/lib/src/standalone_test.dart index 840f0fd3..4adbf61f 100644 --- a/packages/orm/angel_orm_test/lib/src/standalone_test.dart +++ b/packages/orm/angel_orm_test/lib/src/standalone_test.dart @@ -22,7 +22,7 @@ void standaloneTests(FutureOr Function() createExecutor, test('parseRow', () { // 'id', 'created_at', 'updated_at', 'make', 'description', 'family_friendly', 'recalled_at' // var row = [0, 'Mazda', 'CX9', true, y2k, y2k, y2k]; - var row = [0, y2k, y2k, 'Mazda', 'CX9', true, y2k]; + var row = [0, y2k, y2k, 'Mazda', 'CX9', true, y2k, 80000.00]; //print(row); var carOpt = CarQuery().deserialize(row); expect(carOpt.isPresent, true); @@ -38,6 +38,7 @@ void standaloneTests(FutureOr Function() createExecutor, y2k.toIso8601String(), startsWith(car.createdAt!.toIso8601String())); expect( y2k.toIso8601String(), startsWith(car.updatedAt!.toIso8601String())); + expect(car.price, 80000.00); }); }); @@ -66,6 +67,7 @@ void standaloneTests(FutureOr Function() createExecutor, ..createdAt = y2k ..updatedAt = y2k ..description = 'Vroom vroom!' + //..price = 120000.00 ..familyFriendly = false; ferrari = (await query.insert(executor!)).value; }); diff --git a/packages/orm/angel_orm_test/pubspec.yaml b/packages/orm/angel_orm_test/pubspec.yaml index f4a91c87..5ae7de8a 100644 --- a/packages/orm/angel_orm_test/pubspec.yaml +++ b/packages/orm/angel_orm_test/pubspec.yaml @@ -1,5 +1,5 @@ name: angel3_orm_test -version: 7.0.0 +version: 7.0.1 description: Common tests for Angel3 ORM. Reference implmentation of the generated ORM files. homepage: https://angel3-framework.web.app/ repository: https://github.com/dukefirehawk/angel/tree/master/packages/orm/angel_orm_test @@ -19,7 +19,7 @@ dev_dependencies: angel3_framework: ^7.0.0 build_runner: ^2.0.1 lints: ^2.0.0 -# dependency_overrides: +dependency_overrides: # angel3_container: # path: ../../container/angel_container # angel3_framework: @@ -40,5 +40,5 @@ dev_dependencies: # path: ../angel_orm # angel3_migration: # path: ../angel_migration -# angel3_orm_generator: -# path: ../angel_orm_generator + angel3_orm_generator: + path: ../angel_orm_generator