diff --git a/CHANGELOG.md b/CHANGELOG.md index 08c95d55..99c8b69f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,10 +34,10 @@ * Migrated angel_orm to 3.0.0 (0/0 tests passed) * Migrated angel_migration to 3.0.0 (0/0 tests passed) * Added inflection2 and migrated to 1.0.0 (28/32 tests passed) -* Updated angel_orm_generator to 4.0.0 (0/0 tests passed) -* Updated angel_migration_runner to 3.0.0 (0/0 tests passed) -* Updated angel_orm_test to 1.0.0 (in progress) -* Updated angel_orm_postgres to 2.0.0 (in progress) +* Migrated angel_orm_generator to 4.0.0 (0/0 tests passed) +* Migrated angel_migration_runner to 3.0.0 (0/0 tests passed) +* Migrated angel_orm_test to 3.0.0 (0/0 tests passed) +* Migrated angel_orm_postgres to 3.0.0 (0/0 tests passed) * Update orm-sdk-2.12.x boilerplate (in progress) <= Milestone 2 diff --git a/packages/orm/angel_orm_postgres/lib/angel_orm_postgres.dart b/packages/orm/angel_orm_postgres/lib/angel_orm_postgres.dart index 83cff0c3..faa1900f 100644 --- a/packages/orm/angel_orm_postgres/lib/angel_orm_postgres.dart +++ b/packages/orm/angel_orm_postgres/lib/angel_orm_postgres.dart @@ -9,7 +9,7 @@ class PostgreSqlExecutor extends QueryExecutor { PostgreSQLExecutionContext _connection; /// An optional [Logger] to print information to. - final Logger logger; + final Logger? logger; PostgreSqlExecutor(this._connection, {this.logger}); @@ -27,8 +27,8 @@ class PostgreSqlExecutor extends QueryExecutor { @override Future> query( - String tableName, String query, Map substitutionValues, - [List returningFields]) { + String tableName, String? query, Map substitutionValues, + [List? returningFields]) { if (returningFields != null) { var fields = returningFields.join(', '); var returning = 'RETURNING $fields'; @@ -37,15 +37,17 @@ class PostgreSqlExecutor extends QueryExecutor { logger?.fine('Query: $query'); logger?.fine('Values: $substitutionValues'); - return _connection.query(query, substitutionValues: substitutionValues); + return _connection.query(query!, substitutionValues: substitutionValues); } @override - Future transaction(FutureOr Function(QueryExecutor) f) async { - if (_connection is! PostgreSQLConnection) return await f(this); + Future transaction(FutureOr Function(QueryExecutor) f) async { + if (_connection is! PostgreSQLConnection) { + return await f(this); + } var conn = _connection as PostgreSQLConnection; - T returnValue; + T? returnValue; var txResult = await conn.transaction((ctx) async { try { @@ -61,12 +63,12 @@ class PostgreSqlExecutor extends QueryExecutor { }); if (txResult is PostgreSQLRollback) { - if (txResult.reason == null) { - throw StateError('The transaction was cancelled.'); - } else { - throw StateError( - 'The transaction was cancelled with reason "${txResult.reason}".'); - } + //if (txResult.reason == null) { + // throw StateError('The transaction was cancelled.'); + //} else { + throw StateError( + 'The transaction was cancelled with reason "${txResult.reason}".'); + //} } else { return returnValue; } @@ -84,7 +86,7 @@ class PostgreSqlExecutorPool extends QueryExecutor { final PostgreSQLConnection Function() connectionFactory; /// An optional [Logger] to print information to. - final Logger logger; + final Logger? logger; final List _connections = []; int _index = 0; @@ -124,8 +126,8 @@ class PostgreSqlExecutorPool extends QueryExecutor { @override Future> query( - String tableName, String query, Map substitutionValues, - [List returningFields]) { + String tableName, String? query, Map substitutionValues, + [List? returningFields]) { return _pool.withResource(() async { var executor = await _next(); return executor.query( @@ -134,7 +136,7 @@ class PostgreSqlExecutorPool extends QueryExecutor { } @override - Future transaction(FutureOr Function(QueryExecutor) f) { + Future transaction(FutureOr Function(QueryExecutor) f) { return _pool.withResource(() async { var executor = await _next(); return executor.transaction(f); diff --git a/packages/orm/angel_orm_postgres/pubspec.yaml b/packages/orm/angel_orm_postgres/pubspec.yaml index 9be827e1..b550f29a 100644 --- a/packages/orm/angel_orm_postgres/pubspec.yaml +++ b/packages/orm/angel_orm_postgres/pubspec.yaml @@ -1,32 +1,29 @@ name: angel_orm_postgres -version: 2.0.0 +version: 3.0.0 description: PostgreSQL support for Angel's ORM. Includes functionality for querying and transactions. -author: Tobe O -homepage: https://github.com/angel-dart/orm +homepage: https://github.com/dukefirehawk/angel publish_to: none environment: - sdk: '>=2.10.0 <3.0.0' + sdk: '>=2.12.0 <3.0.0' dependencies: 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 - logging: ^1.0.0 - pool: ^1.0.0 - postgres: - git: - url: https://github.com/dukefirehawk/postgresql-dart + logging: ^1.0.1 + pool: ^1.5.0 + postgres: ^2.3.2 dev_dependencies: angel_orm_test: git: url: https://github.com/dukefirehawk/angel.git - ref: sdk-2.12.x + ref: sdk-2.12.x_nnbd path: packages/orm/angel_orm_test pretty_logging: git: url: https://github.com/dukefirehawk/angel.git - ref: sdk-2.12.x + ref: sdk-2.12.x_nnbd path: packages/pretty_logging - test: ^1.15.7 + test: ^1.17.3 diff --git a/packages/orm/angel_orm_postgres/test/common.dart b/packages/orm/angel_orm_postgres/test/common.dart index 84be5128..75677844 100644 --- a/packages/orm/angel_orm_postgres/test/common.dart +++ b/packages/orm/angel_orm_postgres/test/common.dart @@ -13,13 +13,13 @@ Future closePg(QueryExecutor executor) => (executor as PostgreSqlExecutor).close(); Future connectToPostgres(Iterable schemas) async { - var conn = new PostgreSQLConnection('127.0.0.1', 5432, 'angel_orm_test', - username: Platform.environment['POSTGRES_USERNAME'] ?? 'postgres', - password: Platform.environment['POSTGRES_PASSWORD'] ?? 'password'); + var conn = PostgreSQLConnection('127.0.0.1', 5432, 'orm_test', + username: Platform.environment['POSTGRES_USERNAME'] ?? 'test', + password: Platform.environment['POSTGRES_PASSWORD'] ?? 'test123'); await conn.open(); for (var s in schemas) - await conn.execute(await new File('test/migrations/$s.sql').readAsString()); + await conn.execute(await File('test/migrations/$s.sql').readAsString()); - return new PostgreSqlExecutor(conn, logger: Logger.root); + return PostgreSqlExecutor(conn, logger: Logger.root); } 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 946c8109..78866493 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 @@ -16,14 +16,14 @@ belongsToTests(FutureOr Function() createExecutor, executor = await createExecutor(); // Insert an author - var query = new AuthorQuery()..values.name = 'J.K. Rowling'; + var query = AuthorQuery()..values.name = 'J.K. Rowling'; jkRowling = await query.insert(executor); query.values.name = 'J.K. Jameson'; jameson = await query.insert(executor); // And a book - var bookQuery = new BookQuery(); + var bookQuery = BookQuery(); bookQuery.values ..authorId = int.parse(jkRowling!.id!) ..partnerAuthorId = int.parse(jameson!.id!) @@ -36,7 +36,7 @@ belongsToTests(FutureOr Function() createExecutor, group('selects', () { test('select all', () async { - var query = new BookQuery(); + var query = BookQuery(); List books = await query.get(executor); expect(books, hasLength(1)); @@ -52,7 +52,7 @@ belongsToTests(FutureOr Function() createExecutor, }); test('select one', () async { - var query = new BookQuery(); + var query = BookQuery(); query.where!.id.equals(int.parse(deathlyHallows!.id!)); print(query.compile(Set())); @@ -68,15 +68,15 @@ belongsToTests(FutureOr Function() createExecutor, }); test('where clause', () async { - var query = new BookQuery() + var query = BookQuery() ..where!.name.equals('Goblet of Fire') ..orWhere((w) => w!.authorId.equals(int.parse(jkRowling!.id!))); print(query.compile(Set())); - List books = await query.get(executor); + List books = await query.get(executor) as List; 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); @@ -88,9 +88,9 @@ belongsToTests(FutureOr Function() createExecutor, }); test('union', () async { - var query1 = new BookQuery()..where!.name.like('Deathly%'); - var query2 = new BookQuery()..where!.authorId.equals(-1); - var query3 = new BookQuery() + var query1 = BookQuery()..where!.name.like('Deathly%'); + var query2 = BookQuery()..where!.authorId.equals(-1); + var query3 = BookQuery() ..where!.name.isIn(['Goblet of Fire', 'Order of the Phoenix']); query1 ..union(query2) @@ -126,12 +126,12 @@ belongsToTests(FutureOr Function() createExecutor, test('delete stream', () async { printSeparator('Delete stream test'); - var query = new BookQuery()..where!.name.equals(deathlyHallows!.name!); + var query = BookQuery()..where!.name.equals(deathlyHallows!.name!); print(query.compile(Set(), preamble: 'DELETE', withFields: false)); - List books = await query.delete(executor); + List? books = await query.delete(executor) as List; expect(books, hasLength(1)); - var book = books.first!; + var book = books.first; expect(book.id, deathlyHallows!.id); expect(book.author, isNotNull); expect(book.author!.name, jkRowling!.name); @@ -139,7 +139,7 @@ belongsToTests(FutureOr Function() createExecutor, test('update book', () async { var cloned = deathlyHallows!.copyWith(name: "Sorcerer's Stone"); - var query = new BookQuery() + var query = BookQuery() ..where!.id.equals(int.parse(cloned.id!)) ..values.copyFrom(cloned); var book = await (query.updateOne(executor) as FutureOr); 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 f553f302..fd7049da 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 @@ -2,7 +2,6 @@ import 'dart:async'; import 'package:angel_orm/angel_orm.dart'; import 'package:test/test.dart'; import 'models/custom_expr.dart'; -import 'util.dart'; customExprTests(FutureOr Function() createExecutor, {FutureOr Function(QueryExecutor)? close}) { 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 052aab08..3eaba995 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 @@ -11,7 +11,7 @@ hasManyTests(FutureOr Function() createExecutor, close ??= (_) => null; setUp(() async { - var query = new TreeQuery()..values.rings = 10; + var query = TreeQuery()..values.rings = 10; executor = await createExecutor(); appleTree = await query.insert(executor); @@ -36,11 +36,11 @@ hasManyTests(FutureOr Function() createExecutor, } setUp(() async { - var appleQuery = new FruitQuery() + var appleQuery = FruitQuery() ..values.treeId = treeId ..values.commonName = 'Apple'; - var bananaQuery = new FruitQuery() + var bananaQuery = FruitQuery() ..values.treeId = treeId ..values.commonName = 'Banana'; @@ -49,13 +49,13 @@ hasManyTests(FutureOr Function() createExecutor, }); test('can fetch any children', () async { - var query = new TreeQuery()..where!.id.equals(treeId); + var query = TreeQuery()..where!.id.equals(treeId); var tree = await (query.getOne(executor) as FutureOr); verify(tree); }); test('sets on update', () async { - var tq = new TreeQuery() + var tq = TreeQuery() ..where!.id.equals(treeId) ..values.rings = 24; var tree = await (tq.updateOne(executor) as FutureOr); @@ -64,13 +64,13 @@ hasManyTests(FutureOr Function() createExecutor, }); test('sets on delete', () async { - var tq = new TreeQuery()..where!.id.equals(treeId); + var tq = 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() + var tq = TreeQuery() ..where!.id.equals(treeId) ..fruits!.where!.commonName.equals('Kiwi'); var tree = await (tq.getOne(executor) as FutureOr); 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 ab55f027..d4cb624b 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 @@ -11,7 +11,7 @@ hasOneTests(FutureOr Function() createExecutor, setUp(() async { executor = await createExecutor(); - var query = new LegQuery()..values.name = 'Left'; + var query = LegQuery()..values.name = 'Left'; originalLeg = await query.insert(executor); }); @@ -19,7 +19,7 @@ hasOneTests(FutureOr Function() createExecutor, test('sets to null if no child', () async { print(LegQuery().compile(Set())); - var query = new LegQuery()..where!.id.equals(int.parse(originalLeg!.id!)); + var query = LegQuery()..where!.id.equals(int.parse(originalLeg!.id!)); var leg = await (query.getOne(executor) as FutureOr); print(leg.toJson()); expect(leg.name, originalLeg!.name); @@ -28,10 +28,10 @@ hasOneTests(FutureOr Function() createExecutor, }); test('can fetch one foot', () async { - var footQuery = new FootQuery() + var footQuery = FootQuery() ..values.legId = int.parse(originalLeg!.id!) ..values.nToes = 5.64; - var legQuery = new LegQuery()..where!.id.equals(int.parse(originalLeg!.id!)); + var legQuery = LegQuery()..where!.id.equals(int.parse(originalLeg!.id!)); var foot = await (footQuery.insert(executor) as FutureOr); var leg = await (legQuery.getOne(executor) as FutureOr); @@ -43,10 +43,10 @@ hasOneTests(FutureOr Function() createExecutor, }); test('only fetches one foot even if there are multiple', () async { - var footQuery = new FootQuery() + var footQuery = FootQuery() ..values.legId = int.parse(originalLeg!.id!) ..values.nToes = 24; - var legQuery = new LegQuery()..where!.id.equals(int.parse(originalLeg!.id!)); + var legQuery = 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); @@ -57,10 +57,10 @@ hasOneTests(FutureOr Function() createExecutor, }); test('sets foot on update', () async { - var footQuery = new FootQuery() + var footQuery = FootQuery() ..values.legId = int.parse(originalLeg!.id!) ..values.nToes = 5.64; - var legQuery = new LegQuery() + var legQuery = LegQuery() ..where!.id.equals(int.parse(originalLeg!.id!)) ..values.copyFrom(originalLeg!.copyWith(name: 'Right')); var foot = await (footQuery.insert(executor) as FutureOr); @@ -73,10 +73,10 @@ hasOneTests(FutureOr Function() createExecutor, }); test('sets foot on delete', () async { - var footQuery = new FootQuery() + var footQuery = FootQuery() ..values.legId = int.parse(originalLeg!.id!) ..values.nToes = 5.64; - var legQuery = new LegQuery()..where!.id.equals(int.parse(originalLeg!.id!)); + var legQuery = 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()); @@ -87,7 +87,7 @@ hasOneTests(FutureOr Function() createExecutor, }); test('sets null on false subquery', () async { - var legQuery = new LegQuery() + var legQuery = LegQuery() ..where!.id.equals(originalLeg!.idAsInt!) ..foot!.where!.legId.equals(originalLeg!.idAsInt! + 1024); var leg = await (legQuery.getOne(executor) as FutureOr); 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 6f6f9070..62a0458b 100644 --- a/packages/orm/angel_orm_test/lib/src/standalone_test.dart +++ b/packages/orm/angel_orm_test/lib/src/standalone_test.dart @@ -3,13 +3,13 @@ import 'package:angel_orm/angel_orm.dart'; import 'package:test/test.dart'; import 'models/car.dart'; -final DateTime y2k = new DateTime.utc(2000, 1, 1); +final DateTime y2k = DateTime.utc(2000, 1, 1); standaloneTests(FutureOr Function() createExecutor, {FutureOr Function(QueryExecutor)? close}) { close ??= (_) => null; test('to where', () { - var query = new CarQuery(); + var query = CarQuery(); query.where ?..familyFriendly.isTrue ..recalledAt.lessThanOrEqualTo(y2k, includeTime: false); @@ -24,7 +24,7 @@ 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 = CarQuery().deserialize(row)!; print(car.toJson()); expect(car.id, '0'); expect(car.make, 'Mazda'); @@ -47,7 +47,7 @@ standaloneTests(FutureOr Function() createExecutor, group('selects', () { test('select all', () async { - List cars = await new CarQuery().get(executor); + List cars = await CarQuery().get(executor); expect(cars, []); }); @@ -55,7 +55,7 @@ standaloneTests(FutureOr Function() createExecutor, Car? ferrari; setUp(() async { - var query = new CarQuery(); + var query = CarQuery(); query.values ..make = 'Ferrarię±' ..description = 'Vroom vroom!' @@ -64,11 +64,11 @@ standaloneTests(FutureOr Function() createExecutor, }); test('where clause is applied', () async { - var query = new CarQuery()..where!.familyFriendly.isTrue; + var query = CarQuery()..where!.familyFriendly.isTrue; List cars = await query.get(executor); expect(cars, isEmpty); - var sportsCars = new CarQuery()..where!.familyFriendly.isFalse; + var sportsCars = CarQuery()..where!.familyFriendly.isFalse; cars = await sportsCars.get(executor); print(cars.map((c) => c!.toJson())); @@ -80,9 +80,9 @@ standaloneTests(FutureOr Function() createExecutor, }); 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 query1 = CarQuery()..where!.make.like('%Fer%'); + var query2 = CarQuery()..where!.familyFriendly.isTrue; + var query3 = CarQuery()..where!.description.equals('Submarine'); Union union = query1.union(query2).unionAll(query3); print(union.compile(Set())); var cars = await union.get(executor); @@ -90,7 +90,7 @@ standaloneTests(FutureOr Function() createExecutor, }); test('or clause', () async { - var query = new CarQuery() + var query = CarQuery() ..where!.make.like('Fer%') ..orWhere((where) => where ?..familyFriendly.isTrue @@ -101,7 +101,7 @@ standaloneTests(FutureOr Function() createExecutor, }); test('limit obeyed', () async { - var query = new CarQuery()..limit(0); + var query = CarQuery()..limit(0); print(query.compile(Set())); List cars = await query.get(executor); expect(cars, isEmpty); @@ -109,23 +109,23 @@ standaloneTests(FutureOr Function() createExecutor, test('get one', () async { var id = int.parse(ferrari!.id!); - var query = new CarQuery()..where!.id.equals(id); + var query = 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 query = CarQuery()..where!.id.equals(id); var car = await (query.deleteOne(executor) as FutureOr); expect(car.toJson(), ferrari!.toJson()); - List cars = await new CarQuery().get(executor); + List cars = await CarQuery().get(executor); expect(cars, isEmpty); }); test('delete stream', () async { - var query = new CarQuery() + var query = CarQuery() ..where!.make.equals('Ferrarię±') ..orWhere((w) => w!.familyFriendly.isTrue); print(query.compile(Set(), preamble: 'DELETE FROM "cars"')); @@ -136,7 +136,7 @@ standaloneTests(FutureOr Function() createExecutor, }); test('update', () async { - var query = new CarQuery() + var query = CarQuery() ..where!.id.equals(int.parse(ferrari!.id!)) ..values.make = 'Hyundai'; List cars = await query.update(executor); @@ -146,7 +146,7 @@ standaloneTests(FutureOr Function() createExecutor, test('update car', () async { var cloned = ferrari!.copyWith(make: 'Angel'); - var query = new CarQuery()..values.copyFrom(cloned); + var query = CarQuery()..values.copyFrom(cloned); var car = await (query.updateOne(executor) as FutureOr); print(car.toJson()); expect(car.toJson(), cloned.toJson()); @@ -155,9 +155,9 @@ standaloneTests(FutureOr Function() createExecutor, }); test('insert', () async { - var recalledAt = new DateTime.now(); - var query = new CarQuery(); - var now = new DateTime.now(); + var recalledAt = DateTime.now(); + var query = CarQuery(); + var now = DateTime.now(); query.values ..make = 'Honda' ..description = 'Hello' @@ -175,13 +175,13 @@ standaloneTests(FutureOr Function() createExecutor, }); test('insert car', () async { - var recalledAt = new DateTime.now(); - var beetle = new Car( + var recalledAt = DateTime.now(); + var beetle = Car( make: 'Beetle', description: 'Herbie', familyFriendly: true, recalledAt: recalledAt); - var query = new CarQuery()..values.copyFrom(beetle); + var query = CarQuery()..values.copyFrom(beetle); var car = await (query.insert(executor) as FutureOr); print(car.toJson()); expect(car.make, beetle.make);