Skip to content

Commit

Permalink
fix: nil parameters with named placeholders
Browse files Browse the repository at this point in the history
- Fixes the remaining edge-case bug with passing nil parameters
  • Loading branch information
darksaid98 committed Oct 16, 2021
1 parent b1babdb commit a6d483c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/parser.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit a6d483c

Please sign in to comment.