jukebox-media-server 0.4.0 → 0.5.0
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/client/assets/{Watch-DE2orFm6.js → Watch-Ja4PAA8Y.js} +31 -31
- package/dist/client/assets/index-AENKhh_8.css +1 -0
- package/dist/client/assets/{index-hOWDqZr2.js → index-Cm9WIhoR.js} +2 -2
- package/dist/client/index.html +2 -2
- package/dist/client/sw.js +1 -1
- package/dist/server/better-sqlite3-Dy_YhTFe.js +2709 -0
- package/dist/server/index.js +223 -4314
- package/dist/server/indexes-VMR6QVVl.js +1409 -0
- package/dist/server/migrator-CWPnMvx5.js +37 -0
- package/package.json +2 -1
- package/dist/client/assets/index-CLZKF1oG.css +0 -1
package/dist/server/index.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
+
import { U as sql, _ as inArray, a as real, f as eq, i as text, l as desc, m as gt, o as integer, r as sqliteTable, t as uniqueIndex, u as and, x as lt } from "./indexes-VMR6QVVl.js";
|
|
1
2
|
import { constants, createReadStream, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync } from "fs";
|
|
2
|
-
import path, { basename, dirname, extname, join } from "path";
|
|
3
|
-
import { fileURLToPath } from "url";
|
|
4
3
|
import { createServer } from "http";
|
|
5
4
|
import { Http2ServerRequest, constants as constants$1 } from "http2";
|
|
6
5
|
import { Readable } from "stream";
|
|
7
6
|
import crypto$1, { randomBytes, scrypt, timingSafeEqual } from "crypto";
|
|
7
|
+
import path, { basename, dirname, extname, join } from "path";
|
|
8
8
|
import { versions } from "process";
|
|
9
|
-
import
|
|
10
|
-
import crypto$2 from "node:crypto";
|
|
11
|
-
import fs from "node:fs";
|
|
9
|
+
import { fileURLToPath } from "url";
|
|
12
10
|
import os, { homedir } from "os";
|
|
13
11
|
import { promisify } from "util";
|
|
14
12
|
import { access, readFile, readdir, stat } from "fs/promises";
|
|
@@ -2461,4331 +2459,223 @@ var TrieRouter = class {
|
|
|
2461
2459
|
constructor() {
|
|
2462
2460
|
this.#node = new Node();
|
|
2463
2461
|
}
|
|
2464
|
-
add(method, path, handler) {
|
|
2465
|
-
const results = checkOptionalParameter(path);
|
|
2466
|
-
if (results) {
|
|
2467
|
-
for (let i = 0, len = results.length; i < len; i++) this.#node.insert(method, results[i], handler);
|
|
2468
|
-
return;
|
|
2469
|
-
}
|
|
2470
|
-
this.#node.insert(method, path, handler);
|
|
2471
|
-
}
|
|
2472
|
-
match(method, path) {
|
|
2473
|
-
return this.#node.search(method, path);
|
|
2474
|
-
}
|
|
2475
|
-
};
|
|
2476
|
-
//#endregion
|
|
2477
|
-
//#region node_modules/hono/dist/hono.js
|
|
2478
|
-
var Hono = class extends Hono$1 {
|
|
2479
|
-
/**
|
|
2480
|
-
* Creates an instance of the Hono class.
|
|
2481
|
-
*
|
|
2482
|
-
* @param options - Optional configuration options for the Hono instance.
|
|
2483
|
-
*/
|
|
2484
|
-
constructor(options = {}) {
|
|
2485
|
-
super(options);
|
|
2486
|
-
this.router = options.router ?? new SmartRouter({ routers: [new RegExpRouter(), new TrieRouter()] });
|
|
2487
|
-
}
|
|
2488
|
-
};
|
|
2489
|
-
//#endregion
|
|
2490
|
-
//#region node_modules/hono/dist/utils/color.js
|
|
2491
|
-
function getColorEnabled() {
|
|
2492
|
-
const { process, Deno } = globalThis;
|
|
2493
|
-
return !(typeof Deno?.noColor === "boolean" ? Deno.noColor : process !== void 0 ? "NO_COLOR" in process?.env : false);
|
|
2494
|
-
}
|
|
2495
|
-
async function getColorEnabledAsync() {
|
|
2496
|
-
const { navigator } = globalThis;
|
|
2497
|
-
const cfWorkers = "cloudflare:workers";
|
|
2498
|
-
return !(navigator !== void 0 && navigator.userAgent === "Cloudflare-Workers" ? await (async () => {
|
|
2499
|
-
try {
|
|
2500
|
-
return "NO_COLOR" in ((await import(cfWorkers)).env ?? {});
|
|
2501
|
-
} catch {
|
|
2502
|
-
return false;
|
|
2503
|
-
}
|
|
2504
|
-
})() : !getColorEnabled());
|
|
2505
|
-
}
|
|
2506
|
-
//#endregion
|
|
2507
|
-
//#region node_modules/hono/dist/middleware/logger/index.js
|
|
2508
|
-
var humanize = (times) => {
|
|
2509
|
-
const [delimiter, separator] = [",", "."];
|
|
2510
|
-
return times.map((v) => v.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1" + delimiter)).join(separator);
|
|
2511
|
-
};
|
|
2512
|
-
var time = (start) => {
|
|
2513
|
-
const delta = Date.now() - start;
|
|
2514
|
-
return humanize([delta < 1e3 ? delta + "ms" : Math.round(delta / 1e3) + "s"]);
|
|
2515
|
-
};
|
|
2516
|
-
var colorStatus = async (status) => {
|
|
2517
|
-
if (await getColorEnabledAsync()) switch (status / 100 | 0) {
|
|
2518
|
-
case 5: return `\x1B[31m${status}\x1B[0m`;
|
|
2519
|
-
case 4: return `\x1B[33m${status}\x1B[0m`;
|
|
2520
|
-
case 3: return `\x1B[36m${status}\x1B[0m`;
|
|
2521
|
-
case 2: return `\x1B[32m${status}\x1B[0m`;
|
|
2522
|
-
}
|
|
2523
|
-
return `${status}`;
|
|
2524
|
-
};
|
|
2525
|
-
async function log$1(fn, prefix, method, path, status = 0, elapsed) {
|
|
2526
|
-
fn(prefix === "<--" ? `${prefix} ${method} ${path}` : `${prefix} ${method} ${path} ${await colorStatus(status)} ${elapsed}`);
|
|
2527
|
-
}
|
|
2528
|
-
var logger$1 = (fn = console.log) => {
|
|
2529
|
-
return async function logger2(c, next) {
|
|
2530
|
-
const { method, url } = c.req;
|
|
2531
|
-
const path = url.slice(url.indexOf("/", 8));
|
|
2532
|
-
await log$1(fn, "<--", method, path);
|
|
2533
|
-
const start = Date.now();
|
|
2534
|
-
await next();
|
|
2535
|
-
await log$1(fn, "-->", method, path, c.res.status, time(start));
|
|
2536
|
-
};
|
|
2537
|
-
};
|
|
2538
|
-
//#endregion
|
|
2539
|
-
//#region node_modules/drizzle-orm/entity.js
|
|
2540
|
-
const entityKind = Symbol.for("drizzle:entityKind");
|
|
2541
|
-
function is(value, type) {
|
|
2542
|
-
if (!value || typeof value !== "object") return false;
|
|
2543
|
-
if (value instanceof type) return true;
|
|
2544
|
-
if (!Object.prototype.hasOwnProperty.call(type, entityKind)) throw new Error(`Class "${type.name ?? "<unknown>"}" doesn't look like a Drizzle entity. If this is incorrect and the class is provided by Drizzle, please report this as a bug.`);
|
|
2545
|
-
let cls = Object.getPrototypeOf(value).constructor;
|
|
2546
|
-
if (cls) while (cls) {
|
|
2547
|
-
if (entityKind in cls && cls[entityKind] === type[entityKind]) return true;
|
|
2548
|
-
cls = Object.getPrototypeOf(cls);
|
|
2549
|
-
}
|
|
2550
|
-
return false;
|
|
2551
|
-
}
|
|
2552
|
-
//#endregion
|
|
2553
|
-
//#region node_modules/drizzle-orm/column.js
|
|
2554
|
-
var Column = class {
|
|
2555
|
-
constructor(table, config) {
|
|
2556
|
-
this.table = table;
|
|
2557
|
-
this.config = config;
|
|
2558
|
-
this.name = config.name;
|
|
2559
|
-
this.keyAsName = config.keyAsName;
|
|
2560
|
-
this.notNull = config.notNull;
|
|
2561
|
-
this.default = config.default;
|
|
2562
|
-
this.defaultFn = config.defaultFn;
|
|
2563
|
-
this.onUpdateFn = config.onUpdateFn;
|
|
2564
|
-
this.hasDefault = config.hasDefault;
|
|
2565
|
-
this.primary = config.primaryKey;
|
|
2566
|
-
this.isUnique = config.isUnique;
|
|
2567
|
-
this.uniqueName = config.uniqueName;
|
|
2568
|
-
this.uniqueType = config.uniqueType;
|
|
2569
|
-
this.dataType = config.dataType;
|
|
2570
|
-
this.columnType = config.columnType;
|
|
2571
|
-
this.generated = config.generated;
|
|
2572
|
-
this.generatedIdentity = config.generatedIdentity;
|
|
2573
|
-
}
|
|
2574
|
-
static [entityKind] = "Column";
|
|
2575
|
-
name;
|
|
2576
|
-
keyAsName;
|
|
2577
|
-
primary;
|
|
2578
|
-
notNull;
|
|
2579
|
-
default;
|
|
2580
|
-
defaultFn;
|
|
2581
|
-
onUpdateFn;
|
|
2582
|
-
hasDefault;
|
|
2583
|
-
isUnique;
|
|
2584
|
-
uniqueName;
|
|
2585
|
-
uniqueType;
|
|
2586
|
-
dataType;
|
|
2587
|
-
columnType;
|
|
2588
|
-
enumValues = void 0;
|
|
2589
|
-
generated = void 0;
|
|
2590
|
-
generatedIdentity = void 0;
|
|
2591
|
-
config;
|
|
2592
|
-
mapFromDriverValue(value) {
|
|
2593
|
-
return value;
|
|
2594
|
-
}
|
|
2595
|
-
mapToDriverValue(value) {
|
|
2596
|
-
return value;
|
|
2597
|
-
}
|
|
2598
|
-
shouldDisableInsert() {
|
|
2599
|
-
return this.config.generated !== void 0 && this.config.generated.type !== "byDefault";
|
|
2600
|
-
}
|
|
2601
|
-
};
|
|
2602
|
-
//#endregion
|
|
2603
|
-
//#region node_modules/drizzle-orm/column-builder.js
|
|
2604
|
-
var ColumnBuilder = class {
|
|
2605
|
-
static [entityKind] = "ColumnBuilder";
|
|
2606
|
-
config;
|
|
2607
|
-
constructor(name, dataType, columnType) {
|
|
2608
|
-
this.config = {
|
|
2609
|
-
name,
|
|
2610
|
-
keyAsName: name === "",
|
|
2611
|
-
notNull: false,
|
|
2612
|
-
default: void 0,
|
|
2613
|
-
hasDefault: false,
|
|
2614
|
-
primaryKey: false,
|
|
2615
|
-
isUnique: false,
|
|
2616
|
-
uniqueName: void 0,
|
|
2617
|
-
uniqueType: void 0,
|
|
2618
|
-
dataType,
|
|
2619
|
-
columnType,
|
|
2620
|
-
generated: void 0
|
|
2621
|
-
};
|
|
2622
|
-
}
|
|
2623
|
-
/**
|
|
2624
|
-
* Changes the data type of the column. Commonly used with `json` columns. Also, useful for branded types.
|
|
2625
|
-
*
|
|
2626
|
-
* @example
|
|
2627
|
-
* ```ts
|
|
2628
|
-
* const users = pgTable('users', {
|
|
2629
|
-
* id: integer('id').$type<UserId>().primaryKey(),
|
|
2630
|
-
* details: json('details').$type<UserDetails>().notNull(),
|
|
2631
|
-
* });
|
|
2632
|
-
* ```
|
|
2633
|
-
*/
|
|
2634
|
-
$type() {
|
|
2635
|
-
return this;
|
|
2636
|
-
}
|
|
2637
|
-
/**
|
|
2638
|
-
* Adds a `not null` clause to the column definition.
|
|
2639
|
-
*
|
|
2640
|
-
* Affects the `select` model of the table - columns *without* `not null` will be nullable on select.
|
|
2641
|
-
*/
|
|
2642
|
-
notNull() {
|
|
2643
|
-
this.config.notNull = true;
|
|
2644
|
-
return this;
|
|
2645
|
-
}
|
|
2646
|
-
/**
|
|
2647
|
-
* Adds a `default <value>` clause to the column definition.
|
|
2648
|
-
*
|
|
2649
|
-
* Affects the `insert` model of the table - columns *with* `default` are optional on insert.
|
|
2650
|
-
*
|
|
2651
|
-
* If you need to set a dynamic default value, use {@link $defaultFn} instead.
|
|
2652
|
-
*/
|
|
2653
|
-
default(value) {
|
|
2654
|
-
this.config.default = value;
|
|
2655
|
-
this.config.hasDefault = true;
|
|
2656
|
-
return this;
|
|
2657
|
-
}
|
|
2658
|
-
/**
|
|
2659
|
-
* Adds a dynamic default value to the column.
|
|
2660
|
-
* The function will be called when the row is inserted, and the returned value will be used as the column value.
|
|
2661
|
-
*
|
|
2662
|
-
* **Note:** This value does not affect the `drizzle-kit` behavior, it is only used at runtime in `drizzle-orm`.
|
|
2663
|
-
*/
|
|
2664
|
-
$defaultFn(fn) {
|
|
2665
|
-
this.config.defaultFn = fn;
|
|
2666
|
-
this.config.hasDefault = true;
|
|
2667
|
-
return this;
|
|
2668
|
-
}
|
|
2669
|
-
/**
|
|
2670
|
-
* Alias for {@link $defaultFn}.
|
|
2671
|
-
*/
|
|
2672
|
-
$default = this.$defaultFn;
|
|
2673
|
-
/**
|
|
2674
|
-
* Adds a dynamic update value to the column.
|
|
2675
|
-
* The function will be called when the row is updated, and the returned value will be used as the column value if none is provided.
|
|
2676
|
-
* If no `default` (or `$defaultFn`) value is provided, the function will be called when the row is inserted as well, and the returned value will be used as the column value.
|
|
2677
|
-
*
|
|
2678
|
-
* **Note:** This value does not affect the `drizzle-kit` behavior, it is only used at runtime in `drizzle-orm`.
|
|
2679
|
-
*/
|
|
2680
|
-
$onUpdateFn(fn) {
|
|
2681
|
-
this.config.onUpdateFn = fn;
|
|
2682
|
-
this.config.hasDefault = true;
|
|
2683
|
-
return this;
|
|
2684
|
-
}
|
|
2685
|
-
/**
|
|
2686
|
-
* Alias for {@link $onUpdateFn}.
|
|
2687
|
-
*/
|
|
2688
|
-
$onUpdate = this.$onUpdateFn;
|
|
2689
|
-
/**
|
|
2690
|
-
* Adds a `primary key` clause to the column definition. This implicitly makes the column `not null`.
|
|
2691
|
-
*
|
|
2692
|
-
* In SQLite, `integer primary key` implicitly makes the column auto-incrementing.
|
|
2693
|
-
*/
|
|
2694
|
-
primaryKey() {
|
|
2695
|
-
this.config.primaryKey = true;
|
|
2696
|
-
this.config.notNull = true;
|
|
2697
|
-
return this;
|
|
2698
|
-
}
|
|
2699
|
-
/** @internal Sets the name of the column to the key within the table definition if a name was not given. */
|
|
2700
|
-
setName(name) {
|
|
2701
|
-
if (this.config.name !== "") return;
|
|
2702
|
-
this.config.name = name;
|
|
2703
|
-
}
|
|
2704
|
-
};
|
|
2705
|
-
//#endregion
|
|
2706
|
-
//#region node_modules/drizzle-orm/table.utils.js
|
|
2707
|
-
const TableName = Symbol.for("drizzle:Name");
|
|
2708
|
-
//#endregion
|
|
2709
|
-
//#region node_modules/drizzle-orm/pg-core/columns/enum.js
|
|
2710
|
-
const isPgEnumSym = Symbol.for("drizzle:isPgEnum");
|
|
2711
|
-
function isPgEnum(obj) {
|
|
2712
|
-
return !!obj && typeof obj === "function" && isPgEnumSym in obj && obj[isPgEnumSym] === true;
|
|
2713
|
-
}
|
|
2714
|
-
//#endregion
|
|
2715
|
-
//#region node_modules/drizzle-orm/subquery.js
|
|
2716
|
-
var Subquery = class {
|
|
2717
|
-
static [entityKind] = "Subquery";
|
|
2718
|
-
constructor(sql, fields, alias, isWith = false, usedTables = []) {
|
|
2719
|
-
this._ = {
|
|
2720
|
-
brand: "Subquery",
|
|
2721
|
-
sql,
|
|
2722
|
-
selectedFields: fields,
|
|
2723
|
-
alias,
|
|
2724
|
-
isWith,
|
|
2725
|
-
usedTables
|
|
2726
|
-
};
|
|
2727
|
-
}
|
|
2728
|
-
};
|
|
2729
|
-
var WithSubquery = class extends Subquery {
|
|
2730
|
-
static [entityKind] = "WithSubquery";
|
|
2731
|
-
};
|
|
2732
|
-
//#endregion
|
|
2733
|
-
//#region node_modules/drizzle-orm/tracing.js
|
|
2734
|
-
const tracer = { startActiveSpan(name, fn) {
|
|
2735
|
-
return fn();
|
|
2736
|
-
} };
|
|
2737
|
-
//#endregion
|
|
2738
|
-
//#region node_modules/drizzle-orm/view-common.js
|
|
2739
|
-
const ViewBaseConfig = Symbol.for("drizzle:ViewBaseConfig");
|
|
2740
|
-
//#endregion
|
|
2741
|
-
//#region node_modules/drizzle-orm/table.js
|
|
2742
|
-
const Schema = Symbol.for("drizzle:Schema");
|
|
2743
|
-
const Columns = Symbol.for("drizzle:Columns");
|
|
2744
|
-
const ExtraConfigColumns = Symbol.for("drizzle:ExtraConfigColumns");
|
|
2745
|
-
const OriginalName = Symbol.for("drizzle:OriginalName");
|
|
2746
|
-
const BaseName = Symbol.for("drizzle:BaseName");
|
|
2747
|
-
const IsAlias = Symbol.for("drizzle:IsAlias");
|
|
2748
|
-
const ExtraConfigBuilder = Symbol.for("drizzle:ExtraConfigBuilder");
|
|
2749
|
-
const IsDrizzleTable = Symbol.for("drizzle:IsDrizzleTable");
|
|
2750
|
-
var Table = class {
|
|
2751
|
-
static [entityKind] = "Table";
|
|
2752
|
-
/** @internal */
|
|
2753
|
-
static Symbol = {
|
|
2754
|
-
Name: TableName,
|
|
2755
|
-
Schema,
|
|
2756
|
-
OriginalName,
|
|
2757
|
-
Columns,
|
|
2758
|
-
ExtraConfigColumns,
|
|
2759
|
-
BaseName,
|
|
2760
|
-
IsAlias,
|
|
2761
|
-
ExtraConfigBuilder
|
|
2762
|
-
};
|
|
2763
|
-
/**
|
|
2764
|
-
* @internal
|
|
2765
|
-
* Can be changed if the table is aliased.
|
|
2766
|
-
*/
|
|
2767
|
-
[TableName];
|
|
2768
|
-
/**
|
|
2769
|
-
* @internal
|
|
2770
|
-
* Used to store the original name of the table, before any aliasing.
|
|
2771
|
-
*/
|
|
2772
|
-
[OriginalName];
|
|
2773
|
-
/** @internal */
|
|
2774
|
-
[Schema];
|
|
2775
|
-
/** @internal */
|
|
2776
|
-
[Columns];
|
|
2777
|
-
/** @internal */
|
|
2778
|
-
[ExtraConfigColumns];
|
|
2779
|
-
/**
|
|
2780
|
-
* @internal
|
|
2781
|
-
* Used to store the table name before the transformation via the `tableCreator` functions.
|
|
2782
|
-
*/
|
|
2783
|
-
[BaseName];
|
|
2784
|
-
/** @internal */
|
|
2785
|
-
[IsAlias] = false;
|
|
2786
|
-
/** @internal */
|
|
2787
|
-
[IsDrizzleTable] = true;
|
|
2788
|
-
/** @internal */
|
|
2789
|
-
[ExtraConfigBuilder] = void 0;
|
|
2790
|
-
constructor(name, schema, baseName) {
|
|
2791
|
-
this[TableName] = this[OriginalName] = name;
|
|
2792
|
-
this[Schema] = schema;
|
|
2793
|
-
this[BaseName] = baseName;
|
|
2794
|
-
}
|
|
2795
|
-
};
|
|
2796
|
-
function getTableName(table) {
|
|
2797
|
-
return table[TableName];
|
|
2798
|
-
}
|
|
2799
|
-
function getTableUniqueName(table) {
|
|
2800
|
-
return `${table[Schema] ?? "public"}.${table[TableName]}`;
|
|
2801
|
-
}
|
|
2802
|
-
//#endregion
|
|
2803
|
-
//#region node_modules/drizzle-orm/sql/sql.js
|
|
2804
|
-
function isSQLWrapper(value) {
|
|
2805
|
-
return value !== null && value !== void 0 && typeof value.getSQL === "function";
|
|
2806
|
-
}
|
|
2807
|
-
function mergeQueries(queries) {
|
|
2808
|
-
const result = {
|
|
2809
|
-
sql: "",
|
|
2810
|
-
params: []
|
|
2811
|
-
};
|
|
2812
|
-
for (const query of queries) {
|
|
2813
|
-
result.sql += query.sql;
|
|
2814
|
-
result.params.push(...query.params);
|
|
2815
|
-
if (query.typings?.length) {
|
|
2816
|
-
if (!result.typings) result.typings = [];
|
|
2817
|
-
result.typings.push(...query.typings);
|
|
2818
|
-
}
|
|
2819
|
-
}
|
|
2820
|
-
return result;
|
|
2821
|
-
}
|
|
2822
|
-
var StringChunk = class {
|
|
2823
|
-
static [entityKind] = "StringChunk";
|
|
2824
|
-
value;
|
|
2825
|
-
constructor(value) {
|
|
2826
|
-
this.value = Array.isArray(value) ? value : [value];
|
|
2827
|
-
}
|
|
2828
|
-
getSQL() {
|
|
2829
|
-
return new SQL([this]);
|
|
2830
|
-
}
|
|
2831
|
-
};
|
|
2832
|
-
var SQL = class SQL {
|
|
2833
|
-
constructor(queryChunks) {
|
|
2834
|
-
this.queryChunks = queryChunks;
|
|
2835
|
-
for (const chunk of queryChunks) if (is(chunk, Table)) {
|
|
2836
|
-
const schemaName = chunk[Table.Symbol.Schema];
|
|
2837
|
-
this.usedTables.push(schemaName === void 0 ? chunk[Table.Symbol.Name] : schemaName + "." + chunk[Table.Symbol.Name]);
|
|
2838
|
-
}
|
|
2839
|
-
}
|
|
2840
|
-
static [entityKind] = "SQL";
|
|
2841
|
-
/** @internal */
|
|
2842
|
-
decoder = noopDecoder;
|
|
2843
|
-
shouldInlineParams = false;
|
|
2844
|
-
/** @internal */
|
|
2845
|
-
usedTables = [];
|
|
2846
|
-
append(query) {
|
|
2847
|
-
this.queryChunks.push(...query.queryChunks);
|
|
2848
|
-
return this;
|
|
2849
|
-
}
|
|
2850
|
-
toQuery(config) {
|
|
2851
|
-
return tracer.startActiveSpan("drizzle.buildSQL", (span) => {
|
|
2852
|
-
const query = this.buildQueryFromSourceParams(this.queryChunks, config);
|
|
2853
|
-
span?.setAttributes({
|
|
2854
|
-
"drizzle.query.text": query.sql,
|
|
2855
|
-
"drizzle.query.params": JSON.stringify(query.params)
|
|
2856
|
-
});
|
|
2857
|
-
return query;
|
|
2858
|
-
});
|
|
2859
|
-
}
|
|
2860
|
-
buildQueryFromSourceParams(chunks, _config) {
|
|
2861
|
-
const config = Object.assign({}, _config, {
|
|
2862
|
-
inlineParams: _config.inlineParams || this.shouldInlineParams,
|
|
2863
|
-
paramStartIndex: _config.paramStartIndex || { value: 0 }
|
|
2864
|
-
});
|
|
2865
|
-
const { casing, escapeName, escapeParam, prepareTyping, inlineParams, paramStartIndex } = config;
|
|
2866
|
-
return mergeQueries(chunks.map((chunk) => {
|
|
2867
|
-
if (is(chunk, StringChunk)) return {
|
|
2868
|
-
sql: chunk.value.join(""),
|
|
2869
|
-
params: []
|
|
2870
|
-
};
|
|
2871
|
-
if (is(chunk, Name)) return {
|
|
2872
|
-
sql: escapeName(chunk.value),
|
|
2873
|
-
params: []
|
|
2874
|
-
};
|
|
2875
|
-
if (chunk === void 0) return {
|
|
2876
|
-
sql: "",
|
|
2877
|
-
params: []
|
|
2878
|
-
};
|
|
2879
|
-
if (Array.isArray(chunk)) {
|
|
2880
|
-
const result = [new StringChunk("(")];
|
|
2881
|
-
for (const [i, p] of chunk.entries()) {
|
|
2882
|
-
result.push(p);
|
|
2883
|
-
if (i < chunk.length - 1) result.push(new StringChunk(", "));
|
|
2884
|
-
}
|
|
2885
|
-
result.push(new StringChunk(")"));
|
|
2886
|
-
return this.buildQueryFromSourceParams(result, config);
|
|
2887
|
-
}
|
|
2888
|
-
if (is(chunk, SQL)) return this.buildQueryFromSourceParams(chunk.queryChunks, {
|
|
2889
|
-
...config,
|
|
2890
|
-
inlineParams: inlineParams || chunk.shouldInlineParams
|
|
2891
|
-
});
|
|
2892
|
-
if (is(chunk, Table)) {
|
|
2893
|
-
const schemaName = chunk[Table.Symbol.Schema];
|
|
2894
|
-
const tableName = chunk[Table.Symbol.Name];
|
|
2895
|
-
return {
|
|
2896
|
-
sql: schemaName === void 0 || chunk[IsAlias] ? escapeName(tableName) : escapeName(schemaName) + "." + escapeName(tableName),
|
|
2897
|
-
params: []
|
|
2898
|
-
};
|
|
2899
|
-
}
|
|
2900
|
-
if (is(chunk, Column)) {
|
|
2901
|
-
const columnName = casing.getColumnCasing(chunk);
|
|
2902
|
-
if (_config.invokeSource === "indexes") return {
|
|
2903
|
-
sql: escapeName(columnName),
|
|
2904
|
-
params: []
|
|
2905
|
-
};
|
|
2906
|
-
const schemaName = chunk.table[Table.Symbol.Schema];
|
|
2907
|
-
return {
|
|
2908
|
-
sql: chunk.table[IsAlias] || schemaName === void 0 ? escapeName(chunk.table[Table.Symbol.Name]) + "." + escapeName(columnName) : escapeName(schemaName) + "." + escapeName(chunk.table[Table.Symbol.Name]) + "." + escapeName(columnName),
|
|
2909
|
-
params: []
|
|
2910
|
-
};
|
|
2911
|
-
}
|
|
2912
|
-
if (is(chunk, View)) {
|
|
2913
|
-
const schemaName = chunk[ViewBaseConfig].schema;
|
|
2914
|
-
const viewName = chunk[ViewBaseConfig].name;
|
|
2915
|
-
return {
|
|
2916
|
-
sql: schemaName === void 0 || chunk[ViewBaseConfig].isAlias ? escapeName(viewName) : escapeName(schemaName) + "." + escapeName(viewName),
|
|
2917
|
-
params: []
|
|
2918
|
-
};
|
|
2919
|
-
}
|
|
2920
|
-
if (is(chunk, Param)) {
|
|
2921
|
-
if (is(chunk.value, Placeholder)) return {
|
|
2922
|
-
sql: escapeParam(paramStartIndex.value++, chunk),
|
|
2923
|
-
params: [chunk],
|
|
2924
|
-
typings: ["none"]
|
|
2925
|
-
};
|
|
2926
|
-
const mappedValue = chunk.value === null ? null : chunk.encoder.mapToDriverValue(chunk.value);
|
|
2927
|
-
if (is(mappedValue, SQL)) return this.buildQueryFromSourceParams([mappedValue], config);
|
|
2928
|
-
if (inlineParams) return {
|
|
2929
|
-
sql: this.mapInlineParam(mappedValue, config),
|
|
2930
|
-
params: []
|
|
2931
|
-
};
|
|
2932
|
-
let typings = ["none"];
|
|
2933
|
-
if (prepareTyping) typings = [prepareTyping(chunk.encoder)];
|
|
2934
|
-
return {
|
|
2935
|
-
sql: escapeParam(paramStartIndex.value++, mappedValue),
|
|
2936
|
-
params: [mappedValue],
|
|
2937
|
-
typings
|
|
2938
|
-
};
|
|
2939
|
-
}
|
|
2940
|
-
if (is(chunk, Placeholder)) return {
|
|
2941
|
-
sql: escapeParam(paramStartIndex.value++, chunk),
|
|
2942
|
-
params: [chunk],
|
|
2943
|
-
typings: ["none"]
|
|
2944
|
-
};
|
|
2945
|
-
if (is(chunk, SQL.Aliased) && chunk.fieldAlias !== void 0) return {
|
|
2946
|
-
sql: escapeName(chunk.fieldAlias),
|
|
2947
|
-
params: []
|
|
2948
|
-
};
|
|
2949
|
-
if (is(chunk, Subquery)) {
|
|
2950
|
-
if (chunk._.isWith) return {
|
|
2951
|
-
sql: escapeName(chunk._.alias),
|
|
2952
|
-
params: []
|
|
2953
|
-
};
|
|
2954
|
-
return this.buildQueryFromSourceParams([
|
|
2955
|
-
new StringChunk("("),
|
|
2956
|
-
chunk._.sql,
|
|
2957
|
-
new StringChunk(") "),
|
|
2958
|
-
new Name(chunk._.alias)
|
|
2959
|
-
], config);
|
|
2960
|
-
}
|
|
2961
|
-
if (isPgEnum(chunk)) {
|
|
2962
|
-
if (chunk.schema) return {
|
|
2963
|
-
sql: escapeName(chunk.schema) + "." + escapeName(chunk.enumName),
|
|
2964
|
-
params: []
|
|
2965
|
-
};
|
|
2966
|
-
return {
|
|
2967
|
-
sql: escapeName(chunk.enumName),
|
|
2968
|
-
params: []
|
|
2969
|
-
};
|
|
2970
|
-
}
|
|
2971
|
-
if (isSQLWrapper(chunk)) {
|
|
2972
|
-
if (chunk.shouldOmitSQLParens?.()) return this.buildQueryFromSourceParams([chunk.getSQL()], config);
|
|
2973
|
-
return this.buildQueryFromSourceParams([
|
|
2974
|
-
new StringChunk("("),
|
|
2975
|
-
chunk.getSQL(),
|
|
2976
|
-
new StringChunk(")")
|
|
2977
|
-
], config);
|
|
2978
|
-
}
|
|
2979
|
-
if (inlineParams) return {
|
|
2980
|
-
sql: this.mapInlineParam(chunk, config),
|
|
2981
|
-
params: []
|
|
2982
|
-
};
|
|
2983
|
-
return {
|
|
2984
|
-
sql: escapeParam(paramStartIndex.value++, chunk),
|
|
2985
|
-
params: [chunk],
|
|
2986
|
-
typings: ["none"]
|
|
2987
|
-
};
|
|
2988
|
-
}));
|
|
2989
|
-
}
|
|
2990
|
-
mapInlineParam(chunk, { escapeString }) {
|
|
2991
|
-
if (chunk === null) return "null";
|
|
2992
|
-
if (typeof chunk === "number" || typeof chunk === "boolean") return chunk.toString();
|
|
2993
|
-
if (typeof chunk === "string") return escapeString(chunk);
|
|
2994
|
-
if (typeof chunk === "object") {
|
|
2995
|
-
const mappedValueAsString = chunk.toString();
|
|
2996
|
-
if (mappedValueAsString === "[object Object]") return escapeString(JSON.stringify(chunk));
|
|
2997
|
-
return escapeString(mappedValueAsString);
|
|
2998
|
-
}
|
|
2999
|
-
throw new Error("Unexpected param value: " + chunk);
|
|
3000
|
-
}
|
|
3001
|
-
getSQL() {
|
|
3002
|
-
return this;
|
|
3003
|
-
}
|
|
3004
|
-
as(alias) {
|
|
3005
|
-
if (alias === void 0) return this;
|
|
3006
|
-
return new SQL.Aliased(this, alias);
|
|
3007
|
-
}
|
|
3008
|
-
mapWith(decoder) {
|
|
3009
|
-
this.decoder = typeof decoder === "function" ? { mapFromDriverValue: decoder } : decoder;
|
|
3010
|
-
return this;
|
|
3011
|
-
}
|
|
3012
|
-
inlineParams() {
|
|
3013
|
-
this.shouldInlineParams = true;
|
|
3014
|
-
return this;
|
|
3015
|
-
}
|
|
3016
|
-
/**
|
|
3017
|
-
* This method is used to conditionally include a part of the query.
|
|
3018
|
-
*
|
|
3019
|
-
* @param condition - Condition to check
|
|
3020
|
-
* @returns itself if the condition is `true`, otherwise `undefined`
|
|
3021
|
-
*/
|
|
3022
|
-
if(condition) {
|
|
3023
|
-
return condition ? this : void 0;
|
|
3024
|
-
}
|
|
3025
|
-
};
|
|
3026
|
-
var Name = class {
|
|
3027
|
-
constructor(value) {
|
|
3028
|
-
this.value = value;
|
|
3029
|
-
}
|
|
3030
|
-
static [entityKind] = "Name";
|
|
3031
|
-
brand;
|
|
3032
|
-
getSQL() {
|
|
3033
|
-
return new SQL([this]);
|
|
3034
|
-
}
|
|
3035
|
-
};
|
|
3036
|
-
function isDriverValueEncoder(value) {
|
|
3037
|
-
return typeof value === "object" && value !== null && "mapToDriverValue" in value && typeof value.mapToDriverValue === "function";
|
|
3038
|
-
}
|
|
3039
|
-
const noopDecoder = { mapFromDriverValue: (value) => value };
|
|
3040
|
-
const noopEncoder = { mapToDriverValue: (value) => value };
|
|
3041
|
-
({
|
|
3042
|
-
...noopDecoder,
|
|
3043
|
-
...noopEncoder
|
|
3044
|
-
});
|
|
3045
|
-
var Param = class {
|
|
3046
|
-
/**
|
|
3047
|
-
* @param value - Parameter value
|
|
3048
|
-
* @param encoder - Encoder to convert the value to a driver parameter
|
|
3049
|
-
*/
|
|
3050
|
-
constructor(value, encoder = noopEncoder) {
|
|
3051
|
-
this.value = value;
|
|
3052
|
-
this.encoder = encoder;
|
|
3053
|
-
}
|
|
3054
|
-
static [entityKind] = "Param";
|
|
3055
|
-
brand;
|
|
3056
|
-
getSQL() {
|
|
3057
|
-
return new SQL([this]);
|
|
3058
|
-
}
|
|
3059
|
-
};
|
|
3060
|
-
function sql(strings, ...params) {
|
|
3061
|
-
const queryChunks = [];
|
|
3062
|
-
if (params.length > 0 || strings.length > 0 && strings[0] !== "") queryChunks.push(new StringChunk(strings[0]));
|
|
3063
|
-
for (const [paramIndex, param2] of params.entries()) queryChunks.push(param2, new StringChunk(strings[paramIndex + 1]));
|
|
3064
|
-
return new SQL(queryChunks);
|
|
3065
|
-
}
|
|
3066
|
-
((sql2) => {
|
|
3067
|
-
function empty() {
|
|
3068
|
-
return new SQL([]);
|
|
3069
|
-
}
|
|
3070
|
-
sql2.empty = empty;
|
|
3071
|
-
function fromList(list) {
|
|
3072
|
-
return new SQL(list);
|
|
3073
|
-
}
|
|
3074
|
-
sql2.fromList = fromList;
|
|
3075
|
-
function raw(str) {
|
|
3076
|
-
return new SQL([new StringChunk(str)]);
|
|
3077
|
-
}
|
|
3078
|
-
sql2.raw = raw;
|
|
3079
|
-
function join(chunks, separator) {
|
|
3080
|
-
const result = [];
|
|
3081
|
-
for (const [i, chunk] of chunks.entries()) {
|
|
3082
|
-
if (i > 0 && separator !== void 0) result.push(separator);
|
|
3083
|
-
result.push(chunk);
|
|
3084
|
-
}
|
|
3085
|
-
return new SQL(result);
|
|
3086
|
-
}
|
|
3087
|
-
sql2.join = join;
|
|
3088
|
-
function identifier(value) {
|
|
3089
|
-
return new Name(value);
|
|
3090
|
-
}
|
|
3091
|
-
sql2.identifier = identifier;
|
|
3092
|
-
function placeholder2(name2) {
|
|
3093
|
-
return new Placeholder(name2);
|
|
3094
|
-
}
|
|
3095
|
-
sql2.placeholder = placeholder2;
|
|
3096
|
-
function param2(value, encoder) {
|
|
3097
|
-
return new Param(value, encoder);
|
|
3098
|
-
}
|
|
3099
|
-
sql2.param = param2;
|
|
3100
|
-
})(sql || (sql = {}));
|
|
3101
|
-
((SQL2) => {
|
|
3102
|
-
class Aliased {
|
|
3103
|
-
constructor(sql2, fieldAlias) {
|
|
3104
|
-
this.sql = sql2;
|
|
3105
|
-
this.fieldAlias = fieldAlias;
|
|
3106
|
-
}
|
|
3107
|
-
static [entityKind] = "SQL.Aliased";
|
|
3108
|
-
/** @internal */
|
|
3109
|
-
isSelectionField = false;
|
|
3110
|
-
getSQL() {
|
|
3111
|
-
return this.sql;
|
|
3112
|
-
}
|
|
3113
|
-
/** @internal */
|
|
3114
|
-
clone() {
|
|
3115
|
-
return new Aliased(this.sql, this.fieldAlias);
|
|
3116
|
-
}
|
|
3117
|
-
}
|
|
3118
|
-
SQL2.Aliased = Aliased;
|
|
3119
|
-
})(SQL || (SQL = {}));
|
|
3120
|
-
var Placeholder = class {
|
|
3121
|
-
constructor(name2) {
|
|
3122
|
-
this.name = name2;
|
|
3123
|
-
}
|
|
3124
|
-
static [entityKind] = "Placeholder";
|
|
3125
|
-
getSQL() {
|
|
3126
|
-
return new SQL([this]);
|
|
3127
|
-
}
|
|
3128
|
-
};
|
|
3129
|
-
function fillPlaceholders(params, values) {
|
|
3130
|
-
return params.map((p) => {
|
|
3131
|
-
if (is(p, Placeholder)) {
|
|
3132
|
-
if (!(p.name in values)) throw new Error(`No value for placeholder "${p.name}" was provided`);
|
|
3133
|
-
return values[p.name];
|
|
3134
|
-
}
|
|
3135
|
-
if (is(p, Param) && is(p.value, Placeholder)) {
|
|
3136
|
-
if (!(p.value.name in values)) throw new Error(`No value for placeholder "${p.value.name}" was provided`);
|
|
3137
|
-
return p.encoder.mapToDriverValue(values[p.value.name]);
|
|
3138
|
-
}
|
|
3139
|
-
return p;
|
|
3140
|
-
});
|
|
3141
|
-
}
|
|
3142
|
-
const IsDrizzleView = Symbol.for("drizzle:IsDrizzleView");
|
|
3143
|
-
var View = class {
|
|
3144
|
-
static [entityKind] = "View";
|
|
3145
|
-
/** @internal */
|
|
3146
|
-
[ViewBaseConfig];
|
|
3147
|
-
/** @internal */
|
|
3148
|
-
[IsDrizzleView] = true;
|
|
3149
|
-
constructor({ name: name2, schema, selectedFields, query }) {
|
|
3150
|
-
this[ViewBaseConfig] = {
|
|
3151
|
-
name: name2,
|
|
3152
|
-
originalName: name2,
|
|
3153
|
-
schema,
|
|
3154
|
-
selectedFields,
|
|
3155
|
-
query,
|
|
3156
|
-
isExisting: !query,
|
|
3157
|
-
isAlias: false
|
|
3158
|
-
};
|
|
3159
|
-
}
|
|
3160
|
-
getSQL() {
|
|
3161
|
-
return new SQL([this]);
|
|
3162
|
-
}
|
|
3163
|
-
};
|
|
3164
|
-
Column.prototype.getSQL = function() {
|
|
3165
|
-
return new SQL([this]);
|
|
3166
|
-
};
|
|
3167
|
-
Table.prototype.getSQL = function() {
|
|
3168
|
-
return new SQL([this]);
|
|
3169
|
-
};
|
|
3170
|
-
Subquery.prototype.getSQL = function() {
|
|
3171
|
-
return new SQL([this]);
|
|
3172
|
-
};
|
|
3173
|
-
//#endregion
|
|
3174
|
-
//#region node_modules/drizzle-orm/alias.js
|
|
3175
|
-
var ColumnAliasProxyHandler = class {
|
|
3176
|
-
constructor(table) {
|
|
3177
|
-
this.table = table;
|
|
3178
|
-
}
|
|
3179
|
-
static [entityKind] = "ColumnAliasProxyHandler";
|
|
3180
|
-
get(columnObj, prop) {
|
|
3181
|
-
if (prop === "table") return this.table;
|
|
3182
|
-
return columnObj[prop];
|
|
3183
|
-
}
|
|
3184
|
-
};
|
|
3185
|
-
var TableAliasProxyHandler = class {
|
|
3186
|
-
constructor(alias, replaceOriginalName) {
|
|
3187
|
-
this.alias = alias;
|
|
3188
|
-
this.replaceOriginalName = replaceOriginalName;
|
|
3189
|
-
}
|
|
3190
|
-
static [entityKind] = "TableAliasProxyHandler";
|
|
3191
|
-
get(target, prop) {
|
|
3192
|
-
if (prop === Table.Symbol.IsAlias) return true;
|
|
3193
|
-
if (prop === Table.Symbol.Name) return this.alias;
|
|
3194
|
-
if (this.replaceOriginalName && prop === Table.Symbol.OriginalName) return this.alias;
|
|
3195
|
-
if (prop === ViewBaseConfig) return {
|
|
3196
|
-
...target[ViewBaseConfig],
|
|
3197
|
-
name: this.alias,
|
|
3198
|
-
isAlias: true
|
|
3199
|
-
};
|
|
3200
|
-
if (prop === Table.Symbol.Columns) {
|
|
3201
|
-
const columns = target[Table.Symbol.Columns];
|
|
3202
|
-
if (!columns) return columns;
|
|
3203
|
-
const proxiedColumns = {};
|
|
3204
|
-
Object.keys(columns).map((key) => {
|
|
3205
|
-
proxiedColumns[key] = new Proxy(columns[key], new ColumnAliasProxyHandler(new Proxy(target, this)));
|
|
3206
|
-
});
|
|
3207
|
-
return proxiedColumns;
|
|
3208
|
-
}
|
|
3209
|
-
const value = target[prop];
|
|
3210
|
-
if (is(value, Column)) return new Proxy(value, new ColumnAliasProxyHandler(new Proxy(target, this)));
|
|
3211
|
-
return value;
|
|
3212
|
-
}
|
|
3213
|
-
};
|
|
3214
|
-
function aliasedTable(table, tableAlias) {
|
|
3215
|
-
return new Proxy(table, new TableAliasProxyHandler(tableAlias, false));
|
|
3216
|
-
}
|
|
3217
|
-
function aliasedTableColumn(column, tableAlias) {
|
|
3218
|
-
return new Proxy(column, new ColumnAliasProxyHandler(new Proxy(column.table, new TableAliasProxyHandler(tableAlias, false))));
|
|
3219
|
-
}
|
|
3220
|
-
function mapColumnsInAliasedSQLToAlias(query, alias) {
|
|
3221
|
-
return new SQL.Aliased(mapColumnsInSQLToAlias(query.sql, alias), query.fieldAlias);
|
|
3222
|
-
}
|
|
3223
|
-
function mapColumnsInSQLToAlias(query, alias) {
|
|
3224
|
-
return sql.join(query.queryChunks.map((c) => {
|
|
3225
|
-
if (is(c, Column)) return aliasedTableColumn(c, alias);
|
|
3226
|
-
if (is(c, SQL)) return mapColumnsInSQLToAlias(c, alias);
|
|
3227
|
-
if (is(c, SQL.Aliased)) return mapColumnsInAliasedSQLToAlias(c, alias);
|
|
3228
|
-
return c;
|
|
3229
|
-
}));
|
|
3230
|
-
}
|
|
3231
|
-
//#endregion
|
|
3232
|
-
//#region node_modules/drizzle-orm/errors.js
|
|
3233
|
-
var DrizzleError = class extends Error {
|
|
3234
|
-
static [entityKind] = "DrizzleError";
|
|
3235
|
-
constructor({ message, cause }) {
|
|
3236
|
-
super(message);
|
|
3237
|
-
this.name = "DrizzleError";
|
|
3238
|
-
this.cause = cause;
|
|
3239
|
-
}
|
|
3240
|
-
};
|
|
3241
|
-
var DrizzleQueryError = class DrizzleQueryError extends Error {
|
|
3242
|
-
constructor(query, params, cause) {
|
|
3243
|
-
super(`Failed query: ${query}
|
|
3244
|
-
params: ${params}`);
|
|
3245
|
-
this.query = query;
|
|
3246
|
-
this.params = params;
|
|
3247
|
-
this.cause = cause;
|
|
3248
|
-
Error.captureStackTrace(this, DrizzleQueryError);
|
|
3249
|
-
if (cause) this.cause = cause;
|
|
3250
|
-
}
|
|
3251
|
-
};
|
|
3252
|
-
var TransactionRollbackError = class extends DrizzleError {
|
|
3253
|
-
static [entityKind] = "TransactionRollbackError";
|
|
3254
|
-
constructor() {
|
|
3255
|
-
super({ message: "Rollback" });
|
|
3256
|
-
}
|
|
3257
|
-
};
|
|
3258
|
-
//#endregion
|
|
3259
|
-
//#region node_modules/drizzle-orm/logger.js
|
|
3260
|
-
var ConsoleLogWriter = class {
|
|
3261
|
-
static [entityKind] = "ConsoleLogWriter";
|
|
3262
|
-
write(message) {
|
|
3263
|
-
console.log(message);
|
|
3264
|
-
}
|
|
3265
|
-
};
|
|
3266
|
-
var DefaultLogger = class {
|
|
3267
|
-
static [entityKind] = "DefaultLogger";
|
|
3268
|
-
writer;
|
|
3269
|
-
constructor(config) {
|
|
3270
|
-
this.writer = config?.writer ?? new ConsoleLogWriter();
|
|
3271
|
-
}
|
|
3272
|
-
logQuery(query, params) {
|
|
3273
|
-
const stringifiedParams = params.map((p) => {
|
|
3274
|
-
try {
|
|
3275
|
-
return JSON.stringify(p);
|
|
3276
|
-
} catch {
|
|
3277
|
-
return String(p);
|
|
3278
|
-
}
|
|
3279
|
-
});
|
|
3280
|
-
const paramsStr = stringifiedParams.length ? ` -- params: [${stringifiedParams.join(", ")}]` : "";
|
|
3281
|
-
this.writer.write(`Query: ${query}${paramsStr}`);
|
|
3282
|
-
}
|
|
3283
|
-
};
|
|
3284
|
-
var NoopLogger = class {
|
|
3285
|
-
static [entityKind] = "NoopLogger";
|
|
3286
|
-
logQuery() {}
|
|
3287
|
-
};
|
|
3288
|
-
//#endregion
|
|
3289
|
-
//#region node_modules/drizzle-orm/query-promise.js
|
|
3290
|
-
var QueryPromise = class {
|
|
3291
|
-
static [entityKind] = "QueryPromise";
|
|
3292
|
-
[Symbol.toStringTag] = "QueryPromise";
|
|
3293
|
-
catch(onRejected) {
|
|
3294
|
-
return this.then(void 0, onRejected);
|
|
3295
|
-
}
|
|
3296
|
-
finally(onFinally) {
|
|
3297
|
-
return this.then((value) => {
|
|
3298
|
-
onFinally?.();
|
|
3299
|
-
return value;
|
|
3300
|
-
}, (reason) => {
|
|
3301
|
-
onFinally?.();
|
|
3302
|
-
throw reason;
|
|
3303
|
-
});
|
|
3304
|
-
}
|
|
3305
|
-
then(onFulfilled, onRejected) {
|
|
3306
|
-
return this.execute().then(onFulfilled, onRejected);
|
|
3307
|
-
}
|
|
3308
|
-
};
|
|
3309
|
-
//#endregion
|
|
3310
|
-
//#region node_modules/drizzle-orm/utils.js
|
|
3311
|
-
function mapResultRow(columns, row, joinsNotNullableMap) {
|
|
3312
|
-
const nullifyMap = {};
|
|
3313
|
-
const result = columns.reduce((result2, { path, field }, columnIndex) => {
|
|
3314
|
-
let decoder;
|
|
3315
|
-
if (is(field, Column)) decoder = field;
|
|
3316
|
-
else if (is(field, SQL)) decoder = field.decoder;
|
|
3317
|
-
else if (is(field, Subquery)) decoder = field._.sql.decoder;
|
|
3318
|
-
else decoder = field.sql.decoder;
|
|
3319
|
-
let node = result2;
|
|
3320
|
-
for (const [pathChunkIndex, pathChunk] of path.entries()) if (pathChunkIndex < path.length - 1) {
|
|
3321
|
-
if (!(pathChunk in node)) node[pathChunk] = {};
|
|
3322
|
-
node = node[pathChunk];
|
|
3323
|
-
} else {
|
|
3324
|
-
const rawValue = row[columnIndex];
|
|
3325
|
-
const value = node[pathChunk] = rawValue === null ? null : decoder.mapFromDriverValue(rawValue);
|
|
3326
|
-
if (joinsNotNullableMap && is(field, Column) && path.length === 2) {
|
|
3327
|
-
const objectName = path[0];
|
|
3328
|
-
if (!(objectName in nullifyMap)) nullifyMap[objectName] = value === null ? getTableName(field.table) : false;
|
|
3329
|
-
else if (typeof nullifyMap[objectName] === "string" && nullifyMap[objectName] !== getTableName(field.table)) nullifyMap[objectName] = false;
|
|
3330
|
-
}
|
|
3331
|
-
}
|
|
3332
|
-
return result2;
|
|
3333
|
-
}, {});
|
|
3334
|
-
if (joinsNotNullableMap && Object.keys(nullifyMap).length > 0) {
|
|
3335
|
-
for (const [objectName, tableName] of Object.entries(nullifyMap)) if (typeof tableName === "string" && !joinsNotNullableMap[tableName]) result[objectName] = null;
|
|
3336
|
-
}
|
|
3337
|
-
return result;
|
|
3338
|
-
}
|
|
3339
|
-
function orderSelectedFields(fields, pathPrefix) {
|
|
3340
|
-
return Object.entries(fields).reduce((result, [name, field]) => {
|
|
3341
|
-
if (typeof name !== "string") return result;
|
|
3342
|
-
const newPath = pathPrefix ? [...pathPrefix, name] : [name];
|
|
3343
|
-
if (is(field, Column) || is(field, SQL) || is(field, SQL.Aliased) || is(field, Subquery)) result.push({
|
|
3344
|
-
path: newPath,
|
|
3345
|
-
field
|
|
3346
|
-
});
|
|
3347
|
-
else if (is(field, Table)) result.push(...orderSelectedFields(field[Table.Symbol.Columns], newPath));
|
|
3348
|
-
else result.push(...orderSelectedFields(field, newPath));
|
|
3349
|
-
return result;
|
|
3350
|
-
}, []);
|
|
3351
|
-
}
|
|
3352
|
-
function haveSameKeys(left, right) {
|
|
3353
|
-
const leftKeys = Object.keys(left);
|
|
3354
|
-
const rightKeys = Object.keys(right);
|
|
3355
|
-
if (leftKeys.length !== rightKeys.length) return false;
|
|
3356
|
-
for (const [index, key] of leftKeys.entries()) if (key !== rightKeys[index]) return false;
|
|
3357
|
-
return true;
|
|
3358
|
-
}
|
|
3359
|
-
function mapUpdateSet(table, values) {
|
|
3360
|
-
const entries = Object.entries(values).filter(([, value]) => value !== void 0).map(([key, value]) => {
|
|
3361
|
-
if (is(value, SQL) || is(value, Column)) return [key, value];
|
|
3362
|
-
else return [key, new Param(value, table[Table.Symbol.Columns][key])];
|
|
3363
|
-
});
|
|
3364
|
-
if (entries.length === 0) throw new Error("No values to set");
|
|
3365
|
-
return Object.fromEntries(entries);
|
|
3366
|
-
}
|
|
3367
|
-
function applyMixins(baseClass, extendedClasses) {
|
|
3368
|
-
for (const extendedClass of extendedClasses) for (const name of Object.getOwnPropertyNames(extendedClass.prototype)) {
|
|
3369
|
-
if (name === "constructor") continue;
|
|
3370
|
-
Object.defineProperty(baseClass.prototype, name, Object.getOwnPropertyDescriptor(extendedClass.prototype, name) || /* @__PURE__ */ Object.create(null));
|
|
3371
|
-
}
|
|
3372
|
-
}
|
|
3373
|
-
function getTableColumns(table) {
|
|
3374
|
-
return table[Table.Symbol.Columns];
|
|
3375
|
-
}
|
|
3376
|
-
function getTableLikeName(table) {
|
|
3377
|
-
return is(table, Subquery) ? table._.alias : is(table, View) ? table[ViewBaseConfig].name : is(table, SQL) ? void 0 : table[Table.Symbol.IsAlias] ? table[Table.Symbol.Name] : table[Table.Symbol.BaseName];
|
|
3378
|
-
}
|
|
3379
|
-
function getColumnNameAndConfig(a, b) {
|
|
3380
|
-
return {
|
|
3381
|
-
name: typeof a === "string" && a.length > 0 ? a : "",
|
|
3382
|
-
config: typeof a === "object" ? a : b
|
|
3383
|
-
};
|
|
3384
|
-
}
|
|
3385
|
-
function isConfig(data) {
|
|
3386
|
-
if (typeof data !== "object" || data === null) return false;
|
|
3387
|
-
if (data.constructor.name !== "Object") return false;
|
|
3388
|
-
if ("logger" in data) {
|
|
3389
|
-
const type = typeof data["logger"];
|
|
3390
|
-
if (type !== "boolean" && (type !== "object" || typeof data["logger"]["logQuery"] !== "function") && type !== "undefined") return false;
|
|
3391
|
-
return true;
|
|
3392
|
-
}
|
|
3393
|
-
if ("schema" in data) {
|
|
3394
|
-
const type = typeof data["schema"];
|
|
3395
|
-
if (type !== "object" && type !== "undefined") return false;
|
|
3396
|
-
return true;
|
|
3397
|
-
}
|
|
3398
|
-
if ("casing" in data) {
|
|
3399
|
-
const type = typeof data["casing"];
|
|
3400
|
-
if (type !== "string" && type !== "undefined") return false;
|
|
3401
|
-
return true;
|
|
3402
|
-
}
|
|
3403
|
-
if ("mode" in data) {
|
|
3404
|
-
if (data["mode"] !== "default" || data["mode"] !== "planetscale" || data["mode"] !== void 0) return false;
|
|
3405
|
-
return true;
|
|
3406
|
-
}
|
|
3407
|
-
if ("connection" in data) {
|
|
3408
|
-
const type = typeof data["connection"];
|
|
3409
|
-
if (type !== "string" && type !== "object" && type !== "undefined") return false;
|
|
3410
|
-
return true;
|
|
3411
|
-
}
|
|
3412
|
-
if ("client" in data) {
|
|
3413
|
-
const type = typeof data["client"];
|
|
3414
|
-
if (type !== "object" && type !== "function" && type !== "undefined") return false;
|
|
3415
|
-
return true;
|
|
3416
|
-
}
|
|
3417
|
-
if (Object.keys(data).length === 0) return true;
|
|
3418
|
-
return false;
|
|
3419
|
-
}
|
|
3420
|
-
const textDecoder = typeof TextDecoder === "undefined" ? null : new TextDecoder();
|
|
3421
|
-
//#endregion
|
|
3422
|
-
//#region node_modules/drizzle-orm/pg-core/table.js
|
|
3423
|
-
const InlineForeignKeys$1 = Symbol.for("drizzle:PgInlineForeignKeys");
|
|
3424
|
-
const EnableRLS = Symbol.for("drizzle:EnableRLS");
|
|
3425
|
-
var PgTable = class extends Table {
|
|
3426
|
-
static [entityKind] = "PgTable";
|
|
3427
|
-
/** @internal */
|
|
3428
|
-
static Symbol = Object.assign({}, Table.Symbol, {
|
|
3429
|
-
InlineForeignKeys: InlineForeignKeys$1,
|
|
3430
|
-
EnableRLS
|
|
3431
|
-
});
|
|
3432
|
-
/**@internal */
|
|
3433
|
-
[InlineForeignKeys$1] = [];
|
|
3434
|
-
/** @internal */
|
|
3435
|
-
[EnableRLS] = false;
|
|
3436
|
-
/** @internal */
|
|
3437
|
-
[Table.Symbol.ExtraConfigBuilder] = void 0;
|
|
3438
|
-
/** @internal */
|
|
3439
|
-
[Table.Symbol.ExtraConfigColumns] = {};
|
|
3440
|
-
};
|
|
3441
|
-
//#endregion
|
|
3442
|
-
//#region node_modules/drizzle-orm/pg-core/primary-keys.js
|
|
3443
|
-
var PrimaryKeyBuilder = class {
|
|
3444
|
-
static [entityKind] = "PgPrimaryKeyBuilder";
|
|
3445
|
-
/** @internal */
|
|
3446
|
-
columns;
|
|
3447
|
-
/** @internal */
|
|
3448
|
-
name;
|
|
3449
|
-
constructor(columns, name) {
|
|
3450
|
-
this.columns = columns;
|
|
3451
|
-
this.name = name;
|
|
3452
|
-
}
|
|
3453
|
-
/** @internal */
|
|
3454
|
-
build(table) {
|
|
3455
|
-
return new PrimaryKey(table, this.columns, this.name);
|
|
3456
|
-
}
|
|
3457
|
-
};
|
|
3458
|
-
var PrimaryKey = class {
|
|
3459
|
-
constructor(table, columns, name) {
|
|
3460
|
-
this.table = table;
|
|
3461
|
-
this.columns = columns;
|
|
3462
|
-
this.name = name;
|
|
3463
|
-
}
|
|
3464
|
-
static [entityKind] = "PgPrimaryKey";
|
|
3465
|
-
columns;
|
|
3466
|
-
name;
|
|
3467
|
-
getName() {
|
|
3468
|
-
return this.name ?? `${this.table[PgTable.Symbol.Name]}_${this.columns.map((column) => column.name).join("_")}_pk`;
|
|
3469
|
-
}
|
|
3470
|
-
};
|
|
3471
|
-
//#endregion
|
|
3472
|
-
//#region node_modules/drizzle-orm/sql/expressions/conditions.js
|
|
3473
|
-
function bindIfParam(value, column) {
|
|
3474
|
-
if (isDriverValueEncoder(column) && !isSQLWrapper(value) && !is(value, Param) && !is(value, Placeholder) && !is(value, Column) && !is(value, Table) && !is(value, View)) return new Param(value, column);
|
|
3475
|
-
return value;
|
|
3476
|
-
}
|
|
3477
|
-
const eq = (left, right) => {
|
|
3478
|
-
return sql`${left} = ${bindIfParam(right, left)}`;
|
|
3479
|
-
};
|
|
3480
|
-
const ne = (left, right) => {
|
|
3481
|
-
return sql`${left} <> ${bindIfParam(right, left)}`;
|
|
3482
|
-
};
|
|
3483
|
-
function and(...unfilteredConditions) {
|
|
3484
|
-
const conditions = unfilteredConditions.filter((c) => c !== void 0);
|
|
3485
|
-
if (conditions.length === 0) return;
|
|
3486
|
-
if (conditions.length === 1) return new SQL(conditions);
|
|
3487
|
-
return new SQL([
|
|
3488
|
-
new StringChunk("("),
|
|
3489
|
-
sql.join(conditions, new StringChunk(" and ")),
|
|
3490
|
-
new StringChunk(")")
|
|
3491
|
-
]);
|
|
3492
|
-
}
|
|
3493
|
-
function or(...unfilteredConditions) {
|
|
3494
|
-
const conditions = unfilteredConditions.filter((c) => c !== void 0);
|
|
3495
|
-
if (conditions.length === 0) return;
|
|
3496
|
-
if (conditions.length === 1) return new SQL(conditions);
|
|
3497
|
-
return new SQL([
|
|
3498
|
-
new StringChunk("("),
|
|
3499
|
-
sql.join(conditions, new StringChunk(" or ")),
|
|
3500
|
-
new StringChunk(")")
|
|
3501
|
-
]);
|
|
3502
|
-
}
|
|
3503
|
-
function not(condition) {
|
|
3504
|
-
return sql`not ${condition}`;
|
|
3505
|
-
}
|
|
3506
|
-
const gt = (left, right) => {
|
|
3507
|
-
return sql`${left} > ${bindIfParam(right, left)}`;
|
|
3508
|
-
};
|
|
3509
|
-
const gte = (left, right) => {
|
|
3510
|
-
return sql`${left} >= ${bindIfParam(right, left)}`;
|
|
3511
|
-
};
|
|
3512
|
-
const lt = (left, right) => {
|
|
3513
|
-
return sql`${left} < ${bindIfParam(right, left)}`;
|
|
3514
|
-
};
|
|
3515
|
-
const lte = (left, right) => {
|
|
3516
|
-
return sql`${left} <= ${bindIfParam(right, left)}`;
|
|
3517
|
-
};
|
|
3518
|
-
function inArray(column, values) {
|
|
3519
|
-
if (Array.isArray(values)) {
|
|
3520
|
-
if (values.length === 0) return sql`false`;
|
|
3521
|
-
return sql`${column} in ${values.map((v) => bindIfParam(v, column))}`;
|
|
3522
|
-
}
|
|
3523
|
-
return sql`${column} in ${bindIfParam(values, column)}`;
|
|
3524
|
-
}
|
|
3525
|
-
function notInArray(column, values) {
|
|
3526
|
-
if (Array.isArray(values)) {
|
|
3527
|
-
if (values.length === 0) return sql`true`;
|
|
3528
|
-
return sql`${column} not in ${values.map((v) => bindIfParam(v, column))}`;
|
|
3529
|
-
}
|
|
3530
|
-
return sql`${column} not in ${bindIfParam(values, column)}`;
|
|
3531
|
-
}
|
|
3532
|
-
function isNull(value) {
|
|
3533
|
-
return sql`${value} is null`;
|
|
3534
|
-
}
|
|
3535
|
-
function isNotNull(value) {
|
|
3536
|
-
return sql`${value} is not null`;
|
|
3537
|
-
}
|
|
3538
|
-
function exists(subquery) {
|
|
3539
|
-
return sql`exists ${subquery}`;
|
|
3540
|
-
}
|
|
3541
|
-
function notExists(subquery) {
|
|
3542
|
-
return sql`not exists ${subquery}`;
|
|
3543
|
-
}
|
|
3544
|
-
function between(column, min, max) {
|
|
3545
|
-
return sql`${column} between ${bindIfParam(min, column)} and ${bindIfParam(max, column)}`;
|
|
3546
|
-
}
|
|
3547
|
-
function notBetween(column, min, max) {
|
|
3548
|
-
return sql`${column} not between ${bindIfParam(min, column)} and ${bindIfParam(max, column)}`;
|
|
3549
|
-
}
|
|
3550
|
-
function like(column, value) {
|
|
3551
|
-
return sql`${column} like ${value}`;
|
|
3552
|
-
}
|
|
3553
|
-
function notLike(column, value) {
|
|
3554
|
-
return sql`${column} not like ${value}`;
|
|
3555
|
-
}
|
|
3556
|
-
function ilike(column, value) {
|
|
3557
|
-
return sql`${column} ilike ${value}`;
|
|
3558
|
-
}
|
|
3559
|
-
function notIlike(column, value) {
|
|
3560
|
-
return sql`${column} not ilike ${value}`;
|
|
3561
|
-
}
|
|
3562
|
-
//#endregion
|
|
3563
|
-
//#region node_modules/drizzle-orm/sql/expressions/select.js
|
|
3564
|
-
function asc(column) {
|
|
3565
|
-
return sql`${column} asc`;
|
|
3566
|
-
}
|
|
3567
|
-
function desc(column) {
|
|
3568
|
-
return sql`${column} desc`;
|
|
3569
|
-
}
|
|
3570
|
-
//#endregion
|
|
3571
|
-
//#region node_modules/drizzle-orm/relations.js
|
|
3572
|
-
var Relation = class {
|
|
3573
|
-
constructor(sourceTable, referencedTable, relationName) {
|
|
3574
|
-
this.sourceTable = sourceTable;
|
|
3575
|
-
this.referencedTable = referencedTable;
|
|
3576
|
-
this.relationName = relationName;
|
|
3577
|
-
this.referencedTableName = referencedTable[Table.Symbol.Name];
|
|
3578
|
-
}
|
|
3579
|
-
static [entityKind] = "Relation";
|
|
3580
|
-
referencedTableName;
|
|
3581
|
-
fieldName;
|
|
3582
|
-
};
|
|
3583
|
-
var Relations = class {
|
|
3584
|
-
constructor(table, config) {
|
|
3585
|
-
this.table = table;
|
|
3586
|
-
this.config = config;
|
|
3587
|
-
}
|
|
3588
|
-
static [entityKind] = "Relations";
|
|
3589
|
-
};
|
|
3590
|
-
var One = class One extends Relation {
|
|
3591
|
-
constructor(sourceTable, referencedTable, config, isNullable) {
|
|
3592
|
-
super(sourceTable, referencedTable, config?.relationName);
|
|
3593
|
-
this.config = config;
|
|
3594
|
-
this.isNullable = isNullable;
|
|
3595
|
-
}
|
|
3596
|
-
static [entityKind] = "One";
|
|
3597
|
-
withFieldName(fieldName) {
|
|
3598
|
-
const relation = new One(this.sourceTable, this.referencedTable, this.config, this.isNullable);
|
|
3599
|
-
relation.fieldName = fieldName;
|
|
3600
|
-
return relation;
|
|
3601
|
-
}
|
|
3602
|
-
};
|
|
3603
|
-
var Many = class Many extends Relation {
|
|
3604
|
-
constructor(sourceTable, referencedTable, config) {
|
|
3605
|
-
super(sourceTable, referencedTable, config?.relationName);
|
|
3606
|
-
this.config = config;
|
|
3607
|
-
}
|
|
3608
|
-
static [entityKind] = "Many";
|
|
3609
|
-
withFieldName(fieldName) {
|
|
3610
|
-
const relation = new Many(this.sourceTable, this.referencedTable, this.config);
|
|
3611
|
-
relation.fieldName = fieldName;
|
|
3612
|
-
return relation;
|
|
3613
|
-
}
|
|
3614
|
-
};
|
|
3615
|
-
function getOperators() {
|
|
3616
|
-
return {
|
|
3617
|
-
and,
|
|
3618
|
-
between,
|
|
3619
|
-
eq,
|
|
3620
|
-
exists,
|
|
3621
|
-
gt,
|
|
3622
|
-
gte,
|
|
3623
|
-
ilike,
|
|
3624
|
-
inArray,
|
|
3625
|
-
isNull,
|
|
3626
|
-
isNotNull,
|
|
3627
|
-
like,
|
|
3628
|
-
lt,
|
|
3629
|
-
lte,
|
|
3630
|
-
ne,
|
|
3631
|
-
not,
|
|
3632
|
-
notBetween,
|
|
3633
|
-
notExists,
|
|
3634
|
-
notLike,
|
|
3635
|
-
notIlike,
|
|
3636
|
-
notInArray,
|
|
3637
|
-
or,
|
|
3638
|
-
sql
|
|
3639
|
-
};
|
|
3640
|
-
}
|
|
3641
|
-
function getOrderByOperators() {
|
|
3642
|
-
return {
|
|
3643
|
-
sql,
|
|
3644
|
-
asc,
|
|
3645
|
-
desc
|
|
3646
|
-
};
|
|
3647
|
-
}
|
|
3648
|
-
function extractTablesRelationalConfig(schema, configHelpers) {
|
|
3649
|
-
if (Object.keys(schema).length === 1 && "default" in schema && !is(schema["default"], Table)) schema = schema["default"];
|
|
3650
|
-
const tableNamesMap = {};
|
|
3651
|
-
const relationsBuffer = {};
|
|
3652
|
-
const tablesConfig = {};
|
|
3653
|
-
for (const [key, value] of Object.entries(schema)) if (is(value, Table)) {
|
|
3654
|
-
const dbName = getTableUniqueName(value);
|
|
3655
|
-
const bufferedRelations = relationsBuffer[dbName];
|
|
3656
|
-
tableNamesMap[dbName] = key;
|
|
3657
|
-
tablesConfig[key] = {
|
|
3658
|
-
tsName: key,
|
|
3659
|
-
dbName: value[Table.Symbol.Name],
|
|
3660
|
-
schema: value[Table.Symbol.Schema],
|
|
3661
|
-
columns: value[Table.Symbol.Columns],
|
|
3662
|
-
relations: bufferedRelations?.relations ?? {},
|
|
3663
|
-
primaryKey: bufferedRelations?.primaryKey ?? []
|
|
3664
|
-
};
|
|
3665
|
-
for (const column of Object.values(value[Table.Symbol.Columns])) if (column.primary) tablesConfig[key].primaryKey.push(column);
|
|
3666
|
-
const extraConfig = value[Table.Symbol.ExtraConfigBuilder]?.(value[Table.Symbol.ExtraConfigColumns]);
|
|
3667
|
-
if (extraConfig) {
|
|
3668
|
-
for (const configEntry of Object.values(extraConfig)) if (is(configEntry, PrimaryKeyBuilder)) tablesConfig[key].primaryKey.push(...configEntry.columns);
|
|
3669
|
-
}
|
|
3670
|
-
} else if (is(value, Relations)) {
|
|
3671
|
-
const dbName = getTableUniqueName(value.table);
|
|
3672
|
-
const tableName = tableNamesMap[dbName];
|
|
3673
|
-
const relations2 = value.config(configHelpers(value.table));
|
|
3674
|
-
let primaryKey;
|
|
3675
|
-
for (const [relationName, relation] of Object.entries(relations2)) if (tableName) {
|
|
3676
|
-
const tableConfig = tablesConfig[tableName];
|
|
3677
|
-
tableConfig.relations[relationName] = relation;
|
|
3678
|
-
} else {
|
|
3679
|
-
if (!(dbName in relationsBuffer)) relationsBuffer[dbName] = {
|
|
3680
|
-
relations: {},
|
|
3681
|
-
primaryKey
|
|
3682
|
-
};
|
|
3683
|
-
relationsBuffer[dbName].relations[relationName] = relation;
|
|
3684
|
-
}
|
|
3685
|
-
}
|
|
3686
|
-
return {
|
|
3687
|
-
tables: tablesConfig,
|
|
3688
|
-
tableNamesMap
|
|
3689
|
-
};
|
|
3690
|
-
}
|
|
3691
|
-
function createOne(sourceTable) {
|
|
3692
|
-
return function one(table, config) {
|
|
3693
|
-
return new One(sourceTable, table, config, config?.fields.reduce((res, f) => res && f.notNull, true) ?? false);
|
|
3694
|
-
};
|
|
3695
|
-
}
|
|
3696
|
-
function createMany(sourceTable) {
|
|
3697
|
-
return function many(referencedTable, config) {
|
|
3698
|
-
return new Many(sourceTable, referencedTable, config);
|
|
3699
|
-
};
|
|
3700
|
-
}
|
|
3701
|
-
function normalizeRelation(schema, tableNamesMap, relation) {
|
|
3702
|
-
if (is(relation, One) && relation.config) return {
|
|
3703
|
-
fields: relation.config.fields,
|
|
3704
|
-
references: relation.config.references
|
|
3705
|
-
};
|
|
3706
|
-
const referencedTableTsName = tableNamesMap[getTableUniqueName(relation.referencedTable)];
|
|
3707
|
-
if (!referencedTableTsName) throw new Error(`Table "${relation.referencedTable[Table.Symbol.Name]}" not found in schema`);
|
|
3708
|
-
const referencedTableConfig = schema[referencedTableTsName];
|
|
3709
|
-
if (!referencedTableConfig) throw new Error(`Table "${referencedTableTsName}" not found in schema`);
|
|
3710
|
-
const sourceTable = relation.sourceTable;
|
|
3711
|
-
const sourceTableTsName = tableNamesMap[getTableUniqueName(sourceTable)];
|
|
3712
|
-
if (!sourceTableTsName) throw new Error(`Table "${sourceTable[Table.Symbol.Name]}" not found in schema`);
|
|
3713
|
-
const reverseRelations = [];
|
|
3714
|
-
for (const referencedTableRelation of Object.values(referencedTableConfig.relations)) if (relation.relationName && relation !== referencedTableRelation && referencedTableRelation.relationName === relation.relationName || !relation.relationName && referencedTableRelation.referencedTable === relation.sourceTable) reverseRelations.push(referencedTableRelation);
|
|
3715
|
-
if (reverseRelations.length > 1) throw relation.relationName ? /* @__PURE__ */ new Error(`There are multiple relations with name "${relation.relationName}" in table "${referencedTableTsName}"`) : /* @__PURE__ */ new Error(`There are multiple relations between "${referencedTableTsName}" and "${relation.sourceTable[Table.Symbol.Name]}". Please specify relation name`);
|
|
3716
|
-
if (reverseRelations[0] && is(reverseRelations[0], One) && reverseRelations[0].config) return {
|
|
3717
|
-
fields: reverseRelations[0].config.references,
|
|
3718
|
-
references: reverseRelations[0].config.fields
|
|
3719
|
-
};
|
|
3720
|
-
throw new Error(`There is not enough information to infer relation "${sourceTableTsName}.${relation.fieldName}"`);
|
|
3721
|
-
}
|
|
3722
|
-
function createTableRelationsHelpers(sourceTable) {
|
|
3723
|
-
return {
|
|
3724
|
-
one: createOne(sourceTable),
|
|
3725
|
-
many: createMany(sourceTable)
|
|
3726
|
-
};
|
|
3727
|
-
}
|
|
3728
|
-
function mapRelationalRow(tablesConfig, tableConfig, row, buildQueryResultSelection, mapColumnValue = (value) => value) {
|
|
3729
|
-
const result = {};
|
|
3730
|
-
for (const [selectionItemIndex, selectionItem] of buildQueryResultSelection.entries()) if (selectionItem.isJson) {
|
|
3731
|
-
const relation = tableConfig.relations[selectionItem.tsKey];
|
|
3732
|
-
const rawSubRows = row[selectionItemIndex];
|
|
3733
|
-
const subRows = typeof rawSubRows === "string" ? JSON.parse(rawSubRows) : rawSubRows;
|
|
3734
|
-
result[selectionItem.tsKey] = is(relation, One) ? subRows && mapRelationalRow(tablesConfig, tablesConfig[selectionItem.relationTableTsKey], subRows, selectionItem.selection, mapColumnValue) : subRows.map((subRow) => mapRelationalRow(tablesConfig, tablesConfig[selectionItem.relationTableTsKey], subRow, selectionItem.selection, mapColumnValue));
|
|
3735
|
-
} else {
|
|
3736
|
-
const value = mapColumnValue(row[selectionItemIndex]);
|
|
3737
|
-
const field = selectionItem.field;
|
|
3738
|
-
let decoder;
|
|
3739
|
-
if (is(field, Column)) decoder = field;
|
|
3740
|
-
else if (is(field, SQL)) decoder = field.decoder;
|
|
3741
|
-
else decoder = field.sql.decoder;
|
|
3742
|
-
result[selectionItem.tsKey] = value === null ? null : decoder.mapFromDriverValue(value);
|
|
3743
|
-
}
|
|
3744
|
-
return result;
|
|
3745
|
-
}
|
|
3746
|
-
//#endregion
|
|
3747
|
-
//#region node_modules/hono/dist/helper/factory/index.js
|
|
3748
|
-
var createMiddleware = (middleware) => middleware;
|
|
3749
|
-
//#endregion
|
|
3750
|
-
//#region node_modules/hono/dist/utils/cookie.js
|
|
3751
|
-
var validCookieNameRegEx = /^[\w!#$%&'*.^`|~+-]+$/;
|
|
3752
|
-
var validCookieValueRegEx = /^[ !#-:<-[\]-~]*$/;
|
|
3753
|
-
var parse = (cookie, name) => {
|
|
3754
|
-
if (name && cookie.indexOf(name) === -1) return {};
|
|
3755
|
-
const pairs = cookie.trim().split(";");
|
|
3756
|
-
const parsedCookie = {};
|
|
3757
|
-
for (let pairStr of pairs) {
|
|
3758
|
-
pairStr = pairStr.trim();
|
|
3759
|
-
const valueStartPos = pairStr.indexOf("=");
|
|
3760
|
-
if (valueStartPos === -1) continue;
|
|
3761
|
-
const cookieName = pairStr.substring(0, valueStartPos).trim();
|
|
3762
|
-
if (name && name !== cookieName || !validCookieNameRegEx.test(cookieName)) continue;
|
|
3763
|
-
let cookieValue = pairStr.substring(valueStartPos + 1).trim();
|
|
3764
|
-
if (cookieValue.startsWith("\"") && cookieValue.endsWith("\"")) cookieValue = cookieValue.slice(1, -1);
|
|
3765
|
-
if (validCookieValueRegEx.test(cookieValue)) {
|
|
3766
|
-
parsedCookie[cookieName] = cookieValue.indexOf("%") !== -1 ? tryDecode(cookieValue, decodeURIComponent_) : cookieValue;
|
|
3767
|
-
if (name) break;
|
|
3768
|
-
}
|
|
3769
|
-
}
|
|
3770
|
-
return parsedCookie;
|
|
3771
|
-
};
|
|
3772
|
-
var _serialize = (name, value, opt = {}) => {
|
|
3773
|
-
let cookie = `${name}=${value}`;
|
|
3774
|
-
if (name.startsWith("__Secure-") && !opt.secure) throw new Error("__Secure- Cookie must have Secure attributes");
|
|
3775
|
-
if (name.startsWith("__Host-")) {
|
|
3776
|
-
if (!opt.secure) throw new Error("__Host- Cookie must have Secure attributes");
|
|
3777
|
-
if (opt.path !== "/") throw new Error("__Host- Cookie must have Path attributes with \"/\"");
|
|
3778
|
-
if (opt.domain) throw new Error("__Host- Cookie must not have Domain attributes");
|
|
3779
|
-
}
|
|
3780
|
-
if (opt && typeof opt.maxAge === "number" && opt.maxAge >= 0) {
|
|
3781
|
-
if (opt.maxAge > 3456e4) throw new Error("Cookies Max-Age SHOULD NOT be greater than 400 days (34560000 seconds) in duration.");
|
|
3782
|
-
cookie += `; Max-Age=${opt.maxAge | 0}`;
|
|
3783
|
-
}
|
|
3784
|
-
if (opt.domain && opt.prefix !== "host") cookie += `; Domain=${opt.domain}`;
|
|
3785
|
-
if (opt.path) cookie += `; Path=${opt.path}`;
|
|
3786
|
-
if (opt.expires) {
|
|
3787
|
-
if (opt.expires.getTime() - Date.now() > 3456e7) throw new Error("Cookies Expires SHOULD NOT be greater than 400 days (34560000 seconds) in the future.");
|
|
3788
|
-
cookie += `; Expires=${opt.expires.toUTCString()}`;
|
|
3789
|
-
}
|
|
3790
|
-
if (opt.httpOnly) cookie += "; HttpOnly";
|
|
3791
|
-
if (opt.secure) cookie += "; Secure";
|
|
3792
|
-
if (opt.sameSite) cookie += `; SameSite=${opt.sameSite.charAt(0).toUpperCase() + opt.sameSite.slice(1)}`;
|
|
3793
|
-
if (opt.priority) cookie += `; Priority=${opt.priority.charAt(0).toUpperCase() + opt.priority.slice(1)}`;
|
|
3794
|
-
if (opt.partitioned) {
|
|
3795
|
-
if (!opt.secure) throw new Error("Partitioned Cookie must have Secure attributes");
|
|
3796
|
-
cookie += "; Partitioned";
|
|
3797
|
-
}
|
|
3798
|
-
return cookie;
|
|
3799
|
-
};
|
|
3800
|
-
var serialize = (name, value, opt) => {
|
|
3801
|
-
value = encodeURIComponent(value);
|
|
3802
|
-
return _serialize(name, value, opt);
|
|
3803
|
-
};
|
|
3804
|
-
//#endregion
|
|
3805
|
-
//#region node_modules/hono/dist/helper/cookie/index.js
|
|
3806
|
-
var getCookie = (c, key, prefix) => {
|
|
3807
|
-
const cookie = c.req.raw.headers.get("Cookie");
|
|
3808
|
-
if (typeof key === "string") {
|
|
3809
|
-
if (!cookie) return;
|
|
3810
|
-
let finalKey = key;
|
|
3811
|
-
if (prefix === "secure") finalKey = "__Secure-" + key;
|
|
3812
|
-
else if (prefix === "host") finalKey = "__Host-" + key;
|
|
3813
|
-
return parse(cookie, finalKey)[finalKey];
|
|
3814
|
-
}
|
|
3815
|
-
if (!cookie) return {};
|
|
3816
|
-
return parse(cookie);
|
|
3817
|
-
};
|
|
3818
|
-
var generateCookie = (name, value, opt) => {
|
|
3819
|
-
let cookie;
|
|
3820
|
-
if (opt?.prefix === "secure") cookie = serialize("__Secure-" + name, value, {
|
|
3821
|
-
path: "/",
|
|
3822
|
-
...opt,
|
|
3823
|
-
secure: true
|
|
3824
|
-
});
|
|
3825
|
-
else if (opt?.prefix === "host") cookie = serialize("__Host-" + name, value, {
|
|
3826
|
-
...opt,
|
|
3827
|
-
path: "/",
|
|
3828
|
-
secure: true,
|
|
3829
|
-
domain: void 0
|
|
3830
|
-
});
|
|
3831
|
-
else cookie = serialize(name, value, {
|
|
3832
|
-
path: "/",
|
|
3833
|
-
...opt
|
|
3834
|
-
});
|
|
3835
|
-
return cookie;
|
|
3836
|
-
};
|
|
3837
|
-
var setCookie = (c, name, value, opt) => {
|
|
3838
|
-
const cookie = generateCookie(name, value, opt);
|
|
3839
|
-
c.header("Set-Cookie", cookie, { append: true });
|
|
3840
|
-
};
|
|
3841
|
-
var deleteCookie = (c, name, opt) => {
|
|
3842
|
-
const deletedCookie = getCookie(c, name, opt?.prefix);
|
|
3843
|
-
setCookie(c, name, "", {
|
|
3844
|
-
...opt,
|
|
3845
|
-
maxAge: 0
|
|
3846
|
-
});
|
|
3847
|
-
return deletedCookie;
|
|
3848
|
-
};
|
|
3849
|
-
//#endregion
|
|
3850
|
-
//#region node_modules/drizzle-orm/selection-proxy.js
|
|
3851
|
-
var SelectionProxyHandler = class SelectionProxyHandler {
|
|
3852
|
-
static [entityKind] = "SelectionProxyHandler";
|
|
3853
|
-
config;
|
|
3854
|
-
constructor(config) {
|
|
3855
|
-
this.config = { ...config };
|
|
3856
|
-
}
|
|
3857
|
-
get(subquery, prop) {
|
|
3858
|
-
if (prop === "_") return {
|
|
3859
|
-
...subquery["_"],
|
|
3860
|
-
selectedFields: new Proxy(subquery._.selectedFields, this)
|
|
3861
|
-
};
|
|
3862
|
-
if (prop === ViewBaseConfig) return {
|
|
3863
|
-
...subquery[ViewBaseConfig],
|
|
3864
|
-
selectedFields: new Proxy(subquery[ViewBaseConfig].selectedFields, this)
|
|
3865
|
-
};
|
|
3866
|
-
if (typeof prop === "symbol") return subquery[prop];
|
|
3867
|
-
const value = (is(subquery, Subquery) ? subquery._.selectedFields : is(subquery, View) ? subquery[ViewBaseConfig].selectedFields : subquery)[prop];
|
|
3868
|
-
if (is(value, SQL.Aliased)) {
|
|
3869
|
-
if (this.config.sqlAliasedBehavior === "sql" && !value.isSelectionField) return value.sql;
|
|
3870
|
-
const newValue = value.clone();
|
|
3871
|
-
newValue.isSelectionField = true;
|
|
3872
|
-
return newValue;
|
|
3873
|
-
}
|
|
3874
|
-
if (is(value, SQL)) {
|
|
3875
|
-
if (this.config.sqlBehavior === "sql") return value;
|
|
3876
|
-
throw new Error(`You tried to reference "${prop}" field from a subquery, which is a raw SQL field, but it doesn't have an alias declared. Please add an alias to the field using ".as('alias')" method.`);
|
|
3877
|
-
}
|
|
3878
|
-
if (is(value, Column)) {
|
|
3879
|
-
if (this.config.alias) return new Proxy(value, new ColumnAliasProxyHandler(new Proxy(value.table, new TableAliasProxyHandler(this.config.alias, this.config.replaceOriginalName ?? false))));
|
|
3880
|
-
return value;
|
|
3881
|
-
}
|
|
3882
|
-
if (typeof value !== "object" || value === null) return value;
|
|
3883
|
-
return new Proxy(value, new SelectionProxyHandler(this.config));
|
|
3884
|
-
}
|
|
3885
|
-
};
|
|
3886
|
-
//#endregion
|
|
3887
|
-
//#region node_modules/drizzle-orm/sqlite-core/foreign-keys.js
|
|
3888
|
-
var ForeignKeyBuilder = class {
|
|
3889
|
-
static [entityKind] = "SQLiteForeignKeyBuilder";
|
|
3890
|
-
/** @internal */
|
|
3891
|
-
reference;
|
|
3892
|
-
/** @internal */
|
|
3893
|
-
_onUpdate;
|
|
3894
|
-
/** @internal */
|
|
3895
|
-
_onDelete;
|
|
3896
|
-
constructor(config, actions) {
|
|
3897
|
-
this.reference = () => {
|
|
3898
|
-
const { name, columns, foreignColumns } = config();
|
|
3899
|
-
return {
|
|
3900
|
-
name,
|
|
3901
|
-
columns,
|
|
3902
|
-
foreignTable: foreignColumns[0].table,
|
|
3903
|
-
foreignColumns
|
|
3904
|
-
};
|
|
3905
|
-
};
|
|
3906
|
-
if (actions) {
|
|
3907
|
-
this._onUpdate = actions.onUpdate;
|
|
3908
|
-
this._onDelete = actions.onDelete;
|
|
3909
|
-
}
|
|
3910
|
-
}
|
|
3911
|
-
onUpdate(action) {
|
|
3912
|
-
this._onUpdate = action;
|
|
3913
|
-
return this;
|
|
3914
|
-
}
|
|
3915
|
-
onDelete(action) {
|
|
3916
|
-
this._onDelete = action;
|
|
3917
|
-
return this;
|
|
3918
|
-
}
|
|
3919
|
-
/** @internal */
|
|
3920
|
-
build(table) {
|
|
3921
|
-
return new ForeignKey(table, this);
|
|
3922
|
-
}
|
|
3923
|
-
};
|
|
3924
|
-
var ForeignKey = class {
|
|
3925
|
-
constructor(table, builder) {
|
|
3926
|
-
this.table = table;
|
|
3927
|
-
this.reference = builder.reference;
|
|
3928
|
-
this.onUpdate = builder._onUpdate;
|
|
3929
|
-
this.onDelete = builder._onDelete;
|
|
3930
|
-
}
|
|
3931
|
-
static [entityKind] = "SQLiteForeignKey";
|
|
3932
|
-
reference;
|
|
3933
|
-
onUpdate;
|
|
3934
|
-
onDelete;
|
|
3935
|
-
getName() {
|
|
3936
|
-
const { name, columns, foreignColumns } = this.reference();
|
|
3937
|
-
const columnNames = columns.map((column) => column.name);
|
|
3938
|
-
const foreignColumnNames = foreignColumns.map((column) => column.name);
|
|
3939
|
-
const chunks = [
|
|
3940
|
-
this.table[TableName],
|
|
3941
|
-
...columnNames,
|
|
3942
|
-
foreignColumns[0].table[TableName],
|
|
3943
|
-
...foreignColumnNames
|
|
3944
|
-
];
|
|
3945
|
-
return name ?? `${chunks.join("_")}_fk`;
|
|
3946
|
-
}
|
|
3947
|
-
};
|
|
3948
|
-
//#endregion
|
|
3949
|
-
//#region node_modules/drizzle-orm/sqlite-core/unique-constraint.js
|
|
3950
|
-
function uniqueKeyName(table, columns) {
|
|
3951
|
-
return `${table[TableName]}_${columns.join("_")}_unique`;
|
|
3952
|
-
}
|
|
3953
|
-
//#endregion
|
|
3954
|
-
//#region node_modules/drizzle-orm/sqlite-core/columns/common.js
|
|
3955
|
-
var SQLiteColumnBuilder = class extends ColumnBuilder {
|
|
3956
|
-
static [entityKind] = "SQLiteColumnBuilder";
|
|
3957
|
-
foreignKeyConfigs = [];
|
|
3958
|
-
references(ref, actions = {}) {
|
|
3959
|
-
this.foreignKeyConfigs.push({
|
|
3960
|
-
ref,
|
|
3961
|
-
actions
|
|
3962
|
-
});
|
|
3963
|
-
return this;
|
|
3964
|
-
}
|
|
3965
|
-
unique(name) {
|
|
3966
|
-
this.config.isUnique = true;
|
|
3967
|
-
this.config.uniqueName = name;
|
|
3968
|
-
return this;
|
|
3969
|
-
}
|
|
3970
|
-
generatedAlwaysAs(as, config) {
|
|
3971
|
-
this.config.generated = {
|
|
3972
|
-
as,
|
|
3973
|
-
type: "always",
|
|
3974
|
-
mode: config?.mode ?? "virtual"
|
|
3975
|
-
};
|
|
3976
|
-
return this;
|
|
3977
|
-
}
|
|
3978
|
-
/** @internal */
|
|
3979
|
-
buildForeignKeys(column, table) {
|
|
3980
|
-
return this.foreignKeyConfigs.map(({ ref, actions }) => {
|
|
3981
|
-
return ((ref2, actions2) => {
|
|
3982
|
-
const builder = new ForeignKeyBuilder(() => {
|
|
3983
|
-
const foreignColumn = ref2();
|
|
3984
|
-
return {
|
|
3985
|
-
columns: [column],
|
|
3986
|
-
foreignColumns: [foreignColumn]
|
|
3987
|
-
};
|
|
3988
|
-
});
|
|
3989
|
-
if (actions2.onUpdate) builder.onUpdate(actions2.onUpdate);
|
|
3990
|
-
if (actions2.onDelete) builder.onDelete(actions2.onDelete);
|
|
3991
|
-
return builder.build(table);
|
|
3992
|
-
})(ref, actions);
|
|
3993
|
-
});
|
|
3994
|
-
}
|
|
3995
|
-
};
|
|
3996
|
-
var SQLiteColumn = class extends Column {
|
|
3997
|
-
constructor(table, config) {
|
|
3998
|
-
if (!config.uniqueName) config.uniqueName = uniqueKeyName(table, [config.name]);
|
|
3999
|
-
super(table, config);
|
|
4000
|
-
this.table = table;
|
|
4001
|
-
}
|
|
4002
|
-
static [entityKind] = "SQLiteColumn";
|
|
4003
|
-
};
|
|
4004
|
-
//#endregion
|
|
4005
|
-
//#region node_modules/drizzle-orm/sqlite-core/columns/blob.js
|
|
4006
|
-
var SQLiteBigIntBuilder = class extends SQLiteColumnBuilder {
|
|
4007
|
-
static [entityKind] = "SQLiteBigIntBuilder";
|
|
4008
|
-
constructor(name) {
|
|
4009
|
-
super(name, "bigint", "SQLiteBigInt");
|
|
4010
|
-
}
|
|
4011
|
-
/** @internal */
|
|
4012
|
-
build(table) {
|
|
4013
|
-
return new SQLiteBigInt(table, this.config);
|
|
4014
|
-
}
|
|
4015
|
-
};
|
|
4016
|
-
var SQLiteBigInt = class extends SQLiteColumn {
|
|
4017
|
-
static [entityKind] = "SQLiteBigInt";
|
|
4018
|
-
getSQLType() {
|
|
4019
|
-
return "blob";
|
|
4020
|
-
}
|
|
4021
|
-
mapFromDriverValue(value) {
|
|
4022
|
-
if (typeof Buffer !== "undefined" && Buffer.from) {
|
|
4023
|
-
const buf = Buffer.isBuffer(value) ? value : value instanceof ArrayBuffer ? Buffer.from(value) : value.buffer ? Buffer.from(value.buffer, value.byteOffset, value.byteLength) : Buffer.from(value);
|
|
4024
|
-
return BigInt(buf.toString("utf8"));
|
|
4025
|
-
}
|
|
4026
|
-
return BigInt(textDecoder.decode(value));
|
|
4027
|
-
}
|
|
4028
|
-
mapToDriverValue(value) {
|
|
4029
|
-
return Buffer.from(value.toString());
|
|
4030
|
-
}
|
|
4031
|
-
};
|
|
4032
|
-
var SQLiteBlobJsonBuilder = class extends SQLiteColumnBuilder {
|
|
4033
|
-
static [entityKind] = "SQLiteBlobJsonBuilder";
|
|
4034
|
-
constructor(name) {
|
|
4035
|
-
super(name, "json", "SQLiteBlobJson");
|
|
4036
|
-
}
|
|
4037
|
-
/** @internal */
|
|
4038
|
-
build(table) {
|
|
4039
|
-
return new SQLiteBlobJson(table, this.config);
|
|
4040
|
-
}
|
|
4041
|
-
};
|
|
4042
|
-
var SQLiteBlobJson = class extends SQLiteColumn {
|
|
4043
|
-
static [entityKind] = "SQLiteBlobJson";
|
|
4044
|
-
getSQLType() {
|
|
4045
|
-
return "blob";
|
|
4046
|
-
}
|
|
4047
|
-
mapFromDriverValue(value) {
|
|
4048
|
-
if (typeof Buffer !== "undefined" && Buffer.from) {
|
|
4049
|
-
const buf = Buffer.isBuffer(value) ? value : value instanceof ArrayBuffer ? Buffer.from(value) : value.buffer ? Buffer.from(value.buffer, value.byteOffset, value.byteLength) : Buffer.from(value);
|
|
4050
|
-
return JSON.parse(buf.toString("utf8"));
|
|
4051
|
-
}
|
|
4052
|
-
return JSON.parse(textDecoder.decode(value));
|
|
4053
|
-
}
|
|
4054
|
-
mapToDriverValue(value) {
|
|
4055
|
-
return Buffer.from(JSON.stringify(value));
|
|
4056
|
-
}
|
|
4057
|
-
};
|
|
4058
|
-
var SQLiteBlobBufferBuilder = class extends SQLiteColumnBuilder {
|
|
4059
|
-
static [entityKind] = "SQLiteBlobBufferBuilder";
|
|
4060
|
-
constructor(name) {
|
|
4061
|
-
super(name, "buffer", "SQLiteBlobBuffer");
|
|
4062
|
-
}
|
|
4063
|
-
/** @internal */
|
|
4064
|
-
build(table) {
|
|
4065
|
-
return new SQLiteBlobBuffer(table, this.config);
|
|
4066
|
-
}
|
|
4067
|
-
};
|
|
4068
|
-
var SQLiteBlobBuffer = class extends SQLiteColumn {
|
|
4069
|
-
static [entityKind] = "SQLiteBlobBuffer";
|
|
4070
|
-
mapFromDriverValue(value) {
|
|
4071
|
-
if (Buffer.isBuffer(value)) return value;
|
|
4072
|
-
return Buffer.from(value);
|
|
4073
|
-
}
|
|
4074
|
-
getSQLType() {
|
|
4075
|
-
return "blob";
|
|
4076
|
-
}
|
|
4077
|
-
};
|
|
4078
|
-
function blob(a, b) {
|
|
4079
|
-
const { name, config } = getColumnNameAndConfig(a, b);
|
|
4080
|
-
if (config?.mode === "json") return new SQLiteBlobJsonBuilder(name);
|
|
4081
|
-
if (config?.mode === "bigint") return new SQLiteBigIntBuilder(name);
|
|
4082
|
-
return new SQLiteBlobBufferBuilder(name);
|
|
4083
|
-
}
|
|
4084
|
-
//#endregion
|
|
4085
|
-
//#region node_modules/drizzle-orm/sqlite-core/columns/custom.js
|
|
4086
|
-
var SQLiteCustomColumnBuilder = class extends SQLiteColumnBuilder {
|
|
4087
|
-
static [entityKind] = "SQLiteCustomColumnBuilder";
|
|
4088
|
-
constructor(name, fieldConfig, customTypeParams) {
|
|
4089
|
-
super(name, "custom", "SQLiteCustomColumn");
|
|
4090
|
-
this.config.fieldConfig = fieldConfig;
|
|
4091
|
-
this.config.customTypeParams = customTypeParams;
|
|
4092
|
-
}
|
|
4093
|
-
/** @internal */
|
|
4094
|
-
build(table) {
|
|
4095
|
-
return new SQLiteCustomColumn(table, this.config);
|
|
4096
|
-
}
|
|
4097
|
-
};
|
|
4098
|
-
var SQLiteCustomColumn = class extends SQLiteColumn {
|
|
4099
|
-
static [entityKind] = "SQLiteCustomColumn";
|
|
4100
|
-
sqlName;
|
|
4101
|
-
mapTo;
|
|
4102
|
-
mapFrom;
|
|
4103
|
-
constructor(table, config) {
|
|
4104
|
-
super(table, config);
|
|
4105
|
-
this.sqlName = config.customTypeParams.dataType(config.fieldConfig);
|
|
4106
|
-
this.mapTo = config.customTypeParams.toDriver;
|
|
4107
|
-
this.mapFrom = config.customTypeParams.fromDriver;
|
|
4108
|
-
}
|
|
4109
|
-
getSQLType() {
|
|
4110
|
-
return this.sqlName;
|
|
4111
|
-
}
|
|
4112
|
-
mapFromDriverValue(value) {
|
|
4113
|
-
return typeof this.mapFrom === "function" ? this.mapFrom(value) : value;
|
|
4114
|
-
}
|
|
4115
|
-
mapToDriverValue(value) {
|
|
4116
|
-
return typeof this.mapTo === "function" ? this.mapTo(value) : value;
|
|
4117
|
-
}
|
|
4118
|
-
};
|
|
4119
|
-
function customType(customTypeParams) {
|
|
4120
|
-
return (a, b) => {
|
|
4121
|
-
const { name, config } = getColumnNameAndConfig(a, b);
|
|
4122
|
-
return new SQLiteCustomColumnBuilder(name, config, customTypeParams);
|
|
4123
|
-
};
|
|
4124
|
-
}
|
|
4125
|
-
//#endregion
|
|
4126
|
-
//#region node_modules/drizzle-orm/sqlite-core/columns/integer.js
|
|
4127
|
-
var SQLiteBaseIntegerBuilder = class extends SQLiteColumnBuilder {
|
|
4128
|
-
static [entityKind] = "SQLiteBaseIntegerBuilder";
|
|
4129
|
-
constructor(name, dataType, columnType) {
|
|
4130
|
-
super(name, dataType, columnType);
|
|
4131
|
-
this.config.autoIncrement = false;
|
|
4132
|
-
}
|
|
4133
|
-
primaryKey(config) {
|
|
4134
|
-
if (config?.autoIncrement) this.config.autoIncrement = true;
|
|
4135
|
-
this.config.hasDefault = true;
|
|
4136
|
-
return super.primaryKey();
|
|
4137
|
-
}
|
|
4138
|
-
};
|
|
4139
|
-
var SQLiteBaseInteger = class extends SQLiteColumn {
|
|
4140
|
-
static [entityKind] = "SQLiteBaseInteger";
|
|
4141
|
-
autoIncrement = this.config.autoIncrement;
|
|
4142
|
-
getSQLType() {
|
|
4143
|
-
return "integer";
|
|
4144
|
-
}
|
|
4145
|
-
};
|
|
4146
|
-
var SQLiteIntegerBuilder = class extends SQLiteBaseIntegerBuilder {
|
|
4147
|
-
static [entityKind] = "SQLiteIntegerBuilder";
|
|
4148
|
-
constructor(name) {
|
|
4149
|
-
super(name, "number", "SQLiteInteger");
|
|
4150
|
-
}
|
|
4151
|
-
build(table) {
|
|
4152
|
-
return new SQLiteInteger(table, this.config);
|
|
4153
|
-
}
|
|
4154
|
-
};
|
|
4155
|
-
var SQLiteInteger = class extends SQLiteBaseInteger {
|
|
4156
|
-
static [entityKind] = "SQLiteInteger";
|
|
4157
|
-
};
|
|
4158
|
-
var SQLiteTimestampBuilder = class extends SQLiteBaseIntegerBuilder {
|
|
4159
|
-
static [entityKind] = "SQLiteTimestampBuilder";
|
|
4160
|
-
constructor(name, mode) {
|
|
4161
|
-
super(name, "date", "SQLiteTimestamp");
|
|
4162
|
-
this.config.mode = mode;
|
|
4163
|
-
}
|
|
4164
|
-
/**
|
|
4165
|
-
* @deprecated Use `default()` with your own expression instead.
|
|
4166
|
-
*
|
|
4167
|
-
* Adds `DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer))` to the column, which is the current epoch timestamp in milliseconds.
|
|
4168
|
-
*/
|
|
4169
|
-
defaultNow() {
|
|
4170
|
-
return this.default(sql`(cast((julianday('now') - 2440587.5)*86400000 as integer))`);
|
|
4171
|
-
}
|
|
4172
|
-
build(table) {
|
|
4173
|
-
return new SQLiteTimestamp(table, this.config);
|
|
4174
|
-
}
|
|
4175
|
-
};
|
|
4176
|
-
var SQLiteTimestamp = class extends SQLiteBaseInteger {
|
|
4177
|
-
static [entityKind] = "SQLiteTimestamp";
|
|
4178
|
-
mode = this.config.mode;
|
|
4179
|
-
mapFromDriverValue(value) {
|
|
4180
|
-
if (this.config.mode === "timestamp") return /* @__PURE__ */ new Date(value * 1e3);
|
|
4181
|
-
return new Date(value);
|
|
4182
|
-
}
|
|
4183
|
-
mapToDriverValue(value) {
|
|
4184
|
-
const unix = value.getTime();
|
|
4185
|
-
if (this.config.mode === "timestamp") return Math.floor(unix / 1e3);
|
|
4186
|
-
return unix;
|
|
4187
|
-
}
|
|
4188
|
-
};
|
|
4189
|
-
var SQLiteBooleanBuilder = class extends SQLiteBaseIntegerBuilder {
|
|
4190
|
-
static [entityKind] = "SQLiteBooleanBuilder";
|
|
4191
|
-
constructor(name, mode) {
|
|
4192
|
-
super(name, "boolean", "SQLiteBoolean");
|
|
4193
|
-
this.config.mode = mode;
|
|
4194
|
-
}
|
|
4195
|
-
build(table) {
|
|
4196
|
-
return new SQLiteBoolean(table, this.config);
|
|
4197
|
-
}
|
|
4198
|
-
};
|
|
4199
|
-
var SQLiteBoolean = class extends SQLiteBaseInteger {
|
|
4200
|
-
static [entityKind] = "SQLiteBoolean";
|
|
4201
|
-
mode = this.config.mode;
|
|
4202
|
-
mapFromDriverValue(value) {
|
|
4203
|
-
return Number(value) === 1;
|
|
4204
|
-
}
|
|
4205
|
-
mapToDriverValue(value) {
|
|
4206
|
-
return value ? 1 : 0;
|
|
4207
|
-
}
|
|
4208
|
-
};
|
|
4209
|
-
function integer(a, b) {
|
|
4210
|
-
const { name, config } = getColumnNameAndConfig(a, b);
|
|
4211
|
-
if (config?.mode === "timestamp" || config?.mode === "timestamp_ms") return new SQLiteTimestampBuilder(name, config.mode);
|
|
4212
|
-
if (config?.mode === "boolean") return new SQLiteBooleanBuilder(name, config.mode);
|
|
4213
|
-
return new SQLiteIntegerBuilder(name);
|
|
4214
|
-
}
|
|
4215
|
-
//#endregion
|
|
4216
|
-
//#region node_modules/drizzle-orm/sqlite-core/columns/numeric.js
|
|
4217
|
-
var SQLiteNumericBuilder = class extends SQLiteColumnBuilder {
|
|
4218
|
-
static [entityKind] = "SQLiteNumericBuilder";
|
|
4219
|
-
constructor(name) {
|
|
4220
|
-
super(name, "string", "SQLiteNumeric");
|
|
4221
|
-
}
|
|
4222
|
-
/** @internal */
|
|
4223
|
-
build(table) {
|
|
4224
|
-
return new SQLiteNumeric(table, this.config);
|
|
4225
|
-
}
|
|
4226
|
-
};
|
|
4227
|
-
var SQLiteNumeric = class extends SQLiteColumn {
|
|
4228
|
-
static [entityKind] = "SQLiteNumeric";
|
|
4229
|
-
mapFromDriverValue(value) {
|
|
4230
|
-
if (typeof value === "string") return value;
|
|
4231
|
-
return String(value);
|
|
4232
|
-
}
|
|
4233
|
-
getSQLType() {
|
|
4234
|
-
return "numeric";
|
|
4235
|
-
}
|
|
4236
|
-
};
|
|
4237
|
-
var SQLiteNumericNumberBuilder = class extends SQLiteColumnBuilder {
|
|
4238
|
-
static [entityKind] = "SQLiteNumericNumberBuilder";
|
|
4239
|
-
constructor(name) {
|
|
4240
|
-
super(name, "number", "SQLiteNumericNumber");
|
|
4241
|
-
}
|
|
4242
|
-
/** @internal */
|
|
4243
|
-
build(table) {
|
|
4244
|
-
return new SQLiteNumericNumber(table, this.config);
|
|
4245
|
-
}
|
|
4246
|
-
};
|
|
4247
|
-
var SQLiteNumericNumber = class extends SQLiteColumn {
|
|
4248
|
-
static [entityKind] = "SQLiteNumericNumber";
|
|
4249
|
-
mapFromDriverValue(value) {
|
|
4250
|
-
if (typeof value === "number") return value;
|
|
4251
|
-
return Number(value);
|
|
4252
|
-
}
|
|
4253
|
-
mapToDriverValue = String;
|
|
4254
|
-
getSQLType() {
|
|
4255
|
-
return "numeric";
|
|
4256
|
-
}
|
|
4257
|
-
};
|
|
4258
|
-
var SQLiteNumericBigIntBuilder = class extends SQLiteColumnBuilder {
|
|
4259
|
-
static [entityKind] = "SQLiteNumericBigIntBuilder";
|
|
4260
|
-
constructor(name) {
|
|
4261
|
-
super(name, "bigint", "SQLiteNumericBigInt");
|
|
4262
|
-
}
|
|
4263
|
-
/** @internal */
|
|
4264
|
-
build(table) {
|
|
4265
|
-
return new SQLiteNumericBigInt(table, this.config);
|
|
4266
|
-
}
|
|
4267
|
-
};
|
|
4268
|
-
var SQLiteNumericBigInt = class extends SQLiteColumn {
|
|
4269
|
-
static [entityKind] = "SQLiteNumericBigInt";
|
|
4270
|
-
mapFromDriverValue = BigInt;
|
|
4271
|
-
mapToDriverValue = String;
|
|
4272
|
-
getSQLType() {
|
|
4273
|
-
return "numeric";
|
|
4274
|
-
}
|
|
4275
|
-
};
|
|
4276
|
-
function numeric(a, b) {
|
|
4277
|
-
const { name, config } = getColumnNameAndConfig(a, b);
|
|
4278
|
-
const mode = config?.mode;
|
|
4279
|
-
return mode === "number" ? new SQLiteNumericNumberBuilder(name) : mode === "bigint" ? new SQLiteNumericBigIntBuilder(name) : new SQLiteNumericBuilder(name);
|
|
4280
|
-
}
|
|
4281
|
-
//#endregion
|
|
4282
|
-
//#region node_modules/drizzle-orm/sqlite-core/columns/real.js
|
|
4283
|
-
var SQLiteRealBuilder = class extends SQLiteColumnBuilder {
|
|
4284
|
-
static [entityKind] = "SQLiteRealBuilder";
|
|
4285
|
-
constructor(name) {
|
|
4286
|
-
super(name, "number", "SQLiteReal");
|
|
4287
|
-
}
|
|
4288
|
-
/** @internal */
|
|
4289
|
-
build(table) {
|
|
4290
|
-
return new SQLiteReal(table, this.config);
|
|
4291
|
-
}
|
|
4292
|
-
};
|
|
4293
|
-
var SQLiteReal = class extends SQLiteColumn {
|
|
4294
|
-
static [entityKind] = "SQLiteReal";
|
|
4295
|
-
getSQLType() {
|
|
4296
|
-
return "real";
|
|
4297
|
-
}
|
|
4298
|
-
};
|
|
4299
|
-
function real(name) {
|
|
4300
|
-
return new SQLiteRealBuilder(name ?? "");
|
|
4301
|
-
}
|
|
4302
|
-
//#endregion
|
|
4303
|
-
//#region node_modules/drizzle-orm/sqlite-core/columns/text.js
|
|
4304
|
-
var SQLiteTextBuilder = class extends SQLiteColumnBuilder {
|
|
4305
|
-
static [entityKind] = "SQLiteTextBuilder";
|
|
4306
|
-
constructor(name, config) {
|
|
4307
|
-
super(name, "string", "SQLiteText");
|
|
4308
|
-
this.config.enumValues = config.enum;
|
|
4309
|
-
this.config.length = config.length;
|
|
4310
|
-
}
|
|
4311
|
-
/** @internal */
|
|
4312
|
-
build(table) {
|
|
4313
|
-
return new SQLiteText(table, this.config);
|
|
4314
|
-
}
|
|
4315
|
-
};
|
|
4316
|
-
var SQLiteText = class extends SQLiteColumn {
|
|
4317
|
-
static [entityKind] = "SQLiteText";
|
|
4318
|
-
enumValues = this.config.enumValues;
|
|
4319
|
-
length = this.config.length;
|
|
4320
|
-
constructor(table, config) {
|
|
4321
|
-
super(table, config);
|
|
4322
|
-
}
|
|
4323
|
-
getSQLType() {
|
|
4324
|
-
return `text${this.config.length ? `(${this.config.length})` : ""}`;
|
|
4325
|
-
}
|
|
4326
|
-
};
|
|
4327
|
-
var SQLiteTextJsonBuilder = class extends SQLiteColumnBuilder {
|
|
4328
|
-
static [entityKind] = "SQLiteTextJsonBuilder";
|
|
4329
|
-
constructor(name) {
|
|
4330
|
-
super(name, "json", "SQLiteTextJson");
|
|
4331
|
-
}
|
|
4332
|
-
/** @internal */
|
|
4333
|
-
build(table) {
|
|
4334
|
-
return new SQLiteTextJson(table, this.config);
|
|
4335
|
-
}
|
|
4336
|
-
};
|
|
4337
|
-
var SQLiteTextJson = class extends SQLiteColumn {
|
|
4338
|
-
static [entityKind] = "SQLiteTextJson";
|
|
4339
|
-
getSQLType() {
|
|
4340
|
-
return "text";
|
|
4341
|
-
}
|
|
4342
|
-
mapFromDriverValue(value) {
|
|
4343
|
-
return JSON.parse(value);
|
|
4344
|
-
}
|
|
4345
|
-
mapToDriverValue(value) {
|
|
4346
|
-
return JSON.stringify(value);
|
|
4347
|
-
}
|
|
4348
|
-
};
|
|
4349
|
-
function text(a, b = {}) {
|
|
4350
|
-
const { name, config } = getColumnNameAndConfig(a, b);
|
|
4351
|
-
if (config.mode === "json") return new SQLiteTextJsonBuilder(name);
|
|
4352
|
-
return new SQLiteTextBuilder(name, config);
|
|
4353
|
-
}
|
|
4354
|
-
//#endregion
|
|
4355
|
-
//#region node_modules/drizzle-orm/sqlite-core/columns/all.js
|
|
4356
|
-
function getSQLiteColumnBuilders() {
|
|
4357
|
-
return {
|
|
4358
|
-
blob,
|
|
4359
|
-
customType,
|
|
4360
|
-
integer,
|
|
4361
|
-
numeric,
|
|
4362
|
-
real,
|
|
4363
|
-
text
|
|
4364
|
-
};
|
|
4365
|
-
}
|
|
4366
|
-
//#endregion
|
|
4367
|
-
//#region node_modules/drizzle-orm/sqlite-core/table.js
|
|
4368
|
-
const InlineForeignKeys = Symbol.for("drizzle:SQLiteInlineForeignKeys");
|
|
4369
|
-
var SQLiteTable = class extends Table {
|
|
4370
|
-
static [entityKind] = "SQLiteTable";
|
|
4371
|
-
/** @internal */
|
|
4372
|
-
static Symbol = Object.assign({}, Table.Symbol, { InlineForeignKeys });
|
|
4373
|
-
/** @internal */
|
|
4374
|
-
[Table.Symbol.Columns];
|
|
4375
|
-
/** @internal */
|
|
4376
|
-
[InlineForeignKeys] = [];
|
|
4377
|
-
/** @internal */
|
|
4378
|
-
[Table.Symbol.ExtraConfigBuilder] = void 0;
|
|
4379
|
-
};
|
|
4380
|
-
function sqliteTableBase(name, columns, extraConfig, schema, baseName = name) {
|
|
4381
|
-
const rawTable = new SQLiteTable(name, schema, baseName);
|
|
4382
|
-
const parsedColumns = typeof columns === "function" ? columns(getSQLiteColumnBuilders()) : columns;
|
|
4383
|
-
const builtColumns = Object.fromEntries(Object.entries(parsedColumns).map(([name2, colBuilderBase]) => {
|
|
4384
|
-
const colBuilder = colBuilderBase;
|
|
4385
|
-
colBuilder.setName(name2);
|
|
4386
|
-
const column = colBuilder.build(rawTable);
|
|
4387
|
-
rawTable[InlineForeignKeys].push(...colBuilder.buildForeignKeys(column, rawTable));
|
|
4388
|
-
return [name2, column];
|
|
4389
|
-
}));
|
|
4390
|
-
const table = Object.assign(rawTable, builtColumns);
|
|
4391
|
-
table[Table.Symbol.Columns] = builtColumns;
|
|
4392
|
-
table[Table.Symbol.ExtraConfigColumns] = builtColumns;
|
|
4393
|
-
if (extraConfig) table[SQLiteTable.Symbol.ExtraConfigBuilder] = extraConfig;
|
|
4394
|
-
return table;
|
|
4395
|
-
}
|
|
4396
|
-
const sqliteTable = (name, columns, extraConfig) => {
|
|
4397
|
-
return sqliteTableBase(name, columns, extraConfig);
|
|
4398
|
-
};
|
|
4399
|
-
//#endregion
|
|
4400
|
-
//#region node_modules/drizzle-orm/sqlite-core/indexes.js
|
|
4401
|
-
var IndexBuilderOn = class {
|
|
4402
|
-
constructor(name, unique) {
|
|
4403
|
-
this.name = name;
|
|
4404
|
-
this.unique = unique;
|
|
4405
|
-
}
|
|
4406
|
-
static [entityKind] = "SQLiteIndexBuilderOn";
|
|
4407
|
-
on(...columns) {
|
|
4408
|
-
return new IndexBuilder(this.name, columns, this.unique);
|
|
4409
|
-
}
|
|
4410
|
-
};
|
|
4411
|
-
var IndexBuilder = class {
|
|
4412
|
-
static [entityKind] = "SQLiteIndexBuilder";
|
|
4413
|
-
/** @internal */
|
|
4414
|
-
config;
|
|
4415
|
-
constructor(name, columns, unique) {
|
|
4416
|
-
this.config = {
|
|
4417
|
-
name,
|
|
4418
|
-
columns,
|
|
4419
|
-
unique,
|
|
4420
|
-
where: void 0
|
|
4421
|
-
};
|
|
4422
|
-
}
|
|
4423
|
-
/**
|
|
4424
|
-
* Condition for partial index.
|
|
4425
|
-
*/
|
|
4426
|
-
where(condition) {
|
|
4427
|
-
this.config.where = condition;
|
|
4428
|
-
return this;
|
|
4429
|
-
}
|
|
4430
|
-
/** @internal */
|
|
4431
|
-
build(table) {
|
|
4432
|
-
return new Index(this.config, table);
|
|
4433
|
-
}
|
|
4434
|
-
};
|
|
4435
|
-
var Index = class {
|
|
4436
|
-
static [entityKind] = "SQLiteIndex";
|
|
4437
|
-
config;
|
|
4438
|
-
constructor(config, table) {
|
|
4439
|
-
this.config = {
|
|
4440
|
-
...config,
|
|
4441
|
-
table
|
|
4442
|
-
};
|
|
4443
|
-
}
|
|
4444
|
-
};
|
|
4445
|
-
function uniqueIndex(name) {
|
|
4446
|
-
return new IndexBuilderOn(name, true);
|
|
4447
|
-
}
|
|
4448
|
-
//#endregion
|
|
4449
|
-
//#region node_modules/drizzle-orm/sqlite-core/utils.js
|
|
4450
|
-
function extractUsedTable(table) {
|
|
4451
|
-
if (is(table, SQLiteTable)) return [`${table[Table.Symbol.BaseName]}`];
|
|
4452
|
-
if (is(table, Subquery)) return table._.usedTables ?? [];
|
|
4453
|
-
if (is(table, SQL)) return table.usedTables ?? [];
|
|
4454
|
-
return [];
|
|
4455
|
-
}
|
|
4456
|
-
//#endregion
|
|
4457
|
-
//#region node_modules/drizzle-orm/sqlite-core/query-builders/delete.js
|
|
4458
|
-
var SQLiteDeleteBase = class extends QueryPromise {
|
|
4459
|
-
constructor(table, session, dialect, withList) {
|
|
4460
|
-
super();
|
|
4461
|
-
this.table = table;
|
|
4462
|
-
this.session = session;
|
|
4463
|
-
this.dialect = dialect;
|
|
4464
|
-
this.config = {
|
|
4465
|
-
table,
|
|
4466
|
-
withList
|
|
4467
|
-
};
|
|
4468
|
-
}
|
|
4469
|
-
static [entityKind] = "SQLiteDelete";
|
|
4470
|
-
/** @internal */
|
|
4471
|
-
config;
|
|
4472
|
-
/**
|
|
4473
|
-
* Adds a `where` clause to the query.
|
|
4474
|
-
*
|
|
4475
|
-
* Calling this method will delete only those rows that fulfill a specified condition.
|
|
4476
|
-
*
|
|
4477
|
-
* See docs: {@link https://orm.drizzle.team/docs/delete}
|
|
4478
|
-
*
|
|
4479
|
-
* @param where the `where` clause.
|
|
4480
|
-
*
|
|
4481
|
-
* @example
|
|
4482
|
-
* You can use conditional operators and `sql function` to filter the rows to be deleted.
|
|
4483
|
-
*
|
|
4484
|
-
* ```ts
|
|
4485
|
-
* // Delete all cars with green color
|
|
4486
|
-
* db.delete(cars).where(eq(cars.color, 'green'));
|
|
4487
|
-
* // or
|
|
4488
|
-
* db.delete(cars).where(sql`${cars.color} = 'green'`)
|
|
4489
|
-
* ```
|
|
4490
|
-
*
|
|
4491
|
-
* You can logically combine conditional operators with `and()` and `or()` operators:
|
|
4492
|
-
*
|
|
4493
|
-
* ```ts
|
|
4494
|
-
* // Delete all BMW cars with a green color
|
|
4495
|
-
* db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
|
4496
|
-
*
|
|
4497
|
-
* // Delete all cars with the green or blue color
|
|
4498
|
-
* db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
|
4499
|
-
* ```
|
|
4500
|
-
*/
|
|
4501
|
-
where(where) {
|
|
4502
|
-
this.config.where = where;
|
|
4503
|
-
return this;
|
|
4504
|
-
}
|
|
4505
|
-
orderBy(...columns) {
|
|
4506
|
-
if (typeof columns[0] === "function") {
|
|
4507
|
-
const orderBy = columns[0](new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
|
|
4508
|
-
sqlAliasedBehavior: "alias",
|
|
4509
|
-
sqlBehavior: "sql"
|
|
4510
|
-
})));
|
|
4511
|
-
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
|
4512
|
-
this.config.orderBy = orderByArray;
|
|
4513
|
-
} else {
|
|
4514
|
-
const orderByArray = columns;
|
|
4515
|
-
this.config.orderBy = orderByArray;
|
|
4516
|
-
}
|
|
4517
|
-
return this;
|
|
4518
|
-
}
|
|
4519
|
-
limit(limit) {
|
|
4520
|
-
this.config.limit = limit;
|
|
4521
|
-
return this;
|
|
4522
|
-
}
|
|
4523
|
-
returning(fields = this.table[SQLiteTable.Symbol.Columns]) {
|
|
4524
|
-
this.config.returning = orderSelectedFields(fields);
|
|
4525
|
-
return this;
|
|
4526
|
-
}
|
|
4527
|
-
/** @internal */
|
|
4528
|
-
getSQL() {
|
|
4529
|
-
return this.dialect.buildDeleteQuery(this.config);
|
|
4530
|
-
}
|
|
4531
|
-
toSQL() {
|
|
4532
|
-
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
|
4533
|
-
return rest;
|
|
4534
|
-
}
|
|
4535
|
-
/** @internal */
|
|
4536
|
-
_prepare(isOneTimeQuery = true) {
|
|
4537
|
-
return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](this.dialect.sqlToQuery(this.getSQL()), this.config.returning, this.config.returning ? "all" : "run", true, void 0, {
|
|
4538
|
-
type: "delete",
|
|
4539
|
-
tables: extractUsedTable(this.config.table)
|
|
4540
|
-
});
|
|
4541
|
-
}
|
|
4542
|
-
prepare() {
|
|
4543
|
-
return this._prepare(false);
|
|
4544
|
-
}
|
|
4545
|
-
run = (placeholderValues) => {
|
|
4546
|
-
return this._prepare().run(placeholderValues);
|
|
4547
|
-
};
|
|
4548
|
-
all = (placeholderValues) => {
|
|
4549
|
-
return this._prepare().all(placeholderValues);
|
|
4550
|
-
};
|
|
4551
|
-
get = (placeholderValues) => {
|
|
4552
|
-
return this._prepare().get(placeholderValues);
|
|
4553
|
-
};
|
|
4554
|
-
values = (placeholderValues) => {
|
|
4555
|
-
return this._prepare().values(placeholderValues);
|
|
4556
|
-
};
|
|
4557
|
-
async execute(placeholderValues) {
|
|
4558
|
-
return this._prepare().execute(placeholderValues);
|
|
4559
|
-
}
|
|
4560
|
-
$dynamic() {
|
|
4561
|
-
return this;
|
|
4562
|
-
}
|
|
4563
|
-
};
|
|
4564
|
-
//#endregion
|
|
4565
|
-
//#region node_modules/drizzle-orm/casing.js
|
|
4566
|
-
function toSnakeCase(input) {
|
|
4567
|
-
return (input.replace(/['\u2019]/g, "").match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g) ?? []).map((word) => word.toLowerCase()).join("_");
|
|
4568
|
-
}
|
|
4569
|
-
function toCamelCase(input) {
|
|
4570
|
-
return (input.replace(/['\u2019]/g, "").match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g) ?? []).reduce((acc, word, i) => {
|
|
4571
|
-
return acc + (i === 0 ? word.toLowerCase() : `${word[0].toUpperCase()}${word.slice(1)}`);
|
|
4572
|
-
}, "");
|
|
4573
|
-
}
|
|
4574
|
-
function noopCase(input) {
|
|
4575
|
-
return input;
|
|
4576
|
-
}
|
|
4577
|
-
var CasingCache = class {
|
|
4578
|
-
static [entityKind] = "CasingCache";
|
|
4579
|
-
/** @internal */
|
|
4580
|
-
cache = {};
|
|
4581
|
-
cachedTables = {};
|
|
4582
|
-
convert;
|
|
4583
|
-
constructor(casing) {
|
|
4584
|
-
this.convert = casing === "snake_case" ? toSnakeCase : casing === "camelCase" ? toCamelCase : noopCase;
|
|
4585
|
-
}
|
|
4586
|
-
getColumnCasing(column) {
|
|
4587
|
-
if (!column.keyAsName) return column.name;
|
|
4588
|
-
const key = `${column.table[Table.Symbol.Schema] ?? "public"}.${column.table[Table.Symbol.OriginalName]}.${column.name}`;
|
|
4589
|
-
if (!this.cache[key]) this.cacheTable(column.table);
|
|
4590
|
-
return this.cache[key];
|
|
4591
|
-
}
|
|
4592
|
-
cacheTable(table) {
|
|
4593
|
-
const tableKey = `${table[Table.Symbol.Schema] ?? "public"}.${table[Table.Symbol.OriginalName]}`;
|
|
4594
|
-
if (!this.cachedTables[tableKey]) {
|
|
4595
|
-
for (const column of Object.values(table[Table.Symbol.Columns])) {
|
|
4596
|
-
const columnKey = `${tableKey}.${column.name}`;
|
|
4597
|
-
this.cache[columnKey] = this.convert(column.name);
|
|
4598
|
-
}
|
|
4599
|
-
this.cachedTables[tableKey] = true;
|
|
4600
|
-
}
|
|
4601
|
-
}
|
|
4602
|
-
clearCache() {
|
|
4603
|
-
this.cache = {};
|
|
4604
|
-
this.cachedTables = {};
|
|
4605
|
-
}
|
|
4606
|
-
};
|
|
4607
|
-
//#endregion
|
|
4608
|
-
//#region node_modules/drizzle-orm/sqlite-core/view-base.js
|
|
4609
|
-
var SQLiteViewBase = class extends View {
|
|
4610
|
-
static [entityKind] = "SQLiteViewBase";
|
|
4611
|
-
};
|
|
4612
|
-
//#endregion
|
|
4613
|
-
//#region node_modules/drizzle-orm/sqlite-core/dialect.js
|
|
4614
|
-
var SQLiteDialect = class {
|
|
4615
|
-
static [entityKind] = "SQLiteDialect";
|
|
4616
|
-
/** @internal */
|
|
4617
|
-
casing;
|
|
4618
|
-
constructor(config) {
|
|
4619
|
-
this.casing = new CasingCache(config?.casing);
|
|
4620
|
-
}
|
|
4621
|
-
escapeName(name) {
|
|
4622
|
-
return `"${name}"`;
|
|
4623
|
-
}
|
|
4624
|
-
escapeParam(_num) {
|
|
4625
|
-
return "?";
|
|
4626
|
-
}
|
|
4627
|
-
escapeString(str) {
|
|
4628
|
-
return `'${str.replace(/'/g, "''")}'`;
|
|
4629
|
-
}
|
|
4630
|
-
buildWithCTE(queries) {
|
|
4631
|
-
if (!queries?.length) return void 0;
|
|
4632
|
-
const withSqlChunks = [sql`with `];
|
|
4633
|
-
for (const [i, w] of queries.entries()) {
|
|
4634
|
-
withSqlChunks.push(sql`${sql.identifier(w._.alias)} as (${w._.sql})`);
|
|
4635
|
-
if (i < queries.length - 1) withSqlChunks.push(sql`, `);
|
|
4636
|
-
}
|
|
4637
|
-
withSqlChunks.push(sql` `);
|
|
4638
|
-
return sql.join(withSqlChunks);
|
|
4639
|
-
}
|
|
4640
|
-
buildDeleteQuery({ table, where, returning, withList, limit, orderBy }) {
|
|
4641
|
-
const withSql = this.buildWithCTE(withList);
|
|
4642
|
-
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
|
|
4643
|
-
return sql`${withSql}delete from ${table}${where ? sql` where ${where}` : void 0}${returningSql}${this.buildOrderBy(orderBy)}${this.buildLimit(limit)}`;
|
|
4644
|
-
}
|
|
4645
|
-
buildUpdateSet(table, set) {
|
|
4646
|
-
const tableColumns = table[Table.Symbol.Columns];
|
|
4647
|
-
const columnNames = Object.keys(tableColumns).filter((colName) => set[colName] !== void 0 || tableColumns[colName]?.onUpdateFn !== void 0);
|
|
4648
|
-
const setSize = columnNames.length;
|
|
4649
|
-
return sql.join(columnNames.flatMap((colName, i) => {
|
|
4650
|
-
const col = tableColumns[colName];
|
|
4651
|
-
const onUpdateFnResult = col.onUpdateFn?.();
|
|
4652
|
-
const value = set[colName] ?? (is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col));
|
|
4653
|
-
const res = sql`${sql.identifier(this.casing.getColumnCasing(col))} = ${value}`;
|
|
4654
|
-
if (i < setSize - 1) return [res, sql.raw(", ")];
|
|
4655
|
-
return [res];
|
|
4656
|
-
}));
|
|
4657
|
-
}
|
|
4658
|
-
buildUpdateQuery({ table, set, where, returning, withList, joins, from, limit, orderBy }) {
|
|
4659
|
-
const withSql = this.buildWithCTE(withList);
|
|
4660
|
-
const setSql = this.buildUpdateSet(table, set);
|
|
4661
|
-
const fromSql = from && sql.join([sql.raw(" from "), this.buildFromTable(from)]);
|
|
4662
|
-
const joinsSql = this.buildJoins(joins);
|
|
4663
|
-
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
|
|
4664
|
-
return sql`${withSql}update ${table} set ${setSql}${fromSql}${joinsSql}${where ? sql` where ${where}` : void 0}${returningSql}${this.buildOrderBy(orderBy)}${this.buildLimit(limit)}`;
|
|
4665
|
-
}
|
|
4666
|
-
/**
|
|
4667
|
-
* Builds selection SQL with provided fields/expressions
|
|
4668
|
-
*
|
|
4669
|
-
* Examples:
|
|
4670
|
-
*
|
|
4671
|
-
* `select <selection> from`
|
|
4672
|
-
*
|
|
4673
|
-
* `insert ... returning <selection>`
|
|
4674
|
-
*
|
|
4675
|
-
* If `isSingleTable` is true, then columns won't be prefixed with table name
|
|
4676
|
-
*/
|
|
4677
|
-
buildSelection(fields, { isSingleTable = false } = {}) {
|
|
4678
|
-
const columnsLen = fields.length;
|
|
4679
|
-
const chunks = fields.flatMap(({ field }, i) => {
|
|
4680
|
-
const chunk = [];
|
|
4681
|
-
if (is(field, SQL.Aliased) && field.isSelectionField) chunk.push(sql.identifier(field.fieldAlias));
|
|
4682
|
-
else if (is(field, SQL.Aliased) || is(field, SQL)) {
|
|
4683
|
-
const query = is(field, SQL.Aliased) ? field.sql : field;
|
|
4684
|
-
if (isSingleTable) chunk.push(new SQL(query.queryChunks.map((c) => {
|
|
4685
|
-
if (is(c, Column)) return sql.identifier(this.casing.getColumnCasing(c));
|
|
4686
|
-
return c;
|
|
4687
|
-
})));
|
|
4688
|
-
else chunk.push(query);
|
|
4689
|
-
if (is(field, SQL.Aliased)) chunk.push(sql` as ${sql.identifier(field.fieldAlias)}`);
|
|
4690
|
-
} else if (is(field, Column)) {
|
|
4691
|
-
const tableName = field.table[Table.Symbol.Name];
|
|
4692
|
-
if (field.columnType === "SQLiteNumericBigInt") if (isSingleTable) chunk.push(sql`cast(${sql.identifier(this.casing.getColumnCasing(field))} as text)`);
|
|
4693
|
-
else chunk.push(sql`cast(${sql.identifier(tableName)}.${sql.identifier(this.casing.getColumnCasing(field))} as text)`);
|
|
4694
|
-
else if (isSingleTable) chunk.push(sql.identifier(this.casing.getColumnCasing(field)));
|
|
4695
|
-
else chunk.push(sql`${sql.identifier(tableName)}.${sql.identifier(this.casing.getColumnCasing(field))}`);
|
|
4696
|
-
} else if (is(field, Subquery)) {
|
|
4697
|
-
const entries = Object.entries(field._.selectedFields);
|
|
4698
|
-
if (entries.length === 1) {
|
|
4699
|
-
const entry = entries[0][1];
|
|
4700
|
-
const fieldDecoder = is(entry, SQL) ? entry.decoder : is(entry, Column) ? { mapFromDriverValue: (v) => entry.mapFromDriverValue(v) } : entry.sql.decoder;
|
|
4701
|
-
if (fieldDecoder) field._.sql.decoder = fieldDecoder;
|
|
4702
|
-
}
|
|
4703
|
-
chunk.push(field);
|
|
4704
|
-
}
|
|
4705
|
-
if (i < columnsLen - 1) chunk.push(sql`, `);
|
|
4706
|
-
return chunk;
|
|
4707
|
-
});
|
|
4708
|
-
return sql.join(chunks);
|
|
4709
|
-
}
|
|
4710
|
-
buildJoins(joins) {
|
|
4711
|
-
if (!joins || joins.length === 0) return;
|
|
4712
|
-
const joinsArray = [];
|
|
4713
|
-
if (joins) for (const [index, joinMeta] of joins.entries()) {
|
|
4714
|
-
if (index === 0) joinsArray.push(sql` `);
|
|
4715
|
-
const table = joinMeta.table;
|
|
4716
|
-
const onSql = joinMeta.on ? sql` on ${joinMeta.on}` : void 0;
|
|
4717
|
-
if (is(table, SQLiteTable)) {
|
|
4718
|
-
const tableName = table[SQLiteTable.Symbol.Name];
|
|
4719
|
-
const tableSchema = table[SQLiteTable.Symbol.Schema];
|
|
4720
|
-
const origTableName = table[SQLiteTable.Symbol.OriginalName];
|
|
4721
|
-
const alias = tableName === origTableName ? void 0 : joinMeta.alias;
|
|
4722
|
-
joinsArray.push(sql`${sql.raw(joinMeta.joinType)} join ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`}${onSql}`);
|
|
4723
|
-
} else joinsArray.push(sql`${sql.raw(joinMeta.joinType)} join ${table}${onSql}`);
|
|
4724
|
-
if (index < joins.length - 1) joinsArray.push(sql` `);
|
|
4725
|
-
}
|
|
4726
|
-
return sql.join(joinsArray);
|
|
4727
|
-
}
|
|
4728
|
-
buildLimit(limit) {
|
|
4729
|
-
return typeof limit === "object" || typeof limit === "number" && limit >= 0 ? sql` limit ${limit}` : void 0;
|
|
4730
|
-
}
|
|
4731
|
-
buildOrderBy(orderBy) {
|
|
4732
|
-
const orderByList = [];
|
|
4733
|
-
if (orderBy) for (const [index, orderByValue] of orderBy.entries()) {
|
|
4734
|
-
orderByList.push(orderByValue);
|
|
4735
|
-
if (index < orderBy.length - 1) orderByList.push(sql`, `);
|
|
4736
|
-
}
|
|
4737
|
-
return orderByList.length > 0 ? sql` order by ${sql.join(orderByList)}` : void 0;
|
|
4738
|
-
}
|
|
4739
|
-
buildFromTable(table) {
|
|
4740
|
-
if (is(table, Table) && table[Table.Symbol.IsAlias]) return sql`${sql`${sql.identifier(table[Table.Symbol.Schema] ?? "")}.`.if(table[Table.Symbol.Schema])}${sql.identifier(table[Table.Symbol.OriginalName])} ${sql.identifier(table[Table.Symbol.Name])}`;
|
|
4741
|
-
return table;
|
|
4742
|
-
}
|
|
4743
|
-
buildSelectQuery({ withList, fields, fieldsFlat, where, having, table, joins, orderBy, groupBy, limit, offset, distinct, setOperators }) {
|
|
4744
|
-
const fieldsList = fieldsFlat ?? orderSelectedFields(fields);
|
|
4745
|
-
for (const f of fieldsList) if (is(f.field, Column) && getTableName(f.field.table) !== (is(table, Subquery) ? table._.alias : is(table, SQLiteViewBase) ? table[ViewBaseConfig].name : is(table, SQL) ? void 0 : getTableName(table)) && !((table2) => joins?.some(({ alias }) => alias === (table2[Table.Symbol.IsAlias] ? getTableName(table2) : table2[Table.Symbol.BaseName])))(f.field.table)) {
|
|
4746
|
-
const tableName = getTableName(f.field.table);
|
|
4747
|
-
throw new Error(`Your "${f.path.join("->")}" field references a column "${tableName}"."${f.field.name}", but the table "${tableName}" is not part of the query! Did you forget to join it?`);
|
|
4748
|
-
}
|
|
4749
|
-
const isSingleTable = !joins || joins.length === 0;
|
|
4750
|
-
const withSql = this.buildWithCTE(withList);
|
|
4751
|
-
const distinctSql = distinct ? sql` distinct` : void 0;
|
|
4752
|
-
const selection = this.buildSelection(fieldsList, { isSingleTable });
|
|
4753
|
-
const tableSql = this.buildFromTable(table);
|
|
4754
|
-
const joinsSql = this.buildJoins(joins);
|
|
4755
|
-
const whereSql = where ? sql` where ${where}` : void 0;
|
|
4756
|
-
const havingSql = having ? sql` having ${having}` : void 0;
|
|
4757
|
-
const groupByList = [];
|
|
4758
|
-
if (groupBy) for (const [index, groupByValue] of groupBy.entries()) {
|
|
4759
|
-
groupByList.push(groupByValue);
|
|
4760
|
-
if (index < groupBy.length - 1) groupByList.push(sql`, `);
|
|
4761
|
-
}
|
|
4762
|
-
const finalQuery = sql`${withSql}select${distinctSql} ${selection} from ${tableSql}${joinsSql}${whereSql}${groupByList.length > 0 ? sql` group by ${sql.join(groupByList)}` : void 0}${havingSql}${this.buildOrderBy(orderBy)}${this.buildLimit(limit)}${offset ? sql` offset ${offset}` : void 0}`;
|
|
4763
|
-
if (setOperators.length > 0) return this.buildSetOperations(finalQuery, setOperators);
|
|
4764
|
-
return finalQuery;
|
|
4765
|
-
}
|
|
4766
|
-
buildSetOperations(leftSelect, setOperators) {
|
|
4767
|
-
const [setOperator, ...rest] = setOperators;
|
|
4768
|
-
if (!setOperator) throw new Error("Cannot pass undefined values to any set operator");
|
|
4769
|
-
if (rest.length === 0) return this.buildSetOperationQuery({
|
|
4770
|
-
leftSelect,
|
|
4771
|
-
setOperator
|
|
4772
|
-
});
|
|
4773
|
-
return this.buildSetOperations(this.buildSetOperationQuery({
|
|
4774
|
-
leftSelect,
|
|
4775
|
-
setOperator
|
|
4776
|
-
}), rest);
|
|
4777
|
-
}
|
|
4778
|
-
buildSetOperationQuery({ leftSelect, setOperator: { type, isAll, rightSelect, limit, orderBy, offset } }) {
|
|
4779
|
-
const leftChunk = sql`${leftSelect.getSQL()} `;
|
|
4780
|
-
const rightChunk = sql`${rightSelect.getSQL()}`;
|
|
4781
|
-
let orderBySql;
|
|
4782
|
-
if (orderBy && orderBy.length > 0) {
|
|
4783
|
-
const orderByValues = [];
|
|
4784
|
-
for (const singleOrderBy of orderBy) if (is(singleOrderBy, SQLiteColumn)) orderByValues.push(sql.identifier(singleOrderBy.name));
|
|
4785
|
-
else if (is(singleOrderBy, SQL)) {
|
|
4786
|
-
for (let i = 0; i < singleOrderBy.queryChunks.length; i++) {
|
|
4787
|
-
const chunk = singleOrderBy.queryChunks[i];
|
|
4788
|
-
if (is(chunk, SQLiteColumn)) singleOrderBy.queryChunks[i] = sql.identifier(this.casing.getColumnCasing(chunk));
|
|
4789
|
-
}
|
|
4790
|
-
orderByValues.push(sql`${singleOrderBy}`);
|
|
4791
|
-
} else orderByValues.push(sql`${singleOrderBy}`);
|
|
4792
|
-
orderBySql = sql` order by ${sql.join(orderByValues, sql`, `)}`;
|
|
4793
|
-
}
|
|
4794
|
-
const limitSql = typeof limit === "object" || typeof limit === "number" && limit >= 0 ? sql` limit ${limit}` : void 0;
|
|
4795
|
-
const operatorChunk = sql.raw(`${type} ${isAll ? "all " : ""}`);
|
|
4796
|
-
const offsetSql = offset ? sql` offset ${offset}` : void 0;
|
|
4797
|
-
return sql`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;
|
|
4798
|
-
}
|
|
4799
|
-
buildInsertQuery({ table, values: valuesOrSelect, onConflict, returning, withList, select }) {
|
|
4800
|
-
const valuesSqlList = [];
|
|
4801
|
-
const columns = table[Table.Symbol.Columns];
|
|
4802
|
-
const colEntries = Object.entries(columns).filter(([_, col]) => !col.shouldDisableInsert());
|
|
4803
|
-
const insertOrder = colEntries.map(([, column]) => sql.identifier(this.casing.getColumnCasing(column)));
|
|
4804
|
-
if (select) {
|
|
4805
|
-
const select2 = valuesOrSelect;
|
|
4806
|
-
if (is(select2, SQL)) valuesSqlList.push(select2);
|
|
4807
|
-
else valuesSqlList.push(select2.getSQL());
|
|
4808
|
-
} else {
|
|
4809
|
-
const values = valuesOrSelect;
|
|
4810
|
-
valuesSqlList.push(sql.raw("values "));
|
|
4811
|
-
for (const [valueIndex, value] of values.entries()) {
|
|
4812
|
-
const valueList = [];
|
|
4813
|
-
for (const [fieldName, col] of colEntries) {
|
|
4814
|
-
const colValue = value[fieldName];
|
|
4815
|
-
if (colValue === void 0 || is(colValue, Param) && colValue.value === void 0) {
|
|
4816
|
-
let defaultValue;
|
|
4817
|
-
if (col.default !== null && col.default !== void 0) defaultValue = is(col.default, SQL) ? col.default : sql.param(col.default, col);
|
|
4818
|
-
else if (col.defaultFn !== void 0) {
|
|
4819
|
-
const defaultFnResult = col.defaultFn();
|
|
4820
|
-
defaultValue = is(defaultFnResult, SQL) ? defaultFnResult : sql.param(defaultFnResult, col);
|
|
4821
|
-
} else if (!col.default && col.onUpdateFn !== void 0) {
|
|
4822
|
-
const onUpdateFnResult = col.onUpdateFn();
|
|
4823
|
-
defaultValue = is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col);
|
|
4824
|
-
} else defaultValue = sql`null`;
|
|
4825
|
-
valueList.push(defaultValue);
|
|
4826
|
-
} else valueList.push(colValue);
|
|
4827
|
-
}
|
|
4828
|
-
valuesSqlList.push(valueList);
|
|
4829
|
-
if (valueIndex < values.length - 1) valuesSqlList.push(sql`, `);
|
|
4830
|
-
}
|
|
4831
|
-
}
|
|
4832
|
-
const withSql = this.buildWithCTE(withList);
|
|
4833
|
-
const valuesSql = sql.join(valuesSqlList);
|
|
4834
|
-
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
|
|
4835
|
-
return sql`${withSql}insert into ${table} ${insertOrder} ${valuesSql}${onConflict?.length ? sql.join(onConflict) : void 0}${returningSql}`;
|
|
4836
|
-
}
|
|
4837
|
-
sqlToQuery(sql2, invokeSource) {
|
|
4838
|
-
return sql2.toQuery({
|
|
4839
|
-
casing: this.casing,
|
|
4840
|
-
escapeName: this.escapeName,
|
|
4841
|
-
escapeParam: this.escapeParam,
|
|
4842
|
-
escapeString: this.escapeString,
|
|
4843
|
-
invokeSource
|
|
4844
|
-
});
|
|
4845
|
-
}
|
|
4846
|
-
buildRelationalQuery({ fullSchema, schema, tableNamesMap, table, tableConfig, queryConfig: config, tableAlias, nestedQueryRelation, joinOn }) {
|
|
4847
|
-
let selection = [];
|
|
4848
|
-
let limit, offset, orderBy = [], where;
|
|
4849
|
-
const joins = [];
|
|
4850
|
-
if (config === true) selection = Object.entries(tableConfig.columns).map(([key, value]) => ({
|
|
4851
|
-
dbKey: value.name,
|
|
4852
|
-
tsKey: key,
|
|
4853
|
-
field: aliasedTableColumn(value, tableAlias),
|
|
4854
|
-
relationTableTsKey: void 0,
|
|
4855
|
-
isJson: false,
|
|
4856
|
-
selection: []
|
|
4857
|
-
}));
|
|
4858
|
-
else {
|
|
4859
|
-
const aliasedColumns = Object.fromEntries(Object.entries(tableConfig.columns).map(([key, value]) => [key, aliasedTableColumn(value, tableAlias)]));
|
|
4860
|
-
if (config.where) {
|
|
4861
|
-
const whereSql = typeof config.where === "function" ? config.where(aliasedColumns, getOperators()) : config.where;
|
|
4862
|
-
where = whereSql && mapColumnsInSQLToAlias(whereSql, tableAlias);
|
|
4863
|
-
}
|
|
4864
|
-
const fieldsSelection = [];
|
|
4865
|
-
let selectedColumns = [];
|
|
4866
|
-
if (config.columns) {
|
|
4867
|
-
let isIncludeMode = false;
|
|
4868
|
-
for (const [field, value] of Object.entries(config.columns)) {
|
|
4869
|
-
if (value === void 0) continue;
|
|
4870
|
-
if (field in tableConfig.columns) {
|
|
4871
|
-
if (!isIncludeMode && value === true) isIncludeMode = true;
|
|
4872
|
-
selectedColumns.push(field);
|
|
4873
|
-
}
|
|
4874
|
-
}
|
|
4875
|
-
if (selectedColumns.length > 0) selectedColumns = isIncludeMode ? selectedColumns.filter((c) => config.columns?.[c] === true) : Object.keys(tableConfig.columns).filter((key) => !selectedColumns.includes(key));
|
|
4876
|
-
} else selectedColumns = Object.keys(tableConfig.columns);
|
|
4877
|
-
for (const field of selectedColumns) {
|
|
4878
|
-
const column = tableConfig.columns[field];
|
|
4879
|
-
fieldsSelection.push({
|
|
4880
|
-
tsKey: field,
|
|
4881
|
-
value: column
|
|
4882
|
-
});
|
|
4883
|
-
}
|
|
4884
|
-
let selectedRelations = [];
|
|
4885
|
-
if (config.with) selectedRelations = Object.entries(config.with).filter((entry) => !!entry[1]).map(([tsKey, queryConfig]) => ({
|
|
4886
|
-
tsKey,
|
|
4887
|
-
queryConfig,
|
|
4888
|
-
relation: tableConfig.relations[tsKey]
|
|
4889
|
-
}));
|
|
4890
|
-
let extras;
|
|
4891
|
-
if (config.extras) {
|
|
4892
|
-
extras = typeof config.extras === "function" ? config.extras(aliasedColumns, { sql }) : config.extras;
|
|
4893
|
-
for (const [tsKey, value] of Object.entries(extras)) fieldsSelection.push({
|
|
4894
|
-
tsKey,
|
|
4895
|
-
value: mapColumnsInAliasedSQLToAlias(value, tableAlias)
|
|
4896
|
-
});
|
|
4897
|
-
}
|
|
4898
|
-
for (const { tsKey, value } of fieldsSelection) selection.push({
|
|
4899
|
-
dbKey: is(value, SQL.Aliased) ? value.fieldAlias : tableConfig.columns[tsKey].name,
|
|
4900
|
-
tsKey,
|
|
4901
|
-
field: is(value, Column) ? aliasedTableColumn(value, tableAlias) : value,
|
|
4902
|
-
relationTableTsKey: void 0,
|
|
4903
|
-
isJson: false,
|
|
4904
|
-
selection: []
|
|
4905
|
-
});
|
|
4906
|
-
let orderByOrig = typeof config.orderBy === "function" ? config.orderBy(aliasedColumns, getOrderByOperators()) : config.orderBy ?? [];
|
|
4907
|
-
if (!Array.isArray(orderByOrig)) orderByOrig = [orderByOrig];
|
|
4908
|
-
orderBy = orderByOrig.map((orderByValue) => {
|
|
4909
|
-
if (is(orderByValue, Column)) return aliasedTableColumn(orderByValue, tableAlias);
|
|
4910
|
-
return mapColumnsInSQLToAlias(orderByValue, tableAlias);
|
|
4911
|
-
});
|
|
4912
|
-
limit = config.limit;
|
|
4913
|
-
offset = config.offset;
|
|
4914
|
-
for (const { tsKey: selectedRelationTsKey, queryConfig: selectedRelationConfigValue, relation } of selectedRelations) {
|
|
4915
|
-
const normalizedRelation = normalizeRelation(schema, tableNamesMap, relation);
|
|
4916
|
-
const relationTableTsName = tableNamesMap[getTableUniqueName(relation.referencedTable)];
|
|
4917
|
-
const relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;
|
|
4918
|
-
const joinOn2 = and(...normalizedRelation.fields.map((field2, i) => eq(aliasedTableColumn(normalizedRelation.references[i], relationTableAlias), aliasedTableColumn(field2, tableAlias))));
|
|
4919
|
-
const builtRelation = this.buildRelationalQuery({
|
|
4920
|
-
fullSchema,
|
|
4921
|
-
schema,
|
|
4922
|
-
tableNamesMap,
|
|
4923
|
-
table: fullSchema[relationTableTsName],
|
|
4924
|
-
tableConfig: schema[relationTableTsName],
|
|
4925
|
-
queryConfig: is(relation, One) ? selectedRelationConfigValue === true ? { limit: 1 } : {
|
|
4926
|
-
...selectedRelationConfigValue,
|
|
4927
|
-
limit: 1
|
|
4928
|
-
} : selectedRelationConfigValue,
|
|
4929
|
-
tableAlias: relationTableAlias,
|
|
4930
|
-
joinOn: joinOn2,
|
|
4931
|
-
nestedQueryRelation: relation
|
|
4932
|
-
});
|
|
4933
|
-
const field = sql`(${builtRelation.sql})`.as(selectedRelationTsKey);
|
|
4934
|
-
selection.push({
|
|
4935
|
-
dbKey: selectedRelationTsKey,
|
|
4936
|
-
tsKey: selectedRelationTsKey,
|
|
4937
|
-
field,
|
|
4938
|
-
relationTableTsKey: relationTableTsName,
|
|
4939
|
-
isJson: true,
|
|
4940
|
-
selection: builtRelation.selection
|
|
4941
|
-
});
|
|
4942
|
-
}
|
|
4943
|
-
}
|
|
4944
|
-
if (selection.length === 0) throw new DrizzleError({ message: `No fields selected for table "${tableConfig.tsName}" ("${tableAlias}"). You need to have at least one item in "columns", "with" or "extras". If you need to select all columns, omit the "columns" key or set it to undefined.` });
|
|
4945
|
-
let result;
|
|
4946
|
-
where = and(joinOn, where);
|
|
4947
|
-
if (nestedQueryRelation) {
|
|
4948
|
-
let field = sql`json_array(${sql.join(selection.map(({ field: field2 }) => is(field2, SQLiteColumn) ? sql.identifier(this.casing.getColumnCasing(field2)) : is(field2, SQL.Aliased) ? field2.sql : field2), sql`, `)})`;
|
|
4949
|
-
if (is(nestedQueryRelation, Many)) field = sql`coalesce(json_group_array(${field}), json_array())`;
|
|
4950
|
-
const nestedSelection = [{
|
|
4951
|
-
dbKey: "data",
|
|
4952
|
-
tsKey: "data",
|
|
4953
|
-
field: field.as("data"),
|
|
4954
|
-
isJson: true,
|
|
4955
|
-
relationTableTsKey: tableConfig.tsName,
|
|
4956
|
-
selection
|
|
4957
|
-
}];
|
|
4958
|
-
if (limit !== void 0 || offset !== void 0 || orderBy.length > 0) {
|
|
4959
|
-
result = this.buildSelectQuery({
|
|
4960
|
-
table: aliasedTable(table, tableAlias),
|
|
4961
|
-
fields: {},
|
|
4962
|
-
fieldsFlat: [{
|
|
4963
|
-
path: [],
|
|
4964
|
-
field: sql.raw("*")
|
|
4965
|
-
}],
|
|
4966
|
-
where,
|
|
4967
|
-
limit,
|
|
4968
|
-
offset,
|
|
4969
|
-
orderBy,
|
|
4970
|
-
setOperators: []
|
|
4971
|
-
});
|
|
4972
|
-
where = void 0;
|
|
4973
|
-
limit = void 0;
|
|
4974
|
-
offset = void 0;
|
|
4975
|
-
orderBy = void 0;
|
|
4976
|
-
} else result = aliasedTable(table, tableAlias);
|
|
4977
|
-
result = this.buildSelectQuery({
|
|
4978
|
-
table: is(result, SQLiteTable) ? result : new Subquery(result, {}, tableAlias),
|
|
4979
|
-
fields: {},
|
|
4980
|
-
fieldsFlat: nestedSelection.map(({ field: field2 }) => ({
|
|
4981
|
-
path: [],
|
|
4982
|
-
field: is(field2, Column) ? aliasedTableColumn(field2, tableAlias) : field2
|
|
4983
|
-
})),
|
|
4984
|
-
joins,
|
|
4985
|
-
where,
|
|
4986
|
-
limit,
|
|
4987
|
-
offset,
|
|
4988
|
-
orderBy,
|
|
4989
|
-
setOperators: []
|
|
4990
|
-
});
|
|
4991
|
-
} else result = this.buildSelectQuery({
|
|
4992
|
-
table: aliasedTable(table, tableAlias),
|
|
4993
|
-
fields: {},
|
|
4994
|
-
fieldsFlat: selection.map(({ field }) => ({
|
|
4995
|
-
path: [],
|
|
4996
|
-
field: is(field, Column) ? aliasedTableColumn(field, tableAlias) : field
|
|
4997
|
-
})),
|
|
4998
|
-
joins,
|
|
4999
|
-
where,
|
|
5000
|
-
limit,
|
|
5001
|
-
offset,
|
|
5002
|
-
orderBy,
|
|
5003
|
-
setOperators: []
|
|
5004
|
-
});
|
|
5005
|
-
return {
|
|
5006
|
-
tableTsKey: tableConfig.tsName,
|
|
5007
|
-
sql: result,
|
|
5008
|
-
selection
|
|
5009
|
-
};
|
|
5010
|
-
}
|
|
5011
|
-
};
|
|
5012
|
-
var SQLiteSyncDialect = class extends SQLiteDialect {
|
|
5013
|
-
static [entityKind] = "SQLiteSyncDialect";
|
|
5014
|
-
migrate(migrations, session, config) {
|
|
5015
|
-
const migrationsTable = config === void 0 ? "__drizzle_migrations" : typeof config === "string" ? "__drizzle_migrations" : config.migrationsTable ?? "__drizzle_migrations";
|
|
5016
|
-
const migrationTableCreate = sql`
|
|
5017
|
-
CREATE TABLE IF NOT EXISTS ${sql.identifier(migrationsTable)} (
|
|
5018
|
-
id SERIAL PRIMARY KEY,
|
|
5019
|
-
hash text NOT NULL,
|
|
5020
|
-
created_at numeric
|
|
5021
|
-
)
|
|
5022
|
-
`;
|
|
5023
|
-
session.run(migrationTableCreate);
|
|
5024
|
-
const lastDbMigration = session.values(sql`SELECT id, hash, created_at FROM ${sql.identifier(migrationsTable)} ORDER BY created_at DESC LIMIT 1`)[0] ?? void 0;
|
|
5025
|
-
session.run(sql`BEGIN`);
|
|
5026
|
-
try {
|
|
5027
|
-
for (const migration of migrations) if (!lastDbMigration || Number(lastDbMigration[2]) < migration.folderMillis) {
|
|
5028
|
-
for (const stmt of migration.sql) session.run(sql.raw(stmt));
|
|
5029
|
-
session.run(sql`INSERT INTO ${sql.identifier(migrationsTable)} ("hash", "created_at") VALUES(${migration.hash}, ${migration.folderMillis})`);
|
|
5030
|
-
}
|
|
5031
|
-
session.run(sql`COMMIT`);
|
|
5032
|
-
} catch (e) {
|
|
5033
|
-
session.run(sql`ROLLBACK`);
|
|
5034
|
-
throw e;
|
|
5035
|
-
}
|
|
5036
|
-
}
|
|
5037
|
-
};
|
|
5038
|
-
//#endregion
|
|
5039
|
-
//#region node_modules/drizzle-orm/query-builders/query-builder.js
|
|
5040
|
-
var TypedQueryBuilder = class {
|
|
5041
|
-
static [entityKind] = "TypedQueryBuilder";
|
|
5042
|
-
/** @internal */
|
|
5043
|
-
getSelectedFields() {
|
|
5044
|
-
return this._.selectedFields;
|
|
5045
|
-
}
|
|
5046
|
-
};
|
|
5047
|
-
//#endregion
|
|
5048
|
-
//#region node_modules/drizzle-orm/sqlite-core/query-builders/select.js
|
|
5049
|
-
var SQLiteSelectBuilder = class {
|
|
5050
|
-
static [entityKind] = "SQLiteSelectBuilder";
|
|
5051
|
-
fields;
|
|
5052
|
-
session;
|
|
5053
|
-
dialect;
|
|
5054
|
-
withList;
|
|
5055
|
-
distinct;
|
|
5056
|
-
constructor(config) {
|
|
5057
|
-
this.fields = config.fields;
|
|
5058
|
-
this.session = config.session;
|
|
5059
|
-
this.dialect = config.dialect;
|
|
5060
|
-
this.withList = config.withList;
|
|
5061
|
-
this.distinct = config.distinct;
|
|
5062
|
-
}
|
|
5063
|
-
from(source) {
|
|
5064
|
-
const isPartialSelect = !!this.fields;
|
|
5065
|
-
let fields;
|
|
5066
|
-
if (this.fields) fields = this.fields;
|
|
5067
|
-
else if (is(source, Subquery)) fields = Object.fromEntries(Object.keys(source._.selectedFields).map((key) => [key, source[key]]));
|
|
5068
|
-
else if (is(source, SQLiteViewBase)) fields = source[ViewBaseConfig].selectedFields;
|
|
5069
|
-
else if (is(source, SQL)) fields = {};
|
|
5070
|
-
else fields = getTableColumns(source);
|
|
5071
|
-
return new SQLiteSelectBase({
|
|
5072
|
-
table: source,
|
|
5073
|
-
fields,
|
|
5074
|
-
isPartialSelect,
|
|
5075
|
-
session: this.session,
|
|
5076
|
-
dialect: this.dialect,
|
|
5077
|
-
withList: this.withList,
|
|
5078
|
-
distinct: this.distinct
|
|
5079
|
-
});
|
|
5080
|
-
}
|
|
5081
|
-
};
|
|
5082
|
-
var SQLiteSelectQueryBuilderBase = class extends TypedQueryBuilder {
|
|
5083
|
-
static [entityKind] = "SQLiteSelectQueryBuilder";
|
|
5084
|
-
_;
|
|
5085
|
-
/** @internal */
|
|
5086
|
-
config;
|
|
5087
|
-
joinsNotNullableMap;
|
|
5088
|
-
tableName;
|
|
5089
|
-
isPartialSelect;
|
|
5090
|
-
session;
|
|
5091
|
-
dialect;
|
|
5092
|
-
cacheConfig = void 0;
|
|
5093
|
-
usedTables = /* @__PURE__ */ new Set();
|
|
5094
|
-
constructor({ table, fields, isPartialSelect, session, dialect, withList, distinct }) {
|
|
5095
|
-
super();
|
|
5096
|
-
this.config = {
|
|
5097
|
-
withList,
|
|
5098
|
-
table,
|
|
5099
|
-
fields: { ...fields },
|
|
5100
|
-
distinct,
|
|
5101
|
-
setOperators: []
|
|
5102
|
-
};
|
|
5103
|
-
this.isPartialSelect = isPartialSelect;
|
|
5104
|
-
this.session = session;
|
|
5105
|
-
this.dialect = dialect;
|
|
5106
|
-
this._ = {
|
|
5107
|
-
selectedFields: fields,
|
|
5108
|
-
config: this.config
|
|
5109
|
-
};
|
|
5110
|
-
this.tableName = getTableLikeName(table);
|
|
5111
|
-
this.joinsNotNullableMap = typeof this.tableName === "string" ? { [this.tableName]: true } : {};
|
|
5112
|
-
for (const item of extractUsedTable(table)) this.usedTables.add(item);
|
|
5113
|
-
}
|
|
5114
|
-
/** @internal */
|
|
5115
|
-
getUsedTables() {
|
|
5116
|
-
return [...this.usedTables];
|
|
5117
|
-
}
|
|
5118
|
-
createJoin(joinType) {
|
|
5119
|
-
return (table, on) => {
|
|
5120
|
-
const baseTableName = this.tableName;
|
|
5121
|
-
const tableName = getTableLikeName(table);
|
|
5122
|
-
for (const item of extractUsedTable(table)) this.usedTables.add(item);
|
|
5123
|
-
if (typeof tableName === "string" && this.config.joins?.some((join) => join.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
5124
|
-
if (!this.isPartialSelect) {
|
|
5125
|
-
if (Object.keys(this.joinsNotNullableMap).length === 1 && typeof baseTableName === "string") this.config.fields = { [baseTableName]: this.config.fields };
|
|
5126
|
-
if (typeof tableName === "string" && !is(table, SQL)) {
|
|
5127
|
-
const selection = is(table, Subquery) ? table._.selectedFields : is(table, View) ? table[ViewBaseConfig].selectedFields : table[Table.Symbol.Columns];
|
|
5128
|
-
this.config.fields[tableName] = selection;
|
|
5129
|
-
}
|
|
5130
|
-
}
|
|
5131
|
-
if (typeof on === "function") on = on(new Proxy(this.config.fields, new SelectionProxyHandler({
|
|
5132
|
-
sqlAliasedBehavior: "sql",
|
|
5133
|
-
sqlBehavior: "sql"
|
|
5134
|
-
})));
|
|
5135
|
-
if (!this.config.joins) this.config.joins = [];
|
|
5136
|
-
this.config.joins.push({
|
|
5137
|
-
on,
|
|
5138
|
-
table,
|
|
5139
|
-
joinType,
|
|
5140
|
-
alias: tableName
|
|
5141
|
-
});
|
|
5142
|
-
if (typeof tableName === "string") switch (joinType) {
|
|
5143
|
-
case "left":
|
|
5144
|
-
this.joinsNotNullableMap[tableName] = false;
|
|
5145
|
-
break;
|
|
5146
|
-
case "right":
|
|
5147
|
-
this.joinsNotNullableMap = Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false]));
|
|
5148
|
-
this.joinsNotNullableMap[tableName] = true;
|
|
5149
|
-
break;
|
|
5150
|
-
case "cross":
|
|
5151
|
-
case "inner":
|
|
5152
|
-
this.joinsNotNullableMap[tableName] = true;
|
|
5153
|
-
break;
|
|
5154
|
-
case "full":
|
|
5155
|
-
this.joinsNotNullableMap = Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false]));
|
|
5156
|
-
this.joinsNotNullableMap[tableName] = false;
|
|
5157
|
-
break;
|
|
5158
|
-
}
|
|
5159
|
-
return this;
|
|
5160
|
-
};
|
|
5161
|
-
}
|
|
5162
|
-
/**
|
|
5163
|
-
* Executes a `left join` operation by adding another table to the current query.
|
|
5164
|
-
*
|
|
5165
|
-
* Calling this method associates each row of the table with the corresponding row from the joined table, if a match is found. If no matching row exists, it sets all columns of the joined table to null.
|
|
5166
|
-
*
|
|
5167
|
-
* See docs: {@link https://orm.drizzle.team/docs/joins#left-join}
|
|
5168
|
-
*
|
|
5169
|
-
* @param table the table to join.
|
|
5170
|
-
* @param on the `on` clause.
|
|
5171
|
-
*
|
|
5172
|
-
* @example
|
|
5173
|
-
*
|
|
5174
|
-
* ```ts
|
|
5175
|
-
* // Select all users and their pets
|
|
5176
|
-
* const usersWithPets: { user: User; pets: Pet | null; }[] = await db.select()
|
|
5177
|
-
* .from(users)
|
|
5178
|
-
* .leftJoin(pets, eq(users.id, pets.ownerId))
|
|
5179
|
-
*
|
|
5180
|
-
* // Select userId and petId
|
|
5181
|
-
* const usersIdsAndPetIds: { userId: number; petId: number | null; }[] = await db.select({
|
|
5182
|
-
* userId: users.id,
|
|
5183
|
-
* petId: pets.id,
|
|
5184
|
-
* })
|
|
5185
|
-
* .from(users)
|
|
5186
|
-
* .leftJoin(pets, eq(users.id, pets.ownerId))
|
|
5187
|
-
* ```
|
|
5188
|
-
*/
|
|
5189
|
-
leftJoin = this.createJoin("left");
|
|
5190
|
-
/**
|
|
5191
|
-
* Executes a `right join` operation by adding another table to the current query.
|
|
5192
|
-
*
|
|
5193
|
-
* Calling this method associates each row of the joined table with the corresponding row from the main table, if a match is found. If no matching row exists, it sets all columns of the main table to null.
|
|
5194
|
-
*
|
|
5195
|
-
* See docs: {@link https://orm.drizzle.team/docs/joins#right-join}
|
|
5196
|
-
*
|
|
5197
|
-
* @param table the table to join.
|
|
5198
|
-
* @param on the `on` clause.
|
|
5199
|
-
*
|
|
5200
|
-
* @example
|
|
5201
|
-
*
|
|
5202
|
-
* ```ts
|
|
5203
|
-
* // Select all users and their pets
|
|
5204
|
-
* const usersWithPets: { user: User | null; pets: Pet; }[] = await db.select()
|
|
5205
|
-
* .from(users)
|
|
5206
|
-
* .rightJoin(pets, eq(users.id, pets.ownerId))
|
|
5207
|
-
*
|
|
5208
|
-
* // Select userId and petId
|
|
5209
|
-
* const usersIdsAndPetIds: { userId: number | null; petId: number; }[] = await db.select({
|
|
5210
|
-
* userId: users.id,
|
|
5211
|
-
* petId: pets.id,
|
|
5212
|
-
* })
|
|
5213
|
-
* .from(users)
|
|
5214
|
-
* .rightJoin(pets, eq(users.id, pets.ownerId))
|
|
5215
|
-
* ```
|
|
5216
|
-
*/
|
|
5217
|
-
rightJoin = this.createJoin("right");
|
|
5218
|
-
/**
|
|
5219
|
-
* Executes an `inner join` operation, creating a new table by combining rows from two tables that have matching values.
|
|
5220
|
-
*
|
|
5221
|
-
* Calling this method retrieves rows that have corresponding entries in both joined tables. Rows without matching entries in either table are excluded, resulting in a table that includes only matching pairs.
|
|
5222
|
-
*
|
|
5223
|
-
* See docs: {@link https://orm.drizzle.team/docs/joins#inner-join}
|
|
5224
|
-
*
|
|
5225
|
-
* @param table the table to join.
|
|
5226
|
-
* @param on the `on` clause.
|
|
5227
|
-
*
|
|
5228
|
-
* @example
|
|
5229
|
-
*
|
|
5230
|
-
* ```ts
|
|
5231
|
-
* // Select all users and their pets
|
|
5232
|
-
* const usersWithPets: { user: User; pets: Pet; }[] = await db.select()
|
|
5233
|
-
* .from(users)
|
|
5234
|
-
* .innerJoin(pets, eq(users.id, pets.ownerId))
|
|
5235
|
-
*
|
|
5236
|
-
* // Select userId and petId
|
|
5237
|
-
* const usersIdsAndPetIds: { userId: number; petId: number; }[] = await db.select({
|
|
5238
|
-
* userId: users.id,
|
|
5239
|
-
* petId: pets.id,
|
|
5240
|
-
* })
|
|
5241
|
-
* .from(users)
|
|
5242
|
-
* .innerJoin(pets, eq(users.id, pets.ownerId))
|
|
5243
|
-
* ```
|
|
5244
|
-
*/
|
|
5245
|
-
innerJoin = this.createJoin("inner");
|
|
5246
|
-
/**
|
|
5247
|
-
* Executes a `full join` operation by combining rows from two tables into a new table.
|
|
5248
|
-
*
|
|
5249
|
-
* Calling this method retrieves all rows from both main and joined tables, merging rows with matching values and filling in `null` for non-matching columns.
|
|
5250
|
-
*
|
|
5251
|
-
* See docs: {@link https://orm.drizzle.team/docs/joins#full-join}
|
|
5252
|
-
*
|
|
5253
|
-
* @param table the table to join.
|
|
5254
|
-
* @param on the `on` clause.
|
|
5255
|
-
*
|
|
5256
|
-
* @example
|
|
5257
|
-
*
|
|
5258
|
-
* ```ts
|
|
5259
|
-
* // Select all users and their pets
|
|
5260
|
-
* const usersWithPets: { user: User | null; pets: Pet | null; }[] = await db.select()
|
|
5261
|
-
* .from(users)
|
|
5262
|
-
* .fullJoin(pets, eq(users.id, pets.ownerId))
|
|
5263
|
-
*
|
|
5264
|
-
* // Select userId and petId
|
|
5265
|
-
* const usersIdsAndPetIds: { userId: number | null; petId: number | null; }[] = await db.select({
|
|
5266
|
-
* userId: users.id,
|
|
5267
|
-
* petId: pets.id,
|
|
5268
|
-
* })
|
|
5269
|
-
* .from(users)
|
|
5270
|
-
* .fullJoin(pets, eq(users.id, pets.ownerId))
|
|
5271
|
-
* ```
|
|
5272
|
-
*/
|
|
5273
|
-
fullJoin = this.createJoin("full");
|
|
5274
|
-
/**
|
|
5275
|
-
* Executes a `cross join` operation by combining rows from two tables into a new table.
|
|
5276
|
-
*
|
|
5277
|
-
* Calling this method retrieves all rows from both main and joined tables, merging all rows from each table.
|
|
5278
|
-
*
|
|
5279
|
-
* See docs: {@link https://orm.drizzle.team/docs/joins#cross-join}
|
|
5280
|
-
*
|
|
5281
|
-
* @param table the table to join.
|
|
5282
|
-
*
|
|
5283
|
-
* @example
|
|
5284
|
-
*
|
|
5285
|
-
* ```ts
|
|
5286
|
-
* // Select all users, each user with every pet
|
|
5287
|
-
* const usersWithPets: { user: User; pets: Pet; }[] = await db.select()
|
|
5288
|
-
* .from(users)
|
|
5289
|
-
* .crossJoin(pets)
|
|
5290
|
-
*
|
|
5291
|
-
* // Select userId and petId
|
|
5292
|
-
* const usersIdsAndPetIds: { userId: number; petId: number; }[] = await db.select({
|
|
5293
|
-
* userId: users.id,
|
|
5294
|
-
* petId: pets.id,
|
|
5295
|
-
* })
|
|
5296
|
-
* .from(users)
|
|
5297
|
-
* .crossJoin(pets)
|
|
5298
|
-
* ```
|
|
5299
|
-
*/
|
|
5300
|
-
crossJoin = this.createJoin("cross");
|
|
5301
|
-
createSetOperator(type, isAll) {
|
|
5302
|
-
return (rightSelection) => {
|
|
5303
|
-
const rightSelect = typeof rightSelection === "function" ? rightSelection(getSQLiteSetOperators()) : rightSelection;
|
|
5304
|
-
if (!haveSameKeys(this.getSelectedFields(), rightSelect.getSelectedFields())) throw new Error("Set operator error (union / intersect / except): selected fields are not the same or are in a different order");
|
|
5305
|
-
this.config.setOperators.push({
|
|
5306
|
-
type,
|
|
5307
|
-
isAll,
|
|
5308
|
-
rightSelect
|
|
5309
|
-
});
|
|
5310
|
-
return this;
|
|
5311
|
-
};
|
|
5312
|
-
}
|
|
5313
|
-
/**
|
|
5314
|
-
* Adds `union` set operator to the query.
|
|
5315
|
-
*
|
|
5316
|
-
* Calling this method will combine the result sets of the `select` statements and remove any duplicate rows that appear across them.
|
|
5317
|
-
*
|
|
5318
|
-
* See docs: {@link https://orm.drizzle.team/docs/set-operations#union}
|
|
5319
|
-
*
|
|
5320
|
-
* @example
|
|
5321
|
-
*
|
|
5322
|
-
* ```ts
|
|
5323
|
-
* // Select all unique names from customers and users tables
|
|
5324
|
-
* await db.select({ name: users.name })
|
|
5325
|
-
* .from(users)
|
|
5326
|
-
* .union(
|
|
5327
|
-
* db.select({ name: customers.name }).from(customers)
|
|
5328
|
-
* );
|
|
5329
|
-
* // or
|
|
5330
|
-
* import { union } from 'drizzle-orm/sqlite-core'
|
|
5331
|
-
*
|
|
5332
|
-
* await union(
|
|
5333
|
-
* db.select({ name: users.name }).from(users),
|
|
5334
|
-
* db.select({ name: customers.name }).from(customers)
|
|
5335
|
-
* );
|
|
5336
|
-
* ```
|
|
5337
|
-
*/
|
|
5338
|
-
union = this.createSetOperator("union", false);
|
|
5339
|
-
/**
|
|
5340
|
-
* Adds `union all` set operator to the query.
|
|
5341
|
-
*
|
|
5342
|
-
* Calling this method will combine the result-set of the `select` statements and keep all duplicate rows that appear across them.
|
|
5343
|
-
*
|
|
5344
|
-
* See docs: {@link https://orm.drizzle.team/docs/set-operations#union-all}
|
|
5345
|
-
*
|
|
5346
|
-
* @example
|
|
5347
|
-
*
|
|
5348
|
-
* ```ts
|
|
5349
|
-
* // Select all transaction ids from both online and in-store sales
|
|
5350
|
-
* await db.select({ transaction: onlineSales.transactionId })
|
|
5351
|
-
* .from(onlineSales)
|
|
5352
|
-
* .unionAll(
|
|
5353
|
-
* db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
|
|
5354
|
-
* );
|
|
5355
|
-
* // or
|
|
5356
|
-
* import { unionAll } from 'drizzle-orm/sqlite-core'
|
|
5357
|
-
*
|
|
5358
|
-
* await unionAll(
|
|
5359
|
-
* db.select({ transaction: onlineSales.transactionId }).from(onlineSales),
|
|
5360
|
-
* db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
|
|
5361
|
-
* );
|
|
5362
|
-
* ```
|
|
5363
|
-
*/
|
|
5364
|
-
unionAll = this.createSetOperator("union", true);
|
|
5365
|
-
/**
|
|
5366
|
-
* Adds `intersect` set operator to the query.
|
|
5367
|
-
*
|
|
5368
|
-
* Calling this method will retain only the rows that are present in both result sets and eliminate duplicates.
|
|
5369
|
-
*
|
|
5370
|
-
* See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect}
|
|
5371
|
-
*
|
|
5372
|
-
* @example
|
|
5373
|
-
*
|
|
5374
|
-
* ```ts
|
|
5375
|
-
* // Select course names that are offered in both departments A and B
|
|
5376
|
-
* await db.select({ courseName: depA.courseName })
|
|
5377
|
-
* .from(depA)
|
|
5378
|
-
* .intersect(
|
|
5379
|
-
* db.select({ courseName: depB.courseName }).from(depB)
|
|
5380
|
-
* );
|
|
5381
|
-
* // or
|
|
5382
|
-
* import { intersect } from 'drizzle-orm/sqlite-core'
|
|
5383
|
-
*
|
|
5384
|
-
* await intersect(
|
|
5385
|
-
* db.select({ courseName: depA.courseName }).from(depA),
|
|
5386
|
-
* db.select({ courseName: depB.courseName }).from(depB)
|
|
5387
|
-
* );
|
|
5388
|
-
* ```
|
|
5389
|
-
*/
|
|
5390
|
-
intersect = this.createSetOperator("intersect", false);
|
|
5391
|
-
/**
|
|
5392
|
-
* Adds `except` set operator to the query.
|
|
5393
|
-
*
|
|
5394
|
-
* Calling this method will retrieve all unique rows from the left query, except for the rows that are present in the result set of the right query.
|
|
5395
|
-
*
|
|
5396
|
-
* See docs: {@link https://orm.drizzle.team/docs/set-operations#except}
|
|
5397
|
-
*
|
|
5398
|
-
* @example
|
|
5399
|
-
*
|
|
5400
|
-
* ```ts
|
|
5401
|
-
* // Select all courses offered in department A but not in department B
|
|
5402
|
-
* await db.select({ courseName: depA.courseName })
|
|
5403
|
-
* .from(depA)
|
|
5404
|
-
* .except(
|
|
5405
|
-
* db.select({ courseName: depB.courseName }).from(depB)
|
|
5406
|
-
* );
|
|
5407
|
-
* // or
|
|
5408
|
-
* import { except } from 'drizzle-orm/sqlite-core'
|
|
5409
|
-
*
|
|
5410
|
-
* await except(
|
|
5411
|
-
* db.select({ courseName: depA.courseName }).from(depA),
|
|
5412
|
-
* db.select({ courseName: depB.courseName }).from(depB)
|
|
5413
|
-
* );
|
|
5414
|
-
* ```
|
|
5415
|
-
*/
|
|
5416
|
-
except = this.createSetOperator("except", false);
|
|
5417
|
-
/** @internal */
|
|
5418
|
-
addSetOperators(setOperators) {
|
|
5419
|
-
this.config.setOperators.push(...setOperators);
|
|
5420
|
-
return this;
|
|
5421
|
-
}
|
|
5422
|
-
/**
|
|
5423
|
-
* Adds a `where` clause to the query.
|
|
5424
|
-
*
|
|
5425
|
-
* Calling this method will select only those rows that fulfill a specified condition.
|
|
5426
|
-
*
|
|
5427
|
-
* See docs: {@link https://orm.drizzle.team/docs/select#filtering}
|
|
5428
|
-
*
|
|
5429
|
-
* @param where the `where` clause.
|
|
5430
|
-
*
|
|
5431
|
-
* @example
|
|
5432
|
-
* You can use conditional operators and `sql function` to filter the rows to be selected.
|
|
5433
|
-
*
|
|
5434
|
-
* ```ts
|
|
5435
|
-
* // Select all cars with green color
|
|
5436
|
-
* await db.select().from(cars).where(eq(cars.color, 'green'));
|
|
5437
|
-
* // or
|
|
5438
|
-
* await db.select().from(cars).where(sql`${cars.color} = 'green'`)
|
|
5439
|
-
* ```
|
|
5440
|
-
*
|
|
5441
|
-
* You can logically combine conditional operators with `and()` and `or()` operators:
|
|
5442
|
-
*
|
|
5443
|
-
* ```ts
|
|
5444
|
-
* // Select all BMW cars with a green color
|
|
5445
|
-
* await db.select().from(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
|
5446
|
-
*
|
|
5447
|
-
* // Select all cars with the green or blue color
|
|
5448
|
-
* await db.select().from(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
|
5449
|
-
* ```
|
|
5450
|
-
*/
|
|
5451
|
-
where(where) {
|
|
5452
|
-
if (typeof where === "function") where = where(new Proxy(this.config.fields, new SelectionProxyHandler({
|
|
5453
|
-
sqlAliasedBehavior: "sql",
|
|
5454
|
-
sqlBehavior: "sql"
|
|
5455
|
-
})));
|
|
5456
|
-
this.config.where = where;
|
|
5457
|
-
return this;
|
|
5458
|
-
}
|
|
5459
|
-
/**
|
|
5460
|
-
* Adds a `having` clause to the query.
|
|
5461
|
-
*
|
|
5462
|
-
* Calling this method will select only those rows that fulfill a specified condition. It is typically used with aggregate functions to filter the aggregated data based on a specified condition.
|
|
5463
|
-
*
|
|
5464
|
-
* See docs: {@link https://orm.drizzle.team/docs/select#aggregations}
|
|
5465
|
-
*
|
|
5466
|
-
* @param having the `having` clause.
|
|
5467
|
-
*
|
|
5468
|
-
* @example
|
|
5469
|
-
*
|
|
5470
|
-
* ```ts
|
|
5471
|
-
* // Select all brands with more than one car
|
|
5472
|
-
* await db.select({
|
|
5473
|
-
* brand: cars.brand,
|
|
5474
|
-
* count: sql<number>`cast(count(${cars.id}) as int)`,
|
|
5475
|
-
* })
|
|
5476
|
-
* .from(cars)
|
|
5477
|
-
* .groupBy(cars.brand)
|
|
5478
|
-
* .having(({ count }) => gt(count, 1));
|
|
5479
|
-
* ```
|
|
5480
|
-
*/
|
|
5481
|
-
having(having) {
|
|
5482
|
-
if (typeof having === "function") having = having(new Proxy(this.config.fields, new SelectionProxyHandler({
|
|
5483
|
-
sqlAliasedBehavior: "sql",
|
|
5484
|
-
sqlBehavior: "sql"
|
|
5485
|
-
})));
|
|
5486
|
-
this.config.having = having;
|
|
5487
|
-
return this;
|
|
5488
|
-
}
|
|
5489
|
-
groupBy(...columns) {
|
|
5490
|
-
if (typeof columns[0] === "function") {
|
|
5491
|
-
const groupBy = columns[0](new Proxy(this.config.fields, new SelectionProxyHandler({
|
|
5492
|
-
sqlAliasedBehavior: "alias",
|
|
5493
|
-
sqlBehavior: "sql"
|
|
5494
|
-
})));
|
|
5495
|
-
this.config.groupBy = Array.isArray(groupBy) ? groupBy : [groupBy];
|
|
5496
|
-
} else this.config.groupBy = columns;
|
|
5497
|
-
return this;
|
|
5498
|
-
}
|
|
5499
|
-
orderBy(...columns) {
|
|
5500
|
-
if (typeof columns[0] === "function") {
|
|
5501
|
-
const orderBy = columns[0](new Proxy(this.config.fields, new SelectionProxyHandler({
|
|
5502
|
-
sqlAliasedBehavior: "alias",
|
|
5503
|
-
sqlBehavior: "sql"
|
|
5504
|
-
})));
|
|
5505
|
-
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
|
5506
|
-
if (this.config.setOperators.length > 0) this.config.setOperators.at(-1).orderBy = orderByArray;
|
|
5507
|
-
else this.config.orderBy = orderByArray;
|
|
5508
|
-
} else {
|
|
5509
|
-
const orderByArray = columns;
|
|
5510
|
-
if (this.config.setOperators.length > 0) this.config.setOperators.at(-1).orderBy = orderByArray;
|
|
5511
|
-
else this.config.orderBy = orderByArray;
|
|
5512
|
-
}
|
|
5513
|
-
return this;
|
|
5514
|
-
}
|
|
5515
|
-
/**
|
|
5516
|
-
* Adds a `limit` clause to the query.
|
|
5517
|
-
*
|
|
5518
|
-
* Calling this method will set the maximum number of rows that will be returned by this query.
|
|
5519
|
-
*
|
|
5520
|
-
* See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}
|
|
5521
|
-
*
|
|
5522
|
-
* @param limit the `limit` clause.
|
|
5523
|
-
*
|
|
5524
|
-
* @example
|
|
5525
|
-
*
|
|
5526
|
-
* ```ts
|
|
5527
|
-
* // Get the first 10 people from this query.
|
|
5528
|
-
* await db.select().from(people).limit(10);
|
|
5529
|
-
* ```
|
|
5530
|
-
*/
|
|
5531
|
-
limit(limit) {
|
|
5532
|
-
if (this.config.setOperators.length > 0) this.config.setOperators.at(-1).limit = limit;
|
|
5533
|
-
else this.config.limit = limit;
|
|
5534
|
-
return this;
|
|
5535
|
-
}
|
|
5536
|
-
/**
|
|
5537
|
-
* Adds an `offset` clause to the query.
|
|
5538
|
-
*
|
|
5539
|
-
* Calling this method will skip a number of rows when returning results from this query.
|
|
5540
|
-
*
|
|
5541
|
-
* See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}
|
|
5542
|
-
*
|
|
5543
|
-
* @param offset the `offset` clause.
|
|
5544
|
-
*
|
|
5545
|
-
* @example
|
|
5546
|
-
*
|
|
5547
|
-
* ```ts
|
|
5548
|
-
* // Get the 10th-20th people from this query.
|
|
5549
|
-
* await db.select().from(people).offset(10).limit(10);
|
|
5550
|
-
* ```
|
|
5551
|
-
*/
|
|
5552
|
-
offset(offset) {
|
|
5553
|
-
if (this.config.setOperators.length > 0) this.config.setOperators.at(-1).offset = offset;
|
|
5554
|
-
else this.config.offset = offset;
|
|
5555
|
-
return this;
|
|
5556
|
-
}
|
|
5557
|
-
/** @internal */
|
|
5558
|
-
getSQL() {
|
|
5559
|
-
return this.dialect.buildSelectQuery(this.config);
|
|
5560
|
-
}
|
|
5561
|
-
toSQL() {
|
|
5562
|
-
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
|
5563
|
-
return rest;
|
|
5564
|
-
}
|
|
5565
|
-
as(alias) {
|
|
5566
|
-
const usedTables = [];
|
|
5567
|
-
usedTables.push(...extractUsedTable(this.config.table));
|
|
5568
|
-
if (this.config.joins) for (const it of this.config.joins) usedTables.push(...extractUsedTable(it.table));
|
|
5569
|
-
return new Proxy(new Subquery(this.getSQL(), this.config.fields, alias, false, [...new Set(usedTables)]), new SelectionProxyHandler({
|
|
5570
|
-
alias,
|
|
5571
|
-
sqlAliasedBehavior: "alias",
|
|
5572
|
-
sqlBehavior: "error"
|
|
5573
|
-
}));
|
|
5574
|
-
}
|
|
5575
|
-
/** @internal */
|
|
5576
|
-
getSelectedFields() {
|
|
5577
|
-
return new Proxy(this.config.fields, new SelectionProxyHandler({
|
|
5578
|
-
alias: this.tableName,
|
|
5579
|
-
sqlAliasedBehavior: "alias",
|
|
5580
|
-
sqlBehavior: "error"
|
|
5581
|
-
}));
|
|
5582
|
-
}
|
|
5583
|
-
$dynamic() {
|
|
5584
|
-
return this;
|
|
5585
|
-
}
|
|
5586
|
-
};
|
|
5587
|
-
var SQLiteSelectBase = class extends SQLiteSelectQueryBuilderBase {
|
|
5588
|
-
static [entityKind] = "SQLiteSelect";
|
|
5589
|
-
/** @internal */
|
|
5590
|
-
_prepare(isOneTimeQuery = true) {
|
|
5591
|
-
if (!this.session) throw new Error("Cannot execute a query on a query builder. Please use a database instance instead.");
|
|
5592
|
-
const fieldsList = orderSelectedFields(this.config.fields);
|
|
5593
|
-
const query = this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](this.dialect.sqlToQuery(this.getSQL()), fieldsList, "all", true, void 0, {
|
|
5594
|
-
type: "select",
|
|
5595
|
-
tables: [...this.usedTables]
|
|
5596
|
-
}, this.cacheConfig);
|
|
5597
|
-
query.joinsNotNullableMap = this.joinsNotNullableMap;
|
|
5598
|
-
return query;
|
|
5599
|
-
}
|
|
5600
|
-
$withCache(config) {
|
|
5601
|
-
this.cacheConfig = config === void 0 ? {
|
|
5602
|
-
config: {},
|
|
5603
|
-
enable: true,
|
|
5604
|
-
autoInvalidate: true
|
|
5605
|
-
} : config === false ? { enable: false } : {
|
|
5606
|
-
enable: true,
|
|
5607
|
-
autoInvalidate: true,
|
|
5608
|
-
...config
|
|
5609
|
-
};
|
|
5610
|
-
return this;
|
|
5611
|
-
}
|
|
5612
|
-
prepare() {
|
|
5613
|
-
return this._prepare(false);
|
|
5614
|
-
}
|
|
5615
|
-
run = (placeholderValues) => {
|
|
5616
|
-
return this._prepare().run(placeholderValues);
|
|
5617
|
-
};
|
|
5618
|
-
all = (placeholderValues) => {
|
|
5619
|
-
return this._prepare().all(placeholderValues);
|
|
5620
|
-
};
|
|
5621
|
-
get = (placeholderValues) => {
|
|
5622
|
-
return this._prepare().get(placeholderValues);
|
|
5623
|
-
};
|
|
5624
|
-
values = (placeholderValues) => {
|
|
5625
|
-
return this._prepare().values(placeholderValues);
|
|
5626
|
-
};
|
|
5627
|
-
async execute() {
|
|
5628
|
-
return this.all();
|
|
5629
|
-
}
|
|
5630
|
-
};
|
|
5631
|
-
applyMixins(SQLiteSelectBase, [QueryPromise]);
|
|
5632
|
-
function createSetOperator(type, isAll) {
|
|
5633
|
-
return (leftSelect, rightSelect, ...restSelects) => {
|
|
5634
|
-
const setOperators = [rightSelect, ...restSelects].map((select) => ({
|
|
5635
|
-
type,
|
|
5636
|
-
isAll,
|
|
5637
|
-
rightSelect: select
|
|
5638
|
-
}));
|
|
5639
|
-
for (const setOperator of setOperators) if (!haveSameKeys(leftSelect.getSelectedFields(), setOperator.rightSelect.getSelectedFields())) throw new Error("Set operator error (union / intersect / except): selected fields are not the same or are in a different order");
|
|
5640
|
-
return leftSelect.addSetOperators(setOperators);
|
|
5641
|
-
};
|
|
5642
|
-
}
|
|
5643
|
-
const getSQLiteSetOperators = () => ({
|
|
5644
|
-
union,
|
|
5645
|
-
unionAll,
|
|
5646
|
-
intersect,
|
|
5647
|
-
except
|
|
5648
|
-
});
|
|
5649
|
-
const union = createSetOperator("union", false);
|
|
5650
|
-
const unionAll = createSetOperator("union", true);
|
|
5651
|
-
const intersect = createSetOperator("intersect", false);
|
|
5652
|
-
const except = createSetOperator("except", false);
|
|
5653
|
-
//#endregion
|
|
5654
|
-
//#region node_modules/drizzle-orm/sqlite-core/query-builders/query-builder.js
|
|
5655
|
-
var QueryBuilder = class {
|
|
5656
|
-
static [entityKind] = "SQLiteQueryBuilder";
|
|
5657
|
-
dialect;
|
|
5658
|
-
dialectConfig;
|
|
5659
|
-
constructor(dialect) {
|
|
5660
|
-
this.dialect = is(dialect, SQLiteDialect) ? dialect : void 0;
|
|
5661
|
-
this.dialectConfig = is(dialect, SQLiteDialect) ? void 0 : dialect;
|
|
5662
|
-
}
|
|
5663
|
-
$with = (alias, selection) => {
|
|
5664
|
-
const queryBuilder = this;
|
|
5665
|
-
const as = (qb) => {
|
|
5666
|
-
if (typeof qb === "function") qb = qb(queryBuilder);
|
|
5667
|
-
return new Proxy(new WithSubquery(qb.getSQL(), selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}), alias, true), new SelectionProxyHandler({
|
|
5668
|
-
alias,
|
|
5669
|
-
sqlAliasedBehavior: "alias",
|
|
5670
|
-
sqlBehavior: "error"
|
|
5671
|
-
}));
|
|
5672
|
-
};
|
|
5673
|
-
return { as };
|
|
5674
|
-
};
|
|
5675
|
-
with(...queries) {
|
|
5676
|
-
const self = this;
|
|
5677
|
-
function select(fields) {
|
|
5678
|
-
return new SQLiteSelectBuilder({
|
|
5679
|
-
fields: fields ?? void 0,
|
|
5680
|
-
session: void 0,
|
|
5681
|
-
dialect: self.getDialect(),
|
|
5682
|
-
withList: queries
|
|
5683
|
-
});
|
|
5684
|
-
}
|
|
5685
|
-
function selectDistinct(fields) {
|
|
5686
|
-
return new SQLiteSelectBuilder({
|
|
5687
|
-
fields: fields ?? void 0,
|
|
5688
|
-
session: void 0,
|
|
5689
|
-
dialect: self.getDialect(),
|
|
5690
|
-
withList: queries,
|
|
5691
|
-
distinct: true
|
|
5692
|
-
});
|
|
5693
|
-
}
|
|
5694
|
-
return {
|
|
5695
|
-
select,
|
|
5696
|
-
selectDistinct
|
|
5697
|
-
};
|
|
5698
|
-
}
|
|
5699
|
-
select(fields) {
|
|
5700
|
-
return new SQLiteSelectBuilder({
|
|
5701
|
-
fields: fields ?? void 0,
|
|
5702
|
-
session: void 0,
|
|
5703
|
-
dialect: this.getDialect()
|
|
5704
|
-
});
|
|
5705
|
-
}
|
|
5706
|
-
selectDistinct(fields) {
|
|
5707
|
-
return new SQLiteSelectBuilder({
|
|
5708
|
-
fields: fields ?? void 0,
|
|
5709
|
-
session: void 0,
|
|
5710
|
-
dialect: this.getDialect(),
|
|
5711
|
-
distinct: true
|
|
5712
|
-
});
|
|
5713
|
-
}
|
|
5714
|
-
getDialect() {
|
|
5715
|
-
if (!this.dialect) this.dialect = new SQLiteSyncDialect(this.dialectConfig);
|
|
5716
|
-
return this.dialect;
|
|
5717
|
-
}
|
|
5718
|
-
};
|
|
5719
|
-
//#endregion
|
|
5720
|
-
//#region node_modules/drizzle-orm/sqlite-core/query-builders/insert.js
|
|
5721
|
-
var SQLiteInsertBuilder = class {
|
|
5722
|
-
constructor(table, session, dialect, withList) {
|
|
5723
|
-
this.table = table;
|
|
5724
|
-
this.session = session;
|
|
5725
|
-
this.dialect = dialect;
|
|
5726
|
-
this.withList = withList;
|
|
5727
|
-
}
|
|
5728
|
-
static [entityKind] = "SQLiteInsertBuilder";
|
|
5729
|
-
values(values) {
|
|
5730
|
-
values = Array.isArray(values) ? values : [values];
|
|
5731
|
-
if (values.length === 0) throw new Error("values() must be called with at least one value");
|
|
5732
|
-
const mappedValues = values.map((entry) => {
|
|
5733
|
-
const result = {};
|
|
5734
|
-
const cols = this.table[Table.Symbol.Columns];
|
|
5735
|
-
for (const colKey of Object.keys(entry)) {
|
|
5736
|
-
const colValue = entry[colKey];
|
|
5737
|
-
result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
|
|
5738
|
-
}
|
|
5739
|
-
return result;
|
|
5740
|
-
});
|
|
5741
|
-
return new SQLiteInsertBase(this.table, mappedValues, this.session, this.dialect, this.withList);
|
|
5742
|
-
}
|
|
5743
|
-
select(selectQuery) {
|
|
5744
|
-
const select = typeof selectQuery === "function" ? selectQuery(new QueryBuilder()) : selectQuery;
|
|
5745
|
-
if (!is(select, SQL) && !haveSameKeys(this.table[Columns], select._.selectedFields)) throw new Error("Insert select error: selected fields are not the same or are in a different order compared to the table definition");
|
|
5746
|
-
return new SQLiteInsertBase(this.table, select, this.session, this.dialect, this.withList, true);
|
|
5747
|
-
}
|
|
5748
|
-
};
|
|
5749
|
-
var SQLiteInsertBase = class extends QueryPromise {
|
|
5750
|
-
constructor(table, values, session, dialect, withList, select) {
|
|
5751
|
-
super();
|
|
5752
|
-
this.session = session;
|
|
5753
|
-
this.dialect = dialect;
|
|
5754
|
-
this.config = {
|
|
5755
|
-
table,
|
|
5756
|
-
values,
|
|
5757
|
-
withList,
|
|
5758
|
-
select
|
|
5759
|
-
};
|
|
5760
|
-
}
|
|
5761
|
-
static [entityKind] = "SQLiteInsert";
|
|
5762
|
-
/** @internal */
|
|
5763
|
-
config;
|
|
5764
|
-
returning(fields = this.config.table[SQLiteTable.Symbol.Columns]) {
|
|
5765
|
-
this.config.returning = orderSelectedFields(fields);
|
|
5766
|
-
return this;
|
|
5767
|
-
}
|
|
5768
|
-
/**
|
|
5769
|
-
* Adds an `on conflict do nothing` clause to the query.
|
|
5770
|
-
*
|
|
5771
|
-
* Calling this method simply avoids inserting a row as its alternative action.
|
|
5772
|
-
*
|
|
5773
|
-
* See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
|
|
5774
|
-
*
|
|
5775
|
-
* @param config The `target` and `where` clauses.
|
|
5776
|
-
*
|
|
5777
|
-
* @example
|
|
5778
|
-
* ```ts
|
|
5779
|
-
* // Insert one row and cancel the insert if there's a conflict
|
|
5780
|
-
* await db.insert(cars)
|
|
5781
|
-
* .values({ id: 1, brand: 'BMW' })
|
|
5782
|
-
* .onConflictDoNothing();
|
|
5783
|
-
*
|
|
5784
|
-
* // Explicitly specify conflict target
|
|
5785
|
-
* await db.insert(cars)
|
|
5786
|
-
* .values({ id: 1, brand: 'BMW' })
|
|
5787
|
-
* .onConflictDoNothing({ target: cars.id });
|
|
5788
|
-
* ```
|
|
5789
|
-
*/
|
|
5790
|
-
onConflictDoNothing(config = {}) {
|
|
5791
|
-
if (!this.config.onConflict) this.config.onConflict = [];
|
|
5792
|
-
if (config.target === void 0) this.config.onConflict.push(sql` on conflict do nothing`);
|
|
5793
|
-
else {
|
|
5794
|
-
const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
|
|
5795
|
-
const whereSql = config.where ? sql` where ${config.where}` : sql``;
|
|
5796
|
-
this.config.onConflict.push(sql` on conflict ${targetSql} do nothing${whereSql}`);
|
|
5797
|
-
}
|
|
5798
|
-
return this;
|
|
5799
|
-
}
|
|
5800
|
-
/**
|
|
5801
|
-
* Adds an `on conflict do update` clause to the query.
|
|
5802
|
-
*
|
|
5803
|
-
* Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
|
|
5804
|
-
*
|
|
5805
|
-
* See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
|
|
5806
|
-
*
|
|
5807
|
-
* @param config The `target`, `set` and `where` clauses.
|
|
5808
|
-
*
|
|
5809
|
-
* @example
|
|
5810
|
-
* ```ts
|
|
5811
|
-
* // Update the row if there's a conflict
|
|
5812
|
-
* await db.insert(cars)
|
|
5813
|
-
* .values({ id: 1, brand: 'BMW' })
|
|
5814
|
-
* .onConflictDoUpdate({
|
|
5815
|
-
* target: cars.id,
|
|
5816
|
-
* set: { brand: 'Porsche' }
|
|
5817
|
-
* });
|
|
5818
|
-
*
|
|
5819
|
-
* // Upsert with 'where' clause
|
|
5820
|
-
* await db.insert(cars)
|
|
5821
|
-
* .values({ id: 1, brand: 'BMW' })
|
|
5822
|
-
* .onConflictDoUpdate({
|
|
5823
|
-
* target: cars.id,
|
|
5824
|
-
* set: { brand: 'newBMW' },
|
|
5825
|
-
* where: sql`${cars.createdAt} > '2023-01-01'::date`,
|
|
5826
|
-
* });
|
|
5827
|
-
* ```
|
|
5828
|
-
*/
|
|
5829
|
-
onConflictDoUpdate(config) {
|
|
5830
|
-
if (config.where && (config.targetWhere || config.setWhere)) throw new Error("You cannot use both \"where\" and \"targetWhere\"/\"setWhere\" at the same time - \"where\" is deprecated, use \"targetWhere\" or \"setWhere\" instead.");
|
|
5831
|
-
if (!this.config.onConflict) this.config.onConflict = [];
|
|
5832
|
-
const whereSql = config.where ? sql` where ${config.where}` : void 0;
|
|
5833
|
-
const targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : void 0;
|
|
5834
|
-
const setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : void 0;
|
|
5835
|
-
const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
|
|
5836
|
-
const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
|
|
5837
|
-
this.config.onConflict.push(sql` on conflict ${targetSql}${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`);
|
|
5838
|
-
return this;
|
|
5839
|
-
}
|
|
5840
|
-
/** @internal */
|
|
5841
|
-
getSQL() {
|
|
5842
|
-
return this.dialect.buildInsertQuery(this.config);
|
|
5843
|
-
}
|
|
5844
|
-
toSQL() {
|
|
5845
|
-
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
|
5846
|
-
return rest;
|
|
5847
|
-
}
|
|
5848
|
-
/** @internal */
|
|
5849
|
-
_prepare(isOneTimeQuery = true) {
|
|
5850
|
-
return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](this.dialect.sqlToQuery(this.getSQL()), this.config.returning, this.config.returning ? "all" : "run", true, void 0, {
|
|
5851
|
-
type: "insert",
|
|
5852
|
-
tables: extractUsedTable(this.config.table)
|
|
5853
|
-
});
|
|
5854
|
-
}
|
|
5855
|
-
prepare() {
|
|
5856
|
-
return this._prepare(false);
|
|
5857
|
-
}
|
|
5858
|
-
run = (placeholderValues) => {
|
|
5859
|
-
return this._prepare().run(placeholderValues);
|
|
5860
|
-
};
|
|
5861
|
-
all = (placeholderValues) => {
|
|
5862
|
-
return this._prepare().all(placeholderValues);
|
|
5863
|
-
};
|
|
5864
|
-
get = (placeholderValues) => {
|
|
5865
|
-
return this._prepare().get(placeholderValues);
|
|
5866
|
-
};
|
|
5867
|
-
values = (placeholderValues) => {
|
|
5868
|
-
return this._prepare().values(placeholderValues);
|
|
5869
|
-
};
|
|
5870
|
-
async execute() {
|
|
5871
|
-
return this.config.returning ? this.all() : this.run();
|
|
5872
|
-
}
|
|
5873
|
-
$dynamic() {
|
|
5874
|
-
return this;
|
|
5875
|
-
}
|
|
5876
|
-
};
|
|
5877
|
-
//#endregion
|
|
5878
|
-
//#region node_modules/drizzle-orm/sqlite-core/query-builders/update.js
|
|
5879
|
-
var SQLiteUpdateBuilder = class {
|
|
5880
|
-
constructor(table, session, dialect, withList) {
|
|
5881
|
-
this.table = table;
|
|
5882
|
-
this.session = session;
|
|
5883
|
-
this.dialect = dialect;
|
|
5884
|
-
this.withList = withList;
|
|
5885
|
-
}
|
|
5886
|
-
static [entityKind] = "SQLiteUpdateBuilder";
|
|
5887
|
-
set(values) {
|
|
5888
|
-
return new SQLiteUpdateBase(this.table, mapUpdateSet(this.table, values), this.session, this.dialect, this.withList);
|
|
5889
|
-
}
|
|
5890
|
-
};
|
|
5891
|
-
var SQLiteUpdateBase = class extends QueryPromise {
|
|
5892
|
-
constructor(table, set, session, dialect, withList) {
|
|
5893
|
-
super();
|
|
5894
|
-
this.session = session;
|
|
5895
|
-
this.dialect = dialect;
|
|
5896
|
-
this.config = {
|
|
5897
|
-
set,
|
|
5898
|
-
table,
|
|
5899
|
-
withList,
|
|
5900
|
-
joins: []
|
|
5901
|
-
};
|
|
5902
|
-
}
|
|
5903
|
-
static [entityKind] = "SQLiteUpdate";
|
|
5904
|
-
/** @internal */
|
|
5905
|
-
config;
|
|
5906
|
-
from(source) {
|
|
5907
|
-
this.config.from = source;
|
|
5908
|
-
return this;
|
|
5909
|
-
}
|
|
5910
|
-
createJoin(joinType) {
|
|
5911
|
-
return (table, on) => {
|
|
5912
|
-
const tableName = getTableLikeName(table);
|
|
5913
|
-
if (typeof tableName === "string" && this.config.joins.some((join) => join.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
5914
|
-
if (typeof on === "function") {
|
|
5915
|
-
const from = this.config.from ? is(table, SQLiteTable) ? table[Table.Symbol.Columns] : is(table, Subquery) ? table._.selectedFields : is(table, SQLiteViewBase) ? table[ViewBaseConfig].selectedFields : void 0 : void 0;
|
|
5916
|
-
on = on(new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
|
|
5917
|
-
sqlAliasedBehavior: "sql",
|
|
5918
|
-
sqlBehavior: "sql"
|
|
5919
|
-
})), from && new Proxy(from, new SelectionProxyHandler({
|
|
5920
|
-
sqlAliasedBehavior: "sql",
|
|
5921
|
-
sqlBehavior: "sql"
|
|
5922
|
-
})));
|
|
5923
|
-
}
|
|
5924
|
-
this.config.joins.push({
|
|
5925
|
-
on,
|
|
5926
|
-
table,
|
|
5927
|
-
joinType,
|
|
5928
|
-
alias: tableName
|
|
5929
|
-
});
|
|
5930
|
-
return this;
|
|
5931
|
-
};
|
|
5932
|
-
}
|
|
5933
|
-
leftJoin = this.createJoin("left");
|
|
5934
|
-
rightJoin = this.createJoin("right");
|
|
5935
|
-
innerJoin = this.createJoin("inner");
|
|
5936
|
-
fullJoin = this.createJoin("full");
|
|
5937
|
-
/**
|
|
5938
|
-
* Adds a 'where' clause to the query.
|
|
5939
|
-
*
|
|
5940
|
-
* Calling this method will update only those rows that fulfill a specified condition.
|
|
5941
|
-
*
|
|
5942
|
-
* See docs: {@link https://orm.drizzle.team/docs/update}
|
|
5943
|
-
*
|
|
5944
|
-
* @param where the 'where' clause.
|
|
5945
|
-
*
|
|
5946
|
-
* @example
|
|
5947
|
-
* You can use conditional operators and `sql function` to filter the rows to be updated.
|
|
5948
|
-
*
|
|
5949
|
-
* ```ts
|
|
5950
|
-
* // Update all cars with green color
|
|
5951
|
-
* db.update(cars).set({ color: 'red' })
|
|
5952
|
-
* .where(eq(cars.color, 'green'));
|
|
5953
|
-
* // or
|
|
5954
|
-
* db.update(cars).set({ color: 'red' })
|
|
5955
|
-
* .where(sql`${cars.color} = 'green'`)
|
|
5956
|
-
* ```
|
|
5957
|
-
*
|
|
5958
|
-
* You can logically combine conditional operators with `and()` and `or()` operators:
|
|
5959
|
-
*
|
|
5960
|
-
* ```ts
|
|
5961
|
-
* // Update all BMW cars with a green color
|
|
5962
|
-
* db.update(cars).set({ color: 'red' })
|
|
5963
|
-
* .where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
|
5964
|
-
*
|
|
5965
|
-
* // Update all cars with the green or blue color
|
|
5966
|
-
* db.update(cars).set({ color: 'red' })
|
|
5967
|
-
* .where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
|
5968
|
-
* ```
|
|
5969
|
-
*/
|
|
5970
|
-
where(where) {
|
|
5971
|
-
this.config.where = where;
|
|
5972
|
-
return this;
|
|
5973
|
-
}
|
|
5974
|
-
orderBy(...columns) {
|
|
5975
|
-
if (typeof columns[0] === "function") {
|
|
5976
|
-
const orderBy = columns[0](new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
|
|
5977
|
-
sqlAliasedBehavior: "alias",
|
|
5978
|
-
sqlBehavior: "sql"
|
|
5979
|
-
})));
|
|
5980
|
-
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
|
5981
|
-
this.config.orderBy = orderByArray;
|
|
5982
|
-
} else {
|
|
5983
|
-
const orderByArray = columns;
|
|
5984
|
-
this.config.orderBy = orderByArray;
|
|
5985
|
-
}
|
|
5986
|
-
return this;
|
|
5987
|
-
}
|
|
5988
|
-
limit(limit) {
|
|
5989
|
-
this.config.limit = limit;
|
|
5990
|
-
return this;
|
|
5991
|
-
}
|
|
5992
|
-
returning(fields = this.config.table[SQLiteTable.Symbol.Columns]) {
|
|
5993
|
-
this.config.returning = orderSelectedFields(fields);
|
|
5994
|
-
return this;
|
|
5995
|
-
}
|
|
5996
|
-
/** @internal */
|
|
5997
|
-
getSQL() {
|
|
5998
|
-
return this.dialect.buildUpdateQuery(this.config);
|
|
5999
|
-
}
|
|
6000
|
-
toSQL() {
|
|
6001
|
-
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
|
6002
|
-
return rest;
|
|
6003
|
-
}
|
|
6004
|
-
/** @internal */
|
|
6005
|
-
_prepare(isOneTimeQuery = true) {
|
|
6006
|
-
return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](this.dialect.sqlToQuery(this.getSQL()), this.config.returning, this.config.returning ? "all" : "run", true, void 0, {
|
|
6007
|
-
type: "insert",
|
|
6008
|
-
tables: extractUsedTable(this.config.table)
|
|
6009
|
-
});
|
|
6010
|
-
}
|
|
6011
|
-
prepare() {
|
|
6012
|
-
return this._prepare(false);
|
|
6013
|
-
}
|
|
6014
|
-
run = (placeholderValues) => {
|
|
6015
|
-
return this._prepare().run(placeholderValues);
|
|
6016
|
-
};
|
|
6017
|
-
all = (placeholderValues) => {
|
|
6018
|
-
return this._prepare().all(placeholderValues);
|
|
6019
|
-
};
|
|
6020
|
-
get = (placeholderValues) => {
|
|
6021
|
-
return this._prepare().get(placeholderValues);
|
|
6022
|
-
};
|
|
6023
|
-
values = (placeholderValues) => {
|
|
6024
|
-
return this._prepare().values(placeholderValues);
|
|
6025
|
-
};
|
|
6026
|
-
async execute() {
|
|
6027
|
-
return this.config.returning ? this.all() : this.run();
|
|
6028
|
-
}
|
|
6029
|
-
$dynamic() {
|
|
6030
|
-
return this;
|
|
6031
|
-
}
|
|
6032
|
-
};
|
|
6033
|
-
//#endregion
|
|
6034
|
-
//#region node_modules/drizzle-orm/sqlite-core/query-builders/count.js
|
|
6035
|
-
var SQLiteCountBuilder = class SQLiteCountBuilder extends SQL {
|
|
6036
|
-
constructor(params) {
|
|
6037
|
-
super(SQLiteCountBuilder.buildEmbeddedCount(params.source, params.filters).queryChunks);
|
|
6038
|
-
this.params = params;
|
|
6039
|
-
this.session = params.session;
|
|
6040
|
-
this.sql = SQLiteCountBuilder.buildCount(params.source, params.filters);
|
|
6041
|
-
}
|
|
6042
|
-
sql;
|
|
6043
|
-
static [entityKind] = "SQLiteCountBuilderAsync";
|
|
6044
|
-
[Symbol.toStringTag] = "SQLiteCountBuilderAsync";
|
|
6045
|
-
session;
|
|
6046
|
-
static buildEmbeddedCount(source, filters) {
|
|
6047
|
-
return sql`(select count(*) from ${source}${sql.raw(" where ").if(filters)}${filters})`;
|
|
6048
|
-
}
|
|
6049
|
-
static buildCount(source, filters) {
|
|
6050
|
-
return sql`select count(*) from ${source}${sql.raw(" where ").if(filters)}${filters}`;
|
|
6051
|
-
}
|
|
6052
|
-
then(onfulfilled, onrejected) {
|
|
6053
|
-
return Promise.resolve(this.session.count(this.sql)).then(onfulfilled, onrejected);
|
|
6054
|
-
}
|
|
6055
|
-
catch(onRejected) {
|
|
6056
|
-
return this.then(void 0, onRejected);
|
|
6057
|
-
}
|
|
6058
|
-
finally(onFinally) {
|
|
6059
|
-
return this.then((value) => {
|
|
6060
|
-
onFinally?.();
|
|
6061
|
-
return value;
|
|
6062
|
-
}, (reason) => {
|
|
6063
|
-
onFinally?.();
|
|
6064
|
-
throw reason;
|
|
6065
|
-
});
|
|
6066
|
-
}
|
|
6067
|
-
};
|
|
6068
|
-
//#endregion
|
|
6069
|
-
//#region node_modules/drizzle-orm/sqlite-core/query-builders/query.js
|
|
6070
|
-
var RelationalQueryBuilder = class {
|
|
6071
|
-
constructor(mode, fullSchema, schema, tableNamesMap, table, tableConfig, dialect, session) {
|
|
6072
|
-
this.mode = mode;
|
|
6073
|
-
this.fullSchema = fullSchema;
|
|
6074
|
-
this.schema = schema;
|
|
6075
|
-
this.tableNamesMap = tableNamesMap;
|
|
6076
|
-
this.table = table;
|
|
6077
|
-
this.tableConfig = tableConfig;
|
|
6078
|
-
this.dialect = dialect;
|
|
6079
|
-
this.session = session;
|
|
6080
|
-
}
|
|
6081
|
-
static [entityKind] = "SQLiteAsyncRelationalQueryBuilder";
|
|
6082
|
-
findMany(config) {
|
|
6083
|
-
return this.mode === "sync" ? new SQLiteSyncRelationalQuery(this.fullSchema, this.schema, this.tableNamesMap, this.table, this.tableConfig, this.dialect, this.session, config ? config : {}, "many") : new SQLiteRelationalQuery(this.fullSchema, this.schema, this.tableNamesMap, this.table, this.tableConfig, this.dialect, this.session, config ? config : {}, "many");
|
|
6084
|
-
}
|
|
6085
|
-
findFirst(config) {
|
|
6086
|
-
return this.mode === "sync" ? new SQLiteSyncRelationalQuery(this.fullSchema, this.schema, this.tableNamesMap, this.table, this.tableConfig, this.dialect, this.session, config ? {
|
|
6087
|
-
...config,
|
|
6088
|
-
limit: 1
|
|
6089
|
-
} : { limit: 1 }, "first") : new SQLiteRelationalQuery(this.fullSchema, this.schema, this.tableNamesMap, this.table, this.tableConfig, this.dialect, this.session, config ? {
|
|
6090
|
-
...config,
|
|
6091
|
-
limit: 1
|
|
6092
|
-
} : { limit: 1 }, "first");
|
|
6093
|
-
}
|
|
6094
|
-
};
|
|
6095
|
-
var SQLiteRelationalQuery = class extends QueryPromise {
|
|
6096
|
-
constructor(fullSchema, schema, tableNamesMap, table, tableConfig, dialect, session, config, mode) {
|
|
6097
|
-
super();
|
|
6098
|
-
this.fullSchema = fullSchema;
|
|
6099
|
-
this.schema = schema;
|
|
6100
|
-
this.tableNamesMap = tableNamesMap;
|
|
6101
|
-
this.table = table;
|
|
6102
|
-
this.tableConfig = tableConfig;
|
|
6103
|
-
this.dialect = dialect;
|
|
6104
|
-
this.session = session;
|
|
6105
|
-
this.config = config;
|
|
6106
|
-
this.mode = mode;
|
|
6107
|
-
}
|
|
6108
|
-
static [entityKind] = "SQLiteAsyncRelationalQuery";
|
|
6109
|
-
/** @internal */
|
|
6110
|
-
mode;
|
|
6111
|
-
/** @internal */
|
|
6112
|
-
getSQL() {
|
|
6113
|
-
return this.dialect.buildRelationalQuery({
|
|
6114
|
-
fullSchema: this.fullSchema,
|
|
6115
|
-
schema: this.schema,
|
|
6116
|
-
tableNamesMap: this.tableNamesMap,
|
|
6117
|
-
table: this.table,
|
|
6118
|
-
tableConfig: this.tableConfig,
|
|
6119
|
-
queryConfig: this.config,
|
|
6120
|
-
tableAlias: this.tableConfig.tsName
|
|
6121
|
-
}).sql;
|
|
6122
|
-
}
|
|
6123
|
-
/** @internal */
|
|
6124
|
-
_prepare(isOneTimeQuery = false) {
|
|
6125
|
-
const { query, builtQuery } = this._toSQL();
|
|
6126
|
-
return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](builtQuery, void 0, this.mode === "first" ? "get" : "all", true, (rawRows, mapColumnValue) => {
|
|
6127
|
-
const rows = rawRows.map((row) => mapRelationalRow(this.schema, this.tableConfig, row, query.selection, mapColumnValue));
|
|
6128
|
-
if (this.mode === "first") return rows[0];
|
|
6129
|
-
return rows;
|
|
6130
|
-
});
|
|
6131
|
-
}
|
|
6132
|
-
prepare() {
|
|
6133
|
-
return this._prepare(false);
|
|
6134
|
-
}
|
|
6135
|
-
_toSQL() {
|
|
6136
|
-
const query = this.dialect.buildRelationalQuery({
|
|
6137
|
-
fullSchema: this.fullSchema,
|
|
6138
|
-
schema: this.schema,
|
|
6139
|
-
tableNamesMap: this.tableNamesMap,
|
|
6140
|
-
table: this.table,
|
|
6141
|
-
tableConfig: this.tableConfig,
|
|
6142
|
-
queryConfig: this.config,
|
|
6143
|
-
tableAlias: this.tableConfig.tsName
|
|
6144
|
-
});
|
|
6145
|
-
return {
|
|
6146
|
-
query,
|
|
6147
|
-
builtQuery: this.dialect.sqlToQuery(query.sql)
|
|
6148
|
-
};
|
|
6149
|
-
}
|
|
6150
|
-
toSQL() {
|
|
6151
|
-
return this._toSQL().builtQuery;
|
|
6152
|
-
}
|
|
6153
|
-
/** @internal */
|
|
6154
|
-
executeRaw() {
|
|
6155
|
-
if (this.mode === "first") return this._prepare(false).get();
|
|
6156
|
-
return this._prepare(false).all();
|
|
6157
|
-
}
|
|
6158
|
-
async execute() {
|
|
6159
|
-
return this.executeRaw();
|
|
6160
|
-
}
|
|
6161
|
-
};
|
|
6162
|
-
var SQLiteSyncRelationalQuery = class extends SQLiteRelationalQuery {
|
|
6163
|
-
static [entityKind] = "SQLiteSyncRelationalQuery";
|
|
6164
|
-
sync() {
|
|
6165
|
-
return this.executeRaw();
|
|
6166
|
-
}
|
|
6167
|
-
};
|
|
6168
|
-
//#endregion
|
|
6169
|
-
//#region node_modules/drizzle-orm/sqlite-core/query-builders/raw.js
|
|
6170
|
-
var SQLiteRaw = class extends QueryPromise {
|
|
6171
|
-
constructor(execute, getSQL, action, dialect, mapBatchResult) {
|
|
6172
|
-
super();
|
|
6173
|
-
this.execute = execute;
|
|
6174
|
-
this.getSQL = getSQL;
|
|
6175
|
-
this.dialect = dialect;
|
|
6176
|
-
this.mapBatchResult = mapBatchResult;
|
|
6177
|
-
this.config = { action };
|
|
6178
|
-
}
|
|
6179
|
-
static [entityKind] = "SQLiteRaw";
|
|
6180
|
-
/** @internal */
|
|
6181
|
-
config;
|
|
6182
|
-
getQuery() {
|
|
6183
|
-
return {
|
|
6184
|
-
...this.dialect.sqlToQuery(this.getSQL()),
|
|
6185
|
-
method: this.config.action
|
|
6186
|
-
};
|
|
6187
|
-
}
|
|
6188
|
-
mapResult(result, isFromBatch) {
|
|
6189
|
-
return isFromBatch ? this.mapBatchResult(result) : result;
|
|
6190
|
-
}
|
|
6191
|
-
_prepare() {
|
|
6192
|
-
return this;
|
|
6193
|
-
}
|
|
6194
|
-
/** @internal */
|
|
6195
|
-
isResponseInArrayMode() {
|
|
6196
|
-
return false;
|
|
6197
|
-
}
|
|
6198
|
-
};
|
|
6199
|
-
//#endregion
|
|
6200
|
-
//#region node_modules/drizzle-orm/sqlite-core/db.js
|
|
6201
|
-
var BaseSQLiteDatabase = class {
|
|
6202
|
-
constructor(resultKind, dialect, session, schema) {
|
|
6203
|
-
this.resultKind = resultKind;
|
|
6204
|
-
this.dialect = dialect;
|
|
6205
|
-
this.session = session;
|
|
6206
|
-
this._ = schema ? {
|
|
6207
|
-
schema: schema.schema,
|
|
6208
|
-
fullSchema: schema.fullSchema,
|
|
6209
|
-
tableNamesMap: schema.tableNamesMap
|
|
6210
|
-
} : {
|
|
6211
|
-
schema: void 0,
|
|
6212
|
-
fullSchema: {},
|
|
6213
|
-
tableNamesMap: {}
|
|
6214
|
-
};
|
|
6215
|
-
this.query = {};
|
|
6216
|
-
const query = this.query;
|
|
6217
|
-
if (this._.schema) for (const [tableName, columns] of Object.entries(this._.schema)) query[tableName] = new RelationalQueryBuilder(resultKind, schema.fullSchema, this._.schema, this._.tableNamesMap, schema.fullSchema[tableName], columns, dialect, session);
|
|
6218
|
-
this.$cache = { invalidate: async (_params) => {} };
|
|
6219
|
-
}
|
|
6220
|
-
static [entityKind] = "BaseSQLiteDatabase";
|
|
6221
|
-
query;
|
|
6222
|
-
/**
|
|
6223
|
-
* Creates a subquery that defines a temporary named result set as a CTE.
|
|
6224
|
-
*
|
|
6225
|
-
* It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
|
|
6226
|
-
*
|
|
6227
|
-
* See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
|
|
6228
|
-
*
|
|
6229
|
-
* @param alias The alias for the subquery.
|
|
6230
|
-
*
|
|
6231
|
-
* Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
|
|
6232
|
-
*
|
|
6233
|
-
* @example
|
|
6234
|
-
*
|
|
6235
|
-
* ```ts
|
|
6236
|
-
* // Create a subquery with alias 'sq' and use it in the select query
|
|
6237
|
-
* const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
|
|
6238
|
-
*
|
|
6239
|
-
* const result = await db.with(sq).select().from(sq);
|
|
6240
|
-
* ```
|
|
6241
|
-
*
|
|
6242
|
-
* To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:
|
|
6243
|
-
*
|
|
6244
|
-
* ```ts
|
|
6245
|
-
* // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
|
|
6246
|
-
* const sq = db.$with('sq').as(db.select({
|
|
6247
|
-
* name: sql<string>`upper(${users.name})`.as('name'),
|
|
6248
|
-
* })
|
|
6249
|
-
* .from(users));
|
|
6250
|
-
*
|
|
6251
|
-
* const result = await db.with(sq).select({ name: sq.name }).from(sq);
|
|
6252
|
-
* ```
|
|
6253
|
-
*/
|
|
6254
|
-
$with = (alias, selection) => {
|
|
6255
|
-
const self = this;
|
|
6256
|
-
const as = (qb) => {
|
|
6257
|
-
if (typeof qb === "function") qb = qb(new QueryBuilder(self.dialect));
|
|
6258
|
-
return new Proxy(new WithSubquery(qb.getSQL(), selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}), alias, true), new SelectionProxyHandler({
|
|
6259
|
-
alias,
|
|
6260
|
-
sqlAliasedBehavior: "alias",
|
|
6261
|
-
sqlBehavior: "error"
|
|
6262
|
-
}));
|
|
6263
|
-
};
|
|
6264
|
-
return { as };
|
|
6265
|
-
};
|
|
6266
|
-
$count(source, filters) {
|
|
6267
|
-
return new SQLiteCountBuilder({
|
|
6268
|
-
source,
|
|
6269
|
-
filters,
|
|
6270
|
-
session: this.session
|
|
6271
|
-
});
|
|
6272
|
-
}
|
|
6273
|
-
/**
|
|
6274
|
-
* Incorporates a previously defined CTE (using `$with`) into the main query.
|
|
6275
|
-
*
|
|
6276
|
-
* This method allows the main query to reference a temporary named result set.
|
|
6277
|
-
*
|
|
6278
|
-
* See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
|
|
6279
|
-
*
|
|
6280
|
-
* @param queries The CTEs to incorporate into the main query.
|
|
6281
|
-
*
|
|
6282
|
-
* @example
|
|
6283
|
-
*
|
|
6284
|
-
* ```ts
|
|
6285
|
-
* // Define a subquery 'sq' as a CTE using $with
|
|
6286
|
-
* const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
|
|
6287
|
-
*
|
|
6288
|
-
* // Incorporate the CTE 'sq' into the main query and select from it
|
|
6289
|
-
* const result = await db.with(sq).select().from(sq);
|
|
6290
|
-
* ```
|
|
6291
|
-
*/
|
|
6292
|
-
with(...queries) {
|
|
6293
|
-
const self = this;
|
|
6294
|
-
function select(fields) {
|
|
6295
|
-
return new SQLiteSelectBuilder({
|
|
6296
|
-
fields: fields ?? void 0,
|
|
6297
|
-
session: self.session,
|
|
6298
|
-
dialect: self.dialect,
|
|
6299
|
-
withList: queries
|
|
6300
|
-
});
|
|
6301
|
-
}
|
|
6302
|
-
function selectDistinct(fields) {
|
|
6303
|
-
return new SQLiteSelectBuilder({
|
|
6304
|
-
fields: fields ?? void 0,
|
|
6305
|
-
session: self.session,
|
|
6306
|
-
dialect: self.dialect,
|
|
6307
|
-
withList: queries,
|
|
6308
|
-
distinct: true
|
|
6309
|
-
});
|
|
6310
|
-
}
|
|
6311
|
-
function update(table) {
|
|
6312
|
-
return new SQLiteUpdateBuilder(table, self.session, self.dialect, queries);
|
|
6313
|
-
}
|
|
6314
|
-
function insert(into) {
|
|
6315
|
-
return new SQLiteInsertBuilder(into, self.session, self.dialect, queries);
|
|
6316
|
-
}
|
|
6317
|
-
function delete_(from) {
|
|
6318
|
-
return new SQLiteDeleteBase(from, self.session, self.dialect, queries);
|
|
6319
|
-
}
|
|
6320
|
-
return {
|
|
6321
|
-
select,
|
|
6322
|
-
selectDistinct,
|
|
6323
|
-
update,
|
|
6324
|
-
insert,
|
|
6325
|
-
delete: delete_
|
|
6326
|
-
};
|
|
6327
|
-
}
|
|
6328
|
-
select(fields) {
|
|
6329
|
-
return new SQLiteSelectBuilder({
|
|
6330
|
-
fields: fields ?? void 0,
|
|
6331
|
-
session: this.session,
|
|
6332
|
-
dialect: this.dialect
|
|
6333
|
-
});
|
|
6334
|
-
}
|
|
6335
|
-
selectDistinct(fields) {
|
|
6336
|
-
return new SQLiteSelectBuilder({
|
|
6337
|
-
fields: fields ?? void 0,
|
|
6338
|
-
session: this.session,
|
|
6339
|
-
dialect: this.dialect,
|
|
6340
|
-
distinct: true
|
|
6341
|
-
});
|
|
6342
|
-
}
|
|
6343
|
-
/**
|
|
6344
|
-
* Creates an update query.
|
|
6345
|
-
*
|
|
6346
|
-
* Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.
|
|
6347
|
-
*
|
|
6348
|
-
* Use `.set()` method to specify which values to update.
|
|
6349
|
-
*
|
|
6350
|
-
* See docs: {@link https://orm.drizzle.team/docs/update}
|
|
6351
|
-
*
|
|
6352
|
-
* @param table The table to update.
|
|
6353
|
-
*
|
|
6354
|
-
* @example
|
|
6355
|
-
*
|
|
6356
|
-
* ```ts
|
|
6357
|
-
* // Update all rows in the 'cars' table
|
|
6358
|
-
* await db.update(cars).set({ color: 'red' });
|
|
6359
|
-
*
|
|
6360
|
-
* // Update rows with filters and conditions
|
|
6361
|
-
* await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));
|
|
6362
|
-
*
|
|
6363
|
-
* // Update with returning clause
|
|
6364
|
-
* const updatedCar: Car[] = await db.update(cars)
|
|
6365
|
-
* .set({ color: 'red' })
|
|
6366
|
-
* .where(eq(cars.id, 1))
|
|
6367
|
-
* .returning();
|
|
6368
|
-
* ```
|
|
6369
|
-
*/
|
|
6370
|
-
update(table) {
|
|
6371
|
-
return new SQLiteUpdateBuilder(table, this.session, this.dialect);
|
|
6372
|
-
}
|
|
6373
|
-
$cache;
|
|
6374
|
-
/**
|
|
6375
|
-
* Creates an insert query.
|
|
6376
|
-
*
|
|
6377
|
-
* Calling this method will create new rows in a table. Use `.values()` method to specify which values to insert.
|
|
6378
|
-
*
|
|
6379
|
-
* See docs: {@link https://orm.drizzle.team/docs/insert}
|
|
6380
|
-
*
|
|
6381
|
-
* @param table The table to insert into.
|
|
6382
|
-
*
|
|
6383
|
-
* @example
|
|
6384
|
-
*
|
|
6385
|
-
* ```ts
|
|
6386
|
-
* // Insert one row
|
|
6387
|
-
* await db.insert(cars).values({ brand: 'BMW' });
|
|
6388
|
-
*
|
|
6389
|
-
* // Insert multiple rows
|
|
6390
|
-
* await db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);
|
|
6391
|
-
*
|
|
6392
|
-
* // Insert with returning clause
|
|
6393
|
-
* const insertedCar: Car[] = await db.insert(cars)
|
|
6394
|
-
* .values({ brand: 'BMW' })
|
|
6395
|
-
* .returning();
|
|
6396
|
-
* ```
|
|
6397
|
-
*/
|
|
6398
|
-
insert(into) {
|
|
6399
|
-
return new SQLiteInsertBuilder(into, this.session, this.dialect);
|
|
2462
|
+
add(method, path, handler) {
|
|
2463
|
+
const results = checkOptionalParameter(path);
|
|
2464
|
+
if (results) {
|
|
2465
|
+
for (let i = 0, len = results.length; i < len; i++) this.#node.insert(method, results[i], handler);
|
|
2466
|
+
return;
|
|
2467
|
+
}
|
|
2468
|
+
this.#node.insert(method, path, handler);
|
|
2469
|
+
}
|
|
2470
|
+
match(method, path) {
|
|
2471
|
+
return this.#node.search(method, path);
|
|
6400
2472
|
}
|
|
2473
|
+
};
|
|
2474
|
+
//#endregion
|
|
2475
|
+
//#region node_modules/hono/dist/hono.js
|
|
2476
|
+
var Hono = class extends Hono$1 {
|
|
6401
2477
|
/**
|
|
6402
|
-
* Creates
|
|
6403
|
-
*
|
|
6404
|
-
* Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.
|
|
6405
|
-
*
|
|
6406
|
-
* See docs: {@link https://orm.drizzle.team/docs/delete}
|
|
6407
|
-
*
|
|
6408
|
-
* @param table The table to delete from.
|
|
6409
|
-
*
|
|
6410
|
-
* @example
|
|
6411
|
-
*
|
|
6412
|
-
* ```ts
|
|
6413
|
-
* // Delete all rows in the 'cars' table
|
|
6414
|
-
* await db.delete(cars);
|
|
6415
|
-
*
|
|
6416
|
-
* // Delete rows with filters and conditions
|
|
6417
|
-
* await db.delete(cars).where(eq(cars.color, 'green'));
|
|
2478
|
+
* Creates an instance of the Hono class.
|
|
6418
2479
|
*
|
|
6419
|
-
*
|
|
6420
|
-
* const deletedCar: Car[] = await db.delete(cars)
|
|
6421
|
-
* .where(eq(cars.id, 1))
|
|
6422
|
-
* .returning();
|
|
6423
|
-
* ```
|
|
2480
|
+
* @param options - Optional configuration options for the Hono instance.
|
|
6424
2481
|
*/
|
|
6425
|
-
|
|
6426
|
-
|
|
6427
|
-
|
|
6428
|
-
run(query) {
|
|
6429
|
-
const sequel = typeof query === "string" ? sql.raw(query) : query.getSQL();
|
|
6430
|
-
if (this.resultKind === "async") return new SQLiteRaw(async () => this.session.run(sequel), () => sequel, "run", this.dialect, this.session.extractRawRunValueFromBatchResult.bind(this.session));
|
|
6431
|
-
return this.session.run(sequel);
|
|
6432
|
-
}
|
|
6433
|
-
all(query) {
|
|
6434
|
-
const sequel = typeof query === "string" ? sql.raw(query) : query.getSQL();
|
|
6435
|
-
if (this.resultKind === "async") return new SQLiteRaw(async () => this.session.all(sequel), () => sequel, "all", this.dialect, this.session.extractRawAllValueFromBatchResult.bind(this.session));
|
|
6436
|
-
return this.session.all(sequel);
|
|
6437
|
-
}
|
|
6438
|
-
get(query) {
|
|
6439
|
-
const sequel = typeof query === "string" ? sql.raw(query) : query.getSQL();
|
|
6440
|
-
if (this.resultKind === "async") return new SQLiteRaw(async () => this.session.get(sequel), () => sequel, "get", this.dialect, this.session.extractRawGetValueFromBatchResult.bind(this.session));
|
|
6441
|
-
return this.session.get(sequel);
|
|
6442
|
-
}
|
|
6443
|
-
values(query) {
|
|
6444
|
-
const sequel = typeof query === "string" ? sql.raw(query) : query.getSQL();
|
|
6445
|
-
if (this.resultKind === "async") return new SQLiteRaw(async () => this.session.values(sequel), () => sequel, "values", this.dialect, this.session.extractRawValuesValueFromBatchResult.bind(this.session));
|
|
6446
|
-
return this.session.values(sequel);
|
|
6447
|
-
}
|
|
6448
|
-
transaction(transaction, config) {
|
|
6449
|
-
return this.session.transaction(transaction, config);
|
|
2482
|
+
constructor(options = {}) {
|
|
2483
|
+
super(options);
|
|
2484
|
+
this.router = options.router ?? new SmartRouter({ routers: [new RegExpRouter(), new TrieRouter()] });
|
|
6450
2485
|
}
|
|
6451
2486
|
};
|
|
6452
2487
|
//#endregion
|
|
6453
|
-
//#region node_modules/
|
|
6454
|
-
|
|
6455
|
-
|
|
6456
|
-
|
|
6457
|
-
var NoopCache = class extends Cache {
|
|
6458
|
-
strategy() {
|
|
6459
|
-
return "all";
|
|
6460
|
-
}
|
|
6461
|
-
static [entityKind] = "NoopCache";
|
|
6462
|
-
async get(_key) {}
|
|
6463
|
-
async put(_hashedQuery, _response, _tables, _config) {}
|
|
6464
|
-
async onMutate(_params) {}
|
|
6465
|
-
};
|
|
6466
|
-
async function hashQuery(sql, params) {
|
|
6467
|
-
const dataToHash = `${sql}-${JSON.stringify(params)}`;
|
|
6468
|
-
const data = new TextEncoder().encode(dataToHash);
|
|
6469
|
-
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
|
|
6470
|
-
return [...new Uint8Array(hashBuffer)].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
2488
|
+
//#region node_modules/hono/dist/utils/color.js
|
|
2489
|
+
function getColorEnabled() {
|
|
2490
|
+
const { process, Deno } = globalThis;
|
|
2491
|
+
return !(typeof Deno?.noColor === "boolean" ? Deno.noColor : process !== void 0 ? "NO_COLOR" in process?.env : false);
|
|
6471
2492
|
}
|
|
6472
|
-
|
|
6473
|
-
|
|
6474
|
-
|
|
6475
|
-
|
|
6476
|
-
super();
|
|
6477
|
-
this.resultCb = resultCb;
|
|
6478
|
-
}
|
|
6479
|
-
static [entityKind] = "ExecuteResultSync";
|
|
6480
|
-
async execute() {
|
|
6481
|
-
return this.resultCb();
|
|
6482
|
-
}
|
|
6483
|
-
sync() {
|
|
6484
|
-
return this.resultCb();
|
|
6485
|
-
}
|
|
6486
|
-
};
|
|
6487
|
-
var SQLitePreparedQuery = class {
|
|
6488
|
-
constructor(mode, executeMethod, query, cache, queryMetadata, cacheConfig) {
|
|
6489
|
-
this.mode = mode;
|
|
6490
|
-
this.executeMethod = executeMethod;
|
|
6491
|
-
this.query = query;
|
|
6492
|
-
this.cache = cache;
|
|
6493
|
-
this.queryMetadata = queryMetadata;
|
|
6494
|
-
this.cacheConfig = cacheConfig;
|
|
6495
|
-
if (cache && cache.strategy() === "all" && cacheConfig === void 0) this.cacheConfig = {
|
|
6496
|
-
enable: true,
|
|
6497
|
-
autoInvalidate: true
|
|
6498
|
-
};
|
|
6499
|
-
if (!this.cacheConfig?.enable) this.cacheConfig = void 0;
|
|
6500
|
-
}
|
|
6501
|
-
static [entityKind] = "PreparedQuery";
|
|
6502
|
-
/** @internal */
|
|
6503
|
-
joinsNotNullableMap;
|
|
6504
|
-
/** @internal */
|
|
6505
|
-
async queryWithCache(queryString, params, query) {
|
|
6506
|
-
if (this.cache === void 0 || is(this.cache, NoopCache) || this.queryMetadata === void 0) try {
|
|
6507
|
-
return await query();
|
|
6508
|
-
} catch (e) {
|
|
6509
|
-
throw new DrizzleQueryError(queryString, params, e);
|
|
6510
|
-
}
|
|
6511
|
-
if (this.cacheConfig && !this.cacheConfig.enable) try {
|
|
6512
|
-
return await query();
|
|
6513
|
-
} catch (e) {
|
|
6514
|
-
throw new DrizzleQueryError(queryString, params, e);
|
|
6515
|
-
}
|
|
6516
|
-
if ((this.queryMetadata.type === "insert" || this.queryMetadata.type === "update" || this.queryMetadata.type === "delete") && this.queryMetadata.tables.length > 0) try {
|
|
6517
|
-
const [res] = await Promise.all([query(), this.cache.onMutate({ tables: this.queryMetadata.tables })]);
|
|
6518
|
-
return res;
|
|
6519
|
-
} catch (e) {
|
|
6520
|
-
throw new DrizzleQueryError(queryString, params, e);
|
|
6521
|
-
}
|
|
6522
|
-
if (!this.cacheConfig) try {
|
|
6523
|
-
return await query();
|
|
6524
|
-
} catch (e) {
|
|
6525
|
-
throw new DrizzleQueryError(queryString, params, e);
|
|
6526
|
-
}
|
|
6527
|
-
if (this.queryMetadata.type === "select") {
|
|
6528
|
-
const fromCache = await this.cache.get(this.cacheConfig.tag ?? await hashQuery(queryString, params), this.queryMetadata.tables, this.cacheConfig.tag !== void 0, this.cacheConfig.autoInvalidate);
|
|
6529
|
-
if (fromCache === void 0) {
|
|
6530
|
-
let result;
|
|
6531
|
-
try {
|
|
6532
|
-
result = await query();
|
|
6533
|
-
} catch (e) {
|
|
6534
|
-
throw new DrizzleQueryError(queryString, params, e);
|
|
6535
|
-
}
|
|
6536
|
-
await this.cache.put(this.cacheConfig.tag ?? await hashQuery(queryString, params), result, this.cacheConfig.autoInvalidate ? this.queryMetadata.tables : [], this.cacheConfig.tag !== void 0, this.cacheConfig.config);
|
|
6537
|
-
return result;
|
|
6538
|
-
}
|
|
6539
|
-
return fromCache;
|
|
6540
|
-
}
|
|
2493
|
+
async function getColorEnabledAsync() {
|
|
2494
|
+
const { navigator } = globalThis;
|
|
2495
|
+
const cfWorkers = "cloudflare:workers";
|
|
2496
|
+
return !(navigator !== void 0 && navigator.userAgent === "Cloudflare-Workers" ? await (async () => {
|
|
6541
2497
|
try {
|
|
6542
|
-
return await
|
|
6543
|
-
} catch
|
|
6544
|
-
|
|
6545
|
-
}
|
|
6546
|
-
}
|
|
6547
|
-
getQuery() {
|
|
6548
|
-
return this.query;
|
|
6549
|
-
}
|
|
6550
|
-
mapRunResult(result, _isFromBatch) {
|
|
6551
|
-
return result;
|
|
6552
|
-
}
|
|
6553
|
-
mapAllResult(_result, _isFromBatch) {
|
|
6554
|
-
throw new Error("Not implemented");
|
|
6555
|
-
}
|
|
6556
|
-
mapGetResult(_result, _isFromBatch) {
|
|
6557
|
-
throw new Error("Not implemented");
|
|
6558
|
-
}
|
|
6559
|
-
execute(placeholderValues) {
|
|
6560
|
-
if (this.mode === "async") return this[this.executeMethod](placeholderValues);
|
|
6561
|
-
return new ExecuteResultSync(() => this[this.executeMethod](placeholderValues));
|
|
6562
|
-
}
|
|
6563
|
-
mapResult(response, isFromBatch) {
|
|
6564
|
-
switch (this.executeMethod) {
|
|
6565
|
-
case "run": return this.mapRunResult(response, isFromBatch);
|
|
6566
|
-
case "all": return this.mapAllResult(response, isFromBatch);
|
|
6567
|
-
case "get": return this.mapGetResult(response, isFromBatch);
|
|
2498
|
+
return "NO_COLOR" in ((await import(cfWorkers)).env ?? {});
|
|
2499
|
+
} catch {
|
|
2500
|
+
return false;
|
|
6568
2501
|
}
|
|
6569
|
-
}
|
|
2502
|
+
})() : !getColorEnabled());
|
|
2503
|
+
}
|
|
2504
|
+
//#endregion
|
|
2505
|
+
//#region node_modules/hono/dist/middleware/logger/index.js
|
|
2506
|
+
var humanize = (times) => {
|
|
2507
|
+
const [delimiter, separator] = [",", "."];
|
|
2508
|
+
return times.map((v) => v.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1" + delimiter)).join(separator);
|
|
2509
|
+
};
|
|
2510
|
+
var time = (start) => {
|
|
2511
|
+
const delta = Date.now() - start;
|
|
2512
|
+
return humanize([delta < 1e3 ? delta + "ms" : Math.round(delta / 1e3) + "s"]);
|
|
6570
2513
|
};
|
|
6571
|
-
var
|
|
6572
|
-
|
|
6573
|
-
|
|
2514
|
+
var colorStatus = async (status) => {
|
|
2515
|
+
if (await getColorEnabledAsync()) switch (status / 100 | 0) {
|
|
2516
|
+
case 5: return `\x1B[31m${status}\x1B[0m`;
|
|
2517
|
+
case 4: return `\x1B[33m${status}\x1B[0m`;
|
|
2518
|
+
case 3: return `\x1B[36m${status}\x1B[0m`;
|
|
2519
|
+
case 2: return `\x1B[32m${status}\x1B[0m`;
|
|
6574
2520
|
}
|
|
6575
|
-
|
|
6576
|
-
|
|
6577
|
-
|
|
2521
|
+
return `${status}`;
|
|
2522
|
+
};
|
|
2523
|
+
async function log$1(fn, prefix, method, path, status = 0, elapsed) {
|
|
2524
|
+
fn(prefix === "<--" ? `${prefix} ${method} ${path}` : `${prefix} ${method} ${path} ${await colorStatus(status)} ${elapsed}`);
|
|
2525
|
+
}
|
|
2526
|
+
var logger$1 = (fn = console.log) => {
|
|
2527
|
+
return async function logger2(c, next) {
|
|
2528
|
+
const { method, url } = c.req;
|
|
2529
|
+
const path = url.slice(url.indexOf("/", 8));
|
|
2530
|
+
await log$1(fn, "<--", method, path);
|
|
2531
|
+
const start = Date.now();
|
|
2532
|
+
await next();
|
|
2533
|
+
await log$1(fn, "-->", method, path, c.res.status, time(start));
|
|
2534
|
+
};
|
|
2535
|
+
};
|
|
2536
|
+
//#endregion
|
|
2537
|
+
//#region src/runtime-paths.ts
|
|
2538
|
+
const virtualFileSystemPrefix = "/$bunfs/";
|
|
2539
|
+
function isCompiledExecutable() {
|
|
2540
|
+
const currentModuleUrl = import.meta.url;
|
|
2541
|
+
if (currentModuleUrl.includes(virtualFileSystemPrefix)) return true;
|
|
2542
|
+
if (currentModuleUrl.startsWith("compiled://")) return true;
|
|
2543
|
+
return false;
|
|
2544
|
+
}
|
|
2545
|
+
function resolveBinaryDirectory() {
|
|
2546
|
+
const executablePath = process.execPath;
|
|
2547
|
+
return path.dirname(executablePath);
|
|
2548
|
+
}
|
|
2549
|
+
function getApplicationRoot() {
|
|
2550
|
+
if (isCompiledExecutable()) return resolveBinaryDirectory();
|
|
2551
|
+
const currentDirectory = path.dirname(fileURLToPath(import.meta.url));
|
|
2552
|
+
const sourceRelativeRoot = path.resolve(currentDirectory, "..");
|
|
2553
|
+
const bundleRelativeRoot = path.resolve(currentDirectory, "../..");
|
|
2554
|
+
if (looksLikeApplicationRoot(sourceRelativeRoot)) return sourceRelativeRoot;
|
|
2555
|
+
if (looksLikeApplicationRoot(bundleRelativeRoot)) return bundleRelativeRoot;
|
|
2556
|
+
return sourceRelativeRoot;
|
|
2557
|
+
}
|
|
2558
|
+
function looksLikeApplicationRoot(directory) {
|
|
2559
|
+
try {
|
|
2560
|
+
const packageJsonPath = path.join(directory, "package.json");
|
|
2561
|
+
if (!existsSync(packageJsonPath)) return false;
|
|
2562
|
+
return JSON.parse(readFileSync(packageJsonPath, "utf-8")).name === "jukebox-media-server";
|
|
2563
|
+
} catch {
|
|
2564
|
+
return false;
|
|
6578
2565
|
}
|
|
6579
|
-
|
|
6580
|
-
|
|
6581
|
-
|
|
6582
|
-
|
|
6583
|
-
|
|
6584
|
-
|
|
6585
|
-
|
|
6586
|
-
|
|
6587
|
-
|
|
2566
|
+
}
|
|
2567
|
+
function getClientAssetsDirectory() {
|
|
2568
|
+
return path.join(getApplicationRoot(), "dist", "client");
|
|
2569
|
+
}
|
|
2570
|
+
function getMigrationsDirectory() {
|
|
2571
|
+
return path.join(getApplicationRoot(), "drizzle");
|
|
2572
|
+
}
|
|
2573
|
+
function getPackageJsonPath() {
|
|
2574
|
+
return path.join(getApplicationRoot(), "package.json");
|
|
2575
|
+
}
|
|
2576
|
+
//#endregion
|
|
2577
|
+
//#region node_modules/hono/dist/helper/factory/index.js
|
|
2578
|
+
var createMiddleware = (middleware) => middleware;
|
|
2579
|
+
//#endregion
|
|
2580
|
+
//#region node_modules/hono/dist/utils/cookie.js
|
|
2581
|
+
var validCookieNameRegEx = /^[\w!#$%&'*.^`|~+-]+$/;
|
|
2582
|
+
var validCookieValueRegEx = /^[ !#-:<-[\]-~]*$/;
|
|
2583
|
+
var parse = (cookie, name) => {
|
|
2584
|
+
if (name && cookie.indexOf(name) === -1) return {};
|
|
2585
|
+
const pairs = cookie.trim().split(";");
|
|
2586
|
+
const parsedCookie = {};
|
|
2587
|
+
for (let pairStr of pairs) {
|
|
2588
|
+
pairStr = pairStr.trim();
|
|
2589
|
+
const valueStartPos = pairStr.indexOf("=");
|
|
2590
|
+
if (valueStartPos === -1) continue;
|
|
2591
|
+
const cookieName = pairStr.substring(0, valueStartPos).trim();
|
|
2592
|
+
if (name && name !== cookieName || !validCookieNameRegEx.test(cookieName)) continue;
|
|
2593
|
+
let cookieValue = pairStr.substring(valueStartPos + 1).trim();
|
|
2594
|
+
if (cookieValue.startsWith("\"") && cookieValue.endsWith("\"")) cookieValue = cookieValue.slice(1, -1);
|
|
2595
|
+
if (validCookieValueRegEx.test(cookieValue)) {
|
|
2596
|
+
parsedCookie[cookieName] = cookieValue.indexOf("%") !== -1 ? tryDecode(cookieValue, decodeURIComponent_) : cookieValue;
|
|
2597
|
+
if (name) break;
|
|
6588
2598
|
}
|
|
6589
2599
|
}
|
|
6590
|
-
|
|
6591
|
-
|
|
6592
|
-
|
|
6593
|
-
}
|
|
6594
|
-
|
|
6595
|
-
|
|
6596
|
-
|
|
6597
|
-
|
|
6598
|
-
|
|
6599
|
-
throw new Error("Not implemented");
|
|
6600
|
-
}
|
|
6601
|
-
get(query) {
|
|
6602
|
-
return this.prepareOneTimeQuery(this.dialect.sqlToQuery(query), void 0, "run", false).get();
|
|
6603
|
-
}
|
|
6604
|
-
/** @internal */
|
|
6605
|
-
extractRawGetValueFromBatchResult(_result) {
|
|
6606
|
-
throw new Error("Not implemented");
|
|
2600
|
+
return parsedCookie;
|
|
2601
|
+
};
|
|
2602
|
+
var _serialize = (name, value, opt = {}) => {
|
|
2603
|
+
let cookie = `${name}=${value}`;
|
|
2604
|
+
if (name.startsWith("__Secure-") && !opt.secure) throw new Error("__Secure- Cookie must have Secure attributes");
|
|
2605
|
+
if (name.startsWith("__Host-")) {
|
|
2606
|
+
if (!opt.secure) throw new Error("__Host- Cookie must have Secure attributes");
|
|
2607
|
+
if (opt.path !== "/") throw new Error("__Host- Cookie must have Path attributes with \"/\"");
|
|
2608
|
+
if (opt.domain) throw new Error("__Host- Cookie must not have Domain attributes");
|
|
6607
2609
|
}
|
|
6608
|
-
|
|
6609
|
-
|
|
2610
|
+
if (opt && typeof opt.maxAge === "number" && opt.maxAge >= 0) {
|
|
2611
|
+
if (opt.maxAge > 3456e4) throw new Error("Cookies Max-Age SHOULD NOT be greater than 400 days (34560000 seconds) in duration.");
|
|
2612
|
+
cookie += `; Max-Age=${opt.maxAge | 0}`;
|
|
6610
2613
|
}
|
|
6611
|
-
|
|
6612
|
-
|
|
2614
|
+
if (opt.domain && opt.prefix !== "host") cookie += `; Domain=${opt.domain}`;
|
|
2615
|
+
if (opt.path) cookie += `; Path=${opt.path}`;
|
|
2616
|
+
if (opt.expires) {
|
|
2617
|
+
if (opt.expires.getTime() - Date.now() > 3456e7) throw new Error("Cookies Expires SHOULD NOT be greater than 400 days (34560000 seconds) in the future.");
|
|
2618
|
+
cookie += `; Expires=${opt.expires.toUTCString()}`;
|
|
6613
2619
|
}
|
|
6614
|
-
|
|
6615
|
-
|
|
6616
|
-
|
|
2620
|
+
if (opt.httpOnly) cookie += "; HttpOnly";
|
|
2621
|
+
if (opt.secure) cookie += "; Secure";
|
|
2622
|
+
if (opt.sameSite) cookie += `; SameSite=${opt.sameSite.charAt(0).toUpperCase() + opt.sameSite.slice(1)}`;
|
|
2623
|
+
if (opt.priority) cookie += `; Priority=${opt.priority.charAt(0).toUpperCase() + opt.priority.slice(1)}`;
|
|
2624
|
+
if (opt.partitioned) {
|
|
2625
|
+
if (!opt.secure) throw new Error("Partitioned Cookie must have Secure attributes");
|
|
2626
|
+
cookie += "; Partitioned";
|
|
6617
2627
|
}
|
|
2628
|
+
return cookie;
|
|
6618
2629
|
};
|
|
6619
|
-
var
|
|
6620
|
-
|
|
6621
|
-
|
|
6622
|
-
this.schema = schema;
|
|
6623
|
-
this.nestedIndex = nestedIndex;
|
|
6624
|
-
}
|
|
6625
|
-
static [entityKind] = "SQLiteTransaction";
|
|
6626
|
-
rollback() {
|
|
6627
|
-
throw new TransactionRollbackError();
|
|
6628
|
-
}
|
|
2630
|
+
var serialize = (name, value, opt) => {
|
|
2631
|
+
value = encodeURIComponent(value);
|
|
2632
|
+
return _serialize(name, value, opt);
|
|
6629
2633
|
};
|
|
6630
2634
|
//#endregion
|
|
6631
|
-
//#region node_modules/
|
|
6632
|
-
var
|
|
6633
|
-
|
|
6634
|
-
|
|
6635
|
-
|
|
6636
|
-
|
|
6637
|
-
|
|
6638
|
-
|
|
6639
|
-
|
|
6640
|
-
static [entityKind] = "BetterSQLiteSession";
|
|
6641
|
-
logger;
|
|
6642
|
-
cache;
|
|
6643
|
-
prepareQuery(query, fields, executeMethod, isResponseInArrayMode, customResultMapper, queryMetadata, cacheConfig) {
|
|
6644
|
-
return new PreparedQuery(this.client.prepare(query.sql), query, this.logger, this.cache, queryMetadata, cacheConfig, fields, executeMethod, isResponseInArrayMode, customResultMapper);
|
|
6645
|
-
}
|
|
6646
|
-
transaction(transaction, config = {}) {
|
|
6647
|
-
const tx = new BetterSQLiteTransaction("sync", this.dialect, this, this.schema);
|
|
6648
|
-
return this.client.transaction(transaction)[config.behavior ?? "deferred"](tx);
|
|
2635
|
+
//#region node_modules/hono/dist/helper/cookie/index.js
|
|
2636
|
+
var getCookie = (c, key, prefix) => {
|
|
2637
|
+
const cookie = c.req.raw.headers.get("Cookie");
|
|
2638
|
+
if (typeof key === "string") {
|
|
2639
|
+
if (!cookie) return;
|
|
2640
|
+
let finalKey = key;
|
|
2641
|
+
if (prefix === "secure") finalKey = "__Secure-" + key;
|
|
2642
|
+
else if (prefix === "host") finalKey = "__Host-" + key;
|
|
2643
|
+
return parse(cookie, finalKey)[finalKey];
|
|
6649
2644
|
}
|
|
2645
|
+
if (!cookie) return {};
|
|
2646
|
+
return parse(cookie);
|
|
6650
2647
|
};
|
|
6651
|
-
var
|
|
6652
|
-
|
|
6653
|
-
|
|
6654
|
-
|
|
6655
|
-
|
|
6656
|
-
|
|
6657
|
-
|
|
6658
|
-
|
|
6659
|
-
|
|
6660
|
-
|
|
6661
|
-
|
|
6662
|
-
|
|
6663
|
-
|
|
6664
|
-
|
|
6665
|
-
|
|
2648
|
+
var generateCookie = (name, value, opt) => {
|
|
2649
|
+
let cookie;
|
|
2650
|
+
if (opt?.prefix === "secure") cookie = serialize("__Secure-" + name, value, {
|
|
2651
|
+
path: "/",
|
|
2652
|
+
...opt,
|
|
2653
|
+
secure: true
|
|
2654
|
+
});
|
|
2655
|
+
else if (opt?.prefix === "host") cookie = serialize("__Host-" + name, value, {
|
|
2656
|
+
...opt,
|
|
2657
|
+
path: "/",
|
|
2658
|
+
secure: true,
|
|
2659
|
+
domain: void 0
|
|
2660
|
+
});
|
|
2661
|
+
else cookie = serialize(name, value, {
|
|
2662
|
+
path: "/",
|
|
2663
|
+
...opt
|
|
2664
|
+
});
|
|
2665
|
+
return cookie;
|
|
6666
2666
|
};
|
|
6667
|
-
var
|
|
6668
|
-
|
|
6669
|
-
|
|
6670
|
-
this.stmt = stmt;
|
|
6671
|
-
this.logger = logger;
|
|
6672
|
-
this.fields = fields;
|
|
6673
|
-
this._isResponseInArrayMode = _isResponseInArrayMode;
|
|
6674
|
-
this.customResultMapper = customResultMapper;
|
|
6675
|
-
}
|
|
6676
|
-
static [entityKind] = "BetterSQLitePreparedQuery";
|
|
6677
|
-
run(placeholderValues) {
|
|
6678
|
-
const params = fillPlaceholders(this.query.params, placeholderValues ?? {});
|
|
6679
|
-
this.logger.logQuery(this.query.sql, params);
|
|
6680
|
-
return this.stmt.run(...params);
|
|
6681
|
-
}
|
|
6682
|
-
all(placeholderValues) {
|
|
6683
|
-
const { fields, joinsNotNullableMap, query, logger, stmt, customResultMapper } = this;
|
|
6684
|
-
if (!fields && !customResultMapper) {
|
|
6685
|
-
const params = fillPlaceholders(query.params, placeholderValues ?? {});
|
|
6686
|
-
logger.logQuery(query.sql, params);
|
|
6687
|
-
return stmt.all(...params);
|
|
6688
|
-
}
|
|
6689
|
-
const rows = this.values(placeholderValues);
|
|
6690
|
-
if (customResultMapper) return customResultMapper(rows);
|
|
6691
|
-
return rows.map((row) => mapResultRow(fields, row, joinsNotNullableMap));
|
|
6692
|
-
}
|
|
6693
|
-
get(placeholderValues) {
|
|
6694
|
-
const params = fillPlaceholders(this.query.params, placeholderValues ?? {});
|
|
6695
|
-
this.logger.logQuery(this.query.sql, params);
|
|
6696
|
-
const { fields, stmt, joinsNotNullableMap, customResultMapper } = this;
|
|
6697
|
-
if (!fields && !customResultMapper) return stmt.get(...params);
|
|
6698
|
-
const row = stmt.raw().get(...params);
|
|
6699
|
-
if (!row) return;
|
|
6700
|
-
if (customResultMapper) return customResultMapper([row]);
|
|
6701
|
-
return mapResultRow(fields, row, joinsNotNullableMap);
|
|
6702
|
-
}
|
|
6703
|
-
values(placeholderValues) {
|
|
6704
|
-
const params = fillPlaceholders(this.query.params, placeholderValues ?? {});
|
|
6705
|
-
this.logger.logQuery(this.query.sql, params);
|
|
6706
|
-
return this.stmt.raw().all(...params);
|
|
6707
|
-
}
|
|
6708
|
-
/** @internal */
|
|
6709
|
-
isResponseInArrayMode() {
|
|
6710
|
-
return this._isResponseInArrayMode;
|
|
6711
|
-
}
|
|
2667
|
+
var setCookie = (c, name, value, opt) => {
|
|
2668
|
+
const cookie = generateCookie(name, value, opt);
|
|
2669
|
+
c.header("Set-Cookie", cookie, { append: true });
|
|
6712
2670
|
};
|
|
6713
|
-
|
|
6714
|
-
|
|
6715
|
-
|
|
6716
|
-
|
|
2671
|
+
var deleteCookie = (c, name, opt) => {
|
|
2672
|
+
const deletedCookie = getCookie(c, name, opt?.prefix);
|
|
2673
|
+
setCookie(c, name, "", {
|
|
2674
|
+
...opt,
|
|
2675
|
+
maxAge: 0
|
|
2676
|
+
});
|
|
2677
|
+
return deletedCookie;
|
|
6717
2678
|
};
|
|
6718
|
-
function construct(client, config = {}) {
|
|
6719
|
-
const dialect = new SQLiteSyncDialect({ casing: config.casing });
|
|
6720
|
-
let logger;
|
|
6721
|
-
if (config.logger === true) logger = new DefaultLogger();
|
|
6722
|
-
else if (config.logger !== false) logger = config.logger;
|
|
6723
|
-
let schema;
|
|
6724
|
-
if (config.schema) {
|
|
6725
|
-
const tablesConfig = extractTablesRelationalConfig(config.schema, createTableRelationsHelpers);
|
|
6726
|
-
schema = {
|
|
6727
|
-
fullSchema: config.schema,
|
|
6728
|
-
schema: tablesConfig.tables,
|
|
6729
|
-
tableNamesMap: tablesConfig.tableNamesMap
|
|
6730
|
-
};
|
|
6731
|
-
}
|
|
6732
|
-
const db = new BetterSQLite3Database("sync", dialect, new BetterSQLiteSession(client, dialect, schema, { logger }), schema);
|
|
6733
|
-
db.$client = client;
|
|
6734
|
-
return db;
|
|
6735
|
-
}
|
|
6736
|
-
function drizzle(...params) {
|
|
6737
|
-
if (params[0] === void 0 || typeof params[0] === "string") return construct(params[0] === void 0 ? new Database() : new Database(params[0]), params[1]);
|
|
6738
|
-
if (isConfig(params[0])) {
|
|
6739
|
-
const { connection, client, ...drizzleConfig } = params[0];
|
|
6740
|
-
if (client) return construct(client, drizzleConfig);
|
|
6741
|
-
if (typeof connection === "object") {
|
|
6742
|
-
const { source, ...options } = connection;
|
|
6743
|
-
return construct(new Database(source, options), drizzleConfig);
|
|
6744
|
-
}
|
|
6745
|
-
return construct(new Database(connection), drizzleConfig);
|
|
6746
|
-
}
|
|
6747
|
-
return construct(params[0], params[1]);
|
|
6748
|
-
}
|
|
6749
|
-
((drizzle2) => {
|
|
6750
|
-
function mock(config) {
|
|
6751
|
-
return construct({}, config);
|
|
6752
|
-
}
|
|
6753
|
-
drizzle2.mock = mock;
|
|
6754
|
-
})(drizzle || (drizzle = {}));
|
|
6755
|
-
//#endregion
|
|
6756
|
-
//#region node_modules/drizzle-orm/migrator.js
|
|
6757
|
-
function readMigrationFiles(config) {
|
|
6758
|
-
const migrationFolderTo = config.migrationsFolder;
|
|
6759
|
-
const migrationQueries = [];
|
|
6760
|
-
const journalPath = `${migrationFolderTo}/meta/_journal.json`;
|
|
6761
|
-
if (!fs.existsSync(journalPath)) throw new Error(`Can't find meta/_journal.json file`);
|
|
6762
|
-
const journalAsString = fs.readFileSync(`${migrationFolderTo}/meta/_journal.json`).toString();
|
|
6763
|
-
const journal = JSON.parse(journalAsString);
|
|
6764
|
-
for (const journalEntry of journal.entries) {
|
|
6765
|
-
const migrationPath = `${migrationFolderTo}/${journalEntry.tag}.sql`;
|
|
6766
|
-
try {
|
|
6767
|
-
const query = fs.readFileSync(`${migrationFolderTo}/${journalEntry.tag}.sql`).toString();
|
|
6768
|
-
const result = query.split("--> statement-breakpoint").map((it) => {
|
|
6769
|
-
return it;
|
|
6770
|
-
});
|
|
6771
|
-
migrationQueries.push({
|
|
6772
|
-
sql: result,
|
|
6773
|
-
bps: journalEntry.breakpoints,
|
|
6774
|
-
folderMillis: journalEntry.when,
|
|
6775
|
-
hash: crypto$2.createHash("sha256").update(query).digest("hex")
|
|
6776
|
-
});
|
|
6777
|
-
} catch {
|
|
6778
|
-
throw new Error(`No file ${migrationPath} found in ${migrationFolderTo} folder`);
|
|
6779
|
-
}
|
|
6780
|
-
}
|
|
6781
|
-
return migrationQueries;
|
|
6782
|
-
}
|
|
6783
|
-
//#endregion
|
|
6784
|
-
//#region node_modules/drizzle-orm/better-sqlite3/migrator.js
|
|
6785
|
-
function migrate(db, config) {
|
|
6786
|
-
const migrations = readMigrationFiles(config);
|
|
6787
|
-
db.dialect.migrate(migrations, db.session, config);
|
|
6788
|
-
}
|
|
6789
2679
|
//#endregion
|
|
6790
2680
|
//#region src/config/index.ts
|
|
6791
2681
|
const configDirectory = join(homedir(), ".jukebox");
|
|
@@ -6938,11 +2828,31 @@ const subtitles = sqliteTable("subtitles", {
|
|
|
6938
2828
|
//#endregion
|
|
6939
2829
|
//#region src/database/index.ts
|
|
6940
2830
|
ensureConfigDirectory();
|
|
6941
|
-
|
|
6942
|
-
|
|
6943
|
-
|
|
6944
|
-
const
|
|
6945
|
-
|
|
2831
|
+
async function createDatabase() {
|
|
2832
|
+
const migrationsFolder = getMigrationsDirectory();
|
|
2833
|
+
if (typeof Bun !== "undefined") {
|
|
2834
|
+
const bunSqliteModule = "bun:sqlite";
|
|
2835
|
+
const bunSqliteDrizzleModule = "drizzle-orm/bun-sqlite";
|
|
2836
|
+
const bunSqliteMigratorModule = "drizzle-orm/bun-sqlite/migrator";
|
|
2837
|
+
const { Database: BunDatabase } = await import(bunSqliteModule);
|
|
2838
|
+
const { drizzle } = await import(bunSqliteDrizzleModule);
|
|
2839
|
+
const { migrate } = await import(bunSqliteMigratorModule);
|
|
2840
|
+
const sqlite = new BunDatabase(databasePath);
|
|
2841
|
+
sqlite.exec("PRAGMA foreign_keys = ON");
|
|
2842
|
+
const db = drizzle(sqlite, { schema: schema_exports });
|
|
2843
|
+
migrate(db, { migrationsFolder });
|
|
2844
|
+
return db;
|
|
2845
|
+
}
|
|
2846
|
+
const { default: NodeDatabase } = await import("better-sqlite3");
|
|
2847
|
+
const { drizzle } = await import("./better-sqlite3-Dy_YhTFe.js");
|
|
2848
|
+
const { migrate } = await import("./migrator-CWPnMvx5.js");
|
|
2849
|
+
const sqlite = new NodeDatabase(databasePath);
|
|
2850
|
+
sqlite.pragma("foreign_keys = ON");
|
|
2851
|
+
const db = drizzle(sqlite, { schema: schema_exports });
|
|
2852
|
+
migrate(db, { migrationsFolder });
|
|
2853
|
+
return db;
|
|
2854
|
+
}
|
|
2855
|
+
const db = await createDatabase();
|
|
6946
2856
|
//#endregion
|
|
6947
2857
|
//#region node_modules/tiny-invariant/dist/esm/tiny-invariant.js
|
|
6948
2858
|
var import_dayjs_min = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
@@ -10723,8 +6633,7 @@ app.route("/api/stream", streamRoutes);
|
|
|
10723
6633
|
app.route("/api/subtitles", subtitleRoutes);
|
|
10724
6634
|
app.route("/api/transcode", transcodeRoutes);
|
|
10725
6635
|
app.get("/api", (c) => c.json({ message: "Jukebox API" }));
|
|
10726
|
-
const
|
|
10727
|
-
const clientDir = path.resolve(__dirname$1, "../client");
|
|
6636
|
+
const clientDir = getClientAssetsDirectory();
|
|
10728
6637
|
function setupStaticServing() {
|
|
10729
6638
|
app.use("*", serveStatic({
|
|
10730
6639
|
root: clientDir,
|
|
@@ -10773,14 +6682,14 @@ function setupViteProxy(vitePort) {
|
|
|
10773
6682
|
}
|
|
10774
6683
|
//#endregion
|
|
10775
6684
|
//#region src/index.ts
|
|
6685
|
+
if (isCompiledExecutable()) process.env.NODE_ENV = process.env.NODE_ENV ?? "production";
|
|
10776
6686
|
const port = process.env.PORT ? Number(process.env.PORT) : 1990;
|
|
10777
6687
|
const vitePort = 5173;
|
|
10778
6688
|
const isDevelopment = process.env.NODE_ENV !== "production";
|
|
10779
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
10780
6689
|
function readPackageVersion() {
|
|
10781
|
-
|
|
10782
|
-
|
|
10783
|
-
const content = JSON.parse(readFileSync(
|
|
6690
|
+
if (typeof JUKEBOX_BUILD_VERSION === "string" && JUKEBOX_BUILD_VERSION.length > 0) return JUKEBOX_BUILD_VERSION;
|
|
6691
|
+
try {
|
|
6692
|
+
const content = JSON.parse(readFileSync(getPackageJsonPath(), "utf-8"));
|
|
10784
6693
|
if (content.name === "jukebox-media-server" && content.version) return content.version;
|
|
10785
6694
|
} catch {}
|
|
10786
6695
|
return "unknown";
|