mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-04 14:38:50 +00:00
fix: nil parameters with named placeholders
- Fixes the remaining edge-case bug with passing nil parameters
This commit is contained in:
1 file changed
+13
-1
+13
-1
@@ -1,4 +1,7 @@
|
|||||||
import { FormatError } from './errors';
|
import { FormatError } from './errors';
|
||||||
|
import * as createCompiler from 'named-placeholders';
|
||||||
|
|
||||||
|
const convertNamedPlaceholders = createCompiler();
|
||||||
|
|
||||||
const parseTypes = (field, next) => {
|
const parseTypes = (field, next) => {
|
||||||
//https://github.com/GHMatti/ghmattimysql/blob/37f1d2ae5c53f91782d168fe81fba80512d3c46d/packages/ghmattimysql/src/server/utility/typeCast.ts#L3
|
//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 (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);
|
const queryParams = query.match(/\?(?!\?)/g);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user