diff --git a/packages/orm/angel_orm_postgres/CHANGELOG.md b/packages/orm/angel_orm_postgres/CHANGELOG.md index a30a460a..572deb6d 100644 --- a/packages/orm/angel_orm_postgres/CHANGELOG.md +++ b/packages/orm/angel_orm_postgres/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## 3.0.1 + +* Fixed json data issue + ## 3.0.0 * Fixed NNBD issues diff --git a/packages/orm/angel_orm_postgres/README.md b/packages/orm/angel_orm_postgres/README.md index 499d4456..41edfc8b 100644 --- a/packages/orm/angel_orm_postgres/README.md +++ b/packages/orm/angel_orm_postgres/README.md @@ -1,6 +1,6 @@ # Angel3 ORM for Postgresql -[![version](https://img.shields.io/badge/pub-v4.0.0-brightgreen)](https://pub.dartlang.org/packages/angel3_orm_postgres) +[![version](https://img.shields.io/badge/pub-v4.0.1-brightgreen)](https://pub.dartlang.org/packages/angel3_orm_postgres) [![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety) [![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion) diff --git a/packages/orm/angel_orm_postgres/lib/angel3_orm_postgres.dart b/packages/orm/angel_orm_postgres/lib/angel3_orm_postgres.dart index fde370a6..433fcf66 100644 --- a/packages/orm/angel_orm_postgres/lib/angel3_orm_postgres.dart +++ b/packages/orm/angel_orm_postgres/lib/angel3_orm_postgres.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:convert'; import 'package:angel3_orm/angel3_orm.dart'; import 'package:logging/logging.dart'; import 'package:pool/pool.dart'; @@ -9,9 +10,15 @@ class PostgreSqlExecutor extends QueryExecutor { final PostgreSQLExecutionContext _connection; /// An optional [Logger] to print information to. - final Logger? logger; + late Logger logger; - PostgreSqlExecutor(this._connection, {this.logger}); + PostgreSqlExecutor(this._connection, {Logger? logger}) { + if (logger != null) { + this.logger = logger; + } else { + this.logger = Logger('PostgreSqlExecutor'); + } + } /// The underlying connection. PostgreSQLExecutionContext get connection => _connection; @@ -27,7 +34,7 @@ class PostgreSqlExecutor extends QueryExecutor { @override Future> query( - String tableName, String? query, Map substitutionValues, + String tableName, String query, Map substitutionValues, [List? returningFields]) { if (returningFields != null) { var fields = returningFields.join(', '); @@ -35,9 +42,20 @@ class PostgreSqlExecutor extends QueryExecutor { query = '$query $returning'; } - logger?.fine('Query: $query'); - logger?.fine('Values: $substitutionValues'); - return _connection.query(query!, substitutionValues: substitutionValues); + logger.fine('Query: $query'); + logger.fine('Values: $substitutionValues'); + + // Convert List into String + var param = {}; + substitutionValues.forEach((key, value) { + if (value is List) { + param[key] = jsonEncode(value); + } else { + param[key] = value; + } + }); + + return _connection.query(query, substitutionValues: param); } @override @@ -51,7 +69,7 @@ class PostgreSqlExecutor extends QueryExecutor { var txResult = await conn.transaction((ctx) async { try { - logger?.fine('Entering transaction'); + logger.fine('Entering transaction'); var tx = PostgreSqlExecutor(ctx, logger: logger); returnValue = await f(tx); @@ -60,7 +78,7 @@ class PostgreSqlExecutor extends QueryExecutor { ctx.cancelTransaction(reason: e.toString()); rethrow; } finally { - logger?.fine('Exiting transaction'); + logger.fine('Exiting transaction'); } }); @@ -88,14 +106,20 @@ class PostgreSqlExecutorPool extends QueryExecutor { final PostgreSQLConnection Function() connectionFactory; /// An optional [Logger] to print information to. - final Logger? logger; + late Logger logger; final List _connections = []; int _index = 0; final Pool _pool, _connMutex = Pool(1); - PostgreSqlExecutorPool(this.size, this.connectionFactory, {this.logger}) + PostgreSqlExecutorPool(this.size, this.connectionFactory, {Logger? logger}) : _pool = Pool(size) { + if (logger != null) { + this.logger = logger; + } else { + this.logger = Logger('PostgreSqlExecutorPool'); + } + assert(size > 0, 'Connection pool cannot be empty.'); } @@ -109,7 +133,7 @@ class PostgreSqlExecutorPool extends QueryExecutor { Future _open() async { if (_connections.isEmpty) { _connections.addAll(await Future.wait(List.generate(size, (_) { - logger?.fine('Spawning connections...'); + logger.fine('Spawning connections...'); var conn = connectionFactory(); return conn .open() @@ -128,7 +152,7 @@ class PostgreSqlExecutorPool extends QueryExecutor { @override Future> query( - String tableName, String? query, Map substitutionValues, + String tableName, String query, Map substitutionValues, [List? returningFields]) { return _pool.withResource(() async { var executor = await _next(); diff --git a/packages/orm/angel_orm_postgres/pubspec.yaml b/packages/orm/angel_orm_postgres/pubspec.yaml index 36667d6f..ac2d2dc1 100644 --- a/packages/orm/angel_orm_postgres/pubspec.yaml +++ b/packages/orm/angel_orm_postgres/pubspec.yaml @@ -1,5 +1,5 @@ name: angel3_orm_postgres -version: 3.0.0 +version: 3.0.1 description: PostgreSQL support for Angel3 ORM. Includes functionality for querying and transactions. homepage: https://angel3-framework.web.app/ repository: https://github.com/dukefirehawk/angel/tree/angel3/packages/orm/angel_orm_postgres @@ -15,4 +15,3 @@ dev_dependencies: test: ^1.17.0 pedantic: ^1.11.0 angel3_orm_test: ^3.0.0 -