fix: nil parameters with named placeholders

- Fixes the remaining edge-case bug with passing nil parameters
This commit is contained in:
darksaid98 committed 2021-10-16 19:05:57 +02:00
1 parent b1babdbc09
commit a6d483ca48
1 file changed
+13 -1
+13 -1
View File
@@ -1,4 +1,7 @@
import { FormatError } from './errors';
import * as createCompiler from 'named-placeholders';
const convertNamedPlaceholders = createCompiler();
const parseTypes = (field, next) => {
//https://github.com/GHMatti/ghmattimysql/blob/37f1d2ae5c53f91782d168fe81fba80512d3c46d/packages/ghmattimysql/src/server/utility/typeCast.ts#L3
@@ -27,7 +30,16 @@ const parseParameters = (query, parameters) => {
if (typeof parameters === 'function') return [query, []];
if (query.includes('@') || query.includes(':')) return [query, parameters];
if (query.includes('@') || query.includes(':')) {
const obj = parameters.length !== 0 ? parameters : (() => {
let obj = {};
const [_, paramName] = convertNamedPlaceholders.parse(query);
for (let i = 0; i < paramName.length; i++) obj[paramName[i]] = null;
return obj;
})();
return [query, obj]
};
const queryParams = query.match(/\?(?!\?)/g);