diff --git a/src/parser.js b/src/parser.js index ca51fe2..979a00e 100644 --- a/src/parser.js +++ b/src/parser.js @@ -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);