@congzhen/changewayguard 6.8.12
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/LICENSE +21 -0
- package/README.md +270 -0
- package/dashboard-dist/api/104.index.js +1420 -0
- package/dashboard-dist/api/104.index.js.map +1 -0
- package/dashboard-dist/api/113.index.js +496 -0
- package/dashboard-dist/api/113.index.js.map +1 -0
- package/dashboard-dist/api/18.index.js +67 -0
- package/dashboard-dist/api/18.index.js.map +1 -0
- package/dashboard-dist/api/217.index.js +44 -0
- package/dashboard-dist/api/217.index.js.map +1 -0
- package/dashboard-dist/api/222.index.js +90 -0
- package/dashboard-dist/api/222.index.js.map +1 -0
- package/dashboard-dist/api/25.index.js +3562 -0
- package/dashboard-dist/api/25.index.js.map +1 -0
- package/dashboard-dist/api/280.index.js +206 -0
- package/dashboard-dist/api/280.index.js.map +1 -0
- package/dashboard-dist/api/369.index.js +115 -0
- package/dashboard-dist/api/369.index.js.map +1 -0
- package/dashboard-dist/api/377.index.js +1176 -0
- package/dashboard-dist/api/377.index.js.map +1 -0
- package/dashboard-dist/api/411.index.js +4250 -0
- package/dashboard-dist/api/411.index.js.map +1 -0
- package/dashboard-dist/api/424.index.js +135 -0
- package/dashboard-dist/api/424.index.js.map +1 -0
- package/dashboard-dist/api/573.index.js +806 -0
- package/dashboard-dist/api/573.index.js.map +1 -0
- package/dashboard-dist/api/598.index.js +328 -0
- package/dashboard-dist/api/598.index.js.map +1 -0
- package/dashboard-dist/api/62.index.js +4151 -0
- package/dashboard-dist/api/62.index.js.map +1 -0
- package/dashboard-dist/api/67.index.js +23383 -0
- package/dashboard-dist/api/67.index.js.map +1 -0
- package/dashboard-dist/api/678.index.js +2734 -0
- package/dashboard-dist/api/678.index.js.map +1 -0
- package/dashboard-dist/api/698.index.js +1896 -0
- package/dashboard-dist/api/698.index.js.map +1 -0
- package/dashboard-dist/api/720.index.js +98 -0
- package/dashboard-dist/api/720.index.js.map +1 -0
- package/dashboard-dist/api/830.index.js +95 -0
- package/dashboard-dist/api/830.index.js.map +1 -0
- package/dashboard-dist/api/831.index.js +99 -0
- package/dashboard-dist/api/831.index.js.map +1 -0
- package/dashboard-dist/api/84.index.js +64 -0
- package/dashboard-dist/api/84.index.js.map +1 -0
- package/dashboard-dist/api/900.index.js +65 -0
- package/dashboard-dist/api/900.index.js.map +1 -0
- package/dashboard-dist/api/917.index.js +88 -0
- package/dashboard-dist/api/917.index.js.map +1 -0
- package/dashboard-dist/api/948.index.js +64 -0
- package/dashboard-dist/api/948.index.js.map +1 -0
- package/dashboard-dist/api/953.index.js +67 -0
- package/dashboard-dist/api/953.index.js.map +1 -0
- package/dashboard-dist/api/975.index.js +374 -0
- package/dashboard-dist/api/975.index.js.map +1 -0
- package/dashboard-dist/api/drizzle/sqlite/0000_short_captain_stacy.sql +70 -0
- package/dashboard-dist/api/drizzle/sqlite/0001_closed_magus.sql +10 -0
- package/dashboard-dist/api/drizzle/sqlite/0002_agent_capability_observation.sql +38 -0
- package/dashboard-dist/api/drizzle/sqlite/0003_auth_magic_link.sql +28 -0
- package/dashboard-dist/api/drizzle/sqlite/0004_static_scan_fields.sql +8 -0
- package/dashboard-dist/api/drizzle/sqlite/0005_gateway_activity.sql +24 -0
- package/dashboard-dist/api/drizzle/sqlite/0006_sour_marauders.sql +41 -0
- package/dashboard-dist/api/drizzle/sqlite/meta/0000_snapshot.json +460 -0
- package/dashboard-dist/api/drizzle/sqlite/meta/0001_snapshot.json +536 -0
- package/dashboard-dist/api/drizzle/sqlite/meta/0006_snapshot.json +1249 -0
- package/dashboard-dist/api/drizzle/sqlite/meta/_journal.json +55 -0
- package/dashboard-dist/api/index.js +27340 -0
- package/dashboard-dist/api/index.js.map +1 -0
- package/dashboard-dist/api/package.json +16 -0
- package/dashboard-dist/api/sourcemap-register.cjs +1 -0
- package/dashboard-dist/web/assets/index-CqWIeBTD.js +158 -0
- package/dashboard-dist/web/assets/index-Dw7--9q4.css +1 -0
- package/dashboard-dist/web/changeway-logo.png +0 -0
- package/dashboard-dist/web/favicon.svg +29 -0
- package/dashboard-dist/web/index.html +14 -0
- package/dashboard-dist/web/logo.svg +16 -0
- package/dist/agent/auth.d.ts +37 -0
- package/dist/agent/auth.d.ts.map +1 -0
- package/dist/agent/auth.js +151 -0
- package/dist/agent/auth.js.map +1 -0
- package/dist/agent/behavior-detector.d.ts +150 -0
- package/dist/agent/behavior-detector.d.ts.map +1 -0
- package/dist/agent/behavior-detector.js +573 -0
- package/dist/agent/behavior-detector.js.map +1 -0
- package/dist/agent/business-reporter.d.ts +114 -0
- package/dist/agent/business-reporter.d.ts.map +1 -0
- package/dist/agent/business-reporter.js +359 -0
- package/dist/agent/business-reporter.js.map +1 -0
- package/dist/agent/config-sync.d.ts +70 -0
- package/dist/agent/config-sync.d.ts.map +1 -0
- package/dist/agent/config-sync.js +133 -0
- package/dist/agent/config-sync.js.map +1 -0
- package/dist/agent/config.d.ts +97 -0
- package/dist/agent/config.d.ts.map +1 -0
- package/dist/agent/config.js +359 -0
- package/dist/agent/config.js.map +1 -0
- package/dist/agent/content-injection-scanner.d.ts +35 -0
- package/dist/agent/content-injection-scanner.d.ts.map +1 -0
- package/dist/agent/content-injection-scanner.js +270 -0
- package/dist/agent/content-injection-scanner.js.map +1 -0
- package/dist/agent/engine-log-writer.d.ts +6 -0
- package/dist/agent/engine-log-writer.d.ts.map +1 -0
- package/dist/agent/engine-log-writer.js +18 -0
- package/dist/agent/engine-log-writer.js.map +1 -0
- package/dist/agent/env.d.ts +19 -0
- package/dist/agent/env.d.ts.map +1 -0
- package/dist/agent/env.js +43 -0
- package/dist/agent/env.js.map +1 -0
- package/dist/agent/event-reporter.d.ts +87 -0
- package/dist/agent/event-reporter.d.ts.map +1 -0
- package/dist/agent/event-reporter.js +315 -0
- package/dist/agent/event-reporter.js.map +1 -0
- package/dist/agent/file-watcher.d.ts +50 -0
- package/dist/agent/file-watcher.d.ts.map +1 -0
- package/dist/agent/file-watcher.js +135 -0
- package/dist/agent/file-watcher.js.map +1 -0
- package/dist/agent/fs-utils.d.ts +22 -0
- package/dist/agent/fs-utils.d.ts.map +1 -0
- package/dist/agent/fs-utils.js +41 -0
- package/dist/agent/fs-utils.js.map +1 -0
- package/dist/agent/gateway-manager.d.ts +59 -0
- package/dist/agent/gateway-manager.d.ts.map +1 -0
- package/dist/agent/gateway-manager.js +583 -0
- package/dist/agent/gateway-manager.js.map +1 -0
- package/dist/agent/hook-types.d.ts +276 -0
- package/dist/agent/hook-types.d.ts.map +1 -0
- package/dist/agent/hook-types.js +51 -0
- package/dist/agent/hook-types.js.map +1 -0
- package/dist/agent/index.d.ts +8 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +8 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/prompt-gate.d.ts +13 -0
- package/dist/agent/prompt-gate.d.ts.map +1 -0
- package/dist/agent/prompt-gate.js +28 -0
- package/dist/agent/prompt-gate.js.map +1 -0
- package/dist/agent/prompt-input.d.ts +9 -0
- package/dist/agent/prompt-input.d.ts.map +1 -0
- package/dist/agent/prompt-input.js +158 -0
- package/dist/agent/prompt-input.js.map +1 -0
- package/dist/agent/prompt-output.d.ts +4 -0
- package/dist/agent/prompt-output.d.ts.map +1 -0
- package/dist/agent/prompt-output.js +19 -0
- package/dist/agent/prompt-output.js.map +1 -0
- package/dist/agent/runner.d.ts +23 -0
- package/dist/agent/runner.d.ts.map +1 -0
- package/dist/agent/runner.js +154 -0
- package/dist/agent/runner.js.map +1 -0
- package/dist/agent/sanitizer.d.ts +10 -0
- package/dist/agent/sanitizer.d.ts.map +1 -0
- package/dist/agent/sanitizer.js +175 -0
- package/dist/agent/sanitizer.js.map +1 -0
- package/dist/agent/scan-activity.d.ts +18 -0
- package/dist/agent/scan-activity.d.ts.map +1 -0
- package/dist/agent/scan-activity.js +32 -0
- package/dist/agent/scan-activity.js.map +1 -0
- package/dist/agent/types.d.ts +177 -0
- package/dist/agent/types.d.ts.map +1 -0
- package/dist/agent/types.js +5 -0
- package/dist/agent/types.js.map +1 -0
- package/dist/agent/workspace-scanner.d.ts +35 -0
- package/dist/agent/workspace-scanner.d.ts.map +1 -0
- package/dist/agent/workspace-scanner.js +137 -0
- package/dist/agent/workspace-scanner.js.map +1 -0
- package/dist/dashboard-launcher.d.ts +52 -0
- package/dist/dashboard-launcher.d.ts.map +1 -0
- package/dist/dashboard-launcher.js +363 -0
- package/dist/dashboard-launcher.js.map +1 -0
- package/dist/gateway/activity.d.ts +52 -0
- package/dist/gateway/activity.d.ts.map +1 -0
- package/dist/gateway/activity.js +111 -0
- package/dist/gateway/activity.js.map +1 -0
- package/dist/gateway/config.d.ts +50 -0
- package/dist/gateway/config.d.ts.map +1 -0
- package/dist/gateway/config.js +200 -0
- package/dist/gateway/config.js.map +1 -0
- package/dist/gateway/gateway/activity.d.ts +52 -0
- package/dist/gateway/gateway/activity.d.ts.map +1 -0
- package/dist/gateway/gateway/activity.js +111 -0
- package/dist/gateway/gateway/activity.js.map +1 -0
- package/dist/gateway/gateway/config.d.ts +50 -0
- package/dist/gateway/gateway/config.d.ts.map +1 -0
- package/dist/gateway/gateway/config.js +200 -0
- package/dist/gateway/gateway/config.js.map +1 -0
- package/dist/gateway/gateway/handlers/anthropic.d.ts +12 -0
- package/dist/gateway/gateway/handlers/anthropic.d.ts.map +1 -0
- package/dist/gateway/gateway/handlers/anthropic.js +254 -0
- package/dist/gateway/gateway/handlers/anthropic.js.map +1 -0
- package/dist/gateway/gateway/handlers/gemini.d.ts +12 -0
- package/dist/gateway/gateway/handlers/gemini.d.ts.map +1 -0
- package/dist/gateway/gateway/handlers/gemini.js +101 -0
- package/dist/gateway/gateway/handlers/gemini.js.map +1 -0
- package/dist/gateway/gateway/handlers/models.d.ts +4 -0
- package/dist/gateway/gateway/handlers/models.d.ts.map +1 -0
- package/dist/gateway/gateway/handlers/models.js +36 -0
- package/dist/gateway/gateway/handlers/models.js.map +1 -0
- package/dist/gateway/gateway/handlers/openai.d.ts +16 -0
- package/dist/gateway/gateway/handlers/openai.d.ts.map +1 -0
- package/dist/gateway/gateway/handlers/openai.js +254 -0
- package/dist/gateway/gateway/handlers/openai.js.map +1 -0
- package/dist/gateway/gateway/index.d.ts +27 -0
- package/dist/gateway/gateway/index.d.ts.map +1 -0
- package/dist/gateway/gateway/index.js +293 -0
- package/dist/gateway/gateway/index.js.map +1 -0
- package/dist/gateway/gateway/mapping-store.d.ts +38 -0
- package/dist/gateway/gateway/mapping-store.d.ts.map +1 -0
- package/dist/gateway/gateway/mapping-store.js +74 -0
- package/dist/gateway/gateway/mapping-store.js.map +1 -0
- package/dist/gateway/gateway/restorer.d.ts +63 -0
- package/dist/gateway/gateway/restorer.d.ts.map +1 -0
- package/dist/gateway/gateway/restorer.js +284 -0
- package/dist/gateway/gateway/restorer.js.map +1 -0
- package/dist/gateway/gateway/sanitizer.d.ts +17 -0
- package/dist/gateway/gateway/sanitizer.d.ts.map +1 -0
- package/dist/gateway/gateway/sanitizer.js +228 -0
- package/dist/gateway/gateway/sanitizer.js.map +1 -0
- package/dist/gateway/gateway/types.d.ts +53 -0
- package/dist/gateway/gateway/types.d.ts.map +1 -0
- package/dist/gateway/gateway/types.js +5 -0
- package/dist/gateway/gateway/types.js.map +1 -0
- package/dist/gateway/handlers/anthropic.d.ts +12 -0
- package/dist/gateway/handlers/anthropic.d.ts.map +1 -0
- package/dist/gateway/handlers/anthropic.js +254 -0
- package/dist/gateway/handlers/anthropic.js.map +1 -0
- package/dist/gateway/handlers/gemini.d.ts +12 -0
- package/dist/gateway/handlers/gemini.d.ts.map +1 -0
- package/dist/gateway/handlers/gemini.js +101 -0
- package/dist/gateway/handlers/gemini.js.map +1 -0
- package/dist/gateway/handlers/models.d.ts +4 -0
- package/dist/gateway/handlers/models.d.ts.map +1 -0
- package/dist/gateway/handlers/models.js +36 -0
- package/dist/gateway/handlers/models.js.map +1 -0
- package/dist/gateway/handlers/openai.d.ts +16 -0
- package/dist/gateway/handlers/openai.d.ts.map +1 -0
- package/dist/gateway/handlers/openai.js +254 -0
- package/dist/gateway/handlers/openai.js.map +1 -0
- package/dist/gateway/index.d.ts +27 -0
- package/dist/gateway/index.d.ts.map +1 -0
- package/dist/gateway/index.js +293 -0
- package/dist/gateway/index.js.map +1 -0
- package/dist/gateway/mapping-store.d.ts +38 -0
- package/dist/gateway/mapping-store.d.ts.map +1 -0
- package/dist/gateway/mapping-store.js +74 -0
- package/dist/gateway/mapping-store.js.map +1 -0
- package/dist/gateway/restorer.d.ts +63 -0
- package/dist/gateway/restorer.d.ts.map +1 -0
- package/dist/gateway/restorer.js +284 -0
- package/dist/gateway/restorer.js.map +1 -0
- package/dist/gateway/sanitizer.d.ts +17 -0
- package/dist/gateway/sanitizer.d.ts.map +1 -0
- package/dist/gateway/sanitizer.js +228 -0
- package/dist/gateway/sanitizer.js.map +1 -0
- package/dist/gateway/types.d.ts +53 -0
- package/dist/gateway/types.d.ts.map +1 -0
- package/dist/gateway/types.js +5 -0
- package/dist/gateway/types.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2084 -0
- package/dist/index.js.map +1 -0
- package/dist/memory/index.d.ts +5 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +5 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/store.d.ts +82 -0
- package/dist/memory/store.d.ts.map +1 -0
- package/dist/memory/store.js +194 -0
- package/dist/memory/store.js.map +1 -0
- package/dist/platform-client/index.d.ts +63 -0
- package/dist/platform-client/index.d.ts.map +1 -0
- package/dist/platform-client/index.js +294 -0
- package/dist/platform-client/index.js.map +1 -0
- package/dist/platform-client/types.d.ts +109 -0
- package/dist/platform-client/types.d.ts.map +1 -0
- package/dist/platform-client/types.js +3 -0
- package/dist/platform-client/types.js.map +1 -0
- package/gateway/activity.d.ts +52 -0
- package/gateway/activity.d.ts.map +1 -0
- package/gateway/activity.js +111 -0
- package/gateway/activity.js.map +1 -0
- package/gateway/config.d.ts +50 -0
- package/gateway/config.d.ts.map +1 -0
- package/gateway/config.js +200 -0
- package/gateway/config.js.map +1 -0
- package/gateway/handlers/anthropic.d.ts +12 -0
- package/gateway/handlers/anthropic.d.ts.map +1 -0
- package/gateway/handlers/anthropic.js +254 -0
- package/gateway/handlers/anthropic.js.map +1 -0
- package/gateway/handlers/gemini.d.ts +12 -0
- package/gateway/handlers/gemini.d.ts.map +1 -0
- package/gateway/handlers/gemini.js +101 -0
- package/gateway/handlers/gemini.js.map +1 -0
- package/gateway/handlers/models.d.ts +4 -0
- package/gateway/handlers/models.d.ts.map +1 -0
- package/gateway/handlers/models.js +36 -0
- package/gateway/handlers/models.js.map +1 -0
- package/gateway/handlers/openai.d.ts +16 -0
- package/gateway/handlers/openai.d.ts.map +1 -0
- package/gateway/handlers/openai.js +254 -0
- package/gateway/handlers/openai.js.map +1 -0
- package/gateway/index.d.ts +27 -0
- package/gateway/index.d.ts.map +1 -0
- package/gateway/index.js +293 -0
- package/gateway/index.js.map +1 -0
- package/gateway/mapping-store.d.ts +38 -0
- package/gateway/mapping-store.d.ts.map +1 -0
- package/gateway/mapping-store.js +74 -0
- package/gateway/mapping-store.js.map +1 -0
- package/gateway/restorer.d.ts +63 -0
- package/gateway/restorer.d.ts.map +1 -0
- package/gateway/restorer.js +284 -0
- package/gateway/restorer.js.map +1 -0
- package/gateway/sanitizer.d.ts +17 -0
- package/gateway/sanitizer.d.ts.map +1 -0
- package/gateway/sanitizer.js +228 -0
- package/gateway/sanitizer.js.map +1 -0
- package/gateway/types.d.ts +53 -0
- package/gateway/types.d.ts.map +1 -0
- package/gateway/types.js +5 -0
- package/gateway/types.js.map +1 -0
- package/openclaw.plugin.json +86 -0
- package/package.json +74 -0
- package/samples/Untitled +1 -0
- package/samples/clean-email.txt +20 -0
- package/samples/test-document.md +53 -0
- package/samples/test-email-popup.txt +44 -0
- package/samples/test-email.txt +32 -0
- package/samples/test-webpage.html +51 -0
- package/scripts/enterprise-enroll.sh +89 -0
- package/scripts/enterprise-unenroll.sh +75 -0
|
@@ -0,0 +1,4151 @@
|
|
|
1
|
+
export const id = 62;
|
|
2
|
+
export const ids = [62];
|
|
3
|
+
export const modules = {
|
|
4
|
+
|
|
5
|
+
/***/ 8575:
|
|
6
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
7
|
+
|
|
8
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
9
|
+
/* harmony export */ Hs: () => (/* binding */ mapColumnsInAliasedSQLToAlias),
|
|
10
|
+
/* harmony export */ Ht: () => (/* binding */ ColumnAliasProxyHandler),
|
|
11
|
+
/* harmony export */ h_: () => (/* binding */ TableAliasProxyHandler),
|
|
12
|
+
/* harmony export */ oG: () => (/* binding */ aliasedTable),
|
|
13
|
+
/* harmony export */ ug: () => (/* binding */ aliasedTableColumn),
|
|
14
|
+
/* harmony export */ yY: () => (/* binding */ mapColumnsInSQLToAlias)
|
|
15
|
+
/* harmony export */ });
|
|
16
|
+
/* unused harmony exports RelationTableAliasProxyHandler, aliasedRelation */
|
|
17
|
+
/* harmony import */ var _column_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(2345);
|
|
18
|
+
/* harmony import */ var _entity_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9724);
|
|
19
|
+
/* harmony import */ var _sql_sql_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(183);
|
|
20
|
+
/* harmony import */ var _table_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(8407);
|
|
21
|
+
/* harmony import */ var _view_common_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6146);
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class ColumnAliasProxyHandler {
|
|
28
|
+
constructor(table) {
|
|
29
|
+
this.table = table;
|
|
30
|
+
}
|
|
31
|
+
static [_entity_js__WEBPACK_IMPORTED_MODULE_0__/* .entityKind */ .i] = "ColumnAliasProxyHandler";
|
|
32
|
+
get(columnObj, prop) {
|
|
33
|
+
if (prop === "table") {
|
|
34
|
+
return this.table;
|
|
35
|
+
}
|
|
36
|
+
return columnObj[prop];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
class TableAliasProxyHandler {
|
|
40
|
+
constructor(alias, replaceOriginalName) {
|
|
41
|
+
this.alias = alias;
|
|
42
|
+
this.replaceOriginalName = replaceOriginalName;
|
|
43
|
+
}
|
|
44
|
+
static [_entity_js__WEBPACK_IMPORTED_MODULE_0__/* .entityKind */ .i] = "TableAliasProxyHandler";
|
|
45
|
+
get(target, prop) {
|
|
46
|
+
if (prop === _table_js__WEBPACK_IMPORTED_MODULE_1__/* .Table */ .XI.Symbol.IsAlias) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
if (prop === _table_js__WEBPACK_IMPORTED_MODULE_1__/* .Table */ .XI.Symbol.Name) {
|
|
50
|
+
return this.alias;
|
|
51
|
+
}
|
|
52
|
+
if (this.replaceOriginalName && prop === _table_js__WEBPACK_IMPORTED_MODULE_1__/* .Table */ .XI.Symbol.OriginalName) {
|
|
53
|
+
return this.alias;
|
|
54
|
+
}
|
|
55
|
+
if (prop === _view_common_js__WEBPACK_IMPORTED_MODULE_2__/* .ViewBaseConfig */ .n) {
|
|
56
|
+
return {
|
|
57
|
+
...target[_view_common_js__WEBPACK_IMPORTED_MODULE_2__/* .ViewBaseConfig */ .n],
|
|
58
|
+
name: this.alias,
|
|
59
|
+
isAlias: true
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
if (prop === _table_js__WEBPACK_IMPORTED_MODULE_1__/* .Table */ .XI.Symbol.Columns) {
|
|
63
|
+
const columns = target[_table_js__WEBPACK_IMPORTED_MODULE_1__/* .Table */ .XI.Symbol.Columns];
|
|
64
|
+
if (!columns) {
|
|
65
|
+
return columns;
|
|
66
|
+
}
|
|
67
|
+
const proxiedColumns = {};
|
|
68
|
+
Object.keys(columns).map((key) => {
|
|
69
|
+
proxiedColumns[key] = new Proxy(
|
|
70
|
+
columns[key],
|
|
71
|
+
new ColumnAliasProxyHandler(new Proxy(target, this))
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
return proxiedColumns;
|
|
75
|
+
}
|
|
76
|
+
const value = target[prop];
|
|
77
|
+
if ((0,_entity_js__WEBPACK_IMPORTED_MODULE_0__.is)(value, _column_js__WEBPACK_IMPORTED_MODULE_3__/* .Column */ .V)) {
|
|
78
|
+
return new Proxy(value, new ColumnAliasProxyHandler(new Proxy(target, this)));
|
|
79
|
+
}
|
|
80
|
+
return value;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
class RelationTableAliasProxyHandler {
|
|
84
|
+
constructor(alias) {
|
|
85
|
+
this.alias = alias;
|
|
86
|
+
}
|
|
87
|
+
static [_entity_js__WEBPACK_IMPORTED_MODULE_0__/* .entityKind */ .i] = (/* unused pure expression or super */ null && ("RelationTableAliasProxyHandler"));
|
|
88
|
+
get(target, prop) {
|
|
89
|
+
if (prop === "sourceTable") {
|
|
90
|
+
return aliasedTable(target.sourceTable, this.alias);
|
|
91
|
+
}
|
|
92
|
+
return target[prop];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function aliasedTable(table, tableAlias) {
|
|
96
|
+
return new Proxy(table, new TableAliasProxyHandler(tableAlias, false));
|
|
97
|
+
}
|
|
98
|
+
function aliasedRelation(relation, tableAlias) {
|
|
99
|
+
return new Proxy(relation, new RelationTableAliasProxyHandler(tableAlias));
|
|
100
|
+
}
|
|
101
|
+
function aliasedTableColumn(column, tableAlias) {
|
|
102
|
+
return new Proxy(
|
|
103
|
+
column,
|
|
104
|
+
new ColumnAliasProxyHandler(new Proxy(column.table, new TableAliasProxyHandler(tableAlias, false)))
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
function mapColumnsInAliasedSQLToAlias(query, alias) {
|
|
108
|
+
return new _sql_sql_js__WEBPACK_IMPORTED_MODULE_4__/* .SQL */ .Xs.Aliased(mapColumnsInSQLToAlias(query.sql, alias), query.fieldAlias);
|
|
109
|
+
}
|
|
110
|
+
function mapColumnsInSQLToAlias(query, alias) {
|
|
111
|
+
return _sql_sql_js__WEBPACK_IMPORTED_MODULE_4__/* .sql */ .ll.join(query.queryChunks.map((c) => {
|
|
112
|
+
if ((0,_entity_js__WEBPACK_IMPORTED_MODULE_0__.is)(c, _column_js__WEBPACK_IMPORTED_MODULE_3__/* .Column */ .V)) {
|
|
113
|
+
return aliasedTableColumn(c, alias);
|
|
114
|
+
}
|
|
115
|
+
if ((0,_entity_js__WEBPACK_IMPORTED_MODULE_0__.is)(c, _sql_sql_js__WEBPACK_IMPORTED_MODULE_4__/* .SQL */ .Xs)) {
|
|
116
|
+
return mapColumnsInSQLToAlias(c, alias);
|
|
117
|
+
}
|
|
118
|
+
if ((0,_entity_js__WEBPACK_IMPORTED_MODULE_0__.is)(c, _sql_sql_js__WEBPACK_IMPORTED_MODULE_4__/* .SQL */ .Xs.Aliased)) {
|
|
119
|
+
return mapColumnsInAliasedSQLToAlias(c, alias);
|
|
120
|
+
}
|
|
121
|
+
return c;
|
|
122
|
+
}));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
//# sourceMappingURL=alias.js.map
|
|
126
|
+
|
|
127
|
+
/***/ }),
|
|
128
|
+
|
|
129
|
+
/***/ 568:
|
|
130
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
131
|
+
|
|
132
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
133
|
+
/* harmony export */ Yn: () => (/* binding */ CasingCache)
|
|
134
|
+
/* harmony export */ });
|
|
135
|
+
/* unused harmony exports toCamelCase, toSnakeCase */
|
|
136
|
+
/* harmony import */ var _entity_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9724);
|
|
137
|
+
/* harmony import */ var _table_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(8407);
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
function toSnakeCase(input) {
|
|
141
|
+
const words = input.replace(/['\u2019]/g, "").match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g) ?? [];
|
|
142
|
+
return words.map((word) => word.toLowerCase()).join("_");
|
|
143
|
+
}
|
|
144
|
+
function toCamelCase(input) {
|
|
145
|
+
const words = input.replace(/['\u2019]/g, "").match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g) ?? [];
|
|
146
|
+
return words.reduce((acc, word, i) => {
|
|
147
|
+
const formattedWord = i === 0 ? word.toLowerCase() : `${word[0].toUpperCase()}${word.slice(1)}`;
|
|
148
|
+
return acc + formattedWord;
|
|
149
|
+
}, "");
|
|
150
|
+
}
|
|
151
|
+
function noopCase(input) {
|
|
152
|
+
return input;
|
|
153
|
+
}
|
|
154
|
+
class CasingCache {
|
|
155
|
+
static [_entity_js__WEBPACK_IMPORTED_MODULE_0__/* .entityKind */ .i] = "CasingCache";
|
|
156
|
+
/** @internal */
|
|
157
|
+
cache = {};
|
|
158
|
+
cachedTables = {};
|
|
159
|
+
convert;
|
|
160
|
+
constructor(casing) {
|
|
161
|
+
this.convert = casing === "snake_case" ? toSnakeCase : casing === "camelCase" ? toCamelCase : noopCase;
|
|
162
|
+
}
|
|
163
|
+
getColumnCasing(column) {
|
|
164
|
+
if (!column.keyAsName)
|
|
165
|
+
return column.name;
|
|
166
|
+
const schema = column.table[_table_js__WEBPACK_IMPORTED_MODULE_1__/* .Table */ .XI.Symbol.Schema] ?? "public";
|
|
167
|
+
const tableName = column.table[_table_js__WEBPACK_IMPORTED_MODULE_1__/* .Table */ .XI.Symbol.OriginalName];
|
|
168
|
+
const key = `${schema}.${tableName}.${column.name}`;
|
|
169
|
+
if (!this.cache[key]) {
|
|
170
|
+
this.cacheTable(column.table);
|
|
171
|
+
}
|
|
172
|
+
return this.cache[key];
|
|
173
|
+
}
|
|
174
|
+
cacheTable(table) {
|
|
175
|
+
const schema = table[_table_js__WEBPACK_IMPORTED_MODULE_1__/* .Table */ .XI.Symbol.Schema] ?? "public";
|
|
176
|
+
const tableName = table[_table_js__WEBPACK_IMPORTED_MODULE_1__/* .Table */ .XI.Symbol.OriginalName];
|
|
177
|
+
const tableKey = `${schema}.${tableName}`;
|
|
178
|
+
if (!this.cachedTables[tableKey]) {
|
|
179
|
+
for (const column of Object.values(table[_table_js__WEBPACK_IMPORTED_MODULE_1__/* .Table */ .XI.Symbol.Columns])) {
|
|
180
|
+
const columnKey = `${tableKey}.${column.name}`;
|
|
181
|
+
this.cache[columnKey] = this.convert(column.name);
|
|
182
|
+
}
|
|
183
|
+
this.cachedTables[tableKey] = true;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
clearCache() {
|
|
187
|
+
this.cache = {};
|
|
188
|
+
this.cachedTables = {};
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
//# sourceMappingURL=casing.js.map
|
|
193
|
+
|
|
194
|
+
/***/ }),
|
|
195
|
+
|
|
196
|
+
/***/ 6920:
|
|
197
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
198
|
+
|
|
199
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
200
|
+
/* harmony export */ j: () => (/* binding */ TransactionRollbackError),
|
|
201
|
+
/* harmony export */ n: () => (/* binding */ DrizzleError)
|
|
202
|
+
/* harmony export */ });
|
|
203
|
+
/* harmony import */ var _entity_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9724);
|
|
204
|
+
|
|
205
|
+
class DrizzleError extends Error {
|
|
206
|
+
static [_entity_js__WEBPACK_IMPORTED_MODULE_0__/* .entityKind */ .i] = "DrizzleError";
|
|
207
|
+
constructor({ message, cause }) {
|
|
208
|
+
super(message);
|
|
209
|
+
this.name = "DrizzleError";
|
|
210
|
+
this.cause = cause;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
class TransactionRollbackError extends DrizzleError {
|
|
214
|
+
static [_entity_js__WEBPACK_IMPORTED_MODULE_0__/* .entityKind */ .i] = "TransactionRollbackError";
|
|
215
|
+
constructor() {
|
|
216
|
+
super({ message: "Rollback" });
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
//# sourceMappingURL=errors.js.map
|
|
221
|
+
|
|
222
|
+
/***/ }),
|
|
223
|
+
|
|
224
|
+
/***/ 6743:
|
|
225
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
226
|
+
|
|
227
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
228
|
+
/* harmony export */ Pv: () => (/* binding */ NoopLogger),
|
|
229
|
+
/* harmony export */ w: () => (/* binding */ DefaultLogger)
|
|
230
|
+
/* harmony export */ });
|
|
231
|
+
/* unused harmony export ConsoleLogWriter */
|
|
232
|
+
/* harmony import */ var _entity_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9724);
|
|
233
|
+
|
|
234
|
+
class ConsoleLogWriter {
|
|
235
|
+
static [_entity_js__WEBPACK_IMPORTED_MODULE_0__/* .entityKind */ .i] = "ConsoleLogWriter";
|
|
236
|
+
write(message) {
|
|
237
|
+
console.log(message);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
class DefaultLogger {
|
|
241
|
+
static [_entity_js__WEBPACK_IMPORTED_MODULE_0__/* .entityKind */ .i] = "DefaultLogger";
|
|
242
|
+
writer;
|
|
243
|
+
constructor(config) {
|
|
244
|
+
this.writer = config?.writer ?? new ConsoleLogWriter();
|
|
245
|
+
}
|
|
246
|
+
logQuery(query, params) {
|
|
247
|
+
const stringifiedParams = params.map((p) => {
|
|
248
|
+
try {
|
|
249
|
+
return JSON.stringify(p);
|
|
250
|
+
} catch {
|
|
251
|
+
return String(p);
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
const paramsStr = stringifiedParams.length ? ` -- params: [${stringifiedParams.join(", ")}]` : "";
|
|
255
|
+
this.writer.write(`Query: ${query}${paramsStr}`);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
class NoopLogger {
|
|
259
|
+
static [_entity_js__WEBPACK_IMPORTED_MODULE_0__/* .entityKind */ .i] = "NoopLogger";
|
|
260
|
+
logQuery() {
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
//# sourceMappingURL=logger.js.map
|
|
265
|
+
|
|
266
|
+
/***/ }),
|
|
267
|
+
|
|
268
|
+
/***/ 8062:
|
|
269
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
// EXPORTS
|
|
273
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
274
|
+
drizzle: () => (/* reexport */ drizzle)
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
// UNUSED EXPORTS: PostgresJsDatabase, PostgresJsPreparedQuery, PostgresJsSession, PostgresJsTransaction
|
|
278
|
+
|
|
279
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/src/index.js + 9 modules
|
|
280
|
+
var src = __webpack_require__(5678);
|
|
281
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/entity.js
|
|
282
|
+
var entity = __webpack_require__(9724);
|
|
283
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/logger.js
|
|
284
|
+
var drizzle_orm_logger = __webpack_require__(6743);
|
|
285
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/alias.js
|
|
286
|
+
var alias = __webpack_require__(8575);
|
|
287
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/casing.js
|
|
288
|
+
var casing = __webpack_require__(568);
|
|
289
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/column.js
|
|
290
|
+
var column = __webpack_require__(2345);
|
|
291
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/errors.js
|
|
292
|
+
var errors = __webpack_require__(6920);
|
|
293
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/pg-core/columns/common.js + 3 modules
|
|
294
|
+
var common = __webpack_require__(2414);
|
|
295
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/pg-core/columns/jsonb.js
|
|
296
|
+
var jsonb = __webpack_require__(1343);
|
|
297
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/pg-core/columns/json.js
|
|
298
|
+
var json = __webpack_require__(6077);
|
|
299
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/pg-core/columns/numeric.js
|
|
300
|
+
var numeric = __webpack_require__(5584);
|
|
301
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/pg-core/columns/time.js
|
|
302
|
+
var time = __webpack_require__(1810);
|
|
303
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/pg-core/columns/timestamp.js
|
|
304
|
+
var timestamp = __webpack_require__(8631);
|
|
305
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/pg-core/columns/date.js
|
|
306
|
+
var date = __webpack_require__(763);
|
|
307
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/pg-core/columns/uuid.js
|
|
308
|
+
var uuid = __webpack_require__(1848);
|
|
309
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/pg-core/table.js + 22 modules
|
|
310
|
+
var pg_core_table = __webpack_require__(698);
|
|
311
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/relations.js + 1 modules
|
|
312
|
+
var relations = __webpack_require__(4750);
|
|
313
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/sql/sql.js + 1 modules
|
|
314
|
+
var sql = __webpack_require__(183);
|
|
315
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/sql/expressions/conditions.js
|
|
316
|
+
var conditions = __webpack_require__(420);
|
|
317
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/subquery.js
|
|
318
|
+
var subquery = __webpack_require__(6453);
|
|
319
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/table.js
|
|
320
|
+
var drizzle_orm_table = __webpack_require__(8407);
|
|
321
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/utils.js
|
|
322
|
+
var utils = __webpack_require__(3853);
|
|
323
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/view-common.js
|
|
324
|
+
var view_common = __webpack_require__(6146);
|
|
325
|
+
;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/pg-core/view-base.js
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
class PgViewBase extends sql/* View */.Ss {
|
|
329
|
+
static [entity/* entityKind */.i] = "PgViewBase";
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
//# sourceMappingURL=view-base.js.map
|
|
333
|
+
;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/pg-core/dialect.js
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
class PgDialect {
|
|
350
|
+
static [entity/* entityKind */.i] = "PgDialect";
|
|
351
|
+
/** @internal */
|
|
352
|
+
casing;
|
|
353
|
+
constructor(config) {
|
|
354
|
+
this.casing = new casing/* CasingCache */.Yn(config?.casing);
|
|
355
|
+
}
|
|
356
|
+
async migrate(migrations, session, config) {
|
|
357
|
+
const migrationsTable = typeof config === "string" ? "__drizzle_migrations" : config.migrationsTable ?? "__drizzle_migrations";
|
|
358
|
+
const migrationsSchema = typeof config === "string" ? "drizzle" : config.migrationsSchema ?? "drizzle";
|
|
359
|
+
const migrationTableCreate = (0,sql/* sql */.ll)`
|
|
360
|
+
CREATE TABLE IF NOT EXISTS ${sql/* sql */.ll.identifier(migrationsSchema)}.${sql/* sql */.ll.identifier(migrationsTable)} (
|
|
361
|
+
id SERIAL PRIMARY KEY,
|
|
362
|
+
hash text NOT NULL,
|
|
363
|
+
created_at bigint
|
|
364
|
+
)
|
|
365
|
+
`;
|
|
366
|
+
await session.execute((0,sql/* sql */.ll)`CREATE SCHEMA IF NOT EXISTS ${sql/* sql */.ll.identifier(migrationsSchema)}`);
|
|
367
|
+
await session.execute(migrationTableCreate);
|
|
368
|
+
const dbMigrations = await session.all(
|
|
369
|
+
(0,sql/* sql */.ll)`select id, hash, created_at from ${sql/* sql */.ll.identifier(migrationsSchema)}.${sql/* sql */.ll.identifier(migrationsTable)} order by created_at desc limit 1`
|
|
370
|
+
);
|
|
371
|
+
const lastDbMigration = dbMigrations[0];
|
|
372
|
+
await session.transaction(async (tx) => {
|
|
373
|
+
for await (const migration of migrations) {
|
|
374
|
+
if (!lastDbMigration || Number(lastDbMigration.created_at) < migration.folderMillis) {
|
|
375
|
+
for (const stmt of migration.sql) {
|
|
376
|
+
await tx.execute(sql/* sql */.ll.raw(stmt));
|
|
377
|
+
}
|
|
378
|
+
await tx.execute(
|
|
379
|
+
(0,sql/* sql */.ll)`insert into ${sql/* sql */.ll.identifier(migrationsSchema)}.${sql/* sql */.ll.identifier(migrationsTable)} ("hash", "created_at") values(${migration.hash}, ${migration.folderMillis})`
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
escapeName(name) {
|
|
386
|
+
return `"${name}"`;
|
|
387
|
+
}
|
|
388
|
+
escapeParam(num) {
|
|
389
|
+
return `$${num + 1}`;
|
|
390
|
+
}
|
|
391
|
+
escapeString(str) {
|
|
392
|
+
return `'${str.replace(/'/g, "''")}'`;
|
|
393
|
+
}
|
|
394
|
+
buildWithCTE(queries) {
|
|
395
|
+
if (!queries?.length)
|
|
396
|
+
return void 0;
|
|
397
|
+
const withSqlChunks = [(0,sql/* sql */.ll)`with `];
|
|
398
|
+
for (const [i, w] of queries.entries()) {
|
|
399
|
+
withSqlChunks.push((0,sql/* sql */.ll)`${sql/* sql */.ll.identifier(w._.alias)} as (${w._.sql})`);
|
|
400
|
+
if (i < queries.length - 1) {
|
|
401
|
+
withSqlChunks.push((0,sql/* sql */.ll)`, `);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
withSqlChunks.push((0,sql/* sql */.ll)` `);
|
|
405
|
+
return sql/* sql */.ll.join(withSqlChunks);
|
|
406
|
+
}
|
|
407
|
+
buildDeleteQuery({ table, where, returning, withList }) {
|
|
408
|
+
const withSql = this.buildWithCTE(withList);
|
|
409
|
+
const returningSql = returning ? (0,sql/* sql */.ll)` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
|
|
410
|
+
const whereSql = where ? (0,sql/* sql */.ll)` where ${where}` : void 0;
|
|
411
|
+
return (0,sql/* sql */.ll)`${withSql}delete from ${table}${whereSql}${returningSql}`;
|
|
412
|
+
}
|
|
413
|
+
buildUpdateSet(table, set) {
|
|
414
|
+
const tableColumns = table[drizzle_orm_table/* Table */.XI.Symbol.Columns];
|
|
415
|
+
const columnNames = Object.keys(tableColumns).filter(
|
|
416
|
+
(colName) => set[colName] !== void 0 || tableColumns[colName]?.onUpdateFn !== void 0
|
|
417
|
+
);
|
|
418
|
+
const setSize = columnNames.length;
|
|
419
|
+
return sql/* sql */.ll.join(columnNames.flatMap((colName, i) => {
|
|
420
|
+
const col = tableColumns[colName];
|
|
421
|
+
const value = set[colName] ?? sql/* sql */.ll.param(col.onUpdateFn(), col);
|
|
422
|
+
const res = (0,sql/* sql */.ll)`${sql/* sql */.ll.identifier(this.casing.getColumnCasing(col))} = ${value}`;
|
|
423
|
+
if (i < setSize - 1) {
|
|
424
|
+
return [res, sql/* sql */.ll.raw(", ")];
|
|
425
|
+
}
|
|
426
|
+
return [res];
|
|
427
|
+
}));
|
|
428
|
+
}
|
|
429
|
+
buildUpdateQuery({ table, set, where, returning, withList, from, joins }) {
|
|
430
|
+
const withSql = this.buildWithCTE(withList);
|
|
431
|
+
const tableName = table[pg_core_table/* PgTable */.mu.Symbol.Name];
|
|
432
|
+
const tableSchema = table[pg_core_table/* PgTable */.mu.Symbol.Schema];
|
|
433
|
+
const origTableName = table[pg_core_table/* PgTable */.mu.Symbol.OriginalName];
|
|
434
|
+
const alias = tableName === origTableName ? void 0 : tableName;
|
|
435
|
+
const tableSql = (0,sql/* sql */.ll)`${tableSchema ? (0,sql/* sql */.ll)`${sql/* sql */.ll.identifier(tableSchema)}.` : void 0}${sql/* sql */.ll.identifier(origTableName)}${alias && (0,sql/* sql */.ll)` ${sql/* sql */.ll.identifier(alias)}`}`;
|
|
436
|
+
const setSql = this.buildUpdateSet(table, set);
|
|
437
|
+
const fromSql = from && sql/* sql */.ll.join([sql/* sql */.ll.raw(" from "), this.buildFromTable(from)]);
|
|
438
|
+
const joinsSql = this.buildJoins(joins);
|
|
439
|
+
const returningSql = returning ? (0,sql/* sql */.ll)` returning ${this.buildSelection(returning, { isSingleTable: !from })}` : void 0;
|
|
440
|
+
const whereSql = where ? (0,sql/* sql */.ll)` where ${where}` : void 0;
|
|
441
|
+
return (0,sql/* sql */.ll)`${withSql}update ${tableSql} set ${setSql}${fromSql}${joinsSql}${whereSql}${returningSql}`;
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Builds selection SQL with provided fields/expressions
|
|
445
|
+
*
|
|
446
|
+
* Examples:
|
|
447
|
+
*
|
|
448
|
+
* `select <selection> from`
|
|
449
|
+
*
|
|
450
|
+
* `insert ... returning <selection>`
|
|
451
|
+
*
|
|
452
|
+
* If `isSingleTable` is true, then columns won't be prefixed with table name
|
|
453
|
+
*/
|
|
454
|
+
buildSelection(fields, { isSingleTable = false } = {}) {
|
|
455
|
+
const columnsLen = fields.length;
|
|
456
|
+
const chunks = fields.flatMap(({ field }, i) => {
|
|
457
|
+
const chunk = [];
|
|
458
|
+
if ((0,entity.is)(field, sql/* SQL */.Xs.Aliased) && field.isSelectionField) {
|
|
459
|
+
chunk.push(sql/* sql */.ll.identifier(field.fieldAlias));
|
|
460
|
+
} else if ((0,entity.is)(field, sql/* SQL */.Xs.Aliased) || (0,entity.is)(field, sql/* SQL */.Xs)) {
|
|
461
|
+
const query = (0,entity.is)(field, sql/* SQL */.Xs.Aliased) ? field.sql : field;
|
|
462
|
+
if (isSingleTable) {
|
|
463
|
+
chunk.push(
|
|
464
|
+
new sql/* SQL */.Xs(
|
|
465
|
+
query.queryChunks.map((c) => {
|
|
466
|
+
if ((0,entity.is)(c, common/* PgColumn */.Kl)) {
|
|
467
|
+
return sql/* sql */.ll.identifier(this.casing.getColumnCasing(c));
|
|
468
|
+
}
|
|
469
|
+
return c;
|
|
470
|
+
})
|
|
471
|
+
)
|
|
472
|
+
);
|
|
473
|
+
} else {
|
|
474
|
+
chunk.push(query);
|
|
475
|
+
}
|
|
476
|
+
if ((0,entity.is)(field, sql/* SQL */.Xs.Aliased)) {
|
|
477
|
+
chunk.push((0,sql/* sql */.ll)` as ${sql/* sql */.ll.identifier(field.fieldAlias)}`);
|
|
478
|
+
}
|
|
479
|
+
} else if ((0,entity.is)(field, column/* Column */.V)) {
|
|
480
|
+
if (isSingleTable) {
|
|
481
|
+
chunk.push(sql/* sql */.ll.identifier(this.casing.getColumnCasing(field)));
|
|
482
|
+
} else {
|
|
483
|
+
chunk.push(field);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
if (i < columnsLen - 1) {
|
|
487
|
+
chunk.push((0,sql/* sql */.ll)`, `);
|
|
488
|
+
}
|
|
489
|
+
return chunk;
|
|
490
|
+
});
|
|
491
|
+
return sql/* sql */.ll.join(chunks);
|
|
492
|
+
}
|
|
493
|
+
buildJoins(joins) {
|
|
494
|
+
if (!joins || joins.length === 0) {
|
|
495
|
+
return void 0;
|
|
496
|
+
}
|
|
497
|
+
const joinsArray = [];
|
|
498
|
+
for (const [index, joinMeta] of joins.entries()) {
|
|
499
|
+
if (index === 0) {
|
|
500
|
+
joinsArray.push((0,sql/* sql */.ll)` `);
|
|
501
|
+
}
|
|
502
|
+
const table = joinMeta.table;
|
|
503
|
+
const lateralSql = joinMeta.lateral ? (0,sql/* sql */.ll)` lateral` : void 0;
|
|
504
|
+
if ((0,entity.is)(table, pg_core_table/* PgTable */.mu)) {
|
|
505
|
+
const tableName = table[pg_core_table/* PgTable */.mu.Symbol.Name];
|
|
506
|
+
const tableSchema = table[pg_core_table/* PgTable */.mu.Symbol.Schema];
|
|
507
|
+
const origTableName = table[pg_core_table/* PgTable */.mu.Symbol.OriginalName];
|
|
508
|
+
const alias = tableName === origTableName ? void 0 : joinMeta.alias;
|
|
509
|
+
joinsArray.push(
|
|
510
|
+
(0,sql/* sql */.ll)`${sql/* sql */.ll.raw(joinMeta.joinType)} join${lateralSql} ${tableSchema ? (0,sql/* sql */.ll)`${sql/* sql */.ll.identifier(tableSchema)}.` : void 0}${sql/* sql */.ll.identifier(origTableName)}${alias && (0,sql/* sql */.ll)` ${sql/* sql */.ll.identifier(alias)}`} on ${joinMeta.on}`
|
|
511
|
+
);
|
|
512
|
+
} else if ((0,entity.is)(table, sql/* View */.Ss)) {
|
|
513
|
+
const viewName = table[view_common/* ViewBaseConfig */.n].name;
|
|
514
|
+
const viewSchema = table[view_common/* ViewBaseConfig */.n].schema;
|
|
515
|
+
const origViewName = table[view_common/* ViewBaseConfig */.n].originalName;
|
|
516
|
+
const alias = viewName === origViewName ? void 0 : joinMeta.alias;
|
|
517
|
+
joinsArray.push(
|
|
518
|
+
(0,sql/* sql */.ll)`${sql/* sql */.ll.raw(joinMeta.joinType)} join${lateralSql} ${viewSchema ? (0,sql/* sql */.ll)`${sql/* sql */.ll.identifier(viewSchema)}.` : void 0}${sql/* sql */.ll.identifier(origViewName)}${alias && (0,sql/* sql */.ll)` ${sql/* sql */.ll.identifier(alias)}`} on ${joinMeta.on}`
|
|
519
|
+
);
|
|
520
|
+
} else {
|
|
521
|
+
joinsArray.push(
|
|
522
|
+
(0,sql/* sql */.ll)`${sql/* sql */.ll.raw(joinMeta.joinType)} join${lateralSql} ${table} on ${joinMeta.on}`
|
|
523
|
+
);
|
|
524
|
+
}
|
|
525
|
+
if (index < joins.length - 1) {
|
|
526
|
+
joinsArray.push((0,sql/* sql */.ll)` `);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
return sql/* sql */.ll.join(joinsArray);
|
|
530
|
+
}
|
|
531
|
+
buildFromTable(table) {
|
|
532
|
+
if ((0,entity.is)(table, drizzle_orm_table/* Table */.XI) && table[drizzle_orm_table/* Table */.XI.Symbol.OriginalName] !== table[drizzle_orm_table/* Table */.XI.Symbol.Name]) {
|
|
533
|
+
let fullName = (0,sql/* sql */.ll)`${sql/* sql */.ll.identifier(table[drizzle_orm_table/* Table */.XI.Symbol.OriginalName])}`;
|
|
534
|
+
if (table[drizzle_orm_table/* Table */.XI.Symbol.Schema]) {
|
|
535
|
+
fullName = (0,sql/* sql */.ll)`${sql/* sql */.ll.identifier(table[drizzle_orm_table/* Table */.XI.Symbol.Schema])}.${fullName}`;
|
|
536
|
+
}
|
|
537
|
+
return (0,sql/* sql */.ll)`${fullName} ${sql/* sql */.ll.identifier(table[drizzle_orm_table/* Table */.XI.Symbol.Name])}`;
|
|
538
|
+
}
|
|
539
|
+
return table;
|
|
540
|
+
}
|
|
541
|
+
buildSelectQuery({
|
|
542
|
+
withList,
|
|
543
|
+
fields,
|
|
544
|
+
fieldsFlat,
|
|
545
|
+
where,
|
|
546
|
+
having,
|
|
547
|
+
table,
|
|
548
|
+
joins,
|
|
549
|
+
orderBy,
|
|
550
|
+
groupBy,
|
|
551
|
+
limit,
|
|
552
|
+
offset,
|
|
553
|
+
lockingClause,
|
|
554
|
+
distinct,
|
|
555
|
+
setOperators
|
|
556
|
+
}) {
|
|
557
|
+
const fieldsList = fieldsFlat ?? (0,utils/* orderSelectedFields */.He)(fields);
|
|
558
|
+
for (const f of fieldsList) {
|
|
559
|
+
if ((0,entity.is)(f.field, column/* Column */.V) && (0,drizzle_orm_table/* getTableName */.Io)(f.field.table) !== ((0,entity.is)(table, subquery/* Subquery */.n) ? table._.alias : (0,entity.is)(table, PgViewBase) ? table[view_common/* ViewBaseConfig */.n].name : (0,entity.is)(table, sql/* SQL */.Xs) ? void 0 : (0,drizzle_orm_table/* getTableName */.Io)(table)) && !((table2) => joins?.some(
|
|
560
|
+
({ alias }) => alias === (table2[drizzle_orm_table/* Table */.XI.Symbol.IsAlias] ? (0,drizzle_orm_table/* getTableName */.Io)(table2) : table2[drizzle_orm_table/* Table */.XI.Symbol.BaseName])
|
|
561
|
+
))(f.field.table)) {
|
|
562
|
+
const tableName = (0,drizzle_orm_table/* getTableName */.Io)(f.field.table);
|
|
563
|
+
throw new Error(
|
|
564
|
+
`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?`
|
|
565
|
+
);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
const isSingleTable = !joins || joins.length === 0;
|
|
569
|
+
const withSql = this.buildWithCTE(withList);
|
|
570
|
+
let distinctSql;
|
|
571
|
+
if (distinct) {
|
|
572
|
+
distinctSql = distinct === true ? (0,sql/* sql */.ll)` distinct` : (0,sql/* sql */.ll)` distinct on (${sql/* sql */.ll.join(distinct.on, (0,sql/* sql */.ll)`, `)})`;
|
|
573
|
+
}
|
|
574
|
+
const selection = this.buildSelection(fieldsList, { isSingleTable });
|
|
575
|
+
const tableSql = this.buildFromTable(table);
|
|
576
|
+
const joinsSql = this.buildJoins(joins);
|
|
577
|
+
const whereSql = where ? (0,sql/* sql */.ll)` where ${where}` : void 0;
|
|
578
|
+
const havingSql = having ? (0,sql/* sql */.ll)` having ${having}` : void 0;
|
|
579
|
+
let orderBySql;
|
|
580
|
+
if (orderBy && orderBy.length > 0) {
|
|
581
|
+
orderBySql = (0,sql/* sql */.ll)` order by ${sql/* sql */.ll.join(orderBy, (0,sql/* sql */.ll)`, `)}`;
|
|
582
|
+
}
|
|
583
|
+
let groupBySql;
|
|
584
|
+
if (groupBy && groupBy.length > 0) {
|
|
585
|
+
groupBySql = (0,sql/* sql */.ll)` group by ${sql/* sql */.ll.join(groupBy, (0,sql/* sql */.ll)`, `)}`;
|
|
586
|
+
}
|
|
587
|
+
const limitSql = typeof limit === "object" || typeof limit === "number" && limit >= 0 ? (0,sql/* sql */.ll)` limit ${limit}` : void 0;
|
|
588
|
+
const offsetSql = offset ? (0,sql/* sql */.ll)` offset ${offset}` : void 0;
|
|
589
|
+
const lockingClauseSql = sql/* sql */.ll.empty();
|
|
590
|
+
if (lockingClause) {
|
|
591
|
+
const clauseSql = (0,sql/* sql */.ll)` for ${sql/* sql */.ll.raw(lockingClause.strength)}`;
|
|
592
|
+
if (lockingClause.config.of) {
|
|
593
|
+
clauseSql.append(
|
|
594
|
+
(0,sql/* sql */.ll)` of ${sql/* sql */.ll.join(
|
|
595
|
+
Array.isArray(lockingClause.config.of) ? lockingClause.config.of : [lockingClause.config.of],
|
|
596
|
+
(0,sql/* sql */.ll)`, `
|
|
597
|
+
)}`
|
|
598
|
+
);
|
|
599
|
+
}
|
|
600
|
+
if (lockingClause.config.noWait) {
|
|
601
|
+
clauseSql.append((0,sql/* sql */.ll)` no wait`);
|
|
602
|
+
} else if (lockingClause.config.skipLocked) {
|
|
603
|
+
clauseSql.append((0,sql/* sql */.ll)` skip locked`);
|
|
604
|
+
}
|
|
605
|
+
lockingClauseSql.append(clauseSql);
|
|
606
|
+
}
|
|
607
|
+
const finalQuery = (0,sql/* sql */.ll)`${withSql}select${distinctSql} ${selection} from ${tableSql}${joinsSql}${whereSql}${groupBySql}${havingSql}${orderBySql}${limitSql}${offsetSql}${lockingClauseSql}`;
|
|
608
|
+
if (setOperators.length > 0) {
|
|
609
|
+
return this.buildSetOperations(finalQuery, setOperators);
|
|
610
|
+
}
|
|
611
|
+
return finalQuery;
|
|
612
|
+
}
|
|
613
|
+
buildSetOperations(leftSelect, setOperators) {
|
|
614
|
+
const [setOperator, ...rest] = setOperators;
|
|
615
|
+
if (!setOperator) {
|
|
616
|
+
throw new Error("Cannot pass undefined values to any set operator");
|
|
617
|
+
}
|
|
618
|
+
if (rest.length === 0) {
|
|
619
|
+
return this.buildSetOperationQuery({ leftSelect, setOperator });
|
|
620
|
+
}
|
|
621
|
+
return this.buildSetOperations(
|
|
622
|
+
this.buildSetOperationQuery({ leftSelect, setOperator }),
|
|
623
|
+
rest
|
|
624
|
+
);
|
|
625
|
+
}
|
|
626
|
+
buildSetOperationQuery({
|
|
627
|
+
leftSelect,
|
|
628
|
+
setOperator: { type, isAll, rightSelect, limit, orderBy, offset }
|
|
629
|
+
}) {
|
|
630
|
+
const leftChunk = (0,sql/* sql */.ll)`(${leftSelect.getSQL()}) `;
|
|
631
|
+
const rightChunk = (0,sql/* sql */.ll)`(${rightSelect.getSQL()})`;
|
|
632
|
+
let orderBySql;
|
|
633
|
+
if (orderBy && orderBy.length > 0) {
|
|
634
|
+
const orderByValues = [];
|
|
635
|
+
for (const singleOrderBy of orderBy) {
|
|
636
|
+
if ((0,entity.is)(singleOrderBy, common/* PgColumn */.Kl)) {
|
|
637
|
+
orderByValues.push(sql/* sql */.ll.identifier(singleOrderBy.name));
|
|
638
|
+
} else if ((0,entity.is)(singleOrderBy, sql/* SQL */.Xs)) {
|
|
639
|
+
for (let i = 0; i < singleOrderBy.queryChunks.length; i++) {
|
|
640
|
+
const chunk = singleOrderBy.queryChunks[i];
|
|
641
|
+
if ((0,entity.is)(chunk, common/* PgColumn */.Kl)) {
|
|
642
|
+
singleOrderBy.queryChunks[i] = sql/* sql */.ll.identifier(chunk.name);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
orderByValues.push((0,sql/* sql */.ll)`${singleOrderBy}`);
|
|
646
|
+
} else {
|
|
647
|
+
orderByValues.push((0,sql/* sql */.ll)`${singleOrderBy}`);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
orderBySql = (0,sql/* sql */.ll)` order by ${sql/* sql */.ll.join(orderByValues, (0,sql/* sql */.ll)`, `)} `;
|
|
651
|
+
}
|
|
652
|
+
const limitSql = typeof limit === "object" || typeof limit === "number" && limit >= 0 ? (0,sql/* sql */.ll)` limit ${limit}` : void 0;
|
|
653
|
+
const operatorChunk = sql/* sql */.ll.raw(`${type} ${isAll ? "all " : ""}`);
|
|
654
|
+
const offsetSql = offset ? (0,sql/* sql */.ll)` offset ${offset}` : void 0;
|
|
655
|
+
return (0,sql/* sql */.ll)`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;
|
|
656
|
+
}
|
|
657
|
+
buildInsertQuery({ table, values: valuesOrSelect, onConflict, returning, withList, select, overridingSystemValue_ }) {
|
|
658
|
+
const valuesSqlList = [];
|
|
659
|
+
const columns = table[drizzle_orm_table/* Table */.XI.Symbol.Columns];
|
|
660
|
+
const colEntries = Object.entries(columns).filter(([_, col]) => !col.shouldDisableInsert());
|
|
661
|
+
const insertOrder = colEntries.map(
|
|
662
|
+
([, column]) => sql/* sql */.ll.identifier(this.casing.getColumnCasing(column))
|
|
663
|
+
);
|
|
664
|
+
if (select) {
|
|
665
|
+
const select2 = valuesOrSelect;
|
|
666
|
+
if ((0,entity.is)(select2, sql/* SQL */.Xs)) {
|
|
667
|
+
valuesSqlList.push(select2);
|
|
668
|
+
} else {
|
|
669
|
+
valuesSqlList.push(select2.getSQL());
|
|
670
|
+
}
|
|
671
|
+
} else {
|
|
672
|
+
const values = valuesOrSelect;
|
|
673
|
+
valuesSqlList.push(sql/* sql */.ll.raw("values "));
|
|
674
|
+
for (const [valueIndex, value] of values.entries()) {
|
|
675
|
+
const valueList = [];
|
|
676
|
+
for (const [fieldName, col] of colEntries) {
|
|
677
|
+
const colValue = value[fieldName];
|
|
678
|
+
if (colValue === void 0 || (0,entity.is)(colValue, sql/* Param */.Iw) && colValue.value === void 0) {
|
|
679
|
+
if (col.defaultFn !== void 0) {
|
|
680
|
+
const defaultFnResult = col.defaultFn();
|
|
681
|
+
const defaultValue = (0,entity.is)(defaultFnResult, sql/* SQL */.Xs) ? defaultFnResult : sql/* sql */.ll.param(defaultFnResult, col);
|
|
682
|
+
valueList.push(defaultValue);
|
|
683
|
+
} else if (!col.default && col.onUpdateFn !== void 0) {
|
|
684
|
+
const onUpdateFnResult = col.onUpdateFn();
|
|
685
|
+
const newValue = (0,entity.is)(onUpdateFnResult, sql/* SQL */.Xs) ? onUpdateFnResult : sql/* sql */.ll.param(onUpdateFnResult, col);
|
|
686
|
+
valueList.push(newValue);
|
|
687
|
+
} else {
|
|
688
|
+
valueList.push((0,sql/* sql */.ll)`default`);
|
|
689
|
+
}
|
|
690
|
+
} else {
|
|
691
|
+
valueList.push(colValue);
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
valuesSqlList.push(valueList);
|
|
695
|
+
if (valueIndex < values.length - 1) {
|
|
696
|
+
valuesSqlList.push((0,sql/* sql */.ll)`, `);
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
const withSql = this.buildWithCTE(withList);
|
|
701
|
+
const valuesSql = sql/* sql */.ll.join(valuesSqlList);
|
|
702
|
+
const returningSql = returning ? (0,sql/* sql */.ll)` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
|
|
703
|
+
const onConflictSql = onConflict ? (0,sql/* sql */.ll)` on conflict ${onConflict}` : void 0;
|
|
704
|
+
const overridingSql = overridingSystemValue_ === true ? (0,sql/* sql */.ll)`overriding system value ` : void 0;
|
|
705
|
+
return (0,sql/* sql */.ll)`${withSql}insert into ${table} ${insertOrder} ${overridingSql}${valuesSql}${onConflictSql}${returningSql}`;
|
|
706
|
+
}
|
|
707
|
+
buildRefreshMaterializedViewQuery({ view, concurrently, withNoData }) {
|
|
708
|
+
const concurrentlySql = concurrently ? (0,sql/* sql */.ll)` concurrently` : void 0;
|
|
709
|
+
const withNoDataSql = withNoData ? (0,sql/* sql */.ll)` with no data` : void 0;
|
|
710
|
+
return (0,sql/* sql */.ll)`refresh materialized view${concurrentlySql} ${view}${withNoDataSql}`;
|
|
711
|
+
}
|
|
712
|
+
prepareTyping(encoder) {
|
|
713
|
+
if ((0,entity.is)(encoder, jsonb/* PgJsonb */.kn) || (0,entity.is)(encoder, json/* PgJson */.iX)) {
|
|
714
|
+
return "json";
|
|
715
|
+
} else if ((0,entity.is)(encoder, numeric/* PgNumeric */.Z5)) {
|
|
716
|
+
return "decimal";
|
|
717
|
+
} else if ((0,entity.is)(encoder, time/* PgTime */.Xd)) {
|
|
718
|
+
return "time";
|
|
719
|
+
} else if ((0,entity.is)(encoder, timestamp/* PgTimestamp */.KM) || (0,entity.is)(encoder, timestamp/* PgTimestampString */.xQ)) {
|
|
720
|
+
return "timestamp";
|
|
721
|
+
} else if ((0,entity.is)(encoder, date/* PgDate */.qw) || (0,entity.is)(encoder, date/* PgDateString */.dw)) {
|
|
722
|
+
return "date";
|
|
723
|
+
} else if ((0,entity.is)(encoder, uuid/* PgUUID */.dL)) {
|
|
724
|
+
return "uuid";
|
|
725
|
+
} else {
|
|
726
|
+
return "none";
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
sqlToQuery(sql2, invokeSource) {
|
|
730
|
+
return sql2.toQuery({
|
|
731
|
+
casing: this.casing,
|
|
732
|
+
escapeName: this.escapeName,
|
|
733
|
+
escapeParam: this.escapeParam,
|
|
734
|
+
escapeString: this.escapeString,
|
|
735
|
+
prepareTyping: this.prepareTyping,
|
|
736
|
+
invokeSource
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
// buildRelationalQueryWithPK({
|
|
740
|
+
// fullSchema,
|
|
741
|
+
// schema,
|
|
742
|
+
// tableNamesMap,
|
|
743
|
+
// table,
|
|
744
|
+
// tableConfig,
|
|
745
|
+
// queryConfig: config,
|
|
746
|
+
// tableAlias,
|
|
747
|
+
// isRoot = false,
|
|
748
|
+
// joinOn,
|
|
749
|
+
// }: {
|
|
750
|
+
// fullSchema: Record<string, unknown>;
|
|
751
|
+
// schema: TablesRelationalConfig;
|
|
752
|
+
// tableNamesMap: Record<string, string>;
|
|
753
|
+
// table: PgTable;
|
|
754
|
+
// tableConfig: TableRelationalConfig;
|
|
755
|
+
// queryConfig: true | DBQueryConfig<'many', true>;
|
|
756
|
+
// tableAlias: string;
|
|
757
|
+
// isRoot?: boolean;
|
|
758
|
+
// joinOn?: SQL;
|
|
759
|
+
// }): BuildRelationalQueryResult<PgTable, PgColumn> {
|
|
760
|
+
// // For { "<relation>": true }, return a table with selection of all columns
|
|
761
|
+
// if (config === true) {
|
|
762
|
+
// const selectionEntries = Object.entries(tableConfig.columns);
|
|
763
|
+
// const selection: BuildRelationalQueryResult<PgTable, PgColumn>['selection'] = selectionEntries.map((
|
|
764
|
+
// [key, value],
|
|
765
|
+
// ) => ({
|
|
766
|
+
// dbKey: value.name,
|
|
767
|
+
// tsKey: key,
|
|
768
|
+
// field: value as PgColumn,
|
|
769
|
+
// relationTableTsKey: undefined,
|
|
770
|
+
// isJson: false,
|
|
771
|
+
// selection: [],
|
|
772
|
+
// }));
|
|
773
|
+
// return {
|
|
774
|
+
// tableTsKey: tableConfig.tsName,
|
|
775
|
+
// sql: table,
|
|
776
|
+
// selection,
|
|
777
|
+
// };
|
|
778
|
+
// }
|
|
779
|
+
// // let selection: BuildRelationalQueryResult<PgTable, PgColumn>['selection'] = [];
|
|
780
|
+
// // let selectionForBuild = selection;
|
|
781
|
+
// const aliasedColumns = Object.fromEntries(
|
|
782
|
+
// Object.entries(tableConfig.columns).map(([key, value]) => [key, aliasedTableColumn(value, tableAlias)]),
|
|
783
|
+
// );
|
|
784
|
+
// const aliasedRelations = Object.fromEntries(
|
|
785
|
+
// Object.entries(tableConfig.relations).map(([key, value]) => [key, aliasedRelation(value, tableAlias)]),
|
|
786
|
+
// );
|
|
787
|
+
// const aliasedFields = Object.assign({}, aliasedColumns, aliasedRelations);
|
|
788
|
+
// let where, hasUserDefinedWhere;
|
|
789
|
+
// if (config.where) {
|
|
790
|
+
// const whereSql = typeof config.where === 'function' ? config.where(aliasedFields, operators) : config.where;
|
|
791
|
+
// where = whereSql && mapColumnsInSQLToAlias(whereSql, tableAlias);
|
|
792
|
+
// hasUserDefinedWhere = !!where;
|
|
793
|
+
// }
|
|
794
|
+
// where = and(joinOn, where);
|
|
795
|
+
// // const fieldsSelection: { tsKey: string; value: PgColumn | SQL.Aliased; isExtra?: boolean }[] = [];
|
|
796
|
+
// let joins: Join[] = [];
|
|
797
|
+
// let selectedColumns: string[] = [];
|
|
798
|
+
// // Figure out which columns to select
|
|
799
|
+
// if (config.columns) {
|
|
800
|
+
// let isIncludeMode = false;
|
|
801
|
+
// for (const [field, value] of Object.entries(config.columns)) {
|
|
802
|
+
// if (value === undefined) {
|
|
803
|
+
// continue;
|
|
804
|
+
// }
|
|
805
|
+
// if (field in tableConfig.columns) {
|
|
806
|
+
// if (!isIncludeMode && value === true) {
|
|
807
|
+
// isIncludeMode = true;
|
|
808
|
+
// }
|
|
809
|
+
// selectedColumns.push(field);
|
|
810
|
+
// }
|
|
811
|
+
// }
|
|
812
|
+
// if (selectedColumns.length > 0) {
|
|
813
|
+
// selectedColumns = isIncludeMode
|
|
814
|
+
// ? selectedColumns.filter((c) => config.columns?.[c] === true)
|
|
815
|
+
// : Object.keys(tableConfig.columns).filter((key) => !selectedColumns.includes(key));
|
|
816
|
+
// }
|
|
817
|
+
// } else {
|
|
818
|
+
// // Select all columns if selection is not specified
|
|
819
|
+
// selectedColumns = Object.keys(tableConfig.columns);
|
|
820
|
+
// }
|
|
821
|
+
// // for (const field of selectedColumns) {
|
|
822
|
+
// // const column = tableConfig.columns[field]! as PgColumn;
|
|
823
|
+
// // fieldsSelection.push({ tsKey: field, value: column });
|
|
824
|
+
// // }
|
|
825
|
+
// let initiallySelectedRelations: {
|
|
826
|
+
// tsKey: string;
|
|
827
|
+
// queryConfig: true | DBQueryConfig<'many', false>;
|
|
828
|
+
// relation: Relation;
|
|
829
|
+
// }[] = [];
|
|
830
|
+
// // let selectedRelations: BuildRelationalQueryResult<PgTable, PgColumn>['selection'] = [];
|
|
831
|
+
// // Figure out which relations to select
|
|
832
|
+
// if (config.with) {
|
|
833
|
+
// initiallySelectedRelations = Object.entries(config.with)
|
|
834
|
+
// .filter((entry): entry is [typeof entry[0], NonNullable<typeof entry[1]>] => !!entry[1])
|
|
835
|
+
// .map(([tsKey, queryConfig]) => ({ tsKey, queryConfig, relation: tableConfig.relations[tsKey]! }));
|
|
836
|
+
// }
|
|
837
|
+
// const manyRelations = initiallySelectedRelations.filter((r) =>
|
|
838
|
+
// is(r.relation, Many)
|
|
839
|
+
// && (schema[tableNamesMap[r.relation.referencedTable[Table.Symbol.Name]]!]?.primaryKey.length ?? 0) > 0
|
|
840
|
+
// );
|
|
841
|
+
// // If this is the last Many relation (or there are no Many relations), we are on the innermost subquery level
|
|
842
|
+
// const isInnermostQuery = manyRelations.length < 2;
|
|
843
|
+
// const selectedExtras: {
|
|
844
|
+
// tsKey: string;
|
|
845
|
+
// value: SQL.Aliased;
|
|
846
|
+
// }[] = [];
|
|
847
|
+
// // Figure out which extras to select
|
|
848
|
+
// if (isInnermostQuery && config.extras) {
|
|
849
|
+
// const extras = typeof config.extras === 'function'
|
|
850
|
+
// ? config.extras(aliasedFields, { sql })
|
|
851
|
+
// : config.extras;
|
|
852
|
+
// for (const [tsKey, value] of Object.entries(extras)) {
|
|
853
|
+
// selectedExtras.push({
|
|
854
|
+
// tsKey,
|
|
855
|
+
// value: mapColumnsInAliasedSQLToAlias(value, tableAlias),
|
|
856
|
+
// });
|
|
857
|
+
// }
|
|
858
|
+
// }
|
|
859
|
+
// // Transform `fieldsSelection` into `selection`
|
|
860
|
+
// // `fieldsSelection` shouldn't be used after this point
|
|
861
|
+
// // for (const { tsKey, value, isExtra } of fieldsSelection) {
|
|
862
|
+
// // selection.push({
|
|
863
|
+
// // dbKey: is(value, SQL.Aliased) ? value.fieldAlias : tableConfig.columns[tsKey]!.name,
|
|
864
|
+
// // tsKey,
|
|
865
|
+
// // field: is(value, Column) ? aliasedTableColumn(value, tableAlias) : value,
|
|
866
|
+
// // relationTableTsKey: undefined,
|
|
867
|
+
// // isJson: false,
|
|
868
|
+
// // isExtra,
|
|
869
|
+
// // selection: [],
|
|
870
|
+
// // });
|
|
871
|
+
// // }
|
|
872
|
+
// let orderByOrig = typeof config.orderBy === 'function'
|
|
873
|
+
// ? config.orderBy(aliasedFields, orderByOperators)
|
|
874
|
+
// : config.orderBy ?? [];
|
|
875
|
+
// if (!Array.isArray(orderByOrig)) {
|
|
876
|
+
// orderByOrig = [orderByOrig];
|
|
877
|
+
// }
|
|
878
|
+
// const orderBy = orderByOrig.map((orderByValue) => {
|
|
879
|
+
// if (is(orderByValue, Column)) {
|
|
880
|
+
// return aliasedTableColumn(orderByValue, tableAlias) as PgColumn;
|
|
881
|
+
// }
|
|
882
|
+
// return mapColumnsInSQLToAlias(orderByValue, tableAlias);
|
|
883
|
+
// });
|
|
884
|
+
// const limit = isInnermostQuery ? config.limit : undefined;
|
|
885
|
+
// const offset = isInnermostQuery ? config.offset : undefined;
|
|
886
|
+
// // For non-root queries without additional config except columns, return a table with selection
|
|
887
|
+
// if (
|
|
888
|
+
// !isRoot
|
|
889
|
+
// && initiallySelectedRelations.length === 0
|
|
890
|
+
// && selectedExtras.length === 0
|
|
891
|
+
// && !where
|
|
892
|
+
// && orderBy.length === 0
|
|
893
|
+
// && limit === undefined
|
|
894
|
+
// && offset === undefined
|
|
895
|
+
// ) {
|
|
896
|
+
// return {
|
|
897
|
+
// tableTsKey: tableConfig.tsName,
|
|
898
|
+
// sql: table,
|
|
899
|
+
// selection: selectedColumns.map((key) => ({
|
|
900
|
+
// dbKey: tableConfig.columns[key]!.name,
|
|
901
|
+
// tsKey: key,
|
|
902
|
+
// field: tableConfig.columns[key] as PgColumn,
|
|
903
|
+
// relationTableTsKey: undefined,
|
|
904
|
+
// isJson: false,
|
|
905
|
+
// selection: [],
|
|
906
|
+
// })),
|
|
907
|
+
// };
|
|
908
|
+
// }
|
|
909
|
+
// const selectedRelationsWithoutPK:
|
|
910
|
+
// // Process all relations without primary keys, because they need to be joined differently and will all be on the same query level
|
|
911
|
+
// for (
|
|
912
|
+
// const {
|
|
913
|
+
// tsKey: selectedRelationTsKey,
|
|
914
|
+
// queryConfig: selectedRelationConfigValue,
|
|
915
|
+
// relation,
|
|
916
|
+
// } of initiallySelectedRelations
|
|
917
|
+
// ) {
|
|
918
|
+
// const normalizedRelation = normalizeRelation(schema, tableNamesMap, relation);
|
|
919
|
+
// const relationTableName = relation.referencedTable[Table.Symbol.Name];
|
|
920
|
+
// const relationTableTsName = tableNamesMap[relationTableName]!;
|
|
921
|
+
// const relationTable = schema[relationTableTsName]!;
|
|
922
|
+
// if (relationTable.primaryKey.length > 0) {
|
|
923
|
+
// continue;
|
|
924
|
+
// }
|
|
925
|
+
// const relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;
|
|
926
|
+
// const joinOn = and(
|
|
927
|
+
// ...normalizedRelation.fields.map((field, i) =>
|
|
928
|
+
// eq(
|
|
929
|
+
// aliasedTableColumn(normalizedRelation.references[i]!, relationTableAlias),
|
|
930
|
+
// aliasedTableColumn(field, tableAlias),
|
|
931
|
+
// )
|
|
932
|
+
// ),
|
|
933
|
+
// );
|
|
934
|
+
// const builtRelation = this.buildRelationalQueryWithoutPK({
|
|
935
|
+
// fullSchema,
|
|
936
|
+
// schema,
|
|
937
|
+
// tableNamesMap,
|
|
938
|
+
// table: fullSchema[relationTableTsName] as PgTable,
|
|
939
|
+
// tableConfig: schema[relationTableTsName]!,
|
|
940
|
+
// queryConfig: selectedRelationConfigValue,
|
|
941
|
+
// tableAlias: relationTableAlias,
|
|
942
|
+
// joinOn,
|
|
943
|
+
// nestedQueryRelation: relation,
|
|
944
|
+
// });
|
|
945
|
+
// const field = sql`${sql.identifier(relationTableAlias)}.${sql.identifier('data')}`.as(selectedRelationTsKey);
|
|
946
|
+
// joins.push({
|
|
947
|
+
// on: sql`true`,
|
|
948
|
+
// table: new Subquery(builtRelation.sql as SQL, {}, relationTableAlias),
|
|
949
|
+
// alias: relationTableAlias,
|
|
950
|
+
// joinType: 'left',
|
|
951
|
+
// lateral: true,
|
|
952
|
+
// });
|
|
953
|
+
// selectedRelations.push({
|
|
954
|
+
// dbKey: selectedRelationTsKey,
|
|
955
|
+
// tsKey: selectedRelationTsKey,
|
|
956
|
+
// field,
|
|
957
|
+
// relationTableTsKey: relationTableTsName,
|
|
958
|
+
// isJson: true,
|
|
959
|
+
// selection: builtRelation.selection,
|
|
960
|
+
// });
|
|
961
|
+
// }
|
|
962
|
+
// const oneRelations = initiallySelectedRelations.filter((r): r is typeof r & { relation: One } =>
|
|
963
|
+
// is(r.relation, One)
|
|
964
|
+
// );
|
|
965
|
+
// // Process all One relations with PKs, because they can all be joined on the same level
|
|
966
|
+
// for (
|
|
967
|
+
// const {
|
|
968
|
+
// tsKey: selectedRelationTsKey,
|
|
969
|
+
// queryConfig: selectedRelationConfigValue,
|
|
970
|
+
// relation,
|
|
971
|
+
// } of oneRelations
|
|
972
|
+
// ) {
|
|
973
|
+
// const normalizedRelation = normalizeRelation(schema, tableNamesMap, relation);
|
|
974
|
+
// const relationTableName = relation.referencedTable[Table.Symbol.Name];
|
|
975
|
+
// const relationTableTsName = tableNamesMap[relationTableName]!;
|
|
976
|
+
// const relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;
|
|
977
|
+
// const relationTable = schema[relationTableTsName]!;
|
|
978
|
+
// if (relationTable.primaryKey.length === 0) {
|
|
979
|
+
// continue;
|
|
980
|
+
// }
|
|
981
|
+
// const joinOn = and(
|
|
982
|
+
// ...normalizedRelation.fields.map((field, i) =>
|
|
983
|
+
// eq(
|
|
984
|
+
// aliasedTableColumn(normalizedRelation.references[i]!, relationTableAlias),
|
|
985
|
+
// aliasedTableColumn(field, tableAlias),
|
|
986
|
+
// )
|
|
987
|
+
// ),
|
|
988
|
+
// );
|
|
989
|
+
// const builtRelation = this.buildRelationalQueryWithPK({
|
|
990
|
+
// fullSchema,
|
|
991
|
+
// schema,
|
|
992
|
+
// tableNamesMap,
|
|
993
|
+
// table: fullSchema[relationTableTsName] as PgTable,
|
|
994
|
+
// tableConfig: schema[relationTableTsName]!,
|
|
995
|
+
// queryConfig: selectedRelationConfigValue,
|
|
996
|
+
// tableAlias: relationTableAlias,
|
|
997
|
+
// joinOn,
|
|
998
|
+
// });
|
|
999
|
+
// const field = sql`case when ${sql.identifier(relationTableAlias)} is null then null else json_build_array(${
|
|
1000
|
+
// sql.join(
|
|
1001
|
+
// builtRelation.selection.map(({ field }) =>
|
|
1002
|
+
// is(field, SQL.Aliased)
|
|
1003
|
+
// ? sql`${sql.identifier(relationTableAlias)}.${sql.identifier(field.fieldAlias)}`
|
|
1004
|
+
// : is(field, Column)
|
|
1005
|
+
// ? aliasedTableColumn(field, relationTableAlias)
|
|
1006
|
+
// : field
|
|
1007
|
+
// ),
|
|
1008
|
+
// sql`, `,
|
|
1009
|
+
// )
|
|
1010
|
+
// }) end`.as(selectedRelationTsKey);
|
|
1011
|
+
// const isLateralJoin = is(builtRelation.sql, SQL);
|
|
1012
|
+
// joins.push({
|
|
1013
|
+
// on: isLateralJoin ? sql`true` : joinOn,
|
|
1014
|
+
// table: is(builtRelation.sql, SQL)
|
|
1015
|
+
// ? new Subquery(builtRelation.sql, {}, relationTableAlias)
|
|
1016
|
+
// : aliasedTable(builtRelation.sql, relationTableAlias),
|
|
1017
|
+
// alias: relationTableAlias,
|
|
1018
|
+
// joinType: 'left',
|
|
1019
|
+
// lateral: is(builtRelation.sql, SQL),
|
|
1020
|
+
// });
|
|
1021
|
+
// selectedRelations.push({
|
|
1022
|
+
// dbKey: selectedRelationTsKey,
|
|
1023
|
+
// tsKey: selectedRelationTsKey,
|
|
1024
|
+
// field,
|
|
1025
|
+
// relationTableTsKey: relationTableTsName,
|
|
1026
|
+
// isJson: true,
|
|
1027
|
+
// selection: builtRelation.selection,
|
|
1028
|
+
// });
|
|
1029
|
+
// }
|
|
1030
|
+
// let distinct: PgSelectConfig['distinct'];
|
|
1031
|
+
// let tableFrom: PgTable | Subquery = table;
|
|
1032
|
+
// // Process first Many relation - each one requires a nested subquery
|
|
1033
|
+
// const manyRelation = manyRelations[0];
|
|
1034
|
+
// if (manyRelation) {
|
|
1035
|
+
// const {
|
|
1036
|
+
// tsKey: selectedRelationTsKey,
|
|
1037
|
+
// queryConfig: selectedRelationQueryConfig,
|
|
1038
|
+
// relation,
|
|
1039
|
+
// } = manyRelation;
|
|
1040
|
+
// distinct = {
|
|
1041
|
+
// on: tableConfig.primaryKey.map((c) => aliasedTableColumn(c as PgColumn, tableAlias)),
|
|
1042
|
+
// };
|
|
1043
|
+
// const normalizedRelation = normalizeRelation(schema, tableNamesMap, relation);
|
|
1044
|
+
// const relationTableName = relation.referencedTable[Table.Symbol.Name];
|
|
1045
|
+
// const relationTableTsName = tableNamesMap[relationTableName]!;
|
|
1046
|
+
// const relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;
|
|
1047
|
+
// const joinOn = and(
|
|
1048
|
+
// ...normalizedRelation.fields.map((field, i) =>
|
|
1049
|
+
// eq(
|
|
1050
|
+
// aliasedTableColumn(normalizedRelation.references[i]!, relationTableAlias),
|
|
1051
|
+
// aliasedTableColumn(field, tableAlias),
|
|
1052
|
+
// )
|
|
1053
|
+
// ),
|
|
1054
|
+
// );
|
|
1055
|
+
// const builtRelationJoin = this.buildRelationalQueryWithPK({
|
|
1056
|
+
// fullSchema,
|
|
1057
|
+
// schema,
|
|
1058
|
+
// tableNamesMap,
|
|
1059
|
+
// table: fullSchema[relationTableTsName] as PgTable,
|
|
1060
|
+
// tableConfig: schema[relationTableTsName]!,
|
|
1061
|
+
// queryConfig: selectedRelationQueryConfig,
|
|
1062
|
+
// tableAlias: relationTableAlias,
|
|
1063
|
+
// joinOn,
|
|
1064
|
+
// });
|
|
1065
|
+
// const builtRelationSelectionField = sql`case when ${
|
|
1066
|
+
// sql.identifier(relationTableAlias)
|
|
1067
|
+
// } is null then '[]' else json_agg(json_build_array(${
|
|
1068
|
+
// sql.join(
|
|
1069
|
+
// builtRelationJoin.selection.map(({ field }) =>
|
|
1070
|
+
// is(field, SQL.Aliased)
|
|
1071
|
+
// ? sql`${sql.identifier(relationTableAlias)}.${sql.identifier(field.fieldAlias)}`
|
|
1072
|
+
// : is(field, Column)
|
|
1073
|
+
// ? aliasedTableColumn(field, relationTableAlias)
|
|
1074
|
+
// : field
|
|
1075
|
+
// ),
|
|
1076
|
+
// sql`, `,
|
|
1077
|
+
// )
|
|
1078
|
+
// })) over (partition by ${sql.join(distinct.on, sql`, `)}) end`.as(selectedRelationTsKey);
|
|
1079
|
+
// const isLateralJoin = is(builtRelationJoin.sql, SQL);
|
|
1080
|
+
// joins.push({
|
|
1081
|
+
// on: isLateralJoin ? sql`true` : joinOn,
|
|
1082
|
+
// table: isLateralJoin
|
|
1083
|
+
// ? new Subquery(builtRelationJoin.sql as SQL, {}, relationTableAlias)
|
|
1084
|
+
// : aliasedTable(builtRelationJoin.sql as PgTable, relationTableAlias),
|
|
1085
|
+
// alias: relationTableAlias,
|
|
1086
|
+
// joinType: 'left',
|
|
1087
|
+
// lateral: isLateralJoin,
|
|
1088
|
+
// });
|
|
1089
|
+
// // Build the "from" subquery with the remaining Many relations
|
|
1090
|
+
// const builtTableFrom = this.buildRelationalQueryWithPK({
|
|
1091
|
+
// fullSchema,
|
|
1092
|
+
// schema,
|
|
1093
|
+
// tableNamesMap,
|
|
1094
|
+
// table,
|
|
1095
|
+
// tableConfig,
|
|
1096
|
+
// queryConfig: {
|
|
1097
|
+
// ...config,
|
|
1098
|
+
// where: undefined,
|
|
1099
|
+
// orderBy: undefined,
|
|
1100
|
+
// limit: undefined,
|
|
1101
|
+
// offset: undefined,
|
|
1102
|
+
// with: manyRelations.slice(1).reduce<NonNullable<typeof config['with']>>(
|
|
1103
|
+
// (result, { tsKey, queryConfig: configValue }) => {
|
|
1104
|
+
// result[tsKey] = configValue;
|
|
1105
|
+
// return result;
|
|
1106
|
+
// },
|
|
1107
|
+
// {},
|
|
1108
|
+
// ),
|
|
1109
|
+
// },
|
|
1110
|
+
// tableAlias,
|
|
1111
|
+
// });
|
|
1112
|
+
// selectedRelations.push({
|
|
1113
|
+
// dbKey: selectedRelationTsKey,
|
|
1114
|
+
// tsKey: selectedRelationTsKey,
|
|
1115
|
+
// field: builtRelationSelectionField,
|
|
1116
|
+
// relationTableTsKey: relationTableTsName,
|
|
1117
|
+
// isJson: true,
|
|
1118
|
+
// selection: builtRelationJoin.selection,
|
|
1119
|
+
// });
|
|
1120
|
+
// // selection = builtTableFrom.selection.map((item) =>
|
|
1121
|
+
// // is(item.field, SQL.Aliased)
|
|
1122
|
+
// // ? { ...item, field: sql`${sql.identifier(tableAlias)}.${sql.identifier(item.field.fieldAlias)}` }
|
|
1123
|
+
// // : item
|
|
1124
|
+
// // );
|
|
1125
|
+
// // selectionForBuild = [{
|
|
1126
|
+
// // dbKey: '*',
|
|
1127
|
+
// // tsKey: '*',
|
|
1128
|
+
// // field: sql`${sql.identifier(tableAlias)}.*`,
|
|
1129
|
+
// // selection: [],
|
|
1130
|
+
// // isJson: false,
|
|
1131
|
+
// // relationTableTsKey: undefined,
|
|
1132
|
+
// // }];
|
|
1133
|
+
// // const newSelectionItem: (typeof selection)[number] = {
|
|
1134
|
+
// // dbKey: selectedRelationTsKey,
|
|
1135
|
+
// // tsKey: selectedRelationTsKey,
|
|
1136
|
+
// // field,
|
|
1137
|
+
// // relationTableTsKey: relationTableTsName,
|
|
1138
|
+
// // isJson: true,
|
|
1139
|
+
// // selection: builtRelationJoin.selection,
|
|
1140
|
+
// // };
|
|
1141
|
+
// // selection.push(newSelectionItem);
|
|
1142
|
+
// // selectionForBuild.push(newSelectionItem);
|
|
1143
|
+
// tableFrom = is(builtTableFrom.sql, PgTable)
|
|
1144
|
+
// ? builtTableFrom.sql
|
|
1145
|
+
// : new Subquery(builtTableFrom.sql, {}, tableAlias);
|
|
1146
|
+
// }
|
|
1147
|
+
// if (selectedColumns.length === 0 && selectedRelations.length === 0 && selectedExtras.length === 0) {
|
|
1148
|
+
// throw new DrizzleError(`No fields selected for table "${tableConfig.tsName}" ("${tableAlias}")`);
|
|
1149
|
+
// }
|
|
1150
|
+
// let selection: BuildRelationalQueryResult<PgTable, PgColumn>['selection'];
|
|
1151
|
+
// function prepareSelectedColumns() {
|
|
1152
|
+
// return selectedColumns.map((key) => ({
|
|
1153
|
+
// dbKey: tableConfig.columns[key]!.name,
|
|
1154
|
+
// tsKey: key,
|
|
1155
|
+
// field: tableConfig.columns[key] as PgColumn,
|
|
1156
|
+
// relationTableTsKey: undefined,
|
|
1157
|
+
// isJson: false,
|
|
1158
|
+
// selection: [],
|
|
1159
|
+
// }));
|
|
1160
|
+
// }
|
|
1161
|
+
// function prepareSelectedExtras() {
|
|
1162
|
+
// return selectedExtras.map((item) => ({
|
|
1163
|
+
// dbKey: item.value.fieldAlias,
|
|
1164
|
+
// tsKey: item.tsKey,
|
|
1165
|
+
// field: item.value,
|
|
1166
|
+
// relationTableTsKey: undefined,
|
|
1167
|
+
// isJson: false,
|
|
1168
|
+
// selection: [],
|
|
1169
|
+
// }));
|
|
1170
|
+
// }
|
|
1171
|
+
// if (isRoot) {
|
|
1172
|
+
// selection = [
|
|
1173
|
+
// ...prepareSelectedColumns(),
|
|
1174
|
+
// ...prepareSelectedExtras(),
|
|
1175
|
+
// ];
|
|
1176
|
+
// }
|
|
1177
|
+
// if (hasUserDefinedWhere || orderBy.length > 0) {
|
|
1178
|
+
// tableFrom = new Subquery(
|
|
1179
|
+
// this.buildSelectQuery({
|
|
1180
|
+
// table: is(tableFrom, PgTable) ? aliasedTable(tableFrom, tableAlias) : tableFrom,
|
|
1181
|
+
// fields: {},
|
|
1182
|
+
// fieldsFlat: selectionForBuild.map(({ field }) => ({
|
|
1183
|
+
// path: [],
|
|
1184
|
+
// field: is(field, Column) ? aliasedTableColumn(field, tableAlias) : field,
|
|
1185
|
+
// })),
|
|
1186
|
+
// joins,
|
|
1187
|
+
// distinct,
|
|
1188
|
+
// }),
|
|
1189
|
+
// {},
|
|
1190
|
+
// tableAlias,
|
|
1191
|
+
// );
|
|
1192
|
+
// selectionForBuild = selection.map((item) =>
|
|
1193
|
+
// is(item.field, SQL.Aliased)
|
|
1194
|
+
// ? { ...item, field: sql`${sql.identifier(tableAlias)}.${sql.identifier(item.field.fieldAlias)}` }
|
|
1195
|
+
// : item
|
|
1196
|
+
// );
|
|
1197
|
+
// joins = [];
|
|
1198
|
+
// distinct = undefined;
|
|
1199
|
+
// }
|
|
1200
|
+
// const result = this.buildSelectQuery({
|
|
1201
|
+
// table: is(tableFrom, PgTable) ? aliasedTable(tableFrom, tableAlias) : tableFrom,
|
|
1202
|
+
// fields: {},
|
|
1203
|
+
// fieldsFlat: selectionForBuild.map(({ field }) => ({
|
|
1204
|
+
// path: [],
|
|
1205
|
+
// field: is(field, Column) ? aliasedTableColumn(field, tableAlias) : field,
|
|
1206
|
+
// })),
|
|
1207
|
+
// where,
|
|
1208
|
+
// limit,
|
|
1209
|
+
// offset,
|
|
1210
|
+
// joins,
|
|
1211
|
+
// orderBy,
|
|
1212
|
+
// distinct,
|
|
1213
|
+
// });
|
|
1214
|
+
// return {
|
|
1215
|
+
// tableTsKey: tableConfig.tsName,
|
|
1216
|
+
// sql: result,
|
|
1217
|
+
// selection,
|
|
1218
|
+
// };
|
|
1219
|
+
// }
|
|
1220
|
+
buildRelationalQueryWithoutPK({
|
|
1221
|
+
fullSchema,
|
|
1222
|
+
schema,
|
|
1223
|
+
tableNamesMap,
|
|
1224
|
+
table,
|
|
1225
|
+
tableConfig,
|
|
1226
|
+
queryConfig: config,
|
|
1227
|
+
tableAlias,
|
|
1228
|
+
nestedQueryRelation,
|
|
1229
|
+
joinOn
|
|
1230
|
+
}) {
|
|
1231
|
+
let selection = [];
|
|
1232
|
+
let limit, offset, orderBy = [], where;
|
|
1233
|
+
const joins = [];
|
|
1234
|
+
if (config === true) {
|
|
1235
|
+
const selectionEntries = Object.entries(tableConfig.columns);
|
|
1236
|
+
selection = selectionEntries.map(([key, value]) => ({
|
|
1237
|
+
dbKey: value.name,
|
|
1238
|
+
tsKey: key,
|
|
1239
|
+
field: (0,alias/* aliasedTableColumn */.ug)(value, tableAlias),
|
|
1240
|
+
relationTableTsKey: void 0,
|
|
1241
|
+
isJson: false,
|
|
1242
|
+
selection: []
|
|
1243
|
+
}));
|
|
1244
|
+
} else {
|
|
1245
|
+
const aliasedColumns = Object.fromEntries(
|
|
1246
|
+
Object.entries(tableConfig.columns).map(([key, value]) => [key, (0,alias/* aliasedTableColumn */.ug)(value, tableAlias)])
|
|
1247
|
+
);
|
|
1248
|
+
if (config.where) {
|
|
1249
|
+
const whereSql = typeof config.where === "function" ? config.where(aliasedColumns, (0,relations/* getOperators */.mm)()) : config.where;
|
|
1250
|
+
where = whereSql && (0,alias/* mapColumnsInSQLToAlias */.yY)(whereSql, tableAlias);
|
|
1251
|
+
}
|
|
1252
|
+
const fieldsSelection = [];
|
|
1253
|
+
let selectedColumns = [];
|
|
1254
|
+
if (config.columns) {
|
|
1255
|
+
let isIncludeMode = false;
|
|
1256
|
+
for (const [field, value] of Object.entries(config.columns)) {
|
|
1257
|
+
if (value === void 0) {
|
|
1258
|
+
continue;
|
|
1259
|
+
}
|
|
1260
|
+
if (field in tableConfig.columns) {
|
|
1261
|
+
if (!isIncludeMode && value === true) {
|
|
1262
|
+
isIncludeMode = true;
|
|
1263
|
+
}
|
|
1264
|
+
selectedColumns.push(field);
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
if (selectedColumns.length > 0) {
|
|
1268
|
+
selectedColumns = isIncludeMode ? selectedColumns.filter((c) => config.columns?.[c] === true) : Object.keys(tableConfig.columns).filter((key) => !selectedColumns.includes(key));
|
|
1269
|
+
}
|
|
1270
|
+
} else {
|
|
1271
|
+
selectedColumns = Object.keys(tableConfig.columns);
|
|
1272
|
+
}
|
|
1273
|
+
for (const field of selectedColumns) {
|
|
1274
|
+
const column = tableConfig.columns[field];
|
|
1275
|
+
fieldsSelection.push({ tsKey: field, value: column });
|
|
1276
|
+
}
|
|
1277
|
+
let selectedRelations = [];
|
|
1278
|
+
if (config.with) {
|
|
1279
|
+
selectedRelations = Object.entries(config.with).filter((entry) => !!entry[1]).map(([tsKey, queryConfig]) => ({ tsKey, queryConfig, relation: tableConfig.relations[tsKey] }));
|
|
1280
|
+
}
|
|
1281
|
+
let extras;
|
|
1282
|
+
if (config.extras) {
|
|
1283
|
+
extras = typeof config.extras === "function" ? config.extras(aliasedColumns, { sql: sql/* sql */.ll }) : config.extras;
|
|
1284
|
+
for (const [tsKey, value] of Object.entries(extras)) {
|
|
1285
|
+
fieldsSelection.push({
|
|
1286
|
+
tsKey,
|
|
1287
|
+
value: (0,alias/* mapColumnsInAliasedSQLToAlias */.Hs)(value, tableAlias)
|
|
1288
|
+
});
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
for (const { tsKey, value } of fieldsSelection) {
|
|
1292
|
+
selection.push({
|
|
1293
|
+
dbKey: (0,entity.is)(value, sql/* SQL */.Xs.Aliased) ? value.fieldAlias : tableConfig.columns[tsKey].name,
|
|
1294
|
+
tsKey,
|
|
1295
|
+
field: (0,entity.is)(value, column/* Column */.V) ? (0,alias/* aliasedTableColumn */.ug)(value, tableAlias) : value,
|
|
1296
|
+
relationTableTsKey: void 0,
|
|
1297
|
+
isJson: false,
|
|
1298
|
+
selection: []
|
|
1299
|
+
});
|
|
1300
|
+
}
|
|
1301
|
+
let orderByOrig = typeof config.orderBy === "function" ? config.orderBy(aliasedColumns, (0,relations/* getOrderByOperators */.rl)()) : config.orderBy ?? [];
|
|
1302
|
+
if (!Array.isArray(orderByOrig)) {
|
|
1303
|
+
orderByOrig = [orderByOrig];
|
|
1304
|
+
}
|
|
1305
|
+
orderBy = orderByOrig.map((orderByValue) => {
|
|
1306
|
+
if ((0,entity.is)(orderByValue, column/* Column */.V)) {
|
|
1307
|
+
return (0,alias/* aliasedTableColumn */.ug)(orderByValue, tableAlias);
|
|
1308
|
+
}
|
|
1309
|
+
return (0,alias/* mapColumnsInSQLToAlias */.yY)(orderByValue, tableAlias);
|
|
1310
|
+
});
|
|
1311
|
+
limit = config.limit;
|
|
1312
|
+
offset = config.offset;
|
|
1313
|
+
for (const {
|
|
1314
|
+
tsKey: selectedRelationTsKey,
|
|
1315
|
+
queryConfig: selectedRelationConfigValue,
|
|
1316
|
+
relation
|
|
1317
|
+
} of selectedRelations) {
|
|
1318
|
+
const normalizedRelation = (0,relations/* normalizeRelation */.W0)(schema, tableNamesMap, relation);
|
|
1319
|
+
const relationTableName = (0,drizzle_orm_table/* getTableUniqueName */.Lf)(relation.referencedTable);
|
|
1320
|
+
const relationTableTsName = tableNamesMap[relationTableName];
|
|
1321
|
+
const relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;
|
|
1322
|
+
const joinOn2 = (0,conditions/* and */.Uo)(
|
|
1323
|
+
...normalizedRelation.fields.map(
|
|
1324
|
+
(field2, i) => (0,conditions.eq)(
|
|
1325
|
+
(0,alias/* aliasedTableColumn */.ug)(normalizedRelation.references[i], relationTableAlias),
|
|
1326
|
+
(0,alias/* aliasedTableColumn */.ug)(field2, tableAlias)
|
|
1327
|
+
)
|
|
1328
|
+
)
|
|
1329
|
+
);
|
|
1330
|
+
const builtRelation = this.buildRelationalQueryWithoutPK({
|
|
1331
|
+
fullSchema,
|
|
1332
|
+
schema,
|
|
1333
|
+
tableNamesMap,
|
|
1334
|
+
table: fullSchema[relationTableTsName],
|
|
1335
|
+
tableConfig: schema[relationTableTsName],
|
|
1336
|
+
queryConfig: (0,entity.is)(relation, relations/* One */.pD) ? selectedRelationConfigValue === true ? { limit: 1 } : { ...selectedRelationConfigValue, limit: 1 } : selectedRelationConfigValue,
|
|
1337
|
+
tableAlias: relationTableAlias,
|
|
1338
|
+
joinOn: joinOn2,
|
|
1339
|
+
nestedQueryRelation: relation
|
|
1340
|
+
});
|
|
1341
|
+
const field = (0,sql/* sql */.ll)`${sql/* sql */.ll.identifier(relationTableAlias)}.${sql/* sql */.ll.identifier("data")}`.as(selectedRelationTsKey);
|
|
1342
|
+
joins.push({
|
|
1343
|
+
on: (0,sql/* sql */.ll)`true`,
|
|
1344
|
+
table: new subquery/* Subquery */.n(builtRelation.sql, {}, relationTableAlias),
|
|
1345
|
+
alias: relationTableAlias,
|
|
1346
|
+
joinType: "left",
|
|
1347
|
+
lateral: true
|
|
1348
|
+
});
|
|
1349
|
+
selection.push({
|
|
1350
|
+
dbKey: selectedRelationTsKey,
|
|
1351
|
+
tsKey: selectedRelationTsKey,
|
|
1352
|
+
field,
|
|
1353
|
+
relationTableTsKey: relationTableTsName,
|
|
1354
|
+
isJson: true,
|
|
1355
|
+
selection: builtRelation.selection
|
|
1356
|
+
});
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
if (selection.length === 0) {
|
|
1360
|
+
throw new errors/* DrizzleError */.n({ message: `No fields selected for table "${tableConfig.tsName}" ("${tableAlias}")` });
|
|
1361
|
+
}
|
|
1362
|
+
let result;
|
|
1363
|
+
where = (0,conditions/* and */.Uo)(joinOn, where);
|
|
1364
|
+
if (nestedQueryRelation) {
|
|
1365
|
+
let field = (0,sql/* sql */.ll)`json_build_array(${sql/* sql */.ll.join(
|
|
1366
|
+
selection.map(
|
|
1367
|
+
({ field: field2, tsKey, isJson }) => isJson ? (0,sql/* sql */.ll)`${sql/* sql */.ll.identifier(`${tableAlias}_${tsKey}`)}.${sql/* sql */.ll.identifier("data")}` : (0,entity.is)(field2, sql/* SQL */.Xs.Aliased) ? field2.sql : field2
|
|
1368
|
+
),
|
|
1369
|
+
(0,sql/* sql */.ll)`, `
|
|
1370
|
+
)})`;
|
|
1371
|
+
if ((0,entity.is)(nestedQueryRelation, relations/* Many */.iv)) {
|
|
1372
|
+
field = (0,sql/* sql */.ll)`coalesce(json_agg(${field}${orderBy.length > 0 ? (0,sql/* sql */.ll)` order by ${sql/* sql */.ll.join(orderBy, (0,sql/* sql */.ll)`, `)}` : void 0}), '[]'::json)`;
|
|
1373
|
+
}
|
|
1374
|
+
const nestedSelection = [{
|
|
1375
|
+
dbKey: "data",
|
|
1376
|
+
tsKey: "data",
|
|
1377
|
+
field: field.as("data"),
|
|
1378
|
+
isJson: true,
|
|
1379
|
+
relationTableTsKey: tableConfig.tsName,
|
|
1380
|
+
selection
|
|
1381
|
+
}];
|
|
1382
|
+
const needsSubquery = limit !== void 0 || offset !== void 0 || orderBy.length > 0;
|
|
1383
|
+
if (needsSubquery) {
|
|
1384
|
+
result = this.buildSelectQuery({
|
|
1385
|
+
table: (0,alias/* aliasedTable */.oG)(table, tableAlias),
|
|
1386
|
+
fields: {},
|
|
1387
|
+
fieldsFlat: [{
|
|
1388
|
+
path: [],
|
|
1389
|
+
field: sql/* sql */.ll.raw("*")
|
|
1390
|
+
}],
|
|
1391
|
+
where,
|
|
1392
|
+
limit,
|
|
1393
|
+
offset,
|
|
1394
|
+
orderBy,
|
|
1395
|
+
setOperators: []
|
|
1396
|
+
});
|
|
1397
|
+
where = void 0;
|
|
1398
|
+
limit = void 0;
|
|
1399
|
+
offset = void 0;
|
|
1400
|
+
orderBy = [];
|
|
1401
|
+
} else {
|
|
1402
|
+
result = (0,alias/* aliasedTable */.oG)(table, tableAlias);
|
|
1403
|
+
}
|
|
1404
|
+
result = this.buildSelectQuery({
|
|
1405
|
+
table: (0,entity.is)(result, pg_core_table/* PgTable */.mu) ? result : new subquery/* Subquery */.n(result, {}, tableAlias),
|
|
1406
|
+
fields: {},
|
|
1407
|
+
fieldsFlat: nestedSelection.map(({ field: field2 }) => ({
|
|
1408
|
+
path: [],
|
|
1409
|
+
field: (0,entity.is)(field2, column/* Column */.V) ? (0,alias/* aliasedTableColumn */.ug)(field2, tableAlias) : field2
|
|
1410
|
+
})),
|
|
1411
|
+
joins,
|
|
1412
|
+
where,
|
|
1413
|
+
limit,
|
|
1414
|
+
offset,
|
|
1415
|
+
orderBy,
|
|
1416
|
+
setOperators: []
|
|
1417
|
+
});
|
|
1418
|
+
} else {
|
|
1419
|
+
result = this.buildSelectQuery({
|
|
1420
|
+
table: (0,alias/* aliasedTable */.oG)(table, tableAlias),
|
|
1421
|
+
fields: {},
|
|
1422
|
+
fieldsFlat: selection.map(({ field }) => ({
|
|
1423
|
+
path: [],
|
|
1424
|
+
field: (0,entity.is)(field, column/* Column */.V) ? (0,alias/* aliasedTableColumn */.ug)(field, tableAlias) : field
|
|
1425
|
+
})),
|
|
1426
|
+
joins,
|
|
1427
|
+
where,
|
|
1428
|
+
limit,
|
|
1429
|
+
offset,
|
|
1430
|
+
orderBy,
|
|
1431
|
+
setOperators: []
|
|
1432
|
+
});
|
|
1433
|
+
}
|
|
1434
|
+
return {
|
|
1435
|
+
tableTsKey: tableConfig.tsName,
|
|
1436
|
+
sql: result,
|
|
1437
|
+
selection
|
|
1438
|
+
};
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
//# sourceMappingURL=dialect.js.map
|
|
1443
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/selection-proxy.js
|
|
1444
|
+
var selection_proxy = __webpack_require__(8296);
|
|
1445
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/query-builders/query-builder.js
|
|
1446
|
+
var query_builder = __webpack_require__(6685);
|
|
1447
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/query-promise.js
|
|
1448
|
+
var query_promise = __webpack_require__(4579);
|
|
1449
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/tracing.js + 1 modules
|
|
1450
|
+
var tracing = __webpack_require__(6412);
|
|
1451
|
+
;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/pg-core/query-builders/select.js
|
|
1452
|
+
|
|
1453
|
+
|
|
1454
|
+
|
|
1455
|
+
|
|
1456
|
+
|
|
1457
|
+
|
|
1458
|
+
|
|
1459
|
+
|
|
1460
|
+
|
|
1461
|
+
|
|
1462
|
+
|
|
1463
|
+
|
|
1464
|
+
class PgSelectBuilder {
|
|
1465
|
+
static [entity/* entityKind */.i] = "PgSelectBuilder";
|
|
1466
|
+
fields;
|
|
1467
|
+
session;
|
|
1468
|
+
dialect;
|
|
1469
|
+
withList = [];
|
|
1470
|
+
distinct;
|
|
1471
|
+
constructor(config) {
|
|
1472
|
+
this.fields = config.fields;
|
|
1473
|
+
this.session = config.session;
|
|
1474
|
+
this.dialect = config.dialect;
|
|
1475
|
+
if (config.withList) {
|
|
1476
|
+
this.withList = config.withList;
|
|
1477
|
+
}
|
|
1478
|
+
this.distinct = config.distinct;
|
|
1479
|
+
}
|
|
1480
|
+
authToken;
|
|
1481
|
+
/** @internal */
|
|
1482
|
+
setToken(token) {
|
|
1483
|
+
this.authToken = token;
|
|
1484
|
+
return this;
|
|
1485
|
+
}
|
|
1486
|
+
/**
|
|
1487
|
+
* Specify the table, subquery, or other target that you're
|
|
1488
|
+
* building a select query against.
|
|
1489
|
+
*
|
|
1490
|
+
* {@link https://www.postgresql.org/docs/current/sql-select.html#SQL-FROM | Postgres from documentation}
|
|
1491
|
+
*/
|
|
1492
|
+
from(source) {
|
|
1493
|
+
const isPartialSelect = !!this.fields;
|
|
1494
|
+
let fields;
|
|
1495
|
+
if (this.fields) {
|
|
1496
|
+
fields = this.fields;
|
|
1497
|
+
} else if ((0,entity.is)(source, subquery/* Subquery */.n)) {
|
|
1498
|
+
fields = Object.fromEntries(
|
|
1499
|
+
Object.keys(source._.selectedFields).map((key) => [key, source[key]])
|
|
1500
|
+
);
|
|
1501
|
+
} else if ((0,entity.is)(source, PgViewBase)) {
|
|
1502
|
+
fields = source[view_common/* ViewBaseConfig */.n].selectedFields;
|
|
1503
|
+
} else if ((0,entity.is)(source, sql/* SQL */.Xs)) {
|
|
1504
|
+
fields = {};
|
|
1505
|
+
} else {
|
|
1506
|
+
fields = (0,utils/* getTableColumns */.YD)(source);
|
|
1507
|
+
}
|
|
1508
|
+
return this.authToken === void 0 ? new PgSelectBase({
|
|
1509
|
+
table: source,
|
|
1510
|
+
fields,
|
|
1511
|
+
isPartialSelect,
|
|
1512
|
+
session: this.session,
|
|
1513
|
+
dialect: this.dialect,
|
|
1514
|
+
withList: this.withList,
|
|
1515
|
+
distinct: this.distinct
|
|
1516
|
+
}) : new PgSelectBase({
|
|
1517
|
+
table: source,
|
|
1518
|
+
fields,
|
|
1519
|
+
isPartialSelect,
|
|
1520
|
+
session: this.session,
|
|
1521
|
+
dialect: this.dialect,
|
|
1522
|
+
withList: this.withList,
|
|
1523
|
+
distinct: this.distinct
|
|
1524
|
+
}).setToken(this.authToken);
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
class PgSelectQueryBuilderBase extends query_builder/* TypedQueryBuilder */.O {
|
|
1528
|
+
static [entity/* entityKind */.i] = "PgSelectQueryBuilder";
|
|
1529
|
+
_;
|
|
1530
|
+
config;
|
|
1531
|
+
joinsNotNullableMap;
|
|
1532
|
+
tableName;
|
|
1533
|
+
isPartialSelect;
|
|
1534
|
+
session;
|
|
1535
|
+
dialect;
|
|
1536
|
+
constructor({ table, fields, isPartialSelect, session, dialect, withList, distinct }) {
|
|
1537
|
+
super();
|
|
1538
|
+
this.config = {
|
|
1539
|
+
withList,
|
|
1540
|
+
table,
|
|
1541
|
+
fields: { ...fields },
|
|
1542
|
+
distinct,
|
|
1543
|
+
setOperators: []
|
|
1544
|
+
};
|
|
1545
|
+
this.isPartialSelect = isPartialSelect;
|
|
1546
|
+
this.session = session;
|
|
1547
|
+
this.dialect = dialect;
|
|
1548
|
+
this._ = {
|
|
1549
|
+
selectedFields: fields
|
|
1550
|
+
};
|
|
1551
|
+
this.tableName = (0,utils/* getTableLikeName */.zN)(table);
|
|
1552
|
+
this.joinsNotNullableMap = typeof this.tableName === "string" ? { [this.tableName]: true } : {};
|
|
1553
|
+
}
|
|
1554
|
+
createJoin(joinType) {
|
|
1555
|
+
return (table, on) => {
|
|
1556
|
+
const baseTableName = this.tableName;
|
|
1557
|
+
const tableName = (0,utils/* getTableLikeName */.zN)(table);
|
|
1558
|
+
if (typeof tableName === "string" && this.config.joins?.some((join) => join.alias === tableName)) {
|
|
1559
|
+
throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
1560
|
+
}
|
|
1561
|
+
if (!this.isPartialSelect) {
|
|
1562
|
+
if (Object.keys(this.joinsNotNullableMap).length === 1 && typeof baseTableName === "string") {
|
|
1563
|
+
this.config.fields = {
|
|
1564
|
+
[baseTableName]: this.config.fields
|
|
1565
|
+
};
|
|
1566
|
+
}
|
|
1567
|
+
if (typeof tableName === "string" && !(0,entity.is)(table, sql/* SQL */.Xs)) {
|
|
1568
|
+
const selection = (0,entity.is)(table, subquery/* Subquery */.n) ? table._.selectedFields : (0,entity.is)(table, sql/* View */.Ss) ? table[view_common/* ViewBaseConfig */.n].selectedFields : table[drizzle_orm_table/* Table */.XI.Symbol.Columns];
|
|
1569
|
+
this.config.fields[tableName] = selection;
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
if (typeof on === "function") {
|
|
1573
|
+
on = on(
|
|
1574
|
+
new Proxy(
|
|
1575
|
+
this.config.fields,
|
|
1576
|
+
new selection_proxy/* SelectionProxyHandler */.b({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
|
1577
|
+
)
|
|
1578
|
+
);
|
|
1579
|
+
}
|
|
1580
|
+
if (!this.config.joins) {
|
|
1581
|
+
this.config.joins = [];
|
|
1582
|
+
}
|
|
1583
|
+
this.config.joins.push({ on, table, joinType, alias: tableName });
|
|
1584
|
+
if (typeof tableName === "string") {
|
|
1585
|
+
switch (joinType) {
|
|
1586
|
+
case "left": {
|
|
1587
|
+
this.joinsNotNullableMap[tableName] = false;
|
|
1588
|
+
break;
|
|
1589
|
+
}
|
|
1590
|
+
case "right": {
|
|
1591
|
+
this.joinsNotNullableMap = Object.fromEntries(
|
|
1592
|
+
Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false])
|
|
1593
|
+
);
|
|
1594
|
+
this.joinsNotNullableMap[tableName] = true;
|
|
1595
|
+
break;
|
|
1596
|
+
}
|
|
1597
|
+
case "inner": {
|
|
1598
|
+
this.joinsNotNullableMap[tableName] = true;
|
|
1599
|
+
break;
|
|
1600
|
+
}
|
|
1601
|
+
case "full": {
|
|
1602
|
+
this.joinsNotNullableMap = Object.fromEntries(
|
|
1603
|
+
Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false])
|
|
1604
|
+
);
|
|
1605
|
+
this.joinsNotNullableMap[tableName] = false;
|
|
1606
|
+
break;
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
return this;
|
|
1611
|
+
};
|
|
1612
|
+
}
|
|
1613
|
+
/**
|
|
1614
|
+
* Executes a `left join` operation by adding another table to the current query.
|
|
1615
|
+
*
|
|
1616
|
+
* 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.
|
|
1617
|
+
*
|
|
1618
|
+
* See docs: {@link https://orm.drizzle.team/docs/joins#left-join}
|
|
1619
|
+
*
|
|
1620
|
+
* @param table the table to join.
|
|
1621
|
+
* @param on the `on` clause.
|
|
1622
|
+
*
|
|
1623
|
+
* @example
|
|
1624
|
+
*
|
|
1625
|
+
* ```ts
|
|
1626
|
+
* // Select all users and their pets
|
|
1627
|
+
* const usersWithPets: { user: User; pets: Pet | null }[] = await db.select()
|
|
1628
|
+
* .from(users)
|
|
1629
|
+
* .leftJoin(pets, eq(users.id, pets.ownerId))
|
|
1630
|
+
*
|
|
1631
|
+
* // Select userId and petId
|
|
1632
|
+
* const usersIdsAndPetIds: { userId: number; petId: number | null }[] = await db.select({
|
|
1633
|
+
* userId: users.id,
|
|
1634
|
+
* petId: pets.id,
|
|
1635
|
+
* })
|
|
1636
|
+
* .from(users)
|
|
1637
|
+
* .leftJoin(pets, eq(users.id, pets.ownerId))
|
|
1638
|
+
* ```
|
|
1639
|
+
*/
|
|
1640
|
+
leftJoin = this.createJoin("left");
|
|
1641
|
+
/**
|
|
1642
|
+
* Executes a `right join` operation by adding another table to the current query.
|
|
1643
|
+
*
|
|
1644
|
+
* 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.
|
|
1645
|
+
*
|
|
1646
|
+
* See docs: {@link https://orm.drizzle.team/docs/joins#right-join}
|
|
1647
|
+
*
|
|
1648
|
+
* @param table the table to join.
|
|
1649
|
+
* @param on the `on` clause.
|
|
1650
|
+
*
|
|
1651
|
+
* @example
|
|
1652
|
+
*
|
|
1653
|
+
* ```ts
|
|
1654
|
+
* // Select all users and their pets
|
|
1655
|
+
* const usersWithPets: { user: User | null; pets: Pet }[] = await db.select()
|
|
1656
|
+
* .from(users)
|
|
1657
|
+
* .rightJoin(pets, eq(users.id, pets.ownerId))
|
|
1658
|
+
*
|
|
1659
|
+
* // Select userId and petId
|
|
1660
|
+
* const usersIdsAndPetIds: { userId: number | null; petId: number }[] = await db.select({
|
|
1661
|
+
* userId: users.id,
|
|
1662
|
+
* petId: pets.id,
|
|
1663
|
+
* })
|
|
1664
|
+
* .from(users)
|
|
1665
|
+
* .rightJoin(pets, eq(users.id, pets.ownerId))
|
|
1666
|
+
* ```
|
|
1667
|
+
*/
|
|
1668
|
+
rightJoin = this.createJoin("right");
|
|
1669
|
+
/**
|
|
1670
|
+
* Executes an `inner join` operation, creating a new table by combining rows from two tables that have matching values.
|
|
1671
|
+
*
|
|
1672
|
+
* 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.
|
|
1673
|
+
*
|
|
1674
|
+
* See docs: {@link https://orm.drizzle.team/docs/joins#inner-join}
|
|
1675
|
+
*
|
|
1676
|
+
* @param table the table to join.
|
|
1677
|
+
* @param on the `on` clause.
|
|
1678
|
+
*
|
|
1679
|
+
* @example
|
|
1680
|
+
*
|
|
1681
|
+
* ```ts
|
|
1682
|
+
* // Select all users and their pets
|
|
1683
|
+
* const usersWithPets: { user: User; pets: Pet }[] = await db.select()
|
|
1684
|
+
* .from(users)
|
|
1685
|
+
* .innerJoin(pets, eq(users.id, pets.ownerId))
|
|
1686
|
+
*
|
|
1687
|
+
* // Select userId and petId
|
|
1688
|
+
* const usersIdsAndPetIds: { userId: number; petId: number }[] = await db.select({
|
|
1689
|
+
* userId: users.id,
|
|
1690
|
+
* petId: pets.id,
|
|
1691
|
+
* })
|
|
1692
|
+
* .from(users)
|
|
1693
|
+
* .innerJoin(pets, eq(users.id, pets.ownerId))
|
|
1694
|
+
* ```
|
|
1695
|
+
*/
|
|
1696
|
+
innerJoin = this.createJoin("inner");
|
|
1697
|
+
/**
|
|
1698
|
+
* Executes a `full join` operation by combining rows from two tables into a new table.
|
|
1699
|
+
*
|
|
1700
|
+
* 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.
|
|
1701
|
+
*
|
|
1702
|
+
* See docs: {@link https://orm.drizzle.team/docs/joins#full-join}
|
|
1703
|
+
*
|
|
1704
|
+
* @param table the table to join.
|
|
1705
|
+
* @param on the `on` clause.
|
|
1706
|
+
*
|
|
1707
|
+
* @example
|
|
1708
|
+
*
|
|
1709
|
+
* ```ts
|
|
1710
|
+
* // Select all users and their pets
|
|
1711
|
+
* const usersWithPets: { user: User | null; pets: Pet | null }[] = await db.select()
|
|
1712
|
+
* .from(users)
|
|
1713
|
+
* .fullJoin(pets, eq(users.id, pets.ownerId))
|
|
1714
|
+
*
|
|
1715
|
+
* // Select userId and petId
|
|
1716
|
+
* const usersIdsAndPetIds: { userId: number | null; petId: number | null }[] = await db.select({
|
|
1717
|
+
* userId: users.id,
|
|
1718
|
+
* petId: pets.id,
|
|
1719
|
+
* })
|
|
1720
|
+
* .from(users)
|
|
1721
|
+
* .fullJoin(pets, eq(users.id, pets.ownerId))
|
|
1722
|
+
* ```
|
|
1723
|
+
*/
|
|
1724
|
+
fullJoin = this.createJoin("full");
|
|
1725
|
+
createSetOperator(type, isAll) {
|
|
1726
|
+
return (rightSelection) => {
|
|
1727
|
+
const rightSelect = typeof rightSelection === "function" ? rightSelection(getPgSetOperators()) : rightSelection;
|
|
1728
|
+
if (!(0,utils/* haveSameKeys */.DV)(this.getSelectedFields(), rightSelect.getSelectedFields())) {
|
|
1729
|
+
throw new Error(
|
|
1730
|
+
"Set operator error (union / intersect / except): selected fields are not the same or are in a different order"
|
|
1731
|
+
);
|
|
1732
|
+
}
|
|
1733
|
+
this.config.setOperators.push({ type, isAll, rightSelect });
|
|
1734
|
+
return this;
|
|
1735
|
+
};
|
|
1736
|
+
}
|
|
1737
|
+
/**
|
|
1738
|
+
* Adds `union` set operator to the query.
|
|
1739
|
+
*
|
|
1740
|
+
* Calling this method will combine the result sets of the `select` statements and remove any duplicate rows that appear across them.
|
|
1741
|
+
*
|
|
1742
|
+
* See docs: {@link https://orm.drizzle.team/docs/set-operations#union}
|
|
1743
|
+
*
|
|
1744
|
+
* @example
|
|
1745
|
+
*
|
|
1746
|
+
* ```ts
|
|
1747
|
+
* // Select all unique names from customers and users tables
|
|
1748
|
+
* await db.select({ name: users.name })
|
|
1749
|
+
* .from(users)
|
|
1750
|
+
* .union(
|
|
1751
|
+
* db.select({ name: customers.name }).from(customers)
|
|
1752
|
+
* );
|
|
1753
|
+
* // or
|
|
1754
|
+
* import { union } from 'drizzle-orm/pg-core'
|
|
1755
|
+
*
|
|
1756
|
+
* await union(
|
|
1757
|
+
* db.select({ name: users.name }).from(users),
|
|
1758
|
+
* db.select({ name: customers.name }).from(customers)
|
|
1759
|
+
* );
|
|
1760
|
+
* ```
|
|
1761
|
+
*/
|
|
1762
|
+
union = this.createSetOperator("union", false);
|
|
1763
|
+
/**
|
|
1764
|
+
* Adds `union all` set operator to the query.
|
|
1765
|
+
*
|
|
1766
|
+
* Calling this method will combine the result-set of the `select` statements and keep all duplicate rows that appear across them.
|
|
1767
|
+
*
|
|
1768
|
+
* See docs: {@link https://orm.drizzle.team/docs/set-operations#union-all}
|
|
1769
|
+
*
|
|
1770
|
+
* @example
|
|
1771
|
+
*
|
|
1772
|
+
* ```ts
|
|
1773
|
+
* // Select all transaction ids from both online and in-store sales
|
|
1774
|
+
* await db.select({ transaction: onlineSales.transactionId })
|
|
1775
|
+
* .from(onlineSales)
|
|
1776
|
+
* .unionAll(
|
|
1777
|
+
* db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
|
|
1778
|
+
* );
|
|
1779
|
+
* // or
|
|
1780
|
+
* import { unionAll } from 'drizzle-orm/pg-core'
|
|
1781
|
+
*
|
|
1782
|
+
* await unionAll(
|
|
1783
|
+
* db.select({ transaction: onlineSales.transactionId }).from(onlineSales),
|
|
1784
|
+
* db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
|
|
1785
|
+
* );
|
|
1786
|
+
* ```
|
|
1787
|
+
*/
|
|
1788
|
+
unionAll = this.createSetOperator("union", true);
|
|
1789
|
+
/**
|
|
1790
|
+
* Adds `intersect` set operator to the query.
|
|
1791
|
+
*
|
|
1792
|
+
* Calling this method will retain only the rows that are present in both result sets and eliminate duplicates.
|
|
1793
|
+
*
|
|
1794
|
+
* See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect}
|
|
1795
|
+
*
|
|
1796
|
+
* @example
|
|
1797
|
+
*
|
|
1798
|
+
* ```ts
|
|
1799
|
+
* // Select course names that are offered in both departments A and B
|
|
1800
|
+
* await db.select({ courseName: depA.courseName })
|
|
1801
|
+
* .from(depA)
|
|
1802
|
+
* .intersect(
|
|
1803
|
+
* db.select({ courseName: depB.courseName }).from(depB)
|
|
1804
|
+
* );
|
|
1805
|
+
* // or
|
|
1806
|
+
* import { intersect } from 'drizzle-orm/pg-core'
|
|
1807
|
+
*
|
|
1808
|
+
* await intersect(
|
|
1809
|
+
* db.select({ courseName: depA.courseName }).from(depA),
|
|
1810
|
+
* db.select({ courseName: depB.courseName }).from(depB)
|
|
1811
|
+
* );
|
|
1812
|
+
* ```
|
|
1813
|
+
*/
|
|
1814
|
+
intersect = this.createSetOperator("intersect", false);
|
|
1815
|
+
/**
|
|
1816
|
+
* Adds `intersect all` set operator to the query.
|
|
1817
|
+
*
|
|
1818
|
+
* Calling this method will retain only the rows that are present in both result sets including all duplicates.
|
|
1819
|
+
*
|
|
1820
|
+
* See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect-all}
|
|
1821
|
+
*
|
|
1822
|
+
* @example
|
|
1823
|
+
*
|
|
1824
|
+
* ```ts
|
|
1825
|
+
* // Select all products and quantities that are ordered by both regular and VIP customers
|
|
1826
|
+
* await db.select({
|
|
1827
|
+
* productId: regularCustomerOrders.productId,
|
|
1828
|
+
* quantityOrdered: regularCustomerOrders.quantityOrdered
|
|
1829
|
+
* })
|
|
1830
|
+
* .from(regularCustomerOrders)
|
|
1831
|
+
* .intersectAll(
|
|
1832
|
+
* db.select({
|
|
1833
|
+
* productId: vipCustomerOrders.productId,
|
|
1834
|
+
* quantityOrdered: vipCustomerOrders.quantityOrdered
|
|
1835
|
+
* })
|
|
1836
|
+
* .from(vipCustomerOrders)
|
|
1837
|
+
* );
|
|
1838
|
+
* // or
|
|
1839
|
+
* import { intersectAll } from 'drizzle-orm/pg-core'
|
|
1840
|
+
*
|
|
1841
|
+
* await intersectAll(
|
|
1842
|
+
* db.select({
|
|
1843
|
+
* productId: regularCustomerOrders.productId,
|
|
1844
|
+
* quantityOrdered: regularCustomerOrders.quantityOrdered
|
|
1845
|
+
* })
|
|
1846
|
+
* .from(regularCustomerOrders),
|
|
1847
|
+
* db.select({
|
|
1848
|
+
* productId: vipCustomerOrders.productId,
|
|
1849
|
+
* quantityOrdered: vipCustomerOrders.quantityOrdered
|
|
1850
|
+
* })
|
|
1851
|
+
* .from(vipCustomerOrders)
|
|
1852
|
+
* );
|
|
1853
|
+
* ```
|
|
1854
|
+
*/
|
|
1855
|
+
intersectAll = this.createSetOperator("intersect", true);
|
|
1856
|
+
/**
|
|
1857
|
+
* Adds `except` set operator to the query.
|
|
1858
|
+
*
|
|
1859
|
+
* 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.
|
|
1860
|
+
*
|
|
1861
|
+
* See docs: {@link https://orm.drizzle.team/docs/set-operations#except}
|
|
1862
|
+
*
|
|
1863
|
+
* @example
|
|
1864
|
+
*
|
|
1865
|
+
* ```ts
|
|
1866
|
+
* // Select all courses offered in department A but not in department B
|
|
1867
|
+
* await db.select({ courseName: depA.courseName })
|
|
1868
|
+
* .from(depA)
|
|
1869
|
+
* .except(
|
|
1870
|
+
* db.select({ courseName: depB.courseName }).from(depB)
|
|
1871
|
+
* );
|
|
1872
|
+
* // or
|
|
1873
|
+
* import { except } from 'drizzle-orm/pg-core'
|
|
1874
|
+
*
|
|
1875
|
+
* await except(
|
|
1876
|
+
* db.select({ courseName: depA.courseName }).from(depA),
|
|
1877
|
+
* db.select({ courseName: depB.courseName }).from(depB)
|
|
1878
|
+
* );
|
|
1879
|
+
* ```
|
|
1880
|
+
*/
|
|
1881
|
+
except = this.createSetOperator("except", false);
|
|
1882
|
+
/**
|
|
1883
|
+
* Adds `except all` set operator to the query.
|
|
1884
|
+
*
|
|
1885
|
+
* Calling this method will retrieve all rows from the left query, except for the rows that are present in the result set of the right query.
|
|
1886
|
+
*
|
|
1887
|
+
* See docs: {@link https://orm.drizzle.team/docs/set-operations#except-all}
|
|
1888
|
+
*
|
|
1889
|
+
* @example
|
|
1890
|
+
*
|
|
1891
|
+
* ```ts
|
|
1892
|
+
* // Select all products that are ordered by regular customers but not by VIP customers
|
|
1893
|
+
* await db.select({
|
|
1894
|
+
* productId: regularCustomerOrders.productId,
|
|
1895
|
+
* quantityOrdered: regularCustomerOrders.quantityOrdered,
|
|
1896
|
+
* })
|
|
1897
|
+
* .from(regularCustomerOrders)
|
|
1898
|
+
* .exceptAll(
|
|
1899
|
+
* db.select({
|
|
1900
|
+
* productId: vipCustomerOrders.productId,
|
|
1901
|
+
* quantityOrdered: vipCustomerOrders.quantityOrdered,
|
|
1902
|
+
* })
|
|
1903
|
+
* .from(vipCustomerOrders)
|
|
1904
|
+
* );
|
|
1905
|
+
* // or
|
|
1906
|
+
* import { exceptAll } from 'drizzle-orm/pg-core'
|
|
1907
|
+
*
|
|
1908
|
+
* await exceptAll(
|
|
1909
|
+
* db.select({
|
|
1910
|
+
* productId: regularCustomerOrders.productId,
|
|
1911
|
+
* quantityOrdered: regularCustomerOrders.quantityOrdered
|
|
1912
|
+
* })
|
|
1913
|
+
* .from(regularCustomerOrders),
|
|
1914
|
+
* db.select({
|
|
1915
|
+
* productId: vipCustomerOrders.productId,
|
|
1916
|
+
* quantityOrdered: vipCustomerOrders.quantityOrdered
|
|
1917
|
+
* })
|
|
1918
|
+
* .from(vipCustomerOrders)
|
|
1919
|
+
* );
|
|
1920
|
+
* ```
|
|
1921
|
+
*/
|
|
1922
|
+
exceptAll = this.createSetOperator("except", true);
|
|
1923
|
+
/** @internal */
|
|
1924
|
+
addSetOperators(setOperators) {
|
|
1925
|
+
this.config.setOperators.push(...setOperators);
|
|
1926
|
+
return this;
|
|
1927
|
+
}
|
|
1928
|
+
/**
|
|
1929
|
+
* Adds a `where` clause to the query.
|
|
1930
|
+
*
|
|
1931
|
+
* Calling this method will select only those rows that fulfill a specified condition.
|
|
1932
|
+
*
|
|
1933
|
+
* See docs: {@link https://orm.drizzle.team/docs/select#filtering}
|
|
1934
|
+
*
|
|
1935
|
+
* @param where the `where` clause.
|
|
1936
|
+
*
|
|
1937
|
+
* @example
|
|
1938
|
+
* You can use conditional operators and `sql function` to filter the rows to be selected.
|
|
1939
|
+
*
|
|
1940
|
+
* ```ts
|
|
1941
|
+
* // Select all cars with green color
|
|
1942
|
+
* await db.select().from(cars).where(eq(cars.color, 'green'));
|
|
1943
|
+
* // or
|
|
1944
|
+
* await db.select().from(cars).where(sql`${cars.color} = 'green'`)
|
|
1945
|
+
* ```
|
|
1946
|
+
*
|
|
1947
|
+
* You can logically combine conditional operators with `and()` and `or()` operators:
|
|
1948
|
+
*
|
|
1949
|
+
* ```ts
|
|
1950
|
+
* // Select all BMW cars with a green color
|
|
1951
|
+
* await db.select().from(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
|
1952
|
+
*
|
|
1953
|
+
* // Select all cars with the green or blue color
|
|
1954
|
+
* await db.select().from(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
|
1955
|
+
* ```
|
|
1956
|
+
*/
|
|
1957
|
+
where(where) {
|
|
1958
|
+
if (typeof where === "function") {
|
|
1959
|
+
where = where(
|
|
1960
|
+
new Proxy(
|
|
1961
|
+
this.config.fields,
|
|
1962
|
+
new selection_proxy/* SelectionProxyHandler */.b({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
|
1963
|
+
)
|
|
1964
|
+
);
|
|
1965
|
+
}
|
|
1966
|
+
this.config.where = where;
|
|
1967
|
+
return this;
|
|
1968
|
+
}
|
|
1969
|
+
/**
|
|
1970
|
+
* Adds a `having` clause to the query.
|
|
1971
|
+
*
|
|
1972
|
+
* 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.
|
|
1973
|
+
*
|
|
1974
|
+
* See docs: {@link https://orm.drizzle.team/docs/select#aggregations}
|
|
1975
|
+
*
|
|
1976
|
+
* @param having the `having` clause.
|
|
1977
|
+
*
|
|
1978
|
+
* @example
|
|
1979
|
+
*
|
|
1980
|
+
* ```ts
|
|
1981
|
+
* // Select all brands with more than one car
|
|
1982
|
+
* await db.select({
|
|
1983
|
+
* brand: cars.brand,
|
|
1984
|
+
* count: sql<number>`cast(count(${cars.id}) as int)`,
|
|
1985
|
+
* })
|
|
1986
|
+
* .from(cars)
|
|
1987
|
+
* .groupBy(cars.brand)
|
|
1988
|
+
* .having(({ count }) => gt(count, 1));
|
|
1989
|
+
* ```
|
|
1990
|
+
*/
|
|
1991
|
+
having(having) {
|
|
1992
|
+
if (typeof having === "function") {
|
|
1993
|
+
having = having(
|
|
1994
|
+
new Proxy(
|
|
1995
|
+
this.config.fields,
|
|
1996
|
+
new selection_proxy/* SelectionProxyHandler */.b({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
|
1997
|
+
)
|
|
1998
|
+
);
|
|
1999
|
+
}
|
|
2000
|
+
this.config.having = having;
|
|
2001
|
+
return this;
|
|
2002
|
+
}
|
|
2003
|
+
groupBy(...columns) {
|
|
2004
|
+
if (typeof columns[0] === "function") {
|
|
2005
|
+
const groupBy = columns[0](
|
|
2006
|
+
new Proxy(
|
|
2007
|
+
this.config.fields,
|
|
2008
|
+
new selection_proxy/* SelectionProxyHandler */.b({ sqlAliasedBehavior: "alias", sqlBehavior: "sql" })
|
|
2009
|
+
)
|
|
2010
|
+
);
|
|
2011
|
+
this.config.groupBy = Array.isArray(groupBy) ? groupBy : [groupBy];
|
|
2012
|
+
} else {
|
|
2013
|
+
this.config.groupBy = columns;
|
|
2014
|
+
}
|
|
2015
|
+
return this;
|
|
2016
|
+
}
|
|
2017
|
+
orderBy(...columns) {
|
|
2018
|
+
if (typeof columns[0] === "function") {
|
|
2019
|
+
const orderBy = columns[0](
|
|
2020
|
+
new Proxy(
|
|
2021
|
+
this.config.fields,
|
|
2022
|
+
new selection_proxy/* SelectionProxyHandler */.b({ sqlAliasedBehavior: "alias", sqlBehavior: "sql" })
|
|
2023
|
+
)
|
|
2024
|
+
);
|
|
2025
|
+
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
|
2026
|
+
if (this.config.setOperators.length > 0) {
|
|
2027
|
+
this.config.setOperators.at(-1).orderBy = orderByArray;
|
|
2028
|
+
} else {
|
|
2029
|
+
this.config.orderBy = orderByArray;
|
|
2030
|
+
}
|
|
2031
|
+
} else {
|
|
2032
|
+
const orderByArray = columns;
|
|
2033
|
+
if (this.config.setOperators.length > 0) {
|
|
2034
|
+
this.config.setOperators.at(-1).orderBy = orderByArray;
|
|
2035
|
+
} else {
|
|
2036
|
+
this.config.orderBy = orderByArray;
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
return this;
|
|
2040
|
+
}
|
|
2041
|
+
/**
|
|
2042
|
+
* Adds a `limit` clause to the query.
|
|
2043
|
+
*
|
|
2044
|
+
* Calling this method will set the maximum number of rows that will be returned by this query.
|
|
2045
|
+
*
|
|
2046
|
+
* See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}
|
|
2047
|
+
*
|
|
2048
|
+
* @param limit the `limit` clause.
|
|
2049
|
+
*
|
|
2050
|
+
* @example
|
|
2051
|
+
*
|
|
2052
|
+
* ```ts
|
|
2053
|
+
* // Get the first 10 people from this query.
|
|
2054
|
+
* await db.select().from(people).limit(10);
|
|
2055
|
+
* ```
|
|
2056
|
+
*/
|
|
2057
|
+
limit(limit) {
|
|
2058
|
+
if (this.config.setOperators.length > 0) {
|
|
2059
|
+
this.config.setOperators.at(-1).limit = limit;
|
|
2060
|
+
} else {
|
|
2061
|
+
this.config.limit = limit;
|
|
2062
|
+
}
|
|
2063
|
+
return this;
|
|
2064
|
+
}
|
|
2065
|
+
/**
|
|
2066
|
+
* Adds an `offset` clause to the query.
|
|
2067
|
+
*
|
|
2068
|
+
* Calling this method will skip a number of rows when returning results from this query.
|
|
2069
|
+
*
|
|
2070
|
+
* See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}
|
|
2071
|
+
*
|
|
2072
|
+
* @param offset the `offset` clause.
|
|
2073
|
+
*
|
|
2074
|
+
* @example
|
|
2075
|
+
*
|
|
2076
|
+
* ```ts
|
|
2077
|
+
* // Get the 10th-20th people from this query.
|
|
2078
|
+
* await db.select().from(people).offset(10).limit(10);
|
|
2079
|
+
* ```
|
|
2080
|
+
*/
|
|
2081
|
+
offset(offset) {
|
|
2082
|
+
if (this.config.setOperators.length > 0) {
|
|
2083
|
+
this.config.setOperators.at(-1).offset = offset;
|
|
2084
|
+
} else {
|
|
2085
|
+
this.config.offset = offset;
|
|
2086
|
+
}
|
|
2087
|
+
return this;
|
|
2088
|
+
}
|
|
2089
|
+
/**
|
|
2090
|
+
* Adds a `for` clause to the query.
|
|
2091
|
+
*
|
|
2092
|
+
* Calling this method will specify a lock strength for this query that controls how strictly it acquires exclusive access to the rows being queried.
|
|
2093
|
+
*
|
|
2094
|
+
* See docs: {@link https://www.postgresql.org/docs/current/sql-select.html#SQL-FOR-UPDATE-SHARE}
|
|
2095
|
+
*
|
|
2096
|
+
* @param strength the lock strength.
|
|
2097
|
+
* @param config the lock configuration.
|
|
2098
|
+
*/
|
|
2099
|
+
for(strength, config = {}) {
|
|
2100
|
+
this.config.lockingClause = { strength, config };
|
|
2101
|
+
return this;
|
|
2102
|
+
}
|
|
2103
|
+
/** @internal */
|
|
2104
|
+
getSQL() {
|
|
2105
|
+
return this.dialect.buildSelectQuery(this.config);
|
|
2106
|
+
}
|
|
2107
|
+
toSQL() {
|
|
2108
|
+
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
|
2109
|
+
return rest;
|
|
2110
|
+
}
|
|
2111
|
+
as(alias) {
|
|
2112
|
+
return new Proxy(
|
|
2113
|
+
new subquery/* Subquery */.n(this.getSQL(), this.config.fields, alias),
|
|
2114
|
+
new selection_proxy/* SelectionProxyHandler */.b({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
|
|
2115
|
+
);
|
|
2116
|
+
}
|
|
2117
|
+
/** @internal */
|
|
2118
|
+
getSelectedFields() {
|
|
2119
|
+
return new Proxy(
|
|
2120
|
+
this.config.fields,
|
|
2121
|
+
new selection_proxy/* SelectionProxyHandler */.b({ alias: this.tableName, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
|
|
2122
|
+
);
|
|
2123
|
+
}
|
|
2124
|
+
$dynamic() {
|
|
2125
|
+
return this;
|
|
2126
|
+
}
|
|
2127
|
+
}
|
|
2128
|
+
class PgSelectBase extends PgSelectQueryBuilderBase {
|
|
2129
|
+
static [entity/* entityKind */.i] = "PgSelect";
|
|
2130
|
+
/** @internal */
|
|
2131
|
+
_prepare(name) {
|
|
2132
|
+
const { session, config, dialect, joinsNotNullableMap, authToken } = this;
|
|
2133
|
+
if (!session) {
|
|
2134
|
+
throw new Error("Cannot execute a query on a query builder. Please use a database instance instead.");
|
|
2135
|
+
}
|
|
2136
|
+
return tracing/* tracer */.k.startActiveSpan("drizzle.prepareQuery", () => {
|
|
2137
|
+
const fieldsList = (0,utils/* orderSelectedFields */.He)(config.fields);
|
|
2138
|
+
const query = session.prepareQuery(dialect.sqlToQuery(this.getSQL()), fieldsList, name, true);
|
|
2139
|
+
query.joinsNotNullableMap = joinsNotNullableMap;
|
|
2140
|
+
return authToken === void 0 ? query : query.setToken(authToken);
|
|
2141
|
+
});
|
|
2142
|
+
}
|
|
2143
|
+
/**
|
|
2144
|
+
* Create a prepared statement for this query. This allows
|
|
2145
|
+
* the database to remember this query for the given session
|
|
2146
|
+
* and call it by name, rather than specifying the full query.
|
|
2147
|
+
*
|
|
2148
|
+
* {@link https://www.postgresql.org/docs/current/sql-prepare.html | Postgres prepare documentation}
|
|
2149
|
+
*/
|
|
2150
|
+
prepare(name) {
|
|
2151
|
+
return this._prepare(name);
|
|
2152
|
+
}
|
|
2153
|
+
authToken;
|
|
2154
|
+
/** @internal */
|
|
2155
|
+
setToken(token) {
|
|
2156
|
+
this.authToken = token;
|
|
2157
|
+
return this;
|
|
2158
|
+
}
|
|
2159
|
+
execute = (placeholderValues) => {
|
|
2160
|
+
return tracing/* tracer */.k.startActiveSpan("drizzle.operation", () => {
|
|
2161
|
+
return this._prepare().execute(placeholderValues, this.authToken);
|
|
2162
|
+
});
|
|
2163
|
+
};
|
|
2164
|
+
}
|
|
2165
|
+
(0,utils/* applyMixins */.XJ)(PgSelectBase, [query_promise/* QueryPromise */.k]);
|
|
2166
|
+
function createSetOperator(type, isAll) {
|
|
2167
|
+
return (leftSelect, rightSelect, ...restSelects) => {
|
|
2168
|
+
const setOperators = [rightSelect, ...restSelects].map((select) => ({
|
|
2169
|
+
type,
|
|
2170
|
+
isAll,
|
|
2171
|
+
rightSelect: select
|
|
2172
|
+
}));
|
|
2173
|
+
for (const setOperator of setOperators) {
|
|
2174
|
+
if (!(0,utils/* haveSameKeys */.DV)(leftSelect.getSelectedFields(), setOperator.rightSelect.getSelectedFields())) {
|
|
2175
|
+
throw new Error(
|
|
2176
|
+
"Set operator error (union / intersect / except): selected fields are not the same or are in a different order"
|
|
2177
|
+
);
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2180
|
+
return leftSelect.addSetOperators(setOperators);
|
|
2181
|
+
};
|
|
2182
|
+
}
|
|
2183
|
+
const getPgSetOperators = () => ({
|
|
2184
|
+
union,
|
|
2185
|
+
unionAll,
|
|
2186
|
+
intersect,
|
|
2187
|
+
intersectAll,
|
|
2188
|
+
except,
|
|
2189
|
+
exceptAll
|
|
2190
|
+
});
|
|
2191
|
+
const union = createSetOperator("union", false);
|
|
2192
|
+
const unionAll = createSetOperator("union", true);
|
|
2193
|
+
const intersect = createSetOperator("intersect", false);
|
|
2194
|
+
const intersectAll = createSetOperator("intersect", true);
|
|
2195
|
+
const except = createSetOperator("except", false);
|
|
2196
|
+
const exceptAll = createSetOperator("except", true);
|
|
2197
|
+
|
|
2198
|
+
//# sourceMappingURL=select.js.map
|
|
2199
|
+
;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/pg-core/query-builders/query-builder.js
|
|
2200
|
+
|
|
2201
|
+
|
|
2202
|
+
|
|
2203
|
+
|
|
2204
|
+
|
|
2205
|
+
class QueryBuilder {
|
|
2206
|
+
static [entity/* entityKind */.i] = "PgQueryBuilder";
|
|
2207
|
+
dialect;
|
|
2208
|
+
dialectConfig;
|
|
2209
|
+
constructor(dialect) {
|
|
2210
|
+
this.dialect = (0,entity.is)(dialect, PgDialect) ? dialect : void 0;
|
|
2211
|
+
this.dialectConfig = (0,entity.is)(dialect, PgDialect) ? void 0 : dialect;
|
|
2212
|
+
}
|
|
2213
|
+
$with(alias) {
|
|
2214
|
+
const queryBuilder = this;
|
|
2215
|
+
return {
|
|
2216
|
+
as(qb) {
|
|
2217
|
+
if (typeof qb === "function") {
|
|
2218
|
+
qb = qb(queryBuilder);
|
|
2219
|
+
}
|
|
2220
|
+
return new Proxy(
|
|
2221
|
+
new subquery/* WithSubquery */.J(qb.getSQL(), qb.getSelectedFields(), alias, true),
|
|
2222
|
+
new selection_proxy/* SelectionProxyHandler */.b({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
|
|
2223
|
+
);
|
|
2224
|
+
}
|
|
2225
|
+
};
|
|
2226
|
+
}
|
|
2227
|
+
with(...queries) {
|
|
2228
|
+
const self = this;
|
|
2229
|
+
function select(fields) {
|
|
2230
|
+
return new PgSelectBuilder({
|
|
2231
|
+
fields: fields ?? void 0,
|
|
2232
|
+
session: void 0,
|
|
2233
|
+
dialect: self.getDialect(),
|
|
2234
|
+
withList: queries
|
|
2235
|
+
});
|
|
2236
|
+
}
|
|
2237
|
+
function selectDistinct(fields) {
|
|
2238
|
+
return new PgSelectBuilder({
|
|
2239
|
+
fields: fields ?? void 0,
|
|
2240
|
+
session: void 0,
|
|
2241
|
+
dialect: self.getDialect(),
|
|
2242
|
+
distinct: true
|
|
2243
|
+
});
|
|
2244
|
+
}
|
|
2245
|
+
function selectDistinctOn(on, fields) {
|
|
2246
|
+
return new PgSelectBuilder({
|
|
2247
|
+
fields: fields ?? void 0,
|
|
2248
|
+
session: void 0,
|
|
2249
|
+
dialect: self.getDialect(),
|
|
2250
|
+
distinct: { on }
|
|
2251
|
+
});
|
|
2252
|
+
}
|
|
2253
|
+
return { select, selectDistinct, selectDistinctOn };
|
|
2254
|
+
}
|
|
2255
|
+
select(fields) {
|
|
2256
|
+
return new PgSelectBuilder({
|
|
2257
|
+
fields: fields ?? void 0,
|
|
2258
|
+
session: void 0,
|
|
2259
|
+
dialect: this.getDialect()
|
|
2260
|
+
});
|
|
2261
|
+
}
|
|
2262
|
+
selectDistinct(fields) {
|
|
2263
|
+
return new PgSelectBuilder({
|
|
2264
|
+
fields: fields ?? void 0,
|
|
2265
|
+
session: void 0,
|
|
2266
|
+
dialect: this.getDialect(),
|
|
2267
|
+
distinct: true
|
|
2268
|
+
});
|
|
2269
|
+
}
|
|
2270
|
+
selectDistinctOn(on, fields) {
|
|
2271
|
+
return new PgSelectBuilder({
|
|
2272
|
+
fields: fields ?? void 0,
|
|
2273
|
+
session: void 0,
|
|
2274
|
+
dialect: this.getDialect(),
|
|
2275
|
+
distinct: { on }
|
|
2276
|
+
});
|
|
2277
|
+
}
|
|
2278
|
+
// Lazy load dialect to avoid circular dependency
|
|
2279
|
+
getDialect() {
|
|
2280
|
+
if (!this.dialect) {
|
|
2281
|
+
this.dialect = new PgDialect(this.dialectConfig);
|
|
2282
|
+
}
|
|
2283
|
+
return this.dialect;
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2286
|
+
|
|
2287
|
+
//# sourceMappingURL=query-builder.js.map
|
|
2288
|
+
;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/pg-core/query-builders/update.js
|
|
2289
|
+
|
|
2290
|
+
|
|
2291
|
+
|
|
2292
|
+
|
|
2293
|
+
|
|
2294
|
+
|
|
2295
|
+
|
|
2296
|
+
|
|
2297
|
+
|
|
2298
|
+
class PgUpdateBuilder {
|
|
2299
|
+
constructor(table, session, dialect, withList) {
|
|
2300
|
+
this.table = table;
|
|
2301
|
+
this.session = session;
|
|
2302
|
+
this.dialect = dialect;
|
|
2303
|
+
this.withList = withList;
|
|
2304
|
+
}
|
|
2305
|
+
static [entity/* entityKind */.i] = "PgUpdateBuilder";
|
|
2306
|
+
authToken;
|
|
2307
|
+
setToken(token) {
|
|
2308
|
+
this.authToken = token;
|
|
2309
|
+
return this;
|
|
2310
|
+
}
|
|
2311
|
+
set(values) {
|
|
2312
|
+
return this.authToken === void 0 ? new PgUpdateBase(
|
|
2313
|
+
this.table,
|
|
2314
|
+
(0,utils/* mapUpdateSet */.q)(this.table, values),
|
|
2315
|
+
this.session,
|
|
2316
|
+
this.dialect,
|
|
2317
|
+
this.withList
|
|
2318
|
+
) : new PgUpdateBase(
|
|
2319
|
+
this.table,
|
|
2320
|
+
(0,utils/* mapUpdateSet */.q)(this.table, values),
|
|
2321
|
+
this.session,
|
|
2322
|
+
this.dialect,
|
|
2323
|
+
this.withList
|
|
2324
|
+
).setToken(this.authToken);
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
class PgUpdateBase extends query_promise/* QueryPromise */.k {
|
|
2328
|
+
constructor(table, set, session, dialect, withList) {
|
|
2329
|
+
super();
|
|
2330
|
+
this.session = session;
|
|
2331
|
+
this.dialect = dialect;
|
|
2332
|
+
this.config = { set, table, withList, joins: [] };
|
|
2333
|
+
this.tableName = (0,utils/* getTableLikeName */.zN)(table);
|
|
2334
|
+
this.joinsNotNullableMap = typeof this.tableName === "string" ? { [this.tableName]: true } : {};
|
|
2335
|
+
}
|
|
2336
|
+
static [entity/* entityKind */.i] = "PgUpdate";
|
|
2337
|
+
config;
|
|
2338
|
+
tableName;
|
|
2339
|
+
joinsNotNullableMap;
|
|
2340
|
+
from(source) {
|
|
2341
|
+
const tableName = (0,utils/* getTableLikeName */.zN)(source);
|
|
2342
|
+
if (typeof tableName === "string") {
|
|
2343
|
+
this.joinsNotNullableMap[tableName] = true;
|
|
2344
|
+
}
|
|
2345
|
+
this.config.from = source;
|
|
2346
|
+
return this;
|
|
2347
|
+
}
|
|
2348
|
+
getTableLikeFields(table) {
|
|
2349
|
+
if ((0,entity.is)(table, pg_core_table/* PgTable */.mu)) {
|
|
2350
|
+
return table[drizzle_orm_table/* Table */.XI.Symbol.Columns];
|
|
2351
|
+
} else if ((0,entity.is)(table, subquery/* Subquery */.n)) {
|
|
2352
|
+
return table._.selectedFields;
|
|
2353
|
+
}
|
|
2354
|
+
return table[view_common/* ViewBaseConfig */.n].selectedFields;
|
|
2355
|
+
}
|
|
2356
|
+
createJoin(joinType) {
|
|
2357
|
+
return (table, on) => {
|
|
2358
|
+
const tableName = (0,utils/* getTableLikeName */.zN)(table);
|
|
2359
|
+
if (typeof tableName === "string" && this.config.joins.some((join) => join.alias === tableName)) {
|
|
2360
|
+
throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
2361
|
+
}
|
|
2362
|
+
if (typeof on === "function") {
|
|
2363
|
+
const from = this.config.from && !(0,entity.is)(this.config.from, sql/* SQL */.Xs) ? this.getTableLikeFields(this.config.from) : void 0;
|
|
2364
|
+
on = on(
|
|
2365
|
+
new Proxy(
|
|
2366
|
+
this.config.table[drizzle_orm_table/* Table */.XI.Symbol.Columns],
|
|
2367
|
+
new selection_proxy/* SelectionProxyHandler */.b({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
|
2368
|
+
),
|
|
2369
|
+
from && new Proxy(
|
|
2370
|
+
from,
|
|
2371
|
+
new selection_proxy/* SelectionProxyHandler */.b({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
|
2372
|
+
)
|
|
2373
|
+
);
|
|
2374
|
+
}
|
|
2375
|
+
this.config.joins.push({ on, table, joinType, alias: tableName });
|
|
2376
|
+
if (typeof tableName === "string") {
|
|
2377
|
+
switch (joinType) {
|
|
2378
|
+
case "left": {
|
|
2379
|
+
this.joinsNotNullableMap[tableName] = false;
|
|
2380
|
+
break;
|
|
2381
|
+
}
|
|
2382
|
+
case "right": {
|
|
2383
|
+
this.joinsNotNullableMap = Object.fromEntries(
|
|
2384
|
+
Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false])
|
|
2385
|
+
);
|
|
2386
|
+
this.joinsNotNullableMap[tableName] = true;
|
|
2387
|
+
break;
|
|
2388
|
+
}
|
|
2389
|
+
case "inner": {
|
|
2390
|
+
this.joinsNotNullableMap[tableName] = true;
|
|
2391
|
+
break;
|
|
2392
|
+
}
|
|
2393
|
+
case "full": {
|
|
2394
|
+
this.joinsNotNullableMap = Object.fromEntries(
|
|
2395
|
+
Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false])
|
|
2396
|
+
);
|
|
2397
|
+
this.joinsNotNullableMap[tableName] = false;
|
|
2398
|
+
break;
|
|
2399
|
+
}
|
|
2400
|
+
}
|
|
2401
|
+
}
|
|
2402
|
+
return this;
|
|
2403
|
+
};
|
|
2404
|
+
}
|
|
2405
|
+
leftJoin = this.createJoin("left");
|
|
2406
|
+
rightJoin = this.createJoin("right");
|
|
2407
|
+
innerJoin = this.createJoin("inner");
|
|
2408
|
+
fullJoin = this.createJoin("full");
|
|
2409
|
+
/**
|
|
2410
|
+
* Adds a 'where' clause to the query.
|
|
2411
|
+
*
|
|
2412
|
+
* Calling this method will update only those rows that fulfill a specified condition.
|
|
2413
|
+
*
|
|
2414
|
+
* See docs: {@link https://orm.drizzle.team/docs/update}
|
|
2415
|
+
*
|
|
2416
|
+
* @param where the 'where' clause.
|
|
2417
|
+
*
|
|
2418
|
+
* @example
|
|
2419
|
+
* You can use conditional operators and `sql function` to filter the rows to be updated.
|
|
2420
|
+
*
|
|
2421
|
+
* ```ts
|
|
2422
|
+
* // Update all cars with green color
|
|
2423
|
+
* await db.update(cars).set({ color: 'red' })
|
|
2424
|
+
* .where(eq(cars.color, 'green'));
|
|
2425
|
+
* // or
|
|
2426
|
+
* await db.update(cars).set({ color: 'red' })
|
|
2427
|
+
* .where(sql`${cars.color} = 'green'`)
|
|
2428
|
+
* ```
|
|
2429
|
+
*
|
|
2430
|
+
* You can logically combine conditional operators with `and()` and `or()` operators:
|
|
2431
|
+
*
|
|
2432
|
+
* ```ts
|
|
2433
|
+
* // Update all BMW cars with a green color
|
|
2434
|
+
* await db.update(cars).set({ color: 'red' })
|
|
2435
|
+
* .where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
|
2436
|
+
*
|
|
2437
|
+
* // Update all cars with the green or blue color
|
|
2438
|
+
* await db.update(cars).set({ color: 'red' })
|
|
2439
|
+
* .where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
|
2440
|
+
* ```
|
|
2441
|
+
*/
|
|
2442
|
+
where(where) {
|
|
2443
|
+
this.config.where = where;
|
|
2444
|
+
return this;
|
|
2445
|
+
}
|
|
2446
|
+
returning(fields) {
|
|
2447
|
+
if (!fields) {
|
|
2448
|
+
fields = Object.assign({}, this.config.table[drizzle_orm_table/* Table */.XI.Symbol.Columns]);
|
|
2449
|
+
if (this.config.from) {
|
|
2450
|
+
const tableName = (0,utils/* getTableLikeName */.zN)(this.config.from);
|
|
2451
|
+
if (typeof tableName === "string" && this.config.from && !(0,entity.is)(this.config.from, sql/* SQL */.Xs)) {
|
|
2452
|
+
const fromFields = this.getTableLikeFields(this.config.from);
|
|
2453
|
+
fields[tableName] = fromFields;
|
|
2454
|
+
}
|
|
2455
|
+
for (const join of this.config.joins) {
|
|
2456
|
+
const tableName2 = (0,utils/* getTableLikeName */.zN)(join.table);
|
|
2457
|
+
if (typeof tableName2 === "string" && !(0,entity.is)(join.table, sql/* SQL */.Xs)) {
|
|
2458
|
+
const fromFields = this.getTableLikeFields(join.table);
|
|
2459
|
+
fields[tableName2] = fromFields;
|
|
2460
|
+
}
|
|
2461
|
+
}
|
|
2462
|
+
}
|
|
2463
|
+
}
|
|
2464
|
+
this.config.returning = (0,utils/* orderSelectedFields */.He)(fields);
|
|
2465
|
+
return this;
|
|
2466
|
+
}
|
|
2467
|
+
/** @internal */
|
|
2468
|
+
getSQL() {
|
|
2469
|
+
return this.dialect.buildUpdateQuery(this.config);
|
|
2470
|
+
}
|
|
2471
|
+
toSQL() {
|
|
2472
|
+
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
|
2473
|
+
return rest;
|
|
2474
|
+
}
|
|
2475
|
+
/** @internal */
|
|
2476
|
+
_prepare(name) {
|
|
2477
|
+
const query = this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), this.config.returning, name, true);
|
|
2478
|
+
query.joinsNotNullableMap = this.joinsNotNullableMap;
|
|
2479
|
+
return query;
|
|
2480
|
+
}
|
|
2481
|
+
prepare(name) {
|
|
2482
|
+
return this._prepare(name);
|
|
2483
|
+
}
|
|
2484
|
+
authToken;
|
|
2485
|
+
/** @internal */
|
|
2486
|
+
setToken(token) {
|
|
2487
|
+
this.authToken = token;
|
|
2488
|
+
return this;
|
|
2489
|
+
}
|
|
2490
|
+
execute = (placeholderValues) => {
|
|
2491
|
+
return this._prepare().execute(placeholderValues, this.authToken);
|
|
2492
|
+
};
|
|
2493
|
+
$dynamic() {
|
|
2494
|
+
return this;
|
|
2495
|
+
}
|
|
2496
|
+
}
|
|
2497
|
+
|
|
2498
|
+
//# sourceMappingURL=update.js.map
|
|
2499
|
+
;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/pg-core/query-builders/insert.js
|
|
2500
|
+
|
|
2501
|
+
|
|
2502
|
+
|
|
2503
|
+
|
|
2504
|
+
|
|
2505
|
+
|
|
2506
|
+
|
|
2507
|
+
class PgInsertBuilder {
|
|
2508
|
+
constructor(table, session, dialect, withList, overridingSystemValue_) {
|
|
2509
|
+
this.table = table;
|
|
2510
|
+
this.session = session;
|
|
2511
|
+
this.dialect = dialect;
|
|
2512
|
+
this.withList = withList;
|
|
2513
|
+
this.overridingSystemValue_ = overridingSystemValue_;
|
|
2514
|
+
}
|
|
2515
|
+
static [entity/* entityKind */.i] = "PgInsertBuilder";
|
|
2516
|
+
authToken;
|
|
2517
|
+
/** @internal */
|
|
2518
|
+
setToken(token) {
|
|
2519
|
+
this.authToken = token;
|
|
2520
|
+
return this;
|
|
2521
|
+
}
|
|
2522
|
+
overridingSystemValue() {
|
|
2523
|
+
this.overridingSystemValue_ = true;
|
|
2524
|
+
return this;
|
|
2525
|
+
}
|
|
2526
|
+
values(values) {
|
|
2527
|
+
values = Array.isArray(values) ? values : [values];
|
|
2528
|
+
if (values.length === 0) {
|
|
2529
|
+
throw new Error("values() must be called with at least one value");
|
|
2530
|
+
}
|
|
2531
|
+
const mappedValues = values.map((entry) => {
|
|
2532
|
+
const result = {};
|
|
2533
|
+
const cols = this.table[drizzle_orm_table/* Table */.XI.Symbol.Columns];
|
|
2534
|
+
for (const colKey of Object.keys(entry)) {
|
|
2535
|
+
const colValue = entry[colKey];
|
|
2536
|
+
result[colKey] = (0,entity.is)(colValue, sql/* SQL */.Xs) ? colValue : new sql/* Param */.Iw(colValue, cols[colKey]);
|
|
2537
|
+
}
|
|
2538
|
+
return result;
|
|
2539
|
+
});
|
|
2540
|
+
return this.authToken === void 0 ? new PgInsertBase(
|
|
2541
|
+
this.table,
|
|
2542
|
+
mappedValues,
|
|
2543
|
+
this.session,
|
|
2544
|
+
this.dialect,
|
|
2545
|
+
this.withList,
|
|
2546
|
+
false,
|
|
2547
|
+
this.overridingSystemValue_
|
|
2548
|
+
) : new PgInsertBase(
|
|
2549
|
+
this.table,
|
|
2550
|
+
mappedValues,
|
|
2551
|
+
this.session,
|
|
2552
|
+
this.dialect,
|
|
2553
|
+
this.withList,
|
|
2554
|
+
false,
|
|
2555
|
+
this.overridingSystemValue_
|
|
2556
|
+
).setToken(this.authToken);
|
|
2557
|
+
}
|
|
2558
|
+
select(selectQuery) {
|
|
2559
|
+
const select = typeof selectQuery === "function" ? selectQuery(new QueryBuilder()) : selectQuery;
|
|
2560
|
+
if (!(0,entity.is)(select, sql/* SQL */.Xs) && !(0,utils/* haveSameKeys */.DV)(this.table[drizzle_orm_table/* Columns */.e], select._.selectedFields)) {
|
|
2561
|
+
throw new Error(
|
|
2562
|
+
"Insert select error: selected fields are not the same or are in a different order compared to the table definition"
|
|
2563
|
+
);
|
|
2564
|
+
}
|
|
2565
|
+
return new PgInsertBase(this.table, select, this.session, this.dialect, this.withList, true);
|
|
2566
|
+
}
|
|
2567
|
+
}
|
|
2568
|
+
class PgInsertBase extends query_promise/* QueryPromise */.k {
|
|
2569
|
+
constructor(table, values, session, dialect, withList, select, overridingSystemValue_) {
|
|
2570
|
+
super();
|
|
2571
|
+
this.session = session;
|
|
2572
|
+
this.dialect = dialect;
|
|
2573
|
+
this.config = { table, values, withList, select, overridingSystemValue_ };
|
|
2574
|
+
}
|
|
2575
|
+
static [entity/* entityKind */.i] = "PgInsert";
|
|
2576
|
+
config;
|
|
2577
|
+
returning(fields = this.config.table[drizzle_orm_table/* Table */.XI.Symbol.Columns]) {
|
|
2578
|
+
this.config.returning = (0,utils/* orderSelectedFields */.He)(fields);
|
|
2579
|
+
return this;
|
|
2580
|
+
}
|
|
2581
|
+
/**
|
|
2582
|
+
* Adds an `on conflict do nothing` clause to the query.
|
|
2583
|
+
*
|
|
2584
|
+
* Calling this method simply avoids inserting a row as its alternative action.
|
|
2585
|
+
*
|
|
2586
|
+
* See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
|
|
2587
|
+
*
|
|
2588
|
+
* @param config The `target` and `where` clauses.
|
|
2589
|
+
*
|
|
2590
|
+
* @example
|
|
2591
|
+
* ```ts
|
|
2592
|
+
* // Insert one row and cancel the insert if there's a conflict
|
|
2593
|
+
* await db.insert(cars)
|
|
2594
|
+
* .values({ id: 1, brand: 'BMW' })
|
|
2595
|
+
* .onConflictDoNothing();
|
|
2596
|
+
*
|
|
2597
|
+
* // Explicitly specify conflict target
|
|
2598
|
+
* await db.insert(cars)
|
|
2599
|
+
* .values({ id: 1, brand: 'BMW' })
|
|
2600
|
+
* .onConflictDoNothing({ target: cars.id });
|
|
2601
|
+
* ```
|
|
2602
|
+
*/
|
|
2603
|
+
onConflictDoNothing(config = {}) {
|
|
2604
|
+
if (config.target === void 0) {
|
|
2605
|
+
this.config.onConflict = (0,sql/* sql */.ll)`do nothing`;
|
|
2606
|
+
} else {
|
|
2607
|
+
let targetColumn = "";
|
|
2608
|
+
targetColumn = Array.isArray(config.target) ? config.target.map((it) => this.dialect.escapeName(this.dialect.casing.getColumnCasing(it))).join(",") : this.dialect.escapeName(this.dialect.casing.getColumnCasing(config.target));
|
|
2609
|
+
const whereSql = config.where ? (0,sql/* sql */.ll)` where ${config.where}` : void 0;
|
|
2610
|
+
this.config.onConflict = (0,sql/* sql */.ll)`(${sql/* sql */.ll.raw(targetColumn)})${whereSql} do nothing`;
|
|
2611
|
+
}
|
|
2612
|
+
return this;
|
|
2613
|
+
}
|
|
2614
|
+
/**
|
|
2615
|
+
* Adds an `on conflict do update` clause to the query.
|
|
2616
|
+
*
|
|
2617
|
+
* Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
|
|
2618
|
+
*
|
|
2619
|
+
* See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
|
|
2620
|
+
*
|
|
2621
|
+
* @param config The `target`, `set` and `where` clauses.
|
|
2622
|
+
*
|
|
2623
|
+
* @example
|
|
2624
|
+
* ```ts
|
|
2625
|
+
* // Update the row if there's a conflict
|
|
2626
|
+
* await db.insert(cars)
|
|
2627
|
+
* .values({ id: 1, brand: 'BMW' })
|
|
2628
|
+
* .onConflictDoUpdate({
|
|
2629
|
+
* target: cars.id,
|
|
2630
|
+
* set: { brand: 'Porsche' }
|
|
2631
|
+
* });
|
|
2632
|
+
*
|
|
2633
|
+
* // Upsert with 'where' clause
|
|
2634
|
+
* await db.insert(cars)
|
|
2635
|
+
* .values({ id: 1, brand: 'BMW' })
|
|
2636
|
+
* .onConflictDoUpdate({
|
|
2637
|
+
* target: cars.id,
|
|
2638
|
+
* set: { brand: 'newBMW' },
|
|
2639
|
+
* targetWhere: sql`${cars.createdAt} > '2023-01-01'::date`,
|
|
2640
|
+
* });
|
|
2641
|
+
* ```
|
|
2642
|
+
*/
|
|
2643
|
+
onConflictDoUpdate(config) {
|
|
2644
|
+
if (config.where && (config.targetWhere || config.setWhere)) {
|
|
2645
|
+
throw new Error(
|
|
2646
|
+
'You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.'
|
|
2647
|
+
);
|
|
2648
|
+
}
|
|
2649
|
+
const whereSql = config.where ? (0,sql/* sql */.ll)` where ${config.where}` : void 0;
|
|
2650
|
+
const targetWhereSql = config.targetWhere ? (0,sql/* sql */.ll)` where ${config.targetWhere}` : void 0;
|
|
2651
|
+
const setWhereSql = config.setWhere ? (0,sql/* sql */.ll)` where ${config.setWhere}` : void 0;
|
|
2652
|
+
const setSql = this.dialect.buildUpdateSet(this.config.table, (0,utils/* mapUpdateSet */.q)(this.config.table, config.set));
|
|
2653
|
+
let targetColumn = "";
|
|
2654
|
+
targetColumn = Array.isArray(config.target) ? config.target.map((it) => this.dialect.escapeName(this.dialect.casing.getColumnCasing(it))).join(",") : this.dialect.escapeName(this.dialect.casing.getColumnCasing(config.target));
|
|
2655
|
+
this.config.onConflict = (0,sql/* sql */.ll)`(${sql/* sql */.ll.raw(targetColumn)})${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`;
|
|
2656
|
+
return this;
|
|
2657
|
+
}
|
|
2658
|
+
/** @internal */
|
|
2659
|
+
getSQL() {
|
|
2660
|
+
return this.dialect.buildInsertQuery(this.config);
|
|
2661
|
+
}
|
|
2662
|
+
toSQL() {
|
|
2663
|
+
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
|
2664
|
+
return rest;
|
|
2665
|
+
}
|
|
2666
|
+
/** @internal */
|
|
2667
|
+
_prepare(name) {
|
|
2668
|
+
return tracing/* tracer */.k.startActiveSpan("drizzle.prepareQuery", () => {
|
|
2669
|
+
return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), this.config.returning, name, true);
|
|
2670
|
+
});
|
|
2671
|
+
}
|
|
2672
|
+
prepare(name) {
|
|
2673
|
+
return this._prepare(name);
|
|
2674
|
+
}
|
|
2675
|
+
authToken;
|
|
2676
|
+
/** @internal */
|
|
2677
|
+
setToken(token) {
|
|
2678
|
+
this.authToken = token;
|
|
2679
|
+
return this;
|
|
2680
|
+
}
|
|
2681
|
+
execute = (placeholderValues) => {
|
|
2682
|
+
return tracing/* tracer */.k.startActiveSpan("drizzle.operation", () => {
|
|
2683
|
+
return this._prepare().execute(placeholderValues, this.authToken);
|
|
2684
|
+
});
|
|
2685
|
+
};
|
|
2686
|
+
$dynamic() {
|
|
2687
|
+
return this;
|
|
2688
|
+
}
|
|
2689
|
+
}
|
|
2690
|
+
|
|
2691
|
+
//# sourceMappingURL=insert.js.map
|
|
2692
|
+
;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/pg-core/query-builders/delete.js
|
|
2693
|
+
|
|
2694
|
+
|
|
2695
|
+
|
|
2696
|
+
|
|
2697
|
+
|
|
2698
|
+
class PgDeleteBase extends query_promise/* QueryPromise */.k {
|
|
2699
|
+
constructor(table, session, dialect, withList) {
|
|
2700
|
+
super();
|
|
2701
|
+
this.session = session;
|
|
2702
|
+
this.dialect = dialect;
|
|
2703
|
+
this.config = { table, withList };
|
|
2704
|
+
}
|
|
2705
|
+
static [entity/* entityKind */.i] = "PgDelete";
|
|
2706
|
+
config;
|
|
2707
|
+
/**
|
|
2708
|
+
* Adds a `where` clause to the query.
|
|
2709
|
+
*
|
|
2710
|
+
* Calling this method will delete only those rows that fulfill a specified condition.
|
|
2711
|
+
*
|
|
2712
|
+
* See docs: {@link https://orm.drizzle.team/docs/delete}
|
|
2713
|
+
*
|
|
2714
|
+
* @param where the `where` clause.
|
|
2715
|
+
*
|
|
2716
|
+
* @example
|
|
2717
|
+
* You can use conditional operators and `sql function` to filter the rows to be deleted.
|
|
2718
|
+
*
|
|
2719
|
+
* ```ts
|
|
2720
|
+
* // Delete all cars with green color
|
|
2721
|
+
* await db.delete(cars).where(eq(cars.color, 'green'));
|
|
2722
|
+
* // or
|
|
2723
|
+
* await db.delete(cars).where(sql`${cars.color} = 'green'`)
|
|
2724
|
+
* ```
|
|
2725
|
+
*
|
|
2726
|
+
* You can logically combine conditional operators with `and()` and `or()` operators:
|
|
2727
|
+
*
|
|
2728
|
+
* ```ts
|
|
2729
|
+
* // Delete all BMW cars with a green color
|
|
2730
|
+
* await db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
|
2731
|
+
*
|
|
2732
|
+
* // Delete all cars with the green or blue color
|
|
2733
|
+
* await db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
|
2734
|
+
* ```
|
|
2735
|
+
*/
|
|
2736
|
+
where(where) {
|
|
2737
|
+
this.config.where = where;
|
|
2738
|
+
return this;
|
|
2739
|
+
}
|
|
2740
|
+
returning(fields = this.config.table[drizzle_orm_table/* Table */.XI.Symbol.Columns]) {
|
|
2741
|
+
this.config.returning = (0,utils/* orderSelectedFields */.He)(fields);
|
|
2742
|
+
return this;
|
|
2743
|
+
}
|
|
2744
|
+
/** @internal */
|
|
2745
|
+
getSQL() {
|
|
2746
|
+
return this.dialect.buildDeleteQuery(this.config);
|
|
2747
|
+
}
|
|
2748
|
+
toSQL() {
|
|
2749
|
+
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
|
2750
|
+
return rest;
|
|
2751
|
+
}
|
|
2752
|
+
/** @internal */
|
|
2753
|
+
_prepare(name) {
|
|
2754
|
+
return tracing/* tracer */.k.startActiveSpan("drizzle.prepareQuery", () => {
|
|
2755
|
+
return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), this.config.returning, name, true);
|
|
2756
|
+
});
|
|
2757
|
+
}
|
|
2758
|
+
prepare(name) {
|
|
2759
|
+
return this._prepare(name);
|
|
2760
|
+
}
|
|
2761
|
+
authToken;
|
|
2762
|
+
/** @internal */
|
|
2763
|
+
setToken(token) {
|
|
2764
|
+
this.authToken = token;
|
|
2765
|
+
return this;
|
|
2766
|
+
}
|
|
2767
|
+
execute = (placeholderValues) => {
|
|
2768
|
+
return tracing/* tracer */.k.startActiveSpan("drizzle.operation", () => {
|
|
2769
|
+
return this._prepare().execute(placeholderValues, this.authToken);
|
|
2770
|
+
});
|
|
2771
|
+
};
|
|
2772
|
+
$dynamic() {
|
|
2773
|
+
return this;
|
|
2774
|
+
}
|
|
2775
|
+
}
|
|
2776
|
+
|
|
2777
|
+
//# sourceMappingURL=delete.js.map
|
|
2778
|
+
;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/pg-core/query-builders/count.js
|
|
2779
|
+
|
|
2780
|
+
|
|
2781
|
+
class PgCountBuilder extends sql/* SQL */.Xs {
|
|
2782
|
+
constructor(params) {
|
|
2783
|
+
super(PgCountBuilder.buildEmbeddedCount(params.source, params.filters).queryChunks);
|
|
2784
|
+
this.params = params;
|
|
2785
|
+
this.mapWith(Number);
|
|
2786
|
+
this.session = params.session;
|
|
2787
|
+
this.sql = PgCountBuilder.buildCount(
|
|
2788
|
+
params.source,
|
|
2789
|
+
params.filters
|
|
2790
|
+
);
|
|
2791
|
+
}
|
|
2792
|
+
sql;
|
|
2793
|
+
token;
|
|
2794
|
+
static [entity/* entityKind */.i] = "PgCountBuilder";
|
|
2795
|
+
[Symbol.toStringTag] = "PgCountBuilder";
|
|
2796
|
+
session;
|
|
2797
|
+
static buildEmbeddedCount(source, filters) {
|
|
2798
|
+
return (0,sql/* sql */.ll)`(select count(*) from ${source}${sql/* sql */.ll.raw(" where ").if(filters)}${filters})`;
|
|
2799
|
+
}
|
|
2800
|
+
static buildCount(source, filters) {
|
|
2801
|
+
return (0,sql/* sql */.ll)`select count(*) as count from ${source}${sql/* sql */.ll.raw(" where ").if(filters)}${filters};`;
|
|
2802
|
+
}
|
|
2803
|
+
/** @intrnal */
|
|
2804
|
+
setToken(token) {
|
|
2805
|
+
this.token = token;
|
|
2806
|
+
}
|
|
2807
|
+
then(onfulfilled, onrejected) {
|
|
2808
|
+
return Promise.resolve(this.session.count(this.sql, this.token)).then(
|
|
2809
|
+
onfulfilled,
|
|
2810
|
+
onrejected
|
|
2811
|
+
);
|
|
2812
|
+
}
|
|
2813
|
+
catch(onRejected) {
|
|
2814
|
+
return this.then(void 0, onRejected);
|
|
2815
|
+
}
|
|
2816
|
+
finally(onFinally) {
|
|
2817
|
+
return this.then(
|
|
2818
|
+
(value) => {
|
|
2819
|
+
onFinally?.();
|
|
2820
|
+
return value;
|
|
2821
|
+
},
|
|
2822
|
+
(reason) => {
|
|
2823
|
+
onFinally?.();
|
|
2824
|
+
throw reason;
|
|
2825
|
+
}
|
|
2826
|
+
);
|
|
2827
|
+
}
|
|
2828
|
+
}
|
|
2829
|
+
|
|
2830
|
+
//# sourceMappingURL=count.js.map
|
|
2831
|
+
;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/pg-core/query-builders/query.js
|
|
2832
|
+
|
|
2833
|
+
|
|
2834
|
+
|
|
2835
|
+
|
|
2836
|
+
class RelationalQueryBuilder {
|
|
2837
|
+
constructor(fullSchema, schema, tableNamesMap, table, tableConfig, dialect, session) {
|
|
2838
|
+
this.fullSchema = fullSchema;
|
|
2839
|
+
this.schema = schema;
|
|
2840
|
+
this.tableNamesMap = tableNamesMap;
|
|
2841
|
+
this.table = table;
|
|
2842
|
+
this.tableConfig = tableConfig;
|
|
2843
|
+
this.dialect = dialect;
|
|
2844
|
+
this.session = session;
|
|
2845
|
+
}
|
|
2846
|
+
static [entity/* entityKind */.i] = "PgRelationalQueryBuilder";
|
|
2847
|
+
findMany(config) {
|
|
2848
|
+
return new PgRelationalQuery(
|
|
2849
|
+
this.fullSchema,
|
|
2850
|
+
this.schema,
|
|
2851
|
+
this.tableNamesMap,
|
|
2852
|
+
this.table,
|
|
2853
|
+
this.tableConfig,
|
|
2854
|
+
this.dialect,
|
|
2855
|
+
this.session,
|
|
2856
|
+
config ? config : {},
|
|
2857
|
+
"many"
|
|
2858
|
+
);
|
|
2859
|
+
}
|
|
2860
|
+
findFirst(config) {
|
|
2861
|
+
return new PgRelationalQuery(
|
|
2862
|
+
this.fullSchema,
|
|
2863
|
+
this.schema,
|
|
2864
|
+
this.tableNamesMap,
|
|
2865
|
+
this.table,
|
|
2866
|
+
this.tableConfig,
|
|
2867
|
+
this.dialect,
|
|
2868
|
+
this.session,
|
|
2869
|
+
config ? { ...config, limit: 1 } : { limit: 1 },
|
|
2870
|
+
"first"
|
|
2871
|
+
);
|
|
2872
|
+
}
|
|
2873
|
+
}
|
|
2874
|
+
class PgRelationalQuery extends query_promise/* QueryPromise */.k {
|
|
2875
|
+
constructor(fullSchema, schema, tableNamesMap, table, tableConfig, dialect, session, config, mode) {
|
|
2876
|
+
super();
|
|
2877
|
+
this.fullSchema = fullSchema;
|
|
2878
|
+
this.schema = schema;
|
|
2879
|
+
this.tableNamesMap = tableNamesMap;
|
|
2880
|
+
this.table = table;
|
|
2881
|
+
this.tableConfig = tableConfig;
|
|
2882
|
+
this.dialect = dialect;
|
|
2883
|
+
this.session = session;
|
|
2884
|
+
this.config = config;
|
|
2885
|
+
this.mode = mode;
|
|
2886
|
+
}
|
|
2887
|
+
static [entity/* entityKind */.i] = "PgRelationalQuery";
|
|
2888
|
+
/** @internal */
|
|
2889
|
+
_prepare(name) {
|
|
2890
|
+
return tracing/* tracer */.k.startActiveSpan("drizzle.prepareQuery", () => {
|
|
2891
|
+
const { query, builtQuery } = this._toSQL();
|
|
2892
|
+
return this.session.prepareQuery(
|
|
2893
|
+
builtQuery,
|
|
2894
|
+
void 0,
|
|
2895
|
+
name,
|
|
2896
|
+
true,
|
|
2897
|
+
(rawRows, mapColumnValue) => {
|
|
2898
|
+
const rows = rawRows.map(
|
|
2899
|
+
(row) => (0,relations/* mapRelationalRow */.I$)(this.schema, this.tableConfig, row, query.selection, mapColumnValue)
|
|
2900
|
+
);
|
|
2901
|
+
if (this.mode === "first") {
|
|
2902
|
+
return rows[0];
|
|
2903
|
+
}
|
|
2904
|
+
return rows;
|
|
2905
|
+
}
|
|
2906
|
+
);
|
|
2907
|
+
});
|
|
2908
|
+
}
|
|
2909
|
+
prepare(name) {
|
|
2910
|
+
return this._prepare(name);
|
|
2911
|
+
}
|
|
2912
|
+
_getQuery() {
|
|
2913
|
+
return this.dialect.buildRelationalQueryWithoutPK({
|
|
2914
|
+
fullSchema: this.fullSchema,
|
|
2915
|
+
schema: this.schema,
|
|
2916
|
+
tableNamesMap: this.tableNamesMap,
|
|
2917
|
+
table: this.table,
|
|
2918
|
+
tableConfig: this.tableConfig,
|
|
2919
|
+
queryConfig: this.config,
|
|
2920
|
+
tableAlias: this.tableConfig.tsName
|
|
2921
|
+
});
|
|
2922
|
+
}
|
|
2923
|
+
/** @internal */
|
|
2924
|
+
getSQL() {
|
|
2925
|
+
return this._getQuery().sql;
|
|
2926
|
+
}
|
|
2927
|
+
_toSQL() {
|
|
2928
|
+
const query = this._getQuery();
|
|
2929
|
+
const builtQuery = this.dialect.sqlToQuery(query.sql);
|
|
2930
|
+
return { query, builtQuery };
|
|
2931
|
+
}
|
|
2932
|
+
toSQL() {
|
|
2933
|
+
return this._toSQL().builtQuery;
|
|
2934
|
+
}
|
|
2935
|
+
authToken;
|
|
2936
|
+
/** @internal */
|
|
2937
|
+
setToken(token) {
|
|
2938
|
+
this.authToken = token;
|
|
2939
|
+
return this;
|
|
2940
|
+
}
|
|
2941
|
+
execute() {
|
|
2942
|
+
return tracing/* tracer */.k.startActiveSpan("drizzle.operation", () => {
|
|
2943
|
+
return this._prepare().execute(void 0, this.authToken);
|
|
2944
|
+
});
|
|
2945
|
+
}
|
|
2946
|
+
}
|
|
2947
|
+
|
|
2948
|
+
//# sourceMappingURL=query.js.map
|
|
2949
|
+
;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/pg-core/query-builders/raw.js
|
|
2950
|
+
|
|
2951
|
+
|
|
2952
|
+
class PgRaw extends query_promise/* QueryPromise */.k {
|
|
2953
|
+
constructor(execute, sql, query, mapBatchResult) {
|
|
2954
|
+
super();
|
|
2955
|
+
this.execute = execute;
|
|
2956
|
+
this.sql = sql;
|
|
2957
|
+
this.query = query;
|
|
2958
|
+
this.mapBatchResult = mapBatchResult;
|
|
2959
|
+
}
|
|
2960
|
+
static [entity/* entityKind */.i] = "PgRaw";
|
|
2961
|
+
/** @internal */
|
|
2962
|
+
getSQL() {
|
|
2963
|
+
return this.sql;
|
|
2964
|
+
}
|
|
2965
|
+
getQuery() {
|
|
2966
|
+
return this.query;
|
|
2967
|
+
}
|
|
2968
|
+
mapResult(result, isFromBatch) {
|
|
2969
|
+
return isFromBatch ? this.mapBatchResult(result) : result;
|
|
2970
|
+
}
|
|
2971
|
+
_prepare() {
|
|
2972
|
+
return this;
|
|
2973
|
+
}
|
|
2974
|
+
/** @internal */
|
|
2975
|
+
isResponseInArrayMode() {
|
|
2976
|
+
return false;
|
|
2977
|
+
}
|
|
2978
|
+
}
|
|
2979
|
+
|
|
2980
|
+
//# sourceMappingURL=raw.js.map
|
|
2981
|
+
;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/pg-core/query-builders/refresh-materialized-view.js
|
|
2982
|
+
|
|
2983
|
+
|
|
2984
|
+
|
|
2985
|
+
class PgRefreshMaterializedView extends query_promise/* QueryPromise */.k {
|
|
2986
|
+
constructor(view, session, dialect) {
|
|
2987
|
+
super();
|
|
2988
|
+
this.session = session;
|
|
2989
|
+
this.dialect = dialect;
|
|
2990
|
+
this.config = { view };
|
|
2991
|
+
}
|
|
2992
|
+
static [entity/* entityKind */.i] = "PgRefreshMaterializedView";
|
|
2993
|
+
config;
|
|
2994
|
+
concurrently() {
|
|
2995
|
+
if (this.config.withNoData !== void 0) {
|
|
2996
|
+
throw new Error("Cannot use concurrently and withNoData together");
|
|
2997
|
+
}
|
|
2998
|
+
this.config.concurrently = true;
|
|
2999
|
+
return this;
|
|
3000
|
+
}
|
|
3001
|
+
withNoData() {
|
|
3002
|
+
if (this.config.concurrently !== void 0) {
|
|
3003
|
+
throw new Error("Cannot use concurrently and withNoData together");
|
|
3004
|
+
}
|
|
3005
|
+
this.config.withNoData = true;
|
|
3006
|
+
return this;
|
|
3007
|
+
}
|
|
3008
|
+
/** @internal */
|
|
3009
|
+
getSQL() {
|
|
3010
|
+
return this.dialect.buildRefreshMaterializedViewQuery(this.config);
|
|
3011
|
+
}
|
|
3012
|
+
toSQL() {
|
|
3013
|
+
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
|
3014
|
+
return rest;
|
|
3015
|
+
}
|
|
3016
|
+
/** @internal */
|
|
3017
|
+
_prepare(name) {
|
|
3018
|
+
return tracing/* tracer */.k.startActiveSpan("drizzle.prepareQuery", () => {
|
|
3019
|
+
return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), void 0, name, true);
|
|
3020
|
+
});
|
|
3021
|
+
}
|
|
3022
|
+
prepare(name) {
|
|
3023
|
+
return this._prepare(name);
|
|
3024
|
+
}
|
|
3025
|
+
authToken;
|
|
3026
|
+
/** @internal */
|
|
3027
|
+
setToken(token) {
|
|
3028
|
+
this.authToken = token;
|
|
3029
|
+
return this;
|
|
3030
|
+
}
|
|
3031
|
+
execute = (placeholderValues) => {
|
|
3032
|
+
return tracing/* tracer */.k.startActiveSpan("drizzle.operation", () => {
|
|
3033
|
+
return this._prepare().execute(placeholderValues, this.authToken);
|
|
3034
|
+
});
|
|
3035
|
+
};
|
|
3036
|
+
}
|
|
3037
|
+
|
|
3038
|
+
//# sourceMappingURL=refresh-materialized-view.js.map
|
|
3039
|
+
;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/pg-core/db.js
|
|
3040
|
+
|
|
3041
|
+
|
|
3042
|
+
|
|
3043
|
+
|
|
3044
|
+
|
|
3045
|
+
|
|
3046
|
+
|
|
3047
|
+
|
|
3048
|
+
|
|
3049
|
+
class PgDatabase {
|
|
3050
|
+
constructor(dialect, session, schema) {
|
|
3051
|
+
this.dialect = dialect;
|
|
3052
|
+
this.session = session;
|
|
3053
|
+
this._ = schema ? {
|
|
3054
|
+
schema: schema.schema,
|
|
3055
|
+
fullSchema: schema.fullSchema,
|
|
3056
|
+
tableNamesMap: schema.tableNamesMap,
|
|
3057
|
+
session
|
|
3058
|
+
} : {
|
|
3059
|
+
schema: void 0,
|
|
3060
|
+
fullSchema: {},
|
|
3061
|
+
tableNamesMap: {},
|
|
3062
|
+
session
|
|
3063
|
+
};
|
|
3064
|
+
this.query = {};
|
|
3065
|
+
if (this._.schema) {
|
|
3066
|
+
for (const [tableName, columns] of Object.entries(this._.schema)) {
|
|
3067
|
+
this.query[tableName] = new RelationalQueryBuilder(
|
|
3068
|
+
schema.fullSchema,
|
|
3069
|
+
this._.schema,
|
|
3070
|
+
this._.tableNamesMap,
|
|
3071
|
+
schema.fullSchema[tableName],
|
|
3072
|
+
columns,
|
|
3073
|
+
dialect,
|
|
3074
|
+
session
|
|
3075
|
+
);
|
|
3076
|
+
}
|
|
3077
|
+
}
|
|
3078
|
+
}
|
|
3079
|
+
static [entity/* entityKind */.i] = "PgDatabase";
|
|
3080
|
+
query;
|
|
3081
|
+
/**
|
|
3082
|
+
* Creates a subquery that defines a temporary named result set as a CTE.
|
|
3083
|
+
*
|
|
3084
|
+
* It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
|
|
3085
|
+
*
|
|
3086
|
+
* See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
|
|
3087
|
+
*
|
|
3088
|
+
* @param alias The alias for the subquery.
|
|
3089
|
+
*
|
|
3090
|
+
* Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
|
|
3091
|
+
*
|
|
3092
|
+
* @example
|
|
3093
|
+
*
|
|
3094
|
+
* ```ts
|
|
3095
|
+
* // Create a subquery with alias 'sq' and use it in the select query
|
|
3096
|
+
* const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
|
|
3097
|
+
*
|
|
3098
|
+
* const result = await db.with(sq).select().from(sq);
|
|
3099
|
+
* ```
|
|
3100
|
+
*
|
|
3101
|
+
* 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:
|
|
3102
|
+
*
|
|
3103
|
+
* ```ts
|
|
3104
|
+
* // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
|
|
3105
|
+
* const sq = db.$with('sq').as(db.select({
|
|
3106
|
+
* name: sql<string>`upper(${users.name})`.as('name'),
|
|
3107
|
+
* })
|
|
3108
|
+
* .from(users));
|
|
3109
|
+
*
|
|
3110
|
+
* const result = await db.with(sq).select({ name: sq.name }).from(sq);
|
|
3111
|
+
* ```
|
|
3112
|
+
*/
|
|
3113
|
+
$with(alias) {
|
|
3114
|
+
const self = this;
|
|
3115
|
+
return {
|
|
3116
|
+
as(qb) {
|
|
3117
|
+
if (typeof qb === "function") {
|
|
3118
|
+
qb = qb(new QueryBuilder(self.dialect));
|
|
3119
|
+
}
|
|
3120
|
+
return new Proxy(
|
|
3121
|
+
new subquery/* WithSubquery */.J(qb.getSQL(), qb.getSelectedFields(), alias, true),
|
|
3122
|
+
new selection_proxy/* SelectionProxyHandler */.b({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
|
|
3123
|
+
);
|
|
3124
|
+
}
|
|
3125
|
+
};
|
|
3126
|
+
}
|
|
3127
|
+
$count(source, filters) {
|
|
3128
|
+
return new PgCountBuilder({ source, filters, session: this.session });
|
|
3129
|
+
}
|
|
3130
|
+
/**
|
|
3131
|
+
* Incorporates a previously defined CTE (using `$with`) into the main query.
|
|
3132
|
+
*
|
|
3133
|
+
* This method allows the main query to reference a temporary named result set.
|
|
3134
|
+
*
|
|
3135
|
+
* See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
|
|
3136
|
+
*
|
|
3137
|
+
* @param queries The CTEs to incorporate into the main query.
|
|
3138
|
+
*
|
|
3139
|
+
* @example
|
|
3140
|
+
*
|
|
3141
|
+
* ```ts
|
|
3142
|
+
* // Define a subquery 'sq' as a CTE using $with
|
|
3143
|
+
* const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
|
|
3144
|
+
*
|
|
3145
|
+
* // Incorporate the CTE 'sq' into the main query and select from it
|
|
3146
|
+
* const result = await db.with(sq).select().from(sq);
|
|
3147
|
+
* ```
|
|
3148
|
+
*/
|
|
3149
|
+
with(...queries) {
|
|
3150
|
+
const self = this;
|
|
3151
|
+
function select(fields) {
|
|
3152
|
+
return new PgSelectBuilder({
|
|
3153
|
+
fields: fields ?? void 0,
|
|
3154
|
+
session: self.session,
|
|
3155
|
+
dialect: self.dialect,
|
|
3156
|
+
withList: queries
|
|
3157
|
+
});
|
|
3158
|
+
}
|
|
3159
|
+
function selectDistinct(fields) {
|
|
3160
|
+
return new PgSelectBuilder({
|
|
3161
|
+
fields: fields ?? void 0,
|
|
3162
|
+
session: self.session,
|
|
3163
|
+
dialect: self.dialect,
|
|
3164
|
+
withList: queries,
|
|
3165
|
+
distinct: true
|
|
3166
|
+
});
|
|
3167
|
+
}
|
|
3168
|
+
function selectDistinctOn(on, fields) {
|
|
3169
|
+
return new PgSelectBuilder({
|
|
3170
|
+
fields: fields ?? void 0,
|
|
3171
|
+
session: self.session,
|
|
3172
|
+
dialect: self.dialect,
|
|
3173
|
+
withList: queries,
|
|
3174
|
+
distinct: { on }
|
|
3175
|
+
});
|
|
3176
|
+
}
|
|
3177
|
+
function update(table) {
|
|
3178
|
+
return new PgUpdateBuilder(table, self.session, self.dialect, queries);
|
|
3179
|
+
}
|
|
3180
|
+
function insert(table) {
|
|
3181
|
+
return new PgInsertBuilder(table, self.session, self.dialect, queries);
|
|
3182
|
+
}
|
|
3183
|
+
function delete_(table) {
|
|
3184
|
+
return new PgDeleteBase(table, self.session, self.dialect, queries);
|
|
3185
|
+
}
|
|
3186
|
+
return { select, selectDistinct, selectDistinctOn, update, insert, delete: delete_ };
|
|
3187
|
+
}
|
|
3188
|
+
select(fields) {
|
|
3189
|
+
return new PgSelectBuilder({
|
|
3190
|
+
fields: fields ?? void 0,
|
|
3191
|
+
session: this.session,
|
|
3192
|
+
dialect: this.dialect
|
|
3193
|
+
});
|
|
3194
|
+
}
|
|
3195
|
+
selectDistinct(fields) {
|
|
3196
|
+
return new PgSelectBuilder({
|
|
3197
|
+
fields: fields ?? void 0,
|
|
3198
|
+
session: this.session,
|
|
3199
|
+
dialect: this.dialect,
|
|
3200
|
+
distinct: true
|
|
3201
|
+
});
|
|
3202
|
+
}
|
|
3203
|
+
selectDistinctOn(on, fields) {
|
|
3204
|
+
return new PgSelectBuilder({
|
|
3205
|
+
fields: fields ?? void 0,
|
|
3206
|
+
session: this.session,
|
|
3207
|
+
dialect: this.dialect,
|
|
3208
|
+
distinct: { on }
|
|
3209
|
+
});
|
|
3210
|
+
}
|
|
3211
|
+
/**
|
|
3212
|
+
* Creates an update query.
|
|
3213
|
+
*
|
|
3214
|
+
* Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.
|
|
3215
|
+
*
|
|
3216
|
+
* Use `.set()` method to specify which values to update.
|
|
3217
|
+
*
|
|
3218
|
+
* See docs: {@link https://orm.drizzle.team/docs/update}
|
|
3219
|
+
*
|
|
3220
|
+
* @param table The table to update.
|
|
3221
|
+
*
|
|
3222
|
+
* @example
|
|
3223
|
+
*
|
|
3224
|
+
* ```ts
|
|
3225
|
+
* // Update all rows in the 'cars' table
|
|
3226
|
+
* await db.update(cars).set({ color: 'red' });
|
|
3227
|
+
*
|
|
3228
|
+
* // Update rows with filters and conditions
|
|
3229
|
+
* await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));
|
|
3230
|
+
*
|
|
3231
|
+
* // Update with returning clause
|
|
3232
|
+
* const updatedCar: Car[] = await db.update(cars)
|
|
3233
|
+
* .set({ color: 'red' })
|
|
3234
|
+
* .where(eq(cars.id, 1))
|
|
3235
|
+
* .returning();
|
|
3236
|
+
* ```
|
|
3237
|
+
*/
|
|
3238
|
+
update(table) {
|
|
3239
|
+
return new PgUpdateBuilder(table, this.session, this.dialect);
|
|
3240
|
+
}
|
|
3241
|
+
/**
|
|
3242
|
+
* Creates an insert query.
|
|
3243
|
+
*
|
|
3244
|
+
* Calling this method will create new rows in a table. Use `.values()` method to specify which values to insert.
|
|
3245
|
+
*
|
|
3246
|
+
* See docs: {@link https://orm.drizzle.team/docs/insert}
|
|
3247
|
+
*
|
|
3248
|
+
* @param table The table to insert into.
|
|
3249
|
+
*
|
|
3250
|
+
* @example
|
|
3251
|
+
*
|
|
3252
|
+
* ```ts
|
|
3253
|
+
* // Insert one row
|
|
3254
|
+
* await db.insert(cars).values({ brand: 'BMW' });
|
|
3255
|
+
*
|
|
3256
|
+
* // Insert multiple rows
|
|
3257
|
+
* await db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);
|
|
3258
|
+
*
|
|
3259
|
+
* // Insert with returning clause
|
|
3260
|
+
* const insertedCar: Car[] = await db.insert(cars)
|
|
3261
|
+
* .values({ brand: 'BMW' })
|
|
3262
|
+
* .returning();
|
|
3263
|
+
* ```
|
|
3264
|
+
*/
|
|
3265
|
+
insert(table) {
|
|
3266
|
+
return new PgInsertBuilder(table, this.session, this.dialect);
|
|
3267
|
+
}
|
|
3268
|
+
/**
|
|
3269
|
+
* Creates a delete query.
|
|
3270
|
+
*
|
|
3271
|
+
* Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.
|
|
3272
|
+
*
|
|
3273
|
+
* See docs: {@link https://orm.drizzle.team/docs/delete}
|
|
3274
|
+
*
|
|
3275
|
+
* @param table The table to delete from.
|
|
3276
|
+
*
|
|
3277
|
+
* @example
|
|
3278
|
+
*
|
|
3279
|
+
* ```ts
|
|
3280
|
+
* // Delete all rows in the 'cars' table
|
|
3281
|
+
* await db.delete(cars);
|
|
3282
|
+
*
|
|
3283
|
+
* // Delete rows with filters and conditions
|
|
3284
|
+
* await db.delete(cars).where(eq(cars.color, 'green'));
|
|
3285
|
+
*
|
|
3286
|
+
* // Delete with returning clause
|
|
3287
|
+
* const deletedCar: Car[] = await db.delete(cars)
|
|
3288
|
+
* .where(eq(cars.id, 1))
|
|
3289
|
+
* .returning();
|
|
3290
|
+
* ```
|
|
3291
|
+
*/
|
|
3292
|
+
delete(table) {
|
|
3293
|
+
return new PgDeleteBase(table, this.session, this.dialect);
|
|
3294
|
+
}
|
|
3295
|
+
refreshMaterializedView(view) {
|
|
3296
|
+
return new PgRefreshMaterializedView(view, this.session, this.dialect);
|
|
3297
|
+
}
|
|
3298
|
+
authToken;
|
|
3299
|
+
execute(query) {
|
|
3300
|
+
const sequel = typeof query === "string" ? sql/* sql */.ll.raw(query) : query.getSQL();
|
|
3301
|
+
const builtQuery = this.dialect.sqlToQuery(sequel);
|
|
3302
|
+
const prepared = this.session.prepareQuery(
|
|
3303
|
+
builtQuery,
|
|
3304
|
+
void 0,
|
|
3305
|
+
void 0,
|
|
3306
|
+
false
|
|
3307
|
+
);
|
|
3308
|
+
return new PgRaw(
|
|
3309
|
+
() => prepared.execute(void 0, this.authToken),
|
|
3310
|
+
sequel,
|
|
3311
|
+
builtQuery,
|
|
3312
|
+
(result) => prepared.mapResult(result, true)
|
|
3313
|
+
);
|
|
3314
|
+
}
|
|
3315
|
+
transaction(transaction, config) {
|
|
3316
|
+
return this.session.transaction(transaction, config);
|
|
3317
|
+
}
|
|
3318
|
+
}
|
|
3319
|
+
const withReplicas = (primary, replicas, getReplica = () => replicas[Math.floor(Math.random() * replicas.length)]) => {
|
|
3320
|
+
const select = (...args) => getReplica(replicas).select(...args);
|
|
3321
|
+
const selectDistinct = (...args) => getReplica(replicas).selectDistinct(...args);
|
|
3322
|
+
const selectDistinctOn = (...args) => getReplica(replicas).selectDistinctOn(...args);
|
|
3323
|
+
const $with = (...args) => getReplica(replicas).with(...args);
|
|
3324
|
+
const update = (...args) => primary.update(...args);
|
|
3325
|
+
const insert = (...args) => primary.insert(...args);
|
|
3326
|
+
const $delete = (...args) => primary.delete(...args);
|
|
3327
|
+
const execute = (...args) => primary.execute(...args);
|
|
3328
|
+
const transaction = (...args) => primary.transaction(...args);
|
|
3329
|
+
const refreshMaterializedView = (...args) => primary.refreshMaterializedView(...args);
|
|
3330
|
+
return {
|
|
3331
|
+
...primary,
|
|
3332
|
+
update,
|
|
3333
|
+
insert,
|
|
3334
|
+
delete: $delete,
|
|
3335
|
+
execute,
|
|
3336
|
+
transaction,
|
|
3337
|
+
refreshMaterializedView,
|
|
3338
|
+
$primary: primary,
|
|
3339
|
+
select,
|
|
3340
|
+
selectDistinct,
|
|
3341
|
+
selectDistinctOn,
|
|
3342
|
+
with: $with,
|
|
3343
|
+
get query() {
|
|
3344
|
+
return getReplica(replicas).query;
|
|
3345
|
+
}
|
|
3346
|
+
};
|
|
3347
|
+
};
|
|
3348
|
+
|
|
3349
|
+
//# sourceMappingURL=db.js.map
|
|
3350
|
+
;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/pg-core/session.js
|
|
3351
|
+
|
|
3352
|
+
|
|
3353
|
+
|
|
3354
|
+
|
|
3355
|
+
|
|
3356
|
+
class PgPreparedQuery {
|
|
3357
|
+
constructor(query) {
|
|
3358
|
+
this.query = query;
|
|
3359
|
+
}
|
|
3360
|
+
authToken;
|
|
3361
|
+
getQuery() {
|
|
3362
|
+
return this.query;
|
|
3363
|
+
}
|
|
3364
|
+
mapResult(response, _isFromBatch) {
|
|
3365
|
+
return response;
|
|
3366
|
+
}
|
|
3367
|
+
/** @internal */
|
|
3368
|
+
setToken(token) {
|
|
3369
|
+
this.authToken = token;
|
|
3370
|
+
return this;
|
|
3371
|
+
}
|
|
3372
|
+
static [entity/* entityKind */.i] = "PgPreparedQuery";
|
|
3373
|
+
/** @internal */
|
|
3374
|
+
joinsNotNullableMap;
|
|
3375
|
+
}
|
|
3376
|
+
class PgSession {
|
|
3377
|
+
constructor(dialect) {
|
|
3378
|
+
this.dialect = dialect;
|
|
3379
|
+
}
|
|
3380
|
+
static [entity/* entityKind */.i] = "PgSession";
|
|
3381
|
+
/** @internal */
|
|
3382
|
+
execute(query, token) {
|
|
3383
|
+
return tracing/* tracer */.k.startActiveSpan("drizzle.operation", () => {
|
|
3384
|
+
const prepared = tracing/* tracer */.k.startActiveSpan("drizzle.prepareQuery", () => {
|
|
3385
|
+
return this.prepareQuery(
|
|
3386
|
+
this.dialect.sqlToQuery(query),
|
|
3387
|
+
void 0,
|
|
3388
|
+
void 0,
|
|
3389
|
+
false
|
|
3390
|
+
);
|
|
3391
|
+
});
|
|
3392
|
+
return prepared.setToken(token).execute(void 0, token);
|
|
3393
|
+
});
|
|
3394
|
+
}
|
|
3395
|
+
all(query) {
|
|
3396
|
+
return this.prepareQuery(
|
|
3397
|
+
this.dialect.sqlToQuery(query),
|
|
3398
|
+
void 0,
|
|
3399
|
+
void 0,
|
|
3400
|
+
false
|
|
3401
|
+
).all();
|
|
3402
|
+
}
|
|
3403
|
+
/** @internal */
|
|
3404
|
+
async count(sql2, token) {
|
|
3405
|
+
const res = await this.execute(sql2, token);
|
|
3406
|
+
return Number(
|
|
3407
|
+
res[0]["count"]
|
|
3408
|
+
);
|
|
3409
|
+
}
|
|
3410
|
+
}
|
|
3411
|
+
class PgTransaction extends PgDatabase {
|
|
3412
|
+
constructor(dialect, session, schema, nestedIndex = 0) {
|
|
3413
|
+
super(dialect, session, schema);
|
|
3414
|
+
this.schema = schema;
|
|
3415
|
+
this.nestedIndex = nestedIndex;
|
|
3416
|
+
}
|
|
3417
|
+
static [entity/* entityKind */.i] = "PgTransaction";
|
|
3418
|
+
rollback() {
|
|
3419
|
+
throw new errors/* TransactionRollbackError */.j();
|
|
3420
|
+
}
|
|
3421
|
+
/** @internal */
|
|
3422
|
+
getTransactionConfigSQL(config) {
|
|
3423
|
+
const chunks = [];
|
|
3424
|
+
if (config.isolationLevel) {
|
|
3425
|
+
chunks.push(`isolation level ${config.isolationLevel}`);
|
|
3426
|
+
}
|
|
3427
|
+
if (config.accessMode) {
|
|
3428
|
+
chunks.push(config.accessMode);
|
|
3429
|
+
}
|
|
3430
|
+
if (typeof config.deferrable === "boolean") {
|
|
3431
|
+
chunks.push(config.deferrable ? "deferrable" : "not deferrable");
|
|
3432
|
+
}
|
|
3433
|
+
return sql/* sql */.ll.raw(chunks.join(" "));
|
|
3434
|
+
}
|
|
3435
|
+
setTransaction(config) {
|
|
3436
|
+
return this.session.execute((0,sql/* sql */.ll)`set transaction ${this.getTransactionConfigSQL(config)}`);
|
|
3437
|
+
}
|
|
3438
|
+
}
|
|
3439
|
+
|
|
3440
|
+
//# sourceMappingURL=session.js.map
|
|
3441
|
+
;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/postgres-js/session.js
|
|
3442
|
+
|
|
3443
|
+
|
|
3444
|
+
|
|
3445
|
+
|
|
3446
|
+
|
|
3447
|
+
|
|
3448
|
+
|
|
3449
|
+
class PostgresJsPreparedQuery extends PgPreparedQuery {
|
|
3450
|
+
constructor(client, queryString, params, logger, fields, _isResponseInArrayMode, customResultMapper) {
|
|
3451
|
+
super({ sql: queryString, params });
|
|
3452
|
+
this.client = client;
|
|
3453
|
+
this.queryString = queryString;
|
|
3454
|
+
this.params = params;
|
|
3455
|
+
this.logger = logger;
|
|
3456
|
+
this.fields = fields;
|
|
3457
|
+
this._isResponseInArrayMode = _isResponseInArrayMode;
|
|
3458
|
+
this.customResultMapper = customResultMapper;
|
|
3459
|
+
}
|
|
3460
|
+
static [entity/* entityKind */.i] = "PostgresJsPreparedQuery";
|
|
3461
|
+
async execute(placeholderValues = {}) {
|
|
3462
|
+
return tracing/* tracer */.k.startActiveSpan("drizzle.execute", async (span) => {
|
|
3463
|
+
const params = (0,sql/* fillPlaceholders */.Ct)(this.params, placeholderValues);
|
|
3464
|
+
span?.setAttributes({
|
|
3465
|
+
"drizzle.query.text": this.queryString,
|
|
3466
|
+
"drizzle.query.params": JSON.stringify(params)
|
|
3467
|
+
});
|
|
3468
|
+
this.logger.logQuery(this.queryString, params);
|
|
3469
|
+
const { fields, queryString: query, client, joinsNotNullableMap, customResultMapper } = this;
|
|
3470
|
+
if (!fields && !customResultMapper) {
|
|
3471
|
+
return tracing/* tracer */.k.startActiveSpan("drizzle.driver.execute", () => {
|
|
3472
|
+
return client.unsafe(query, params);
|
|
3473
|
+
});
|
|
3474
|
+
}
|
|
3475
|
+
const rows = await tracing/* tracer */.k.startActiveSpan("drizzle.driver.execute", () => {
|
|
3476
|
+
span?.setAttributes({
|
|
3477
|
+
"drizzle.query.text": query,
|
|
3478
|
+
"drizzle.query.params": JSON.stringify(params)
|
|
3479
|
+
});
|
|
3480
|
+
return client.unsafe(query, params).values();
|
|
3481
|
+
});
|
|
3482
|
+
return tracing/* tracer */.k.startActiveSpan("drizzle.mapResponse", () => {
|
|
3483
|
+
return customResultMapper ? customResultMapper(rows) : rows.map((row) => (0,utils/* mapResultRow */.a6)(fields, row, joinsNotNullableMap));
|
|
3484
|
+
});
|
|
3485
|
+
});
|
|
3486
|
+
}
|
|
3487
|
+
all(placeholderValues = {}) {
|
|
3488
|
+
return tracing/* tracer */.k.startActiveSpan("drizzle.execute", async (span) => {
|
|
3489
|
+
const params = (0,sql/* fillPlaceholders */.Ct)(this.params, placeholderValues);
|
|
3490
|
+
span?.setAttributes({
|
|
3491
|
+
"drizzle.query.text": this.queryString,
|
|
3492
|
+
"drizzle.query.params": JSON.stringify(params)
|
|
3493
|
+
});
|
|
3494
|
+
this.logger.logQuery(this.queryString, params);
|
|
3495
|
+
return tracing/* tracer */.k.startActiveSpan("drizzle.driver.execute", () => {
|
|
3496
|
+
span?.setAttributes({
|
|
3497
|
+
"drizzle.query.text": this.queryString,
|
|
3498
|
+
"drizzle.query.params": JSON.stringify(params)
|
|
3499
|
+
});
|
|
3500
|
+
return this.client.unsafe(this.queryString, params);
|
|
3501
|
+
});
|
|
3502
|
+
});
|
|
3503
|
+
}
|
|
3504
|
+
/** @internal */
|
|
3505
|
+
isResponseInArrayMode() {
|
|
3506
|
+
return this._isResponseInArrayMode;
|
|
3507
|
+
}
|
|
3508
|
+
}
|
|
3509
|
+
class PostgresJsSession extends PgSession {
|
|
3510
|
+
constructor(client, dialect, schema, options = {}) {
|
|
3511
|
+
super(dialect);
|
|
3512
|
+
this.client = client;
|
|
3513
|
+
this.schema = schema;
|
|
3514
|
+
this.options = options;
|
|
3515
|
+
this.logger = options.logger ?? new drizzle_orm_logger/* NoopLogger */.Pv();
|
|
3516
|
+
}
|
|
3517
|
+
static [entity/* entityKind */.i] = "PostgresJsSession";
|
|
3518
|
+
logger;
|
|
3519
|
+
prepareQuery(query, fields, name, isResponseInArrayMode, customResultMapper) {
|
|
3520
|
+
return new PostgresJsPreparedQuery(
|
|
3521
|
+
this.client,
|
|
3522
|
+
query.sql,
|
|
3523
|
+
query.params,
|
|
3524
|
+
this.logger,
|
|
3525
|
+
fields,
|
|
3526
|
+
isResponseInArrayMode,
|
|
3527
|
+
customResultMapper
|
|
3528
|
+
);
|
|
3529
|
+
}
|
|
3530
|
+
query(query, params) {
|
|
3531
|
+
this.logger.logQuery(query, params);
|
|
3532
|
+
return this.client.unsafe(query, params).values();
|
|
3533
|
+
}
|
|
3534
|
+
queryObjects(query, params) {
|
|
3535
|
+
return this.client.unsafe(query, params);
|
|
3536
|
+
}
|
|
3537
|
+
transaction(transaction, config) {
|
|
3538
|
+
return this.client.begin(async (client) => {
|
|
3539
|
+
const session = new PostgresJsSession(
|
|
3540
|
+
client,
|
|
3541
|
+
this.dialect,
|
|
3542
|
+
this.schema,
|
|
3543
|
+
this.options
|
|
3544
|
+
);
|
|
3545
|
+
const tx = new PostgresJsTransaction(this.dialect, session, this.schema);
|
|
3546
|
+
if (config) {
|
|
3547
|
+
await tx.setTransaction(config);
|
|
3548
|
+
}
|
|
3549
|
+
return transaction(tx);
|
|
3550
|
+
});
|
|
3551
|
+
}
|
|
3552
|
+
}
|
|
3553
|
+
class PostgresJsTransaction extends PgTransaction {
|
|
3554
|
+
constructor(dialect, session, schema, nestedIndex = 0) {
|
|
3555
|
+
super(dialect, session, schema, nestedIndex);
|
|
3556
|
+
this.session = session;
|
|
3557
|
+
}
|
|
3558
|
+
static [entity/* entityKind */.i] = "PostgresJsTransaction";
|
|
3559
|
+
transaction(transaction) {
|
|
3560
|
+
return this.session.client.savepoint((client) => {
|
|
3561
|
+
const session = new PostgresJsSession(
|
|
3562
|
+
client,
|
|
3563
|
+
this.dialect,
|
|
3564
|
+
this.schema,
|
|
3565
|
+
this.session.options
|
|
3566
|
+
);
|
|
3567
|
+
const tx = new PostgresJsTransaction(this.dialect, session, this.schema);
|
|
3568
|
+
return transaction(tx);
|
|
3569
|
+
});
|
|
3570
|
+
}
|
|
3571
|
+
}
|
|
3572
|
+
|
|
3573
|
+
//# sourceMappingURL=session.js.map
|
|
3574
|
+
;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/postgres-js/driver.js
|
|
3575
|
+
|
|
3576
|
+
|
|
3577
|
+
|
|
3578
|
+
|
|
3579
|
+
|
|
3580
|
+
|
|
3581
|
+
|
|
3582
|
+
|
|
3583
|
+
class PostgresJsDatabase extends PgDatabase {
|
|
3584
|
+
static [entity/* entityKind */.i] = "PostgresJsDatabase";
|
|
3585
|
+
}
|
|
3586
|
+
function construct(client, config = {}) {
|
|
3587
|
+
const transparentParser = (val) => val;
|
|
3588
|
+
for (const type of ["1184", "1082", "1083", "1114"]) {
|
|
3589
|
+
client.options.parsers[type] = transparentParser;
|
|
3590
|
+
client.options.serializers[type] = transparentParser;
|
|
3591
|
+
}
|
|
3592
|
+
client.options.serializers["114"] = transparentParser;
|
|
3593
|
+
client.options.serializers["3802"] = transparentParser;
|
|
3594
|
+
const dialect = new PgDialect({ casing: config.casing });
|
|
3595
|
+
let logger;
|
|
3596
|
+
if (config.logger === true) {
|
|
3597
|
+
logger = new drizzle_orm_logger/* DefaultLogger */.w();
|
|
3598
|
+
} else if (config.logger !== false) {
|
|
3599
|
+
logger = config.logger;
|
|
3600
|
+
}
|
|
3601
|
+
let schema;
|
|
3602
|
+
if (config.schema) {
|
|
3603
|
+
const tablesConfig = (0,relations/* extractTablesRelationalConfig */._k)(
|
|
3604
|
+
config.schema,
|
|
3605
|
+
relations/* createTableRelationsHelpers */.DZ
|
|
3606
|
+
);
|
|
3607
|
+
schema = {
|
|
3608
|
+
fullSchema: config.schema,
|
|
3609
|
+
schema: tablesConfig.tables,
|
|
3610
|
+
tableNamesMap: tablesConfig.tableNamesMap
|
|
3611
|
+
};
|
|
3612
|
+
}
|
|
3613
|
+
const session = new PostgresJsSession(client, dialect, schema, { logger });
|
|
3614
|
+
const db = new PostgresJsDatabase(dialect, session, schema);
|
|
3615
|
+
db.$client = client;
|
|
3616
|
+
return db;
|
|
3617
|
+
}
|
|
3618
|
+
function drizzle(...params) {
|
|
3619
|
+
if (typeof params[0] === "string") {
|
|
3620
|
+
const instance = (0,src["default"])(params[0]);
|
|
3621
|
+
return construct(instance, params[1]);
|
|
3622
|
+
}
|
|
3623
|
+
if ((0,utils/* isConfig */.Lq)(params[0])) {
|
|
3624
|
+
const { connection, client, ...drizzleConfig } = params[0];
|
|
3625
|
+
if (client)
|
|
3626
|
+
return construct(client, drizzleConfig);
|
|
3627
|
+
if (typeof connection === "object" && connection.url !== void 0) {
|
|
3628
|
+
const { url, ...config } = connection;
|
|
3629
|
+
const instance2 = (0,src["default"])(url, config);
|
|
3630
|
+
return construct(instance2, drizzleConfig);
|
|
3631
|
+
}
|
|
3632
|
+
const instance = (0,src["default"])(connection);
|
|
3633
|
+
return construct(instance, drizzleConfig);
|
|
3634
|
+
}
|
|
3635
|
+
return construct(params[0], params[1]);
|
|
3636
|
+
}
|
|
3637
|
+
((drizzle2) => {
|
|
3638
|
+
function mock(config) {
|
|
3639
|
+
return construct({}, config);
|
|
3640
|
+
}
|
|
3641
|
+
drizzle2.mock = mock;
|
|
3642
|
+
})(drizzle || (drizzle = {}));
|
|
3643
|
+
|
|
3644
|
+
//# sourceMappingURL=driver.js.map
|
|
3645
|
+
;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/postgres-js/index.js
|
|
3646
|
+
|
|
3647
|
+
|
|
3648
|
+
//# sourceMappingURL=index.js.map
|
|
3649
|
+
|
|
3650
|
+
/***/ }),
|
|
3651
|
+
|
|
3652
|
+
/***/ 6685:
|
|
3653
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
3654
|
+
|
|
3655
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
3656
|
+
/* harmony export */ O: () => (/* binding */ TypedQueryBuilder)
|
|
3657
|
+
/* harmony export */ });
|
|
3658
|
+
/* harmony import */ var _entity_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9724);
|
|
3659
|
+
|
|
3660
|
+
class TypedQueryBuilder {
|
|
3661
|
+
static [_entity_js__WEBPACK_IMPORTED_MODULE_0__/* .entityKind */ .i] = "TypedQueryBuilder";
|
|
3662
|
+
/** @internal */
|
|
3663
|
+
getSelectedFields() {
|
|
3664
|
+
return this._.selectedFields;
|
|
3665
|
+
}
|
|
3666
|
+
}
|
|
3667
|
+
|
|
3668
|
+
//# sourceMappingURL=query-builder.js.map
|
|
3669
|
+
|
|
3670
|
+
/***/ }),
|
|
3671
|
+
|
|
3672
|
+
/***/ 4579:
|
|
3673
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
3674
|
+
|
|
3675
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
3676
|
+
/* harmony export */ k: () => (/* binding */ QueryPromise)
|
|
3677
|
+
/* harmony export */ });
|
|
3678
|
+
/* harmony import */ var _entity_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9724);
|
|
3679
|
+
|
|
3680
|
+
class QueryPromise {
|
|
3681
|
+
static [_entity_js__WEBPACK_IMPORTED_MODULE_0__/* .entityKind */ .i] = "QueryPromise";
|
|
3682
|
+
[Symbol.toStringTag] = "QueryPromise";
|
|
3683
|
+
catch(onRejected) {
|
|
3684
|
+
return this.then(void 0, onRejected);
|
|
3685
|
+
}
|
|
3686
|
+
finally(onFinally) {
|
|
3687
|
+
return this.then(
|
|
3688
|
+
(value) => {
|
|
3689
|
+
onFinally?.();
|
|
3690
|
+
return value;
|
|
3691
|
+
},
|
|
3692
|
+
(reason) => {
|
|
3693
|
+
onFinally?.();
|
|
3694
|
+
throw reason;
|
|
3695
|
+
}
|
|
3696
|
+
);
|
|
3697
|
+
}
|
|
3698
|
+
then(onFulfilled, onRejected) {
|
|
3699
|
+
return this.execute().then(onFulfilled, onRejected);
|
|
3700
|
+
}
|
|
3701
|
+
}
|
|
3702
|
+
|
|
3703
|
+
//# sourceMappingURL=query-promise.js.map
|
|
3704
|
+
|
|
3705
|
+
/***/ }),
|
|
3706
|
+
|
|
3707
|
+
/***/ 4750:
|
|
3708
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
3709
|
+
|
|
3710
|
+
|
|
3711
|
+
// EXPORTS
|
|
3712
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
3713
|
+
iv: () => (/* binding */ Many),
|
|
3714
|
+
pD: () => (/* binding */ One),
|
|
3715
|
+
DZ: () => (/* binding */ createTableRelationsHelpers),
|
|
3716
|
+
_k: () => (/* binding */ extractTablesRelationalConfig),
|
|
3717
|
+
mm: () => (/* binding */ getOperators),
|
|
3718
|
+
rl: () => (/* binding */ getOrderByOperators),
|
|
3719
|
+
I$: () => (/* binding */ mapRelationalRow),
|
|
3720
|
+
W0: () => (/* binding */ normalizeRelation)
|
|
3721
|
+
});
|
|
3722
|
+
|
|
3723
|
+
// UNUSED EXPORTS: Relation, Relations, createMany, createOne, relations
|
|
3724
|
+
|
|
3725
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/table.js
|
|
3726
|
+
var table = __webpack_require__(8407);
|
|
3727
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/column.js
|
|
3728
|
+
var column = __webpack_require__(2345);
|
|
3729
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/entity.js
|
|
3730
|
+
var entity = __webpack_require__(9724);
|
|
3731
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/pg-core/table.js + 22 modules
|
|
3732
|
+
var pg_core_table = __webpack_require__(698);
|
|
3733
|
+
;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/pg-core/primary-keys.js
|
|
3734
|
+
|
|
3735
|
+
|
|
3736
|
+
function primaryKey(...config) {
|
|
3737
|
+
if (config[0].columns) {
|
|
3738
|
+
return new PrimaryKeyBuilder(config[0].columns, config[0].name);
|
|
3739
|
+
}
|
|
3740
|
+
return new PrimaryKeyBuilder(config);
|
|
3741
|
+
}
|
|
3742
|
+
class PrimaryKeyBuilder {
|
|
3743
|
+
static [entity/* entityKind */.i] = "PgPrimaryKeyBuilder";
|
|
3744
|
+
/** @internal */
|
|
3745
|
+
columns;
|
|
3746
|
+
/** @internal */
|
|
3747
|
+
name;
|
|
3748
|
+
constructor(columns, name) {
|
|
3749
|
+
this.columns = columns;
|
|
3750
|
+
this.name = name;
|
|
3751
|
+
}
|
|
3752
|
+
/** @internal */
|
|
3753
|
+
build(table) {
|
|
3754
|
+
return new PrimaryKey(table, this.columns, this.name);
|
|
3755
|
+
}
|
|
3756
|
+
}
|
|
3757
|
+
class PrimaryKey {
|
|
3758
|
+
constructor(table, columns, name) {
|
|
3759
|
+
this.table = table;
|
|
3760
|
+
this.columns = columns;
|
|
3761
|
+
this.name = name;
|
|
3762
|
+
}
|
|
3763
|
+
static [entity/* entityKind */.i] = "PgPrimaryKey";
|
|
3764
|
+
columns;
|
|
3765
|
+
name;
|
|
3766
|
+
getName() {
|
|
3767
|
+
return this.name ?? `${this.table[pg_core_table/* PgTable */.mu.Symbol.Name]}_${this.columns.map((column) => column.name).join("_")}_pk`;
|
|
3768
|
+
}
|
|
3769
|
+
}
|
|
3770
|
+
|
|
3771
|
+
//# sourceMappingURL=primary-keys.js.map
|
|
3772
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/sql/expressions/conditions.js
|
|
3773
|
+
var conditions = __webpack_require__(420);
|
|
3774
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/sql/expressions/select.js
|
|
3775
|
+
var expressions_select = __webpack_require__(7038);
|
|
3776
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/sql/sql.js + 1 modules
|
|
3777
|
+
var sql = __webpack_require__(183);
|
|
3778
|
+
;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/relations.js
|
|
3779
|
+
|
|
3780
|
+
|
|
3781
|
+
|
|
3782
|
+
|
|
3783
|
+
|
|
3784
|
+
|
|
3785
|
+
class Relation {
|
|
3786
|
+
constructor(sourceTable, referencedTable, relationName) {
|
|
3787
|
+
this.sourceTable = sourceTable;
|
|
3788
|
+
this.referencedTable = referencedTable;
|
|
3789
|
+
this.relationName = relationName;
|
|
3790
|
+
this.referencedTableName = referencedTable[table/* Table */.XI.Symbol.Name];
|
|
3791
|
+
}
|
|
3792
|
+
static [entity/* entityKind */.i] = "Relation";
|
|
3793
|
+
referencedTableName;
|
|
3794
|
+
fieldName;
|
|
3795
|
+
}
|
|
3796
|
+
class Relations {
|
|
3797
|
+
constructor(table, config) {
|
|
3798
|
+
this.table = table;
|
|
3799
|
+
this.config = config;
|
|
3800
|
+
}
|
|
3801
|
+
static [entity/* entityKind */.i] = "Relations";
|
|
3802
|
+
}
|
|
3803
|
+
class One extends Relation {
|
|
3804
|
+
constructor(sourceTable, referencedTable, config, isNullable) {
|
|
3805
|
+
super(sourceTable, referencedTable, config?.relationName);
|
|
3806
|
+
this.config = config;
|
|
3807
|
+
this.isNullable = isNullable;
|
|
3808
|
+
}
|
|
3809
|
+
static [entity/* entityKind */.i] = "One";
|
|
3810
|
+
withFieldName(fieldName) {
|
|
3811
|
+
const relation = new One(
|
|
3812
|
+
this.sourceTable,
|
|
3813
|
+
this.referencedTable,
|
|
3814
|
+
this.config,
|
|
3815
|
+
this.isNullable
|
|
3816
|
+
);
|
|
3817
|
+
relation.fieldName = fieldName;
|
|
3818
|
+
return relation;
|
|
3819
|
+
}
|
|
3820
|
+
}
|
|
3821
|
+
class Many extends Relation {
|
|
3822
|
+
constructor(sourceTable, referencedTable, config) {
|
|
3823
|
+
super(sourceTable, referencedTable, config?.relationName);
|
|
3824
|
+
this.config = config;
|
|
3825
|
+
}
|
|
3826
|
+
static [entity/* entityKind */.i] = "Many";
|
|
3827
|
+
withFieldName(fieldName) {
|
|
3828
|
+
const relation = new Many(
|
|
3829
|
+
this.sourceTable,
|
|
3830
|
+
this.referencedTable,
|
|
3831
|
+
this.config
|
|
3832
|
+
);
|
|
3833
|
+
relation.fieldName = fieldName;
|
|
3834
|
+
return relation;
|
|
3835
|
+
}
|
|
3836
|
+
}
|
|
3837
|
+
function getOperators() {
|
|
3838
|
+
return {
|
|
3839
|
+
and: conditions/* and */.Uo,
|
|
3840
|
+
between: conditions/* between */.Tq,
|
|
3841
|
+
eq: conditions.eq,
|
|
3842
|
+
exists: conditions/* exists */.t2,
|
|
3843
|
+
gt: conditions.gt,
|
|
3844
|
+
gte: conditions/* gte */.RO,
|
|
3845
|
+
ilike: conditions/* ilike */.B3,
|
|
3846
|
+
inArray: conditions/* inArray */.RV,
|
|
3847
|
+
isNull: conditions/* isNull */.kZ,
|
|
3848
|
+
isNotNull: conditions/* isNotNull */.Pe,
|
|
3849
|
+
like: conditions/* like */.mj,
|
|
3850
|
+
lt: conditions.lt,
|
|
3851
|
+
lte: conditions/* lte */.wJ,
|
|
3852
|
+
ne: conditions.ne,
|
|
3853
|
+
not: conditions/* not */.AU,
|
|
3854
|
+
notBetween: conditions/* notBetween */.o8,
|
|
3855
|
+
notExists: conditions/* notExists */.KJ,
|
|
3856
|
+
notLike: conditions/* notLike */.RK,
|
|
3857
|
+
notIlike: conditions/* notIlike */.q1,
|
|
3858
|
+
notInArray: conditions/* notInArray */.KL,
|
|
3859
|
+
or: conditions.or,
|
|
3860
|
+
sql: sql/* sql */.ll
|
|
3861
|
+
};
|
|
3862
|
+
}
|
|
3863
|
+
function getOrderByOperators() {
|
|
3864
|
+
return {
|
|
3865
|
+
sql: sql/* sql */.ll,
|
|
3866
|
+
asc: expressions_select/* asc */.Y,
|
|
3867
|
+
desc: expressions_select/* desc */.i
|
|
3868
|
+
};
|
|
3869
|
+
}
|
|
3870
|
+
function extractTablesRelationalConfig(schema, configHelpers) {
|
|
3871
|
+
if (Object.keys(schema).length === 1 && "default" in schema && !(0,entity.is)(schema["default"], table/* Table */.XI)) {
|
|
3872
|
+
schema = schema["default"];
|
|
3873
|
+
}
|
|
3874
|
+
const tableNamesMap = {};
|
|
3875
|
+
const relationsBuffer = {};
|
|
3876
|
+
const tablesConfig = {};
|
|
3877
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
3878
|
+
if ((0,entity.is)(value, table/* Table */.XI)) {
|
|
3879
|
+
const dbName = (0,table/* getTableUniqueName */.Lf)(value);
|
|
3880
|
+
const bufferedRelations = relationsBuffer[dbName];
|
|
3881
|
+
tableNamesMap[dbName] = key;
|
|
3882
|
+
tablesConfig[key] = {
|
|
3883
|
+
tsName: key,
|
|
3884
|
+
dbName: value[table/* Table */.XI.Symbol.Name],
|
|
3885
|
+
schema: value[table/* Table */.XI.Symbol.Schema],
|
|
3886
|
+
columns: value[table/* Table */.XI.Symbol.Columns],
|
|
3887
|
+
relations: bufferedRelations?.relations ?? {},
|
|
3888
|
+
primaryKey: bufferedRelations?.primaryKey ?? []
|
|
3889
|
+
};
|
|
3890
|
+
for (const column of Object.values(
|
|
3891
|
+
value[table/* Table */.XI.Symbol.Columns]
|
|
3892
|
+
)) {
|
|
3893
|
+
if (column.primary) {
|
|
3894
|
+
tablesConfig[key].primaryKey.push(column);
|
|
3895
|
+
}
|
|
3896
|
+
}
|
|
3897
|
+
const extraConfig = value[table/* Table */.XI.Symbol.ExtraConfigBuilder]?.(value[table/* Table */.XI.Symbol.ExtraConfigColumns]);
|
|
3898
|
+
if (extraConfig) {
|
|
3899
|
+
for (const configEntry of Object.values(extraConfig)) {
|
|
3900
|
+
if ((0,entity.is)(configEntry, PrimaryKeyBuilder)) {
|
|
3901
|
+
tablesConfig[key].primaryKey.push(...configEntry.columns);
|
|
3902
|
+
}
|
|
3903
|
+
}
|
|
3904
|
+
}
|
|
3905
|
+
} else if ((0,entity.is)(value, Relations)) {
|
|
3906
|
+
const dbName = (0,table/* getTableUniqueName */.Lf)(value.table);
|
|
3907
|
+
const tableName = tableNamesMap[dbName];
|
|
3908
|
+
const relations2 = value.config(
|
|
3909
|
+
configHelpers(value.table)
|
|
3910
|
+
);
|
|
3911
|
+
let primaryKey;
|
|
3912
|
+
for (const [relationName, relation] of Object.entries(relations2)) {
|
|
3913
|
+
if (tableName) {
|
|
3914
|
+
const tableConfig = tablesConfig[tableName];
|
|
3915
|
+
tableConfig.relations[relationName] = relation;
|
|
3916
|
+
if (primaryKey) {
|
|
3917
|
+
tableConfig.primaryKey.push(...primaryKey);
|
|
3918
|
+
}
|
|
3919
|
+
} else {
|
|
3920
|
+
if (!(dbName in relationsBuffer)) {
|
|
3921
|
+
relationsBuffer[dbName] = {
|
|
3922
|
+
relations: {},
|
|
3923
|
+
primaryKey
|
|
3924
|
+
};
|
|
3925
|
+
}
|
|
3926
|
+
relationsBuffer[dbName].relations[relationName] = relation;
|
|
3927
|
+
}
|
|
3928
|
+
}
|
|
3929
|
+
}
|
|
3930
|
+
}
|
|
3931
|
+
return { tables: tablesConfig, tableNamesMap };
|
|
3932
|
+
}
|
|
3933
|
+
function relations(table, relations2) {
|
|
3934
|
+
return new Relations(
|
|
3935
|
+
table,
|
|
3936
|
+
(helpers) => Object.fromEntries(
|
|
3937
|
+
Object.entries(relations2(helpers)).map(([key, value]) => [
|
|
3938
|
+
key,
|
|
3939
|
+
value.withFieldName(key)
|
|
3940
|
+
])
|
|
3941
|
+
)
|
|
3942
|
+
);
|
|
3943
|
+
}
|
|
3944
|
+
function createOne(sourceTable) {
|
|
3945
|
+
return function one(table, config) {
|
|
3946
|
+
return new One(
|
|
3947
|
+
sourceTable,
|
|
3948
|
+
table,
|
|
3949
|
+
config,
|
|
3950
|
+
config?.fields.reduce((res, f) => res && f.notNull, true) ?? false
|
|
3951
|
+
);
|
|
3952
|
+
};
|
|
3953
|
+
}
|
|
3954
|
+
function createMany(sourceTable) {
|
|
3955
|
+
return function many(referencedTable, config) {
|
|
3956
|
+
return new Many(sourceTable, referencedTable, config);
|
|
3957
|
+
};
|
|
3958
|
+
}
|
|
3959
|
+
function normalizeRelation(schema, tableNamesMap, relation) {
|
|
3960
|
+
if ((0,entity.is)(relation, One) && relation.config) {
|
|
3961
|
+
return {
|
|
3962
|
+
fields: relation.config.fields,
|
|
3963
|
+
references: relation.config.references
|
|
3964
|
+
};
|
|
3965
|
+
}
|
|
3966
|
+
const referencedTableTsName = tableNamesMap[(0,table/* getTableUniqueName */.Lf)(relation.referencedTable)];
|
|
3967
|
+
if (!referencedTableTsName) {
|
|
3968
|
+
throw new Error(
|
|
3969
|
+
`Table "${relation.referencedTable[table/* Table */.XI.Symbol.Name]}" not found in schema`
|
|
3970
|
+
);
|
|
3971
|
+
}
|
|
3972
|
+
const referencedTableConfig = schema[referencedTableTsName];
|
|
3973
|
+
if (!referencedTableConfig) {
|
|
3974
|
+
throw new Error(`Table "${referencedTableTsName}" not found in schema`);
|
|
3975
|
+
}
|
|
3976
|
+
const sourceTable = relation.sourceTable;
|
|
3977
|
+
const sourceTableTsName = tableNamesMap[(0,table/* getTableUniqueName */.Lf)(sourceTable)];
|
|
3978
|
+
if (!sourceTableTsName) {
|
|
3979
|
+
throw new Error(
|
|
3980
|
+
`Table "${sourceTable[table/* Table */.XI.Symbol.Name]}" not found in schema`
|
|
3981
|
+
);
|
|
3982
|
+
}
|
|
3983
|
+
const reverseRelations = [];
|
|
3984
|
+
for (const referencedTableRelation of Object.values(
|
|
3985
|
+
referencedTableConfig.relations
|
|
3986
|
+
)) {
|
|
3987
|
+
if (relation.relationName && relation !== referencedTableRelation && referencedTableRelation.relationName === relation.relationName || !relation.relationName && referencedTableRelation.referencedTable === relation.sourceTable) {
|
|
3988
|
+
reverseRelations.push(referencedTableRelation);
|
|
3989
|
+
}
|
|
3990
|
+
}
|
|
3991
|
+
if (reverseRelations.length > 1) {
|
|
3992
|
+
throw relation.relationName ? new Error(
|
|
3993
|
+
`There are multiple relations with name "${relation.relationName}" in table "${referencedTableTsName}"`
|
|
3994
|
+
) : new Error(
|
|
3995
|
+
`There are multiple relations between "${referencedTableTsName}" and "${relation.sourceTable[table/* Table */.XI.Symbol.Name]}". Please specify relation name`
|
|
3996
|
+
);
|
|
3997
|
+
}
|
|
3998
|
+
if (reverseRelations[0] && (0,entity.is)(reverseRelations[0], One) && reverseRelations[0].config) {
|
|
3999
|
+
return {
|
|
4000
|
+
fields: reverseRelations[0].config.references,
|
|
4001
|
+
references: reverseRelations[0].config.fields
|
|
4002
|
+
};
|
|
4003
|
+
}
|
|
4004
|
+
throw new Error(
|
|
4005
|
+
`There is not enough information to infer relation "${sourceTableTsName}.${relation.fieldName}"`
|
|
4006
|
+
);
|
|
4007
|
+
}
|
|
4008
|
+
function createTableRelationsHelpers(sourceTable) {
|
|
4009
|
+
return {
|
|
4010
|
+
one: createOne(sourceTable),
|
|
4011
|
+
many: createMany(sourceTable)
|
|
4012
|
+
};
|
|
4013
|
+
}
|
|
4014
|
+
function mapRelationalRow(tablesConfig, tableConfig, row, buildQueryResultSelection, mapColumnValue = (value) => value) {
|
|
4015
|
+
const result = {};
|
|
4016
|
+
for (const [
|
|
4017
|
+
selectionItemIndex,
|
|
4018
|
+
selectionItem
|
|
4019
|
+
] of buildQueryResultSelection.entries()) {
|
|
4020
|
+
if (selectionItem.isJson) {
|
|
4021
|
+
const relation = tableConfig.relations[selectionItem.tsKey];
|
|
4022
|
+
const rawSubRows = row[selectionItemIndex];
|
|
4023
|
+
const subRows = typeof rawSubRows === "string" ? JSON.parse(rawSubRows) : rawSubRows;
|
|
4024
|
+
result[selectionItem.tsKey] = (0,entity.is)(relation, One) ? subRows && mapRelationalRow(
|
|
4025
|
+
tablesConfig,
|
|
4026
|
+
tablesConfig[selectionItem.relationTableTsKey],
|
|
4027
|
+
subRows,
|
|
4028
|
+
selectionItem.selection,
|
|
4029
|
+
mapColumnValue
|
|
4030
|
+
) : subRows.map(
|
|
4031
|
+
(subRow) => mapRelationalRow(
|
|
4032
|
+
tablesConfig,
|
|
4033
|
+
tablesConfig[selectionItem.relationTableTsKey],
|
|
4034
|
+
subRow,
|
|
4035
|
+
selectionItem.selection,
|
|
4036
|
+
mapColumnValue
|
|
4037
|
+
)
|
|
4038
|
+
);
|
|
4039
|
+
} else {
|
|
4040
|
+
const value = mapColumnValue(row[selectionItemIndex]);
|
|
4041
|
+
const field = selectionItem.field;
|
|
4042
|
+
let decoder;
|
|
4043
|
+
if ((0,entity.is)(field, column/* Column */.V)) {
|
|
4044
|
+
decoder = field;
|
|
4045
|
+
} else if ((0,entity.is)(field, sql/* SQL */.Xs)) {
|
|
4046
|
+
decoder = field.decoder;
|
|
4047
|
+
} else {
|
|
4048
|
+
decoder = field.sql.decoder;
|
|
4049
|
+
}
|
|
4050
|
+
result[selectionItem.tsKey] = value === null ? null : decoder.mapFromDriverValue(value);
|
|
4051
|
+
}
|
|
4052
|
+
}
|
|
4053
|
+
return result;
|
|
4054
|
+
}
|
|
4055
|
+
|
|
4056
|
+
//# sourceMappingURL=relations.js.map
|
|
4057
|
+
|
|
4058
|
+
/***/ }),
|
|
4059
|
+
|
|
4060
|
+
/***/ 8296:
|
|
4061
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
4062
|
+
|
|
4063
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
4064
|
+
/* harmony export */ b: () => (/* binding */ SelectionProxyHandler)
|
|
4065
|
+
/* harmony export */ });
|
|
4066
|
+
/* harmony import */ var _alias_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(8575);
|
|
4067
|
+
/* harmony import */ var _column_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(2345);
|
|
4068
|
+
/* harmony import */ var _entity_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9724);
|
|
4069
|
+
/* harmony import */ var _sql_sql_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(183);
|
|
4070
|
+
/* harmony import */ var _subquery_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6453);
|
|
4071
|
+
/* harmony import */ var _view_common_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6146);
|
|
4072
|
+
|
|
4073
|
+
|
|
4074
|
+
|
|
4075
|
+
|
|
4076
|
+
|
|
4077
|
+
|
|
4078
|
+
class SelectionProxyHandler {
|
|
4079
|
+
static [_entity_js__WEBPACK_IMPORTED_MODULE_0__/* .entityKind */ .i] = "SelectionProxyHandler";
|
|
4080
|
+
config;
|
|
4081
|
+
constructor(config) {
|
|
4082
|
+
this.config = { ...config };
|
|
4083
|
+
}
|
|
4084
|
+
get(subquery, prop) {
|
|
4085
|
+
if (prop === "_") {
|
|
4086
|
+
return {
|
|
4087
|
+
...subquery["_"],
|
|
4088
|
+
selectedFields: new Proxy(
|
|
4089
|
+
subquery._.selectedFields,
|
|
4090
|
+
this
|
|
4091
|
+
)
|
|
4092
|
+
};
|
|
4093
|
+
}
|
|
4094
|
+
if (prop === _view_common_js__WEBPACK_IMPORTED_MODULE_1__/* .ViewBaseConfig */ .n) {
|
|
4095
|
+
return {
|
|
4096
|
+
...subquery[_view_common_js__WEBPACK_IMPORTED_MODULE_1__/* .ViewBaseConfig */ .n],
|
|
4097
|
+
selectedFields: new Proxy(
|
|
4098
|
+
subquery[_view_common_js__WEBPACK_IMPORTED_MODULE_1__/* .ViewBaseConfig */ .n].selectedFields,
|
|
4099
|
+
this
|
|
4100
|
+
)
|
|
4101
|
+
};
|
|
4102
|
+
}
|
|
4103
|
+
if (typeof prop === "symbol") {
|
|
4104
|
+
return subquery[prop];
|
|
4105
|
+
}
|
|
4106
|
+
const columns = (0,_entity_js__WEBPACK_IMPORTED_MODULE_0__.is)(subquery, _subquery_js__WEBPACK_IMPORTED_MODULE_2__/* .Subquery */ .n) ? subquery._.selectedFields : (0,_entity_js__WEBPACK_IMPORTED_MODULE_0__.is)(subquery, _sql_sql_js__WEBPACK_IMPORTED_MODULE_3__/* .View */ .Ss) ? subquery[_view_common_js__WEBPACK_IMPORTED_MODULE_1__/* .ViewBaseConfig */ .n].selectedFields : subquery;
|
|
4107
|
+
const value = columns[prop];
|
|
4108
|
+
if ((0,_entity_js__WEBPACK_IMPORTED_MODULE_0__.is)(value, _sql_sql_js__WEBPACK_IMPORTED_MODULE_3__/* .SQL */ .Xs.Aliased)) {
|
|
4109
|
+
if (this.config.sqlAliasedBehavior === "sql" && !value.isSelectionField) {
|
|
4110
|
+
return value.sql;
|
|
4111
|
+
}
|
|
4112
|
+
const newValue = value.clone();
|
|
4113
|
+
newValue.isSelectionField = true;
|
|
4114
|
+
return newValue;
|
|
4115
|
+
}
|
|
4116
|
+
if ((0,_entity_js__WEBPACK_IMPORTED_MODULE_0__.is)(value, _sql_sql_js__WEBPACK_IMPORTED_MODULE_3__/* .SQL */ .Xs)) {
|
|
4117
|
+
if (this.config.sqlBehavior === "sql") {
|
|
4118
|
+
return value;
|
|
4119
|
+
}
|
|
4120
|
+
throw new Error(
|
|
4121
|
+
`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.`
|
|
4122
|
+
);
|
|
4123
|
+
}
|
|
4124
|
+
if ((0,_entity_js__WEBPACK_IMPORTED_MODULE_0__.is)(value, _column_js__WEBPACK_IMPORTED_MODULE_4__/* .Column */ .V)) {
|
|
4125
|
+
if (this.config.alias) {
|
|
4126
|
+
return new Proxy(
|
|
4127
|
+
value,
|
|
4128
|
+
new _alias_js__WEBPACK_IMPORTED_MODULE_5__/* .ColumnAliasProxyHandler */ .Ht(
|
|
4129
|
+
new Proxy(
|
|
4130
|
+
value.table,
|
|
4131
|
+
new _alias_js__WEBPACK_IMPORTED_MODULE_5__/* .TableAliasProxyHandler */ .h_(this.config.alias, this.config.replaceOriginalName ?? false)
|
|
4132
|
+
)
|
|
4133
|
+
)
|
|
4134
|
+
);
|
|
4135
|
+
}
|
|
4136
|
+
return value;
|
|
4137
|
+
}
|
|
4138
|
+
if (typeof value !== "object" || value === null) {
|
|
4139
|
+
return value;
|
|
4140
|
+
}
|
|
4141
|
+
return new Proxy(value, new SelectionProxyHandler(this.config));
|
|
4142
|
+
}
|
|
4143
|
+
}
|
|
4144
|
+
|
|
4145
|
+
//# sourceMappingURL=selection-proxy.js.map
|
|
4146
|
+
|
|
4147
|
+
/***/ })
|
|
4148
|
+
|
|
4149
|
+
};
|
|
4150
|
+
|
|
4151
|
+
//# sourceMappingURL=62.index.js.map
|