@prisma/adapter-better-sqlite3 7.10.0-dev.8 → 7.10.0-integration-prisma7-project-closeout.6
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 +30 -9
- package/dist/index.mjs +30 -9
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -426,6 +426,9 @@ function mapArg(arg, argType, options) {
|
|
|
426
426
|
}
|
|
427
427
|
|
|
428
428
|
// src/errors.ts
|
|
429
|
+
var SQLITE_BUSY = 5;
|
|
430
|
+
var PRIMARY_ERROR_CODE_MASK = 255;
|
|
431
|
+
var UNKNOWN_ERROR_CODE_PREFIX = "UNKNOWN_SQLITE_ERROR_";
|
|
429
432
|
function convertDriverError(error) {
|
|
430
433
|
if (isDriverError(error)) {
|
|
431
434
|
return {
|
|
@@ -438,16 +441,15 @@ function convertDriverError(error) {
|
|
|
438
441
|
}
|
|
439
442
|
function mapDriverError(error) {
|
|
440
443
|
switch (error.code) {
|
|
441
|
-
case "SQLITE_BUSY":
|
|
442
|
-
return {
|
|
443
|
-
kind: "SocketTimeout"
|
|
444
|
-
};
|
|
445
444
|
case "SQLITE_CONSTRAINT_UNIQUE":
|
|
446
445
|
case "SQLITE_CONSTRAINT_PRIMARYKEY": {
|
|
447
|
-
const
|
|
446
|
+
const columns = error.message.split("constraint failed: ").at(1)?.split(", ");
|
|
447
|
+
const fields = columns?.map((field) => field.split(".").pop());
|
|
448
|
+
const table = columns?.at(0)?.split(".").slice(0, -1).join(".") || void 0;
|
|
448
449
|
return {
|
|
449
450
|
kind: "UniqueConstraintViolation",
|
|
450
|
-
constraint: fields !== void 0 ? { fields } : void 0
|
|
451
|
+
constraint: fields !== void 0 ? { fields } : void 0,
|
|
452
|
+
table
|
|
451
453
|
};
|
|
452
454
|
}
|
|
453
455
|
case "SQLITE_CONSTRAINT_NOTNULL": {
|
|
@@ -463,8 +465,13 @@ function mapDriverError(error) {
|
|
|
463
465
|
kind: "ForeignKeyConstraintViolation",
|
|
464
466
|
constraint: { foreignKey: {} }
|
|
465
467
|
};
|
|
466
|
-
default:
|
|
467
|
-
|
|
468
|
+
default: {
|
|
469
|
+
const extendedCode = extendedCodeFromName(error.code);
|
|
470
|
+
if (error.code.startsWith("SQLITE_BUSY") || extendedCode !== void 0 && (extendedCode & PRIMARY_ERROR_CODE_MASK) === SQLITE_BUSY) {
|
|
471
|
+
return {
|
|
472
|
+
kind: "SocketTimeout"
|
|
473
|
+
};
|
|
474
|
+
} else if (error.message.startsWith("no such table")) {
|
|
468
475
|
return {
|
|
469
476
|
kind: "TableDoesNotExist",
|
|
470
477
|
table: error.message.split(": ").at(1)
|
|
@@ -480,8 +487,22 @@ function mapDriverError(error) {
|
|
|
480
487
|
column: error.message.split("has no column named ").at(1)
|
|
481
488
|
};
|
|
482
489
|
}
|
|
483
|
-
|
|
490
|
+
return {
|
|
491
|
+
kind: "sqlite",
|
|
492
|
+
// Falling back to the generic code, like the d1 adapter does when the
|
|
493
|
+
// driver gives it none.
|
|
494
|
+
extendedCode: extendedCode ?? 1,
|
|
495
|
+
message: error.message
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
function extendedCodeFromName(code) {
|
|
501
|
+
if (!code.startsWith(UNKNOWN_ERROR_CODE_PREFIX)) {
|
|
502
|
+
return void 0;
|
|
484
503
|
}
|
|
504
|
+
const extendedCode = Number(code.slice(UNKNOWN_ERROR_CODE_PREFIX.length));
|
|
505
|
+
return Number.isInteger(extendedCode) ? extendedCode : void 0;
|
|
485
506
|
}
|
|
486
507
|
function isDriverError(error) {
|
|
487
508
|
return typeof error.code === "string" && typeof error.message === "string";
|
package/dist/index.mjs
CHANGED
|
@@ -390,6 +390,9 @@ function mapArg(arg, argType, options) {
|
|
|
390
390
|
}
|
|
391
391
|
|
|
392
392
|
// src/errors.ts
|
|
393
|
+
var SQLITE_BUSY = 5;
|
|
394
|
+
var PRIMARY_ERROR_CODE_MASK = 255;
|
|
395
|
+
var UNKNOWN_ERROR_CODE_PREFIX = "UNKNOWN_SQLITE_ERROR_";
|
|
393
396
|
function convertDriverError(error) {
|
|
394
397
|
if (isDriverError(error)) {
|
|
395
398
|
return {
|
|
@@ -402,16 +405,15 @@ function convertDriverError(error) {
|
|
|
402
405
|
}
|
|
403
406
|
function mapDriverError(error) {
|
|
404
407
|
switch (error.code) {
|
|
405
|
-
case "SQLITE_BUSY":
|
|
406
|
-
return {
|
|
407
|
-
kind: "SocketTimeout"
|
|
408
|
-
};
|
|
409
408
|
case "SQLITE_CONSTRAINT_UNIQUE":
|
|
410
409
|
case "SQLITE_CONSTRAINT_PRIMARYKEY": {
|
|
411
|
-
const
|
|
410
|
+
const columns = error.message.split("constraint failed: ").at(1)?.split(", ");
|
|
411
|
+
const fields = columns?.map((field) => field.split(".").pop());
|
|
412
|
+
const table = columns?.at(0)?.split(".").slice(0, -1).join(".") || void 0;
|
|
412
413
|
return {
|
|
413
414
|
kind: "UniqueConstraintViolation",
|
|
414
|
-
constraint: fields !== void 0 ? { fields } : void 0
|
|
415
|
+
constraint: fields !== void 0 ? { fields } : void 0,
|
|
416
|
+
table
|
|
415
417
|
};
|
|
416
418
|
}
|
|
417
419
|
case "SQLITE_CONSTRAINT_NOTNULL": {
|
|
@@ -427,8 +429,13 @@ function mapDriverError(error) {
|
|
|
427
429
|
kind: "ForeignKeyConstraintViolation",
|
|
428
430
|
constraint: { foreignKey: {} }
|
|
429
431
|
};
|
|
430
|
-
default:
|
|
431
|
-
|
|
432
|
+
default: {
|
|
433
|
+
const extendedCode = extendedCodeFromName(error.code);
|
|
434
|
+
if (error.code.startsWith("SQLITE_BUSY") || extendedCode !== void 0 && (extendedCode & PRIMARY_ERROR_CODE_MASK) === SQLITE_BUSY) {
|
|
435
|
+
return {
|
|
436
|
+
kind: "SocketTimeout"
|
|
437
|
+
};
|
|
438
|
+
} else if (error.message.startsWith("no such table")) {
|
|
432
439
|
return {
|
|
433
440
|
kind: "TableDoesNotExist",
|
|
434
441
|
table: error.message.split(": ").at(1)
|
|
@@ -444,8 +451,22 @@ function mapDriverError(error) {
|
|
|
444
451
|
column: error.message.split("has no column named ").at(1)
|
|
445
452
|
};
|
|
446
453
|
}
|
|
447
|
-
|
|
454
|
+
return {
|
|
455
|
+
kind: "sqlite",
|
|
456
|
+
// Falling back to the generic code, like the d1 adapter does when the
|
|
457
|
+
// driver gives it none.
|
|
458
|
+
extendedCode: extendedCode ?? 1,
|
|
459
|
+
message: error.message
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
function extendedCodeFromName(code) {
|
|
465
|
+
if (!code.startsWith(UNKNOWN_ERROR_CODE_PREFIX)) {
|
|
466
|
+
return void 0;
|
|
448
467
|
}
|
|
468
|
+
const extendedCode = Number(code.slice(UNKNOWN_ERROR_CODE_PREFIX.length));
|
|
469
|
+
return Number.isInteger(extendedCode) ? extendedCode : void 0;
|
|
449
470
|
}
|
|
450
471
|
function isDriverError(error) {
|
|
451
472
|
return typeof error.code === "string" && typeof error.message === "string";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/adapter-better-sqlite3",
|
|
3
|
-
"version": "7.10.0-
|
|
3
|
+
"version": "7.10.0-integration-prisma7-project-closeout.6",
|
|
4
4
|
"description": "Prisma's driver adapter for better-sqlite3, a fast SQLite3 driver for JavaScript runtimes",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"sideEffects": false,
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"better-sqlite3": "^12.6.0",
|
|
35
|
-
"@prisma/driver-adapter-utils": "7.10.0-
|
|
35
|
+
"@prisma/driver-adapter-utils": "7.10.0-integration-prisma7-project-closeout.6"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/better-sqlite3": "7.6.12",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"dev": "DEV=true tsx helpers/build.ts",
|
|
43
|
-
"build": "tsx helpers/build.ts"
|
|
43
|
+
"build": "tsx helpers/build.ts",
|
|
44
|
+
"test": "vitest run"
|
|
44
45
|
}
|
|
45
46
|
}
|