@prisma/adapter-better-sqlite3 6.16.0-dev.3 → 6.16.0-dev.30
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 +7 -3
- package/dist/index.d.ts +7 -3
- package/dist/index.js +34 -19
- package/dist/index.mjs +34 -19
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -4,16 +4,20 @@ import type { SqlMigrationAwareDriverAdapterFactory } from '@prisma/driver-adapt
|
|
|
4
4
|
|
|
5
5
|
declare type BetterSQLite3InputParams = Options & {
|
|
6
6
|
url: ':memory:' | (string & {});
|
|
7
|
-
shadowDatabaseURL?: ':memory:' | (string & {});
|
|
8
7
|
};
|
|
9
8
|
|
|
10
9
|
export declare class PrismaBetterSQLite3 implements SqlMigrationAwareDriverAdapterFactory {
|
|
11
|
-
private
|
|
10
|
+
#private;
|
|
12
11
|
readonly provider = "sqlite";
|
|
13
12
|
readonly adapterName: string;
|
|
14
|
-
constructor(config: BetterSQLite3InputParams);
|
|
13
|
+
constructor(config: BetterSQLite3InputParams, options?: PrismaBetterSQLite3Options);
|
|
15
14
|
connect(): Promise<SqlDriverAdapter>;
|
|
16
15
|
connectToShadowDb(): Promise<SqlDriverAdapter>;
|
|
17
16
|
}
|
|
18
17
|
|
|
18
|
+
declare type PrismaBetterSQLite3Options = {
|
|
19
|
+
shadowDatabaseUrl?: string;
|
|
20
|
+
timestampFormat?: 'iso8601' | 'unixepoch-ms';
|
|
21
|
+
};
|
|
22
|
+
|
|
19
23
|
export { }
|
package/dist/index.d.ts
CHANGED
|
@@ -4,16 +4,20 @@ import type { SqlMigrationAwareDriverAdapterFactory } from '@prisma/driver-adapt
|
|
|
4
4
|
|
|
5
5
|
declare type BetterSQLite3InputParams = Options & {
|
|
6
6
|
url: ':memory:' | (string & {});
|
|
7
|
-
shadowDatabaseURL?: ':memory:' | (string & {});
|
|
8
7
|
};
|
|
9
8
|
|
|
10
9
|
export declare class PrismaBetterSQLite3 implements SqlMigrationAwareDriverAdapterFactory {
|
|
11
|
-
private
|
|
10
|
+
#private;
|
|
12
11
|
readonly provider = "sqlite";
|
|
13
12
|
readonly adapterName: string;
|
|
14
|
-
constructor(config: BetterSQLite3InputParams);
|
|
13
|
+
constructor(config: BetterSQLite3InputParams, options?: PrismaBetterSQLite3Options);
|
|
15
14
|
connect(): Promise<SqlDriverAdapter>;
|
|
16
15
|
connectToShadowDb(): Promise<SqlDriverAdapter>;
|
|
17
16
|
}
|
|
18
17
|
|
|
18
|
+
declare type PrismaBetterSQLite3Options = {
|
|
19
|
+
shadowDatabaseUrl?: string;
|
|
20
|
+
timestampFormat?: 'iso8601' | 'unixepoch-ms';
|
|
21
|
+
};
|
|
22
|
+
|
|
19
23
|
export { }
|
package/dist/index.js
CHANGED
|
@@ -389,7 +389,7 @@ function mapRow(row, columnTypes) {
|
|
|
389
389
|
}
|
|
390
390
|
return result;
|
|
391
391
|
}
|
|
392
|
-
function mapArg(arg, argType) {
|
|
392
|
+
function mapArg(arg, argType, options) {
|
|
393
393
|
if (arg === null) {
|
|
394
394
|
return null;
|
|
395
395
|
}
|
|
@@ -412,7 +412,15 @@ function mapArg(arg, argType) {
|
|
|
412
412
|
arg = new Date(arg);
|
|
413
413
|
}
|
|
414
414
|
if (arg instanceof Date) {
|
|
415
|
-
|
|
415
|
+
const format = options?.timestampFormat ?? "iso8601";
|
|
416
|
+
switch (format) {
|
|
417
|
+
case "unixepoch-ms":
|
|
418
|
+
return arg.getTime();
|
|
419
|
+
case "iso8601":
|
|
420
|
+
return arg.toISOString().replace("Z", "+00:00");
|
|
421
|
+
default:
|
|
422
|
+
throw new Error(`Unknown timestamp format: ${format}`);
|
|
423
|
+
}
|
|
416
424
|
}
|
|
417
425
|
if (typeof arg === "string" && argType.scalarType === "bytes") {
|
|
418
426
|
return Buffer.from(arg, "base64");
|
|
@@ -488,8 +496,9 @@ function isDriverError(error) {
|
|
|
488
496
|
// src/better-sqlite3.ts
|
|
489
497
|
var debug2 = (0, import_driver_adapter_utils2.Debug)("prisma:driver-adapter:better-sqlite3");
|
|
490
498
|
var BetterSQLite3Queryable = class {
|
|
491
|
-
constructor(client) {
|
|
499
|
+
constructor(client, adapterOptions) {
|
|
492
500
|
this.client = client;
|
|
501
|
+
this.adapterOptions = adapterOptions;
|
|
493
502
|
}
|
|
494
503
|
provider = "sqlite";
|
|
495
504
|
adapterName = name;
|
|
@@ -525,7 +534,7 @@ var BetterSQLite3Queryable = class {
|
|
|
525
534
|
*/
|
|
526
535
|
executeIO(query) {
|
|
527
536
|
try {
|
|
528
|
-
const args = query.args.map((arg, i) => mapArg(arg, query.argTypes[i]));
|
|
537
|
+
const args = query.args.map((arg, i) => mapArg(arg, query.argTypes[i], this.adapterOptions));
|
|
529
538
|
const stmt = this.client.prepare(query.sql).bind(args);
|
|
530
539
|
const result = stmt.run();
|
|
531
540
|
return Promise.resolve(result);
|
|
@@ -540,7 +549,7 @@ var BetterSQLite3Queryable = class {
|
|
|
540
549
|
*/
|
|
541
550
|
performIO(query) {
|
|
542
551
|
try {
|
|
543
|
-
const args = query.args.map((arg, i) => mapArg(arg, query.argTypes[i]));
|
|
552
|
+
const args = query.args.map((arg, i) => mapArg(arg, query.argTypes[i], this.adapterOptions));
|
|
544
553
|
const stmt = this.client.prepare(query.sql).bind(args);
|
|
545
554
|
if (!stmt.reader) {
|
|
546
555
|
stmt.run();
|
|
@@ -567,26 +576,27 @@ var BetterSQLite3Queryable = class {
|
|
|
567
576
|
}
|
|
568
577
|
};
|
|
569
578
|
var BetterSQLite3Transaction = class extends BetterSQLite3Queryable {
|
|
570
|
-
constructor(client, options, unlockParent) {
|
|
571
|
-
super(client);
|
|
579
|
+
constructor(client, options, adapterOptions, unlockParent) {
|
|
580
|
+
super(client, adapterOptions);
|
|
572
581
|
this.options = options;
|
|
573
|
-
this
|
|
582
|
+
this.#unlockParent = unlockParent;
|
|
574
583
|
}
|
|
584
|
+
#unlockParent;
|
|
575
585
|
commit() {
|
|
576
586
|
debug2(`[js::commit]`);
|
|
577
|
-
this
|
|
587
|
+
this.#unlockParent();
|
|
578
588
|
return Promise.resolve();
|
|
579
589
|
}
|
|
580
590
|
rollback() {
|
|
581
591
|
debug2(`[js::rollback]`);
|
|
582
|
-
this
|
|
592
|
+
this.#unlockParent();
|
|
583
593
|
return Promise.resolve();
|
|
584
594
|
}
|
|
585
595
|
};
|
|
586
596
|
var PrismaBetterSQLite3Adapter = class extends BetterSQLite3Queryable {
|
|
587
597
|
#mutex = new Mutex();
|
|
588
|
-
constructor(client) {
|
|
589
|
-
super(client);
|
|
598
|
+
constructor(client, adapterOptions) {
|
|
599
|
+
super(client, adapterOptions);
|
|
590
600
|
}
|
|
591
601
|
executeScript(script) {
|
|
592
602
|
try {
|
|
@@ -611,7 +621,7 @@ var PrismaBetterSQLite3Adapter = class extends BetterSQLite3Queryable {
|
|
|
611
621
|
try {
|
|
612
622
|
const release = await this.#mutex.acquire();
|
|
613
623
|
this.client.prepare("BEGIN").run();
|
|
614
|
-
return new BetterSQLite3Transaction(this.client, options, release);
|
|
624
|
+
return new BetterSQLite3Transaction(this.client, options, this.adapterOptions, release);
|
|
615
625
|
} catch (e) {
|
|
616
626
|
this.onError(e);
|
|
617
627
|
}
|
|
@@ -622,17 +632,22 @@ var PrismaBetterSQLite3Adapter = class extends BetterSQLite3Queryable {
|
|
|
622
632
|
}
|
|
623
633
|
};
|
|
624
634
|
var PrismaBetterSQLite3AdapterFactory = class {
|
|
625
|
-
constructor(config) {
|
|
626
|
-
this.config = config;
|
|
627
|
-
}
|
|
628
635
|
provider = "sqlite";
|
|
629
636
|
adapterName = name;
|
|
637
|
+
#config;
|
|
638
|
+
#options;
|
|
639
|
+
constructor(config, options) {
|
|
640
|
+
this.#config = config;
|
|
641
|
+
this.#options = options;
|
|
642
|
+
}
|
|
630
643
|
connect() {
|
|
631
|
-
return Promise.resolve(new PrismaBetterSQLite3Adapter(createBetterSQLite3Client(this
|
|
644
|
+
return Promise.resolve(new PrismaBetterSQLite3Adapter(createBetterSQLite3Client(this.#config), this.#options));
|
|
632
645
|
}
|
|
633
646
|
connectToShadowDb() {
|
|
634
|
-
const url = this
|
|
635
|
-
return Promise.resolve(
|
|
647
|
+
const url = this.#options?.shadowDatabaseUrl ?? ":memory:";
|
|
648
|
+
return Promise.resolve(
|
|
649
|
+
new PrismaBetterSQLite3Adapter(createBetterSQLite3Client({ ...this.#config, url }), this.#options)
|
|
650
|
+
);
|
|
636
651
|
}
|
|
637
652
|
};
|
|
638
653
|
function createBetterSQLite3Client(input) {
|
package/dist/index.mjs
CHANGED
|
@@ -353,7 +353,7 @@ function mapRow(row, columnTypes) {
|
|
|
353
353
|
}
|
|
354
354
|
return result;
|
|
355
355
|
}
|
|
356
|
-
function mapArg(arg, argType) {
|
|
356
|
+
function mapArg(arg, argType, options) {
|
|
357
357
|
if (arg === null) {
|
|
358
358
|
return null;
|
|
359
359
|
}
|
|
@@ -376,7 +376,15 @@ function mapArg(arg, argType) {
|
|
|
376
376
|
arg = new Date(arg);
|
|
377
377
|
}
|
|
378
378
|
if (arg instanceof Date) {
|
|
379
|
-
|
|
379
|
+
const format = options?.timestampFormat ?? "iso8601";
|
|
380
|
+
switch (format) {
|
|
381
|
+
case "unixepoch-ms":
|
|
382
|
+
return arg.getTime();
|
|
383
|
+
case "iso8601":
|
|
384
|
+
return arg.toISOString().replace("Z", "+00:00");
|
|
385
|
+
default:
|
|
386
|
+
throw new Error(`Unknown timestamp format: ${format}`);
|
|
387
|
+
}
|
|
380
388
|
}
|
|
381
389
|
if (typeof arg === "string" && argType.scalarType === "bytes") {
|
|
382
390
|
return Buffer.from(arg, "base64");
|
|
@@ -452,8 +460,9 @@ function isDriverError(error) {
|
|
|
452
460
|
// src/better-sqlite3.ts
|
|
453
461
|
var debug2 = Debug2("prisma:driver-adapter:better-sqlite3");
|
|
454
462
|
var BetterSQLite3Queryable = class {
|
|
455
|
-
constructor(client) {
|
|
463
|
+
constructor(client, adapterOptions) {
|
|
456
464
|
this.client = client;
|
|
465
|
+
this.adapterOptions = adapterOptions;
|
|
457
466
|
}
|
|
458
467
|
provider = "sqlite";
|
|
459
468
|
adapterName = name;
|
|
@@ -489,7 +498,7 @@ var BetterSQLite3Queryable = class {
|
|
|
489
498
|
*/
|
|
490
499
|
executeIO(query) {
|
|
491
500
|
try {
|
|
492
|
-
const args = query.args.map((arg, i) => mapArg(arg, query.argTypes[i]));
|
|
501
|
+
const args = query.args.map((arg, i) => mapArg(arg, query.argTypes[i], this.adapterOptions));
|
|
493
502
|
const stmt = this.client.prepare(query.sql).bind(args);
|
|
494
503
|
const result = stmt.run();
|
|
495
504
|
return Promise.resolve(result);
|
|
@@ -504,7 +513,7 @@ var BetterSQLite3Queryable = class {
|
|
|
504
513
|
*/
|
|
505
514
|
performIO(query) {
|
|
506
515
|
try {
|
|
507
|
-
const args = query.args.map((arg, i) => mapArg(arg, query.argTypes[i]));
|
|
516
|
+
const args = query.args.map((arg, i) => mapArg(arg, query.argTypes[i], this.adapterOptions));
|
|
508
517
|
const stmt = this.client.prepare(query.sql).bind(args);
|
|
509
518
|
if (!stmt.reader) {
|
|
510
519
|
stmt.run();
|
|
@@ -531,26 +540,27 @@ var BetterSQLite3Queryable = class {
|
|
|
531
540
|
}
|
|
532
541
|
};
|
|
533
542
|
var BetterSQLite3Transaction = class extends BetterSQLite3Queryable {
|
|
534
|
-
constructor(client, options, unlockParent) {
|
|
535
|
-
super(client);
|
|
543
|
+
constructor(client, options, adapterOptions, unlockParent) {
|
|
544
|
+
super(client, adapterOptions);
|
|
536
545
|
this.options = options;
|
|
537
|
-
this
|
|
546
|
+
this.#unlockParent = unlockParent;
|
|
538
547
|
}
|
|
548
|
+
#unlockParent;
|
|
539
549
|
commit() {
|
|
540
550
|
debug2(`[js::commit]`);
|
|
541
|
-
this
|
|
551
|
+
this.#unlockParent();
|
|
542
552
|
return Promise.resolve();
|
|
543
553
|
}
|
|
544
554
|
rollback() {
|
|
545
555
|
debug2(`[js::rollback]`);
|
|
546
|
-
this
|
|
556
|
+
this.#unlockParent();
|
|
547
557
|
return Promise.resolve();
|
|
548
558
|
}
|
|
549
559
|
};
|
|
550
560
|
var PrismaBetterSQLite3Adapter = class extends BetterSQLite3Queryable {
|
|
551
561
|
#mutex = new Mutex();
|
|
552
|
-
constructor(client) {
|
|
553
|
-
super(client);
|
|
562
|
+
constructor(client, adapterOptions) {
|
|
563
|
+
super(client, adapterOptions);
|
|
554
564
|
}
|
|
555
565
|
executeScript(script) {
|
|
556
566
|
try {
|
|
@@ -575,7 +585,7 @@ var PrismaBetterSQLite3Adapter = class extends BetterSQLite3Queryable {
|
|
|
575
585
|
try {
|
|
576
586
|
const release = await this.#mutex.acquire();
|
|
577
587
|
this.client.prepare("BEGIN").run();
|
|
578
|
-
return new BetterSQLite3Transaction(this.client, options, release);
|
|
588
|
+
return new BetterSQLite3Transaction(this.client, options, this.adapterOptions, release);
|
|
579
589
|
} catch (e) {
|
|
580
590
|
this.onError(e);
|
|
581
591
|
}
|
|
@@ -586,17 +596,22 @@ var PrismaBetterSQLite3Adapter = class extends BetterSQLite3Queryable {
|
|
|
586
596
|
}
|
|
587
597
|
};
|
|
588
598
|
var PrismaBetterSQLite3AdapterFactory = class {
|
|
589
|
-
constructor(config) {
|
|
590
|
-
this.config = config;
|
|
591
|
-
}
|
|
592
599
|
provider = "sqlite";
|
|
593
600
|
adapterName = name;
|
|
601
|
+
#config;
|
|
602
|
+
#options;
|
|
603
|
+
constructor(config, options) {
|
|
604
|
+
this.#config = config;
|
|
605
|
+
this.#options = options;
|
|
606
|
+
}
|
|
594
607
|
connect() {
|
|
595
|
-
return Promise.resolve(new PrismaBetterSQLite3Adapter(createBetterSQLite3Client(this
|
|
608
|
+
return Promise.resolve(new PrismaBetterSQLite3Adapter(createBetterSQLite3Client(this.#config), this.#options));
|
|
596
609
|
}
|
|
597
610
|
connectToShadowDb() {
|
|
598
|
-
const url = this
|
|
599
|
-
return Promise.resolve(
|
|
611
|
+
const url = this.#options?.shadowDatabaseUrl ?? ":memory:";
|
|
612
|
+
return Promise.resolve(
|
|
613
|
+
new PrismaBetterSQLite3Adapter(createBetterSQLite3Client({ ...this.#config, url }), this.#options)
|
|
614
|
+
);
|
|
600
615
|
}
|
|
601
616
|
};
|
|
602
617
|
function createBetterSQLite3Client(input) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/adapter-better-sqlite3",
|
|
3
|
-
"version": "6.16.0-dev.
|
|
3
|
+
"version": "6.16.0-dev.30",
|
|
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": "^11.9.0",
|
|
35
|
-
"@prisma/driver-adapter-utils": "6.16.0-dev.
|
|
35
|
+
"@prisma/driver-adapter-utils": "6.16.0-dev.30"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/better-sqlite3": "7.6.12",
|