From fe44b0f60b7d7b3906c1b77b76e25d98aa7cb186 Mon Sep 17 00:00:00 2001 From: thomashii Date: Mon, 12 Feb 2024 12:31:33 +0800 Subject: [PATCH] Updated to support postgresql 3 driver --- .../angel_migration_runner/example/main.dart | 29 ++++++++++++------- packages/orm/angel_orm/lib/src/query.dart | 2 +- .../orm/angel_orm_postgres/example/main.dart | 2 +- packages/orm/angel_orm_postgres/pubspec.yaml | 10 +++---- .../orm/angel_orm_postgres/test/common.dart | 20 ++++++++----- .../lib/src/custom_expr_test.dart | 6 +++- 6 files changed, 44 insertions(+), 25 deletions(-) diff --git a/packages/orm/angel_migration_runner/example/main.dart b/packages/orm/angel_migration_runner/example/main.dart index e7a4926c..d0ec7fe8 100755 --- a/packages/orm/angel_migration_runner/example/main.dart +++ b/packages/orm/angel_migration_runner/example/main.dart @@ -1,20 +1,27 @@ +import 'dart:io'; + import 'package:angel3_migration/angel3_migration.dart'; import 'package:angel3_migration_runner/angel3_migration_runner.dart'; import 'package:angel3_migration_runner/postgres.dart'; -import 'package:angel3_migration_runner/mysql.dart'; import 'package:angel3_orm/angel3_orm.dart'; import 'package:postgres/postgres.dart'; -import 'package:mysql_client/mysql_client.dart'; import 'todo.dart'; void main(List args) async { + var host = Platform.environment['DB_HOST'] ?? 'localhost'; + var database = Platform.environment['DB_NAME'] ?? 'demo'; + var username = Platform.environment['DB_USERNAME'] ?? 'demouser'; + var password = Platform.environment['DB_PASSWORD'] ?? 'demo123'; + + print("$host $database $username $password"); + Connection conn = await Connection.open(Endpoint( - host: 'localhost', + host: host, port: 5432, - database: 'demo', - username: 'demouser', - password: 'demo123')); + database: database, + username: username, + password: password)); var postgresqlMigrationRunner = PostgresMigrationRunner( conn, @@ -25,12 +32,13 @@ void main(List args) async { ], ); + /* var mySQLConn = await MySQLConnection.createConnection( - host: "localhost", + host: host, port: 3306, - databaseName: "orm_test", - userName: "test", - password: "Test123*", + databaseName: database, + userName: username, + password: password, secure: false); // ignore: unused_local_variable @@ -42,6 +50,7 @@ void main(List args) async { FooMigration(), ], ); + */ runMigrations(postgresqlMigrationRunner, args); } diff --git a/packages/orm/angel_orm/lib/src/query.dart b/packages/orm/angel_orm/lib/src/query.dart index e5bdb612..b8145d0f 100644 --- a/packages/orm/angel_orm/lib/src/query.dart +++ b/packages/orm/angel_orm/lib/src/query.dart @@ -392,7 +392,7 @@ abstract class Query extends QueryBase { throw ArgumentError("Unsupported database dialect."); } - //_log.warning("Insert Query = $sql"); + _log.fine("Insert Query = $sql"); return executor .query(tableName, sql, substitutionValues, diff --git a/packages/orm/angel_orm_postgres/example/main.dart b/packages/orm/angel_orm_postgres/example/main.dart index b2bc8c69..8fc33fc0 100644 --- a/packages/orm/angel_orm_postgres/example/main.dart +++ b/packages/orm/angel_orm_postgres/example/main.dart @@ -5,7 +5,7 @@ import 'package:postgres/postgres.dart'; void main() async { var executor = PostgreSqlPoolExecutor(Pool.withEndpoints([ Endpoint( - host: 'localhost', + host: Platform.environment['POSTGRES_HOSTNAME'] ?? 'localhost', port: 5432, database: Platform.environment['POSTGRES_DB'] ?? 'orm_test', username: Platform.environment['POSTGRES_USERNAME'] ?? 'test', diff --git a/packages/orm/angel_orm_postgres/pubspec.yaml b/packages/orm/angel_orm_postgres/pubspec.yaml index d8a77255..2eb7c2d9 100644 --- a/packages/orm/angel_orm_postgres/pubspec.yaml +++ b/packages/orm/angel_orm_postgres/pubspec.yaml @@ -16,18 +16,18 @@ dev_dependencies: angel3_orm_test: ^8.0.0 test: ^1.24.0 lints: ^3.0.0 -# dependency_overrides: +dependency_overrides: # angel3_serialize: # path: ../../serialize/angel_serialize # angel3_serialize_generator: # path: ../../serialize/angel_serialize_generator # angel3_model: # path: ../../model -# angel3_orm_test: -# path: ../angel_orm_test + angel3_orm_test: + path: ../angel_orm_test # angel3_orm_generator: # path: ../angel_orm_generator # angel3_orm: # path: ../angel_orm -# angel3_migration: -# path: ../angel_migration + angel3_migration: + path: ../angel_migration diff --git a/packages/orm/angel_orm_postgres/test/common.dart b/packages/orm/angel_orm_postgres/test/common.dart index daac0d2e..4257eae9 100644 --- a/packages/orm/angel_orm_postgres/test/common.dart +++ b/packages/orm/angel_orm_postgres/test/common.dart @@ -20,13 +20,19 @@ Future closePg(QueryExecutor executor) async { } Future connectToPostgres(Iterable schemas) async { - // postgres://kfayrlbi:OAaEE39zOMLEPfH4DDgHbGNVsQtNdHu7@heffalump.db.elephantsql.com/kfayrlbi - var conn = await Connection.open(Endpoint( - host: 'localhost', - port: 5432, - database: Platform.environment['POSTGRES_DB'] ?? 'orm_test', - username: Platform.environment['POSTGRES_USERNAME'] ?? 'test', - password: Platform.environment['POSTGRES_PASSWORD'] ?? 'test123')); + var host = Platform.environment['POSTGRES_HOST'] ?? 'localhost'; + var database = Platform.environment['POSTGRES_NAME'] ?? 'orm_test'; + var username = Platform.environment['POSTGRES_USERNAME'] ?? 'test'; + var password = Platform.environment['POSTGRES_PASSWORD'] ?? 'test123'; + + var conn = await Connection.open( + Endpoint( + host: host, + port: 5432, + database: database, + username: username, + password: password), + settings: ConnectionSettings(sslMode: SslMode.disable)); // Run sql to create the tables for (var s in schemas) { 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 4ab71f94..0acfc03f 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 @@ -24,7 +24,11 @@ void customExprTests(FutureOr Function() createExecutor, }); }); - tearDown(() => close!(executor)); + tearDown(() { + if (close != null) { + close(executor); + } + }); test('fetches correct result', () async { expect(numbersModel.two, 2);