From 106528a93be164145d56e0bd47e008d1a317bdcd Mon Sep 17 00:00:00 2001 From: "thomashii@dukefirehawk.com" Date: Sun, 2 May 2021 23:34:47 +0800 Subject: [PATCH] Migrated angel_migration_runner --- .../example/car_controller.dart | 4 +- .../lib/src/belongs_to_test.dart | 108 ++--- .../lib/src/custom_expr_test.dart | 20 +- .../lib/src/edge_case_test.dart | 44 +- .../lib/src/enum_and_nested_test.dart | 12 +- .../angel_orm_test/lib/src/has_many_test.dart | 42 +- .../angel_orm_test/lib/src/has_map_test.dart | 28 +- .../angel_orm_test/lib/src/has_one_test.dart | 82 ++-- .../lib/src/many_to_many_test.dart | 37 +- .../angel_orm_test/lib/src/models/book.dart | 8 +- .../angel_orm_test/lib/src/models/book.g.dart | 168 ++++---- .../angel_orm_test/lib/src/models/car.dart | 8 +- .../angel_orm_test/lib/src/models/car.g.dart | 109 +++-- .../lib/src/models/custom_expr.dart | 6 +- .../lib/src/models/custom_expr.g.dart | 146 ++++--- .../lib/src/models/email_indexed.dart | 16 +- .../lib/src/models/email_indexed.g.dart | 215 +++++----- .../lib/src/models/has_car.dart | 2 +- .../lib/src/models/has_car.g.dart | 63 ++- .../lib/src/models/has_map.dart | 4 +- .../lib/src/models/has_map.g.dart | 36 +- .../angel_orm_test/lib/src/models/leg.dart | 8 +- .../angel_orm_test/lib/src/models/leg.g.dart | 159 ++++--- .../angel_orm_test/lib/src/models/order.dart | 8 +- .../lib/src/models/order.g.dart | 167 ++++---- .../angel_orm_test/lib/src/models/tree.dart | 8 +- .../angel_orm_test/lib/src/models/tree.g.dart | 184 ++++---- .../lib/src/models/unorthodox.dart | 30 +- .../lib/src/models/unorthodox.g.dart | 399 +++++++++--------- .../angel_orm_test/lib/src/models/user.dart | 12 +- .../angel_orm_test/lib/src/models/user.g.dart | 294 +++++++------ .../lib/src/standalone_test.dart | 97 ++--- packages/orm/angel_orm_test/pubspec.yaml | 20 +- 33 files changed, 1255 insertions(+), 1289 deletions(-) diff --git a/packages/orm/angel_orm_test/example/car_controller.dart b/packages/orm/angel_orm_test/example/car_controller.dart index 536d0847..fe42f733 100644 --- a/packages/orm/angel_orm_test/example/car_controller.dart +++ b/packages/orm/angel_orm_test/example/car_controller.dart @@ -6,10 +6,10 @@ import 'package:angel_orm_test/src/models/car.dart'; @Expose('/api/cars') class CarController extends Controller { @Expose('/luxury') - Future> getLuxuryCars(QueryExecutor connection) { + Future> getLuxuryCars(QueryExecutor connection) { var query = new CarQuery(); query.where - ..familyFriendly.equals(false) + ?..familyFriendly.equals(false) ..createdAt.year.greaterThanOrEqualTo(2014) ..make.isIn(['Ferrari', 'Lamborghini', 'Mustang', 'Lexus']); return query.get(connection); diff --git a/packages/orm/angel_orm_test/lib/src/belongs_to_test.dart b/packages/orm/angel_orm_test/lib/src/belongs_to_test.dart index c58dc7f8..946c8109 100644 --- a/packages/orm/angel_orm_test/lib/src/belongs_to_test.dart +++ b/packages/orm/angel_orm_test/lib/src/belongs_to_test.dart @@ -5,11 +5,11 @@ import 'models/book.dart'; import 'util.dart'; belongsToTests(FutureOr Function() createExecutor, - {FutureOr Function(QueryExecutor) close}) { - QueryExecutor executor; - Author jkRowling; - Author jameson; - Book deathlyHallows; + {FutureOr Function(QueryExecutor)? close}) { + late QueryExecutor executor; + Author? jkRowling; + Author? jameson; + Book? deathlyHallows; close ??= (_) => null; setUp(() async { @@ -25,128 +25,128 @@ belongsToTests(FutureOr Function() createExecutor, // And a book var bookQuery = new BookQuery(); bookQuery.values - ..authorId = int.parse(jkRowling.id) - ..partnerAuthorId = int.parse(jameson.id) + ..authorId = int.parse(jkRowling!.id!) + ..partnerAuthorId = int.parse(jameson!.id!) ..name = 'Deathly Hallows'; deathlyHallows = await bookQuery.insert(executor); }); - tearDown(() => close(executor)); + tearDown(() => close!(executor)); group('selects', () { test('select all', () async { var query = new BookQuery(); - var books = await query.get(executor); + List books = await query.get(executor); expect(books, hasLength(1)); - var book = books.first; + var book = books.first!; print(book.toJson()); - expect(book.id, deathlyHallows.id); - expect(book.name, deathlyHallows.name); + expect(book.id, deathlyHallows!.id); + expect(book.name, deathlyHallows!.name); - var author = book.author; + var author = book.author!; print(AuthorSerializer.toMap(author)); - expect(author.id, jkRowling.id); - expect(author.name, jkRowling.name); + expect(author.id, jkRowling!.id); + expect(author.name, jkRowling!.name); }); test('select one', () async { var query = new BookQuery(); - query.where.id.equals(int.parse(deathlyHallows.id)); + query.where!.id.equals(int.parse(deathlyHallows!.id!)); print(query.compile(Set())); - var book = await query.getOne(executor); + var book = await (query.getOne(executor) as FutureOr); print(book.toJson()); - expect(book.id, deathlyHallows.id); - expect(book.name, deathlyHallows.name); + expect(book.id, deathlyHallows!.id); + expect(book.name, deathlyHallows!.name); - var author = book.author; + var author = book.author!; print(AuthorSerializer.toMap(author)); - expect(author.id, jkRowling.id); - expect(author.name, jkRowling.name); + expect(author.id, jkRowling!.id); + expect(author.name, jkRowling!.name); }); test('where clause', () async { var query = new BookQuery() - ..where.name.equals('Goblet of Fire') - ..orWhere((w) => w.authorId.equals(int.parse(jkRowling.id))); + ..where!.name.equals('Goblet of Fire') + ..orWhere((w) => w!.authorId.equals(int.parse(jkRowling!.id!))); print(query.compile(Set())); - var books = await query.get(executor); + List books = await query.get(executor); expect(books, hasLength(1)); - var book = books.first; + var book = books.first!; print(book.toJson()); - expect(book.id, deathlyHallows.id); - expect(book.name, deathlyHallows.name); + expect(book.id, deathlyHallows!.id); + expect(book.name, deathlyHallows!.name); - var author = book.author; + var author = book.author!; print(AuthorSerializer.toMap(author)); - expect(author.id, jkRowling.id); - expect(author.name, jkRowling.name); + expect(author.id, jkRowling!.id); + expect(author.name, jkRowling!.name); }); test('union', () async { - var query1 = new BookQuery()..where.name.like('Deathly%'); - var query2 = new BookQuery()..where.authorId.equals(-1); + var query1 = new BookQuery()..where!.name.like('Deathly%'); + var query2 = new BookQuery()..where!.authorId.equals(-1); var query3 = new BookQuery() - ..where.name.isIn(['Goblet of Fire', 'Order of the Phoenix']); + ..where!.name.isIn(['Goblet of Fire', 'Order of the Phoenix']); query1 ..union(query2) ..unionAll(query3); print(query1.compile(Set())); - var books = await query1.get(executor); + List books = await query1.get(executor); expect(books, hasLength(1)); - var book = books.first; + var book = books.first!; print(book.toJson()); - expect(book.id, deathlyHallows.id); - expect(book.name, deathlyHallows.name); + expect(book.id, deathlyHallows!.id); + expect(book.name, deathlyHallows!.name); - var author = book.author; + var author = book.author!; print(AuthorSerializer.toMap(author)); - expect(author.id, jkRowling.id); - expect(author.name, jkRowling.name); + expect(author.id, jkRowling!.id); + expect(author.name, jkRowling!.name); }); test('order by', () async { var query = AuthorQuery()..orderBy(AuthorFields.name, descending: true); - var authors = await query.get(executor); + List authors = await query.get(executor); expect(authors, [jkRowling, jameson]); }); }); test('insert sets relationship', () { - expect(deathlyHallows.author, jkRowling); + expect(deathlyHallows!.author, jkRowling); //expect(deathlyHallows.author, isNotNull); //expect(deathlyHallows.author.name, rowling.name); }); test('delete stream', () async { printSeparator('Delete stream test'); - var query = new BookQuery()..where.name.equals(deathlyHallows.name); + var query = new BookQuery()..where!.name.equals(deathlyHallows!.name!); print(query.compile(Set(), preamble: 'DELETE', withFields: false)); - var books = await query.delete(executor); + List books = await query.delete(executor); expect(books, hasLength(1)); - var book = books.first; - expect(book.id, deathlyHallows.id); + var book = books.first!; + expect(book.id, deathlyHallows!.id); expect(book.author, isNotNull); - expect((book.author).name, jkRowling.name); + expect(book.author!.name, jkRowling!.name); }); test('update book', () async { - var cloned = deathlyHallows.copyWith(name: "Sorcerer's Stone"); + var cloned = deathlyHallows!.copyWith(name: "Sorcerer's Stone"); var query = new BookQuery() - ..where.id.equals(int.parse(cloned.id)) + ..where!.id.equals(int.parse(cloned.id!)) ..values.copyFrom(cloned); - var book = await query.updateOne(executor); + var book = await (query.updateOne(executor) as FutureOr); print(book.toJson()); expect(book.name, cloned.name); expect(book.author, isNotNull); - expect(book.author.name, jkRowling.name); + expect(book.author!.name, jkRowling!.name); }); group('joined subquery', () { @@ -155,13 +155,13 @@ belongsToTests(FutureOr Function() createExecutor, // that should return correctly. test('returns empty on false subquery', () async { printSeparator('False subquery test'); - var query = BookQuery()..author.where.name.equals('Billie Jean'); + var query = BookQuery()..author!.where!.name.equals('Billie Jean'); expect(await query.get(executor), isEmpty); }); test('returns values on true subquery', () async { printSeparator('True subquery test'); - var query = BookQuery()..author.where.name.like('%Rowling%'); + var query = BookQuery()..author!.where!.name.like('%Rowling%'); expect(await query.get(executor), [deathlyHallows]); }); }); diff --git a/packages/orm/angel_orm_test/lib/src/custom_expr_test.dart b/packages/orm/angel_orm_test/lib/src/custom_expr_test.dart index a9c97b63..f553f302 100644 --- a/packages/orm/angel_orm_test/lib/src/custom_expr_test.dart +++ b/packages/orm/angel_orm_test/lib/src/custom_expr_test.dart @@ -5,9 +5,9 @@ import 'models/custom_expr.dart'; import 'util.dart'; customExprTests(FutureOr Function() createExecutor, - {FutureOr Function(QueryExecutor) close}) { - QueryExecutor executor; - Numbers numbersModel; + {FutureOr Function(QueryExecutor)? close}) { + late QueryExecutor executor; + Numbers? numbersModel; close ??= (_) => null; @@ -22,22 +22,22 @@ customExprTests(FutureOr Function() createExecutor, numbersModel = await nQuery.insert(executor); }); - tearDown(() => close(executor)); + tearDown(() => close!(executor)); test('fetches correct result', () async { - expect(numbersModel.two, 2); + expect(numbersModel!.two, 2); }); test('in relation', () async { var abcQuery = AlphabetQuery(); abcQuery.values ..value = 'abc' - ..numbersId = numbersModel.idAsInt - ..createdAt = numbersModel.createdAt - ..updatedAt = numbersModel.updatedAt; - var abc = await abcQuery.insert(executor); + ..numbersId = numbersModel!.idAsInt + ..createdAt = numbersModel!.createdAt + ..updatedAt = numbersModel!.updatedAt; + var abc = await (abcQuery.insert(executor) as FutureOr); expect(abc.numbers, numbersModel); - expect(abc.numbers.two, 2); + expect(abc.numbers!.two, 2); expect(abc.value, 'abc'); }); } diff --git a/packages/orm/angel_orm_test/lib/src/edge_case_test.dart b/packages/orm/angel_orm_test/lib/src/edge_case_test.dart index 00b7f910..260a46b1 100644 --- a/packages/orm/angel_orm_test/lib/src/edge_case_test.dart +++ b/packages/orm/angel_orm_test/lib/src/edge_case_test.dart @@ -4,15 +4,15 @@ import 'package:test/test.dart'; import 'models/unorthodox.dart'; edgeCaseTests(FutureOr Function() createExecutor, - {FutureOr Function(QueryExecutor) close}) { - QueryExecutor executor; + {FutureOr Function(QueryExecutor)? close}) { + late QueryExecutor executor; close ??= (_) => null; setUp(() async { executor = await createExecutor(); }); - tearDown(() => close(executor)); + tearDown(() => close!(executor)); test('can create object with no id', () async { var query = UnorthodoxQuery()..values.name = 'Hey'; @@ -21,7 +21,7 @@ edgeCaseTests(FutureOr Function() createExecutor, }); group('relations on non-model', () { - Unorthodox unorthodox; + Unorthodox? unorthodox; setUp(() async { var query = UnorthodoxQuery()..values.name = 'Hey'; @@ -29,64 +29,64 @@ edgeCaseTests(FutureOr Function() createExecutor, }); test('belongs to', () async { - var query = WeirdJoinQuery()..values.joinName = unorthodox.name; - var model = await query.insert(executor); + var query = WeirdJoinQuery()..values.joinName = unorthodox!.name; + var model = await (query.insert(executor) as FutureOr); print(model.toJson()); expect(model.id, isNotNull); // Postgres should set this. expect(model.unorthodox, unorthodox); }); group('layered', () { - WeirdJoin weirdJoin; - Song girlBlue; + WeirdJoin? weirdJoin; + Song? girlBlue; setUp(() async { - var wjQuery = WeirdJoinQuery()..values.joinName = unorthodox.name; + var wjQuery = WeirdJoinQuery()..values.joinName = unorthodox!.name; weirdJoin = await wjQuery.insert(executor); var gbQuery = SongQuery() - ..values.weirdJoinId = weirdJoin.id + ..values.weirdJoinId = weirdJoin!.id ..values.title = 'Girl Blue'; girlBlue = await gbQuery.insert(executor); }); test('has one', () async { - var query = WeirdJoinQuery()..where.id.equals(weirdJoin.id); - var wj = await query.getOne(executor); + var query = WeirdJoinQuery()..where!.id.equals(weirdJoin!.id!); + var wj = await (query.getOne(executor) as FutureOr); print(wj.toJson()); expect(wj.song, girlBlue); }); test('has many', () async { - var numbas = []; + var numbas = []; for (int i = 0; i < 15; i++) { var query = NumbaQuery() - ..values.parent = weirdJoin.id + ..values.parent = weirdJoin!.id ..values.i = i; var model = await query.insert(executor); numbas.add(model); } - var query = WeirdJoinQuery()..where.id.equals(weirdJoin.id); - var wj = await query.getOne(executor); + var query = WeirdJoinQuery()..where!.id.equals(weirdJoin!.id!); + var wj = await (query.getOne(executor) as FutureOr); print(wj.toJson()); expect(wj.numbas, numbas); }); test('many to many', () async { var fooQuery = FooQuery()..values.bar = 'baz'; - var fooBar = await fooQuery.insert(executor).then((foo) => foo.bar); + var fooBar = await fooQuery.insert(executor).then((foo) => foo!.bar!); var pivotQuery = FooPivotQuery() - ..values.weirdJoinId = weirdJoin.id + ..values.weirdJoinId = weirdJoin!.id ..values.fooBar = fooBar; await pivotQuery.insert(executor); - fooQuery = FooQuery()..where.bar.equals('baz'); + fooQuery = FooQuery()..where!.bar.equals('baz'); - var foo = await fooQuery.getOne(executor); + var foo = await (fooQuery.getOne(executor) as FutureOr); print(foo.toJson()); - print(weirdJoin.toJson()); - expect(foo.weirdJoins[0].id, weirdJoin.id); + print(weirdJoin!.toJson()); + expect(foo.weirdJoins![0]!.id, weirdJoin!.id); }); }); }); diff --git a/packages/orm/angel_orm_test/lib/src/enum_and_nested_test.dart b/packages/orm/angel_orm_test/lib/src/enum_and_nested_test.dart index 9cced77b..e79b3f28 100644 --- a/packages/orm/angel_orm_test/lib/src/enum_and_nested_test.dart +++ b/packages/orm/angel_orm_test/lib/src/enum_and_nested_test.dart @@ -4,8 +4,8 @@ import 'package:test/test.dart'; import 'models/has_car.dart'; enumAndNestedTests(FutureOr Function() createExecutor, - {FutureOr Function(QueryExecutor) close}) { - QueryExecutor executor; + {FutureOr Function(QueryExecutor)? close}) { + late QueryExecutor executor; close ??= (_) => null; setUp(() async { @@ -14,12 +14,12 @@ enumAndNestedTests(FutureOr Function() createExecutor, test('insert', () async { var query = HasCarQuery()..values.type = CarType.sedan; - var result = await query.insert(executor); + var result = await (query.insert(executor) as FutureOr); expect(result.type, CarType.sedan); }); group('query', () { - HasCar initialValue; + HasCar? initialValue; setUp(() async { var query = HasCarQuery(); @@ -29,10 +29,10 @@ enumAndNestedTests(FutureOr Function() createExecutor, test('query by enum', () async { // Check for mismatched type - var query = HasCarQuery()..where.type.equals(CarType.atv); + var query = HasCarQuery()..where!.type.equals(CarType.atv); expect(await query.get(executor), isEmpty); - query = HasCarQuery()..where.type.equals(initialValue.type); + query = HasCarQuery()..where!.type.equals(initialValue!.type); expect(await query.getOne(executor), initialValue); }); }); diff --git a/packages/orm/angel_orm_test/lib/src/has_many_test.dart b/packages/orm/angel_orm_test/lib/src/has_many_test.dart index 17e93821..052aab08 100644 --- a/packages/orm/angel_orm_test/lib/src/has_many_test.dart +++ b/packages/orm/angel_orm_test/lib/src/has_many_test.dart @@ -4,10 +4,10 @@ import 'package:test/test.dart'; import 'models/tree.dart'; hasManyTests(FutureOr Function() createExecutor, - {FutureOr Function(QueryExecutor) close}) { - QueryExecutor executor; - Tree appleTree; - int treeId; + {FutureOr Function(QueryExecutor)? close}) { + late QueryExecutor executor; + Tree? appleTree; + late int treeId; close ??= (_) => null; setUp(() async { @@ -15,24 +15,24 @@ hasManyTests(FutureOr Function() createExecutor, executor = await createExecutor(); appleTree = await query.insert(executor); - treeId = int.parse(appleTree.id); + treeId = int.parse(appleTree!.id!); }); - tearDown(() => close(executor)); + tearDown(() => close!(executor)); test('list is empty if there is nothing', () { - expect(appleTree.rings, 10); - expect(appleTree.fruits, isEmpty); + expect(appleTree!.rings, 10); + expect(appleTree!.fruits, isEmpty); }); group('mutations', () { - Fruit apple, banana; + Fruit? apple, banana; void verify(Tree tree) { - print(tree.fruits.map(FruitSerializer.toMap).toList()); + print(tree.fruits!.map(FruitSerializer.toMap).toList()); expect(tree.fruits, hasLength(2)); - expect(tree.fruits[0].commonName, apple.commonName); - expect(tree.fruits[1].commonName, banana.commonName); + expect(tree.fruits![0].commonName, apple!.commonName); + expect(tree.fruits![1].commonName, banana!.commonName); } setUp(() async { @@ -49,31 +49,31 @@ hasManyTests(FutureOr Function() createExecutor, }); test('can fetch any children', () async { - var query = new TreeQuery()..where.id.equals(treeId); - var tree = await query.getOne(executor); + var query = new TreeQuery()..where!.id.equals(treeId); + var tree = await (query.getOne(executor) as FutureOr); verify(tree); }); test('sets on update', () async { var tq = new TreeQuery() - ..where.id.equals(treeId) + ..where!.id.equals(treeId) ..values.rings = 24; - var tree = await tq.updateOne(executor); + var tree = await (tq.updateOne(executor) as FutureOr); verify(tree); expect(tree.rings, 24); }); test('sets on delete', () async { - var tq = new TreeQuery()..where.id.equals(treeId); - var tree = await tq.deleteOne(executor); + var tq = new TreeQuery()..where!.id.equals(treeId); + var tree = await (tq.deleteOne(executor) as FutureOr); verify(tree); }); test('returns empty on false subquery', () async { var tq = new TreeQuery() - ..where.id.equals(treeId) - ..fruits.where.commonName.equals('Kiwi'); - var tree = await tq.getOne(executor); + ..where!.id.equals(treeId) + ..fruits!.where!.commonName.equals('Kiwi'); + var tree = await (tq.getOne(executor) as FutureOr); expect(tree.fruits, isEmpty); }); }); diff --git a/packages/orm/angel_orm_test/lib/src/has_map_test.dart b/packages/orm/angel_orm_test/lib/src/has_map_test.dart index f61b8551..9772d1ad 100644 --- a/packages/orm/angel_orm_test/lib/src/has_map_test.dart +++ b/packages/orm/angel_orm_test/lib/src/has_map_test.dart @@ -4,22 +4,22 @@ import 'package:test/test.dart'; import 'models/has_map.dart'; hasMapTests(FutureOr Function() createExecutor, - {FutureOr Function(QueryExecutor) close}) { - QueryExecutor executor; + {FutureOr Function(QueryExecutor)? close}) { + late QueryExecutor executor; close ??= (_) => null; setUp(() async { executor = await createExecutor(); }); - tearDown(() => close(executor)); + tearDown(() => close!(executor)); test('insert', () async { var query = HasMapQuery(); query.values ..value = {'foo': 'bar'} ..list = ['1', 2, 3.0]; - var model = await query.insert(executor); + var model = await (query.insert(executor) as FutureOr); print(model.toJson()); expect(model, HasMap(value: {'foo': 'bar'}, list: ['1', 2, 3.0])); }); @@ -29,7 +29,7 @@ hasMapTests(FutureOr Function() createExecutor, query.values ..value = {'foo': 'bar'} ..list = ['1', 2, 3.0]; - var model = await query.insert(executor); + var model = await (query.insert(executor) as FutureOr); print(model.toJson()); query = HasMapQuery()..values.copyFrom(model); @@ -37,7 +37,7 @@ hasMapTests(FutureOr Function() createExecutor, }); group('query', () { - HasMap initialValue; + HasMap? initialValue; setUp(() async { var query = HasMapQuery(); @@ -54,37 +54,37 @@ hasMapTests(FutureOr Function() createExecutor, test('map equals', () async { var query = HasMapQuery(); - query.where.value.equals({'foo': 'bar'}); + query.where!.value.equals({'foo': 'bar'}); expect(await query.get(executor), [initialValue]); query = HasMapQuery(); - query.where.value.equals({'foo': 'baz'}); + query.where!.value.equals({'foo': 'baz'}); expect(await query.get(executor), isEmpty); }); test('list equals', () async { var query = HasMapQuery(); - query.where.list.equals(['1', 2, 3.0]); + query.where!.list.equals(['1', 2, 3.0]); expect(await query.get(executor), [initialValue]); query = HasMapQuery(); - query.where.list.equals(['10', 20, 30.0]); + query.where!.list.equals(['10', 20, 30.0]); expect(await query.get(executor), isEmpty); }); test('property equals', () async { - var query = HasMapQuery()..where.value['foo'].asString.equals('bar'); + var query = HasMapQuery()..where!.value['foo'].asString!.equals('bar'); expect(await query.get(executor), [initialValue]); - query = HasMapQuery()..where.value['foo'].asString.equals('baz'); + query = HasMapQuery()..where!.value['foo'].asString!.equals('baz'); expect(await query.get(executor), []); }); test('index equals', () async { - var query = HasMapQuery()..where.list[0].asString.equals('1'); + var query = HasMapQuery()..where!.list[0].asString!.equals('1'); expect(await query.get(executor), [initialValue]); - query = HasMapQuery()..where.list[1].asInt.equals(3); + query = HasMapQuery()..where!.list[1].asInt!.equals(3); expect(await query.get(executor), []); }); }); diff --git a/packages/orm/angel_orm_test/lib/src/has_one_test.dart b/packages/orm/angel_orm_test/lib/src/has_one_test.dart index 9daeb169..ab55f027 100644 --- a/packages/orm/angel_orm_test/lib/src/has_one_test.dart +++ b/packages/orm/angel_orm_test/lib/src/has_one_test.dart @@ -4,9 +4,9 @@ import 'package:test/test.dart'; import 'models/leg.dart'; hasOneTests(FutureOr Function() createExecutor, - {FutureOr Function(QueryExecutor) close}) { - QueryExecutor executor; - Leg originalLeg; + {FutureOr Function(QueryExecutor)? close}) { + late QueryExecutor executor; + Leg? originalLeg; close ??= (_) => null; setUp(() async { @@ -15,82 +15,82 @@ hasOneTests(FutureOr Function() createExecutor, originalLeg = await query.insert(executor); }); - tearDown(() => close(executor)); + tearDown(() => close!(executor)); test('sets to null if no child', () async { print(LegQuery().compile(Set())); - var query = new LegQuery()..where.id.equals(int.parse(originalLeg.id)); - var leg = await query.getOne(executor); + var query = new LegQuery()..where!.id.equals(int.parse(originalLeg!.id!)); + var leg = await (query.getOne(executor) as FutureOr); print(leg.toJson()); - expect(leg.name, originalLeg.name); - expect(leg.id, originalLeg.id); + expect(leg.name, originalLeg!.name); + expect(leg.id, originalLeg!.id); expect(leg.foot, isNull); }); test('can fetch one foot', () async { var footQuery = new FootQuery() - ..values.legId = int.parse(originalLeg.id) + ..values.legId = int.parse(originalLeg!.id!) ..values.nToes = 5.64; - var legQuery = new LegQuery()..where.id.equals(int.parse(originalLeg.id)); - var foot = await footQuery.insert(executor); - var leg = await legQuery.getOne(executor); + var legQuery = new LegQuery()..where!.id.equals(int.parse(originalLeg!.id!)); + var foot = await (footQuery.insert(executor) as FutureOr); + var leg = await (legQuery.getOne(executor) as FutureOr); - expect(leg.name, originalLeg.name); - expect(leg.id, originalLeg.id); + expect(leg.name, originalLeg!.name); + expect(leg.id, originalLeg!.id); expect(leg.foot, isNotNull); - expect(leg.foot.id, foot.id); - expect(leg.foot.nToes, foot.nToes); + expect(leg.foot!.id, foot.id); + expect(leg.foot!.nToes, foot.nToes); }); test('only fetches one foot even if there are multiple', () async { var footQuery = new FootQuery() - ..values.legId = int.parse(originalLeg.id) + ..values.legId = int.parse(originalLeg!.id!) ..values.nToes = 24; - var legQuery = new LegQuery()..where.id.equals(int.parse(originalLeg.id)); - var foot = await footQuery.insert(executor); - var leg = await legQuery.getOne(executor); - expect(leg.name, originalLeg.name); - expect(leg.id, originalLeg.id); + var legQuery = new LegQuery()..where!.id.equals(int.parse(originalLeg!.id!)); + var foot = await (footQuery.insert(executor) as FutureOr); + var leg = await (legQuery.getOne(executor) as FutureOr); + expect(leg.name, originalLeg!.name); + expect(leg.id, originalLeg!.id); expect(leg.foot, isNotNull); - expect(leg.foot.id, foot.id); - expect(leg.foot.nToes, foot.nToes); + expect(leg.foot!.id, foot.id); + expect(leg.foot!.nToes, foot.nToes); }); test('sets foot on update', () async { var footQuery = new FootQuery() - ..values.legId = int.parse(originalLeg.id) + ..values.legId = int.parse(originalLeg!.id!) ..values.nToes = 5.64; var legQuery = new LegQuery() - ..where.id.equals(int.parse(originalLeg.id)) - ..values.copyFrom(originalLeg.copyWith(name: 'Right')); - var foot = await footQuery.insert(executor); - var leg = await legQuery.updateOne(executor); + ..where!.id.equals(int.parse(originalLeg!.id!)) + ..values.copyFrom(originalLeg!.copyWith(name: 'Right')); + var foot = await (footQuery.insert(executor) as FutureOr); + var leg = await (legQuery.updateOne(executor) as FutureOr); print(leg.toJson()); expect(leg.name, 'Right'); expect(leg.foot, isNotNull); - expect(leg.foot.id, foot.id); - expect(leg.foot.nToes, foot.nToes); + expect(leg.foot!.id, foot.id); + expect(leg.foot!.nToes, foot.nToes); }); test('sets foot on delete', () async { var footQuery = new FootQuery() - ..values.legId = int.parse(originalLeg.id) + ..values.legId = int.parse(originalLeg!.id!) ..values.nToes = 5.64; - var legQuery = new LegQuery()..where.id.equals(int.parse(originalLeg.id)); - var foot = await footQuery.insert(executor); - var leg = await legQuery.deleteOne(executor); + var legQuery = new LegQuery()..where!.id.equals(int.parse(originalLeg!.id!)); + var foot = await (footQuery.insert(executor) as FutureOr); + var leg = await (legQuery.deleteOne(executor) as FutureOr); print(leg.toJson()); - expect(leg.name, originalLeg.name); + expect(leg.name, originalLeg!.name); expect(leg.foot, isNotNull); - expect(leg.foot.id, foot.id); - expect(leg.foot.nToes, foot.nToes); + expect(leg.foot!.id, foot.id); + expect(leg.foot!.nToes, foot.nToes); }); test('sets null on false subquery', () async { var legQuery = new LegQuery() - ..where.id.equals(originalLeg.idAsInt) - ..foot.where.legId.equals(originalLeg.idAsInt + 1024); - var leg = await legQuery.getOne(executor); + ..where!.id.equals(originalLeg!.idAsInt!) + ..foot!.where!.legId.equals(originalLeg!.idAsInt! + 1024); + var leg = await (legQuery.getOne(executor) as FutureOr); expect(leg.foot, isNull); }); } diff --git a/packages/orm/angel_orm_test/lib/src/many_to_many_test.dart b/packages/orm/angel_orm_test/lib/src/many_to_many_test.dart index 531c88e3..ab8e4431 100644 --- a/packages/orm/angel_orm_test/lib/src/many_to_many_test.dart +++ b/packages/orm/angel_orm_test/lib/src/many_to_many_test.dart @@ -6,10 +6,10 @@ import 'models/user.dart'; import 'util.dart'; manyToManyTests(FutureOr Function() createExecutor, - {FutureOr Function(QueryExecutor) close}) { - QueryExecutor executor; - Role canPub, canSub; - User thosakwe; + {FutureOr Function(QueryExecutor)? close}) { + late QueryExecutor executor; + Role? canPub, canSub; + User? thosakwe; close ??= (_) => null; Future dumpQuery(String query) async { @@ -18,7 +18,8 @@ manyToManyTests(FutureOr Function() createExecutor, print('=================================================='); print(' DUMPING QUERY'); print(query); - var rows = await executor.query(null, query, {}); + //var rows = await executor.query(null, query, {}); + var rows = await executor.query('', query, {}); print('\n${rows.length} row(s):'); rows.forEach((r) => print(' * $r')); print('==================================================\n\n'); @@ -65,16 +66,16 @@ manyToManyTests(FutureOr Function() createExecutor, printSeparator('Allow thosakwe to publish'); var thosakwePubQuery = RoleUserQuery(); thosakwePubQuery.values - ..userId = int.parse(thosakwe.id) - ..roleId = int.parse(canPub.id); + ..userId = int.parse(thosakwe!.id!) + ..roleId = int.parse(canPub!.id!); await thosakwePubQuery.insert(executor); // Allow thosakwe to subscribe... printSeparator('Allow thosakwe to subscribe'); var thosakweSubQuery = RoleUserQuery(); thosakweSubQuery.values - ..userId = int.parse(thosakwe.id) - ..roleId = int.parse(canSub.id); + ..userId = int.parse(thosakwe!.id!) + ..roleId = int.parse(canSub!.id!); await thosakweSubQuery.insert(executor); // Print all users... @@ -90,16 +91,16 @@ manyToManyTests(FutureOr Function() createExecutor, print('==================================================\n\n'); }); - tearDown(() => close(executor)); + tearDown(() => close!(executor)); - Future fetchThosakwe() async { - var query = UserQuery()..where.id.equals(int.parse(thosakwe.id)); + Future fetchThosakwe() async { + var query = UserQuery()..where!.id.equals(int.parse(thosakwe!.id!)); return await query.getOne(executor); } test('fetch roles for user', () async { printSeparator('Fetch roles for user test'); - var user = await fetchThosakwe(); + var user = await (fetchThosakwe() as FutureOr); expect(user.roles, hasLength(2)); expect(user.roles, contains(canPub)); expect(user.roles, contains(canSub)); @@ -107,8 +108,8 @@ manyToManyTests(FutureOr Function() createExecutor, test('fetch users for role', () async { for (var role in [canPub, canSub]) { - var query = RoleQuery()..where.id.equals(role.idAsInt); - var r = await query.getOne(executor); + var query = RoleQuery()..where!.id.equals(role!.idAsInt!); + var r = await (query.getOne(executor) as FutureOr); expect(r.users.toList(), [thosakwe]); } }); @@ -121,12 +122,12 @@ manyToManyTests(FutureOr Function() createExecutor, ..username = 'Prince' ..password = 'Rogers' ..email = 'Nelson'; - var user = await userQuery.insert(executor); + var user = await (userQuery.insert(executor) as FutureOr); expect(user.roles, isEmpty); // Fetch again, just to be doubly sure. - var query = UserQuery()..where.id.equals(user.idAsInt); - var fetched = await query.getOne(executor); + var query = UserQuery()..where!.id.equals(user.idAsInt!); + var fetched = await (query.getOne(executor) as FutureOr); expect(fetched.roles, isEmpty); }); } diff --git a/packages/orm/angel_orm_test/lib/src/models/book.dart b/packages/orm/angel_orm_test/lib/src/models/book.dart index b89b171d..c7ed686f 100644 --- a/packages/orm/angel_orm_test/lib/src/models/book.dart +++ b/packages/orm/angel_orm_test/lib/src/models/book.dart @@ -10,12 +10,12 @@ part 'book.g.dart'; @orm class _Book extends Model { @BelongsTo(joinType: JoinType.inner) - _Author author; + _Author? author; @BelongsTo(localKey: "partner_author_id", joinType: JoinType.inner) - _Author partnerAuthor; + _Author? partnerAuthor; - String name; + String? name; } @serializable @@ -23,5 +23,5 @@ class _Book extends Model { abstract class _Author extends Model { @Column(length: 255, indexType: IndexType.unique) @SerializableField(defaultValue: 'Tobe Osakwe') - String get name; + String? get name; } 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 9b0d1bdf..4bfd7f4f 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 @@ -50,8 +50,8 @@ class AuthorMigration extends Migration { // OrmGenerator // ************************************************************************** -class BookQuery extends Query { - BookQuery({Query parent, Set trampoline}) : super(parent: parent) { +class BookQuery extends Query { + BookQuery({Query? parent, Set? trampoline}) : super(parent: parent) { trampoline ??= Set(); trampoline.add(tableName); _where = BookQueryWhere(this); @@ -68,11 +68,11 @@ class BookQuery extends Query { @override final BookQueryValues values = BookQueryValues(); - BookQueryWhere _where; + BookQueryWhere? _where; - AuthorQuery _author; + AuthorQuery? _author; - AuthorQuery _partnerAuthor; + AuthorQuery? _partnerAuthor; @override get casts { @@ -97,7 +97,7 @@ class BookQuery extends Query { } @override - BookQueryWhere get where { + BookQueryWhere? get where { return _where; } @@ -106,13 +106,13 @@ class BookQuery extends Query { return BookQueryWhere(this); } - static Book parseRow(List row) { + static Book? parseRow(List row) { if (row.every((x) => x == null)) return null; var model = Book( id: row[0].toString(), - createdAt: (row[1] as DateTime), - updatedAt: (row[2] as DateTime), - name: (row[5] as String)); + createdAt: (row[1] as DateTime?), + updatedAt: (row[2] as DateTime?), + name: (row[5] as String?)); if (row.length > 6) { model = model.copyWith( author: AuthorQuery.parseRow(row.skip(6).take(4).toList())); @@ -129,11 +129,11 @@ class BookQuery extends Query { return parseRow(row); } - AuthorQuery get author { + AuthorQuery? get author { return _author; } - AuthorQuery get partnerAuthor { + AuthorQuery? get partnerAuthor { return _partnerAuthor; } } @@ -172,51 +172,52 @@ class BookQueryValues extends MapQueryValues { return {}; } - String get id { - return (values['id'] as String); + String? get id { + return (values['id'] as String?); } - set id(String value) => values['id'] = value; - DateTime get createdAt { - return (values['created_at'] as DateTime); + set id(String? value) => values['id'] = value; + DateTime? get createdAt { + return (values['created_at'] as DateTime?); } - set createdAt(DateTime value) => values['created_at'] = value; - DateTime get updatedAt { - return (values['updated_at'] as DateTime); + set createdAt(DateTime? value) => values['created_at'] = value; + DateTime? get updatedAt { + return (values['updated_at'] as DateTime?); } - set updatedAt(DateTime value) => values['updated_at'] = value; - int get authorId { - return (values['author_id'] as int); + set updatedAt(DateTime? value) => values['updated_at'] = value; + int? get authorId { + return (values['author_id'] as int?); } - set authorId(int value) => values['author_id'] = value; - int get partnerAuthorId { - return (values['partner_author_id'] as int); + set authorId(int? value) => values['author_id'] = value; + int? get partnerAuthorId { + return (values['partner_author_id'] as int?); } - set partnerAuthorId(int value) => values['partner_author_id'] = value; - String get name { - return (values['name'] as String); + set partnerAuthorId(int? value) => values['partner_author_id'] = value; + String? get name { + return (values['name'] as String?); } - set name(String value) => values['name'] = value; + set name(String? value) => values['name'] = value; void copyFrom(Book model) { createdAt = model.createdAt; updatedAt = model.updatedAt; name = model.name; if (model.author != null) { - values['author_id'] = model.author.id; + values['author_id'] = model.author!.id; } if (model.partnerAuthor != null) { - values['partner_author_id'] = model.partnerAuthor.id; + values['partner_author_id'] = model.partnerAuthor!.id; } } } -class AuthorQuery extends Query { - AuthorQuery({Query parent, Set trampoline}) : super(parent: parent) { +class AuthorQuery extends Query { + AuthorQuery({Query? parent, Set? trampoline}) + : super(parent: parent) { trampoline ??= Set(); trampoline.add(tableName); _where = AuthorQueryWhere(this); @@ -225,7 +226,7 @@ class AuthorQuery extends Query { @override final AuthorQueryValues values = AuthorQueryValues(); - AuthorQueryWhere _where; + AuthorQueryWhere? _where; @override get casts { @@ -243,7 +244,7 @@ class AuthorQuery extends Query { } @override - AuthorQueryWhere get where { + AuthorQueryWhere? get where { return _where; } @@ -252,13 +253,13 @@ class AuthorQuery extends Query { return AuthorQueryWhere(this); } - static Author parseRow(List row) { + static Author? parseRow(List row) { if (row.every((x) => x == null)) return null; var model = Author( id: row[0].toString(), - createdAt: (row[1] as DateTime), - updatedAt: (row[2] as DateTime), - name: (row[3] as String)); + createdAt: (row[1] as DateTime?), + updatedAt: (row[2] as DateTime?), + name: (row[3] as String?)); return model; } @@ -295,26 +296,26 @@ class AuthorQueryValues extends MapQueryValues { return {}; } - String get id { - return (values['id'] as String); + String? get id { + return (values['id'] as String?); } - set id(String value) => values['id'] = value; - DateTime get createdAt { - return (values['created_at'] as DateTime); + set id(String? value) => values['id'] = value; + DateTime? get createdAt { + return (values['created_at'] as DateTime?); } - set createdAt(DateTime value) => values['created_at'] = value; - DateTime get updatedAt { - return (values['updated_at'] as DateTime); + set createdAt(DateTime? value) => values['created_at'] = value; + DateTime? get updatedAt { + return (values['updated_at'] as DateTime?); } - set updatedAt(DateTime value) => values['updated_at'] = value; - String get name { - return (values['name'] as String); + set updatedAt(DateTime? value) => values['updated_at'] = value; + String? get name { + return (values['name'] as String?); } - set name(String value) => values['name'] = value; + set name(String? value) => values['name'] = value; void copyFrom(Author model) { createdAt = model.createdAt; updatedAt = model.updatedAt; @@ -338,32 +339,32 @@ class Book extends _Book { /// A unique identifier corresponding to this item. @override - String id; + String? id; /// The time at which this item was created. @override - DateTime createdAt; + DateTime? createdAt; /// The last time at which this item was updated. @override - DateTime updatedAt; + DateTime? updatedAt; @override - _Author author; + _Author? author; @override - _Author partnerAuthor; + _Author? partnerAuthor; @override - String name; + String? name; Book copyWith( - {String id, - DateTime createdAt, - DateTime updatedAt, - _Author author, - _Author partnerAuthor, - String name}) { + {String? id, + DateTime? createdAt, + DateTime? updatedAt, + _Author? author, + _Author? partnerAuthor, + String? name}) { return Book( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -404,21 +405,21 @@ class Author extends _Author { /// A unique identifier corresponding to this item. @override - String id; + String? id; /// The time at which this item was created. @override - DateTime createdAt; + DateTime? createdAt; /// The last time at which this item was updated. @override - DateTime updatedAt; + DateTime? updatedAt; @override - final String name; + final String? name; Author copyWith( - {String id, DateTime createdAt, DateTime updatedAt, String name}) { + {String? id, DateTime? createdAt, DateTime? updatedAt, String? name}) { return Author( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -444,7 +445,7 @@ class Author extends _Author { return "Author(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, name=$name)"; } - Map toJson() { + Map? toJson() { return AuthorSerializer.toMap(this); } } @@ -478,15 +479,15 @@ class BookSerializer extends Codec { get decoder => const BookDecoder(); static Book fromMap(Map map) { return Book( - id: map['id'] as String, + id: map['id'] as String?, createdAt: map['created_at'] != null ? (map['created_at'] is DateTime - ? (map['created_at'] as DateTime) + ? (map['created_at'] as DateTime?) : DateTime.parse(map['created_at'].toString())) : null, updatedAt: map['updated_at'] != null ? (map['updated_at'] is DateTime - ? (map['updated_at'] as DateTime) + ? (map['updated_at'] as DateTime?) : DateTime.parse(map['updated_at'].toString())) : null, author: map['author'] != null @@ -495,13 +496,10 @@ class BookSerializer extends Codec { partnerAuthor: map['partner_author'] != null ? AuthorSerializer.fromMap(map['partner_author'] as Map) : null, - name: map['name'] as String); + name: map['name'] as String?); } static Map toMap(_Book model) { - if (model == null) { - return null; - } return { 'id': model.id, 'created_at': model.createdAt?.toIso8601String(), @@ -538,11 +536,11 @@ abstract class BookFields { const AuthorSerializer authorSerializer = AuthorSerializer(); -class AuthorEncoder extends Converter { +class AuthorEncoder extends Converter { const AuthorEncoder(); @override - Map convert(Author model) => AuthorSerializer.toMap(model); + Map? convert(Author model) => AuthorSerializer.toMap(model); } class AuthorDecoder extends Converter { @@ -552,7 +550,7 @@ class AuthorDecoder extends Converter { Author convert(Map map) => AuthorSerializer.fromMap(map); } -class AuthorSerializer extends Codec { +class AuthorSerializer extends Codec { const AuthorSerializer(); @override @@ -561,21 +559,21 @@ class AuthorSerializer extends Codec { get decoder => const AuthorDecoder(); static Author fromMap(Map map) { return Author( - id: map['id'] as String, + id: map['id'] as String?, createdAt: map['created_at'] != null ? (map['created_at'] is DateTime - ? (map['created_at'] as DateTime) + ? (map['created_at'] as DateTime?) : DateTime.parse(map['created_at'].toString())) : null, updatedAt: map['updated_at'] != null ? (map['updated_at'] is DateTime - ? (map['updated_at'] as DateTime) + ? (map['updated_at'] as DateTime?) : DateTime.parse(map['updated_at'].toString())) : null, - name: map['name'] as String ?? 'Tobe Osakwe'); + name: map['name'] as String? ?? 'Tobe Osakwe'); } - static Map toMap(_Author model) { + static Map? toMap(_Author? model) { if (model == null) { return null; } 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 a7f67dcd..6e225f30 100644 --- a/packages/orm/angel_orm_test/lib/src/models/car.dart +++ b/packages/orm/angel_orm_test/lib/src/models/car.dart @@ -9,8 +9,8 @@ part 'car.g.dart'; @serializable @orm class _Car extends Model { - String make; - String description; - bool familyFriendly; - DateTime recalledAt; + String? make; + String? description; + bool? familyFriendly; + DateTime? recalledAt; } 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 9de60a6b..a56ccf0a 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 @@ -30,8 +30,8 @@ class CarMigration extends Migration { // OrmGenerator // ************************************************************************** -class CarQuery extends Query { - CarQuery({Query parent, Set trampoline}) : super(parent: parent) { +class CarQuery extends Query { + CarQuery({Query? parent, Set? trampoline}) : super(parent: parent) { trampoline ??= Set(); trampoline.add(tableName); _where = CarQueryWhere(this); @@ -40,7 +40,7 @@ class CarQuery extends Query { @override final CarQueryValues values = CarQueryValues(); - CarQueryWhere _where; + CarQueryWhere? _where; @override get casts { @@ -66,7 +66,7 @@ class CarQuery extends Query { } @override - CarQueryWhere get where { + CarQueryWhere? get where { return _where; } @@ -75,16 +75,16 @@ class CarQuery extends Query { return CarQueryWhere(this); } - static Car parseRow(List row) { + static Car? parseRow(List row) { if (row.every((x) => x == null)) return null; var model = Car( id: row[0].toString(), - createdAt: (row[1] as DateTime), - updatedAt: (row[2] as DateTime), - make: (row[3] as String), - description: (row[4] as String), - familyFriendly: (row[5] as bool), - recalledAt: (row[6] as DateTime)); + createdAt: (row[1] as DateTime?), + updatedAt: (row[2] as DateTime?), + make: (row[3] as String?), + description: (row[4] as String?), + familyFriendly: (row[5] as bool?), + recalledAt: (row[6] as DateTime?)); return model; } @@ -138,41 +138,41 @@ class CarQueryValues extends MapQueryValues { return {}; } - String get id { - return (values['id'] as String); + String? get id { + return (values['id'] as String?); } - set id(String value) => values['id'] = value; - DateTime get createdAt { - return (values['created_at'] as DateTime); + set id(String? value) => values['id'] = value; + DateTime? get createdAt { + return (values['created_at'] as DateTime?); } - set createdAt(DateTime value) => values['created_at'] = value; - DateTime get updatedAt { - return (values['updated_at'] as DateTime); + set createdAt(DateTime? value) => values['created_at'] = value; + DateTime? get updatedAt { + return (values['updated_at'] as DateTime?); } - set updatedAt(DateTime value) => values['updated_at'] = value; - String get make { - return (values['make'] as String); + set updatedAt(DateTime? value) => values['updated_at'] = value; + String? get make { + return (values['make'] as String?); } - set make(String value) => values['make'] = value; - String get description { - return (values['description'] as String); + set make(String? value) => values['make'] = value; + String? get description { + return (values['description'] as String?); } - set description(String value) => values['description'] = value; - bool get familyFriendly { - return (values['family_friendly'] as bool); + set description(String? value) => values['description'] = value; + bool? get familyFriendly { + return (values['family_friendly'] as bool?); } - set familyFriendly(bool value) => values['family_friendly'] = value; - DateTime get recalledAt { - return (values['recalled_at'] as DateTime); + set familyFriendly(bool? value) => values['family_friendly'] = value; + DateTime? get recalledAt { + return (values['recalled_at'] as DateTime?); } - set recalledAt(DateTime value) => values['recalled_at'] = value; + set recalledAt(DateTime? value) => values['recalled_at'] = value; void copyFrom(Car model) { createdAt = model.createdAt; updatedAt = model.updatedAt; @@ -200,36 +200,36 @@ class Car extends _Car { /// A unique identifier corresponding to this item. @override - String id; + String? id; /// The time at which this item was created. @override - DateTime createdAt; + DateTime? createdAt; /// The last time at which this item was updated. @override - DateTime updatedAt; + DateTime? updatedAt; @override - String make; + String? make; @override - String description; + String? description; @override - bool familyFriendly; + bool? familyFriendly; @override - DateTime recalledAt; + DateTime? recalledAt; Car copyWith( - {String id, - DateTime createdAt, - DateTime updatedAt, - String make, - String description, - bool familyFriendly, - DateTime recalledAt}) { + {String? id, + DateTime? createdAt, + DateTime? updatedAt, + String? make, + String? description, + bool? familyFriendly, + DateTime? recalledAt}) { return Car( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -303,31 +303,28 @@ class CarSerializer extends Codec { get decoder => const CarDecoder(); static Car fromMap(Map map) { return Car( - id: map['id'] as String, + id: map['id'] as String?, createdAt: map['created_at'] != null ? (map['created_at'] is DateTime - ? (map['created_at'] as DateTime) + ? (map['created_at'] as DateTime?) : DateTime.parse(map['created_at'].toString())) : null, updatedAt: map['updated_at'] != null ? (map['updated_at'] is DateTime - ? (map['updated_at'] as DateTime) + ? (map['updated_at'] as DateTime?) : DateTime.parse(map['updated_at'].toString())) : null, - make: map['make'] as String, - description: map['description'] as String, - familyFriendly: map['family_friendly'] as bool, + make: map['make'] as String?, + description: map['description'] as String?, + familyFriendly: map['family_friendly'] as bool?, recalledAt: map['recalled_at'] != null ? (map['recalled_at'] is DateTime - ? (map['recalled_at'] as DateTime) + ? (map['recalled_at'] as DateTime?) : DateTime.parse(map['recalled_at'].toString())) : null); } static Map toMap(_Car model) { - if (model == null) { - return null; - } return { 'id': model.id, 'created_at': model.createdAt?.toIso8601String(), diff --git a/packages/orm/angel_orm_test/lib/src/models/custom_expr.dart b/packages/orm/angel_orm_test/lib/src/models/custom_expr.dart index 23f732a2..622c9201 100644 --- a/packages/orm/angel_orm_test/lib/src/models/custom_expr.dart +++ b/packages/orm/angel_orm_test/lib/src/models/custom_expr.dart @@ -8,14 +8,14 @@ part 'custom_expr.g.dart'; @orm class _Numbers extends Model { @Column(expression: 'SELECT 2') - int two; + int? two; } @serializable @orm class _Alphabet extends Model { - String value; + String? value; @belongsTo - _Numbers numbers; + _Numbers? numbers; } 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 c397d105..4aad11b5 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 @@ -46,8 +46,9 @@ class AlphabetMigration extends Migration { // OrmGenerator // ************************************************************************** -class NumbersQuery extends Query { - NumbersQuery({Query parent, Set trampoline}) : super(parent: parent) { +class NumbersQuery extends Query { + NumbersQuery({Query? parent, Set? trampoline}) + : super(parent: parent) { trampoline ??= Set(); trampoline.add(tableName); expressions['two'] = 'SELECT 2'; @@ -57,7 +58,7 @@ class NumbersQuery extends Query { @override final NumbersQueryValues values = NumbersQueryValues(); - NumbersQueryWhere _where; + NumbersQueryWhere? _where; @override get casts { @@ -75,7 +76,7 @@ class NumbersQuery extends Query { } @override - NumbersQueryWhere get where { + NumbersQueryWhere? get where { return _where; } @@ -84,13 +85,13 @@ class NumbersQuery extends Query { return NumbersQueryWhere(this); } - static Numbers parseRow(List row) { + static Numbers? parseRow(List row) { if (row.every((x) => x == null)) return null; var model = Numbers( id: row[0].toString(), - createdAt: (row[1] as DateTime), - updatedAt: (row[2] as DateTime), - two: (row[3] as int)); + createdAt: (row[1] as DateTime?), + updatedAt: (row[2] as DateTime?), + two: (row[3] as int?)); return model; } @@ -124,29 +125,29 @@ class NumbersQueryValues extends MapQueryValues { return {}; } - String get id { - return (values['id'] as String); + String? get id { + return (values['id'] as String?); } - set id(String value) => values['id'] = value; - DateTime get createdAt { - return (values['created_at'] as DateTime); + set id(String? value) => values['id'] = value; + DateTime? get createdAt { + return (values['created_at'] as DateTime?); } - set createdAt(DateTime value) => values['created_at'] = value; - DateTime get updatedAt { - return (values['updated_at'] as DateTime); + set createdAt(DateTime? value) => values['created_at'] = value; + DateTime? get updatedAt { + return (values['updated_at'] as DateTime?); } - set updatedAt(DateTime value) => values['updated_at'] = value; + set updatedAt(DateTime? value) => values['updated_at'] = value; void copyFrom(Numbers model) { createdAt = model.createdAt; updatedAt = model.updatedAt; } } -class AlphabetQuery extends Query { - AlphabetQuery({Query parent, Set trampoline}) +class AlphabetQuery extends Query { + AlphabetQuery({Query? parent, Set? trampoline}) : super(parent: parent) { trampoline ??= Set(); trampoline.add(tableName); @@ -160,9 +161,9 @@ class AlphabetQuery extends Query { @override final AlphabetQueryValues values = AlphabetQueryValues(); - AlphabetQueryWhere _where; + AlphabetQueryWhere? _where; - NumbersQuery _numbers; + NumbersQuery? _numbers; @override get casts { @@ -180,7 +181,7 @@ class AlphabetQuery extends Query { } @override - AlphabetQueryWhere get where { + AlphabetQueryWhere? get where { return _where; } @@ -189,13 +190,13 @@ class AlphabetQuery extends Query { return AlphabetQueryWhere(this); } - static Alphabet parseRow(List row) { + static Alphabet? parseRow(List row) { if (row.every((x) => x == null)) return null; var model = Alphabet( id: row[0].toString(), - createdAt: (row[1] as DateTime), - updatedAt: (row[2] as DateTime), - value: (row[3] as String)); + createdAt: (row[1] as DateTime?), + updatedAt: (row[2] as DateTime?), + value: (row[3] as String?)); if (row.length > 5) { model = model.copyWith( numbers: NumbersQuery.parseRow(row.skip(5).take(4).toList())); @@ -208,7 +209,7 @@ class AlphabetQuery extends Query { return parseRow(row); } - NumbersQuery get numbers { + NumbersQuery? get numbers { return _numbers; } } @@ -243,37 +244,37 @@ class AlphabetQueryValues extends MapQueryValues { return {}; } - String get id { - return (values['id'] as String); + String? get id { + return (values['id'] as String?); } - set id(String value) => values['id'] = value; - DateTime get createdAt { - return (values['created_at'] as DateTime); + set id(String? value) => values['id'] = value; + DateTime? get createdAt { + return (values['created_at'] as DateTime?); } - set createdAt(DateTime value) => values['created_at'] = value; - DateTime get updatedAt { - return (values['updated_at'] as DateTime); + set createdAt(DateTime? value) => values['created_at'] = value; + DateTime? get updatedAt { + return (values['updated_at'] as DateTime?); } - set updatedAt(DateTime value) => values['updated_at'] = value; - String get value { - return (values['value'] as String); + set updatedAt(DateTime? value) => values['updated_at'] = value; + String? get value { + return (values['value'] as String?); } - set value(String value) => values['value'] = value; - int get numbersId { - return (values['numbers_id'] as int); + set value(String? value) => values['value'] = value; + int? get numbersId { + return (values['numbers_id'] as int?); } - set numbersId(int value) => values['numbers_id'] = value; + set numbersId(int? value) => values['numbers_id'] = value; void copyFrom(Alphabet model) { createdAt = model.createdAt; updatedAt = model.updatedAt; value = model.value; if (model.numbers != null) { - values['numbers_id'] = model.numbers.id; + values['numbers_id'] = model.numbers!.id; } } } @@ -288,21 +289,21 @@ class Numbers extends _Numbers { /// A unique identifier corresponding to this item. @override - String id; + String? id; /// The time at which this item was created. @override - DateTime createdAt; + DateTime? createdAt; /// The last time at which this item was updated. @override - DateTime updatedAt; + DateTime? updatedAt; @override - int two; + int? two; Numbers copyWith( - {String id, DateTime createdAt, DateTime updatedAt, int two}) { + {String? id, DateTime? createdAt, DateTime? updatedAt, int? two}) { return Numbers( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -328,7 +329,7 @@ class Numbers extends _Numbers { return "Numbers(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, two=$two)"; } - Map toJson() { + Map? toJson() { return NumbersSerializer.toMap(this); } } @@ -339,28 +340,28 @@ class Alphabet extends _Alphabet { /// A unique identifier corresponding to this item. @override - String id; + String? id; /// The time at which this item was created. @override - DateTime createdAt; + DateTime? createdAt; /// The last time at which this item was updated. @override - DateTime updatedAt; + DateTime? updatedAt; @override - String value; + String? value; @override - _Numbers numbers; + _Numbers? numbers; Alphabet copyWith( - {String id, - DateTime createdAt, - DateTime updatedAt, - String value, - _Numbers numbers}) { + {String? id, + DateTime? createdAt, + DateTime? updatedAt, + String? value, + _Numbers? numbers}) { return Alphabet( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -399,11 +400,11 @@ class Alphabet extends _Alphabet { const NumbersSerializer numbersSerializer = NumbersSerializer(); -class NumbersEncoder extends Converter { +class NumbersEncoder extends Converter { const NumbersEncoder(); @override - Map convert(Numbers model) => NumbersSerializer.toMap(model); + Map? convert(Numbers model) => NumbersSerializer.toMap(model); } class NumbersDecoder extends Converter { @@ -413,7 +414,7 @@ class NumbersDecoder extends Converter { Numbers convert(Map map) => NumbersSerializer.fromMap(map); } -class NumbersSerializer extends Codec { +class NumbersSerializer extends Codec { const NumbersSerializer(); @override @@ -422,21 +423,21 @@ class NumbersSerializer extends Codec { get decoder => const NumbersDecoder(); static Numbers fromMap(Map map) { return Numbers( - id: map['id'] as String, + id: map['id'] as String?, createdAt: map['created_at'] != null ? (map['created_at'] is DateTime - ? (map['created_at'] as DateTime) + ? (map['created_at'] as DateTime?) : DateTime.parse(map['created_at'].toString())) : null, updatedAt: map['updated_at'] != null ? (map['updated_at'] is DateTime - ? (map['updated_at'] as DateTime) + ? (map['updated_at'] as DateTime?) : DateTime.parse(map['updated_at'].toString())) : null, - two: map['two'] as int); + two: map['two'] as int?); } - static Map toMap(_Numbers model) { + static Map? toMap(_Numbers? model) { if (model == null) { return null; } @@ -486,27 +487,24 @@ class AlphabetSerializer extends Codec { get decoder => const AlphabetDecoder(); static Alphabet fromMap(Map map) { return Alphabet( - id: map['id'] as String, + id: map['id'] as String?, createdAt: map['created_at'] != null ? (map['created_at'] is DateTime - ? (map['created_at'] as DateTime) + ? (map['created_at'] as DateTime?) : DateTime.parse(map['created_at'].toString())) : null, updatedAt: map['updated_at'] != null ? (map['updated_at'] is DateTime - ? (map['updated_at'] as DateTime) + ? (map['updated_at'] as DateTime?) : DateTime.parse(map['updated_at'].toString())) : null, - value: map['value'] as String, + value: map['value'] as String?, numbers: map['numbers'] != null ? NumbersSerializer.fromMap(map['numbers'] as Map) : null); } static Map toMap(_Alphabet model) { - if (model == null) { - return null; - } return { 'id': model.id, 'created_at': model.createdAt?.toIso8601String(), diff --git a/packages/orm/angel_orm_test/lib/src/models/email_indexed.dart b/packages/orm/angel_orm_test/lib/src/models/email_indexed.dart index 676bd12e..903541b7 100644 --- a/packages/orm/angel_orm_test/lib/src/models/email_indexed.dart +++ b/packages/orm/angel_orm_test/lib/src/models/email_indexed.dart @@ -9,20 +9,20 @@ part 'email_indexed.g.dart'; @orm abstract class _Role { @PrimaryKey(columnType: ColumnType.varChar) - String get role; + String? get role; @ManyToMany(_RoleUser) - List<_User> get users; + List<_User?>? get users; } @serializable @orm abstract class _RoleUser { @belongsTo - _Role get role; + _Role? get role; @belongsTo - _User get user; + _User? get user; } @serializable @@ -30,10 +30,10 @@ abstract class _RoleUser { abstract class _User { // @PrimaryKey(columnType: ColumnType.varChar) @primaryKey - String get email; - String get name; - String get password; + String? get email; + String? get name; + String? get password; @ManyToMany(_RoleUser) - List<_Role> get roles; + List<_Role?>? get roles; } 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 4933ad99..d7988a82 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 @@ -59,8 +59,8 @@ class UserMigration extends Migration { // OrmGenerator // ************************************************************************** -class RoleQuery extends Query { - RoleQuery({Query parent, Set trampoline}) : super(parent: parent) { +class RoleQuery extends Query { + RoleQuery({Query? parent, Set? trampoline}) : super(parent: parent) { trampoline ??= Set(); trampoline.add(tableName); _where = RoleQueryWhere(this); @@ -75,7 +75,7 @@ class RoleQuery extends Query { @override final RoleQueryValues values = RoleQueryValues(); - RoleQueryWhere _where; + RoleQueryWhere? _where; @override get casts { @@ -93,7 +93,7 @@ class RoleQuery extends Query { } @override - RoleQueryWhere get where { + RoleQueryWhere? get where { return _where; } @@ -102,9 +102,9 @@ class RoleQuery extends Query { return RoleQueryWhere(this); } - static Role parseRow(List row) { + static Role? parseRow(List row) { if (row.every((x) => x == null)) return null; - var model = Role(role: (row[0] as String)); + var model = Role(role: (row[0] as String?)); if (row.length > 1) { model = model.copyWith( users: [UserQuery.parseRow(row.skip(1).take(3).toList())] @@ -121,24 +121,24 @@ class RoleQuery extends Query { @override bool canCompile(trampoline) { - return (!(trampoline.contains('roles') && - trampoline.contains('role_users'))); + return (!(trampoline?.contains('roles') == true && + trampoline?.contains('role_users') == true)); } @override get(QueryExecutor executor) { return super.get(executor).then((result) { - return result.fold>([], (out, model) { - var idx = out.indexWhere((m) => m.role == model.role); + return result.fold>([], (out, model) { + var idx = out.indexWhere((m) => m!.role == model!.role); if (idx == -1) { return out..add(model); } else { - var l = out[idx]; + var l = out[idx]!; return out ..[idx] = l.copyWith( - users: List<_User>.from(l.users ?? []) - ..addAll(model.users ?? [])); + users: List<_User?>.from(l.users ?? []) + ..addAll(model!.users ?? [])); } }); }); @@ -147,17 +147,17 @@ class RoleQuery extends Query { @override update(QueryExecutor executor) { return super.update(executor).then((result) { - return result.fold>([], (out, model) { - var idx = out.indexWhere((m) => m.role == model.role); + return result.fold>([], (out, model) { + var idx = out.indexWhere((m) => m!.role == model!.role); if (idx == -1) { return out..add(model); } else { - var l = out[idx]; + var l = out[idx]!; return out ..[idx] = l.copyWith( - users: List<_User>.from(l.users ?? []) - ..addAll(model.users ?? [])); + users: List<_User?>.from(l.users ?? []) + ..addAll(model!.users ?? [])); } }); }); @@ -166,17 +166,17 @@ class RoleQuery extends Query { @override delete(QueryExecutor executor) { return super.delete(executor).then((result) { - return result.fold>([], (out, model) { - var idx = out.indexWhere((m) => m.role == model.role); + return result.fold>([], (out, model) { + var idx = out.indexWhere((m) => m!.role == model!.role); if (idx == -1) { return out..add(model); } else { - var l = out[idx]; + var l = out[idx]!; return out ..[idx] = l.copyWith( - users: List<_User>.from(l.users ?? []) - ..addAll(model.users ?? [])); + users: List<_User?>.from(l.users ?? []) + ..addAll(model!.users ?? [])); } }); }); @@ -201,18 +201,18 @@ class RoleQueryValues extends MapQueryValues { return {}; } - String get role { - return (values['role'] as String); + String? get role { + return (values['role'] as String?); } - set role(String value) => values['role'] = value; + set role(String? value) => values['role'] = value; void copyFrom(Role model) { role = model.role; } } -class RoleUserQuery extends Query { - RoleUserQuery({Query parent, Set trampoline}) +class RoleUserQuery extends Query { + RoleUserQuery({Query? parent, Set? trampoline}) : super(parent: parent) { trampoline ??= Set(); trampoline.add(tableName); @@ -229,11 +229,11 @@ class RoleUserQuery extends Query { @override final RoleUserQueryValues values = RoleUserQueryValues(); - RoleUserQueryWhere _where; + RoleUserQueryWhere? _where; - RoleQuery _role; + RoleQuery? _role; - UserQuery _user; + UserQuery? _user; @override get casts { @@ -251,7 +251,7 @@ class RoleUserQuery extends Query { } @override - RoleUserQueryWhere get where { + RoleUserQueryWhere? get where { return _where; } @@ -260,7 +260,7 @@ class RoleUserQuery extends Query { return RoleUserQueryWhere(this); } - static RoleUser parseRow(List row) { + static RoleUser? parseRow(List row) { if (row.every((x) => x == null)) return null; var model = RoleUser(); if (row.length > 2) { @@ -279,11 +279,11 @@ class RoleUserQuery extends Query { return parseRow(row); } - RoleQuery get role { + RoleQuery? get role { return _role; } - UserQuery get user { + UserQuery? get user { return _user; } } @@ -309,28 +309,28 @@ class RoleUserQueryValues extends MapQueryValues { return {}; } - String get roleRole { - return (values['role_role'] as String); + String? get roleRole { + return (values['role_role'] as String?); } - set roleRole(String value) => values['role_role'] = value; - String get userEmail { - return (values['user_email'] as String); + set roleRole(String? value) => values['role_role'] = value; + String? get userEmail { + return (values['user_email'] as String?); } - set userEmail(String value) => values['user_email'] = value; + set userEmail(String? value) => values['user_email'] = value; void copyFrom(RoleUser model) { if (model.role != null) { - values['role_role'] = model.role.role; + values['role_role'] = model.role!.role; } if (model.user != null) { - values['user_email'] = model.user.email; + values['user_email'] = model.user!.email; } } } -class UserQuery extends Query { - UserQuery({Query parent, Set trampoline}) : super(parent: parent) { +class UserQuery extends Query { + UserQuery({Query? parent, Set? trampoline}) : super(parent: parent) { trampoline ??= Set(); trampoline.add(tableName); _where = UserQueryWhere(this); @@ -345,7 +345,7 @@ class UserQuery extends Query { @override final UserQueryValues values = UserQueryValues(); - UserQueryWhere _where; + UserQueryWhere? _where; @override get casts { @@ -363,7 +363,7 @@ class UserQuery extends Query { } @override - UserQueryWhere get where { + UserQueryWhere? get where { return _where; } @@ -372,12 +372,12 @@ class UserQuery extends Query { return UserQueryWhere(this); } - static User parseRow(List row) { + static User? parseRow(List row) { if (row.every((x) => x == null)) return null; var model = User( - email: (row[0] as String), - name: (row[1] as String), - password: (row[2] as String)); + email: (row[0] as String?), + name: (row[1] as String?), + password: (row[2] as String?)); if (row.length > 3) { model = model.copyWith( roles: [RoleQuery.parseRow(row.skip(3).take(1).toList())] @@ -394,24 +394,24 @@ class UserQuery extends Query { @override bool canCompile(trampoline) { - return (!(trampoline.contains('users') && - trampoline.contains('role_users'))); + return (!(trampoline?.contains('users') == true && + trampoline?.contains('role_users') == true)); } @override get(QueryExecutor executor) { return super.get(executor).then((result) { - return result.fold>([], (out, model) { - var idx = out.indexWhere((m) => m.email == model.email); + return result.fold>([], (out, model) { + var idx = out.indexWhere((m) => m!.email == model!.email); if (idx == -1) { return out..add(model); } else { - var l = out[idx]; + var l = out[idx]!; return out ..[idx] = l.copyWith( - roles: List<_Role>.from(l.roles ?? []) - ..addAll(model.roles ?? [])); + roles: List<_Role?>.from(l.roles ?? []) + ..addAll(model!.roles ?? [])); } }); }); @@ -420,17 +420,17 @@ class UserQuery extends Query { @override update(QueryExecutor executor) { return super.update(executor).then((result) { - return result.fold>([], (out, model) { - var idx = out.indexWhere((m) => m.email == model.email); + return result.fold>([], (out, model) { + var idx = out.indexWhere((m) => m!.email == model!.email); if (idx == -1) { return out..add(model); } else { - var l = out[idx]; + var l = out[idx]!; return out ..[idx] = l.copyWith( - roles: List<_Role>.from(l.roles ?? []) - ..addAll(model.roles ?? [])); + roles: List<_Role?>.from(l.roles ?? []) + ..addAll(model!.roles ?? [])); } }); }); @@ -439,17 +439,17 @@ class UserQuery extends Query { @override delete(QueryExecutor executor) { return super.delete(executor).then((result) { - return result.fold>([], (out, model) { - var idx = out.indexWhere((m) => m.email == model.email); + return result.fold>([], (out, model) { + var idx = out.indexWhere((m) => m!.email == model!.email); if (idx == -1) { return out..add(model); } else { - var l = out[idx]; + var l = out[idx]!; return out ..[idx] = l.copyWith( - roles: List<_Role>.from(l.roles ?? []) - ..addAll(model.roles ?? [])); + roles: List<_Role?>.from(l.roles ?? []) + ..addAll(model!.roles ?? [])); } }); }); @@ -480,21 +480,21 @@ class UserQueryValues extends MapQueryValues { return {}; } - String get email { - return (values['email'] as String); + String? get email { + return (values['email'] as String?); } - set email(String value) => values['email'] = value; - String get name { - return (values['name'] as String); + set email(String? value) => values['email'] = value; + String? get name { + return (values['name'] as String?); } - set name(String value) => values['name'] = value; - String get password { - return (values['password'] as String); + set name(String? value) => values['name'] = value; + String? get password { + return (values['password'] as String?); } - set password(String value) => values['password'] = value; + set password(String? value) => values['password'] = value; void copyFrom(User model) { email = model.email; name = model.name; @@ -511,19 +511,19 @@ class Role implements _Role { const Role({this.role, this.users}); @override - final String role; + final String? role; @override - final List<_User> users; + final 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); } bool operator ==(other) { return other is _Role && other.role == role && - ListEquality<_User>(DefaultEquality<_User>()) + ListEquality<_User?>(DefaultEquality<_User>()) .equals(other.users, users); } @@ -537,7 +537,7 @@ class Role implements _Role { return "Role(role=$role, users=$users)"; } - Map toJson() { + Map? toJson() { return RoleSerializer.toMap(this); } } @@ -547,12 +547,12 @@ class RoleUser implements _RoleUser { const RoleUser({this.role, this.user}); @override - final _Role role; + final _Role? role; @override - final _User user; + final _User? user; - RoleUser copyWith({_Role role, _User user}) { + RoleUser copyWith({_Role? role, _User? user}) { return RoleUser(role: role ?? this.role, user: user ?? this.user); } @@ -580,19 +580,19 @@ class User implements _User { const User({this.email, this.name, this.password, this.roles}); @override - final String email; + final String? email; @override - final String name; + final String? name; @override - final String password; + final String? password; @override - final List<_Role> roles; + final List<_Role?>? roles; User copyWith( - {String email, String name, String password, List<_Role> roles}) { + {String? email, String? name, String? password, List<_Role?>? roles}) { return User( email: email ?? this.email, name: name ?? this.name, @@ -605,7 +605,7 @@ class User implements _User { other.email == email && other.name == name && other.password == password && - ListEquality<_Role>(DefaultEquality<_Role>()) + ListEquality<_Role?>(DefaultEquality<_Role>()) .equals(other.roles, roles); } @@ -619,7 +619,7 @@ class User implements _User { return "User(email=$email, name=$name, password=$password, roles=$roles)"; } - Map toJson() { + Map? toJson() { return UserSerializer.toMap(this); } } @@ -630,11 +630,11 @@ class User implements _User { const RoleSerializer roleSerializer = RoleSerializer(); -class RoleEncoder extends Converter { +class RoleEncoder extends Converter { const RoleEncoder(); @override - Map convert(Role model) => RoleSerializer.toMap(model); + Map? convert(Role model) => RoleSerializer.toMap(model); } class RoleDecoder extends Converter { @@ -644,7 +644,7 @@ class RoleDecoder extends Converter { Role convert(Map map) => RoleSerializer.fromMap(map); } -class RoleSerializer extends Codec { +class RoleSerializer extends Codec { const RoleSerializer(); @override @@ -653,20 +653,20 @@ class RoleSerializer extends Codec { get decoder => const RoleDecoder(); static Role fromMap(Map map) { return Role( - role: map['role'] as String, + role: map['role'] as String?, users: map['users'] is Iterable ? List.unmodifiable(((map['users'] as Iterable).whereType()) .map(UserSerializer.fromMap)) : null); } - static Map toMap(_Role model) { + static Map? toMap(_Role? model) { if (model == null) { return null; } return { 'role': model.role, - 'users': model.users?.map((m) => UserSerializer.toMap(m))?.toList() + 'users': model.users?.map((m) => UserSerializer.toMap(m)).toList() }; } } @@ -713,9 +713,6 @@ class RoleUserSerializer extends Codec { } static Map toMap(_RoleUser model) { - if (model == null) { - return null; - } return { 'role': RoleSerializer.toMap(model.role), 'user': UserSerializer.toMap(model.user) @@ -733,11 +730,11 @@ abstract class RoleUserFields { const UserSerializer userSerializer = UserSerializer(); -class UserEncoder extends Converter { +class UserEncoder extends Converter { const UserEncoder(); @override - Map convert(User model) => UserSerializer.toMap(model); + Map? convert(User model) => UserSerializer.toMap(model); } class UserDecoder extends Converter { @@ -747,7 +744,7 @@ class UserDecoder extends Converter { User convert(Map map) => UserSerializer.fromMap(map); } -class UserSerializer extends Codec { +class UserSerializer extends Codec { const UserSerializer(); @override @@ -756,16 +753,16 @@ class UserSerializer extends Codec { get decoder => const UserDecoder(); static User fromMap(Map map) { return User( - email: map['email'] as String, - name: map['name'] as String, - password: map['password'] as String, + email: map['email'] as String?, + name: map['name'] as String?, + password: map['password'] as String?, roles: map['roles'] is Iterable ? List.unmodifiable(((map['roles'] as Iterable).whereType()) .map(RoleSerializer.fromMap)) : null); } - static Map toMap(_User model) { + static Map? toMap(_User? model) { if (model == null) { return null; } @@ -773,7 +770,7 @@ class UserSerializer extends Codec { 'email': model.email, 'name': model.name, 'password': model.password, - 'roles': model.roles?.map((m) => RoleSerializer.toMap(m))?.toList() + 'roles': model.roles?.map((m) => RoleSerializer.toMap(m)).toList() }; } } diff --git a/packages/orm/angel_orm_test/lib/src/models/has_car.dart b/packages/orm/angel_orm_test/lib/src/models/has_car.dart index 6a6e6b64..0e70f87a 100644 --- a/packages/orm/angel_orm_test/lib/src/models/has_car.dart +++ b/packages/orm/angel_orm_test/lib/src/models/has_car.dart @@ -20,5 +20,5 @@ abstract class _HasCar extends Model { // Car get car; @SerializableField(isNullable: false, defaultValue: CarType.sedan) - CarType get type; + CarType? get type; } 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 b8adf3d5..d8e7de73 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 @@ -27,8 +27,9 @@ class HasCarMigration extends Migration { // OrmGenerator // ************************************************************************** -class HasCarQuery extends Query { - HasCarQuery({Query parent, Set trampoline}) : super(parent: parent) { +class HasCarQuery extends Query { + HasCarQuery({Query? parent, Set? trampoline}) + : super(parent: parent) { trampoline ??= Set(); trampoline.add(tableName); _where = HasCarQueryWhere(this); @@ -37,7 +38,7 @@ class HasCarQuery extends Query { @override final HasCarQueryValues values = HasCarQueryValues(); - HasCarQueryWhere _where; + HasCarQueryWhere? _where; @override get casts { @@ -55,7 +56,7 @@ class HasCarQuery extends Query { } @override - HasCarQueryWhere get where { + HasCarQueryWhere? get where { return _where; } @@ -64,12 +65,12 @@ class HasCarQuery extends Query { return HasCarQueryWhere(this); } - static HasCar parseRow(List row) { + static HasCar? parseRow(List row) { if (row.every((x) => x == null)) return null; var model = HasCar( id: row[0].toString(), - createdAt: (row[1] as DateTime), - updatedAt: (row[2] as DateTime), + createdAt: (row[1] as DateTime?), + updatedAt: (row[2] as DateTime?), type: row[3] == null ? null : CarType.values[(row[3] as int)]); return model; } @@ -85,7 +86,8 @@ class HasCarQueryWhere extends QueryWhere { : id = NumericSqlExpressionBuilder(query, 'id'), createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'), - type = EnumSqlExpressionBuilder(query, 'type', (v) => v.index); + type = + EnumSqlExpressionBuilder(query, 'type', (v) => v!.index); final NumericSqlExpressionBuilder id; @@ -93,7 +95,7 @@ class HasCarQueryWhere extends QueryWhere { final DateTimeSqlExpressionBuilder updatedAt; - final EnumSqlExpressionBuilder type; + final EnumSqlExpressionBuilder type; @override get expressionBuilders { @@ -107,26 +109,26 @@ class HasCarQueryValues extends MapQueryValues { return {}; } - String get id { - return (values['id'] as String); + String? get id { + return (values['id'] as String?); } - set id(String value) => values['id'] = value; - DateTime get createdAt { - return (values['created_at'] as DateTime); + set id(String? value) => values['id'] = value; + DateTime? get createdAt { + return (values['created_at'] as DateTime?); } - set createdAt(DateTime value) => values['created_at'] = value; - DateTime get updatedAt { - return (values['updated_at'] as DateTime); + set createdAt(DateTime? value) => values['created_at'] = value; + DateTime? get updatedAt { + return (values['updated_at'] as DateTime?); } - set updatedAt(DateTime value) => values['updated_at'] = value; + set updatedAt(DateTime? value) => values['updated_at'] = value; CarType get type { return CarType.values[(values['type'] as int)]; } - set type(CarType value) => values['type'] = value?.index; + set type(CarType? value) => values['type'] = value?.index; void copyFrom(HasCar model) { createdAt = model.createdAt; updatedAt = model.updatedAt; @@ -144,21 +146,21 @@ class HasCar extends _HasCar { /// A unique identifier corresponding to this item. @override - String id; + String? id; /// The time at which this item was created. @override - DateTime createdAt; + DateTime? createdAt; /// The last time at which this item was updated. @override - DateTime updatedAt; + DateTime? updatedAt; @override - final CarType type; + final CarType? type; HasCar copyWith( - {String id, DateTime createdAt, DateTime updatedAt, CarType type}) { + {String? id, DateTime? createdAt, DateTime? updatedAt, CarType? type}) { return HasCar( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -222,28 +224,25 @@ class HasCarSerializer extends Codec { } return HasCar( - id: map['id'] as String, + id: map['id'] as String?, createdAt: map['created_at'] != null ? (map['created_at'] is DateTime - ? (map['created_at'] as DateTime) + ? (map['created_at'] as DateTime?) : DateTime.parse(map['created_at'].toString())) : null, updatedAt: map['updated_at'] != null ? (map['updated_at'] is DateTime - ? (map['updated_at'] as DateTime) + ? (map['updated_at'] as DateTime?) : DateTime.parse(map['updated_at'].toString())) : null, type: map['type'] is CarType - ? (map['type'] as CarType) + ? (map['type'] as CarType?) : (map['type'] is int ? CarType.values[map['type'] as int] : CarType.sedan)); } static Map toMap(_HasCar model) { - if (model == null) { - return null; - } if (model.type == null) { throw FormatException("Missing required field 'type' on HasCar."); } @@ -252,7 +251,7 @@ class HasCarSerializer extends Codec { 'id': model.id, 'created_at': model.createdAt?.toIso8601String(), 'updated_at': model.updatedAt?.toIso8601String(), - 'type': model.type == null ? null : CarType.values.indexOf(model.type) + 'type': model.type == null ? null : CarType.values.indexOf(model.type!) }; } } diff --git a/packages/orm/angel_orm_test/lib/src/models/has_map.dart b/packages/orm/angel_orm_test/lib/src/models/has_map.dart index f98de5a7..c4452371 100644 --- a/packages/orm/angel_orm_test/lib/src/models/has_map.dart +++ b/packages/orm/angel_orm_test/lib/src/models/has_map.dart @@ -11,9 +11,9 @@ part 'has_map.g.dart'; @orm @serializable abstract class _HasMap { - Map get value; + Map? get value; - List get list; + List? get list; // TODO: Support custom serializers // @SerializableField( 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 71a612f7..6d6cd544 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 @@ -25,8 +25,9 @@ class HasMapMigration extends Migration { // OrmGenerator // ************************************************************************** -class HasMapQuery extends Query { - HasMapQuery({Query parent, Set trampoline}) : super(parent: parent) { +class HasMapQuery extends Query { + HasMapQuery({Query? parent, Set? trampoline}) + : super(parent: parent) { trampoline ??= Set(); trampoline.add(tableName); _where = HasMapQueryWhere(this); @@ -35,7 +36,7 @@ class HasMapQuery extends Query { @override final HasMapQueryValues values = HasMapQueryValues(); - HasMapQueryWhere _where; + HasMapQueryWhere? _where; @override get casts { @@ -53,7 +54,7 @@ class HasMapQuery extends Query { } @override - HasMapQueryWhere get where { + HasMapQueryWhere? get where { return _where; } @@ -62,11 +63,11 @@ class HasMapQuery extends Query { return HasMapQueryWhere(this); } - static HasMap parseRow(List row) { + static HasMap? parseRow(List row) { if (row.every((x) => x == null)) return null; var model = HasMap( - value: (row[0] as Map), - list: (row[1] as List)); + value: (row[0] as Map?), + list: (row[1] as List?)); return model; } @@ -97,16 +98,16 @@ class HasMapQueryValues extends MapQueryValues { return {'list': 'jsonb'}; } - Map get value { - return (values['value'] as Map); + Map? get value { + return (values['value'] as Map?); } - set value(Map value) => values['value'] = value; - List get list { - return (json.decode((values['list'] as String)) as List); + set value(Map? value) => values['value'] = value; + List? get list { + return (json.decode((values['list'] as String)) as List?); } - set list(List value) => values['list'] = json.encode(value); + set list(List? value) => values['list'] = json.encode(value); void copyFrom(HasMap model) { value = model.value; list = model.list; @@ -122,12 +123,12 @@ class HasMap implements _HasMap { const HasMap({this.value, this.list}); @override - final Map value; + final Map? value; @override - final List list; + final List? list; - HasMap copyWith({Map value, List list}) { + HasMap copyWith({Map? value, List? list}) { return HasMap(value: value ?? this.value, list: list ?? this.list); } @@ -192,9 +193,6 @@ class HasMapSerializer extends Codec { } static Map toMap(_HasMap model) { - if (model == null) { - return null; - } return {'value': model.value, 'list': model.list}; } } diff --git a/packages/orm/angel_orm_test/lib/src/models/leg.dart b/packages/orm/angel_orm_test/lib/src/models/leg.dart index 1c7339ad..068584a0 100644 --- a/packages/orm/angel_orm_test/lib/src/models/leg.dart +++ b/packages/orm/angel_orm_test/lib/src/models/leg.dart @@ -10,15 +10,15 @@ part 'leg.g.dart'; @orm class _Leg extends Model { @hasOne - _Foot foot; + _Foot? foot; - String name; + String? name; } @serializable @Orm(tableName: 'feet') class _Foot extends Model { - int legId; + int? legId; - double nToes; + double? nToes; } 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 1575ddfb..73f30efe 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 @@ -45,8 +45,8 @@ class FootMigration extends Migration { // OrmGenerator // ************************************************************************** -class LegQuery extends Query { - LegQuery({Query parent, Set trampoline}) : super(parent: parent) { +class LegQuery extends Query { + LegQuery({Query? parent, Set? trampoline}) : super(parent: parent) { trampoline ??= Set(); trampoline.add(tableName); _where = LegQueryWhere(this); @@ -65,9 +65,9 @@ class LegQuery extends Query { @override final LegQueryValues values = LegQueryValues(); - LegQueryWhere _where; + LegQueryWhere? _where; - FootQuery _foot; + FootQuery? _foot; @override get casts { @@ -85,7 +85,7 @@ class LegQuery extends Query { } @override - LegQueryWhere get where { + LegQueryWhere? get where { return _where; } @@ -94,13 +94,13 @@ class LegQuery extends Query { return LegQueryWhere(this); } - static Leg parseRow(List row) { + static Leg? parseRow(List row) { if (row.every((x) => x == null)) return null; var model = Leg( id: row[0].toString(), - createdAt: (row[1] as DateTime), - updatedAt: (row[2] as DateTime), - name: (row[3] as String)); + createdAt: (row[1] as DateTime?), + updatedAt: (row[2] as DateTime?), + name: (row[3] as String?)); if (row.length > 4) { model = model.copyWith( foot: FootQuery.parseRow(row.skip(4).take(5).toList())); @@ -113,7 +113,7 @@ class LegQuery extends Query { return parseRow(row); } - FootQuery get foot { + FootQuery? get foot { return _foot; } } @@ -145,26 +145,26 @@ class LegQueryValues extends MapQueryValues { return {}; } - String get id { - return (values['id'] as String); + String? get id { + return (values['id'] as String?); } - set id(String value) => values['id'] = value; - DateTime get createdAt { - return (values['created_at'] as DateTime); + set id(String? value) => values['id'] = value; + DateTime? get createdAt { + return (values['created_at'] as DateTime?); } - set createdAt(DateTime value) => values['created_at'] = value; - DateTime get updatedAt { - return (values['updated_at'] as DateTime); + set createdAt(DateTime? value) => values['created_at'] = value; + DateTime? get updatedAt { + return (values['updated_at'] as DateTime?); } - set updatedAt(DateTime value) => values['updated_at'] = value; - String get name { - return (values['name'] as String); + set updatedAt(DateTime? value) => values['updated_at'] = value; + String? get name { + return (values['name'] as String?); } - set name(String value) => values['name'] = value; + set name(String? value) => values['name'] = value; void copyFrom(Leg model) { createdAt = model.createdAt; updatedAt = model.updatedAt; @@ -172,8 +172,8 @@ class LegQueryValues extends MapQueryValues { } } -class FootQuery extends Query { - FootQuery({Query parent, Set trampoline}) : super(parent: parent) { +class FootQuery extends Query { + FootQuery({Query? parent, Set? trampoline}) : super(parent: parent) { trampoline ??= Set(); trampoline.add(tableName); _where = FootQueryWhere(this); @@ -182,7 +182,7 @@ class FootQuery extends Query { @override final FootQueryValues values = FootQueryValues(); - FootQueryWhere _where; + FootQueryWhere? _where; @override get casts { @@ -200,7 +200,7 @@ class FootQuery extends Query { } @override - FootQueryWhere get where { + FootQueryWhere? get where { return _where; } @@ -209,13 +209,13 @@ class FootQuery extends Query { return FootQueryWhere(this); } - static Foot parseRow(List row) { + static Foot? parseRow(List row) { if (row.every((x) => x == null)) return null; var model = Foot( id: row[0].toString(), - createdAt: (row[1] as DateTime), - updatedAt: (row[2] as DateTime), - legId: (row[3] as int), + createdAt: (row[1] as DateTime?), + updatedAt: (row[2] as DateTime?), + legId: (row[3] as int?), nToes: double.tryParse(row[4].toString())); return model; } @@ -256,31 +256,31 @@ class FootQueryValues extends MapQueryValues { return {'n_toes': 'decimal'}; } - String get id { - return (values['id'] as String); + String? get id { + return (values['id'] as String?); } - set id(String value) => values['id'] = value; - DateTime get createdAt { - return (values['created_at'] as DateTime); + set id(String? value) => values['id'] = value; + DateTime? get createdAt { + return (values['created_at'] as DateTime?); } - set createdAt(DateTime value) => values['created_at'] = value; - DateTime get updatedAt { - return (values['updated_at'] as DateTime); + set createdAt(DateTime? value) => values['created_at'] = value; + DateTime? get updatedAt { + return (values['updated_at'] as DateTime?); } - set updatedAt(DateTime value) => values['updated_at'] = value; - int get legId { - return (values['leg_id'] as int); + set updatedAt(DateTime? value) => values['updated_at'] = value; + int? get legId { + return (values['leg_id'] as int?); } - set legId(int value) => values['leg_id'] = value; - double get nToes { + set legId(int? value) => values['leg_id'] = value; + double? get nToes { return double.tryParse((values['n_toes'] as String)); } - set nToes(double value) => values['n_toes'] = value.toString(); + set nToes(double? value) => values['n_toes'] = value.toString(); void copyFrom(Foot model) { createdAt = model.createdAt; updatedAt = model.updatedAt; @@ -299,28 +299,28 @@ class Leg extends _Leg { /// A unique identifier corresponding to this item. @override - String id; + String? id; /// The time at which this item was created. @override - DateTime createdAt; + DateTime? createdAt; /// The last time at which this item was updated. @override - DateTime updatedAt; + DateTime? updatedAt; @override - _Foot foot; + _Foot? foot; @override - String name; + String? name; Leg copyWith( - {String id, - DateTime createdAt, - DateTime updatedAt, - _Foot foot, - String name}) { + {String? id, + DateTime? createdAt, + DateTime? updatedAt, + _Foot? foot, + String? name}) { return Leg( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -359,28 +359,28 @@ class Foot extends _Foot { /// A unique identifier corresponding to this item. @override - String id; + String? id; /// The time at which this item was created. @override - DateTime createdAt; + DateTime? createdAt; /// The last time at which this item was updated. @override - DateTime updatedAt; + DateTime? updatedAt; @override - int legId; + int? legId; @override - double nToes; + double? nToes; Foot copyWith( - {String id, - DateTime createdAt, - DateTime updatedAt, - int legId, - double nToes}) { + {String? id, + DateTime? createdAt, + DateTime? updatedAt, + int? legId, + double? nToes}) { return Foot( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -408,7 +408,7 @@ class Foot extends _Foot { return "Foot(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, legId=$legId, nToes=$nToes)"; } - Map toJson() { + Map? toJson() { return FootSerializer.toMap(this); } } @@ -442,27 +442,24 @@ class LegSerializer extends Codec { get decoder => const LegDecoder(); static Leg fromMap(Map map) { return Leg( - id: map['id'] as String, + id: map['id'] as String?, createdAt: map['created_at'] != null ? (map['created_at'] is DateTime - ? (map['created_at'] as DateTime) + ? (map['created_at'] as DateTime?) : DateTime.parse(map['created_at'].toString())) : null, updatedAt: map['updated_at'] != null ? (map['updated_at'] is DateTime - ? (map['updated_at'] as DateTime) + ? (map['updated_at'] as DateTime?) : DateTime.parse(map['updated_at'].toString())) : null, foot: map['foot'] != null ? FootSerializer.fromMap(map['foot'] as Map) : null, - name: map['name'] as String); + name: map['name'] as String?); } static Map toMap(_Leg model) { - if (model == null) { - return null; - } return { 'id': model.id, 'created_at': model.createdAt?.toIso8601String(), @@ -495,11 +492,11 @@ abstract class LegFields { const FootSerializer footSerializer = FootSerializer(); -class FootEncoder extends Converter { +class FootEncoder extends Converter { const FootEncoder(); @override - Map convert(Foot model) => FootSerializer.toMap(model); + Map? convert(Foot model) => FootSerializer.toMap(model); } class FootDecoder extends Converter { @@ -509,7 +506,7 @@ class FootDecoder extends Converter { Foot convert(Map map) => FootSerializer.fromMap(map); } -class FootSerializer extends Codec { +class FootSerializer extends Codec { const FootSerializer(); @override @@ -518,22 +515,22 @@ class FootSerializer extends Codec { get decoder => const FootDecoder(); static Foot fromMap(Map map) { return Foot( - id: map['id'] as String, + id: map['id'] as String?, createdAt: map['created_at'] != null ? (map['created_at'] is DateTime - ? (map['created_at'] as DateTime) + ? (map['created_at'] as DateTime?) : DateTime.parse(map['created_at'].toString())) : null, updatedAt: map['updated_at'] != null ? (map['updated_at'] is DateTime - ? (map['updated_at'] as DateTime) + ? (map['updated_at'] as DateTime?) : DateTime.parse(map['updated_at'].toString())) : null, - legId: map['leg_id'] as int, - nToes: map['n_toes'] as double); + legId: map['leg_id'] as int?, + nToes: map['n_toes'] as double?); } - static Map toMap(_Foot model) { + static Map? toMap(_Foot? model) { if (model == null) { return null; } diff --git a/packages/orm/angel_orm_test/lib/src/models/order.dart b/packages/orm/angel_orm_test/lib/src/models/order.dart index 90f6a07a..fb3c5cca 100644 --- a/packages/orm/angel_orm_test/lib/src/models/order.dart +++ b/packages/orm/angel_orm_test/lib/src/models/order.dart @@ -10,13 +10,13 @@ part 'order.g.dart'; @serializable abstract class _Order extends Model { @belongsTo - _Customer get customer; + _Customer? get customer; - int get employeeId; + int? get employeeId; - DateTime get orderDate; + DateTime? get orderDate; - int get shipperId; + int? get shipperId; } @orm 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 edff71ca..305fea87 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 @@ -48,8 +48,8 @@ class CustomerMigration extends Migration { // OrmGenerator // ************************************************************************** -class OrderQuery extends Query { - OrderQuery({Query parent, Set trampoline}) : super(parent: parent) { +class OrderQuery extends Query { + OrderQuery({Query? parent, Set? trampoline}) : super(parent: parent) { trampoline ??= Set(); trampoline.add(tableName); _where = OrderQueryWhere(this); @@ -62,9 +62,9 @@ class OrderQuery extends Query { @override final OrderQueryValues values = OrderQueryValues(); - OrderQueryWhere _where; + OrderQueryWhere? _where; - CustomerQuery _customer; + CustomerQuery? _customer; @override get casts { @@ -90,7 +90,7 @@ class OrderQuery extends Query { } @override - OrderQueryWhere get where { + OrderQueryWhere? get where { return _where; } @@ -99,15 +99,15 @@ class OrderQuery extends Query { return OrderQueryWhere(this); } - static Order parseRow(List row) { + static Order? parseRow(List row) { if (row.every((x) => x == null)) return null; var model = Order( id: row[0].toString(), - createdAt: (row[1] as DateTime), - updatedAt: (row[2] as DateTime), - employeeId: (row[4] as int), - orderDate: (row[5] as DateTime), - shipperId: (row[6] as int)); + createdAt: (row[1] as DateTime?), + updatedAt: (row[2] as DateTime?), + employeeId: (row[4] as int?), + orderDate: (row[5] as DateTime?), + shipperId: (row[6] as int?)); if (row.length > 7) { model = model.copyWith( customer: CustomerQuery.parseRow(row.skip(7).take(3).toList())); @@ -120,7 +120,7 @@ class OrderQuery extends Query { return parseRow(row); } - CustomerQuery get customer { + CustomerQuery? get customer { return _customer; } } @@ -169,41 +169,41 @@ class OrderQueryValues extends MapQueryValues { return {}; } - String get id { - return (values['id'] as String); + String? get id { + return (values['id'] as String?); } - set id(String value) => values['id'] = value; - DateTime get createdAt { - return (values['created_at'] as DateTime); + set id(String? value) => values['id'] = value; + DateTime? get createdAt { + return (values['created_at'] as DateTime?); } - set createdAt(DateTime value) => values['created_at'] = value; - DateTime get updatedAt { - return (values['updated_at'] as DateTime); + set createdAt(DateTime? value) => values['created_at'] = value; + DateTime? get updatedAt { + return (values['updated_at'] as DateTime?); } - set updatedAt(DateTime value) => values['updated_at'] = value; - int get customerId { - return (values['customer_id'] as int); + set updatedAt(DateTime? value) => values['updated_at'] = value; + int? get customerId { + return (values['customer_id'] as int?); } - set customerId(int value) => values['customer_id'] = value; - int get employeeId { - return (values['employee_id'] as int); + set customerId(int? value) => values['customer_id'] = value; + int? get employeeId { + return (values['employee_id'] as int?); } - set employeeId(int value) => values['employee_id'] = value; - DateTime get orderDate { - return (values['order_date'] as DateTime); + set employeeId(int? value) => values['employee_id'] = value; + DateTime? get orderDate { + return (values['order_date'] as DateTime?); } - set orderDate(DateTime value) => values['order_date'] = value; - int get shipperId { - return (values['shipper_id'] as int); + set orderDate(DateTime? value) => values['order_date'] = value; + int? get shipperId { + return (values['shipper_id'] as int?); } - set shipperId(int value) => values['shipper_id'] = value; + set shipperId(int? value) => values['shipper_id'] = value; void copyFrom(Order model) { createdAt = model.createdAt; updatedAt = model.updatedAt; @@ -211,13 +211,13 @@ class OrderQueryValues extends MapQueryValues { orderDate = model.orderDate; shipperId = model.shipperId; if (model.customer != null) { - values['customer_id'] = model.customer.id; + values['customer_id'] = model.customer!.id; } } } -class CustomerQuery extends Query { - CustomerQuery({Query parent, Set trampoline}) +class CustomerQuery extends Query { + CustomerQuery({Query? parent, Set? trampoline}) : super(parent: parent) { trampoline ??= Set(); trampoline.add(tableName); @@ -227,7 +227,7 @@ class CustomerQuery extends Query { @override final CustomerQueryValues values = CustomerQueryValues(); - CustomerQueryWhere _where; + CustomerQueryWhere? _where; @override get casts { @@ -245,7 +245,7 @@ class CustomerQuery extends Query { } @override - CustomerQueryWhere get where { + CustomerQueryWhere? get where { return _where; } @@ -254,12 +254,12 @@ class CustomerQuery extends Query { return CustomerQueryWhere(this); } - static Customer parseRow(List row) { + static Customer? parseRow(List row) { if (row.every((x) => x == null)) return null; var model = Customer( id: row[0].toString(), - createdAt: (row[1] as DateTime), - updatedAt: (row[2] as DateTime)); + createdAt: (row[1] as DateTime?), + updatedAt: (row[2] as DateTime?)); return model; } @@ -293,21 +293,21 @@ class CustomerQueryValues extends MapQueryValues { return {}; } - String get id { - return (values['id'] as String); + String? get id { + return (values['id'] as String?); } - set id(String value) => values['id'] = value; - DateTime get createdAt { - return (values['created_at'] as DateTime); + set id(String? value) => values['id'] = value; + DateTime? get createdAt { + return (values['created_at'] as DateTime?); } - set createdAt(DateTime value) => values['created_at'] = value; - DateTime get updatedAt { - return (values['updated_at'] as DateTime); + set createdAt(DateTime? value) => values['created_at'] = value; + DateTime? get updatedAt { + return (values['updated_at'] as DateTime?); } - set updatedAt(DateTime value) => values['updated_at'] = value; + set updatedAt(DateTime? value) => values['updated_at'] = value; void copyFrom(Customer model) { createdAt = model.createdAt; updatedAt = model.updatedAt; @@ -331,36 +331,36 @@ class Order extends _Order { /// A unique identifier corresponding to this item. @override - String id; + String? id; /// The time at which this item was created. @override - DateTime createdAt; + DateTime? createdAt; /// The last time at which this item was updated. @override - DateTime updatedAt; + DateTime? updatedAt; @override - final _Customer customer; + final _Customer? customer; @override - final int employeeId; + final int? employeeId; @override - final DateTime orderDate; + final DateTime? orderDate; @override - final int shipperId; + final int? shipperId; Order copyWith( - {String id, - DateTime createdAt, - DateTime updatedAt, - _Customer customer, - int employeeId, - DateTime orderDate, - int shipperId}) { + {String? id, + DateTime? createdAt, + DateTime? updatedAt, + _Customer? customer, + int? employeeId, + DateTime? orderDate, + int? shipperId}) { return Order( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -404,17 +404,17 @@ class Customer extends _Customer { /// A unique identifier corresponding to this item. @override - String id; + String? id; /// The time at which this item was created. @override - DateTime createdAt; + DateTime? createdAt; /// The last time at which this item was updated. @override - DateTime updatedAt; + 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, @@ -438,7 +438,7 @@ class Customer extends _Customer { return "Customer(id=$id, createdAt=$createdAt, updatedAt=$updatedAt)"; } - Map toJson() { + Map? toJson() { return CustomerSerializer.toMap(this); } } @@ -472,33 +472,30 @@ class OrderSerializer extends Codec { get decoder => const OrderDecoder(); static Order fromMap(Map map) { return Order( - id: map['id'] as String, + id: map['id'] as String?, createdAt: map['created_at'] != null ? (map['created_at'] is DateTime - ? (map['created_at'] as DateTime) + ? (map['created_at'] as DateTime?) : DateTime.parse(map['created_at'].toString())) : null, updatedAt: map['updated_at'] != null ? (map['updated_at'] is DateTime - ? (map['updated_at'] as DateTime) + ? (map['updated_at'] as DateTime?) : DateTime.parse(map['updated_at'].toString())) : null, customer: map['customer'] != null ? CustomerSerializer.fromMap(map['customer'] as Map) : null, - employeeId: map['employee_id'] as int, + employeeId: map['employee_id'] as int?, orderDate: map['order_date'] != null ? (map['order_date'] is DateTime - ? (map['order_date'] as DateTime) + ? (map['order_date'] as DateTime?) : DateTime.parse(map['order_date'].toString())) : null, - shipperId: map['shipper_id'] as int); + shipperId: map['shipper_id'] as int?); } static Map toMap(_Order model) { - if (model == null) { - return null; - } return { 'id': model.id, 'created_at': model.createdAt?.toIso8601String(), @@ -539,11 +536,11 @@ abstract class OrderFields { const CustomerSerializer customerSerializer = CustomerSerializer(); -class CustomerEncoder extends Converter { +class CustomerEncoder extends Converter { const CustomerEncoder(); @override - Map convert(Customer model) => CustomerSerializer.toMap(model); + Map? convert(Customer model) => CustomerSerializer.toMap(model); } class CustomerDecoder extends Converter { @@ -553,7 +550,7 @@ class CustomerDecoder extends Converter { Customer convert(Map map) => CustomerSerializer.fromMap(map); } -class CustomerSerializer extends Codec { +class CustomerSerializer extends Codec { const CustomerSerializer(); @override @@ -562,20 +559,20 @@ class CustomerSerializer extends Codec { get decoder => const CustomerDecoder(); static Customer fromMap(Map map) { return Customer( - id: map['id'] as String, + id: map['id'] as String?, createdAt: map['created_at'] != null ? (map['created_at'] is DateTime - ? (map['created_at'] as DateTime) + ? (map['created_at'] as DateTime?) : DateTime.parse(map['created_at'].toString())) : null, updatedAt: map['updated_at'] != null ? (map['updated_at'] is DateTime - ? (map['updated_at'] as DateTime) + ? (map['updated_at'] as DateTime?) : DateTime.parse(map['updated_at'].toString())) : null); } - static Map toMap(_Customer model) { + static Map? toMap(_Customer? model) { if (model == null) { return null; } diff --git a/packages/orm/angel_orm_test/lib/src/models/tree.dart b/packages/orm/angel_orm_test/lib/src/models/tree.dart index d549bb42..82bee315 100644 --- a/packages/orm/angel_orm_test/lib/src/models/tree.dart +++ b/packages/orm/angel_orm_test/lib/src/models/tree.dart @@ -11,15 +11,15 @@ part 'tree.g.dart'; @orm class _Tree extends Model { @Column(indexType: IndexType.unique, type: ColumnType.smallInt) - int rings; + int? rings; @hasMany - List<_Fruit> fruits; + List<_Fruit>? fruits; } @serializable @orm class _Fruit extends Model { - int treeId; - String commonName; + int? treeId; + String? commonName; } 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 b20ca724..7b5f5ec3 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 @@ -45,8 +45,8 @@ class FruitMigration extends Migration { // OrmGenerator // ************************************************************************** -class TreeQuery extends Query { - TreeQuery({Query parent, Set trampoline}) : super(parent: parent) { +class TreeQuery extends Query { + TreeQuery({Query? parent, Set? trampoline}) : super(parent: parent) { trampoline ??= Set(); trampoline.add(tableName); _where = TreeQueryWhere(this); @@ -65,9 +65,9 @@ class TreeQuery extends Query { @override final TreeQueryValues values = TreeQueryValues(); - TreeQueryWhere _where; + TreeQueryWhere? _where; - FruitQuery _fruits; + FruitQuery? _fruits; @override get casts { @@ -85,7 +85,7 @@ class TreeQuery extends Query { } @override - TreeQueryWhere get where { + TreeQueryWhere? get where { return _where; } @@ -94,13 +94,13 @@ class TreeQuery extends Query { return TreeQueryWhere(this); } - static Tree parseRow(List row) { + static Tree? parseRow(List row) { if (row.every((x) => x == null)) return null; var model = Tree( id: row[0].toString(), - createdAt: (row[1] as DateTime), - updatedAt: (row[2] as DateTime), - rings: (row[3] as int)); + createdAt: (row[1] as DateTime?), + updatedAt: (row[2] as DateTime?), + rings: (row[3] as int?)); if (row.length > 4) { model = model.copyWith( fruits: [FruitQuery.parseRow(row.skip(4).take(5).toList())] @@ -115,24 +115,24 @@ class TreeQuery extends Query { return parseRow(row); } - FruitQuery get fruits { + FruitQuery? get fruits { return _fruits; } @override get(QueryExecutor executor) { return super.get(executor).then((result) { - return result.fold>([], (out, model) { - var idx = out.indexWhere((m) => m.id == model.id); + return result.fold>([], (out, model) { + var idx = out.indexWhere((m) => m!.id == model!.id); if (idx == -1) { return out..add(model); } else { - var l = out[idx]; + var l = out[idx]!; return out ..[idx] = l.copyWith( fruits: List<_Fruit>.from(l.fruits ?? []) - ..addAll(model.fruits ?? [])); + ..addAll(model!.fruits ?? [])); } }); }); @@ -141,17 +141,17 @@ class TreeQuery extends Query { @override update(QueryExecutor executor) { return super.update(executor).then((result) { - return result.fold>([], (out, model) { - var idx = out.indexWhere((m) => m.id == model.id); + return result.fold>([], (out, model) { + var idx = out.indexWhere((m) => m!.id == model!.id); if (idx == -1) { return out..add(model); } else { - var l = out[idx]; + var l = out[idx]!; return out ..[idx] = l.copyWith( fruits: List<_Fruit>.from(l.fruits ?? []) - ..addAll(model.fruits ?? [])); + ..addAll(model!.fruits ?? [])); } }); }); @@ -160,17 +160,17 @@ class TreeQuery extends Query { @override delete(QueryExecutor executor) { return super.delete(executor).then((result) { - return result.fold>([], (out, model) { - var idx = out.indexWhere((m) => m.id == model.id); + return result.fold>([], (out, model) { + var idx = out.indexWhere((m) => m!.id == model!.id); if (idx == -1) { return out..add(model); } else { - var l = out[idx]; + var l = out[idx]!; return out ..[idx] = l.copyWith( fruits: List<_Fruit>.from(l.fruits ?? []) - ..addAll(model.fruits ?? [])); + ..addAll(model!.fruits ?? [])); } }); }); @@ -204,26 +204,26 @@ class TreeQueryValues extends MapQueryValues { return {}; } - String get id { - return (values['id'] as String); + String? get id { + return (values['id'] as String?); } - set id(String value) => values['id'] = value; - DateTime get createdAt { - return (values['created_at'] as DateTime); + set id(String? value) => values['id'] = value; + DateTime? get createdAt { + return (values['created_at'] as DateTime?); } - set createdAt(DateTime value) => values['created_at'] = value; - DateTime get updatedAt { - return (values['updated_at'] as DateTime); + set createdAt(DateTime? value) => values['created_at'] = value; + DateTime? get updatedAt { + return (values['updated_at'] as DateTime?); } - set updatedAt(DateTime value) => values['updated_at'] = value; - int get rings { - return (values['rings'] as int); + set updatedAt(DateTime? value) => values['updated_at'] = value; + int? get rings { + return (values['rings'] as int?); } - set rings(int value) => values['rings'] = value; + set rings(int? value) => values['rings'] = value; void copyFrom(Tree model) { createdAt = model.createdAt; updatedAt = model.updatedAt; @@ -231,8 +231,8 @@ class TreeQueryValues extends MapQueryValues { } } -class FruitQuery extends Query { - FruitQuery({Query parent, Set trampoline}) : super(parent: parent) { +class FruitQuery extends Query { + FruitQuery({Query? parent, Set? trampoline}) : super(parent: parent) { trampoline ??= Set(); trampoline.add(tableName); _where = FruitQueryWhere(this); @@ -241,7 +241,7 @@ class FruitQuery extends Query { @override final FruitQueryValues values = FruitQueryValues(); - FruitQueryWhere _where; + FruitQueryWhere? _where; @override get casts { @@ -259,7 +259,7 @@ class FruitQuery extends Query { } @override - FruitQueryWhere get where { + FruitQueryWhere? get where { return _where; } @@ -268,14 +268,14 @@ class FruitQuery extends Query { return FruitQueryWhere(this); } - static Fruit parseRow(List row) { + static Fruit? parseRow(List row) { if (row.every((x) => x == null)) return null; var model = Fruit( id: row[0].toString(), - createdAt: (row[1] as DateTime), - updatedAt: (row[2] as DateTime), - treeId: (row[3] as int), - commonName: (row[4] as String)); + createdAt: (row[1] as DateTime?), + updatedAt: (row[2] as DateTime?), + treeId: (row[3] as int?), + commonName: (row[4] as String?)); return model; } @@ -315,31 +315,31 @@ class FruitQueryValues extends MapQueryValues { return {}; } - String get id { - return (values['id'] as String); + String? get id { + return (values['id'] as String?); } - set id(String value) => values['id'] = value; - DateTime get createdAt { - return (values['created_at'] as DateTime); + set id(String? value) => values['id'] = value; + DateTime? get createdAt { + return (values['created_at'] as DateTime?); } - set createdAt(DateTime value) => values['created_at'] = value; - DateTime get updatedAt { - return (values['updated_at'] as DateTime); + set createdAt(DateTime? value) => values['created_at'] = value; + DateTime? get updatedAt { + return (values['updated_at'] as DateTime?); } - set updatedAt(DateTime value) => values['updated_at'] = value; - int get treeId { - return (values['tree_id'] as int); + set updatedAt(DateTime? value) => values['updated_at'] = value; + int? get treeId { + return (values['tree_id'] as int?); } - set treeId(int value) => values['tree_id'] = value; - String get commonName { - return (values['common_name'] as String); + set treeId(int? value) => values['tree_id'] = value; + String? get commonName { + return (values['common_name'] as String?); } - set commonName(String value) => values['common_name'] = value; + set commonName(String? value) => values['common_name'] = value; void copyFrom(Fruit model) { createdAt = model.createdAt; updatedAt = model.updatedAt; @@ -359,33 +359,33 @@ class Tree extends _Tree { this.createdAt, this.updatedAt, this.rings, - List<_Fruit> fruits}) + List<_Fruit?>? fruits}) : this.fruits = List.unmodifiable(fruits ?? []); /// A unique identifier corresponding to this item. @override - String id; + String? id; /// The time at which this item was created. @override - DateTime createdAt; + DateTime? createdAt; /// The last time at which this item was updated. @override - DateTime updatedAt; + DateTime? updatedAt; @override - int rings; + int? rings; @override - List<_Fruit> fruits; + List<_Fruit>? fruits; Tree copyWith( - {String id, - DateTime createdAt, - DateTime updatedAt, - int rings, - List<_Fruit> fruits}) { + {String? id, + DateTime? createdAt, + DateTime? updatedAt, + int? rings, + List<_Fruit?>? fruits}) { return Tree( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -426,28 +426,28 @@ class Fruit extends _Fruit { /// A unique identifier corresponding to this item. @override - String id; + String? id; /// The time at which this item was created. @override - DateTime createdAt; + DateTime? createdAt; /// The last time at which this item was updated. @override - DateTime updatedAt; + DateTime? updatedAt; @override - int treeId; + int? treeId; @override - String commonName; + String? commonName; Fruit copyWith( - {String id, - DateTime createdAt, - DateTime updatedAt, - int treeId, - String commonName}) { + {String? id, + DateTime? createdAt, + DateTime? updatedAt, + int? treeId, + String? commonName}) { return Fruit( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -509,18 +509,18 @@ class TreeSerializer extends Codec { get decoder => const TreeDecoder(); static Tree fromMap(Map map) { return Tree( - id: map['id'] as String, + id: map['id'] as String?, createdAt: map['created_at'] != null ? (map['created_at'] is DateTime - ? (map['created_at'] as DateTime) + ? (map['created_at'] as DateTime?) : DateTime.parse(map['created_at'].toString())) : null, updatedAt: map['updated_at'] != null ? (map['updated_at'] is DateTime - ? (map['updated_at'] as DateTime) + ? (map['updated_at'] as DateTime?) : DateTime.parse(map['updated_at'].toString())) : null, - rings: map['rings'] as int, + rings: map['rings'] as int?, fruits: map['fruits'] is Iterable ? List.unmodifiable(((map['fruits'] as Iterable).whereType()) .map(FruitSerializer.fromMap)) @@ -528,15 +528,12 @@ class TreeSerializer extends Codec { } static Map toMap(_Tree model) { - if (model == null) { - return null; - } return { 'id': model.id, 'created_at': model.createdAt?.toIso8601String(), 'updated_at': model.updatedAt?.toIso8601String(), 'rings': model.rings, - 'fruits': model.fruits?.map((m) => FruitSerializer.toMap(m))?.toList() + 'fruits': model.fruits?.map((m) => FruitSerializer.toMap(m)).toList() }; } } @@ -586,25 +583,22 @@ class FruitSerializer extends Codec { get decoder => const FruitDecoder(); static Fruit fromMap(Map map) { return Fruit( - id: map['id'] as String, + id: map['id'] as String?, createdAt: map['created_at'] != null ? (map['created_at'] is DateTime - ? (map['created_at'] as DateTime) + ? (map['created_at'] as DateTime?) : DateTime.parse(map['created_at'].toString())) : null, updatedAt: map['updated_at'] != null ? (map['updated_at'] is DateTime - ? (map['updated_at'] as DateTime) + ? (map['updated_at'] as DateTime?) : DateTime.parse(map['updated_at'].toString())) : null, - treeId: map['tree_id'] as int, - commonName: map['common_name'] as String); + treeId: map['tree_id'] as int?, + commonName: map['common_name'] as String?); } static Map toMap(_Fruit model) { - if (model == null) { - return null; - } return { 'id': model.id, 'created_at': model.createdAt?.toIso8601String(), diff --git a/packages/orm/angel_orm_test/lib/src/models/unorthodox.dart b/packages/orm/angel_orm_test/lib/src/models/unorthodox.dart index 4a56f30a..99c33dbb 100644 --- a/packages/orm/angel_orm_test/lib/src/models/unorthodox.dart +++ b/packages/orm/angel_orm_test/lib/src/models/unorthodox.dart @@ -8,63 +8,63 @@ part 'unorthodox.g.dart'; @orm abstract class _Unorthodox { @Column(indexType: IndexType.primaryKey) - String get name; + String? get name; } @serializable @orm abstract class _WeirdJoin { @primaryKey - int get id; + int? get id; @BelongsTo(localKey: 'join_name', foreignKey: 'name') - _Unorthodox get unorthodox; + _Unorthodox? get unorthodox; @hasOne - _Song get song; + _Song? get song; @HasMany(foreignKey: 'parent') - List<_Numba> get numbas; + List<_Numba?>? get numbas; @ManyToMany(_FooPivot) - List<_Foo> get foos; + List<_Foo?>? get foos; } @serializable @orm abstract class _Song extends Model { - int get weirdJoinId; + int? get weirdJoinId; - String get title; + String? get title; } @serializable @orm class _Numba implements Comparable<_Numba> { @primaryKey - int i; + int? i; - int parent; + int? parent; - int compareTo(_Numba other) => i.compareTo(other.i); + int compareTo(_Numba other) => i!.compareTo(other.i!); } @serializable @orm abstract class _Foo { @primaryKey - String get bar; + String? get bar; @ManyToMany(_FooPivot) - List<_WeirdJoin> get weirdJoins; + List<_WeirdJoin?>? get weirdJoins; } @serializable @orm abstract class _FooPivot { @belongsTo - _WeirdJoin get weirdJoin; + _WeirdJoin? get weirdJoin; @belongsTo - _Foo get foo; + _Foo? get foo; } 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 7a803db9..6e69099e 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 @@ -105,8 +105,8 @@ class FooPivotMigration extends Migration { // OrmGenerator // ************************************************************************** -class UnorthodoxQuery extends Query { - UnorthodoxQuery({Query parent, Set trampoline}) +class UnorthodoxQuery extends Query { + UnorthodoxQuery({Query? parent, Set? trampoline}) : super(parent: parent) { trampoline ??= Set(); trampoline.add(tableName); @@ -116,7 +116,7 @@ class UnorthodoxQuery extends Query { @override final UnorthodoxQueryValues values = UnorthodoxQueryValues(); - UnorthodoxQueryWhere _where; + UnorthodoxQueryWhere? _where; @override get casts { @@ -134,7 +134,7 @@ class UnorthodoxQuery extends Query { } @override - UnorthodoxQueryWhere get where { + UnorthodoxQueryWhere? get where { return _where; } @@ -143,9 +143,9 @@ class UnorthodoxQuery extends Query { return UnorthodoxQueryWhere(this); } - static Unorthodox parseRow(List row) { + static Unorthodox? parseRow(List row) { if (row.every((x) => x == null)) return null; - var model = Unorthodox(name: (row[0] as String)); + var model = Unorthodox(name: (row[0] as String?)); return model; } @@ -173,18 +173,18 @@ class UnorthodoxQueryValues extends MapQueryValues { return {}; } - String get name { - return (values['name'] as String); + String? get name { + return (values['name'] as String?); } - set name(String value) => values['name'] = value; + set name(String? value) => values['name'] = value; void copyFrom(Unorthodox model) { name = model.name; } } -class WeirdJoinQuery extends Query { - WeirdJoinQuery({Query parent, Set trampoline}) +class WeirdJoinQuery extends Query { + WeirdJoinQuery({Query? parent, Set? trampoline}) : super(parent: parent) { trampoline ??= Set(); trampoline.add(tableName); @@ -219,13 +219,13 @@ class WeirdJoinQuery extends Query { @override final WeirdJoinQueryValues values = WeirdJoinQueryValues(); - WeirdJoinQueryWhere _where; + WeirdJoinQueryWhere? _where; - UnorthodoxQuery _unorthodox; + UnorthodoxQuery? _unorthodox; - SongQuery _song; + SongQuery? _song; - NumbaQuery _numbas; + NumbaQuery? _numbas; @override get casts { @@ -243,7 +243,7 @@ class WeirdJoinQuery extends Query { } @override - WeirdJoinQueryWhere get where { + WeirdJoinQueryWhere? get where { return _where; } @@ -252,9 +252,9 @@ class WeirdJoinQuery extends Query { return WeirdJoinQueryWhere(this); } - static WeirdJoin parseRow(List row) { + static WeirdJoin? parseRow(List row) { if (row.every((x) => x == null)) return null; - var model = WeirdJoin(id: (row[0] as int)); + var model = WeirdJoin(id: (row[0] as int?)); if (row.length > 2) { model = model.copyWith( unorthodox: UnorthodoxQuery.parseRow(row.skip(2).take(1).toList())); @@ -283,39 +283,39 @@ class WeirdJoinQuery extends Query { return parseRow(row); } - UnorthodoxQuery get unorthodox { + UnorthodoxQuery? get unorthodox { return _unorthodox; } - SongQuery get song { + SongQuery? get song { return _song; } - NumbaQuery get numbas { + NumbaQuery? get numbas { return _numbas; } @override bool canCompile(trampoline) { - return (!(trampoline.contains('weird_joins') && - trampoline.contains('foo_pivots'))); + return (!(trampoline?.contains('weird_joins') == true && + trampoline?.contains('foo_pivots') == true)); } @override get(QueryExecutor executor) { return super.get(executor).then((result) { - return result.fold>([], (out, model) { - var idx = out.indexWhere((m) => m.id == model.id); + return result.fold>([], (out, model) { + var idx = out.indexWhere((m) => m!.id == model!.id); if (idx == -1) { return out..add(model); } else { - var l = out[idx]; + var l = out[idx]!; return out ..[idx] = l.copyWith( - numbas: List<_Numba>.from(l.numbas ?? []) - ..addAll(model.numbas ?? []), - foos: List<_Foo>.from(l.foos ?? [])..addAll(model.foos ?? [])); + numbas: List<_Numba?>.from(l.numbas ?? []) + ..addAll(model!.numbas ?? []), + foos: List<_Foo?>.from(l.foos ?? [])..addAll(model.foos ?? [])); } }); }); @@ -324,18 +324,18 @@ class WeirdJoinQuery extends Query { @override update(QueryExecutor executor) { return super.update(executor).then((result) { - return result.fold>([], (out, model) { - var idx = out.indexWhere((m) => m.id == model.id); + return result.fold>([], (out, model) { + var idx = out.indexWhere((m) => m!.id == model!.id); if (idx == -1) { return out..add(model); } else { - var l = out[idx]; + var l = out[idx]!; return out ..[idx] = l.copyWith( - numbas: List<_Numba>.from(l.numbas ?? []) - ..addAll(model.numbas ?? []), - foos: List<_Foo>.from(l.foos ?? [])..addAll(model.foos ?? [])); + numbas: List<_Numba?>.from(l.numbas ?? []) + ..addAll(model!.numbas ?? []), + foos: List<_Foo?>.from(l.foos ?? [])..addAll(model.foos ?? [])); } }); }); @@ -344,18 +344,18 @@ class WeirdJoinQuery extends Query { @override delete(QueryExecutor executor) { return super.delete(executor).then((result) { - return result.fold>([], (out, model) { - var idx = out.indexWhere((m) => m.id == model.id); + return result.fold>([], (out, model) { + var idx = out.indexWhere((m) => m!.id == model!.id); if (idx == -1) { return out..add(model); } else { - var l = out[idx]; + var l = out[idx]!; return out ..[idx] = l.copyWith( - numbas: List<_Numba>.from(l.numbas ?? []) - ..addAll(model.numbas ?? []), - foos: List<_Foo>.from(l.foos ?? [])..addAll(model.foos ?? [])); + numbas: List<_Numba?>.from(l.numbas ?? []) + ..addAll(model!.numbas ?? []), + foos: List<_Foo?>.from(l.foos ?? [])..addAll(model.foos ?? [])); } }); }); @@ -383,26 +383,26 @@ class WeirdJoinQueryValues extends MapQueryValues { return {}; } - int get id { - return (values['id'] as int); + int? get id { + return (values['id'] as int?); } - set id(int value) => values['id'] = value; - String get joinName { - return (values['join_name'] as String); + set id(int? value) => values['id'] = value; + String? get joinName { + return (values['join_name'] as String?); } - set joinName(String value) => values['join_name'] = value; + set joinName(String? value) => values['join_name'] = value; void copyFrom(WeirdJoin model) { id = model.id; if (model.unorthodox != null) { - values['join_name'] = model.unorthodox.name; + values['join_name'] = model.unorthodox!.name; } } } -class SongQuery extends Query { - SongQuery({Query parent, Set trampoline}) : super(parent: parent) { +class SongQuery extends Query { + SongQuery({Query? parent, Set? trampoline}) : super(parent: parent) { trampoline ??= Set(); trampoline.add(tableName); _where = SongQueryWhere(this); @@ -411,7 +411,7 @@ class SongQuery extends Query { @override final SongQueryValues values = SongQueryValues(); - SongQueryWhere _where; + SongQueryWhere? _where; @override get casts { @@ -429,7 +429,7 @@ class SongQuery extends Query { } @override - SongQueryWhere get where { + SongQueryWhere? get where { return _where; } @@ -438,14 +438,14 @@ class SongQuery extends Query { return SongQueryWhere(this); } - static Song parseRow(List row) { + static Song? parseRow(List row) { if (row.every((x) => x == null)) return null; var model = Song( id: row[0].toString(), - createdAt: (row[1] as DateTime), - updatedAt: (row[2] as DateTime), - weirdJoinId: (row[3] as int), - title: (row[4] as String)); + createdAt: (row[1] as DateTime?), + updatedAt: (row[2] as DateTime?), + weirdJoinId: (row[3] as int?), + title: (row[4] as String?)); return model; } @@ -485,31 +485,31 @@ class SongQueryValues extends MapQueryValues { return {}; } - String get id { - return (values['id'] as String); + String? get id { + return (values['id'] as String?); } - set id(String value) => values['id'] = value; - DateTime get createdAt { - return (values['created_at'] as DateTime); + set id(String? value) => values['id'] = value; + DateTime? get createdAt { + return (values['created_at'] as DateTime?); } - set createdAt(DateTime value) => values['created_at'] = value; - DateTime get updatedAt { - return (values['updated_at'] as DateTime); + set createdAt(DateTime? value) => values['created_at'] = value; + DateTime? get updatedAt { + return (values['updated_at'] as DateTime?); } - set updatedAt(DateTime value) => values['updated_at'] = value; - int get weirdJoinId { - return (values['weird_join_id'] as int); + set updatedAt(DateTime? value) => values['updated_at'] = value; + int? get weirdJoinId { + return (values['weird_join_id'] as int?); } - set weirdJoinId(int value) => values['weird_join_id'] = value; - String get title { - return (values['title'] as String); + set weirdJoinId(int? value) => values['weird_join_id'] = value; + String? get title { + return (values['title'] as String?); } - set title(String value) => values['title'] = value; + set title(String? value) => values['title'] = value; void copyFrom(Song model) { createdAt = model.createdAt; updatedAt = model.updatedAt; @@ -518,8 +518,8 @@ class SongQueryValues extends MapQueryValues { } } -class NumbaQuery extends Query { - NumbaQuery({Query parent, Set trampoline}) : super(parent: parent) { +class NumbaQuery extends Query { + NumbaQuery({Query? parent, Set? trampoline}) : super(parent: parent) { trampoline ??= Set(); trampoline.add(tableName); _where = NumbaQueryWhere(this); @@ -528,7 +528,7 @@ class NumbaQuery extends Query { @override final NumbaQueryValues values = NumbaQueryValues(); - NumbaQueryWhere _where; + NumbaQueryWhere? _where; @override get casts { @@ -546,7 +546,7 @@ class NumbaQuery extends Query { } @override - NumbaQueryWhere get where { + NumbaQueryWhere? get where { return _where; } @@ -555,9 +555,9 @@ class NumbaQuery extends Query { return NumbaQueryWhere(this); } - static Numba parseRow(List row) { + static Numba? parseRow(List row) { if (row.every((x) => x == null)) return null; - var model = Numba(i: (row[0] as int), parent: (row[1] as int)); + var model = Numba(i: (row[0] as int?), parent: (row[1] as int?)); return model; } @@ -588,24 +588,24 @@ class NumbaQueryValues extends MapQueryValues { return {}; } - int get i { - return (values['i'] as int); + int? get i { + return (values['i'] as int?); } - set i(int value) => values['i'] = value; - int get parent { - return (values['parent'] as int); + set i(int? value) => values['i'] = value; + int? get parent { + return (values['parent'] as int?); } - set parent(int value) => values['parent'] = value; + set parent(int? value) => values['parent'] = value; void copyFrom(Numba model) { i = model.i; parent = model.parent; } } -class FooQuery extends Query { - FooQuery({Query parent, Set trampoline}) : super(parent: parent) { +class FooQuery extends Query { + FooQuery({Query? parent, Set? trampoline}) : super(parent: parent) { trampoline ??= Set(); trampoline.add(tableName); _where = FooQueryWhere(this); @@ -620,7 +620,7 @@ class FooQuery extends Query { @override final FooQueryValues values = FooQueryValues(); - FooQueryWhere _where; + FooQueryWhere? _where; @override get casts { @@ -638,7 +638,7 @@ class FooQuery extends Query { } @override - FooQueryWhere get where { + FooQueryWhere? get where { return _where; } @@ -647,9 +647,9 @@ class FooQuery extends Query { return FooQueryWhere(this); } - static Foo parseRow(List row) { + static Foo? parseRow(List row) { if (row.every((x) => x == null)) return null; - var model = Foo(bar: (row[0] as String)); + var model = Foo(bar: (row[0] as String?)); if (row.length > 1) { model = model.copyWith( weirdJoins: [WeirdJoinQuery.parseRow(row.skip(1).take(2).toList())] @@ -666,24 +666,24 @@ class FooQuery extends Query { @override bool canCompile(trampoline) { - return (!(trampoline.contains('foos') && - trampoline.contains('foo_pivots'))); + return (!(trampoline?.contains('foos') == true && + trampoline?.contains('foo_pivots') == true)); } @override get(QueryExecutor executor) { return super.get(executor).then((result) { - return result.fold>([], (out, model) { - var idx = out.indexWhere((m) => m.bar == model.bar); + return result.fold>([], (out, model) { + var idx = out.indexWhere((m) => m!.bar == model!.bar); if (idx == -1) { return out..add(model); } else { - var l = out[idx]; + var l = out[idx]!; return out ..[idx] = l.copyWith( - weirdJoins: List<_WeirdJoin>.from(l.weirdJoins ?? []) - ..addAll(model.weirdJoins ?? [])); + weirdJoins: List<_WeirdJoin?>.from(l.weirdJoins ?? []) + ..addAll(model!.weirdJoins ?? [])); } }); }); @@ -692,17 +692,17 @@ class FooQuery extends Query { @override update(QueryExecutor executor) { return super.update(executor).then((result) { - return result.fold>([], (out, model) { - var idx = out.indexWhere((m) => m.bar == model.bar); + return result.fold>([], (out, model) { + var idx = out.indexWhere((m) => m!.bar == model!.bar); if (idx == -1) { return out..add(model); } else { - var l = out[idx]; + var l = out[idx]!; return out ..[idx] = l.copyWith( - weirdJoins: List<_WeirdJoin>.from(l.weirdJoins ?? []) - ..addAll(model.weirdJoins ?? [])); + weirdJoins: List<_WeirdJoin?>.from(l.weirdJoins ?? []) + ..addAll(model!.weirdJoins ?? [])); } }); }); @@ -711,17 +711,17 @@ class FooQuery extends Query { @override delete(QueryExecutor executor) { return super.delete(executor).then((result) { - return result.fold>([], (out, model) { - var idx = out.indexWhere((m) => m.bar == model.bar); + return result.fold>([], (out, model) { + var idx = out.indexWhere((m) => m!.bar == model!.bar); if (idx == -1) { return out..add(model); } else { - var l = out[idx]; + var l = out[idx]!; return out ..[idx] = l.copyWith( - weirdJoins: List<_WeirdJoin>.from(l.weirdJoins ?? []) - ..addAll(model.weirdJoins ?? [])); + weirdJoins: List<_WeirdJoin?>.from(l.weirdJoins ?? []) + ..addAll(model!.weirdJoins ?? [])); } }); }); @@ -746,18 +746,18 @@ class FooQueryValues extends MapQueryValues { return {}; } - String get bar { - return (values['bar'] as String); + String? get bar { + return (values['bar'] as String?); } - set bar(String value) => values['bar'] = value; + set bar(String? value) => values['bar'] = value; void copyFrom(Foo model) { bar = model.bar; } } -class FooPivotQuery extends Query { - FooPivotQuery({Query parent, Set trampoline}) +class FooPivotQuery extends Query { + FooPivotQuery({Query? parent, Set? trampoline}) : super(parent: parent) { trampoline ??= Set(); trampoline.add(tableName); @@ -773,11 +773,11 @@ class FooPivotQuery extends Query { @override final FooPivotQueryValues values = FooPivotQueryValues(); - FooPivotQueryWhere _where; + FooPivotQueryWhere? _where; - WeirdJoinQuery _weirdJoin; + WeirdJoinQuery? _weirdJoin; - FooQuery _foo; + FooQuery? _foo; @override get casts { @@ -795,7 +795,7 @@ class FooPivotQuery extends Query { } @override - FooPivotQueryWhere get where { + FooPivotQueryWhere? get where { return _where; } @@ -804,7 +804,7 @@ class FooPivotQuery extends Query { return FooPivotQueryWhere(this); } - static FooPivot parseRow(List row) { + static FooPivot? parseRow(List row) { if (row.every((x) => x == null)) return null; var model = FooPivot(); if (row.length > 2) { @@ -823,11 +823,11 @@ class FooPivotQuery extends Query { return parseRow(row); } - WeirdJoinQuery get weirdJoin { + WeirdJoinQuery? get weirdJoin { return _weirdJoin; } - FooQuery get foo { + FooQuery? get foo { return _foo; } } @@ -853,22 +853,22 @@ class FooPivotQueryValues extends MapQueryValues { return {}; } - int get weirdJoinId { - return (values['weird_join_id'] as int); + int? get weirdJoinId { + return (values['weird_join_id'] as int?); } - set weirdJoinId(int value) => values['weird_join_id'] = value; - String get fooBar { - return (values['foo_bar'] as String); + set weirdJoinId(int? value) => values['weird_join_id'] = value; + String? get fooBar { + return (values['foo_bar'] as String?); } - set fooBar(String value) => values['foo_bar'] = value; + set fooBar(String? value) => values['foo_bar'] = value; void copyFrom(FooPivot model) { if (model.weirdJoin != null) { - values['weird_join_id'] = model.weirdJoin.id; + values['weird_join_id'] = model.weirdJoin!.id; } if (model.foo != null) { - values['foo_bar'] = model.foo.bar; + values['foo_bar'] = model.foo!.bar; } } } @@ -882,9 +882,9 @@ class Unorthodox implements _Unorthodox { const Unorthodox({this.name}); @override - final String name; + final String? name; - Unorthodox copyWith({String name}) { + Unorthodox copyWith({String? name}) { return Unorthodox(name: name ?? this.name); } @@ -902,7 +902,7 @@ class Unorthodox implements _Unorthodox { return "Unorthodox(name=$name)"; } - Map toJson() { + Map? toJson() { return UnorthodoxSerializer.toMap(this); } } @@ -913,26 +913,26 @@ class WeirdJoin implements _WeirdJoin { {this.id, this.unorthodox, this.song, this.numbas, this.foos}); @override - final int id; + final int? id; @override - final _Unorthodox unorthodox; + final _Unorthodox? unorthodox; @override - final _Song song; + final _Song? song; @override - final List<_Numba> numbas; + final List<_Numba?>? numbas; @override - final List<_Foo> foos; + final List<_Foo?>? foos; WeirdJoin copyWith( - {int id, - _Unorthodox unorthodox, - _Song song, - List<_Numba> numbas, - List<_Foo> foos}) { + {int? id, + _Unorthodox? unorthodox, + _Song? song, + List<_Numba?>? numbas, + List<_Foo?>? foos}) { return WeirdJoin( id: id ?? this.id, unorthodox: unorthodox ?? this.unorthodox, @@ -946,9 +946,9 @@ class WeirdJoin implements _WeirdJoin { other.id == id && other.unorthodox == unorthodox && other.song == song && - ListEquality<_Numba>(DefaultEquality<_Numba>()) + ListEquality<_Numba?>(DefaultEquality<_Numba>()) .equals(other.numbas, numbas) && - ListEquality<_Foo>(DefaultEquality<_Foo>()).equals(other.foos, foos); + ListEquality<_Foo?>(DefaultEquality<_Foo>()).equals(other.foos, foos); } @override @@ -961,7 +961,7 @@ class WeirdJoin implements _WeirdJoin { return "WeirdJoin(id=$id, unorthodox=$unorthodox, song=$song, numbas=$numbas, foos=$foos)"; } - Map toJson() { + Map? toJson() { return WeirdJoinSerializer.toMap(this); } } @@ -972,28 +972,28 @@ class Song extends _Song { /// A unique identifier corresponding to this item. @override - String id; + String? id; /// The time at which this item was created. @override - DateTime createdAt; + DateTime? createdAt; /// The last time at which this item was updated. @override - DateTime updatedAt; + DateTime? updatedAt; @override - final int weirdJoinId; + final int? weirdJoinId; @override - final String title; + final String? title; Song copyWith( - {String id, - DateTime createdAt, - DateTime updatedAt, - int weirdJoinId, - String title}) { + {String? id, + DateTime? createdAt, + DateTime? updatedAt, + int? weirdJoinId, + String? title}) { return Song( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -1021,7 +1021,7 @@ class Song extends _Song { return "Song(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, weirdJoinId=$weirdJoinId, title=$title)"; } - Map toJson() { + Map? toJson() { return SongSerializer.toMap(this); } } @@ -1031,12 +1031,12 @@ class Numba extends _Numba { Numba({this.i, this.parent}); @override - int i; + int? i; @override - int parent; + int? parent; - Numba copyWith({int i, int parent}) { + Numba copyWith({int? i, int? parent}) { return Numba(i: i ?? this.i, parent: parent ?? this.parent); } @@ -1054,7 +1054,7 @@ class Numba extends _Numba { return "Numba(i=$i, parent=$parent)"; } - Map toJson() { + Map? toJson() { return NumbaSerializer.toMap(this); } } @@ -1064,19 +1064,19 @@ class Foo implements _Foo { const Foo({this.bar, this.weirdJoins}); @override - final String bar; + final String? bar; @override - final List<_WeirdJoin> weirdJoins; + final 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); } bool operator ==(other) { return other is _Foo && other.bar == bar && - ListEquality<_WeirdJoin>(DefaultEquality<_WeirdJoin>()) + ListEquality<_WeirdJoin?>(DefaultEquality<_WeirdJoin>()) .equals(other.weirdJoins, weirdJoins); } @@ -1090,7 +1090,7 @@ class Foo implements _Foo { return "Foo(bar=$bar, weirdJoins=$weirdJoins)"; } - Map toJson() { + Map? toJson() { return FooSerializer.toMap(this); } } @@ -1100,12 +1100,12 @@ class FooPivot implements _FooPivot { const FooPivot({this.weirdJoin, this.foo}); @override - final _WeirdJoin weirdJoin; + final _WeirdJoin? weirdJoin; @override - final _Foo foo; + final _Foo? foo; - FooPivot copyWith({_WeirdJoin weirdJoin, _Foo foo}) { + FooPivot copyWith({_WeirdJoin? weirdJoin, _Foo? foo}) { return FooPivot( weirdJoin: weirdJoin ?? this.weirdJoin, foo: foo ?? this.foo); } @@ -1137,11 +1137,11 @@ class FooPivot implements _FooPivot { const UnorthodoxSerializer unorthodoxSerializer = UnorthodoxSerializer(); -class UnorthodoxEncoder extends Converter { +class UnorthodoxEncoder extends Converter { const UnorthodoxEncoder(); @override - Map convert(Unorthodox model) => UnorthodoxSerializer.toMap(model); + Map? convert(Unorthodox model) => UnorthodoxSerializer.toMap(model); } class UnorthodoxDecoder extends Converter { @@ -1151,7 +1151,7 @@ class UnorthodoxDecoder extends Converter { Unorthodox convert(Map map) => UnorthodoxSerializer.fromMap(map); } -class UnorthodoxSerializer extends Codec { +class UnorthodoxSerializer extends Codec { const UnorthodoxSerializer(); @override @@ -1159,10 +1159,10 @@ class UnorthodoxSerializer extends Codec { @override get decoder => const UnorthodoxDecoder(); static Unorthodox fromMap(Map map) { - return Unorthodox(name: map['name'] as String); + return Unorthodox(name: map['name'] as String?); } - static Map toMap(_Unorthodox model) { + static Map? toMap(_Unorthodox? model) { if (model == null) { return null; } @@ -1178,11 +1178,11 @@ abstract class UnorthodoxFields { const WeirdJoinSerializer weirdJoinSerializer = WeirdJoinSerializer(); -class WeirdJoinEncoder extends Converter { +class WeirdJoinEncoder extends Converter { const WeirdJoinEncoder(); @override - Map convert(WeirdJoin model) => WeirdJoinSerializer.toMap(model); + Map? convert(WeirdJoin model) => WeirdJoinSerializer.toMap(model); } class WeirdJoinDecoder extends Converter { @@ -1192,7 +1192,7 @@ class WeirdJoinDecoder extends Converter { WeirdJoin convert(Map map) => WeirdJoinSerializer.fromMap(map); } -class WeirdJoinSerializer extends Codec { +class WeirdJoinSerializer extends Codec { const WeirdJoinSerializer(); @override @@ -1201,7 +1201,7 @@ class WeirdJoinSerializer extends Codec { get decoder => const WeirdJoinDecoder(); static WeirdJoin fromMap(Map map) { return WeirdJoin( - id: map['id'] as int, + id: map['id'] as int?, unorthodox: map['unorthodox'] != null ? UnorthodoxSerializer.fromMap(map['unorthodox'] as Map) : null, @@ -1218,7 +1218,7 @@ class WeirdJoinSerializer extends Codec { : null); } - static Map toMap(_WeirdJoin model) { + static Map? toMap(_WeirdJoin? model) { if (model == null) { return null; } @@ -1226,8 +1226,8 @@ class WeirdJoinSerializer extends Codec { 'id': model.id, 'unorthodox': UnorthodoxSerializer.toMap(model.unorthodox), 'song': SongSerializer.toMap(model.song), - 'numbas': model.numbas?.map((m) => NumbaSerializer.toMap(m))?.toList(), - 'foos': model.foos?.map((m) => FooSerializer.toMap(m))?.toList() + 'numbas': model.numbas?.map((m) => NumbaSerializer.toMap(m)).toList(), + 'foos': model.foos?.map((m) => FooSerializer.toMap(m)).toList() }; } } @@ -1254,11 +1254,11 @@ abstract class WeirdJoinFields { const SongSerializer songSerializer = SongSerializer(); -class SongEncoder extends Converter { +class SongEncoder extends Converter { const SongEncoder(); @override - Map convert(Song model) => SongSerializer.toMap(model); + Map? convert(Song model) => SongSerializer.toMap(model); } class SongDecoder extends Converter { @@ -1268,7 +1268,7 @@ class SongDecoder extends Converter { Song convert(Map map) => SongSerializer.fromMap(map); } -class SongSerializer extends Codec { +class SongSerializer extends Codec { const SongSerializer(); @override @@ -1277,22 +1277,22 @@ class SongSerializer extends Codec { get decoder => const SongDecoder(); static Song fromMap(Map map) { return Song( - id: map['id'] as String, + id: map['id'] as String?, createdAt: map['created_at'] != null ? (map['created_at'] is DateTime - ? (map['created_at'] as DateTime) + ? (map['created_at'] as DateTime?) : DateTime.parse(map['created_at'].toString())) : null, updatedAt: map['updated_at'] != null ? (map['updated_at'] is DateTime - ? (map['updated_at'] as DateTime) + ? (map['updated_at'] as DateTime?) : DateTime.parse(map['updated_at'].toString())) : null, - weirdJoinId: map['weird_join_id'] as int, - title: map['title'] as String); + weirdJoinId: map['weird_join_id'] as int?, + title: map['title'] as String?); } - static Map toMap(_Song model) { + static Map? toMap(_Song? model) { if (model == null) { return null; } @@ -1328,11 +1328,11 @@ abstract class SongFields { const NumbaSerializer numbaSerializer = NumbaSerializer(); -class NumbaEncoder extends Converter { +class NumbaEncoder extends Converter { const NumbaEncoder(); @override - Map convert(Numba model) => NumbaSerializer.toMap(model); + Map? convert(Numba model) => NumbaSerializer.toMap(model); } class NumbaDecoder extends Converter { @@ -1342,7 +1342,7 @@ class NumbaDecoder extends Converter { Numba convert(Map map) => NumbaSerializer.fromMap(map); } -class NumbaSerializer extends Codec { +class NumbaSerializer extends Codec { const NumbaSerializer(); @override @@ -1350,10 +1350,10 @@ class NumbaSerializer extends Codec { @override get decoder => const NumbaDecoder(); static Numba fromMap(Map map) { - return Numba(i: map['i'] as int, parent: map['parent'] as int); + return Numba(i: map['i'] as int?, parent: map['parent'] as int?); } - static Map toMap(_Numba model) { + static Map? toMap(_Numba? model) { if (model == null) { return null; } @@ -1371,11 +1371,11 @@ abstract class NumbaFields { const FooSerializer fooSerializer = FooSerializer(); -class FooEncoder extends Converter { +class FooEncoder extends Converter { const FooEncoder(); @override - Map convert(Foo model) => FooSerializer.toMap(model); + Map? convert(Foo model) => FooSerializer.toMap(model); } class FooDecoder extends Converter { @@ -1385,7 +1385,7 @@ class FooDecoder extends Converter { Foo convert(Map map) => FooSerializer.fromMap(map); } -class FooSerializer extends Codec { +class FooSerializer extends Codec { const FooSerializer(); @override @@ -1394,7 +1394,7 @@ class FooSerializer extends Codec { get decoder => const FooDecoder(); static Foo fromMap(Map map) { return Foo( - bar: map['bar'] as String, + bar: map['bar'] as String?, weirdJoins: map['weird_joins'] is Iterable ? List.unmodifiable( ((map['weird_joins'] as Iterable).whereType()) @@ -1402,14 +1402,14 @@ class FooSerializer extends Codec { : null); } - static Map toMap(_Foo model) { + static Map? toMap(_Foo? model) { if (model == null) { return null; } return { 'bar': model.bar, 'weird_joins': - model.weirdJoins?.map((m) => WeirdJoinSerializer.toMap(m))?.toList() + model.weirdJoins?.map((m) => WeirdJoinSerializer.toMap(m)).toList() }; } } @@ -1456,9 +1456,6 @@ class FooPivotSerializer extends Codec { } static Map toMap(_FooPivot model) { - if (model == null) { - return null; - } return { 'weird_join': WeirdJoinSerializer.toMap(model.weirdJoin), 'foo': FooSerializer.toMap(model.foo) diff --git a/packages/orm/angel_orm_test/lib/src/models/user.dart b/packages/orm/angel_orm_test/lib/src/models/user.dart index 76cfa7e6..16da257f 100644 --- a/packages/orm/angel_orm_test/lib/src/models/user.dart +++ b/packages/orm/angel_orm_test/lib/src/models/user.dart @@ -10,9 +10,9 @@ part 'user.g.dart'; @serializable @orm abstract class _User extends Model { - String get username; - String get password; - String get email; + String? get username; + String? get password; + String? get email; @ManyToMany(_RoleUser) List<_Role> get roles; @@ -22,16 +22,16 @@ abstract class _User extends Model { @orm abstract class _RoleUser { @belongsTo - _Role get role; + _Role? get role; @belongsTo - _User get user; + _User? get user; } @serializable @orm abstract class _Role extends Model { - String name; + String? name; @ManyToMany(_RoleUser) List<_User> get users; 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 d8ecab33..0e30467b 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 @@ -61,8 +61,8 @@ class RoleMigration extends Migration { // OrmGenerator // ************************************************************************** -class UserQuery extends Query { - UserQuery({Query parent, Set trampoline}) : super(parent: parent) { +class UserQuery extends Query { + UserQuery({Query? parent, Set? trampoline}) : super(parent: parent) { trampoline ??= Set(); trampoline.add(tableName); _where = UserQueryWhere(this); @@ -77,7 +77,7 @@ class UserQuery extends Query { @override final UserQueryValues values = UserQueryValues(); - UserQueryWhere _where; + UserQueryWhere? _where; @override get casts { @@ -102,7 +102,7 @@ class UserQuery extends Query { } @override - UserQueryWhere get where { + UserQueryWhere? get where { return _where; } @@ -111,15 +111,15 @@ class UserQuery extends Query { return UserQueryWhere(this); } - static User parseRow(List row) { + static User? parseRow(List row) { if (row.every((x) => x == null)) return null; var model = User( id: row[0].toString(), - createdAt: (row[1] as DateTime), - updatedAt: (row[2] as DateTime), - username: (row[3] as String), - password: (row[4] as String), - email: (row[5] as String)); + createdAt: (row[1] as DateTime?), + updatedAt: (row[2] as DateTime?), + username: (row[3] as String?), + password: (row[4] as String?), + email: (row[5] as String?)); if (row.length > 6) { model = model.copyWith( roles: [RoleQuery.parseRow(row.skip(6).take(4).toList())] @@ -136,24 +136,23 @@ class UserQuery extends Query { @override bool canCompile(trampoline) { - return (!(trampoline.contains('users') && - trampoline.contains('role_users'))); + return (!(trampoline?.contains('users') == true && + trampoline?.contains('role_users') == true)); } @override get(QueryExecutor executor) { return super.get(executor).then((result) { - return result.fold>([], (out, model) { - var idx = out.indexWhere((m) => m.id == model.id); + return result.fold>([], (out, model) { + var idx = out.indexWhere((m) => m!.id == model!.id); if (idx == -1) { return out..add(model); } else { - var l = out[idx]; + var l = out[idx]!; return out ..[idx] = l.copyWith( - roles: List<_Role>.from(l.roles ?? []) - ..addAll(model.roles ?? [])); + roles: List<_Role>.from(l.roles)..addAll(model!.roles)); } }); }); @@ -162,17 +161,16 @@ class UserQuery extends Query { @override update(QueryExecutor executor) { return super.update(executor).then((result) { - return result.fold>([], (out, model) { - var idx = out.indexWhere((m) => m.id == model.id); + return result.fold>([], (out, model) { + var idx = out.indexWhere((m) => m!.id == model!.id); if (idx == -1) { return out..add(model); } else { - var l = out[idx]; + var l = out[idx]!; return out ..[idx] = l.copyWith( - roles: List<_Role>.from(l.roles ?? []) - ..addAll(model.roles ?? [])); + roles: List<_Role>.from(l.roles)..addAll(model!.roles)); } }); }); @@ -181,17 +179,16 @@ class UserQuery extends Query { @override delete(QueryExecutor executor) { return super.delete(executor).then((result) { - return result.fold>([], (out, model) { - var idx = out.indexWhere((m) => m.id == model.id); + return result.fold>([], (out, model) { + var idx = out.indexWhere((m) => m!.id == model!.id); if (idx == -1) { return out..add(model); } else { - var l = out[idx]; + var l = out[idx]!; return out ..[idx] = l.copyWith( - roles: List<_Role>.from(l.roles ?? []) - ..addAll(model.roles ?? [])); + roles: List<_Role>.from(l.roles)..addAll(model!.roles)); } }); }); @@ -231,36 +228,36 @@ class UserQueryValues extends MapQueryValues { return {}; } - String get id { - return (values['id'] as String); + String? get id { + return (values['id'] as String?); } - set id(String value) => values['id'] = value; - DateTime get createdAt { - return (values['created_at'] as DateTime); + set id(String? value) => values['id'] = value; + DateTime? get createdAt { + return (values['created_at'] as DateTime?); } - set createdAt(DateTime value) => values['created_at'] = value; - DateTime get updatedAt { - return (values['updated_at'] as DateTime); + set createdAt(DateTime? value) => values['created_at'] = value; + DateTime? get updatedAt { + return (values['updated_at'] as DateTime?); } - set updatedAt(DateTime value) => values['updated_at'] = value; - String get username { - return (values['username'] as String); + set updatedAt(DateTime? value) => values['updated_at'] = value; + String? get username { + return (values['username'] as String?); } - set username(String value) => values['username'] = value; - String get password { - return (values['password'] as String); + set username(String? value) => values['username'] = value; + String? get password { + return (values['password'] as String?); } - set password(String value) => values['password'] = value; - String get email { - return (values['email'] as String); + set password(String? value) => values['password'] = value; + String? get email { + return (values['email'] as String?); } - set email(String value) => values['email'] = value; + set email(String? value) => values['email'] = value; void copyFrom(User model) { createdAt = model.createdAt; updatedAt = model.updatedAt; @@ -270,8 +267,8 @@ class UserQueryValues extends MapQueryValues { } } -class RoleUserQuery extends Query { - RoleUserQuery({Query parent, Set trampoline}) +class RoleUserQuery extends Query { + RoleUserQuery({Query? parent, Set? trampoline}) : super(parent: parent) { trampoline ??= Set(); trampoline.add(tableName); @@ -296,11 +293,11 @@ class RoleUserQuery extends Query { @override final RoleUserQueryValues values = RoleUserQueryValues(); - RoleUserQueryWhere _where; + RoleUserQueryWhere? _where; - RoleQuery _role; + RoleQuery? _role; - UserQuery _user; + UserQuery? _user; @override get casts { @@ -318,7 +315,7 @@ class RoleUserQuery extends Query { } @override - RoleUserQueryWhere get where { + RoleUserQueryWhere? get where { return _where; } @@ -327,7 +324,7 @@ class RoleUserQuery extends Query { return RoleUserQueryWhere(this); } - static RoleUser parseRow(List row) { + static RoleUser? parseRow(List row) { if (row.every((x) => x == null)) return null; var model = RoleUser(); if (row.length > 2) { @@ -346,11 +343,11 @@ class RoleUserQuery extends Query { return parseRow(row); } - RoleQuery get role { + RoleQuery? get role { return _role; } - UserQuery get user { + UserQuery? get user { return _user; } } @@ -376,28 +373,28 @@ class RoleUserQueryValues extends MapQueryValues { return {}; } - int get roleId { - return (values['role_id'] as int); + int? get roleId { + return (values['role_id'] as int?); } - set roleId(int value) => values['role_id'] = value; - int get userId { - return (values['user_id'] as int); + set roleId(int? value) => values['role_id'] = value; + int? get userId { + return (values['user_id'] as int?); } - set userId(int value) => values['user_id'] = value; + set userId(int? value) => values['user_id'] = value; void copyFrom(RoleUser model) { if (model.role != null) { - values['role_id'] = model.role.id; + values['role_id'] = model.role!.id; } if (model.user != null) { - values['user_id'] = model.user.id; + values['user_id'] = model.user!.id; } } } -class RoleQuery extends Query { - RoleQuery({Query parent, Set trampoline}) : super(parent: parent) { +class RoleQuery extends Query { + RoleQuery({Query? parent, Set? trampoline}) : super(parent: parent) { trampoline ??= Set(); trampoline.add(tableName); _where = RoleQueryWhere(this); @@ -419,7 +416,7 @@ class RoleQuery extends Query { @override final RoleQueryValues values = RoleQueryValues(); - RoleQueryWhere _where; + RoleQueryWhere? _where; @override get casts { @@ -437,7 +434,7 @@ class RoleQuery extends Query { } @override - RoleQueryWhere get where { + RoleQueryWhere? get where { return _where; } @@ -446,13 +443,13 @@ class RoleQuery extends Query { return RoleQueryWhere(this); } - static Role parseRow(List row) { + static Role? parseRow(List row) { if (row.every((x) => x == null)) return null; var model = Role( id: row[0].toString(), - createdAt: (row[1] as DateTime), - updatedAt: (row[2] as DateTime), - name: (row[3] as String)); + createdAt: (row[1] as DateTime?), + updatedAt: (row[2] as DateTime?), + name: (row[3] as String?)); if (row.length > 4) { model = model.copyWith( users: [UserQuery.parseRow(row.skip(4).take(6).toList())] @@ -469,24 +466,23 @@ class RoleQuery extends Query { @override bool canCompile(trampoline) { - return (!(trampoline.contains('roles') && - trampoline.contains('role_users'))); + return (!(trampoline?.contains('roles') == true && + trampoline?.contains('role_users') == true)); } @override get(QueryExecutor executor) { return super.get(executor).then((result) { - return result.fold>([], (out, model) { - var idx = out.indexWhere((m) => m.id == model.id); + return result.fold>([], (out, model) { + var idx = out.indexWhere((m) => m!.id == model!.id); if (idx == -1) { return out..add(model); } else { - var l = out[idx]; + var l = out[idx]!; return out ..[idx] = l.copyWith( - users: List<_User>.from(l.users ?? []) - ..addAll(model.users ?? [])); + users: List<_User>.from(l.users)..addAll(model!.users)); } }); }); @@ -495,17 +491,16 @@ class RoleQuery extends Query { @override update(QueryExecutor executor) { return super.update(executor).then((result) { - return result.fold>([], (out, model) { - var idx = out.indexWhere((m) => m.id == model.id); + return result.fold>([], (out, model) { + var idx = out.indexWhere((m) => m!.id == model!.id); if (idx == -1) { return out..add(model); } else { - var l = out[idx]; + var l = out[idx]!; return out ..[idx] = l.copyWith( - users: List<_User>.from(l.users ?? []) - ..addAll(model.users ?? [])); + users: List<_User>.from(l.users)..addAll(model!.users)); } }); }); @@ -514,17 +509,16 @@ class RoleQuery extends Query { @override delete(QueryExecutor executor) { return super.delete(executor).then((result) { - return result.fold>([], (out, model) { - var idx = out.indexWhere((m) => m.id == model.id); + return result.fold>([], (out, model) { + var idx = out.indexWhere((m) => m!.id == model!.id); if (idx == -1) { return out..add(model); } else { - var l = out[idx]; + var l = out[idx]!; return out ..[idx] = l.copyWith( - users: List<_User>.from(l.users ?? []) - ..addAll(model.users ?? [])); + users: List<_User>.from(l.users)..addAll(model!.users)); } }); }); @@ -558,26 +552,26 @@ class RoleQueryValues extends MapQueryValues { return {}; } - String get id { - return (values['id'] as String); + String? get id { + return (values['id'] as String?); } - set id(String value) => values['id'] = value; - DateTime get createdAt { - return (values['created_at'] as DateTime); + set id(String? value) => values['id'] = value; + DateTime? get createdAt { + return (values['created_at'] as DateTime?); } - set createdAt(DateTime value) => values['created_at'] = value; - DateTime get updatedAt { - return (values['updated_at'] as DateTime); + set createdAt(DateTime? value) => values['created_at'] = value; + DateTime? get updatedAt { + return (values['updated_at'] as DateTime?); } - set updatedAt(DateTime value) => values['updated_at'] = value; - String get name { - return (values['name'] as String); + set updatedAt(DateTime? value) => values['updated_at'] = value; + String? get name { + return (values['name'] as String?); } - set name(String value) => values['name'] = value; + set name(String? value) => values['name'] = value; void copyFrom(Role model) { createdAt = model.createdAt; updatedAt = model.updatedAt; @@ -598,41 +592,41 @@ class User extends _User { this.username, this.password, this.email, - List<_Role> roles}) + List<_Role?>? roles}) : this.roles = List.unmodifiable(roles ?? []); /// A unique identifier corresponding to this item. @override - String id; + String? id; /// The time at which this item was created. @override - DateTime createdAt; + DateTime? createdAt; /// The last time at which this item was updated. @override - DateTime updatedAt; + DateTime? updatedAt; @override - final String username; + final String? username; @override - final String password; + final String? password; @override - final String email; + final String? email; @override final List<_Role> roles; User copyWith( - {String id, - DateTime createdAt, - DateTime updatedAt, - String username, - String password, - String email, - List<_Role> roles}) { + {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, @@ -666,7 +660,7 @@ class User extends _User { return "User(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, username=$username, password=$password, email=$email, roles=$roles)"; } - Map toJson() { + Map? toJson() { return UserSerializer.toMap(this); } } @@ -676,12 +670,12 @@ class RoleUser implements _RoleUser { const RoleUser({this.role, this.user}); @override - final _Role role; + final _Role? role; @override - final _User user; + final _User? user; - RoleUser copyWith({_Role role, _User user}) { + RoleUser copyWith({_Role? role, _User? user}) { return RoleUser(role: role ?? this.role, user: user ?? this.user); } @@ -706,33 +700,34 @@ class RoleUser implements _RoleUser { @generatedSerializable class Role extends _Role { - Role({this.id, this.createdAt, this.updatedAt, this.name, List<_User> users}) + Role( + {this.id, this.createdAt, this.updatedAt, this.name, List<_User?>? users}) : this.users = List.unmodifiable(users ?? []); /// A unique identifier corresponding to this item. @override - String id; + String? id; /// The time at which this item was created. @override - DateTime createdAt; + DateTime? createdAt; /// The last time at which this item was updated. @override - DateTime updatedAt; + DateTime? updatedAt; @override - String name; + String? name; @override final List<_User> users; Role copyWith( - {String id, - DateTime createdAt, - DateTime updatedAt, - String name, - List<_User> users}) { + {String? id, + DateTime? createdAt, + DateTime? updatedAt, + String? name, + List<_User?>? users}) { return Role( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, @@ -761,7 +756,7 @@ class Role extends _Role { return "Role(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, name=$name, users=$users)"; } - Map toJson() { + Map? toJson() { return RoleSerializer.toMap(this); } } @@ -772,11 +767,11 @@ class Role extends _Role { const UserSerializer userSerializer = UserSerializer(); -class UserEncoder extends Converter { +class UserEncoder extends Converter { const UserEncoder(); @override - Map convert(User model) => UserSerializer.toMap(model); + Map? convert(User model) => UserSerializer.toMap(model); } class UserDecoder extends Converter { @@ -786,7 +781,7 @@ class UserDecoder extends Converter { User convert(Map map) => UserSerializer.fromMap(map); } -class UserSerializer extends Codec { +class UserSerializer extends Codec { const UserSerializer(); @override @@ -795,27 +790,27 @@ class UserSerializer extends Codec { get decoder => const UserDecoder(); static User fromMap(Map map) { return User( - id: map['id'] as String, + id: map['id'] as String?, createdAt: map['created_at'] != null ? (map['created_at'] is DateTime - ? (map['created_at'] as DateTime) + ? (map['created_at'] as DateTime?) : DateTime.parse(map['created_at'].toString())) : null, updatedAt: map['updated_at'] != null ? (map['updated_at'] is DateTime - ? (map['updated_at'] as DateTime) + ? (map['updated_at'] as DateTime?) : DateTime.parse(map['updated_at'].toString())) : null, - username: map['username'] as String, - password: map['password'] as String, - email: map['email'] as String, + username: map['username'] as String?, + password: map['password'] as String?, + email: map['email'] as String?, roles: map['roles'] is Iterable ? List.unmodifiable(((map['roles'] as Iterable).whereType()) .map(RoleSerializer.fromMap)) : null); } - static Map toMap(_User model) { + static Map? toMap(_User? model) { if (model == null) { return null; } @@ -826,7 +821,7 @@ class UserSerializer extends Codec { 'username': model.username, 'password': model.password, 'email': model.email, - 'roles': model.roles?.map((m) => RoleSerializer.toMap(m))?.toList() + 'roles': model.roles.map((m) => RoleSerializer.toMap(m)).toList() }; } } @@ -891,9 +886,6 @@ class RoleUserSerializer extends Codec { } static Map toMap(_RoleUser model) { - if (model == null) { - return null; - } return { 'role': RoleSerializer.toMap(model.role), 'user': UserSerializer.toMap(model.user) @@ -911,11 +903,11 @@ abstract class RoleUserFields { const RoleSerializer roleSerializer = RoleSerializer(); -class RoleEncoder extends Converter { +class RoleEncoder extends Converter { const RoleEncoder(); @override - Map convert(Role model) => RoleSerializer.toMap(model); + Map? convert(Role model) => RoleSerializer.toMap(model); } class RoleDecoder extends Converter { @@ -925,7 +917,7 @@ class RoleDecoder extends Converter { Role convert(Map map) => RoleSerializer.fromMap(map); } -class RoleSerializer extends Codec { +class RoleSerializer extends Codec { const RoleSerializer(); @override @@ -934,25 +926,25 @@ class RoleSerializer extends Codec { get decoder => const RoleDecoder(); static Role fromMap(Map map) { return Role( - id: map['id'] as String, + id: map['id'] as String?, createdAt: map['created_at'] != null ? (map['created_at'] is DateTime - ? (map['created_at'] as DateTime) + ? (map['created_at'] as DateTime?) : DateTime.parse(map['created_at'].toString())) : null, updatedAt: map['updated_at'] != null ? (map['updated_at'] is DateTime - ? (map['updated_at'] as DateTime) + ? (map['updated_at'] as DateTime?) : DateTime.parse(map['updated_at'].toString())) : null, - name: map['name'] as String, + name: map['name'] as String?, users: map['users'] is Iterable ? List.unmodifiable(((map['users'] as Iterable).whereType()) .map(UserSerializer.fromMap)) : null); } - static Map toMap(_Role model) { + static Map? toMap(_Role? model) { if (model == null) { return null; } @@ -961,7 +953,7 @@ class RoleSerializer extends Codec { 'created_at': model.createdAt?.toIso8601String(), 'updated_at': model.updatedAt?.toIso8601String(), 'name': model.name, - 'users': model.users?.map((m) => UserSerializer.toMap(m))?.toList() + 'users': model.users.map((m) => UserSerializer.toMap(m)).toList() }; } } 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 02107dac..6f6f9070 100644 --- a/packages/orm/angel_orm_test/lib/src/standalone_test.dart +++ b/packages/orm/angel_orm_test/lib/src/standalone_test.dart @@ -6,14 +6,14 @@ import 'models/car.dart'; final DateTime y2k = new DateTime.utc(2000, 1, 1); standaloneTests(FutureOr Function() createExecutor, - {FutureOr Function(QueryExecutor) close}) { + {FutureOr Function(QueryExecutor)? close}) { close ??= (_) => null; test('to where', () { var query = new CarQuery(); query.where - ..familyFriendly.isTrue + ?..familyFriendly.isTrue ..recalledAt.lessThanOrEqualTo(y2k, includeTime: false); - var whereClause = query.where.compile(tableName: 'cars'); + var whereClause = query.where!.compile(tableName: 'cars'); print('Where clause: $whereClause'); expect(whereClause, 'cars.family_friendly = TRUE AND cars.recalled_at <= \'2000-01-01\''); @@ -24,34 +24,35 @@ standaloneTests(FutureOr Function() createExecutor, // var row = [0, 'Mazda', 'CX9', true, y2k, y2k, y2k]; var row = [0, y2k, y2k, 'Mazda', 'CX9', true, y2k]; print(row); - var car = new CarQuery().deserialize(row); + var car = new CarQuery().deserialize(row)!; print(car.toJson()); expect(car.id, '0'); expect(car.make, 'Mazda'); expect(car.description, 'CX9'); expect(car.familyFriendly, true); - expect(y2k.toIso8601String(), startsWith(car.recalledAt.toIso8601String())); - expect(y2k.toIso8601String(), startsWith(car.createdAt.toIso8601String())); - expect(y2k.toIso8601String(), startsWith(car.updatedAt.toIso8601String())); + expect( + y2k.toIso8601String(), startsWith(car.recalledAt!.toIso8601String())); + expect(y2k.toIso8601String(), startsWith(car.createdAt!.toIso8601String())); + expect(y2k.toIso8601String(), startsWith(car.updatedAt!.toIso8601String())); }); group('queries', () { - QueryExecutor executor; + late QueryExecutor executor; setUp(() async { executor = await createExecutor(); }); - tearDown(() => close(executor)); + tearDown(() => close!(executor)); group('selects', () { test('select all', () async { - var cars = await new CarQuery().get(executor); + List cars = await new CarQuery().get(executor); expect(cars, []); }); group('with data', () { - Car ferrari; + Car? ferrari; setUp(() async { var query = new CarQuery(); @@ -63,26 +64,26 @@ standaloneTests(FutureOr Function() createExecutor, }); test('where clause is applied', () async { - var query = new CarQuery()..where.familyFriendly.isTrue; - var cars = await query.get(executor); + var query = new CarQuery()..where!.familyFriendly.isTrue; + List cars = await query.get(executor); expect(cars, isEmpty); - var sportsCars = new CarQuery()..where.familyFriendly.isFalse; + var sportsCars = new CarQuery()..where!.familyFriendly.isFalse; cars = await sportsCars.get(executor); - print(cars.map((c) => c.toJson())); + print(cars.map((c) => c!.toJson())); - var car = cars.first; - expect(car.make, ferrari.make); - expect(car.description, ferrari.description); - expect(car.familyFriendly, ferrari.familyFriendly); + var car = cars.first!; + expect(car.make, ferrari!.make); + expect(car.description, ferrari!.description); + expect(car.familyFriendly, ferrari!.familyFriendly); expect(car.recalledAt, isNull); }); test('union', () async { - var query1 = new CarQuery()..where.make.like('%Fer%'); - var query2 = new CarQuery()..where.familyFriendly.isTrue; - var query3 = new CarQuery()..where.description.equals('Submarine'); - var union = query1.union(query2).unionAll(query3); + var query1 = new CarQuery()..where!.make.like('%Fer%'); + var query2 = new CarQuery()..where!.familyFriendly.isTrue; + var query3 = new CarQuery()..where!.description.equals('Submarine'); + Union union = query1.union(query2).unionAll(query3); print(union.compile(Set())); var cars = await union.get(executor); expect(cars, hasLength(1)); @@ -90,63 +91,63 @@ standaloneTests(FutureOr Function() createExecutor, test('or clause', () async { var query = new CarQuery() - ..where.make.like('Fer%') + ..where!.make.like('Fer%') ..orWhere((where) => where - ..familyFriendly.isTrue + ?..familyFriendly.isTrue ..make.equals('Honda')); print(query.compile(Set())); - var cars = await query.get(executor); + List cars = await query.get(executor); expect(cars, hasLength(1)); }); test('limit obeyed', () async { var query = new CarQuery()..limit(0); print(query.compile(Set())); - var cars = await query.get(executor); + List cars = await query.get(executor); expect(cars, isEmpty); }); test('get one', () async { - var id = int.parse(ferrari.id); - var query = new CarQuery()..where.id.equals(id); + var id = int.parse(ferrari!.id!); + var query = new CarQuery()..where!.id.equals(id); var car = await query.getOne(executor); expect(car, ferrari); }); test('delete one', () async { - var id = int.parse(ferrari.id); - var query = new CarQuery()..where.id.equals(id); - var car = await query.deleteOne(executor); - expect(car.toJson(), ferrari.toJson()); + var id = int.parse(ferrari!.id!); + var query = new CarQuery()..where!.id.equals(id); + var car = await (query.deleteOne(executor) as FutureOr); + expect(car.toJson(), ferrari!.toJson()); - var cars = await new CarQuery().get(executor); + List cars = await new CarQuery().get(executor); expect(cars, isEmpty); }); test('delete stream', () async { var query = new CarQuery() - ..where.make.equals('Ferrarię±') - ..orWhere((w) => w.familyFriendly.isTrue); + ..where!.make.equals('Ferrarię±') + ..orWhere((w) => w!.familyFriendly.isTrue); print(query.compile(Set(), preamble: 'DELETE FROM "cars"')); - var cars = await query.delete(executor); + List cars = await query.delete(executor); expect(cars, hasLength(1)); - expect(cars.first.toJson(), ferrari.toJson()); + expect(cars.first!.toJson(), ferrari!.toJson()); }); test('update', () async { var query = new CarQuery() - ..where.id.equals(int.parse(ferrari.id)) + ..where!.id.equals(int.parse(ferrari!.id!)) ..values.make = 'Hyundai'; - var cars = await query.update(executor); + List cars = await query.update(executor); expect(cars, hasLength(1)); - expect(cars.first.make, 'Hyundai'); + expect(cars.first!.make, 'Hyundai'); }); test('update car', () async { - var cloned = ferrari.copyWith(make: 'Angel'); + var cloned = ferrari!.copyWith(make: 'Angel'); var query = new CarQuery()..values.copyFrom(cloned); - var car = await query.updateOne(executor); + var car = await (query.updateOne(executor) as FutureOr); print(car.toJson()); expect(car.toJson(), cloned.toJson()); }); @@ -164,12 +165,12 @@ standaloneTests(FutureOr Function() createExecutor, ..recalledAt = recalledAt ..createdAt = now ..updatedAt = now; - var car = await query.insert(executor); + var car = await (query.insert(executor) as FutureOr); expect(car.id, isNotNull); expect(car.make, 'Honda'); expect(car.description, 'Hello'); expect(car.familyFriendly, isTrue); - expect(dateYmdHms.format(car.recalledAt), dateYmdHms.format(recalledAt)); + expect(dateYmdHms.format(car.recalledAt!), dateYmdHms.format(recalledAt)); expect(car.createdAt, allOf(isNotNull, equals(car.updatedAt))); }); @@ -181,13 +182,13 @@ standaloneTests(FutureOr Function() createExecutor, familyFriendly: true, recalledAt: recalledAt); var query = new CarQuery()..values.copyFrom(beetle); - var car = await query.insert(executor); + var car = await (query.insert(executor) as FutureOr); print(car.toJson()); expect(car.make, beetle.make); expect(car.description, beetle.description); expect(car.familyFriendly, beetle.familyFriendly); - expect(dateYmdHms.format(car.recalledAt), - dateYmdHms.format(beetle.recalledAt)); + expect(dateYmdHms.format(car.recalledAt!), + dateYmdHms.format(beetle.recalledAt!)); }); }); } diff --git a/packages/orm/angel_orm_test/pubspec.yaml b/packages/orm/angel_orm_test/pubspec.yaml index d5a83f87..e5e430e7 100644 --- a/packages/orm/angel_orm_test/pubspec.yaml +++ b/packages/orm/angel_orm_test/pubspec.yaml @@ -1,40 +1,40 @@ name: angel_orm_test -version: 1.0.0 +version: 3.0.0 publish_to: none description: Common tests for Angel ORM backends. environment: - sdk: '>=2.10.0 <3.0.0' + sdk: '>=2.12.0 <3.0.0' dependencies: angel_migration: git: url: https://github.com/dukefirehawk/angel.git - ref: sdk-2.12.x + ref: sdk-2.12.x_nnbd path: packages/orm/angel_migration angel_model: git: url: https://github.com/dukefirehawk/angel.git - ref: sdk-2.12.x + ref: sdk-2.12.x_nnbd path: packages/model angel_orm: git: url: https://github.com/dukefirehawk/angel.git - ref: sdk-2.12.x + ref: sdk-2.12.x_nnbd path: packages/orm/angel_orm angel_serialize: git: url: https://github.com/dukefirehawk/angel.git - ref: sdk-2.12.x + ref: sdk-2.12.x_nnbd path: packages/serialize/angel_serialize - test: ^1.15.7 + test: ^1.17.3 dev_dependencies: angel_orm_generator: git: url: https://github.com/dukefirehawk/angel.git - ref: sdk-2.12.x + ref: sdk-2.12.x_nnbd path: packages/orm/angel_orm_generator angel_framework: git: url: https://github.com/dukefirehawk/angel.git - ref: sdk-2.12.x + ref: sdk-2.12.x_nnbd path: packages/framework - build_runner: ^1.0.0 + build_runner: ^2.0.1