-
-
Notifications
You must be signed in to change notification settings - Fork 191
/
named-placeholders+1.1.2.patch
57 lines (52 loc) · 2.07 KB
/
named-placeholders+1.1.2.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
diff --git a/node_modules/named-placeholders/index.js b/node_modules/named-placeholders/index.js
index 527d723..f47b591 100644
--- a/node_modules/named-placeholders/index.js
+++ b/node_modules/named-placeholders/index.js
@@ -3,7 +3,7 @@
// based on code from Brian White @mscdex mariasql library - https://github.com/mscdex/node-mariasql/blob/master/lib/Client.js#L272-L332
// License: https://github.com/mscdex/node-mariasql/blob/master/LICENSE
-const RE_PARAM = /(?:\?)|(?::(\d+|(?:[a-zA-Z][a-zA-Z0-9_]*)))/g,
+const RE_PARAM = /(?:\?)|(?:[:@](\d+|(?:[a-zA-Z][a-zA-Z0-9_]*)))/g,
DQUOTE = 34,
SQUOTE = 39,
BSLASH = 92;
@@ -94,15 +94,24 @@ function createCompiler(config) {
if (typeof params == 'undefined')
throw new Error('Named query contains placeholders, but parameters object is undefined');
+ for(const key in params) {
+ if(key.charAt(0) === '@' || key.charAt(0) === ':') {
+ params[key.substring(1)] = params[key];
+ delete params[key];
+ }
+ }
+
const tokens = tree[1];
for (let i=0; i < tokens.length; ++i) {
+ if(params[tokens[i]] === undefined) throw new Error(`Undefined parameter ${tokens[i]}`);
arr.push(params[tokens[i]]);
}
+
return [tree[0], arr];
}
function noTailingSemicolon(s) {
- if (s.slice(-1) == ':') {
+ if (s.slice(-1) == ':' || s.slice(-1) == '@') {
return s.slice(0, -1);
}
return s;
@@ -115,7 +124,7 @@ function createCompiler(config) {
let unnamed = noTailingSemicolon(tree[0][0]);
for (let i=1; i < tree[0].length; ++i) {
- if (tree[0][i-1].slice(-1) == ':') {
+ if (tree[0][i-1].slice(-1) == ':' || tree[0][i-1].slice(-1) == '@') {
unnamed += config.placeholder;
}
unnamed += config.placeholder;
@@ -124,7 +133,7 @@ function createCompiler(config) {
const last = tree[0][tree[0].length -1];
if (tree[0].length == tree[1].length) {
- if (last.slice(-1) == ':') {
+ if (last.slice(-1) == ':' || last.slice(-1) == '@') {
unnamed += config.placeholder;
}
unnamed += config.placeholder;