@sqb/mssql 6.0.0 → 6.0.2
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/mssql-connection.d.ts +1 -0
- package/mssql-connection.js +26 -0
- package/package.json +5 -4
package/mssql-connection.d.ts
CHANGED
package/mssql-connection.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { tokenize } from 'fast-tokenizer';
|
|
1
2
|
import sql, {} from 'mssql';
|
|
2
3
|
import { MssqlCursor } from './mssql-cursor.js';
|
|
3
4
|
const typeNameMap = {
|
|
@@ -30,6 +31,7 @@ const typeNameMap = {
|
|
|
30
31
|
VarBinary: { dataType: 'VARBINARY', jsType: 'Buffer' },
|
|
31
32
|
Image: { dataType: 'IMAGE', jsType: 'Buffer' },
|
|
32
33
|
};
|
|
34
|
+
const NAMED_PARAM_PATTERN = / *:([a-zA-Z_]+)/;
|
|
33
35
|
export class MssqlConnection {
|
|
34
36
|
intlcon;
|
|
35
37
|
_transaction;
|
|
@@ -103,6 +105,8 @@ export class MssqlConnection {
|
|
|
103
105
|
if (!query.autoCommit && !this._transaction)
|
|
104
106
|
await this.startTransaction();
|
|
105
107
|
const out = {};
|
|
108
|
+
if (query.normalizeNamedParams)
|
|
109
|
+
this._normalizeNamedParams(query);
|
|
106
110
|
const m = query.sql.match(/\b(insert into|update|delete from)\b ("?\w+"?)/i);
|
|
107
111
|
if (m) {
|
|
108
112
|
const stmtType = m[1].toLowerCase();
|
|
@@ -189,6 +193,28 @@ export class MssqlConnection {
|
|
|
189
193
|
}
|
|
190
194
|
return result;
|
|
191
195
|
}
|
|
196
|
+
_normalizeNamedParams(query) {
|
|
197
|
+
const tokenizer = tokenize(query.sql, {
|
|
198
|
+
brackets: false,
|
|
199
|
+
delimiters: undefined,
|
|
200
|
+
quotes: true,
|
|
201
|
+
keepBrackets: true,
|
|
202
|
+
keepQuotes: true,
|
|
203
|
+
keepDelimiters: true,
|
|
204
|
+
emptyTokens: true,
|
|
205
|
+
});
|
|
206
|
+
let token;
|
|
207
|
+
let out = '';
|
|
208
|
+
let m;
|
|
209
|
+
while ((token = tokenizer.next())) {
|
|
210
|
+
m = NAMED_PARAM_PATTERN.exec(token);
|
|
211
|
+
if (m) {
|
|
212
|
+
token = '@' + m[1];
|
|
213
|
+
}
|
|
214
|
+
out += token;
|
|
215
|
+
}
|
|
216
|
+
query.sql = out;
|
|
217
|
+
}
|
|
192
218
|
}
|
|
193
219
|
function assertDefined(d) {
|
|
194
220
|
if (d == null)
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqb/mssql",
|
|
3
3
|
"description": "SQB adapter for the mssql (tedious) driver",
|
|
4
|
-
"version": "6.0.
|
|
4
|
+
"version": "6.0.2",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"dependencies": {
|
|
8
|
+
"fast-tokenizer": "^1.9.0",
|
|
8
9
|
"tslib": "^2.8.1"
|
|
9
10
|
},
|
|
10
11
|
"peerDependencies": {
|
|
11
|
-
"@sqb/builder": "^6.0.
|
|
12
|
-
"@sqb/connect": "^6.0.
|
|
13
|
-
"@sqb/mssql-dialect": "^6.0.
|
|
12
|
+
"@sqb/builder": "^6.0.2",
|
|
13
|
+
"@sqb/connect": "^6.0.2",
|
|
14
|
+
"@sqb/mssql-dialect": "^6.0.2",
|
|
14
15
|
"mssql": "^11.0.0 || ^12.0.0"
|
|
15
16
|
},
|
|
16
17
|
"type": "module",
|