@prisma/adapter-mssql 6.14.0 → 6.15.0-dev.10
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.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +65 -8
- package/dist/index.mjs +69 -9
- package/package.json +4 -7
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -113,9 +113,12 @@ function mapIsolationLevel(level) {
|
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
|
-
function mapArg(arg) {
|
|
117
|
-
if (arg
|
|
118
|
-
return
|
|
116
|
+
function mapArg(arg, argType) {
|
|
117
|
+
if (arg === null) {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
if (typeof arg === "string" && argType.scalarType === "bigint") {
|
|
121
|
+
arg = BigInt(arg);
|
|
119
122
|
}
|
|
120
123
|
if (typeof arg === "bigint") {
|
|
121
124
|
if (arg >= BigInt(Number.MIN_SAFE_INTEGER) && arg <= BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
@@ -123,28 +126,74 @@ function mapArg(arg) {
|
|
|
123
126
|
}
|
|
124
127
|
return arg.toString();
|
|
125
128
|
}
|
|
129
|
+
if (typeof arg === "string" && argType.scalarType === "datetime") {
|
|
130
|
+
arg = new Date(arg);
|
|
131
|
+
}
|
|
132
|
+
if (arg instanceof Date) {
|
|
133
|
+
switch (argType.dbType) {
|
|
134
|
+
case "TIME":
|
|
135
|
+
return formatTime(arg);
|
|
136
|
+
case "DATE":
|
|
137
|
+
return formatDate(arg);
|
|
138
|
+
default:
|
|
139
|
+
return formatDateTime(arg);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (typeof arg === "string" && argType.scalarType === "bytes") {
|
|
143
|
+
return Buffer.from(arg, "base64");
|
|
144
|
+
}
|
|
145
|
+
if (Array.isArray(arg) && argType.scalarType === "bytes") {
|
|
146
|
+
return Buffer.from(arg);
|
|
147
|
+
}
|
|
148
|
+
if (ArrayBuffer.isView(arg)) {
|
|
149
|
+
return Buffer.from(arg.buffer, arg.byteOffset, arg.byteLength);
|
|
150
|
+
}
|
|
126
151
|
return arg;
|
|
127
152
|
}
|
|
128
153
|
function mapRow(row, columns) {
|
|
129
154
|
return row.map((value, i) => {
|
|
155
|
+
const type = columns?.[i]?.type;
|
|
130
156
|
if (value instanceof Date) {
|
|
131
|
-
if (
|
|
132
|
-
return value.toISOString().split("T").
|
|
157
|
+
if (type === import_mssql.default.Time) {
|
|
158
|
+
return value.toISOString().split("T")[1].replace("Z", "");
|
|
133
159
|
}
|
|
134
160
|
return value.toISOString();
|
|
135
161
|
}
|
|
162
|
+
if (typeof value === "number" && type === import_mssql.default.Real) {
|
|
163
|
+
for (let digits = 7; digits <= 9; digits++) {
|
|
164
|
+
const parsed = Number.parseFloat(value.toPrecision(digits));
|
|
165
|
+
if (value === new Float32Array([parsed])[0]) {
|
|
166
|
+
return parsed;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return value;
|
|
170
|
+
}
|
|
136
171
|
if (Buffer.isBuffer(value)) {
|
|
137
172
|
return Array.from(value);
|
|
138
173
|
}
|
|
139
|
-
if (typeof value === "string" &&
|
|
174
|
+
if (typeof value === "string" && type === import_mssql.default.UniqueIdentifier) {
|
|
140
175
|
return value.toLowerCase();
|
|
141
176
|
}
|
|
142
|
-
if (typeof value === "boolean" &&
|
|
177
|
+
if (typeof value === "boolean" && type === import_mssql.default.Bit) {
|
|
143
178
|
return value ? 1 : 0;
|
|
144
179
|
}
|
|
145
180
|
return value;
|
|
146
181
|
});
|
|
147
182
|
}
|
|
183
|
+
function formatDateTime(date) {
|
|
184
|
+
const pad = (n, z = 2) => String(n).padStart(z, "0");
|
|
185
|
+
const ms = date.getUTCMilliseconds();
|
|
186
|
+
return date.getUTCFullYear() + "-" + pad(date.getUTCMonth() + 1) + "-" + pad(date.getUTCDate()) + " " + pad(date.getUTCHours()) + ":" + pad(date.getUTCMinutes()) + ":" + pad(date.getUTCSeconds()) + (ms ? "." + String(ms).padStart(3, "0") : "");
|
|
187
|
+
}
|
|
188
|
+
function formatDate(date) {
|
|
189
|
+
const pad = (n, z = 2) => String(n).padStart(z, "0");
|
|
190
|
+
return date.getUTCFullYear() + "-" + pad(date.getUTCMonth() + 1) + "-" + pad(date.getUTCDate());
|
|
191
|
+
}
|
|
192
|
+
function formatTime(date) {
|
|
193
|
+
const pad = (n, z = 2) => String(n).padStart(z, "0");
|
|
194
|
+
const ms = date.getUTCMilliseconds();
|
|
195
|
+
return pad(date.getUTCHours()) + ":" + pad(date.getUTCMinutes()) + ":" + pad(date.getUTCSeconds()) + (ms ? "." + String(ms).padStart(3, "0") : "");
|
|
196
|
+
}
|
|
148
197
|
|
|
149
198
|
// src/errors.ts
|
|
150
199
|
function convertDriverError(error) {
|
|
@@ -359,7 +408,7 @@ var MssqlQueryable = class {
|
|
|
359
408
|
const req = this.conn.request();
|
|
360
409
|
req.arrayRowMode = true;
|
|
361
410
|
for (let i = 0; i < query.args.length; i++) {
|
|
362
|
-
req.input(`P${i + 1}`, mapArg(query.args[i]));
|
|
411
|
+
req.input(`P${i + 1}`, mapArg(query.args[i], query.argTypes[i]));
|
|
363
412
|
}
|
|
364
413
|
const res = await req.query(query.sql);
|
|
365
414
|
return res;
|
|
@@ -420,6 +469,10 @@ var PrismaMssqlAdapter = class extends MssqlQueryable {
|
|
|
420
469
|
const tag = "[js::startTransaction]";
|
|
421
470
|
debug("%s options: %O", tag, options);
|
|
422
471
|
const tx = this.pool.transaction();
|
|
472
|
+
tx.on("error", (err) => {
|
|
473
|
+
debug("Error from pool connection: %O", err);
|
|
474
|
+
this.options?.onConnectionError?.(err);
|
|
475
|
+
});
|
|
423
476
|
try {
|
|
424
477
|
await tx.begin(isolationLevel !== void 0 ? mapIsolationLevel(isolationLevel) : void 0);
|
|
425
478
|
return new MssqlTransaction(tx, options);
|
|
@@ -450,6 +503,10 @@ var PrismaMssqlAdapterFactory = class {
|
|
|
450
503
|
adapterName = name;
|
|
451
504
|
async connect() {
|
|
452
505
|
const pool = new import_mssql2.default.ConnectionPool(this.config);
|
|
506
|
+
pool.on("error", (err) => {
|
|
507
|
+
debug("Error from pool client: %O", err);
|
|
508
|
+
this.options?.onPoolError?.(err);
|
|
509
|
+
});
|
|
453
510
|
await pool.connect();
|
|
454
511
|
return new PrismaMssqlAdapter(pool, this.options);
|
|
455
512
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -10,7 +10,10 @@ import sql2 from "mssql";
|
|
|
10
10
|
var name = "@prisma/adapter-mssql";
|
|
11
11
|
|
|
12
12
|
// src/conversion.ts
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
ColumnTypeEnum,
|
|
15
|
+
DriverAdapterError
|
|
16
|
+
} from "@prisma/driver-adapter-utils";
|
|
14
17
|
import sql from "mssql";
|
|
15
18
|
function mapColumnType(col) {
|
|
16
19
|
switch (col.type) {
|
|
@@ -80,9 +83,12 @@ function mapIsolationLevel(level) {
|
|
|
80
83
|
});
|
|
81
84
|
}
|
|
82
85
|
}
|
|
83
|
-
function mapArg(arg) {
|
|
84
|
-
if (arg
|
|
85
|
-
return
|
|
86
|
+
function mapArg(arg, argType) {
|
|
87
|
+
if (arg === null) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
if (typeof arg === "string" && argType.scalarType === "bigint") {
|
|
91
|
+
arg = BigInt(arg);
|
|
86
92
|
}
|
|
87
93
|
if (typeof arg === "bigint") {
|
|
88
94
|
if (arg >= BigInt(Number.MIN_SAFE_INTEGER) && arg <= BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
@@ -90,28 +96,74 @@ function mapArg(arg) {
|
|
|
90
96
|
}
|
|
91
97
|
return arg.toString();
|
|
92
98
|
}
|
|
99
|
+
if (typeof arg === "string" && argType.scalarType === "datetime") {
|
|
100
|
+
arg = new Date(arg);
|
|
101
|
+
}
|
|
102
|
+
if (arg instanceof Date) {
|
|
103
|
+
switch (argType.dbType) {
|
|
104
|
+
case "TIME":
|
|
105
|
+
return formatTime(arg);
|
|
106
|
+
case "DATE":
|
|
107
|
+
return formatDate(arg);
|
|
108
|
+
default:
|
|
109
|
+
return formatDateTime(arg);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (typeof arg === "string" && argType.scalarType === "bytes") {
|
|
113
|
+
return Buffer.from(arg, "base64");
|
|
114
|
+
}
|
|
115
|
+
if (Array.isArray(arg) && argType.scalarType === "bytes") {
|
|
116
|
+
return Buffer.from(arg);
|
|
117
|
+
}
|
|
118
|
+
if (ArrayBuffer.isView(arg)) {
|
|
119
|
+
return Buffer.from(arg.buffer, arg.byteOffset, arg.byteLength);
|
|
120
|
+
}
|
|
93
121
|
return arg;
|
|
94
122
|
}
|
|
95
123
|
function mapRow(row, columns) {
|
|
96
124
|
return row.map((value, i) => {
|
|
125
|
+
const type = columns?.[i]?.type;
|
|
97
126
|
if (value instanceof Date) {
|
|
98
|
-
if (
|
|
99
|
-
return value.toISOString().split("T").
|
|
127
|
+
if (type === sql.Time) {
|
|
128
|
+
return value.toISOString().split("T")[1].replace("Z", "");
|
|
100
129
|
}
|
|
101
130
|
return value.toISOString();
|
|
102
131
|
}
|
|
132
|
+
if (typeof value === "number" && type === sql.Real) {
|
|
133
|
+
for (let digits = 7; digits <= 9; digits++) {
|
|
134
|
+
const parsed = Number.parseFloat(value.toPrecision(digits));
|
|
135
|
+
if (value === new Float32Array([parsed])[0]) {
|
|
136
|
+
return parsed;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return value;
|
|
140
|
+
}
|
|
103
141
|
if (Buffer.isBuffer(value)) {
|
|
104
142
|
return Array.from(value);
|
|
105
143
|
}
|
|
106
|
-
if (typeof value === "string" &&
|
|
144
|
+
if (typeof value === "string" && type === sql.UniqueIdentifier) {
|
|
107
145
|
return value.toLowerCase();
|
|
108
146
|
}
|
|
109
|
-
if (typeof value === "boolean" &&
|
|
147
|
+
if (typeof value === "boolean" && type === sql.Bit) {
|
|
110
148
|
return value ? 1 : 0;
|
|
111
149
|
}
|
|
112
150
|
return value;
|
|
113
151
|
});
|
|
114
152
|
}
|
|
153
|
+
function formatDateTime(date) {
|
|
154
|
+
const pad = (n, z = 2) => String(n).padStart(z, "0");
|
|
155
|
+
const ms = date.getUTCMilliseconds();
|
|
156
|
+
return date.getUTCFullYear() + "-" + pad(date.getUTCMonth() + 1) + "-" + pad(date.getUTCDate()) + " " + pad(date.getUTCHours()) + ":" + pad(date.getUTCMinutes()) + ":" + pad(date.getUTCSeconds()) + (ms ? "." + String(ms).padStart(3, "0") : "");
|
|
157
|
+
}
|
|
158
|
+
function formatDate(date) {
|
|
159
|
+
const pad = (n, z = 2) => String(n).padStart(z, "0");
|
|
160
|
+
return date.getUTCFullYear() + "-" + pad(date.getUTCMonth() + 1) + "-" + pad(date.getUTCDate());
|
|
161
|
+
}
|
|
162
|
+
function formatTime(date) {
|
|
163
|
+
const pad = (n, z = 2) => String(n).padStart(z, "0");
|
|
164
|
+
const ms = date.getUTCMilliseconds();
|
|
165
|
+
return pad(date.getUTCHours()) + ":" + pad(date.getUTCMinutes()) + ":" + pad(date.getUTCSeconds()) + (ms ? "." + String(ms).padStart(3, "0") : "");
|
|
166
|
+
}
|
|
115
167
|
|
|
116
168
|
// src/errors.ts
|
|
117
169
|
function convertDriverError(error) {
|
|
@@ -326,7 +378,7 @@ var MssqlQueryable = class {
|
|
|
326
378
|
const req = this.conn.request();
|
|
327
379
|
req.arrayRowMode = true;
|
|
328
380
|
for (let i = 0; i < query.args.length; i++) {
|
|
329
|
-
req.input(`P${i + 1}`, mapArg(query.args[i]));
|
|
381
|
+
req.input(`P${i + 1}`, mapArg(query.args[i], query.argTypes[i]));
|
|
330
382
|
}
|
|
331
383
|
const res = await req.query(query.sql);
|
|
332
384
|
return res;
|
|
@@ -387,6 +439,10 @@ var PrismaMssqlAdapter = class extends MssqlQueryable {
|
|
|
387
439
|
const tag = "[js::startTransaction]";
|
|
388
440
|
debug("%s options: %O", tag, options);
|
|
389
441
|
const tx = this.pool.transaction();
|
|
442
|
+
tx.on("error", (err) => {
|
|
443
|
+
debug("Error from pool connection: %O", err);
|
|
444
|
+
this.options?.onConnectionError?.(err);
|
|
445
|
+
});
|
|
390
446
|
try {
|
|
391
447
|
await tx.begin(isolationLevel !== void 0 ? mapIsolationLevel(isolationLevel) : void 0);
|
|
392
448
|
return new MssqlTransaction(tx, options);
|
|
@@ -417,6 +473,10 @@ var PrismaMssqlAdapterFactory = class {
|
|
|
417
473
|
adapterName = name;
|
|
418
474
|
async connect() {
|
|
419
475
|
const pool = new sql2.ConnectionPool(this.config);
|
|
476
|
+
pool.on("error", (err) => {
|
|
477
|
+
debug("Error from pool client: %O", err);
|
|
478
|
+
this.options?.onPoolError?.(err);
|
|
479
|
+
});
|
|
420
480
|
await pool.connect();
|
|
421
481
|
return new PrismaMssqlAdapter(pool, this.options);
|
|
422
482
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/adapter-mssql",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.15.0-dev.10",
|
|
4
4
|
"description": "Prisma's driver adapter for \"mssql\"",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -33,18 +33,15 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"mssql": "^11.0.1",
|
|
35
35
|
"async-mutex": "0.5.0",
|
|
36
|
-
"@prisma/driver-adapter-utils": "6.
|
|
36
|
+
"@prisma/driver-adapter-utils": "6.15.0-dev.10"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/mssql": "9.1.7",
|
|
40
|
-
"
|
|
41
|
-
"@swc/jest": "0.2.37",
|
|
42
|
-
"jest": "29.7.0",
|
|
43
|
-
"jest-junit": "16.0.0"
|
|
40
|
+
"vitest": "3.0.9"
|
|
44
41
|
},
|
|
45
42
|
"scripts": {
|
|
46
43
|
"dev": "DEV=true tsx helpers/build.ts",
|
|
47
44
|
"build": "tsx helpers/build.ts",
|
|
48
|
-
"test": "
|
|
45
|
+
"test": "vitest run"
|
|
49
46
|
}
|
|
50
47
|
}
|