@prisma/client-engine-runtime 6.4.0-dev.34 → 6.4.0-dev.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +73 -24
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -34,45 +34,94 @@ function renderQueryTemplate({
|
|
|
34
34
|
query,
|
|
35
35
|
params
|
|
36
36
|
}) {
|
|
37
|
-
|
|
37
|
+
if (!query.includes(BEGIN_REPEAT)) {
|
|
38
|
+
return { query, params };
|
|
39
|
+
}
|
|
40
|
+
const flattenedParams = [];
|
|
38
41
|
let lastParamId = 1;
|
|
39
42
|
let result = "";
|
|
40
43
|
let templatePos = 0;
|
|
44
|
+
let state = 0 /* Normal */;
|
|
45
|
+
let stateBeforeQuote = 0 /* Normal */;
|
|
41
46
|
while (templatePos < query.length) {
|
|
47
|
+
const nextChar = query[templatePos];
|
|
48
|
+
if (state === 1 /* Quoted */ && nextChar !== '"') {
|
|
49
|
+
result += nextChar;
|
|
50
|
+
templatePos++;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (nextChar === '"') {
|
|
54
|
+
if (state === 1 /* Quoted */) {
|
|
55
|
+
state = stateBeforeQuote;
|
|
56
|
+
} else {
|
|
57
|
+
stateBeforeQuote = state;
|
|
58
|
+
state = 1 /* Quoted */;
|
|
59
|
+
}
|
|
60
|
+
result += nextChar;
|
|
61
|
+
templatePos++;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
42
64
|
if (query.slice(templatePos, templatePos + BEGIN_REPEAT.length) === BEGIN_REPEAT) {
|
|
65
|
+
if (state === 2 /* Repeating */) {
|
|
66
|
+
throw new Error("Nested repetition is not allowed");
|
|
67
|
+
}
|
|
68
|
+
state = 2 /* Repeating */;
|
|
43
69
|
templatePos += BEGIN_REPEAT.length;
|
|
44
70
|
result += "(";
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (query.slice(templatePos, templatePos + END_REPEAT.length) === END_REPEAT) {
|
|
74
|
+
if (state === 0 /* Normal */) {
|
|
75
|
+
throw new Error("Unmatched repetition end");
|
|
76
|
+
}
|
|
77
|
+
state = 0 /* Normal */;
|
|
78
|
+
templatePos += END_REPEAT.length;
|
|
52
79
|
result += ")";
|
|
53
|
-
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (nextChar === "$") {
|
|
54
83
|
const paramMatch = query.slice(templatePos + 1).match(/^\d+/);
|
|
55
|
-
if (paramMatch) {
|
|
56
|
-
|
|
57
|
-
const paramValue = params[paramNum - 1];
|
|
58
|
-
if (!Array.isArray(paramValue)) {
|
|
59
|
-
result += "$" + lastParamId;
|
|
60
|
-
flattened.push(paramValue);
|
|
61
|
-
lastParamId++;
|
|
62
|
-
templatePos += paramMatch[0].length + 1;
|
|
63
|
-
}
|
|
64
|
-
} else {
|
|
65
|
-
result += query[templatePos];
|
|
84
|
+
if (!paramMatch) {
|
|
85
|
+
result += "$";
|
|
66
86
|
templatePos++;
|
|
87
|
+
continue;
|
|
67
88
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
89
|
+
templatePos += paramMatch[0].length + 1;
|
|
90
|
+
const originalParamIdx = parseInt(paramMatch[0]);
|
|
91
|
+
const paramValue = params[originalParamIdx - 1];
|
|
92
|
+
switch (state) {
|
|
93
|
+
case 0 /* Normal */: {
|
|
94
|
+
flattenedParams.push(paramValue);
|
|
95
|
+
result += `$${lastParamId++}`;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
case 2 /* Repeating */: {
|
|
99
|
+
const paramArray = Array.isArray(paramValue) ? paramValue : [paramValue];
|
|
100
|
+
if (paramArray.length === 0) {
|
|
101
|
+
result += "NULL";
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
paramArray.forEach((value, idx) => {
|
|
105
|
+
flattenedParams.push(value);
|
|
106
|
+
result += `$${lastParamId++}`;
|
|
107
|
+
if (idx !== paramArray.length - 1) {
|
|
108
|
+
result += ", ";
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
default: {
|
|
114
|
+
throw new Error(`Unexpected state: ${state}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
continue;
|
|
71
118
|
}
|
|
119
|
+
result += nextChar;
|
|
120
|
+
templatePos++;
|
|
72
121
|
}
|
|
73
122
|
return {
|
|
74
123
|
query: result,
|
|
75
|
-
params:
|
|
124
|
+
params: flattenedParams
|
|
76
125
|
};
|
|
77
126
|
}
|
|
78
127
|
|