@prisma/adapter-mssql 6.15.0-dev.3 → 6.15.0-dev.5
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 +64 -7
- package/dist/index.mjs +64 -7
- 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 (
|
|
157
|
+
if (type === import_mssql.default.Time) {
|
|
132
158
|
return value.toISOString().split("T").at(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
|
@@ -80,9 +80,12 @@ function mapIsolationLevel(level) {
|
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
-
function mapArg(arg) {
|
|
84
|
-
if (arg
|
|
85
|
-
return
|
|
83
|
+
function mapArg(arg, argType) {
|
|
84
|
+
if (arg === null) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
if (typeof arg === "string" && argType.scalarType === "bigint") {
|
|
88
|
+
arg = BigInt(arg);
|
|
86
89
|
}
|
|
87
90
|
if (typeof arg === "bigint") {
|
|
88
91
|
if (arg >= BigInt(Number.MIN_SAFE_INTEGER) && arg <= BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
@@ -90,28 +93,74 @@ function mapArg(arg) {
|
|
|
90
93
|
}
|
|
91
94
|
return arg.toString();
|
|
92
95
|
}
|
|
96
|
+
if (typeof arg === "string" && argType.scalarType === "datetime") {
|
|
97
|
+
arg = new Date(arg);
|
|
98
|
+
}
|
|
99
|
+
if (arg instanceof Date) {
|
|
100
|
+
switch (argType.dbType) {
|
|
101
|
+
case "TIME":
|
|
102
|
+
return formatTime(arg);
|
|
103
|
+
case "DATE":
|
|
104
|
+
return formatDate(arg);
|
|
105
|
+
default:
|
|
106
|
+
return formatDateTime(arg);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (typeof arg === "string" && argType.scalarType === "bytes") {
|
|
110
|
+
return Buffer.from(arg, "base64");
|
|
111
|
+
}
|
|
112
|
+
if (Array.isArray(arg) && argType.scalarType === "bytes") {
|
|
113
|
+
return Buffer.from(arg);
|
|
114
|
+
}
|
|
115
|
+
if (ArrayBuffer.isView(arg)) {
|
|
116
|
+
return Buffer.from(arg.buffer, arg.byteOffset, arg.byteLength);
|
|
117
|
+
}
|
|
93
118
|
return arg;
|
|
94
119
|
}
|
|
95
120
|
function mapRow(row, columns) {
|
|
96
121
|
return row.map((value, i) => {
|
|
122
|
+
const type = columns?.[i]?.type;
|
|
97
123
|
if (value instanceof Date) {
|
|
98
|
-
if (
|
|
124
|
+
if (type === sql.Time) {
|
|
99
125
|
return value.toISOString().split("T").at(1)?.replace("Z", "");
|
|
100
126
|
}
|
|
101
127
|
return value.toISOString();
|
|
102
128
|
}
|
|
129
|
+
if (typeof value === "number" && type === sql.Real) {
|
|
130
|
+
for (let digits = 7; digits <= 9; digits++) {
|
|
131
|
+
const parsed = Number.parseFloat(value.toPrecision(digits));
|
|
132
|
+
if (value === new Float32Array([parsed])[0]) {
|
|
133
|
+
return parsed;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return value;
|
|
137
|
+
}
|
|
103
138
|
if (Buffer.isBuffer(value)) {
|
|
104
139
|
return Array.from(value);
|
|
105
140
|
}
|
|
106
|
-
if (typeof value === "string" &&
|
|
141
|
+
if (typeof value === "string" && type === sql.UniqueIdentifier) {
|
|
107
142
|
return value.toLowerCase();
|
|
108
143
|
}
|
|
109
|
-
if (typeof value === "boolean" &&
|
|
144
|
+
if (typeof value === "boolean" && type === sql.Bit) {
|
|
110
145
|
return value ? 1 : 0;
|
|
111
146
|
}
|
|
112
147
|
return value;
|
|
113
148
|
});
|
|
114
149
|
}
|
|
150
|
+
function formatDateTime(date) {
|
|
151
|
+
const pad = (n, z = 2) => String(n).padStart(z, "0");
|
|
152
|
+
const ms = date.getUTCMilliseconds();
|
|
153
|
+
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") : "");
|
|
154
|
+
}
|
|
155
|
+
function formatDate(date) {
|
|
156
|
+
const pad = (n, z = 2) => String(n).padStart(z, "0");
|
|
157
|
+
return date.getUTCFullYear() + "-" + pad(date.getUTCMonth() + 1) + "-" + pad(date.getUTCDate());
|
|
158
|
+
}
|
|
159
|
+
function formatTime(date) {
|
|
160
|
+
const pad = (n, z = 2) => String(n).padStart(z, "0");
|
|
161
|
+
const ms = date.getUTCMilliseconds();
|
|
162
|
+
return pad(date.getUTCHours()) + ":" + pad(date.getUTCMinutes()) + ":" + pad(date.getUTCSeconds()) + (ms ? "." + String(ms).padStart(3, "0") : "");
|
|
163
|
+
}
|
|
115
164
|
|
|
116
165
|
// src/errors.ts
|
|
117
166
|
function convertDriverError(error) {
|
|
@@ -326,7 +375,7 @@ var MssqlQueryable = class {
|
|
|
326
375
|
const req = this.conn.request();
|
|
327
376
|
req.arrayRowMode = true;
|
|
328
377
|
for (let i = 0; i < query.args.length; i++) {
|
|
329
|
-
req.input(`P${i + 1}`, mapArg(query.args[i]));
|
|
378
|
+
req.input(`P${i + 1}`, mapArg(query.args[i], query.argTypes[i]));
|
|
330
379
|
}
|
|
331
380
|
const res = await req.query(query.sql);
|
|
332
381
|
return res;
|
|
@@ -387,6 +436,10 @@ var PrismaMssqlAdapter = class extends MssqlQueryable {
|
|
|
387
436
|
const tag = "[js::startTransaction]";
|
|
388
437
|
debug("%s options: %O", tag, options);
|
|
389
438
|
const tx = this.pool.transaction();
|
|
439
|
+
tx.on("error", (err) => {
|
|
440
|
+
debug("Error from pool connection: %O", err);
|
|
441
|
+
this.options?.onConnectionError?.(err);
|
|
442
|
+
});
|
|
390
443
|
try {
|
|
391
444
|
await tx.begin(isolationLevel !== void 0 ? mapIsolationLevel(isolationLevel) : void 0);
|
|
392
445
|
return new MssqlTransaction(tx, options);
|
|
@@ -417,6 +470,10 @@ var PrismaMssqlAdapterFactory = class {
|
|
|
417
470
|
adapterName = name;
|
|
418
471
|
async connect() {
|
|
419
472
|
const pool = new sql2.ConnectionPool(this.config);
|
|
473
|
+
pool.on("error", (err) => {
|
|
474
|
+
debug("Error from pool client: %O", err);
|
|
475
|
+
this.options?.onPoolError?.(err);
|
|
476
|
+
});
|
|
420
477
|
await pool.connect();
|
|
421
478
|
return new PrismaMssqlAdapter(pool, this.options);
|
|
422
479
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/adapter-mssql",
|
|
3
|
-
"version": "6.15.0-dev.
|
|
3
|
+
"version": "6.15.0-dev.5",
|
|
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.15.0-dev.
|
|
36
|
+
"@prisma/driver-adapter-utils": "6.15.0-dev.5"
|
|
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
|
}
|