From 98f191eb59cf9c853dd8a54a845a029c7a4ddef8 Mon Sep 17 00:00:00 2001 From: FrancescoBorzi Date: Sun, 16 Jun 2019 19:26:17 +0200 Subject: [PATCH] fix: squel bug workaround - https://github.com/hiddentao/squel/issues/372 --- angular.json | 8 ++++++-- src/app/services/query.service.ts | 22 ++++++++++++---------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/angular.json b/angular.json index c4a2695515..0f968be916 100644 --- a/angular.json +++ b/angular.json @@ -27,7 +27,9 @@ "styles": [ "src/assets/scss/main.scss" ], - "scripts": [] + "scripts": [ + "node_modules/squel/dist/squel.min.js" + ] }, "configurations": { "dev": { @@ -93,7 +95,9 @@ "polyfills": "src/polyfills-test.ts", "tsConfig": "src/tsconfig.spec.json", "karmaConfig": "src/karma.conf.js", - "scripts": [], + "scripts": [ + "node_modules/squel/dist/squel.min.js" + ], "styles": [ "src/assets/scss/main.scss" ], diff --git a/src/app/services/query.service.ts b/src/app/services/query.service.ts index 6ade127acf..602083c7d1 100644 --- a/src/app/services/query.service.ts +++ b/src/app/services/query.service.ts @@ -1,10 +1,12 @@ import { Injectable } from '@angular/core'; -import * as squel from 'squel'; +import { Observable } from 'rxjs'; +import { Squel, Delete, Insert } from 'squel'; import { MysqlService } from './mysql.service'; import { MaxRow, MysqlResult, QueryForm, TableRow } from '../types'; import { squelConfig } from '../config/squel.config'; -import { Observable } from 'rxjs'; + +declare const squel: Squel & {flavour: null}; @Injectable({ providedIn: 'root' @@ -129,8 +131,8 @@ export class QueryService { private getFinalDiffDeleteInsertQuery( addedOrEditedRows: T[], - deleteQuery: squel.Delete, - insertQuery: squel.Insert, + deleteQuery: Delete, + insertQuery: Insert, ): string { let query = deleteQuery.toString() + ';\n'; @@ -169,8 +171,8 @@ export class QueryService { return '-- There are no changes'; } - const deleteQuery: squel.Delete = squel.delete(squelConfig).from(tableName); - const insertQuery: squel.Insert = squel.insert(squelConfig).into(tableName); + const deleteQuery: Delete = squel.delete(squelConfig).from(tableName); + const insertQuery: Insert = squel.insert(squelConfig).into(tableName); if (primaryKey1) { deleteQuery.where('`' + primaryKey1 + '` = ' + newRows[0][primaryKey1]); @@ -201,8 +203,8 @@ export class QueryService { return '-- There are no changes'; } - const deleteQuery: squel.Delete = squel.delete(squelConfig).from(tableName); - const insertQuery: squel.Insert = squel.insert(squelConfig).into(tableName); + const deleteQuery: Delete = squel.delete(squelConfig).from(tableName); + const insertQuery: Insert = squel.insert(squelConfig).into(tableName); deleteQuery.where('`' + primaryKey + '` IN ?', involvedRows); insertQuery.setFieldsRows(addedOrEditedRows); @@ -232,8 +234,8 @@ export class QueryService { deleteCondition += '`' + primaryKey2 + '` IN (' + ids.join(', ') + ')'; } - const deleteQuery: squel.Delete = squel.delete(squelConfig).from(tableName).where(deleteCondition); - const insertQuery: squel.Insert = squel.insert(squelConfig).into(tableName).setFieldsRows(rows); + const deleteQuery: Delete = squel.delete(squelConfig).from(tableName).where(deleteCondition); + const insertQuery: Insert = squel.insert(squelConfig).into(tableName).setFieldsRows(rows); let query: string = deleteQuery.toString() + ';\n'; query += insertQuery.toString() + ';\n';