Skip to content

Commit

Permalink
fix: squel bug workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancescoBorzi committed Jun 16, 2019
1 parent 3eb11f1 commit 98f191e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
8 changes: 6 additions & 2 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
"styles": [
"src/assets/scss/main.scss"
],
"scripts": []
"scripts": [
"node_modules/squel/dist/squel.min.js"
]
},
"configurations": {
"dev": {
Expand Down Expand Up @@ -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"
],
Expand Down
22 changes: 12 additions & 10 deletions src/app/services/query.service.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -129,8 +131,8 @@ export class QueryService {

private getFinalDiffDeleteInsertQuery<T extends TableRow>(
addedOrEditedRows: T[],
deleteQuery: squel.Delete,
insertQuery: squel.Insert,
deleteQuery: Delete,
insertQuery: Insert,
): string {
let query = deleteQuery.toString() + ';\n';

Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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';
Expand Down

0 comments on commit 98f191e

Please sign in to comment.