diff --git a/packages/dox-app/pubspec.yaml b/packages/dox-app/pubspec.yaml index 3345027..d06df41 100644 --- a/packages/dox-app/pubspec.yaml +++ b/packages/dox-app/pubspec.yaml @@ -5,7 +5,7 @@ environment: sdk: '>=3.0.0 <4.0.0' dependencies: - postgres: ^3.0.4 + postgres: ^3.0.5 ioredis: ^1.0.2 short_uuids: ^2.0.0 dox_auth: ^2.0.0-beta.2 diff --git a/packages/dox-query-builder/lib/src/drivers/db_driver.dart b/packages/dox-query-builder/lib/src/drivers/db_driver.dart index 27eb0fd..4086995 100644 --- a/packages/dox-query-builder/lib/src/drivers/db_driver.dart +++ b/packages/dox-query-builder/lib/src/drivers/db_driver.dart @@ -7,8 +7,7 @@ abstract class DBDriver { {Map? substitutionValues}); /// run query and return map result - Future>>> mappedResultsQuery( - String query, + Future>> mappedResultsQuery(String query, {Map? substitutionValues}); /// run query, this function do not return any value diff --git a/packages/dox-query-builder/lib/src/drivers/postgres_driver.dart b/packages/dox-query-builder/lib/src/drivers/postgres_driver.dart index 96e2150..b73108c 100644 --- a/packages/dox-query-builder/lib/src/drivers/postgres_driver.dart +++ b/packages/dox-query-builder/lib/src/drivers/postgres_driver.dart @@ -23,7 +23,7 @@ class PostgresDriver extends DBDriver { /// run query and return map result @override - Future>>> mappedResultsQuery( + Future>> mappedResultsQuery( String query, { Map? substitutionValues, }) async { @@ -44,37 +44,7 @@ class PostgresDriver extends DBDriver { /// extension on postgres extension ToMapList on Result { - List>> toMapList() { - List>> data = - >>[]; - forEach((ResultRow element) { - data.add(element.toMappedColumns()); - }); - return data; - } -} - -extension ToMappedColumns on ResultRow { - Map> toMappedColumns() { - Map> data = >{}; - - for (var (int i, ResultSchemaColumn col) in schema.columns.indexed) { - String tableId = col.tableOid.toString(); - if (col.columnName case String name) { - if (data[tableId] == null) { - data[tableId] = {}; - } - Map table = data[tableId]!; - table[name] = this[i]; - } else { - if (data[tableId] == null) { - data[tableId] = {}; - } - Map table = data[tableId]!; - String name = '[$i]'; - table[name] = this[i]; - } - } - return data; + List> toMapList() { + return map((ResultRow element) => element.toColumnMap()).toList(); } } diff --git a/packages/dox-query-builder/lib/src/insert.dart b/packages/dox-query-builder/lib/src/insert.dart index 97141b0..38239a3 100644 --- a/packages/dox-query-builder/lib/src/insert.dart +++ b/packages/dox-query-builder/lib/src/insert.dart @@ -25,12 +25,11 @@ mixin Insert implements SharedMixin { // ignore: always_specify_types Future insert(Map data) async { // ignore: always_specify_types - List>> result = + List> result = await insertMultiple(>[data]); if (result.isNotEmpty) { - Map> insertedData = result.first; - String tableId = insertedData.keys.first; - int id = insertedData[tableId]?[primaryKey] ?? 0; + Map insertedData = result.first; + int id = insertedData[primaryKey] ?? 0; resetSubstitutionValues(); return await queryBuilder.find(id); } @@ -45,7 +44,7 @@ mixin Insert implements SharedMixin { /// {"title" : "Another blog title"}, /// ]); /// ``` - Future>>> insertMultiple( + Future>> insertMultiple( List> list) async { List columns = []; List values = []; diff --git a/packages/dox-query-builder/lib/src/schema/table.update.dart b/packages/dox-query-builder/lib/src/schema/table.update.dart index 27a1428..3624861 100644 --- a/packages/dox-query-builder/lib/src/schema/table.update.dart +++ b/packages/dox-query-builder/lib/src/schema/table.update.dart @@ -76,16 +76,13 @@ mixin TableUpdate implements TableSharedMixin { Future> getTableColumns() async { String query = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '$tableName'"; - List>> result = - await db.mappedResultsQuery(query); + List> result = await db.mappedResultsQuery(query); List columns = []; - for (Map> element in result) { - element.forEach((String key, Map value) { - value.forEach((String key2, dynamic value2) { - columns.add(value2.toString()); - }); + for (Map element in result) { + element.forEach((String key2, dynamic value2) { + columns.add(value2.toString()); }); } return columns; diff --git a/packages/dox-query-builder/lib/src/utils/helper.dart b/packages/dox-query-builder/lib/src/utils/helper.dart index 9320c88..f07d120 100644 --- a/packages/dox-query-builder/lib/src/utils/helper.dart +++ b/packages/dox-query-builder/lib/src/utils/helper.dart @@ -24,7 +24,7 @@ class QueryBuilderHelper { return query; } - Future>>> runQuery(String query) async { + Future>> runQuery(String query) async { Map values = queryBuilder.substitutionValues; if (queryBuilder.shouldDebug) queryBuilder.logger.log(query, values); DBDriver db = queryBuilder.db; @@ -33,22 +33,17 @@ class QueryBuilderHelper { } List> getMapResult( - List>> queryResult, + List> queryResult, ) { List> result = >[]; // setting key values format from query result - for (Map> row in queryResult) { + for (Map data in queryResult) { Map ret = {}; - (row).forEach((String mainKey, Map data) { - (data).forEach((String key, dynamic value) { - if (ret[key] == null) { - ret[key] = value is DateTime ? value.toIso8601String() : value; - } else { - ret["${mainKey}_$key"] = - value is DateTime ? value.toIso8601String() : value; - } - }); + + (data).forEach((String key, dynamic value) { + ret[key] = value is DateTime ? value.toIso8601String() : value; }); + result.add(ret); } return result; @@ -56,7 +51,7 @@ class QueryBuilderHelper { // ignore: always_specify_types Future formatResult( - List>> queryResult, + List> queryResult, ) async { List> result = getMapResult(queryResult); diff --git a/packages/dox-query-builder/pubspec.yaml b/packages/dox-query-builder/pubspec.yaml index b002e88..83f3d7a 100644 --- a/packages/dox-query-builder/pubspec.yaml +++ b/packages/dox-query-builder/pubspec.yaml @@ -8,7 +8,7 @@ environment: sdk: '>=3.0.0 <4.0.0' dependencies: - postgres: ^3.0.4 + postgres: ^3.0.5 dox_annotation: 1.0.5-alpha2.1 dev_dependencies: