mirror of
https://github.com/Fabio286/antares.git
synced 2025-06-05 21:59:22 +02:00
refactor: improve update cell condition and move whereJson formatter to sqlUtils
This commit is contained in:
@@ -8,6 +8,7 @@ import customizations from '../customizations';
|
||||
import { ClientCode } from '../interfaces/antares';
|
||||
import { getArrayDepth } from './getArrayDepth';
|
||||
import hexToBinary, { HexChar } from './hexToBinary';
|
||||
import * as antares from 'common/interfaces/antares';
|
||||
|
||||
/**
|
||||
* Escapes a string fo SQL use
|
||||
@@ -209,3 +210,20 @@ export const jsonToSqlInsert = (args: {
|
||||
|
||||
return insertsString;
|
||||
};
|
||||
|
||||
export const formatJsonForSqlWhere = (jsonValue: object, clientType: antares.ClientCode) => {
|
||||
const formattedValue = JSON.stringify(jsonValue);
|
||||
|
||||
switch (clientType) {
|
||||
case 'mysql':
|
||||
return ` = CAST('${formattedValue}' AS JSON)`;
|
||||
case 'maria':
|
||||
return ` = '${formattedValue}'`;
|
||||
case 'pg':
|
||||
return `::text = '${formattedValue}'`;
|
||||
case 'firebird':
|
||||
case 'sqlite':
|
||||
default:
|
||||
return ` = '${formattedValue}'`;
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user