@prisma/adapter-better-sqlite3 7.10.1 → 7.11.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.js +34 -13
- package/dist/index.mjs +34 -13
- package/package.json +3 -4
package/dist/index.js
CHANGED
|
@@ -352,7 +352,7 @@ function inferColumnType(value) {
|
|
|
352
352
|
}
|
|
353
353
|
}
|
|
354
354
|
function inferObjectType(value) {
|
|
355
|
-
if (value instanceof ArrayBuffer) {
|
|
355
|
+
if (value instanceof ArrayBuffer || value instanceof Uint8Array) {
|
|
356
356
|
return import_driver_adapter_utils.ColumnTypeEnum.Bytes;
|
|
357
357
|
}
|
|
358
358
|
throw new UnexpectedTypeError(value);
|
|
@@ -517,6 +517,7 @@ var BetterSQLite3Queryable = class {
|
|
|
517
517
|
}
|
|
518
518
|
provider = "sqlite";
|
|
519
519
|
adapterName = name;
|
|
520
|
+
lock = new Mutex();
|
|
520
521
|
/**
|
|
521
522
|
* Execute a query given as SQL, interpolating the given parameters.
|
|
522
523
|
*/
|
|
@@ -547,14 +548,16 @@ var BetterSQLite3Queryable = class {
|
|
|
547
548
|
* Should the query fail due to a connection error, the connection is
|
|
548
549
|
* marked as unhealthy.
|
|
549
550
|
*/
|
|
550
|
-
executeIO(query) {
|
|
551
|
+
async executeIO(query) {
|
|
552
|
+
const release = await this.lock.acquire();
|
|
551
553
|
try {
|
|
552
554
|
const args = query.args.map((arg, i) => mapArg(arg, query.argTypes[i], this.adapterOptions));
|
|
553
555
|
const stmt = this.client.prepare(query.sql).bind(args);
|
|
554
|
-
|
|
555
|
-
return Promise.resolve(result);
|
|
556
|
+
return stmt.run();
|
|
556
557
|
} catch (e) {
|
|
557
558
|
this.onError(e);
|
|
559
|
+
} finally {
|
|
560
|
+
release();
|
|
558
561
|
}
|
|
559
562
|
}
|
|
560
563
|
/**
|
|
@@ -562,27 +565,29 @@ var BetterSQLite3Queryable = class {
|
|
|
562
565
|
* Should the query fail due to a connection error, the connection is
|
|
563
566
|
* marked as unhealthy.
|
|
564
567
|
*/
|
|
565
|
-
performIO(query) {
|
|
568
|
+
async performIO(query) {
|
|
569
|
+
const release = await this.lock.acquire();
|
|
566
570
|
try {
|
|
567
571
|
const args = query.args.map((arg, i) => mapArg(arg, query.argTypes[i], this.adapterOptions));
|
|
568
572
|
const stmt = this.client.prepare(query.sql).bind(args);
|
|
569
573
|
if (!stmt.reader) {
|
|
570
574
|
stmt.run();
|
|
571
|
-
return
|
|
575
|
+
return {
|
|
572
576
|
columnNames: [],
|
|
573
577
|
declaredTypes: [],
|
|
574
578
|
values: []
|
|
575
|
-
}
|
|
579
|
+
};
|
|
576
580
|
}
|
|
577
581
|
const columns = stmt.columns();
|
|
578
|
-
|
|
582
|
+
return {
|
|
579
583
|
declaredTypes: columns.map((column) => column.type),
|
|
580
584
|
columnNames: columns.map((column) => column.name),
|
|
581
585
|
values: stmt.raw().all()
|
|
582
586
|
};
|
|
583
|
-
return Promise.resolve(resultSet);
|
|
584
587
|
} catch (e) {
|
|
585
588
|
this.onError(e);
|
|
589
|
+
} finally {
|
|
590
|
+
release();
|
|
586
591
|
}
|
|
587
592
|
}
|
|
588
593
|
onError(error) {
|
|
@@ -618,17 +623,26 @@ var BetterSQLite3Transaction = class extends BetterSQLite3Queryable {
|
|
|
618
623
|
}
|
|
619
624
|
};
|
|
620
625
|
var PrismaBetterSqlite3Adapter = class extends BetterSQLite3Queryable {
|
|
621
|
-
#
|
|
626
|
+
#maxBindValues;
|
|
622
627
|
constructor(client, adapterOptions) {
|
|
623
628
|
super(client, adapterOptions);
|
|
629
|
+
this.#maxBindValues = readMaxBindValues(client);
|
|
630
|
+
}
|
|
631
|
+
getConnectionInfo() {
|
|
632
|
+
return {
|
|
633
|
+
maxBindValues: this.#maxBindValues,
|
|
634
|
+
supportsRelationJoins: false
|
|
635
|
+
};
|
|
624
636
|
}
|
|
625
|
-
executeScript(script) {
|
|
637
|
+
async executeScript(script) {
|
|
638
|
+
const release = await this.lock.acquire();
|
|
626
639
|
try {
|
|
627
640
|
this.client.exec(script);
|
|
628
641
|
} catch (e) {
|
|
629
642
|
this.onError(e);
|
|
643
|
+
} finally {
|
|
644
|
+
release();
|
|
630
645
|
}
|
|
631
|
-
return Promise.resolve();
|
|
632
646
|
}
|
|
633
647
|
async startTransaction(isolationLevel) {
|
|
634
648
|
if (isolationLevel && isolationLevel !== "SERIALIZABLE") {
|
|
@@ -642,11 +656,12 @@ var PrismaBetterSqlite3Adapter = class extends BetterSQLite3Queryable {
|
|
|
642
656
|
};
|
|
643
657
|
const tag = "[js::startTransaction]";
|
|
644
658
|
debug2("%s options: %O", tag, options);
|
|
659
|
+
const release = await this.lock.acquire();
|
|
645
660
|
try {
|
|
646
|
-
const release = await this.#mutex.acquire();
|
|
647
661
|
this.client.prepare("BEGIN").run();
|
|
648
662
|
return new BetterSQLite3Transaction(this.client, options, this.adapterOptions, release);
|
|
649
663
|
} catch (e) {
|
|
664
|
+
release();
|
|
650
665
|
this.onError(e);
|
|
651
666
|
}
|
|
652
667
|
}
|
|
@@ -674,6 +689,12 @@ var PrismaBetterSqlite3AdapterFactory = class {
|
|
|
674
689
|
);
|
|
675
690
|
}
|
|
676
691
|
};
|
|
692
|
+
function readMaxBindValues(client) {
|
|
693
|
+
const options = client.pragma("compile_options");
|
|
694
|
+
const option = options.find(({ compile_options }) => compile_options.startsWith("MAX_VARIABLE_NUMBER="));
|
|
695
|
+
const value = Number(option?.compile_options.slice("MAX_VARIABLE_NUMBER=".length));
|
|
696
|
+
return Number.isSafeInteger(value) && value > 0 ? value : void 0;
|
|
697
|
+
}
|
|
677
698
|
function createBetterSQLite3Client(input) {
|
|
678
699
|
const { url, ...config } = input;
|
|
679
700
|
const dbPath = url.replace(/^file:/, "");
|
package/dist/index.mjs
CHANGED
|
@@ -316,7 +316,7 @@ function inferColumnType(value) {
|
|
|
316
316
|
}
|
|
317
317
|
}
|
|
318
318
|
function inferObjectType(value) {
|
|
319
|
-
if (value instanceof ArrayBuffer) {
|
|
319
|
+
if (value instanceof ArrayBuffer || value instanceof Uint8Array) {
|
|
320
320
|
return ColumnTypeEnum.Bytes;
|
|
321
321
|
}
|
|
322
322
|
throw new UnexpectedTypeError(value);
|
|
@@ -481,6 +481,7 @@ var BetterSQLite3Queryable = class {
|
|
|
481
481
|
}
|
|
482
482
|
provider = "sqlite";
|
|
483
483
|
adapterName = name;
|
|
484
|
+
lock = new Mutex();
|
|
484
485
|
/**
|
|
485
486
|
* Execute a query given as SQL, interpolating the given parameters.
|
|
486
487
|
*/
|
|
@@ -511,14 +512,16 @@ var BetterSQLite3Queryable = class {
|
|
|
511
512
|
* Should the query fail due to a connection error, the connection is
|
|
512
513
|
* marked as unhealthy.
|
|
513
514
|
*/
|
|
514
|
-
executeIO(query) {
|
|
515
|
+
async executeIO(query) {
|
|
516
|
+
const release = await this.lock.acquire();
|
|
515
517
|
try {
|
|
516
518
|
const args = query.args.map((arg, i) => mapArg(arg, query.argTypes[i], this.adapterOptions));
|
|
517
519
|
const stmt = this.client.prepare(query.sql).bind(args);
|
|
518
|
-
|
|
519
|
-
return Promise.resolve(result);
|
|
520
|
+
return stmt.run();
|
|
520
521
|
} catch (e) {
|
|
521
522
|
this.onError(e);
|
|
523
|
+
} finally {
|
|
524
|
+
release();
|
|
522
525
|
}
|
|
523
526
|
}
|
|
524
527
|
/**
|
|
@@ -526,27 +529,29 @@ var BetterSQLite3Queryable = class {
|
|
|
526
529
|
* Should the query fail due to a connection error, the connection is
|
|
527
530
|
* marked as unhealthy.
|
|
528
531
|
*/
|
|
529
|
-
performIO(query) {
|
|
532
|
+
async performIO(query) {
|
|
533
|
+
const release = await this.lock.acquire();
|
|
530
534
|
try {
|
|
531
535
|
const args = query.args.map((arg, i) => mapArg(arg, query.argTypes[i], this.adapterOptions));
|
|
532
536
|
const stmt = this.client.prepare(query.sql).bind(args);
|
|
533
537
|
if (!stmt.reader) {
|
|
534
538
|
stmt.run();
|
|
535
|
-
return
|
|
539
|
+
return {
|
|
536
540
|
columnNames: [],
|
|
537
541
|
declaredTypes: [],
|
|
538
542
|
values: []
|
|
539
|
-
}
|
|
543
|
+
};
|
|
540
544
|
}
|
|
541
545
|
const columns = stmt.columns();
|
|
542
|
-
|
|
546
|
+
return {
|
|
543
547
|
declaredTypes: columns.map((column) => column.type),
|
|
544
548
|
columnNames: columns.map((column) => column.name),
|
|
545
549
|
values: stmt.raw().all()
|
|
546
550
|
};
|
|
547
|
-
return Promise.resolve(resultSet);
|
|
548
551
|
} catch (e) {
|
|
549
552
|
this.onError(e);
|
|
553
|
+
} finally {
|
|
554
|
+
release();
|
|
550
555
|
}
|
|
551
556
|
}
|
|
552
557
|
onError(error) {
|
|
@@ -582,17 +587,26 @@ var BetterSQLite3Transaction = class extends BetterSQLite3Queryable {
|
|
|
582
587
|
}
|
|
583
588
|
};
|
|
584
589
|
var PrismaBetterSqlite3Adapter = class extends BetterSQLite3Queryable {
|
|
585
|
-
#
|
|
590
|
+
#maxBindValues;
|
|
586
591
|
constructor(client, adapterOptions) {
|
|
587
592
|
super(client, adapterOptions);
|
|
593
|
+
this.#maxBindValues = readMaxBindValues(client);
|
|
594
|
+
}
|
|
595
|
+
getConnectionInfo() {
|
|
596
|
+
return {
|
|
597
|
+
maxBindValues: this.#maxBindValues,
|
|
598
|
+
supportsRelationJoins: false
|
|
599
|
+
};
|
|
588
600
|
}
|
|
589
|
-
executeScript(script) {
|
|
601
|
+
async executeScript(script) {
|
|
602
|
+
const release = await this.lock.acquire();
|
|
590
603
|
try {
|
|
591
604
|
this.client.exec(script);
|
|
592
605
|
} catch (e) {
|
|
593
606
|
this.onError(e);
|
|
607
|
+
} finally {
|
|
608
|
+
release();
|
|
594
609
|
}
|
|
595
|
-
return Promise.resolve();
|
|
596
610
|
}
|
|
597
611
|
async startTransaction(isolationLevel) {
|
|
598
612
|
if (isolationLevel && isolationLevel !== "SERIALIZABLE") {
|
|
@@ -606,11 +620,12 @@ var PrismaBetterSqlite3Adapter = class extends BetterSQLite3Queryable {
|
|
|
606
620
|
};
|
|
607
621
|
const tag = "[js::startTransaction]";
|
|
608
622
|
debug2("%s options: %O", tag, options);
|
|
623
|
+
const release = await this.lock.acquire();
|
|
609
624
|
try {
|
|
610
|
-
const release = await this.#mutex.acquire();
|
|
611
625
|
this.client.prepare("BEGIN").run();
|
|
612
626
|
return new BetterSQLite3Transaction(this.client, options, this.adapterOptions, release);
|
|
613
627
|
} catch (e) {
|
|
628
|
+
release();
|
|
614
629
|
this.onError(e);
|
|
615
630
|
}
|
|
616
631
|
}
|
|
@@ -638,6 +653,12 @@ var PrismaBetterSqlite3AdapterFactory = class {
|
|
|
638
653
|
);
|
|
639
654
|
}
|
|
640
655
|
};
|
|
656
|
+
function readMaxBindValues(client) {
|
|
657
|
+
const options = client.pragma("compile_options");
|
|
658
|
+
const option = options.find(({ compile_options }) => compile_options.startsWith("MAX_VARIABLE_NUMBER="));
|
|
659
|
+
const value = Number(option?.compile_options.slice("MAX_VARIABLE_NUMBER=".length));
|
|
660
|
+
return Number.isSafeInteger(value) && value > 0 ? value : void 0;
|
|
661
|
+
}
|
|
641
662
|
function createBetterSQLite3Client(input) {
|
|
642
663
|
const { url, ...config } = input;
|
|
643
664
|
const dbPath = url.replace(/^file:/, "");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/adapter-better-sqlite3",
|
|
3
|
-
"version": "7.10
|
|
3
|
+
"version": "7.11.0-dev.10",
|
|
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
|
|
35
|
+
"@prisma/driver-adapter-utils": "7.11.0-dev.10"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/better-sqlite3": "7.6.12",
|
|
@@ -40,7 +40,6 @@
|
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"dev": "DEV=true tsx helpers/build.ts",
|
|
43
|
-
"build": "tsx helpers/build.ts"
|
|
44
|
-
"test": "vitest run"
|
|
43
|
+
"build": "tsx helpers/build.ts"
|
|
45
44
|
}
|
|
46
45
|
}
|