docs-i18n 0.9.2 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/admin/dist/server/server.js +20 -20
- package/package.json +1 -1
- package/template/app/components/markdown/Markdown.tsx +7 -1
- package/template/app/utils/docs.server.ts +37 -4
- package/template/app/worker.ts +16 -0
- package/template/dist/client/assets/{Doc-CGhUfH9r.js → Doc-CbmLeLjl.js} +1 -1
- package/template/dist/client/assets/{DocsLayout-CoPL9BM9.js → DocsLayout-ERG7nrAc.js} +1 -1
- package/template/dist/client/assets/{FileTabs-DsPkEUu7.js → FileTabs-CCynw0nL.js} +1 -1
- package/template/dist/client/assets/{Footer-4faHyha8.js → Footer-l6Y8-ltB.js} +1 -1
- package/template/dist/client/assets/{FrameworkContent-Cxg_X_EP.js → FrameworkContent-pNf68F7f.js} +1 -1
- package/template/dist/client/assets/{MarkdownHeadingContext-CwDqQdSh.js → MarkdownHeadingContext-6I862CKH.js} +4 -4
- package/template/dist/client/assets/{PostNotFound-1ZaWdycM.js → PostNotFound-ScC0039d.js} +1 -1
- package/template/dist/client/assets/{_basePickBy-FbrKkfHa.js → _basePickBy-B-GcvGxW.js} +1 -1
- package/template/dist/client/assets/{_baseUniq-g6ljCkn8.js → _baseUniq-C1WySGZQ.js} +1 -1
- package/template/dist/client/assets/_lang-B3tRf7os.js +1 -0
- package/template/dist/client/assets/_lang._project-CH0inpmY.js +1 -0
- package/template/dist/client/assets/_lang._project._version-CESvrqds.js +1 -0
- package/template/dist/client/assets/{_lang._project._version.docs-DjZ_USgK.js → _lang._project._version.docs-aw08dKvN.js} +1 -1
- package/template/dist/client/assets/{_lang._project._version.docs._-CNb1EMFX.js → _lang._project._version.docs._-B4Vb_S0V.js} +1 -1
- package/template/dist/client/assets/_lang._project._version.docs._-BexMyJr9.js +1 -0
- package/template/dist/client/assets/_lang._project._version.docs.framework._framework._-BbQgUWTH.js +1 -0
- package/template/dist/client/assets/{_lang._project._version.docs.framework._framework.index-CqyVy6eq.js → _lang._project._version.docs.framework._framework.index-DInYPTXM.js} +1 -1
- package/template/dist/client/assets/{_lang._project._version.docs.framework.index-S3Frbfn4.js → _lang._project._version.docs.framework.index-B7EvJmBI.js} +1 -1
- package/template/dist/client/assets/{_lang._project.docs-CkmM5v1V.js → _lang._project.docs-4oX3ADgu.js} +1 -1
- package/template/dist/client/assets/_lang._project.docs._-R9bOn492.js +1 -0
- package/template/dist/client/assets/{_lang._project.docs._-BHYKQj_2.js → _lang._project.docs._-emq0IsQw.js} +1 -1
- package/template/dist/client/assets/_lang.blog-BViCs72M.js +1 -0
- package/template/dist/client/assets/_lang.blog-DhVkwYEk.js +1 -0
- package/template/dist/client/assets/_lang.blog._-BHdaHDBU.js +1 -0
- package/template/dist/client/assets/{_lang.blog._-bXJwKw9E.js → _lang.blog._-DErizs7q.js} +1 -1
- package/template/dist/client/assets/_lang.blog.index-CELEUrkj.js +1 -0
- package/template/dist/client/assets/{_lang.blog.index-CdR5PZOo.js → _lang.blog.index-DZDuDkQr.js} +1 -1
- package/template/dist/client/assets/{_lang.docs-Cp3wmc9k.js → _lang.docs-CQK0rfqt.js} +1 -1
- package/template/dist/client/assets/{_lang.docs._-0bwIpeOn.js → _lang.docs._-BiCvgeV1.js} +1 -1
- package/template/dist/client/assets/_lang.docs._-axvS_dfl.js +1 -0
- package/template/dist/client/assets/_lang.docs.framework._framework._-D2FAQ0gW.js +1 -0
- package/template/dist/client/assets/{_lang.docs.framework._framework.index-BLgwIvQA.js → _lang.docs.framework._framework.index-Bu5p5Q_r.js} +1 -1
- package/template/dist/client/assets/{_lang.docs.framework.index-CzW7Dul3.js → _lang.docs.framework.index-uTDFLagP.js} +1 -1
- package/template/dist/client/assets/{arc-B4lRpBfi.js → arc-C16C7aa3.js} +1 -1
- package/template/dist/client/assets/{architectureDiagram-2XIMDMQ5-Coq1Gceq.js → architectureDiagram-2XIMDMQ5-DgSSDH9Z.js} +1 -1
- package/template/dist/client/assets/{blockDiagram-WCTKOSBZ-C7BGTzDN.js → blockDiagram-WCTKOSBZ-Bs8e58Or.js} +1 -1
- package/template/dist/client/assets/{c4Diagram-IC4MRINW-xTBVTs0q.js → c4Diagram-IC4MRINW-DsGaAPtm.js} +1 -1
- package/template/dist/client/assets/channel-Clrp6Lr4.js +1 -0
- package/template/dist/client/assets/{chunk-4BX2VUAB-DUUHBu75.js → chunk-4BX2VUAB-BQdq93Vq.js} +1 -1
- package/template/dist/client/assets/{chunk-55IACEB6-MUxF_n9_.js → chunk-55IACEB6-zjp4uUiZ.js} +1 -1
- package/template/dist/client/assets/{chunk-FMBD7UC4-BWh6wvYo.js → chunk-FMBD7UC4-CEdYlBOF.js} +1 -1
- package/template/dist/client/assets/{chunk-JSJVCQXG-CLUdUV5u.js → chunk-JSJVCQXG-CVkDw9ls.js} +1 -1
- package/template/dist/client/assets/{chunk-KX2RTZJC-CAlz_cXA.js → chunk-KX2RTZJC--1vKv-mr.js} +1 -1
- package/template/dist/client/assets/{chunk-NQ4KR5QH-BaYKfUVy.js → chunk-NQ4KR5QH-Cpo-W18l.js} +1 -1
- package/template/dist/client/assets/{chunk-QZHKN3VN-NxDloxi5.js → chunk-QZHKN3VN-BizWJuB4.js} +1 -1
- package/template/dist/client/assets/{chunk-WL4C6EOR-C2Ncbi5S.js → chunk-WL4C6EOR-6lLYa9R1.js} +1 -1
- package/template/dist/client/assets/classDiagram-VBA2DB6C-Beq6_jEy.js +1 -0
- package/template/dist/client/assets/classDiagram-v2-RAHNMMFH-Beq6_jEy.js +1 -0
- package/template/dist/client/assets/clone-BbBu6MzK.js +1 -0
- package/template/dist/client/assets/{cose-bilkent-S5V4N54A-Ct9-ZJcv.js → cose-bilkent-S5V4N54A-CaD0EGPJ.js} +1 -1
- package/template/dist/client/assets/{dagre-KLK3FWXG-u9dz8dcq.js → dagre-KLK3FWXG-h4F9WtDQ.js} +1 -1
- package/template/dist/client/assets/{diagram-E7M64L7V-BXmcaktT.js → diagram-E7M64L7V-CBUSWzH5.js} +1 -1
- package/template/dist/client/assets/{diagram-IFDJBPK2-CRlP5SeV.js → diagram-IFDJBPK2-C5oMubv0.js} +1 -1
- package/template/dist/client/assets/{diagram-P4PSJMXO-B9rJcj_H.js → diagram-P4PSJMXO-DdPwwhHR.js} +1 -1
- package/template/dist/client/assets/{erDiagram-INFDFZHY-DX-vee6w.js → erDiagram-INFDFZHY-0U5A-RF0.js} +1 -1
- package/template/dist/client/assets/{flowDiagram-PKNHOUZH-CoBCSOFc.js → flowDiagram-PKNHOUZH-CXN3pvSW.js} +1 -1
- package/template/dist/client/assets/{ganttDiagram-A5KZAMGK-BlqU_ghi.js → ganttDiagram-A5KZAMGK-DlovlSO7.js} +1 -1
- package/template/dist/client/assets/{gitGraphDiagram-K3NZZRJ6-CntCsuti.js → gitGraphDiagram-K3NZZRJ6-Bo-Jjy7v.js} +1 -1
- package/template/dist/client/assets/{graph-CZaxZzO8.js → graph-C0TauvuO.js} +1 -1
- package/template/dist/client/assets/{index-XelhTkgl.js → index-iATq4LEm.js} +1 -1
- package/template/dist/client/assets/{infoDiagram-LFFYTUFH-_jCC8Jtt.js → infoDiagram-LFFYTUFH-BbvPzztn.js} +1 -1
- package/template/dist/client/assets/{ishikawaDiagram-PHBUUO56-D3m_r2ig.js → ishikawaDiagram-PHBUUO56-DKCMONMO.js} +1 -1
- package/template/dist/client/assets/{journeyDiagram-4ABVD52K-CvRNm03C.js → journeyDiagram-4ABVD52K-D9NP_vvu.js} +1 -1
- package/template/dist/client/assets/{kanban-definition-K7BYSVSG-nQcLuNSy.js → kanban-definition-K7BYSVSG-X-u_nWxK.js} +1 -1
- package/template/dist/client/assets/{layout-DZIdDq97.js → layout-IeRzBrUX.js} +1 -1
- package/template/dist/client/assets/{linear-C2JcF5ss.js → linear-DEzVUeiK.js} +1 -1
- package/template/dist/client/assets/{main-C8MldI1o.js → main-Csj9i19C.js} +2 -2
- package/template/dist/client/assets/{mermaid.core-DlB0QBo2.js → mermaid.core-CCnh2DG0.js} +4 -4
- package/template/dist/client/assets/{mindmap-definition-YRQLILUH-D9OjtrBW.js → mindmap-definition-YRQLILUH-DgyN4Ft-.js} +1 -1
- package/template/dist/client/assets/{pieDiagram-SKSYHLDU-DoYJZfNJ.js → pieDiagram-SKSYHLDU-DDVqU_2Q.js} +1 -1
- package/template/dist/client/assets/{quadrantDiagram-337W2JSQ-Bs71YHJr.js → quadrantDiagram-337W2JSQ-BeUxMqle.js} +1 -1
- package/template/dist/client/assets/{react-C0klD_r9.js → react-os8EX6z1.js} +1 -1
- package/template/dist/client/assets/{requirementDiagram-Z7DCOOCP-BWvQcALn.js → requirementDiagram-Z7DCOOCP-CpzdlyEd.js} +1 -1
- package/template/dist/client/assets/{sankeyDiagram-WA2Y5GQK-CiGy1SQP.js → sankeyDiagram-WA2Y5GQK-CmSWF6XU.js} +1 -1
- package/template/dist/client/assets/{sequenceDiagram-2WXFIKYE-DRZim8vR.js → sequenceDiagram-2WXFIKYE-DarofLka.js} +1 -1
- package/template/dist/client/assets/{stateDiagram-RAJIS63D-BoqzJeL7.js → stateDiagram-RAJIS63D-CEio2h-7.js} +1 -1
- package/template/dist/client/assets/stateDiagram-v2-FVOUBMTO-CbfK0_BD.js +1 -0
- package/template/dist/client/assets/{timeline-definition-YZTLITO2-CyvR95Wz.js → timeline-definition-YZTLITO2-By_Wk6uc.js} +1 -1
- package/template/dist/client/assets/{treemap-KZPCXAKY-DkXgGvs_.js → treemap-KZPCXAKY-mKcaMbv9.js} +1 -1
- package/template/dist/client/assets/{vennDiagram-LZ73GAT5-CVpGZu6p.js → vennDiagram-LZ73GAT5-Dx_Fh7nH.js} +1 -1
- package/template/dist/client/assets/{xychartDiagram-JWTSCODW-Cjqbi_DU.js → xychartDiagram-JWTSCODW-DSAwWbBw.js} +1 -1
- package/template/dist/server/assets/{Doc-DKBxQduk.js → Doc-B8TJBEmx.js} +3 -3
- package/template/dist/server/assets/{DocsLayout-CQfCTal3.js → DocsLayout-CnWgvk8u.js} +2 -2
- package/template/dist/server/assets/{Footer-Dcw5XVqX.js → Footer-WapWK45U.js} +1 -1
- package/template/dist/server/assets/{FrameworkContent-OJfvCBHi.js → FrameworkContent-gzqT-Q1n.js} +2 -2
- package/template/dist/server/assets/{MarkdownHeadingContext-h4SfZq-C.js → MarkdownHeadingContext-Iyk66Y4x.js} +7 -3
- package/template/dist/server/assets/{PostNotFound-DRJpnWrj.js → PostNotFound-GKdNuzsX.js} +1 -1
- package/template/dist/server/assets/{_lang._project._version.docs-sJvASz_e.js → _lang._project._version.docs-BOZ34yW7.js} +3 -3
- package/template/dist/server/assets/{_lang._project._version.docs-CE_Z2zvG.js → _lang._project._version.docs-DOTNQiDb.js} +1 -1
- package/template/dist/server/assets/{_lang._project._version.docs._-B2vf_QGY.js → _lang._project._version.docs._-5W2jN7Re.js} +5 -5
- package/template/dist/server/assets/{_lang._project._version.docs._-CQcamDns.js → _lang._project._version.docs._-DSg82-Ug.js} +1 -1
- package/template/dist/server/assets/{_lang._project._version.docs.framework._framework._-54LEIllb.js → _lang._project._version.docs.framework._framework._-DbeN6toN.js} +1 -1
- package/template/dist/server/assets/{_lang._project._version.docs.framework._framework._-Dmn8xCf0.js → _lang._project._version.docs.framework._framework._-DeN_oA8l.js} +5 -5
- package/template/dist/server/assets/{_lang._project._version.docs.framework._framework.index-COKb9ffR.js → _lang._project._version.docs.framework._framework.index-jWKDCQSE.js} +1 -1
- package/template/dist/server/assets/{_lang._project._version.docs.framework.index-DoEddI6Z.js → _lang._project._version.docs.framework.index-DOT4MtjZ.js} +1 -1
- package/template/dist/server/assets/{_lang._project.docs-dl8MxaGg.js → _lang._project.docs-BsnkRf-R.js} +1 -1
- package/template/dist/server/assets/{_lang._project.docs-BjOhmwp6.js → _lang._project.docs-r4V9TXuu.js} +3 -3
- package/template/dist/server/assets/{_lang._project.docs._-hSRVM-U7.js → _lang._project.docs._-Bge7JaYE.js} +5 -5
- package/template/dist/server/assets/{_lang._project.docs._-Bq0ajlaH.js → _lang._project.docs._-axRfm8vS.js} +1 -1
- package/template/dist/server/assets/{_lang.blog-Dk36D6Ol.js → _lang.blog-DJOfiyA8.js} +2 -2
- package/template/dist/server/assets/{_lang.blog._-A8h17fpC.js → _lang.blog._-C7iqMj9O.js} +2 -2
- package/template/dist/server/assets/{_lang.blog._-D4CEjSkM.js → _lang.blog._-CjgFipz7.js} +1 -1
- package/template/dist/server/assets/{_lang.blog._-Cm8zXsPs.js → _lang.blog._-yJSqbX08.js} +2 -2
- package/template/dist/server/assets/{_lang.blog.index-orWcAgbi.js → _lang.blog.index-CrdyROhK.js} +2 -2
- package/template/dist/server/assets/{_lang.blog.index-ZhMds6Jp.js → _lang.blog.index-Df_6_IKx.js} +1 -1
- package/template/dist/server/assets/{_lang.blog.index-Dfy48Gbt.js → _lang.blog.index-Dk5fYp4Q.js} +1 -1
- package/template/dist/server/assets/{_lang.docs-CB1sGjRO.js → _lang.docs-DSB3iI6a.js} +1 -1
- package/template/dist/server/assets/{_lang.docs-CAEkhcnT.js → _lang.docs-Jwt4deTW.js} +3 -3
- package/template/dist/server/assets/{_lang.docs._-Zbv8OwJU.js → _lang.docs._-D_DdKLAV.js} +5 -5
- package/template/dist/server/assets/{_lang.docs._-DEX6FutM.js → _lang.docs._-S-y4-3Qn.js} +1 -1
- package/template/dist/server/assets/{_lang.docs.framework._framework._-BnpTV3KM.js → _lang.docs.framework._framework._-BFWLyU2h.js} +1 -1
- package/template/dist/server/assets/{_lang.docs.framework._framework._-4s4-ZCYh.js → _lang.docs.framework._framework._-BkQaZ_1f.js} +5 -5
- package/template/dist/server/assets/{_lang.docs.framework._framework.index-BLryfsl2.js → _lang.docs.framework._framework.index-BLx8p8IS.js} +1 -1
- package/template/dist/server/assets/{_lang.docs.framework.index-DGxWQH6q.js → _lang.docs.framework.index-BytQ_q8T.js} +1 -1
- package/template/dist/server/assets/{_tanstack-start-manifest_v-CURwM8Tc.js → _tanstack-start-manifest_v-RX6ItZ5S.js} +1 -1
- package/template/dist/server/assets/{blog.server-Bbk2Ifog.js → blog.server-WqzZ00iA.js} +1 -1
- package/template/dist/server/assets/{docs.server-7EUAkSBN.js → docs.server-BSH7IvIU.js} +3884 -444
- package/template/dist/server/assets/{index-BvagF3L5.js → index-DvBGSZeA.js} +2 -2
- package/template/dist/server/assets/{router-DK1vpPhv.js → router-DPPgDicW.js} +18 -18
- package/template/dist/server/server.js +14 -14
- package/template/package.json +2 -0
- package/template/vite.config.ts +33 -18
- package/template/wrangler.jsonc +2 -2
- package/template/dist/client/assets/_lang-Cpuy5xmU.js +0 -1
- package/template/dist/client/assets/_lang._project-DBdR04In.js +0 -1
- package/template/dist/client/assets/_lang._project._version-CtCLMJs2.js +0 -1
- package/template/dist/client/assets/_lang._project._version.docs._-CxgRZ17Q.js +0 -1
- package/template/dist/client/assets/_lang._project._version.docs.framework._framework._-Qph6wahA.js +0 -1
- package/template/dist/client/assets/_lang._project.docs._-C_ZfXEJ7.js +0 -1
- package/template/dist/client/assets/_lang.blog-BcRmhv23.js +0 -1
- package/template/dist/client/assets/_lang.blog-C5Aa7k5r.js +0 -1
- package/template/dist/client/assets/_lang.blog._-BVw4vhtF.js +0 -1
- package/template/dist/client/assets/_lang.blog.index-Y35iFzkp.js +0 -1
- package/template/dist/client/assets/_lang.docs._-B9hwwoTY.js +0 -1
- package/template/dist/client/assets/_lang.docs.framework._framework._-BENbKZIu.js +0 -1
- package/template/dist/client/assets/channel-C_1F7tzH.js +0 -1
- package/template/dist/client/assets/classDiagram-VBA2DB6C-CqViWWFw.js +0 -1
- package/template/dist/client/assets/classDiagram-v2-RAHNMMFH-CqViWWFw.js +0 -1
- package/template/dist/client/assets/clone-EeiNAO_N.js +0 -1
- package/template/dist/client/assets/stateDiagram-v2-FVOUBMTO-CJYWvllO.js +0 -1
|
@@ -311,14 +311,14 @@ function containerFlow(parent, state, info) {
|
|
|
311
311
|
}
|
|
312
312
|
if (index2 < children.length - 1) {
|
|
313
313
|
results.push(
|
|
314
|
-
tracker.move(between(child, children[index2 + 1], parent, state))
|
|
314
|
+
tracker.move(between$1(child, children[index2 + 1], parent, state))
|
|
315
315
|
);
|
|
316
316
|
}
|
|
317
317
|
}
|
|
318
318
|
indexStack.pop();
|
|
319
319
|
return results.join("");
|
|
320
320
|
}
|
|
321
|
-
function between(left, right, parent, state) {
|
|
321
|
+
function between$1(left, right, parent, state) {
|
|
322
322
|
let index2 = state.join.length;
|
|
323
323
|
while (index2--) {
|
|
324
324
|
const result = state.join[index2](left, right, parent, state);
|
|
@@ -542,8 +542,8 @@ function remarkStringify(options) {
|
|
|
542
542
|
}
|
|
543
543
|
}
|
|
544
544
|
const remark = unified().use(remarkParse).use(remarkStringify).freeze();
|
|
545
|
-
function normalize(
|
|
546
|
-
let result =
|
|
545
|
+
function normalize(content2) {
|
|
546
|
+
let result = content2;
|
|
547
547
|
result = result.replace(
|
|
548
548
|
/^(<(?:AppOnly|PagesOnly|details[^>]*|div[^>]*)>)\n(?!\n)/gm,
|
|
549
549
|
"$1\n\n"
|
|
@@ -578,12 +578,12 @@ function computeHash(text2) {
|
|
|
578
578
|
return require$$1.createHash("md5").update(text2).digest("hex");
|
|
579
579
|
}
|
|
580
580
|
function parseMdx(rawContent) {
|
|
581
|
-
const
|
|
582
|
-
const tree = remark().parse(
|
|
581
|
+
const content2 = normalize(rawContent);
|
|
582
|
+
const tree = remark().parse(content2);
|
|
583
583
|
const nodes = [];
|
|
584
584
|
let frontmatterHandled = false;
|
|
585
|
-
if (
|
|
586
|
-
const fmMatch =
|
|
585
|
+
if (content2.startsWith("---") && tree.children.length >= 2 && tree.children[0].type === "thematicBreak") {
|
|
586
|
+
const fmMatch = content2.match(/^---\n([\s\S]*?)\n---/);
|
|
587
587
|
if (fmMatch) {
|
|
588
588
|
const fmEnd = fmMatch[0].length;
|
|
589
589
|
const fmText = fmMatch[0];
|
|
@@ -604,7 +604,7 @@ function parseMdx(rawContent) {
|
|
|
604
604
|
if (frontmatterHandled && startOffset < nodes[0].endOffset) {
|
|
605
605
|
continue;
|
|
606
606
|
}
|
|
607
|
-
const rawText =
|
|
607
|
+
const rawText = content2.substring(startOffset, endOffset);
|
|
608
608
|
const type = child.type;
|
|
609
609
|
let needsTranslation;
|
|
610
610
|
if (TRANSLATABLE_TYPES.has(type)) {
|
|
@@ -3082,10 +3082,10 @@ function requireInt$1() {
|
|
|
3082
3082
|
int$1.intOct = intOct;
|
|
3083
3083
|
return int$1;
|
|
3084
3084
|
}
|
|
3085
|
-
var schema$
|
|
3085
|
+
var schema$3 = {};
|
|
3086
3086
|
var hasRequiredSchema$3;
|
|
3087
3087
|
function requireSchema$3() {
|
|
3088
|
-
if (hasRequiredSchema$3) return schema$
|
|
3088
|
+
if (hasRequiredSchema$3) return schema$3;
|
|
3089
3089
|
hasRequiredSchema$3 = 1;
|
|
3090
3090
|
var map2 = requireMap();
|
|
3091
3091
|
var _null2 = require_null();
|
|
@@ -3107,13 +3107,13 @@ function requireSchema$3() {
|
|
|
3107
3107
|
float2.floatExp,
|
|
3108
3108
|
float2.float
|
|
3109
3109
|
];
|
|
3110
|
-
schema$
|
|
3111
|
-
return schema$
|
|
3110
|
+
schema$3.schema = schema2;
|
|
3111
|
+
return schema$3;
|
|
3112
3112
|
}
|
|
3113
|
-
var schema$
|
|
3113
|
+
var schema$2 = {};
|
|
3114
3114
|
var hasRequiredSchema$2;
|
|
3115
3115
|
function requireSchema$2() {
|
|
3116
|
-
if (hasRequiredSchema$2) return schema$
|
|
3116
|
+
if (hasRequiredSchema$2) return schema$2;
|
|
3117
3117
|
hasRequiredSchema$2 = 1;
|
|
3118
3118
|
var Scalar2 = requireScalar();
|
|
3119
3119
|
var map2 = requireMap();
|
|
@@ -3174,8 +3174,8 @@ function requireSchema$2() {
|
|
|
3174
3174
|
}
|
|
3175
3175
|
};
|
|
3176
3176
|
const schema2 = [map2.map, seq2.seq].concat(jsonScalars, jsonError);
|
|
3177
|
-
schema$
|
|
3178
|
-
return schema$
|
|
3177
|
+
schema$2.schema = schema2;
|
|
3178
|
+
return schema$2;
|
|
3179
3179
|
}
|
|
3180
3180
|
var binary = {};
|
|
3181
3181
|
var hasRequiredBinary;
|
|
@@ -3399,7 +3399,7 @@ function requireOmap() {
|
|
|
3399
3399
|
omap.omap = omap$1;
|
|
3400
3400
|
return omap;
|
|
3401
3401
|
}
|
|
3402
|
-
var schema = {};
|
|
3402
|
+
var schema$1 = {};
|
|
3403
3403
|
var bool = {};
|
|
3404
3404
|
var hasRequiredBool;
|
|
3405
3405
|
function requireBool() {
|
|
@@ -3739,7 +3739,7 @@ function requireTimestamp() {
|
|
|
3739
3739
|
}
|
|
3740
3740
|
var hasRequiredSchema$1;
|
|
3741
3741
|
function requireSchema$1() {
|
|
3742
|
-
if (hasRequiredSchema$1) return schema;
|
|
3742
|
+
if (hasRequiredSchema$1) return schema$1;
|
|
3743
3743
|
hasRequiredSchema$1 = 1;
|
|
3744
3744
|
var map2 = requireMap();
|
|
3745
3745
|
var _null2 = require_null();
|
|
@@ -3754,7 +3754,7 @@ function requireSchema$1() {
|
|
|
3754
3754
|
var pairs2 = requirePairs();
|
|
3755
3755
|
var set2 = requireSet();
|
|
3756
3756
|
var timestamp2 = requireTimestamp();
|
|
3757
|
-
const
|
|
3757
|
+
const schema2 = [
|
|
3758
3758
|
map2.map,
|
|
3759
3759
|
seq2.seq,
|
|
3760
3760
|
string2.string,
|
|
@@ -3777,8 +3777,8 @@ function requireSchema$1() {
|
|
|
3777
3777
|
timestamp2.floatTime,
|
|
3778
3778
|
timestamp2.timestamp
|
|
3779
3779
|
];
|
|
3780
|
-
schema.schema =
|
|
3781
|
-
return schema;
|
|
3780
|
+
schema$1.schema = schema2;
|
|
3781
|
+
return schema$1;
|
|
3782
3782
|
}
|
|
3783
3783
|
var hasRequiredTags;
|
|
3784
3784
|
function requireTags() {
|
|
@@ -5046,8 +5046,8 @@ function requireResolveBlockScalar() {
|
|
|
5046
5046
|
const lines = scalar.source ? splitLines(scalar.source) : [];
|
|
5047
5047
|
let chompStart = lines.length;
|
|
5048
5048
|
for (let i = lines.length - 1; i >= 0; --i) {
|
|
5049
|
-
const
|
|
5050
|
-
if (
|
|
5049
|
+
const content2 = lines[i][1];
|
|
5050
|
+
if (content2 === "" || content2 === "\r")
|
|
5051
5051
|
chompStart = i;
|
|
5052
5052
|
else
|
|
5053
5053
|
break;
|
|
@@ -5063,8 +5063,8 @@ function requireResolveBlockScalar() {
|
|
|
5063
5063
|
let offset = scalar.offset + header.length;
|
|
5064
5064
|
let contentStart = 0;
|
|
5065
5065
|
for (let i = 0; i < chompStart; ++i) {
|
|
5066
|
-
const [indent,
|
|
5067
|
-
if (
|
|
5066
|
+
const [indent, content2] = lines[i];
|
|
5067
|
+
if (content2 === "" || content2 === "\r") {
|
|
5068
5068
|
if (header.indent === 0 && indent.length > trimIndent)
|
|
5069
5069
|
trimIndent = indent.length;
|
|
5070
5070
|
} else {
|
|
@@ -5081,7 +5081,7 @@ function requireResolveBlockScalar() {
|
|
|
5081
5081
|
}
|
|
5082
5082
|
break;
|
|
5083
5083
|
}
|
|
5084
|
-
offset += indent.length +
|
|
5084
|
+
offset += indent.length + content2.length + 1;
|
|
5085
5085
|
}
|
|
5086
5086
|
for (let i = lines.length - 1; i >= chompStart; --i) {
|
|
5087
5087
|
if (lines[i][0].length > trimIndent)
|
|
@@ -5093,35 +5093,35 @@ function requireResolveBlockScalar() {
|
|
|
5093
5093
|
for (let i = 0; i < contentStart; ++i)
|
|
5094
5094
|
value += lines[i][0].slice(trimIndent) + "\n";
|
|
5095
5095
|
for (let i = contentStart; i < chompStart; ++i) {
|
|
5096
|
-
let [indent,
|
|
5097
|
-
offset += indent.length +
|
|
5098
|
-
const crlf =
|
|
5096
|
+
let [indent, content2] = lines[i];
|
|
5097
|
+
offset += indent.length + content2.length + 1;
|
|
5098
|
+
const crlf = content2[content2.length - 1] === "\r";
|
|
5099
5099
|
if (crlf)
|
|
5100
|
-
|
|
5101
|
-
if (
|
|
5100
|
+
content2 = content2.slice(0, -1);
|
|
5101
|
+
if (content2 && indent.length < trimIndent) {
|
|
5102
5102
|
const src = header.indent ? "explicit indentation indicator" : "first line";
|
|
5103
5103
|
const message = `Block scalar lines must not be less indented than their ${src}`;
|
|
5104
|
-
onError(offset -
|
|
5104
|
+
onError(offset - content2.length - (crlf ? 2 : 1), "BAD_INDENT", message);
|
|
5105
5105
|
indent = "";
|
|
5106
5106
|
}
|
|
5107
5107
|
if (type === Scalar2.Scalar.BLOCK_LITERAL) {
|
|
5108
|
-
value += sep + indent.slice(trimIndent) +
|
|
5108
|
+
value += sep + indent.slice(trimIndent) + content2;
|
|
5109
5109
|
sep = "\n";
|
|
5110
|
-
} else if (indent.length > trimIndent ||
|
|
5110
|
+
} else if (indent.length > trimIndent || content2[0] === " ") {
|
|
5111
5111
|
if (sep === " ")
|
|
5112
5112
|
sep = "\n";
|
|
5113
5113
|
else if (!prevMoreIndented && sep === "\n")
|
|
5114
5114
|
sep = "\n\n";
|
|
5115
|
-
value += sep + indent.slice(trimIndent) +
|
|
5115
|
+
value += sep + indent.slice(trimIndent) + content2;
|
|
5116
5116
|
sep = "\n";
|
|
5117
5117
|
prevMoreIndented = true;
|
|
5118
|
-
} else if (
|
|
5118
|
+
} else if (content2 === "") {
|
|
5119
5119
|
if (sep === "\n")
|
|
5120
5120
|
value += "\n";
|
|
5121
5121
|
else
|
|
5122
5122
|
sep = "\n";
|
|
5123
5123
|
} else {
|
|
5124
|
-
value += sep +
|
|
5124
|
+
value += sep + content2;
|
|
5125
5125
|
sep = " ";
|
|
5126
5126
|
prevMoreIndented = false;
|
|
5127
5127
|
}
|
|
@@ -8591,6 +8591,9 @@ class Subquery {
|
|
|
8591
8591
|
// return new SQL([this]);
|
|
8592
8592
|
// }
|
|
8593
8593
|
}
|
|
8594
|
+
class WithSubquery extends Subquery {
|
|
8595
|
+
static [entityKind] = "WithSubquery";
|
|
8596
|
+
}
|
|
8594
8597
|
const tracer = {
|
|
8595
8598
|
startActiveSpan(name, fn) {
|
|
8596
8599
|
{
|
|
@@ -8653,6 +8656,12 @@ class Table {
|
|
|
8653
8656
|
this[BaseName] = baseName;
|
|
8654
8657
|
}
|
|
8655
8658
|
}
|
|
8659
|
+
function getTableName(table) {
|
|
8660
|
+
return table[TableName];
|
|
8661
|
+
}
|
|
8662
|
+
function getTableUniqueName(table) {
|
|
8663
|
+
return `${table[Schema] ?? "public"}.${table[TableName]}`;
|
|
8664
|
+
}
|
|
8656
8665
|
function isSQLWrapper(value) {
|
|
8657
8666
|
return value !== null && value !== void 0 && typeof value.getSQL === "function";
|
|
8658
8667
|
}
|
|
@@ -8881,6 +8890,9 @@ class Name {
|
|
|
8881
8890
|
return new SQL([this]);
|
|
8882
8891
|
}
|
|
8883
8892
|
}
|
|
8893
|
+
function isDriverValueEncoder(value) {
|
|
8894
|
+
return typeof value === "object" && value !== null && "mapToDriverValue" in value && typeof value.mapToDriverValue === "function";
|
|
8895
|
+
}
|
|
8884
8896
|
const noopDecoder = {
|
|
8885
8897
|
mapFromDriverValue: (value) => value
|
|
8886
8898
|
};
|
|
@@ -8981,6 +8993,23 @@ class Placeholder {
|
|
|
8981
8993
|
return new SQL([this]);
|
|
8982
8994
|
}
|
|
8983
8995
|
}
|
|
8996
|
+
function fillPlaceholders(params, values) {
|
|
8997
|
+
return params.map((p) => {
|
|
8998
|
+
if (is(p, Placeholder)) {
|
|
8999
|
+
if (!(p.name in values)) {
|
|
9000
|
+
throw new Error(`No value for placeholder "${p.name}" was provided`);
|
|
9001
|
+
}
|
|
9002
|
+
return values[p.name];
|
|
9003
|
+
}
|
|
9004
|
+
if (is(p, Param) && is(p.value, Placeholder)) {
|
|
9005
|
+
if (!(p.value.name in values)) {
|
|
9006
|
+
throw new Error(`No value for placeholder "${p.value.name}" was provided`);
|
|
9007
|
+
}
|
|
9008
|
+
return p.encoder.mapToDriverValue(values[p.value.name]);
|
|
9009
|
+
}
|
|
9010
|
+
return p;
|
|
9011
|
+
});
|
|
9012
|
+
}
|
|
8984
9013
|
const IsDrizzleView = /* @__PURE__ */ Symbol.for("drizzle:IsDrizzleView");
|
|
8985
9014
|
class View {
|
|
8986
9015
|
static [entityKind] = "View";
|
|
@@ -9012,505 +9041,3504 @@ Table.prototype.getSQL = function() {
|
|
|
9012
9041
|
Subquery.prototype.getSQL = function() {
|
|
9013
9042
|
return new SQL([this]);
|
|
9014
9043
|
};
|
|
9015
|
-
|
|
9016
|
-
|
|
9017
|
-
|
|
9018
|
-
config: typeof a === "object" ? a : b
|
|
9019
|
-
};
|
|
9020
|
-
}
|
|
9021
|
-
class ForeignKeyBuilder {
|
|
9022
|
-
static [entityKind] = "SQLiteForeignKeyBuilder";
|
|
9023
|
-
/** @internal */
|
|
9024
|
-
reference;
|
|
9025
|
-
/** @internal */
|
|
9026
|
-
_onUpdate;
|
|
9027
|
-
/** @internal */
|
|
9028
|
-
_onDelete;
|
|
9029
|
-
constructor(config, actions) {
|
|
9030
|
-
this.reference = () => {
|
|
9031
|
-
const { name, columns, foreignColumns } = config();
|
|
9032
|
-
return { name, columns, foreignTable: foreignColumns[0].table, foreignColumns };
|
|
9033
|
-
};
|
|
9034
|
-
if (actions) {
|
|
9035
|
-
this._onUpdate = actions.onUpdate;
|
|
9036
|
-
this._onDelete = actions.onDelete;
|
|
9037
|
-
}
|
|
9044
|
+
class ColumnAliasProxyHandler {
|
|
9045
|
+
constructor(table) {
|
|
9046
|
+
this.table = table;
|
|
9038
9047
|
}
|
|
9039
|
-
|
|
9040
|
-
|
|
9041
|
-
|
|
9048
|
+
static [entityKind] = "ColumnAliasProxyHandler";
|
|
9049
|
+
get(columnObj, prop) {
|
|
9050
|
+
if (prop === "table") {
|
|
9051
|
+
return this.table;
|
|
9052
|
+
}
|
|
9053
|
+
return columnObj[prop];
|
|
9042
9054
|
}
|
|
9043
|
-
|
|
9044
|
-
|
|
9045
|
-
|
|
9055
|
+
}
|
|
9056
|
+
class TableAliasProxyHandler {
|
|
9057
|
+
constructor(alias, replaceOriginalName) {
|
|
9058
|
+
this.alias = alias;
|
|
9059
|
+
this.replaceOriginalName = replaceOriginalName;
|
|
9046
9060
|
}
|
|
9047
|
-
|
|
9048
|
-
|
|
9049
|
-
|
|
9061
|
+
static [entityKind] = "TableAliasProxyHandler";
|
|
9062
|
+
get(target, prop) {
|
|
9063
|
+
if (prop === Table.Symbol.IsAlias) {
|
|
9064
|
+
return true;
|
|
9065
|
+
}
|
|
9066
|
+
if (prop === Table.Symbol.Name) {
|
|
9067
|
+
return this.alias;
|
|
9068
|
+
}
|
|
9069
|
+
if (this.replaceOriginalName && prop === Table.Symbol.OriginalName) {
|
|
9070
|
+
return this.alias;
|
|
9071
|
+
}
|
|
9072
|
+
if (prop === ViewBaseConfig) {
|
|
9073
|
+
return {
|
|
9074
|
+
...target[ViewBaseConfig],
|
|
9075
|
+
name: this.alias,
|
|
9076
|
+
isAlias: true
|
|
9077
|
+
};
|
|
9078
|
+
}
|
|
9079
|
+
if (prop === Table.Symbol.Columns) {
|
|
9080
|
+
const columns = target[Table.Symbol.Columns];
|
|
9081
|
+
if (!columns) {
|
|
9082
|
+
return columns;
|
|
9083
|
+
}
|
|
9084
|
+
const proxiedColumns = {};
|
|
9085
|
+
Object.keys(columns).map((key) => {
|
|
9086
|
+
proxiedColumns[key] = new Proxy(
|
|
9087
|
+
columns[key],
|
|
9088
|
+
new ColumnAliasProxyHandler(new Proxy(target, this))
|
|
9089
|
+
);
|
|
9090
|
+
});
|
|
9091
|
+
return proxiedColumns;
|
|
9092
|
+
}
|
|
9093
|
+
const value = target[prop];
|
|
9094
|
+
if (is(value, Column)) {
|
|
9095
|
+
return new Proxy(value, new ColumnAliasProxyHandler(new Proxy(target, this)));
|
|
9096
|
+
}
|
|
9097
|
+
return value;
|
|
9050
9098
|
}
|
|
9051
9099
|
}
|
|
9052
|
-
|
|
9053
|
-
|
|
9054
|
-
|
|
9055
|
-
|
|
9056
|
-
|
|
9057
|
-
|
|
9100
|
+
function aliasedTable(table, tableAlias) {
|
|
9101
|
+
return new Proxy(table, new TableAliasProxyHandler(tableAlias, false));
|
|
9102
|
+
}
|
|
9103
|
+
function aliasedTableColumn(column, tableAlias) {
|
|
9104
|
+
return new Proxy(
|
|
9105
|
+
column,
|
|
9106
|
+
new ColumnAliasProxyHandler(new Proxy(column.table, new TableAliasProxyHandler(tableAlias, false)))
|
|
9107
|
+
);
|
|
9108
|
+
}
|
|
9109
|
+
function mapColumnsInAliasedSQLToAlias(query, alias) {
|
|
9110
|
+
return new SQL.Aliased(mapColumnsInSQLToAlias(query.sql, alias), query.fieldAlias);
|
|
9111
|
+
}
|
|
9112
|
+
function mapColumnsInSQLToAlias(query, alias) {
|
|
9113
|
+
return sql.join(query.queryChunks.map((c) => {
|
|
9114
|
+
if (is(c, Column)) {
|
|
9115
|
+
return aliasedTableColumn(c, alias);
|
|
9116
|
+
}
|
|
9117
|
+
if (is(c, SQL)) {
|
|
9118
|
+
return mapColumnsInSQLToAlias(c, alias);
|
|
9119
|
+
}
|
|
9120
|
+
if (is(c, SQL.Aliased)) {
|
|
9121
|
+
return mapColumnsInAliasedSQLToAlias(c, alias);
|
|
9122
|
+
}
|
|
9123
|
+
return c;
|
|
9124
|
+
}));
|
|
9125
|
+
}
|
|
9126
|
+
class DrizzleError extends Error {
|
|
9127
|
+
static [entityKind] = "DrizzleError";
|
|
9128
|
+
constructor({ message, cause }) {
|
|
9129
|
+
super(message);
|
|
9130
|
+
this.name = "DrizzleError";
|
|
9131
|
+
this.cause = cause;
|
|
9058
9132
|
}
|
|
9059
|
-
|
|
9060
|
-
|
|
9061
|
-
|
|
9062
|
-
|
|
9063
|
-
|
|
9064
|
-
const { name, columns, foreignColumns } = this.reference();
|
|
9065
|
-
const columnNames = columns.map((column) => column.name);
|
|
9066
|
-
const foreignColumnNames = foreignColumns.map((column) => column.name);
|
|
9067
|
-
const chunks = [
|
|
9068
|
-
this.table[TableName],
|
|
9069
|
-
...columnNames,
|
|
9070
|
-
foreignColumns[0].table[TableName],
|
|
9071
|
-
...foreignColumnNames
|
|
9072
|
-
];
|
|
9073
|
-
return name ?? `${chunks.join("_")}_fk`;
|
|
9133
|
+
}
|
|
9134
|
+
class TransactionRollbackError extends DrizzleError {
|
|
9135
|
+
static [entityKind] = "TransactionRollbackError";
|
|
9136
|
+
constructor() {
|
|
9137
|
+
super({ message: "Rollback" });
|
|
9074
9138
|
}
|
|
9075
9139
|
}
|
|
9076
|
-
function
|
|
9077
|
-
|
|
9140
|
+
function bindIfParam(value, column) {
|
|
9141
|
+
if (isDriverValueEncoder(column) && !isSQLWrapper(value) && !is(value, Param) && !is(value, Placeholder) && !is(value, Column) && !is(value, Table) && !is(value, View)) {
|
|
9142
|
+
return new Param(value, column);
|
|
9143
|
+
}
|
|
9144
|
+
return value;
|
|
9078
9145
|
}
|
|
9079
|
-
|
|
9080
|
-
|
|
9081
|
-
|
|
9082
|
-
|
|
9083
|
-
|
|
9084
|
-
|
|
9146
|
+
const eq = (left, right) => {
|
|
9147
|
+
return sql`${left} = ${bindIfParam(right, left)}`;
|
|
9148
|
+
};
|
|
9149
|
+
const ne = (left, right) => {
|
|
9150
|
+
return sql`${left} <> ${bindIfParam(right, left)}`;
|
|
9151
|
+
};
|
|
9152
|
+
function and(...unfilteredConditions) {
|
|
9153
|
+
const conditions = unfilteredConditions.filter(
|
|
9154
|
+
(c) => c !== void 0
|
|
9155
|
+
);
|
|
9156
|
+
if (conditions.length === 0) {
|
|
9157
|
+
return void 0;
|
|
9085
9158
|
}
|
|
9086
|
-
|
|
9087
|
-
|
|
9088
|
-
this.config.uniqueName = name;
|
|
9089
|
-
return this;
|
|
9159
|
+
if (conditions.length === 1) {
|
|
9160
|
+
return new SQL(conditions);
|
|
9090
9161
|
}
|
|
9091
|
-
|
|
9092
|
-
|
|
9093
|
-
|
|
9094
|
-
|
|
9095
|
-
|
|
9096
|
-
|
|
9097
|
-
|
|
9162
|
+
return new SQL([
|
|
9163
|
+
new StringChunk("("),
|
|
9164
|
+
sql.join(conditions, new StringChunk(" and ")),
|
|
9165
|
+
new StringChunk(")")
|
|
9166
|
+
]);
|
|
9167
|
+
}
|
|
9168
|
+
function or(...unfilteredConditions) {
|
|
9169
|
+
const conditions = unfilteredConditions.filter(
|
|
9170
|
+
(c) => c !== void 0
|
|
9171
|
+
);
|
|
9172
|
+
if (conditions.length === 0) {
|
|
9173
|
+
return void 0;
|
|
9098
9174
|
}
|
|
9099
|
-
|
|
9100
|
-
|
|
9101
|
-
return this.foreignKeyConfigs.map(({ ref, actions }) => {
|
|
9102
|
-
return ((ref2, actions2) => {
|
|
9103
|
-
const builder = new ForeignKeyBuilder(() => {
|
|
9104
|
-
const foreignColumn = ref2();
|
|
9105
|
-
return { columns: [column], foreignColumns: [foreignColumn] };
|
|
9106
|
-
});
|
|
9107
|
-
if (actions2.onUpdate) {
|
|
9108
|
-
builder.onUpdate(actions2.onUpdate);
|
|
9109
|
-
}
|
|
9110
|
-
if (actions2.onDelete) {
|
|
9111
|
-
builder.onDelete(actions2.onDelete);
|
|
9112
|
-
}
|
|
9113
|
-
return builder.build(table);
|
|
9114
|
-
})(ref, actions);
|
|
9115
|
-
});
|
|
9175
|
+
if (conditions.length === 1) {
|
|
9176
|
+
return new SQL(conditions);
|
|
9116
9177
|
}
|
|
9178
|
+
return new SQL([
|
|
9179
|
+
new StringChunk("("),
|
|
9180
|
+
sql.join(conditions, new StringChunk(" or ")),
|
|
9181
|
+
new StringChunk(")")
|
|
9182
|
+
]);
|
|
9117
9183
|
}
|
|
9118
|
-
|
|
9119
|
-
|
|
9120
|
-
|
|
9121
|
-
|
|
9184
|
+
function not(condition) {
|
|
9185
|
+
return sql`not ${condition}`;
|
|
9186
|
+
}
|
|
9187
|
+
const gt = (left, right) => {
|
|
9188
|
+
return sql`${left} > ${bindIfParam(right, left)}`;
|
|
9189
|
+
};
|
|
9190
|
+
const gte = (left, right) => {
|
|
9191
|
+
return sql`${left} >= ${bindIfParam(right, left)}`;
|
|
9192
|
+
};
|
|
9193
|
+
const lt = (left, right) => {
|
|
9194
|
+
return sql`${left} < ${bindIfParam(right, left)}`;
|
|
9195
|
+
};
|
|
9196
|
+
const lte = (left, right) => {
|
|
9197
|
+
return sql`${left} <= ${bindIfParam(right, left)}`;
|
|
9198
|
+
};
|
|
9199
|
+
function inArray(column, values) {
|
|
9200
|
+
if (Array.isArray(values)) {
|
|
9201
|
+
if (values.length === 0) {
|
|
9202
|
+
return sql`false`;
|
|
9122
9203
|
}
|
|
9123
|
-
|
|
9124
|
-
this.table = table;
|
|
9204
|
+
return sql`${column} in ${values.map((v) => bindIfParam(v, column))}`;
|
|
9125
9205
|
}
|
|
9126
|
-
|
|
9206
|
+
return sql`${column} in ${bindIfParam(values, column)}`;
|
|
9127
9207
|
}
|
|
9128
|
-
|
|
9129
|
-
|
|
9130
|
-
|
|
9131
|
-
|
|
9208
|
+
function notInArray(column, values) {
|
|
9209
|
+
if (Array.isArray(values)) {
|
|
9210
|
+
if (values.length === 0) {
|
|
9211
|
+
return sql`true`;
|
|
9212
|
+
}
|
|
9213
|
+
return sql`${column} not in ${values.map((v) => bindIfParam(v, column))}`;
|
|
9132
9214
|
}
|
|
9133
|
-
|
|
9134
|
-
|
|
9135
|
-
|
|
9215
|
+
return sql`${column} not in ${bindIfParam(values, column)}`;
|
|
9216
|
+
}
|
|
9217
|
+
function isNull(value) {
|
|
9218
|
+
return sql`${value} is null`;
|
|
9219
|
+
}
|
|
9220
|
+
function isNotNull(value) {
|
|
9221
|
+
return sql`${value} is not null`;
|
|
9222
|
+
}
|
|
9223
|
+
function exists(subquery) {
|
|
9224
|
+
return sql`exists ${subquery}`;
|
|
9225
|
+
}
|
|
9226
|
+
function notExists(subquery) {
|
|
9227
|
+
return sql`not exists ${subquery}`;
|
|
9228
|
+
}
|
|
9229
|
+
function between(column, min, max) {
|
|
9230
|
+
return sql`${column} between ${bindIfParam(min, column)} and ${bindIfParam(
|
|
9231
|
+
max,
|
|
9232
|
+
column
|
|
9233
|
+
)}`;
|
|
9234
|
+
}
|
|
9235
|
+
function notBetween(column, min, max) {
|
|
9236
|
+
return sql`${column} not between ${bindIfParam(
|
|
9237
|
+
min,
|
|
9238
|
+
column
|
|
9239
|
+
)} and ${bindIfParam(max, column)}`;
|
|
9240
|
+
}
|
|
9241
|
+
function like(column, value) {
|
|
9242
|
+
return sql`${column} like ${value}`;
|
|
9243
|
+
}
|
|
9244
|
+
function notLike(column, value) {
|
|
9245
|
+
return sql`${column} not like ${value}`;
|
|
9246
|
+
}
|
|
9247
|
+
function ilike(column, value) {
|
|
9248
|
+
return sql`${column} ilike ${value}`;
|
|
9249
|
+
}
|
|
9250
|
+
function notIlike(column, value) {
|
|
9251
|
+
return sql`${column} not ilike ${value}`;
|
|
9252
|
+
}
|
|
9253
|
+
function asc(column) {
|
|
9254
|
+
return sql`${column} asc`;
|
|
9255
|
+
}
|
|
9256
|
+
function desc(column) {
|
|
9257
|
+
return sql`${column} desc`;
|
|
9258
|
+
}
|
|
9259
|
+
class ConsoleLogWriter {
|
|
9260
|
+
static [entityKind] = "ConsoleLogWriter";
|
|
9261
|
+
write(message) {
|
|
9262
|
+
console.log(message);
|
|
9136
9263
|
}
|
|
9137
9264
|
}
|
|
9138
|
-
class
|
|
9139
|
-
static [entityKind] = "
|
|
9140
|
-
|
|
9141
|
-
|
|
9265
|
+
class DefaultLogger {
|
|
9266
|
+
static [entityKind] = "DefaultLogger";
|
|
9267
|
+
writer;
|
|
9268
|
+
constructor(config) {
|
|
9269
|
+
this.writer = config?.writer ?? new ConsoleLogWriter();
|
|
9142
9270
|
}
|
|
9143
|
-
|
|
9144
|
-
|
|
9145
|
-
|
|
9146
|
-
|
|
9147
|
-
|
|
9148
|
-
|
|
9149
|
-
|
|
9150
|
-
}
|
|
9151
|
-
|
|
9271
|
+
logQuery(query, params) {
|
|
9272
|
+
const stringifiedParams = params.map((p) => {
|
|
9273
|
+
try {
|
|
9274
|
+
return JSON.stringify(p);
|
|
9275
|
+
} catch {
|
|
9276
|
+
return String(p);
|
|
9277
|
+
}
|
|
9278
|
+
});
|
|
9279
|
+
const paramsStr = stringifiedParams.length ? ` -- params: [${stringifiedParams.join(", ")}]` : "";
|
|
9280
|
+
this.writer.write(`Query: ${query}${paramsStr}`);
|
|
9152
9281
|
}
|
|
9153
|
-
|
|
9154
|
-
|
|
9282
|
+
}
|
|
9283
|
+
class NoopLogger {
|
|
9284
|
+
static [entityKind] = "NoopLogger";
|
|
9285
|
+
logQuery() {
|
|
9155
9286
|
}
|
|
9156
9287
|
}
|
|
9157
|
-
class
|
|
9158
|
-
static [entityKind] = "
|
|
9159
|
-
|
|
9160
|
-
|
|
9288
|
+
class QueryPromise {
|
|
9289
|
+
static [entityKind] = "QueryPromise";
|
|
9290
|
+
[Symbol.toStringTag] = "QueryPromise";
|
|
9291
|
+
catch(onRejected) {
|
|
9292
|
+
return this.then(void 0, onRejected);
|
|
9161
9293
|
}
|
|
9162
|
-
|
|
9163
|
-
|
|
9164
|
-
|
|
9165
|
-
|
|
9166
|
-
|
|
9294
|
+
finally(onFinally) {
|
|
9295
|
+
return this.then(
|
|
9296
|
+
(value) => {
|
|
9297
|
+
onFinally?.();
|
|
9298
|
+
return value;
|
|
9299
|
+
},
|
|
9300
|
+
(reason) => {
|
|
9301
|
+
onFinally?.();
|
|
9302
|
+
throw reason;
|
|
9303
|
+
}
|
|
9167
9304
|
);
|
|
9168
9305
|
}
|
|
9306
|
+
then(onFulfilled, onRejected) {
|
|
9307
|
+
return this.execute().then(onFulfilled, onRejected);
|
|
9308
|
+
}
|
|
9169
9309
|
}
|
|
9170
|
-
|
|
9171
|
-
|
|
9172
|
-
|
|
9173
|
-
|
|
9310
|
+
function mapResultRow(columns, row, joinsNotNullableMap) {
|
|
9311
|
+
const nullifyMap = {};
|
|
9312
|
+
const result = columns.reduce(
|
|
9313
|
+
(result2, { path: path2, field }, columnIndex) => {
|
|
9314
|
+
let decoder;
|
|
9315
|
+
if (is(field, Column)) {
|
|
9316
|
+
decoder = field;
|
|
9317
|
+
} else if (is(field, SQL)) {
|
|
9318
|
+
decoder = field.decoder;
|
|
9319
|
+
} else {
|
|
9320
|
+
decoder = field.sql.decoder;
|
|
9321
|
+
}
|
|
9322
|
+
let node = result2;
|
|
9323
|
+
for (const [pathChunkIndex, pathChunk] of path2.entries()) {
|
|
9324
|
+
if (pathChunkIndex < path2.length - 1) {
|
|
9325
|
+
if (!(pathChunk in node)) {
|
|
9326
|
+
node[pathChunk] = {};
|
|
9327
|
+
}
|
|
9328
|
+
node = node[pathChunk];
|
|
9329
|
+
} else {
|
|
9330
|
+
const rawValue = row[columnIndex];
|
|
9331
|
+
const value = node[pathChunk] = rawValue === null ? null : decoder.mapFromDriverValue(rawValue);
|
|
9332
|
+
if (joinsNotNullableMap && is(field, Column) && path2.length === 2) {
|
|
9333
|
+
const objectName = path2[0];
|
|
9334
|
+
if (!(objectName in nullifyMap)) {
|
|
9335
|
+
nullifyMap[objectName] = value === null ? getTableName(field.table) : false;
|
|
9336
|
+
} else if (typeof nullifyMap[objectName] === "string" && nullifyMap[objectName] !== getTableName(field.table)) {
|
|
9337
|
+
nullifyMap[objectName] = false;
|
|
9338
|
+
}
|
|
9339
|
+
}
|
|
9340
|
+
}
|
|
9341
|
+
}
|
|
9342
|
+
return result2;
|
|
9343
|
+
},
|
|
9344
|
+
{}
|
|
9345
|
+
);
|
|
9346
|
+
if (joinsNotNullableMap && Object.keys(nullifyMap).length > 0) {
|
|
9347
|
+
for (const [objectName, tableName] of Object.entries(nullifyMap)) {
|
|
9348
|
+
if (typeof tableName === "string" && !joinsNotNullableMap[tableName]) {
|
|
9349
|
+
result[objectName] = null;
|
|
9350
|
+
}
|
|
9351
|
+
}
|
|
9174
9352
|
}
|
|
9175
|
-
|
|
9176
|
-
|
|
9177
|
-
|
|
9353
|
+
return result;
|
|
9354
|
+
}
|
|
9355
|
+
function orderSelectedFields(fields, pathPrefix) {
|
|
9356
|
+
return Object.entries(fields).reduce((result, [name, field]) => {
|
|
9357
|
+
if (typeof name !== "string") {
|
|
9358
|
+
return result;
|
|
9178
9359
|
}
|
|
9179
|
-
|
|
9180
|
-
|
|
9181
|
-
|
|
9360
|
+
const newPath = pathPrefix ? [...pathPrefix, name] : [name];
|
|
9361
|
+
if (is(field, Column) || is(field, SQL) || is(field, SQL.Aliased)) {
|
|
9362
|
+
result.push({ path: newPath, field });
|
|
9363
|
+
} else if (is(field, Table)) {
|
|
9364
|
+
result.push(...orderSelectedFields(field[Table.Symbol.Columns], newPath));
|
|
9365
|
+
} else {
|
|
9366
|
+
result.push(...orderSelectedFields(field, newPath));
|
|
9182
9367
|
}
|
|
9183
|
-
return
|
|
9368
|
+
return result;
|
|
9369
|
+
}, []);
|
|
9370
|
+
}
|
|
9371
|
+
function haveSameKeys(left, right) {
|
|
9372
|
+
const leftKeys = Object.keys(left);
|
|
9373
|
+
const rightKeys = Object.keys(right);
|
|
9374
|
+
if (leftKeys.length !== rightKeys.length) {
|
|
9375
|
+
return false;
|
|
9184
9376
|
}
|
|
9185
|
-
|
|
9186
|
-
|
|
9377
|
+
for (const [index2, key] of leftKeys.entries()) {
|
|
9378
|
+
if (key !== rightKeys[index2]) {
|
|
9379
|
+
return false;
|
|
9380
|
+
}
|
|
9187
9381
|
}
|
|
9382
|
+
return true;
|
|
9188
9383
|
}
|
|
9189
|
-
|
|
9190
|
-
|
|
9191
|
-
|
|
9192
|
-
|
|
9384
|
+
function mapUpdateSet(table, values) {
|
|
9385
|
+
const entries = Object.entries(values).filter(([, value]) => value !== void 0).map(([key, value]) => {
|
|
9386
|
+
if (is(value, SQL) || is(value, Column)) {
|
|
9387
|
+
return [key, value];
|
|
9388
|
+
} else {
|
|
9389
|
+
return [key, new Param(value, table[Table.Symbol.Columns][key])];
|
|
9390
|
+
}
|
|
9391
|
+
});
|
|
9392
|
+
if (entries.length === 0) {
|
|
9393
|
+
throw new Error("No values to set");
|
|
9193
9394
|
}
|
|
9194
|
-
|
|
9195
|
-
|
|
9196
|
-
|
|
9395
|
+
return Object.fromEntries(entries);
|
|
9396
|
+
}
|
|
9397
|
+
function applyMixins(baseClass, extendedClasses) {
|
|
9398
|
+
for (const extendedClass of extendedClasses) {
|
|
9399
|
+
for (const name of Object.getOwnPropertyNames(extendedClass.prototype)) {
|
|
9400
|
+
if (name === "constructor")
|
|
9401
|
+
continue;
|
|
9402
|
+
Object.defineProperty(
|
|
9403
|
+
baseClass.prototype,
|
|
9404
|
+
name,
|
|
9405
|
+
Object.getOwnPropertyDescriptor(extendedClass.prototype, name) || /* @__PURE__ */ Object.create(null)
|
|
9406
|
+
);
|
|
9407
|
+
}
|
|
9197
9408
|
}
|
|
9198
9409
|
}
|
|
9199
|
-
|
|
9200
|
-
|
|
9201
|
-
|
|
9202
|
-
|
|
9410
|
+
function getTableColumns(table) {
|
|
9411
|
+
return table[Table.Symbol.Columns];
|
|
9412
|
+
}
|
|
9413
|
+
function getTableLikeName(table) {
|
|
9414
|
+
return is(table, Subquery) ? table._.alias : is(table, View) ? table[ViewBaseConfig].name : is(table, SQL) ? void 0 : table[Table.Symbol.IsAlias] ? table[Table.Symbol.Name] : table[Table.Symbol.BaseName];
|
|
9415
|
+
}
|
|
9416
|
+
function getColumnNameAndConfig(a, b) {
|
|
9417
|
+
return {
|
|
9418
|
+
name: typeof a === "string" && a.length > 0 ? a : "",
|
|
9419
|
+
config: typeof a === "object" ? a : b
|
|
9420
|
+
};
|
|
9421
|
+
}
|
|
9422
|
+
const InlineForeignKeys$1 = /* @__PURE__ */ Symbol.for("drizzle:PgInlineForeignKeys");
|
|
9423
|
+
const EnableRLS = /* @__PURE__ */ Symbol.for("drizzle:EnableRLS");
|
|
9424
|
+
class PgTable extends Table {
|
|
9425
|
+
static [entityKind] = "PgTable";
|
|
9426
|
+
/** @internal */
|
|
9427
|
+
static Symbol = Object.assign({}, Table.Symbol, {
|
|
9428
|
+
InlineForeignKeys: InlineForeignKeys$1,
|
|
9429
|
+
EnableRLS
|
|
9430
|
+
});
|
|
9431
|
+
/**@internal */
|
|
9432
|
+
[InlineForeignKeys$1] = [];
|
|
9433
|
+
/** @internal */
|
|
9434
|
+
[EnableRLS] = false;
|
|
9435
|
+
/** @internal */
|
|
9436
|
+
[Table.Symbol.ExtraConfigBuilder] = void 0;
|
|
9437
|
+
}
|
|
9438
|
+
let PrimaryKeyBuilder$1 = class PrimaryKeyBuilder {
|
|
9439
|
+
static [entityKind] = "PgPrimaryKeyBuilder";
|
|
9440
|
+
/** @internal */
|
|
9441
|
+
columns;
|
|
9442
|
+
/** @internal */
|
|
9443
|
+
name;
|
|
9444
|
+
constructor(columns, name) {
|
|
9445
|
+
this.columns = columns;
|
|
9446
|
+
this.name = name;
|
|
9447
|
+
}
|
|
9448
|
+
/** @internal */
|
|
9449
|
+
build(table) {
|
|
9450
|
+
return new PrimaryKey$1(table, this.columns, this.name);
|
|
9451
|
+
}
|
|
9452
|
+
};
|
|
9453
|
+
let PrimaryKey$1 = class PrimaryKey {
|
|
9454
|
+
constructor(table, columns, name) {
|
|
9455
|
+
this.table = table;
|
|
9456
|
+
this.columns = columns;
|
|
9457
|
+
this.name = name;
|
|
9458
|
+
}
|
|
9459
|
+
static [entityKind] = "PgPrimaryKey";
|
|
9460
|
+
columns;
|
|
9461
|
+
name;
|
|
9462
|
+
getName() {
|
|
9463
|
+
return this.name ?? `${this.table[PgTable.Symbol.Name]}_${this.columns.map((column) => column.name).join("_")}_pk`;
|
|
9464
|
+
}
|
|
9465
|
+
};
|
|
9466
|
+
class Relation {
|
|
9467
|
+
constructor(sourceTable, referencedTable, relationName) {
|
|
9468
|
+
this.sourceTable = sourceTable;
|
|
9469
|
+
this.referencedTable = referencedTable;
|
|
9470
|
+
this.relationName = relationName;
|
|
9471
|
+
this.referencedTableName = referencedTable[Table.Symbol.Name];
|
|
9472
|
+
}
|
|
9473
|
+
static [entityKind] = "Relation";
|
|
9474
|
+
referencedTableName;
|
|
9475
|
+
fieldName;
|
|
9476
|
+
}
|
|
9477
|
+
class Relations {
|
|
9478
|
+
constructor(table, config) {
|
|
9479
|
+
this.table = table;
|
|
9480
|
+
this.config = config;
|
|
9203
9481
|
}
|
|
9482
|
+
static [entityKind] = "Relations";
|
|
9204
9483
|
}
|
|
9205
|
-
|
|
9206
|
-
|
|
9207
|
-
|
|
9208
|
-
|
|
9484
|
+
class One extends Relation {
|
|
9485
|
+
constructor(sourceTable, referencedTable, config, isNullable) {
|
|
9486
|
+
super(sourceTable, referencedTable, config?.relationName);
|
|
9487
|
+
this.config = config;
|
|
9488
|
+
this.isNullable = isNullable;
|
|
9489
|
+
}
|
|
9490
|
+
static [entityKind] = "One";
|
|
9491
|
+
withFieldName(fieldName) {
|
|
9492
|
+
const relation = new One(
|
|
9493
|
+
this.sourceTable,
|
|
9494
|
+
this.referencedTable,
|
|
9495
|
+
this.config,
|
|
9496
|
+
this.isNullable
|
|
9497
|
+
);
|
|
9498
|
+
relation.fieldName = fieldName;
|
|
9499
|
+
return relation;
|
|
9209
9500
|
}
|
|
9210
|
-
|
|
9211
|
-
|
|
9501
|
+
}
|
|
9502
|
+
class Many extends Relation {
|
|
9503
|
+
constructor(sourceTable, referencedTable, config) {
|
|
9504
|
+
super(sourceTable, referencedTable, config?.relationName);
|
|
9505
|
+
this.config = config;
|
|
9506
|
+
}
|
|
9507
|
+
static [entityKind] = "Many";
|
|
9508
|
+
withFieldName(fieldName) {
|
|
9509
|
+
const relation = new Many(
|
|
9510
|
+
this.sourceTable,
|
|
9511
|
+
this.referencedTable,
|
|
9512
|
+
this.config
|
|
9513
|
+
);
|
|
9514
|
+
relation.fieldName = fieldName;
|
|
9515
|
+
return relation;
|
|
9212
9516
|
}
|
|
9213
|
-
return new SQLiteBlobBufferBuilder(name);
|
|
9214
9517
|
}
|
|
9215
|
-
|
|
9216
|
-
|
|
9217
|
-
|
|
9218
|
-
|
|
9219
|
-
|
|
9220
|
-
|
|
9518
|
+
function getOperators() {
|
|
9519
|
+
return {
|
|
9520
|
+
and,
|
|
9521
|
+
between,
|
|
9522
|
+
eq,
|
|
9523
|
+
exists,
|
|
9524
|
+
gt,
|
|
9525
|
+
gte,
|
|
9526
|
+
ilike,
|
|
9527
|
+
inArray,
|
|
9528
|
+
isNull,
|
|
9529
|
+
isNotNull,
|
|
9530
|
+
like,
|
|
9531
|
+
lt,
|
|
9532
|
+
lte,
|
|
9533
|
+
ne,
|
|
9534
|
+
not,
|
|
9535
|
+
notBetween,
|
|
9536
|
+
notExists,
|
|
9537
|
+
notLike,
|
|
9538
|
+
notIlike,
|
|
9539
|
+
notInArray,
|
|
9540
|
+
or,
|
|
9541
|
+
sql
|
|
9542
|
+
};
|
|
9543
|
+
}
|
|
9544
|
+
function getOrderByOperators() {
|
|
9545
|
+
return {
|
|
9546
|
+
sql,
|
|
9547
|
+
asc,
|
|
9548
|
+
desc
|
|
9549
|
+
};
|
|
9550
|
+
}
|
|
9551
|
+
function extractTablesRelationalConfig(schema2, configHelpers) {
|
|
9552
|
+
if (Object.keys(schema2).length === 1 && "default" in schema2 && !is(schema2["default"], Table)) {
|
|
9553
|
+
schema2 = schema2["default"];
|
|
9554
|
+
}
|
|
9555
|
+
const tableNamesMap = {};
|
|
9556
|
+
const relationsBuffer = {};
|
|
9557
|
+
const tablesConfig = {};
|
|
9558
|
+
for (const [key, value] of Object.entries(schema2)) {
|
|
9559
|
+
if (is(value, Table)) {
|
|
9560
|
+
const dbName = getTableUniqueName(value);
|
|
9561
|
+
const bufferedRelations = relationsBuffer[dbName];
|
|
9562
|
+
tableNamesMap[dbName] = key;
|
|
9563
|
+
tablesConfig[key] = {
|
|
9564
|
+
tsName: key,
|
|
9565
|
+
dbName: value[Table.Symbol.Name],
|
|
9566
|
+
schema: value[Table.Symbol.Schema],
|
|
9567
|
+
columns: value[Table.Symbol.Columns],
|
|
9568
|
+
relations: bufferedRelations?.relations ?? {},
|
|
9569
|
+
primaryKey: bufferedRelations?.primaryKey ?? []
|
|
9570
|
+
};
|
|
9571
|
+
for (const column of Object.values(
|
|
9572
|
+
value[Table.Symbol.Columns]
|
|
9573
|
+
)) {
|
|
9574
|
+
if (column.primary) {
|
|
9575
|
+
tablesConfig[key].primaryKey.push(column);
|
|
9576
|
+
}
|
|
9577
|
+
}
|
|
9578
|
+
const extraConfig = value[Table.Symbol.ExtraConfigBuilder]?.(value[Table.Symbol.ExtraConfigColumns]);
|
|
9579
|
+
if (extraConfig) {
|
|
9580
|
+
for (const configEntry of Object.values(extraConfig)) {
|
|
9581
|
+
if (is(configEntry, PrimaryKeyBuilder$1)) {
|
|
9582
|
+
tablesConfig[key].primaryKey.push(...configEntry.columns);
|
|
9583
|
+
}
|
|
9584
|
+
}
|
|
9585
|
+
}
|
|
9586
|
+
} else if (is(value, Relations)) {
|
|
9587
|
+
const dbName = getTableUniqueName(value.table);
|
|
9588
|
+
const tableName = tableNamesMap[dbName];
|
|
9589
|
+
const relations2 = value.config(
|
|
9590
|
+
configHelpers(value.table)
|
|
9591
|
+
);
|
|
9592
|
+
let primaryKey2;
|
|
9593
|
+
for (const [relationName, relation] of Object.entries(relations2)) {
|
|
9594
|
+
if (tableName) {
|
|
9595
|
+
const tableConfig = tablesConfig[tableName];
|
|
9596
|
+
tableConfig.relations[relationName] = relation;
|
|
9597
|
+
} else {
|
|
9598
|
+
if (!(dbName in relationsBuffer)) {
|
|
9599
|
+
relationsBuffer[dbName] = {
|
|
9600
|
+
relations: {},
|
|
9601
|
+
primaryKey: primaryKey2
|
|
9602
|
+
};
|
|
9603
|
+
}
|
|
9604
|
+
relationsBuffer[dbName].relations[relationName] = relation;
|
|
9605
|
+
}
|
|
9606
|
+
}
|
|
9607
|
+
}
|
|
9221
9608
|
}
|
|
9222
|
-
|
|
9223
|
-
|
|
9224
|
-
|
|
9609
|
+
return { tables: tablesConfig, tableNamesMap };
|
|
9610
|
+
}
|
|
9611
|
+
function createOne(sourceTable) {
|
|
9612
|
+
return function one(table, config) {
|
|
9613
|
+
return new One(
|
|
9614
|
+
sourceTable,
|
|
9225
9615
|
table,
|
|
9226
|
-
|
|
9616
|
+
config,
|
|
9617
|
+
config?.fields.reduce((res, f) => res && f.notNull, true) ?? false
|
|
9618
|
+
);
|
|
9619
|
+
};
|
|
9620
|
+
}
|
|
9621
|
+
function createMany(sourceTable) {
|
|
9622
|
+
return function many(referencedTable, config) {
|
|
9623
|
+
return new Many(sourceTable, referencedTable, config);
|
|
9624
|
+
};
|
|
9625
|
+
}
|
|
9626
|
+
function normalizeRelation(schema2, tableNamesMap, relation) {
|
|
9627
|
+
if (is(relation, One) && relation.config) {
|
|
9628
|
+
return {
|
|
9629
|
+
fields: relation.config.fields,
|
|
9630
|
+
references: relation.config.references
|
|
9631
|
+
};
|
|
9632
|
+
}
|
|
9633
|
+
const referencedTableTsName = tableNamesMap[getTableUniqueName(relation.referencedTable)];
|
|
9634
|
+
if (!referencedTableTsName) {
|
|
9635
|
+
throw new Error(
|
|
9636
|
+
`Table "${relation.referencedTable[Table.Symbol.Name]}" not found in schema`
|
|
9637
|
+
);
|
|
9638
|
+
}
|
|
9639
|
+
const referencedTableConfig = schema2[referencedTableTsName];
|
|
9640
|
+
if (!referencedTableConfig) {
|
|
9641
|
+
throw new Error(`Table "${referencedTableTsName}" not found in schema`);
|
|
9642
|
+
}
|
|
9643
|
+
const sourceTable = relation.sourceTable;
|
|
9644
|
+
const sourceTableTsName = tableNamesMap[getTableUniqueName(sourceTable)];
|
|
9645
|
+
if (!sourceTableTsName) {
|
|
9646
|
+
throw new Error(
|
|
9647
|
+
`Table "${sourceTable[Table.Symbol.Name]}" not found in schema`
|
|
9648
|
+
);
|
|
9649
|
+
}
|
|
9650
|
+
const reverseRelations = [];
|
|
9651
|
+
for (const referencedTableRelation of Object.values(
|
|
9652
|
+
referencedTableConfig.relations
|
|
9653
|
+
)) {
|
|
9654
|
+
if (relation.relationName && relation !== referencedTableRelation && referencedTableRelation.relationName === relation.relationName || !relation.relationName && referencedTableRelation.referencedTable === relation.sourceTable) {
|
|
9655
|
+
reverseRelations.push(referencedTableRelation);
|
|
9656
|
+
}
|
|
9657
|
+
}
|
|
9658
|
+
if (reverseRelations.length > 1) {
|
|
9659
|
+
throw relation.relationName ? new Error(
|
|
9660
|
+
`There are multiple relations with name "${relation.relationName}" in table "${referencedTableTsName}"`
|
|
9661
|
+
) : new Error(
|
|
9662
|
+
`There are multiple relations between "${referencedTableTsName}" and "${relation.sourceTable[Table.Symbol.Name]}". Please specify relation name`
|
|
9227
9663
|
);
|
|
9228
9664
|
}
|
|
9665
|
+
if (reverseRelations[0] && is(reverseRelations[0], One) && reverseRelations[0].config) {
|
|
9666
|
+
return {
|
|
9667
|
+
fields: reverseRelations[0].config.references,
|
|
9668
|
+
references: reverseRelations[0].config.fields
|
|
9669
|
+
};
|
|
9670
|
+
}
|
|
9671
|
+
throw new Error(
|
|
9672
|
+
`There is not enough information to infer relation "${sourceTableTsName}.${relation.fieldName}"`
|
|
9673
|
+
);
|
|
9229
9674
|
}
|
|
9230
|
-
|
|
9231
|
-
|
|
9232
|
-
|
|
9233
|
-
|
|
9234
|
-
|
|
9675
|
+
function createTableRelationsHelpers(sourceTable) {
|
|
9676
|
+
return {
|
|
9677
|
+
one: createOne(sourceTable),
|
|
9678
|
+
many: createMany(sourceTable)
|
|
9679
|
+
};
|
|
9680
|
+
}
|
|
9681
|
+
function mapRelationalRow(tablesConfig, tableConfig, row, buildQueryResultSelection, mapColumnValue = (value) => value) {
|
|
9682
|
+
const result = {};
|
|
9683
|
+
for (const [
|
|
9684
|
+
selectionItemIndex,
|
|
9685
|
+
selectionItem
|
|
9686
|
+
] of buildQueryResultSelection.entries()) {
|
|
9687
|
+
if (selectionItem.isJson) {
|
|
9688
|
+
const relation = tableConfig.relations[selectionItem.tsKey];
|
|
9689
|
+
const rawSubRows = row[selectionItemIndex];
|
|
9690
|
+
const subRows = typeof rawSubRows === "string" ? JSON.parse(rawSubRows) : rawSubRows;
|
|
9691
|
+
result[selectionItem.tsKey] = is(relation, One) ? subRows && mapRelationalRow(
|
|
9692
|
+
tablesConfig,
|
|
9693
|
+
tablesConfig[selectionItem.relationTableTsKey],
|
|
9694
|
+
subRows,
|
|
9695
|
+
selectionItem.selection,
|
|
9696
|
+
mapColumnValue
|
|
9697
|
+
) : subRows.map(
|
|
9698
|
+
(subRow) => mapRelationalRow(
|
|
9699
|
+
tablesConfig,
|
|
9700
|
+
tablesConfig[selectionItem.relationTableTsKey],
|
|
9701
|
+
subRow,
|
|
9702
|
+
selectionItem.selection,
|
|
9703
|
+
mapColumnValue
|
|
9704
|
+
)
|
|
9705
|
+
);
|
|
9706
|
+
} else {
|
|
9707
|
+
const value = mapColumnValue(row[selectionItemIndex]);
|
|
9708
|
+
const field = selectionItem.field;
|
|
9709
|
+
let decoder;
|
|
9710
|
+
if (is(field, Column)) {
|
|
9711
|
+
decoder = field;
|
|
9712
|
+
} else if (is(field, SQL)) {
|
|
9713
|
+
decoder = field.decoder;
|
|
9714
|
+
} else {
|
|
9715
|
+
decoder = field.sql.decoder;
|
|
9716
|
+
}
|
|
9717
|
+
result[selectionItem.tsKey] = value === null ? null : decoder.mapFromDriverValue(value);
|
|
9718
|
+
}
|
|
9719
|
+
}
|
|
9720
|
+
return result;
|
|
9721
|
+
}
|
|
9722
|
+
class SelectionProxyHandler {
|
|
9723
|
+
static [entityKind] = "SelectionProxyHandler";
|
|
9724
|
+
config;
|
|
9725
|
+
constructor(config) {
|
|
9726
|
+
this.config = { ...config };
|
|
9727
|
+
}
|
|
9728
|
+
get(subquery, prop) {
|
|
9729
|
+
if (prop === "_") {
|
|
9730
|
+
return {
|
|
9731
|
+
...subquery["_"],
|
|
9732
|
+
selectedFields: new Proxy(
|
|
9733
|
+
subquery._.selectedFields,
|
|
9734
|
+
this
|
|
9735
|
+
)
|
|
9736
|
+
};
|
|
9737
|
+
}
|
|
9738
|
+
if (prop === ViewBaseConfig) {
|
|
9739
|
+
return {
|
|
9740
|
+
...subquery[ViewBaseConfig],
|
|
9741
|
+
selectedFields: new Proxy(
|
|
9742
|
+
subquery[ViewBaseConfig].selectedFields,
|
|
9743
|
+
this
|
|
9744
|
+
)
|
|
9745
|
+
};
|
|
9746
|
+
}
|
|
9747
|
+
if (typeof prop === "symbol") {
|
|
9748
|
+
return subquery[prop];
|
|
9749
|
+
}
|
|
9750
|
+
const columns = is(subquery, Subquery) ? subquery._.selectedFields : is(subquery, View) ? subquery[ViewBaseConfig].selectedFields : subquery;
|
|
9751
|
+
const value = columns[prop];
|
|
9752
|
+
if (is(value, SQL.Aliased)) {
|
|
9753
|
+
if (this.config.sqlAliasedBehavior === "sql" && !value.isSelectionField) {
|
|
9754
|
+
return value.sql;
|
|
9755
|
+
}
|
|
9756
|
+
const newValue = value.clone();
|
|
9757
|
+
newValue.isSelectionField = true;
|
|
9758
|
+
return newValue;
|
|
9759
|
+
}
|
|
9760
|
+
if (is(value, SQL)) {
|
|
9761
|
+
if (this.config.sqlBehavior === "sql") {
|
|
9762
|
+
return value;
|
|
9763
|
+
}
|
|
9764
|
+
throw new Error(
|
|
9765
|
+
`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.`
|
|
9766
|
+
);
|
|
9767
|
+
}
|
|
9768
|
+
if (is(value, Column)) {
|
|
9769
|
+
if (this.config.alias) {
|
|
9770
|
+
return new Proxy(
|
|
9771
|
+
value,
|
|
9772
|
+
new ColumnAliasProxyHandler(
|
|
9773
|
+
new Proxy(
|
|
9774
|
+
value.table,
|
|
9775
|
+
new TableAliasProxyHandler(this.config.alias, this.config.replaceOriginalName ?? false)
|
|
9776
|
+
)
|
|
9777
|
+
)
|
|
9778
|
+
);
|
|
9779
|
+
}
|
|
9780
|
+
return value;
|
|
9781
|
+
}
|
|
9782
|
+
if (typeof value !== "object" || value === null) {
|
|
9783
|
+
return value;
|
|
9784
|
+
}
|
|
9785
|
+
return new Proxy(value, new SelectionProxyHandler(this.config));
|
|
9786
|
+
}
|
|
9787
|
+
}
|
|
9788
|
+
class ForeignKeyBuilder {
|
|
9789
|
+
static [entityKind] = "SQLiteForeignKeyBuilder";
|
|
9790
|
+
/** @internal */
|
|
9791
|
+
reference;
|
|
9792
|
+
/** @internal */
|
|
9793
|
+
_onUpdate;
|
|
9794
|
+
/** @internal */
|
|
9795
|
+
_onDelete;
|
|
9796
|
+
constructor(config, actions) {
|
|
9797
|
+
this.reference = () => {
|
|
9798
|
+
const { name, columns, foreignColumns } = config();
|
|
9799
|
+
return { name, columns, foreignTable: foreignColumns[0].table, foreignColumns };
|
|
9800
|
+
};
|
|
9801
|
+
if (actions) {
|
|
9802
|
+
this._onUpdate = actions.onUpdate;
|
|
9803
|
+
this._onDelete = actions.onDelete;
|
|
9804
|
+
}
|
|
9805
|
+
}
|
|
9806
|
+
onUpdate(action) {
|
|
9807
|
+
this._onUpdate = action;
|
|
9808
|
+
return this;
|
|
9809
|
+
}
|
|
9810
|
+
onDelete(action) {
|
|
9811
|
+
this._onDelete = action;
|
|
9812
|
+
return this;
|
|
9813
|
+
}
|
|
9814
|
+
/** @internal */
|
|
9815
|
+
build(table) {
|
|
9816
|
+
return new ForeignKey(table, this);
|
|
9817
|
+
}
|
|
9818
|
+
}
|
|
9819
|
+
class ForeignKey {
|
|
9820
|
+
constructor(table, builder) {
|
|
9821
|
+
this.table = table;
|
|
9822
|
+
this.reference = builder.reference;
|
|
9823
|
+
this.onUpdate = builder._onUpdate;
|
|
9824
|
+
this.onDelete = builder._onDelete;
|
|
9825
|
+
}
|
|
9826
|
+
static [entityKind] = "SQLiteForeignKey";
|
|
9827
|
+
reference;
|
|
9828
|
+
onUpdate;
|
|
9829
|
+
onDelete;
|
|
9830
|
+
getName() {
|
|
9831
|
+
const { name, columns, foreignColumns } = this.reference();
|
|
9832
|
+
const columnNames = columns.map((column) => column.name);
|
|
9833
|
+
const foreignColumnNames = foreignColumns.map((column) => column.name);
|
|
9834
|
+
const chunks = [
|
|
9835
|
+
this.table[TableName],
|
|
9836
|
+
...columnNames,
|
|
9837
|
+
foreignColumns[0].table[TableName],
|
|
9838
|
+
...foreignColumnNames
|
|
9839
|
+
];
|
|
9840
|
+
return name ?? `${chunks.join("_")}_fk`;
|
|
9841
|
+
}
|
|
9842
|
+
}
|
|
9843
|
+
function uniqueKeyName(table, columns) {
|
|
9844
|
+
return `${table[TableName]}_${columns.join("_")}_unique`;
|
|
9845
|
+
}
|
|
9846
|
+
class SQLiteColumnBuilder extends ColumnBuilder {
|
|
9847
|
+
static [entityKind] = "SQLiteColumnBuilder";
|
|
9848
|
+
foreignKeyConfigs = [];
|
|
9849
|
+
references(ref, actions = {}) {
|
|
9850
|
+
this.foreignKeyConfigs.push({ ref, actions });
|
|
9851
|
+
return this;
|
|
9852
|
+
}
|
|
9853
|
+
unique(name) {
|
|
9854
|
+
this.config.isUnique = true;
|
|
9855
|
+
this.config.uniqueName = name;
|
|
9856
|
+
return this;
|
|
9857
|
+
}
|
|
9858
|
+
generatedAlwaysAs(as, config) {
|
|
9859
|
+
this.config.generated = {
|
|
9860
|
+
as,
|
|
9861
|
+
type: "always",
|
|
9862
|
+
mode: config?.mode ?? "virtual"
|
|
9863
|
+
};
|
|
9864
|
+
return this;
|
|
9865
|
+
}
|
|
9866
|
+
/** @internal */
|
|
9867
|
+
buildForeignKeys(column, table) {
|
|
9868
|
+
return this.foreignKeyConfigs.map(({ ref, actions }) => {
|
|
9869
|
+
return ((ref2, actions2) => {
|
|
9870
|
+
const builder = new ForeignKeyBuilder(() => {
|
|
9871
|
+
const foreignColumn = ref2();
|
|
9872
|
+
return { columns: [column], foreignColumns: [foreignColumn] };
|
|
9873
|
+
});
|
|
9874
|
+
if (actions2.onUpdate) {
|
|
9875
|
+
builder.onUpdate(actions2.onUpdate);
|
|
9876
|
+
}
|
|
9877
|
+
if (actions2.onDelete) {
|
|
9878
|
+
builder.onDelete(actions2.onDelete);
|
|
9879
|
+
}
|
|
9880
|
+
return builder.build(table);
|
|
9881
|
+
})(ref, actions);
|
|
9882
|
+
});
|
|
9883
|
+
}
|
|
9884
|
+
}
|
|
9885
|
+
class SQLiteColumn extends Column {
|
|
9235
9886
|
constructor(table, config) {
|
|
9887
|
+
if (!config.uniqueName) {
|
|
9888
|
+
config.uniqueName = uniqueKeyName(table, [config.name]);
|
|
9889
|
+
}
|
|
9236
9890
|
super(table, config);
|
|
9237
|
-
this.
|
|
9238
|
-
|
|
9239
|
-
|
|
9891
|
+
this.table = table;
|
|
9892
|
+
}
|
|
9893
|
+
static [entityKind] = "SQLiteColumn";
|
|
9894
|
+
}
|
|
9895
|
+
class SQLiteBigIntBuilder extends SQLiteColumnBuilder {
|
|
9896
|
+
static [entityKind] = "SQLiteBigIntBuilder";
|
|
9897
|
+
constructor(name) {
|
|
9898
|
+
super(name, "bigint", "SQLiteBigInt");
|
|
9899
|
+
}
|
|
9900
|
+
/** @internal */
|
|
9901
|
+
build(table) {
|
|
9902
|
+
return new SQLiteBigInt(table, this.config);
|
|
9903
|
+
}
|
|
9904
|
+
}
|
|
9905
|
+
class SQLiteBigInt extends SQLiteColumn {
|
|
9906
|
+
static [entityKind] = "SQLiteBigInt";
|
|
9907
|
+
getSQLType() {
|
|
9908
|
+
return "blob";
|
|
9909
|
+
}
|
|
9910
|
+
mapFromDriverValue(value) {
|
|
9911
|
+
if (Buffer.isBuffer(value)) {
|
|
9912
|
+
return BigInt(value.toString());
|
|
9913
|
+
}
|
|
9914
|
+
if (value instanceof ArrayBuffer) {
|
|
9915
|
+
const decoder = new TextDecoder();
|
|
9916
|
+
return BigInt(decoder.decode(value));
|
|
9917
|
+
}
|
|
9918
|
+
return BigInt(String.fromCodePoint(...value));
|
|
9919
|
+
}
|
|
9920
|
+
mapToDriverValue(value) {
|
|
9921
|
+
return Buffer.from(value.toString());
|
|
9922
|
+
}
|
|
9923
|
+
}
|
|
9924
|
+
class SQLiteBlobJsonBuilder extends SQLiteColumnBuilder {
|
|
9925
|
+
static [entityKind] = "SQLiteBlobJsonBuilder";
|
|
9926
|
+
constructor(name) {
|
|
9927
|
+
super(name, "json", "SQLiteBlobJson");
|
|
9928
|
+
}
|
|
9929
|
+
/** @internal */
|
|
9930
|
+
build(table) {
|
|
9931
|
+
return new SQLiteBlobJson(
|
|
9932
|
+
table,
|
|
9933
|
+
this.config
|
|
9934
|
+
);
|
|
9935
|
+
}
|
|
9936
|
+
}
|
|
9937
|
+
class SQLiteBlobJson extends SQLiteColumn {
|
|
9938
|
+
static [entityKind] = "SQLiteBlobJson";
|
|
9939
|
+
getSQLType() {
|
|
9940
|
+
return "blob";
|
|
9941
|
+
}
|
|
9942
|
+
mapFromDriverValue(value) {
|
|
9943
|
+
if (Buffer.isBuffer(value)) {
|
|
9944
|
+
return JSON.parse(value.toString());
|
|
9945
|
+
}
|
|
9946
|
+
if (value instanceof ArrayBuffer) {
|
|
9947
|
+
const decoder = new TextDecoder();
|
|
9948
|
+
return JSON.parse(decoder.decode(value));
|
|
9949
|
+
}
|
|
9950
|
+
return JSON.parse(String.fromCodePoint(...value));
|
|
9951
|
+
}
|
|
9952
|
+
mapToDriverValue(value) {
|
|
9953
|
+
return Buffer.from(JSON.stringify(value));
|
|
9954
|
+
}
|
|
9955
|
+
}
|
|
9956
|
+
class SQLiteBlobBufferBuilder extends SQLiteColumnBuilder {
|
|
9957
|
+
static [entityKind] = "SQLiteBlobBufferBuilder";
|
|
9958
|
+
constructor(name) {
|
|
9959
|
+
super(name, "buffer", "SQLiteBlobBuffer");
|
|
9960
|
+
}
|
|
9961
|
+
/** @internal */
|
|
9962
|
+
build(table) {
|
|
9963
|
+
return new SQLiteBlobBuffer(table, this.config);
|
|
9964
|
+
}
|
|
9965
|
+
}
|
|
9966
|
+
class SQLiteBlobBuffer extends SQLiteColumn {
|
|
9967
|
+
static [entityKind] = "SQLiteBlobBuffer";
|
|
9968
|
+
getSQLType() {
|
|
9969
|
+
return "blob";
|
|
9970
|
+
}
|
|
9971
|
+
}
|
|
9972
|
+
function blob(a, b) {
|
|
9973
|
+
const { name, config } = getColumnNameAndConfig(a, b);
|
|
9974
|
+
if (config?.mode === "json") {
|
|
9975
|
+
return new SQLiteBlobJsonBuilder(name);
|
|
9976
|
+
}
|
|
9977
|
+
if (config?.mode === "bigint") {
|
|
9978
|
+
return new SQLiteBigIntBuilder(name);
|
|
9979
|
+
}
|
|
9980
|
+
return new SQLiteBlobBufferBuilder(name);
|
|
9981
|
+
}
|
|
9982
|
+
class SQLiteCustomColumnBuilder extends SQLiteColumnBuilder {
|
|
9983
|
+
static [entityKind] = "SQLiteCustomColumnBuilder";
|
|
9984
|
+
constructor(name, fieldConfig, customTypeParams) {
|
|
9985
|
+
super(name, "custom", "SQLiteCustomColumn");
|
|
9986
|
+
this.config.fieldConfig = fieldConfig;
|
|
9987
|
+
this.config.customTypeParams = customTypeParams;
|
|
9988
|
+
}
|
|
9989
|
+
/** @internal */
|
|
9990
|
+
build(table) {
|
|
9991
|
+
return new SQLiteCustomColumn(
|
|
9992
|
+
table,
|
|
9993
|
+
this.config
|
|
9994
|
+
);
|
|
9995
|
+
}
|
|
9996
|
+
}
|
|
9997
|
+
class SQLiteCustomColumn extends SQLiteColumn {
|
|
9998
|
+
static [entityKind] = "SQLiteCustomColumn";
|
|
9999
|
+
sqlName;
|
|
10000
|
+
mapTo;
|
|
10001
|
+
mapFrom;
|
|
10002
|
+
constructor(table, config) {
|
|
10003
|
+
super(table, config);
|
|
10004
|
+
this.sqlName = config.customTypeParams.dataType(config.fieldConfig);
|
|
10005
|
+
this.mapTo = config.customTypeParams.toDriver;
|
|
10006
|
+
this.mapFrom = config.customTypeParams.fromDriver;
|
|
9240
10007
|
}
|
|
9241
10008
|
getSQLType() {
|
|
9242
10009
|
return this.sqlName;
|
|
9243
10010
|
}
|
|
9244
|
-
mapFromDriverValue(value) {
|
|
9245
|
-
return typeof this.mapFrom === "function" ? this.mapFrom(value) : value;
|
|
10011
|
+
mapFromDriverValue(value) {
|
|
10012
|
+
return typeof this.mapFrom === "function" ? this.mapFrom(value) : value;
|
|
10013
|
+
}
|
|
10014
|
+
mapToDriverValue(value) {
|
|
10015
|
+
return typeof this.mapTo === "function" ? this.mapTo(value) : value;
|
|
10016
|
+
}
|
|
10017
|
+
}
|
|
10018
|
+
function customType(customTypeParams) {
|
|
10019
|
+
return (a, b) => {
|
|
10020
|
+
const { name, config } = getColumnNameAndConfig(a, b);
|
|
10021
|
+
return new SQLiteCustomColumnBuilder(
|
|
10022
|
+
name,
|
|
10023
|
+
config,
|
|
10024
|
+
customTypeParams
|
|
10025
|
+
);
|
|
10026
|
+
};
|
|
10027
|
+
}
|
|
10028
|
+
class SQLiteBaseIntegerBuilder extends SQLiteColumnBuilder {
|
|
10029
|
+
static [entityKind] = "SQLiteBaseIntegerBuilder";
|
|
10030
|
+
constructor(name, dataType, columnType) {
|
|
10031
|
+
super(name, dataType, columnType);
|
|
10032
|
+
this.config.autoIncrement = false;
|
|
10033
|
+
}
|
|
10034
|
+
primaryKey(config) {
|
|
10035
|
+
if (config?.autoIncrement) {
|
|
10036
|
+
this.config.autoIncrement = true;
|
|
10037
|
+
}
|
|
10038
|
+
this.config.hasDefault = true;
|
|
10039
|
+
return super.primaryKey();
|
|
10040
|
+
}
|
|
10041
|
+
}
|
|
10042
|
+
class SQLiteBaseInteger extends SQLiteColumn {
|
|
10043
|
+
static [entityKind] = "SQLiteBaseInteger";
|
|
10044
|
+
autoIncrement = this.config.autoIncrement;
|
|
10045
|
+
getSQLType() {
|
|
10046
|
+
return "integer";
|
|
10047
|
+
}
|
|
10048
|
+
}
|
|
10049
|
+
class SQLiteIntegerBuilder extends SQLiteBaseIntegerBuilder {
|
|
10050
|
+
static [entityKind] = "SQLiteIntegerBuilder";
|
|
10051
|
+
constructor(name) {
|
|
10052
|
+
super(name, "number", "SQLiteInteger");
|
|
10053
|
+
}
|
|
10054
|
+
build(table) {
|
|
10055
|
+
return new SQLiteInteger(
|
|
10056
|
+
table,
|
|
10057
|
+
this.config
|
|
10058
|
+
);
|
|
10059
|
+
}
|
|
10060
|
+
}
|
|
10061
|
+
class SQLiteInteger extends SQLiteBaseInteger {
|
|
10062
|
+
static [entityKind] = "SQLiteInteger";
|
|
10063
|
+
}
|
|
10064
|
+
class SQLiteTimestampBuilder extends SQLiteBaseIntegerBuilder {
|
|
10065
|
+
static [entityKind] = "SQLiteTimestampBuilder";
|
|
10066
|
+
constructor(name, mode) {
|
|
10067
|
+
super(name, "date", "SQLiteTimestamp");
|
|
10068
|
+
this.config.mode = mode;
|
|
10069
|
+
}
|
|
10070
|
+
/**
|
|
10071
|
+
* @deprecated Use `default()` with your own expression instead.
|
|
10072
|
+
*
|
|
10073
|
+
* Adds `DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer))` to the column, which is the current epoch timestamp in milliseconds.
|
|
10074
|
+
*/
|
|
10075
|
+
defaultNow() {
|
|
10076
|
+
return this.default(sql`(cast((julianday('now') - 2440587.5)*86400000 as integer))`);
|
|
10077
|
+
}
|
|
10078
|
+
build(table) {
|
|
10079
|
+
return new SQLiteTimestamp(
|
|
10080
|
+
table,
|
|
10081
|
+
this.config
|
|
10082
|
+
);
|
|
10083
|
+
}
|
|
10084
|
+
}
|
|
10085
|
+
class SQLiteTimestamp extends SQLiteBaseInteger {
|
|
10086
|
+
static [entityKind] = "SQLiteTimestamp";
|
|
10087
|
+
mode = this.config.mode;
|
|
10088
|
+
mapFromDriverValue(value) {
|
|
10089
|
+
if (this.config.mode === "timestamp") {
|
|
10090
|
+
return new Date(value * 1e3);
|
|
10091
|
+
}
|
|
10092
|
+
return new Date(value);
|
|
10093
|
+
}
|
|
10094
|
+
mapToDriverValue(value) {
|
|
10095
|
+
const unix = value.getTime();
|
|
10096
|
+
if (this.config.mode === "timestamp") {
|
|
10097
|
+
return Math.floor(unix / 1e3);
|
|
10098
|
+
}
|
|
10099
|
+
return unix;
|
|
10100
|
+
}
|
|
10101
|
+
}
|
|
10102
|
+
class SQLiteBooleanBuilder extends SQLiteBaseIntegerBuilder {
|
|
10103
|
+
static [entityKind] = "SQLiteBooleanBuilder";
|
|
10104
|
+
constructor(name, mode) {
|
|
10105
|
+
super(name, "boolean", "SQLiteBoolean");
|
|
10106
|
+
this.config.mode = mode;
|
|
10107
|
+
}
|
|
10108
|
+
build(table) {
|
|
10109
|
+
return new SQLiteBoolean(
|
|
10110
|
+
table,
|
|
10111
|
+
this.config
|
|
10112
|
+
);
|
|
10113
|
+
}
|
|
10114
|
+
}
|
|
10115
|
+
class SQLiteBoolean extends SQLiteBaseInteger {
|
|
10116
|
+
static [entityKind] = "SQLiteBoolean";
|
|
10117
|
+
mode = this.config.mode;
|
|
10118
|
+
mapFromDriverValue(value) {
|
|
10119
|
+
return Number(value) === 1;
|
|
10120
|
+
}
|
|
10121
|
+
mapToDriverValue(value) {
|
|
10122
|
+
return value ? 1 : 0;
|
|
10123
|
+
}
|
|
10124
|
+
}
|
|
10125
|
+
function integer(a, b) {
|
|
10126
|
+
const { name, config } = getColumnNameAndConfig(a, b);
|
|
10127
|
+
if (config?.mode === "timestamp" || config?.mode === "timestamp_ms") {
|
|
10128
|
+
return new SQLiteTimestampBuilder(name, config.mode);
|
|
10129
|
+
}
|
|
10130
|
+
if (config?.mode === "boolean") {
|
|
10131
|
+
return new SQLiteBooleanBuilder(name, config.mode);
|
|
10132
|
+
}
|
|
10133
|
+
return new SQLiteIntegerBuilder(name);
|
|
10134
|
+
}
|
|
10135
|
+
class SQLiteNumericBuilder extends SQLiteColumnBuilder {
|
|
10136
|
+
static [entityKind] = "SQLiteNumericBuilder";
|
|
10137
|
+
constructor(name) {
|
|
10138
|
+
super(name, "string", "SQLiteNumeric");
|
|
10139
|
+
}
|
|
10140
|
+
/** @internal */
|
|
10141
|
+
build(table) {
|
|
10142
|
+
return new SQLiteNumeric(
|
|
10143
|
+
table,
|
|
10144
|
+
this.config
|
|
10145
|
+
);
|
|
10146
|
+
}
|
|
10147
|
+
}
|
|
10148
|
+
class SQLiteNumeric extends SQLiteColumn {
|
|
10149
|
+
static [entityKind] = "SQLiteNumeric";
|
|
10150
|
+
getSQLType() {
|
|
10151
|
+
return "numeric";
|
|
10152
|
+
}
|
|
10153
|
+
}
|
|
10154
|
+
function numeric(name) {
|
|
10155
|
+
return new SQLiteNumericBuilder(name ?? "");
|
|
10156
|
+
}
|
|
10157
|
+
class SQLiteRealBuilder extends SQLiteColumnBuilder {
|
|
10158
|
+
static [entityKind] = "SQLiteRealBuilder";
|
|
10159
|
+
constructor(name) {
|
|
10160
|
+
super(name, "number", "SQLiteReal");
|
|
10161
|
+
}
|
|
10162
|
+
/** @internal */
|
|
10163
|
+
build(table) {
|
|
10164
|
+
return new SQLiteReal(table, this.config);
|
|
10165
|
+
}
|
|
10166
|
+
}
|
|
10167
|
+
class SQLiteReal extends SQLiteColumn {
|
|
10168
|
+
static [entityKind] = "SQLiteReal";
|
|
10169
|
+
getSQLType() {
|
|
10170
|
+
return "real";
|
|
10171
|
+
}
|
|
10172
|
+
}
|
|
10173
|
+
function real(name) {
|
|
10174
|
+
return new SQLiteRealBuilder(name ?? "");
|
|
10175
|
+
}
|
|
10176
|
+
class SQLiteTextBuilder extends SQLiteColumnBuilder {
|
|
10177
|
+
static [entityKind] = "SQLiteTextBuilder";
|
|
10178
|
+
constructor(name, config) {
|
|
10179
|
+
super(name, "string", "SQLiteText");
|
|
10180
|
+
this.config.enumValues = config.enum;
|
|
10181
|
+
this.config.length = config.length;
|
|
10182
|
+
}
|
|
10183
|
+
/** @internal */
|
|
10184
|
+
build(table) {
|
|
10185
|
+
return new SQLiteText(
|
|
10186
|
+
table,
|
|
10187
|
+
this.config
|
|
10188
|
+
);
|
|
10189
|
+
}
|
|
10190
|
+
}
|
|
10191
|
+
class SQLiteText extends SQLiteColumn {
|
|
10192
|
+
static [entityKind] = "SQLiteText";
|
|
10193
|
+
enumValues = this.config.enumValues;
|
|
10194
|
+
length = this.config.length;
|
|
10195
|
+
constructor(table, config) {
|
|
10196
|
+
super(table, config);
|
|
10197
|
+
}
|
|
10198
|
+
getSQLType() {
|
|
10199
|
+
return `text${this.config.length ? `(${this.config.length})` : ""}`;
|
|
10200
|
+
}
|
|
10201
|
+
}
|
|
10202
|
+
class SQLiteTextJsonBuilder extends SQLiteColumnBuilder {
|
|
10203
|
+
static [entityKind] = "SQLiteTextJsonBuilder";
|
|
10204
|
+
constructor(name) {
|
|
10205
|
+
super(name, "json", "SQLiteTextJson");
|
|
10206
|
+
}
|
|
10207
|
+
/** @internal */
|
|
10208
|
+
build(table) {
|
|
10209
|
+
return new SQLiteTextJson(
|
|
10210
|
+
table,
|
|
10211
|
+
this.config
|
|
10212
|
+
);
|
|
10213
|
+
}
|
|
10214
|
+
}
|
|
10215
|
+
class SQLiteTextJson extends SQLiteColumn {
|
|
10216
|
+
static [entityKind] = "SQLiteTextJson";
|
|
10217
|
+
getSQLType() {
|
|
10218
|
+
return "text";
|
|
10219
|
+
}
|
|
10220
|
+
mapFromDriverValue(value) {
|
|
10221
|
+
return JSON.parse(value);
|
|
10222
|
+
}
|
|
10223
|
+
mapToDriverValue(value) {
|
|
10224
|
+
return JSON.stringify(value);
|
|
10225
|
+
}
|
|
10226
|
+
}
|
|
10227
|
+
function text(a, b = {}) {
|
|
10228
|
+
const { name, config } = getColumnNameAndConfig(a, b);
|
|
10229
|
+
if (config.mode === "json") {
|
|
10230
|
+
return new SQLiteTextJsonBuilder(name);
|
|
10231
|
+
}
|
|
10232
|
+
return new SQLiteTextBuilder(name, config);
|
|
10233
|
+
}
|
|
10234
|
+
function getSQLiteColumnBuilders() {
|
|
10235
|
+
return {
|
|
10236
|
+
blob,
|
|
10237
|
+
customType,
|
|
10238
|
+
integer,
|
|
10239
|
+
numeric,
|
|
10240
|
+
real,
|
|
10241
|
+
text
|
|
10242
|
+
};
|
|
10243
|
+
}
|
|
10244
|
+
const InlineForeignKeys = /* @__PURE__ */ Symbol.for("drizzle:SQLiteInlineForeignKeys");
|
|
10245
|
+
class SQLiteTable extends Table {
|
|
10246
|
+
static [entityKind] = "SQLiteTable";
|
|
10247
|
+
/** @internal */
|
|
10248
|
+
static Symbol = Object.assign({}, Table.Symbol, {
|
|
10249
|
+
InlineForeignKeys
|
|
10250
|
+
});
|
|
10251
|
+
/** @internal */
|
|
10252
|
+
[Table.Symbol.Columns];
|
|
10253
|
+
/** @internal */
|
|
10254
|
+
[InlineForeignKeys] = [];
|
|
10255
|
+
/** @internal */
|
|
10256
|
+
[Table.Symbol.ExtraConfigBuilder] = void 0;
|
|
10257
|
+
}
|
|
10258
|
+
function sqliteTableBase(name, columns, extraConfig, schema2, baseName = name) {
|
|
10259
|
+
const rawTable = new SQLiteTable(name, schema2, baseName);
|
|
10260
|
+
const parsedColumns = typeof columns === "function" ? columns(getSQLiteColumnBuilders()) : columns;
|
|
10261
|
+
const builtColumns = Object.fromEntries(
|
|
10262
|
+
Object.entries(parsedColumns).map(([name2, colBuilderBase]) => {
|
|
10263
|
+
const colBuilder = colBuilderBase;
|
|
10264
|
+
colBuilder.setName(name2);
|
|
10265
|
+
const column = colBuilder.build(rawTable);
|
|
10266
|
+
rawTable[InlineForeignKeys].push(...colBuilder.buildForeignKeys(column, rawTable));
|
|
10267
|
+
return [name2, column];
|
|
10268
|
+
})
|
|
10269
|
+
);
|
|
10270
|
+
const table = Object.assign(rawTable, builtColumns);
|
|
10271
|
+
table[Table.Symbol.Columns] = builtColumns;
|
|
10272
|
+
table[Table.Symbol.ExtraConfigColumns] = builtColumns;
|
|
10273
|
+
if (extraConfig) {
|
|
10274
|
+
table[SQLiteTable.Symbol.ExtraConfigBuilder] = extraConfig;
|
|
10275
|
+
}
|
|
10276
|
+
return table;
|
|
10277
|
+
}
|
|
10278
|
+
const sqliteTable = (name, columns, extraConfig) => {
|
|
10279
|
+
return sqliteTableBase(name, columns, extraConfig);
|
|
10280
|
+
};
|
|
10281
|
+
class SQLiteDeleteBase extends QueryPromise {
|
|
10282
|
+
constructor(table, session, dialect, withList) {
|
|
10283
|
+
super();
|
|
10284
|
+
this.table = table;
|
|
10285
|
+
this.session = session;
|
|
10286
|
+
this.dialect = dialect;
|
|
10287
|
+
this.config = { table, withList };
|
|
10288
|
+
}
|
|
10289
|
+
static [entityKind] = "SQLiteDelete";
|
|
10290
|
+
/** @internal */
|
|
10291
|
+
config;
|
|
10292
|
+
/**
|
|
10293
|
+
* Adds a `where` clause to the query.
|
|
10294
|
+
*
|
|
10295
|
+
* Calling this method will delete only those rows that fulfill a specified condition.
|
|
10296
|
+
*
|
|
10297
|
+
* See docs: {@link https://orm.drizzle.team/docs/delete}
|
|
10298
|
+
*
|
|
10299
|
+
* @param where the `where` clause.
|
|
10300
|
+
*
|
|
10301
|
+
* @example
|
|
10302
|
+
* You can use conditional operators and `sql function` to filter the rows to be deleted.
|
|
10303
|
+
*
|
|
10304
|
+
* ```ts
|
|
10305
|
+
* // Delete all cars with green color
|
|
10306
|
+
* db.delete(cars).where(eq(cars.color, 'green'));
|
|
10307
|
+
* // or
|
|
10308
|
+
* db.delete(cars).where(sql`${cars.color} = 'green'`)
|
|
10309
|
+
* ```
|
|
10310
|
+
*
|
|
10311
|
+
* You can logically combine conditional operators with `and()` and `or()` operators:
|
|
10312
|
+
*
|
|
10313
|
+
* ```ts
|
|
10314
|
+
* // Delete all BMW cars with a green color
|
|
10315
|
+
* db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
|
10316
|
+
*
|
|
10317
|
+
* // Delete all cars with the green or blue color
|
|
10318
|
+
* db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
|
10319
|
+
* ```
|
|
10320
|
+
*/
|
|
10321
|
+
where(where) {
|
|
10322
|
+
this.config.where = where;
|
|
10323
|
+
return this;
|
|
10324
|
+
}
|
|
10325
|
+
orderBy(...columns) {
|
|
10326
|
+
if (typeof columns[0] === "function") {
|
|
10327
|
+
const orderBy = columns[0](
|
|
10328
|
+
new Proxy(
|
|
10329
|
+
this.config.table[Table.Symbol.Columns],
|
|
10330
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "alias", sqlBehavior: "sql" })
|
|
10331
|
+
)
|
|
10332
|
+
);
|
|
10333
|
+
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
|
10334
|
+
this.config.orderBy = orderByArray;
|
|
10335
|
+
} else {
|
|
10336
|
+
const orderByArray = columns;
|
|
10337
|
+
this.config.orderBy = orderByArray;
|
|
10338
|
+
}
|
|
10339
|
+
return this;
|
|
10340
|
+
}
|
|
10341
|
+
limit(limit) {
|
|
10342
|
+
this.config.limit = limit;
|
|
10343
|
+
return this;
|
|
10344
|
+
}
|
|
10345
|
+
returning(fields = this.table[SQLiteTable.Symbol.Columns]) {
|
|
10346
|
+
this.config.returning = orderSelectedFields(fields);
|
|
10347
|
+
return this;
|
|
10348
|
+
}
|
|
10349
|
+
/** @internal */
|
|
10350
|
+
getSQL() {
|
|
10351
|
+
return this.dialect.buildDeleteQuery(this.config);
|
|
10352
|
+
}
|
|
10353
|
+
toSQL() {
|
|
10354
|
+
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
|
10355
|
+
return rest;
|
|
10356
|
+
}
|
|
10357
|
+
/** @internal */
|
|
10358
|
+
_prepare(isOneTimeQuery = true) {
|
|
10359
|
+
return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
|
|
10360
|
+
this.dialect.sqlToQuery(this.getSQL()),
|
|
10361
|
+
this.config.returning,
|
|
10362
|
+
this.config.returning ? "all" : "run",
|
|
10363
|
+
true
|
|
10364
|
+
);
|
|
10365
|
+
}
|
|
10366
|
+
prepare() {
|
|
10367
|
+
return this._prepare(false);
|
|
10368
|
+
}
|
|
10369
|
+
run = (placeholderValues) => {
|
|
10370
|
+
return this._prepare().run(placeholderValues);
|
|
10371
|
+
};
|
|
10372
|
+
all = (placeholderValues) => {
|
|
10373
|
+
return this._prepare().all(placeholderValues);
|
|
10374
|
+
};
|
|
10375
|
+
get = (placeholderValues) => {
|
|
10376
|
+
return this._prepare().get(placeholderValues);
|
|
10377
|
+
};
|
|
10378
|
+
values = (placeholderValues) => {
|
|
10379
|
+
return this._prepare().values(placeholderValues);
|
|
10380
|
+
};
|
|
10381
|
+
async execute(placeholderValues) {
|
|
10382
|
+
return this._prepare().execute(placeholderValues);
|
|
10383
|
+
}
|
|
10384
|
+
$dynamic() {
|
|
10385
|
+
return this;
|
|
10386
|
+
}
|
|
10387
|
+
}
|
|
10388
|
+
function toSnakeCase(input) {
|
|
10389
|
+
const words = input.replace(/['\u2019]/g, "").match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g) ?? [];
|
|
10390
|
+
return words.map((word) => word.toLowerCase()).join("_");
|
|
10391
|
+
}
|
|
10392
|
+
function toCamelCase(input) {
|
|
10393
|
+
const words = input.replace(/['\u2019]/g, "").match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g) ?? [];
|
|
10394
|
+
return words.reduce((acc, word, i) => {
|
|
10395
|
+
const formattedWord = i === 0 ? word.toLowerCase() : `${word[0].toUpperCase()}${word.slice(1)}`;
|
|
10396
|
+
return acc + formattedWord;
|
|
10397
|
+
}, "");
|
|
10398
|
+
}
|
|
10399
|
+
function noopCase(input) {
|
|
10400
|
+
return input;
|
|
10401
|
+
}
|
|
10402
|
+
class CasingCache {
|
|
10403
|
+
static [entityKind] = "CasingCache";
|
|
10404
|
+
/** @internal */
|
|
10405
|
+
cache = {};
|
|
10406
|
+
cachedTables = {};
|
|
10407
|
+
convert;
|
|
10408
|
+
constructor(casing) {
|
|
10409
|
+
this.convert = casing === "snake_case" ? toSnakeCase : casing === "camelCase" ? toCamelCase : noopCase;
|
|
10410
|
+
}
|
|
10411
|
+
getColumnCasing(column) {
|
|
10412
|
+
if (!column.keyAsName)
|
|
10413
|
+
return column.name;
|
|
10414
|
+
const schema2 = column.table[Table.Symbol.Schema] ?? "public";
|
|
10415
|
+
const tableName = column.table[Table.Symbol.OriginalName];
|
|
10416
|
+
const key = `${schema2}.${tableName}.${column.name}`;
|
|
10417
|
+
if (!this.cache[key]) {
|
|
10418
|
+
this.cacheTable(column.table);
|
|
10419
|
+
}
|
|
10420
|
+
return this.cache[key];
|
|
10421
|
+
}
|
|
10422
|
+
cacheTable(table) {
|
|
10423
|
+
const schema2 = table[Table.Symbol.Schema] ?? "public";
|
|
10424
|
+
const tableName = table[Table.Symbol.OriginalName];
|
|
10425
|
+
const tableKey = `${schema2}.${tableName}`;
|
|
10426
|
+
if (!this.cachedTables[tableKey]) {
|
|
10427
|
+
for (const column of Object.values(table[Table.Symbol.Columns])) {
|
|
10428
|
+
const columnKey = `${tableKey}.${column.name}`;
|
|
10429
|
+
this.cache[columnKey] = this.convert(column.name);
|
|
10430
|
+
}
|
|
10431
|
+
this.cachedTables[tableKey] = true;
|
|
10432
|
+
}
|
|
10433
|
+
}
|
|
10434
|
+
clearCache() {
|
|
10435
|
+
this.cache = {};
|
|
10436
|
+
this.cachedTables = {};
|
|
10437
|
+
}
|
|
10438
|
+
}
|
|
10439
|
+
class SQLiteViewBase extends View {
|
|
10440
|
+
static [entityKind] = "SQLiteViewBase";
|
|
10441
|
+
}
|
|
10442
|
+
class SQLiteDialect {
|
|
10443
|
+
static [entityKind] = "SQLiteDialect";
|
|
10444
|
+
/** @internal */
|
|
10445
|
+
casing;
|
|
10446
|
+
constructor(config) {
|
|
10447
|
+
this.casing = new CasingCache(config?.casing);
|
|
10448
|
+
}
|
|
10449
|
+
escapeName(name) {
|
|
10450
|
+
return `"${name}"`;
|
|
10451
|
+
}
|
|
10452
|
+
escapeParam(_num) {
|
|
10453
|
+
return "?";
|
|
10454
|
+
}
|
|
10455
|
+
escapeString(str) {
|
|
10456
|
+
return `'${str.replace(/'/g, "''")}'`;
|
|
10457
|
+
}
|
|
10458
|
+
buildWithCTE(queries) {
|
|
10459
|
+
if (!queries?.length)
|
|
10460
|
+
return void 0;
|
|
10461
|
+
const withSqlChunks = [sql`with `];
|
|
10462
|
+
for (const [i, w] of queries.entries()) {
|
|
10463
|
+
withSqlChunks.push(sql`${sql.identifier(w._.alias)} as (${w._.sql})`);
|
|
10464
|
+
if (i < queries.length - 1) {
|
|
10465
|
+
withSqlChunks.push(sql`, `);
|
|
10466
|
+
}
|
|
10467
|
+
}
|
|
10468
|
+
withSqlChunks.push(sql` `);
|
|
10469
|
+
return sql.join(withSqlChunks);
|
|
10470
|
+
}
|
|
10471
|
+
buildDeleteQuery({ table, where, returning, withList, limit, orderBy }) {
|
|
10472
|
+
const withSql = this.buildWithCTE(withList);
|
|
10473
|
+
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
|
|
10474
|
+
const whereSql = where ? sql` where ${where}` : void 0;
|
|
10475
|
+
const orderBySql = this.buildOrderBy(orderBy);
|
|
10476
|
+
const limitSql = this.buildLimit(limit);
|
|
10477
|
+
return sql`${withSql}delete from ${table}${whereSql}${returningSql}${orderBySql}${limitSql}`;
|
|
10478
|
+
}
|
|
10479
|
+
buildUpdateSet(table, set2) {
|
|
10480
|
+
const tableColumns = table[Table.Symbol.Columns];
|
|
10481
|
+
const columnNames = Object.keys(tableColumns).filter(
|
|
10482
|
+
(colName) => set2[colName] !== void 0 || tableColumns[colName]?.onUpdateFn !== void 0
|
|
10483
|
+
);
|
|
10484
|
+
const setSize = columnNames.length;
|
|
10485
|
+
return sql.join(columnNames.flatMap((colName, i) => {
|
|
10486
|
+
const col = tableColumns[colName];
|
|
10487
|
+
const value = set2[colName] ?? sql.param(col.onUpdateFn(), col);
|
|
10488
|
+
const res = sql`${sql.identifier(this.casing.getColumnCasing(col))} = ${value}`;
|
|
10489
|
+
if (i < setSize - 1) {
|
|
10490
|
+
return [res, sql.raw(", ")];
|
|
10491
|
+
}
|
|
10492
|
+
return [res];
|
|
10493
|
+
}));
|
|
10494
|
+
}
|
|
10495
|
+
buildUpdateQuery({ table, set: set2, where, returning, withList, joins, from, limit, orderBy }) {
|
|
10496
|
+
const withSql = this.buildWithCTE(withList);
|
|
10497
|
+
const setSql = this.buildUpdateSet(table, set2);
|
|
10498
|
+
const fromSql = from && sql.join([sql.raw(" from "), this.buildFromTable(from)]);
|
|
10499
|
+
const joinsSql = this.buildJoins(joins);
|
|
10500
|
+
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
|
|
10501
|
+
const whereSql = where ? sql` where ${where}` : void 0;
|
|
10502
|
+
const orderBySql = this.buildOrderBy(orderBy);
|
|
10503
|
+
const limitSql = this.buildLimit(limit);
|
|
10504
|
+
return sql`${withSql}update ${table} set ${setSql}${fromSql}${joinsSql}${whereSql}${returningSql}${orderBySql}${limitSql}`;
|
|
10505
|
+
}
|
|
10506
|
+
/**
|
|
10507
|
+
* Builds selection SQL with provided fields/expressions
|
|
10508
|
+
*
|
|
10509
|
+
* Examples:
|
|
10510
|
+
*
|
|
10511
|
+
* `select <selection> from`
|
|
10512
|
+
*
|
|
10513
|
+
* `insert ... returning <selection>`
|
|
10514
|
+
*
|
|
10515
|
+
* If `isSingleTable` is true, then columns won't be prefixed with table name
|
|
10516
|
+
*/
|
|
10517
|
+
buildSelection(fields, { isSingleTable = false } = {}) {
|
|
10518
|
+
const columnsLen = fields.length;
|
|
10519
|
+
const chunks = fields.flatMap(({ field }, i) => {
|
|
10520
|
+
const chunk = [];
|
|
10521
|
+
if (is(field, SQL.Aliased) && field.isSelectionField) {
|
|
10522
|
+
chunk.push(sql.identifier(field.fieldAlias));
|
|
10523
|
+
} else if (is(field, SQL.Aliased) || is(field, SQL)) {
|
|
10524
|
+
const query = is(field, SQL.Aliased) ? field.sql : field;
|
|
10525
|
+
if (isSingleTable) {
|
|
10526
|
+
chunk.push(
|
|
10527
|
+
new SQL(
|
|
10528
|
+
query.queryChunks.map((c) => {
|
|
10529
|
+
if (is(c, Column)) {
|
|
10530
|
+
return sql.identifier(this.casing.getColumnCasing(c));
|
|
10531
|
+
}
|
|
10532
|
+
return c;
|
|
10533
|
+
})
|
|
10534
|
+
)
|
|
10535
|
+
);
|
|
10536
|
+
} else {
|
|
10537
|
+
chunk.push(query);
|
|
10538
|
+
}
|
|
10539
|
+
if (is(field, SQL.Aliased)) {
|
|
10540
|
+
chunk.push(sql` as ${sql.identifier(field.fieldAlias)}`);
|
|
10541
|
+
}
|
|
10542
|
+
} else if (is(field, Column)) {
|
|
10543
|
+
const tableName = field.table[Table.Symbol.Name];
|
|
10544
|
+
if (isSingleTable) {
|
|
10545
|
+
chunk.push(sql.identifier(this.casing.getColumnCasing(field)));
|
|
10546
|
+
} else {
|
|
10547
|
+
chunk.push(sql`${sql.identifier(tableName)}.${sql.identifier(this.casing.getColumnCasing(field))}`);
|
|
10548
|
+
}
|
|
10549
|
+
}
|
|
10550
|
+
if (i < columnsLen - 1) {
|
|
10551
|
+
chunk.push(sql`, `);
|
|
10552
|
+
}
|
|
10553
|
+
return chunk;
|
|
10554
|
+
});
|
|
10555
|
+
return sql.join(chunks);
|
|
10556
|
+
}
|
|
10557
|
+
buildJoins(joins) {
|
|
10558
|
+
if (!joins || joins.length === 0) {
|
|
10559
|
+
return void 0;
|
|
10560
|
+
}
|
|
10561
|
+
const joinsArray = [];
|
|
10562
|
+
if (joins) {
|
|
10563
|
+
for (const [index2, joinMeta] of joins.entries()) {
|
|
10564
|
+
if (index2 === 0) {
|
|
10565
|
+
joinsArray.push(sql` `);
|
|
10566
|
+
}
|
|
10567
|
+
const table = joinMeta.table;
|
|
10568
|
+
if (is(table, SQLiteTable)) {
|
|
10569
|
+
const tableName = table[SQLiteTable.Symbol.Name];
|
|
10570
|
+
const tableSchema = table[SQLiteTable.Symbol.Schema];
|
|
10571
|
+
const origTableName = table[SQLiteTable.Symbol.OriginalName];
|
|
10572
|
+
const alias = tableName === origTableName ? void 0 : joinMeta.alias;
|
|
10573
|
+
joinsArray.push(
|
|
10574
|
+
sql`${sql.raw(joinMeta.joinType)} join ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`} on ${joinMeta.on}`
|
|
10575
|
+
);
|
|
10576
|
+
} else {
|
|
10577
|
+
joinsArray.push(
|
|
10578
|
+
sql`${sql.raw(joinMeta.joinType)} join ${table} on ${joinMeta.on}`
|
|
10579
|
+
);
|
|
10580
|
+
}
|
|
10581
|
+
if (index2 < joins.length - 1) {
|
|
10582
|
+
joinsArray.push(sql` `);
|
|
10583
|
+
}
|
|
10584
|
+
}
|
|
10585
|
+
}
|
|
10586
|
+
return sql.join(joinsArray);
|
|
10587
|
+
}
|
|
10588
|
+
buildLimit(limit) {
|
|
10589
|
+
return typeof limit === "object" || typeof limit === "number" && limit >= 0 ? sql` limit ${limit}` : void 0;
|
|
10590
|
+
}
|
|
10591
|
+
buildOrderBy(orderBy) {
|
|
10592
|
+
const orderByList = [];
|
|
10593
|
+
if (orderBy) {
|
|
10594
|
+
for (const [index2, orderByValue] of orderBy.entries()) {
|
|
10595
|
+
orderByList.push(orderByValue);
|
|
10596
|
+
if (index2 < orderBy.length - 1) {
|
|
10597
|
+
orderByList.push(sql`, `);
|
|
10598
|
+
}
|
|
10599
|
+
}
|
|
10600
|
+
}
|
|
10601
|
+
return orderByList.length > 0 ? sql` order by ${sql.join(orderByList)}` : void 0;
|
|
10602
|
+
}
|
|
10603
|
+
buildFromTable(table) {
|
|
10604
|
+
if (is(table, Table) && table[Table.Symbol.OriginalName] !== table[Table.Symbol.Name]) {
|
|
10605
|
+
return sql`${sql.identifier(table[Table.Symbol.OriginalName])} ${sql.identifier(table[Table.Symbol.Name])}`;
|
|
10606
|
+
}
|
|
10607
|
+
return table;
|
|
10608
|
+
}
|
|
10609
|
+
buildSelectQuery({
|
|
10610
|
+
withList,
|
|
10611
|
+
fields,
|
|
10612
|
+
fieldsFlat,
|
|
10613
|
+
where,
|
|
10614
|
+
having,
|
|
10615
|
+
table,
|
|
10616
|
+
joins,
|
|
10617
|
+
orderBy,
|
|
10618
|
+
groupBy,
|
|
10619
|
+
limit,
|
|
10620
|
+
offset,
|
|
10621
|
+
distinct,
|
|
10622
|
+
setOperators
|
|
10623
|
+
}) {
|
|
10624
|
+
const fieldsList = fieldsFlat ?? orderSelectedFields(fields);
|
|
10625
|
+
for (const f of fieldsList) {
|
|
10626
|
+
if (is(f.field, Column) && getTableName(f.field.table) !== (is(table, Subquery) ? table._.alias : is(table, SQLiteViewBase) ? table[ViewBaseConfig].name : is(table, SQL) ? void 0 : getTableName(table)) && !((table2) => joins?.some(
|
|
10627
|
+
({ alias }) => alias === (table2[Table.Symbol.IsAlias] ? getTableName(table2) : table2[Table.Symbol.BaseName])
|
|
10628
|
+
))(f.field.table)) {
|
|
10629
|
+
const tableName = getTableName(f.field.table);
|
|
10630
|
+
throw new Error(
|
|
10631
|
+
`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?`
|
|
10632
|
+
);
|
|
10633
|
+
}
|
|
10634
|
+
}
|
|
10635
|
+
const isSingleTable = !joins || joins.length === 0;
|
|
10636
|
+
const withSql = this.buildWithCTE(withList);
|
|
10637
|
+
const distinctSql = distinct ? sql` distinct` : void 0;
|
|
10638
|
+
const selection = this.buildSelection(fieldsList, { isSingleTable });
|
|
10639
|
+
const tableSql = this.buildFromTable(table);
|
|
10640
|
+
const joinsSql = this.buildJoins(joins);
|
|
10641
|
+
const whereSql = where ? sql` where ${where}` : void 0;
|
|
10642
|
+
const havingSql = having ? sql` having ${having}` : void 0;
|
|
10643
|
+
const groupByList = [];
|
|
10644
|
+
if (groupBy) {
|
|
10645
|
+
for (const [index2, groupByValue] of groupBy.entries()) {
|
|
10646
|
+
groupByList.push(groupByValue);
|
|
10647
|
+
if (index2 < groupBy.length - 1) {
|
|
10648
|
+
groupByList.push(sql`, `);
|
|
10649
|
+
}
|
|
10650
|
+
}
|
|
10651
|
+
}
|
|
10652
|
+
const groupBySql = groupByList.length > 0 ? sql` group by ${sql.join(groupByList)}` : void 0;
|
|
10653
|
+
const orderBySql = this.buildOrderBy(orderBy);
|
|
10654
|
+
const limitSql = this.buildLimit(limit);
|
|
10655
|
+
const offsetSql = offset ? sql` offset ${offset}` : void 0;
|
|
10656
|
+
const finalQuery = sql`${withSql}select${distinctSql} ${selection} from ${tableSql}${joinsSql}${whereSql}${groupBySql}${havingSql}${orderBySql}${limitSql}${offsetSql}`;
|
|
10657
|
+
if (setOperators.length > 0) {
|
|
10658
|
+
return this.buildSetOperations(finalQuery, setOperators);
|
|
10659
|
+
}
|
|
10660
|
+
return finalQuery;
|
|
10661
|
+
}
|
|
10662
|
+
buildSetOperations(leftSelect, setOperators) {
|
|
10663
|
+
const [setOperator, ...rest] = setOperators;
|
|
10664
|
+
if (!setOperator) {
|
|
10665
|
+
throw new Error("Cannot pass undefined values to any set operator");
|
|
10666
|
+
}
|
|
10667
|
+
if (rest.length === 0) {
|
|
10668
|
+
return this.buildSetOperationQuery({ leftSelect, setOperator });
|
|
10669
|
+
}
|
|
10670
|
+
return this.buildSetOperations(
|
|
10671
|
+
this.buildSetOperationQuery({ leftSelect, setOperator }),
|
|
10672
|
+
rest
|
|
10673
|
+
);
|
|
10674
|
+
}
|
|
10675
|
+
buildSetOperationQuery({
|
|
10676
|
+
leftSelect,
|
|
10677
|
+
setOperator: { type, isAll, rightSelect, limit, orderBy, offset }
|
|
10678
|
+
}) {
|
|
10679
|
+
const leftChunk = sql`${leftSelect.getSQL()} `;
|
|
10680
|
+
const rightChunk = sql`${rightSelect.getSQL()}`;
|
|
10681
|
+
let orderBySql;
|
|
10682
|
+
if (orderBy && orderBy.length > 0) {
|
|
10683
|
+
const orderByValues = [];
|
|
10684
|
+
for (const singleOrderBy of orderBy) {
|
|
10685
|
+
if (is(singleOrderBy, SQLiteColumn)) {
|
|
10686
|
+
orderByValues.push(sql.identifier(singleOrderBy.name));
|
|
10687
|
+
} else if (is(singleOrderBy, SQL)) {
|
|
10688
|
+
for (let i = 0; i < singleOrderBy.queryChunks.length; i++) {
|
|
10689
|
+
const chunk = singleOrderBy.queryChunks[i];
|
|
10690
|
+
if (is(chunk, SQLiteColumn)) {
|
|
10691
|
+
singleOrderBy.queryChunks[i] = sql.identifier(this.casing.getColumnCasing(chunk));
|
|
10692
|
+
}
|
|
10693
|
+
}
|
|
10694
|
+
orderByValues.push(sql`${singleOrderBy}`);
|
|
10695
|
+
} else {
|
|
10696
|
+
orderByValues.push(sql`${singleOrderBy}`);
|
|
10697
|
+
}
|
|
10698
|
+
}
|
|
10699
|
+
orderBySql = sql` order by ${sql.join(orderByValues, sql`, `)}`;
|
|
10700
|
+
}
|
|
10701
|
+
const limitSql = typeof limit === "object" || typeof limit === "number" && limit >= 0 ? sql` limit ${limit}` : void 0;
|
|
10702
|
+
const operatorChunk = sql.raw(`${type} ${isAll ? "all " : ""}`);
|
|
10703
|
+
const offsetSql = offset ? sql` offset ${offset}` : void 0;
|
|
10704
|
+
return sql`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;
|
|
10705
|
+
}
|
|
10706
|
+
buildInsertQuery({ table, values: valuesOrSelect, onConflict, returning, withList, select }) {
|
|
10707
|
+
const valuesSqlList = [];
|
|
10708
|
+
const columns = table[Table.Symbol.Columns];
|
|
10709
|
+
const colEntries = Object.entries(columns).filter(
|
|
10710
|
+
([_, col]) => !col.shouldDisableInsert()
|
|
10711
|
+
);
|
|
10712
|
+
const insertOrder = colEntries.map(([, column]) => sql.identifier(this.casing.getColumnCasing(column)));
|
|
10713
|
+
if (select) {
|
|
10714
|
+
const select2 = valuesOrSelect;
|
|
10715
|
+
if (is(select2, SQL)) {
|
|
10716
|
+
valuesSqlList.push(select2);
|
|
10717
|
+
} else {
|
|
10718
|
+
valuesSqlList.push(select2.getSQL());
|
|
10719
|
+
}
|
|
10720
|
+
} else {
|
|
10721
|
+
const values = valuesOrSelect;
|
|
10722
|
+
valuesSqlList.push(sql.raw("values "));
|
|
10723
|
+
for (const [valueIndex, value] of values.entries()) {
|
|
10724
|
+
const valueList = [];
|
|
10725
|
+
for (const [fieldName, col] of colEntries) {
|
|
10726
|
+
const colValue = value[fieldName];
|
|
10727
|
+
if (colValue === void 0 || is(colValue, Param) && colValue.value === void 0) {
|
|
10728
|
+
let defaultValue;
|
|
10729
|
+
if (col.default !== null && col.default !== void 0) {
|
|
10730
|
+
defaultValue = is(col.default, SQL) ? col.default : sql.param(col.default, col);
|
|
10731
|
+
} else if (col.defaultFn !== void 0) {
|
|
10732
|
+
const defaultFnResult = col.defaultFn();
|
|
10733
|
+
defaultValue = is(defaultFnResult, SQL) ? defaultFnResult : sql.param(defaultFnResult, col);
|
|
10734
|
+
} else if (!col.default && col.onUpdateFn !== void 0) {
|
|
10735
|
+
const onUpdateFnResult = col.onUpdateFn();
|
|
10736
|
+
defaultValue = is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col);
|
|
10737
|
+
} else {
|
|
10738
|
+
defaultValue = sql`null`;
|
|
10739
|
+
}
|
|
10740
|
+
valueList.push(defaultValue);
|
|
10741
|
+
} else {
|
|
10742
|
+
valueList.push(colValue);
|
|
10743
|
+
}
|
|
10744
|
+
}
|
|
10745
|
+
valuesSqlList.push(valueList);
|
|
10746
|
+
if (valueIndex < values.length - 1) {
|
|
10747
|
+
valuesSqlList.push(sql`, `);
|
|
10748
|
+
}
|
|
10749
|
+
}
|
|
10750
|
+
}
|
|
10751
|
+
const withSql = this.buildWithCTE(withList);
|
|
10752
|
+
const valuesSql = sql.join(valuesSqlList);
|
|
10753
|
+
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
|
|
10754
|
+
const onConflictSql = onConflict ? sql` on conflict ${onConflict}` : void 0;
|
|
10755
|
+
return sql`${withSql}insert into ${table} ${insertOrder} ${valuesSql}${onConflictSql}${returningSql}`;
|
|
10756
|
+
}
|
|
10757
|
+
sqlToQuery(sql2, invokeSource) {
|
|
10758
|
+
return sql2.toQuery({
|
|
10759
|
+
casing: this.casing,
|
|
10760
|
+
escapeName: this.escapeName,
|
|
10761
|
+
escapeParam: this.escapeParam,
|
|
10762
|
+
escapeString: this.escapeString,
|
|
10763
|
+
invokeSource
|
|
10764
|
+
});
|
|
10765
|
+
}
|
|
10766
|
+
buildRelationalQuery({
|
|
10767
|
+
fullSchema,
|
|
10768
|
+
schema: schema2,
|
|
10769
|
+
tableNamesMap,
|
|
10770
|
+
table,
|
|
10771
|
+
tableConfig,
|
|
10772
|
+
queryConfig: config,
|
|
10773
|
+
tableAlias,
|
|
10774
|
+
nestedQueryRelation,
|
|
10775
|
+
joinOn
|
|
10776
|
+
}) {
|
|
10777
|
+
let selection = [];
|
|
10778
|
+
let limit, offset, orderBy = [], where;
|
|
10779
|
+
const joins = [];
|
|
10780
|
+
if (config === true) {
|
|
10781
|
+
const selectionEntries = Object.entries(tableConfig.columns);
|
|
10782
|
+
selection = selectionEntries.map(([key, value]) => ({
|
|
10783
|
+
dbKey: value.name,
|
|
10784
|
+
tsKey: key,
|
|
10785
|
+
field: aliasedTableColumn(value, tableAlias),
|
|
10786
|
+
relationTableTsKey: void 0,
|
|
10787
|
+
isJson: false,
|
|
10788
|
+
selection: []
|
|
10789
|
+
}));
|
|
10790
|
+
} else {
|
|
10791
|
+
const aliasedColumns = Object.fromEntries(
|
|
10792
|
+
Object.entries(tableConfig.columns).map(([key, value]) => [key, aliasedTableColumn(value, tableAlias)])
|
|
10793
|
+
);
|
|
10794
|
+
if (config.where) {
|
|
10795
|
+
const whereSql = typeof config.where === "function" ? config.where(aliasedColumns, getOperators()) : config.where;
|
|
10796
|
+
where = whereSql && mapColumnsInSQLToAlias(whereSql, tableAlias);
|
|
10797
|
+
}
|
|
10798
|
+
const fieldsSelection = [];
|
|
10799
|
+
let selectedColumns = [];
|
|
10800
|
+
if (config.columns) {
|
|
10801
|
+
let isIncludeMode = false;
|
|
10802
|
+
for (const [field, value] of Object.entries(config.columns)) {
|
|
10803
|
+
if (value === void 0) {
|
|
10804
|
+
continue;
|
|
10805
|
+
}
|
|
10806
|
+
if (field in tableConfig.columns) {
|
|
10807
|
+
if (!isIncludeMode && value === true) {
|
|
10808
|
+
isIncludeMode = true;
|
|
10809
|
+
}
|
|
10810
|
+
selectedColumns.push(field);
|
|
10811
|
+
}
|
|
10812
|
+
}
|
|
10813
|
+
if (selectedColumns.length > 0) {
|
|
10814
|
+
selectedColumns = isIncludeMode ? selectedColumns.filter((c) => config.columns?.[c] === true) : Object.keys(tableConfig.columns).filter((key) => !selectedColumns.includes(key));
|
|
10815
|
+
}
|
|
10816
|
+
} else {
|
|
10817
|
+
selectedColumns = Object.keys(tableConfig.columns);
|
|
10818
|
+
}
|
|
10819
|
+
for (const field of selectedColumns) {
|
|
10820
|
+
const column = tableConfig.columns[field];
|
|
10821
|
+
fieldsSelection.push({ tsKey: field, value: column });
|
|
10822
|
+
}
|
|
10823
|
+
let selectedRelations = [];
|
|
10824
|
+
if (config.with) {
|
|
10825
|
+
selectedRelations = Object.entries(config.with).filter((entry) => !!entry[1]).map(([tsKey, queryConfig]) => ({ tsKey, queryConfig, relation: tableConfig.relations[tsKey] }));
|
|
10826
|
+
}
|
|
10827
|
+
let extras;
|
|
10828
|
+
if (config.extras) {
|
|
10829
|
+
extras = typeof config.extras === "function" ? config.extras(aliasedColumns, { sql }) : config.extras;
|
|
10830
|
+
for (const [tsKey, value] of Object.entries(extras)) {
|
|
10831
|
+
fieldsSelection.push({
|
|
10832
|
+
tsKey,
|
|
10833
|
+
value: mapColumnsInAliasedSQLToAlias(value, tableAlias)
|
|
10834
|
+
});
|
|
10835
|
+
}
|
|
10836
|
+
}
|
|
10837
|
+
for (const { tsKey, value } of fieldsSelection) {
|
|
10838
|
+
selection.push({
|
|
10839
|
+
dbKey: is(value, SQL.Aliased) ? value.fieldAlias : tableConfig.columns[tsKey].name,
|
|
10840
|
+
tsKey,
|
|
10841
|
+
field: is(value, Column) ? aliasedTableColumn(value, tableAlias) : value,
|
|
10842
|
+
relationTableTsKey: void 0,
|
|
10843
|
+
isJson: false,
|
|
10844
|
+
selection: []
|
|
10845
|
+
});
|
|
10846
|
+
}
|
|
10847
|
+
let orderByOrig = typeof config.orderBy === "function" ? config.orderBy(aliasedColumns, getOrderByOperators()) : config.orderBy ?? [];
|
|
10848
|
+
if (!Array.isArray(orderByOrig)) {
|
|
10849
|
+
orderByOrig = [orderByOrig];
|
|
10850
|
+
}
|
|
10851
|
+
orderBy = orderByOrig.map((orderByValue) => {
|
|
10852
|
+
if (is(orderByValue, Column)) {
|
|
10853
|
+
return aliasedTableColumn(orderByValue, tableAlias);
|
|
10854
|
+
}
|
|
10855
|
+
return mapColumnsInSQLToAlias(orderByValue, tableAlias);
|
|
10856
|
+
});
|
|
10857
|
+
limit = config.limit;
|
|
10858
|
+
offset = config.offset;
|
|
10859
|
+
for (const {
|
|
10860
|
+
tsKey: selectedRelationTsKey,
|
|
10861
|
+
queryConfig: selectedRelationConfigValue,
|
|
10862
|
+
relation
|
|
10863
|
+
} of selectedRelations) {
|
|
10864
|
+
const normalizedRelation = normalizeRelation(schema2, tableNamesMap, relation);
|
|
10865
|
+
const relationTableName = getTableUniqueName(relation.referencedTable);
|
|
10866
|
+
const relationTableTsName = tableNamesMap[relationTableName];
|
|
10867
|
+
const relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;
|
|
10868
|
+
const joinOn2 = and(
|
|
10869
|
+
...normalizedRelation.fields.map(
|
|
10870
|
+
(field2, i) => eq(
|
|
10871
|
+
aliasedTableColumn(normalizedRelation.references[i], relationTableAlias),
|
|
10872
|
+
aliasedTableColumn(field2, tableAlias)
|
|
10873
|
+
)
|
|
10874
|
+
)
|
|
10875
|
+
);
|
|
10876
|
+
const builtRelation = this.buildRelationalQuery({
|
|
10877
|
+
fullSchema,
|
|
10878
|
+
schema: schema2,
|
|
10879
|
+
tableNamesMap,
|
|
10880
|
+
table: fullSchema[relationTableTsName],
|
|
10881
|
+
tableConfig: schema2[relationTableTsName],
|
|
10882
|
+
queryConfig: is(relation, One) ? selectedRelationConfigValue === true ? { limit: 1 } : { ...selectedRelationConfigValue, limit: 1 } : selectedRelationConfigValue,
|
|
10883
|
+
tableAlias: relationTableAlias,
|
|
10884
|
+
joinOn: joinOn2,
|
|
10885
|
+
nestedQueryRelation: relation
|
|
10886
|
+
});
|
|
10887
|
+
const field = sql`(${builtRelation.sql})`.as(selectedRelationTsKey);
|
|
10888
|
+
selection.push({
|
|
10889
|
+
dbKey: selectedRelationTsKey,
|
|
10890
|
+
tsKey: selectedRelationTsKey,
|
|
10891
|
+
field,
|
|
10892
|
+
relationTableTsKey: relationTableTsName,
|
|
10893
|
+
isJson: true,
|
|
10894
|
+
selection: builtRelation.selection
|
|
10895
|
+
});
|
|
10896
|
+
}
|
|
10897
|
+
}
|
|
10898
|
+
if (selection.length === 0) {
|
|
10899
|
+
throw new DrizzleError({
|
|
10900
|
+
message: `No fields selected for table "${tableConfig.tsName}" ("${tableAlias}"). You need to have at least one item in "columns", "with" or "extras". If you need to select all columns, omit the "columns" key or set it to undefined.`
|
|
10901
|
+
});
|
|
10902
|
+
}
|
|
10903
|
+
let result;
|
|
10904
|
+
where = and(joinOn, where);
|
|
10905
|
+
if (nestedQueryRelation) {
|
|
10906
|
+
let field = sql`json_array(${sql.join(
|
|
10907
|
+
selection.map(
|
|
10908
|
+
({ field: field2 }) => is(field2, SQLiteColumn) ? sql.identifier(this.casing.getColumnCasing(field2)) : is(field2, SQL.Aliased) ? field2.sql : field2
|
|
10909
|
+
),
|
|
10910
|
+
sql`, `
|
|
10911
|
+
)})`;
|
|
10912
|
+
if (is(nestedQueryRelation, Many)) {
|
|
10913
|
+
field = sql`coalesce(json_group_array(${field}), json_array())`;
|
|
10914
|
+
}
|
|
10915
|
+
const nestedSelection = [{
|
|
10916
|
+
dbKey: "data",
|
|
10917
|
+
tsKey: "data",
|
|
10918
|
+
field: field.as("data"),
|
|
10919
|
+
isJson: true,
|
|
10920
|
+
relationTableTsKey: tableConfig.tsName,
|
|
10921
|
+
selection
|
|
10922
|
+
}];
|
|
10923
|
+
const needsSubquery = limit !== void 0 || offset !== void 0 || orderBy.length > 0;
|
|
10924
|
+
if (needsSubquery) {
|
|
10925
|
+
result = this.buildSelectQuery({
|
|
10926
|
+
table: aliasedTable(table, tableAlias),
|
|
10927
|
+
fields: {},
|
|
10928
|
+
fieldsFlat: [
|
|
10929
|
+
{
|
|
10930
|
+
path: [],
|
|
10931
|
+
field: sql.raw("*")
|
|
10932
|
+
}
|
|
10933
|
+
],
|
|
10934
|
+
where,
|
|
10935
|
+
limit,
|
|
10936
|
+
offset,
|
|
10937
|
+
orderBy,
|
|
10938
|
+
setOperators: []
|
|
10939
|
+
});
|
|
10940
|
+
where = void 0;
|
|
10941
|
+
limit = void 0;
|
|
10942
|
+
offset = void 0;
|
|
10943
|
+
orderBy = void 0;
|
|
10944
|
+
} else {
|
|
10945
|
+
result = aliasedTable(table, tableAlias);
|
|
10946
|
+
}
|
|
10947
|
+
result = this.buildSelectQuery({
|
|
10948
|
+
table: is(result, SQLiteTable) ? result : new Subquery(result, {}, tableAlias),
|
|
10949
|
+
fields: {},
|
|
10950
|
+
fieldsFlat: nestedSelection.map(({ field: field2 }) => ({
|
|
10951
|
+
path: [],
|
|
10952
|
+
field: is(field2, Column) ? aliasedTableColumn(field2, tableAlias) : field2
|
|
10953
|
+
})),
|
|
10954
|
+
joins,
|
|
10955
|
+
where,
|
|
10956
|
+
limit,
|
|
10957
|
+
offset,
|
|
10958
|
+
orderBy,
|
|
10959
|
+
setOperators: []
|
|
10960
|
+
});
|
|
10961
|
+
} else {
|
|
10962
|
+
result = this.buildSelectQuery({
|
|
10963
|
+
table: aliasedTable(table, tableAlias),
|
|
10964
|
+
fields: {},
|
|
10965
|
+
fieldsFlat: selection.map(({ field }) => ({
|
|
10966
|
+
path: [],
|
|
10967
|
+
field: is(field, Column) ? aliasedTableColumn(field, tableAlias) : field
|
|
10968
|
+
})),
|
|
10969
|
+
joins,
|
|
10970
|
+
where,
|
|
10971
|
+
limit,
|
|
10972
|
+
offset,
|
|
10973
|
+
orderBy,
|
|
10974
|
+
setOperators: []
|
|
10975
|
+
});
|
|
10976
|
+
}
|
|
10977
|
+
return {
|
|
10978
|
+
tableTsKey: tableConfig.tsName,
|
|
10979
|
+
sql: result,
|
|
10980
|
+
selection
|
|
10981
|
+
};
|
|
10982
|
+
}
|
|
10983
|
+
}
|
|
10984
|
+
class SQLiteSyncDialect extends SQLiteDialect {
|
|
10985
|
+
static [entityKind] = "SQLiteSyncDialect";
|
|
10986
|
+
migrate(migrations, session, config) {
|
|
10987
|
+
const migrationsTable = config === void 0 ? "__drizzle_migrations" : typeof config === "string" ? "__drizzle_migrations" : config.migrationsTable ?? "__drizzle_migrations";
|
|
10988
|
+
const migrationTableCreate = sql`
|
|
10989
|
+
CREATE TABLE IF NOT EXISTS ${sql.identifier(migrationsTable)} (
|
|
10990
|
+
id SERIAL PRIMARY KEY,
|
|
10991
|
+
hash text NOT NULL,
|
|
10992
|
+
created_at numeric
|
|
10993
|
+
)
|
|
10994
|
+
`;
|
|
10995
|
+
session.run(migrationTableCreate);
|
|
10996
|
+
const dbMigrations = session.values(
|
|
10997
|
+
sql`SELECT id, hash, created_at FROM ${sql.identifier(migrationsTable)} ORDER BY created_at DESC LIMIT 1`
|
|
10998
|
+
);
|
|
10999
|
+
const lastDbMigration = dbMigrations[0] ?? void 0;
|
|
11000
|
+
session.run(sql`BEGIN`);
|
|
11001
|
+
try {
|
|
11002
|
+
for (const migration of migrations) {
|
|
11003
|
+
if (!lastDbMigration || Number(lastDbMigration[2]) < migration.folderMillis) {
|
|
11004
|
+
for (const stmt of migration.sql) {
|
|
11005
|
+
session.run(sql.raw(stmt));
|
|
11006
|
+
}
|
|
11007
|
+
session.run(
|
|
11008
|
+
sql`INSERT INTO ${sql.identifier(migrationsTable)} ("hash", "created_at") VALUES(${migration.hash}, ${migration.folderMillis})`
|
|
11009
|
+
);
|
|
11010
|
+
}
|
|
11011
|
+
}
|
|
11012
|
+
session.run(sql`COMMIT`);
|
|
11013
|
+
} catch (e) {
|
|
11014
|
+
session.run(sql`ROLLBACK`);
|
|
11015
|
+
throw e;
|
|
11016
|
+
}
|
|
11017
|
+
}
|
|
11018
|
+
}
|
|
11019
|
+
class SQLiteAsyncDialect extends SQLiteDialect {
|
|
11020
|
+
static [entityKind] = "SQLiteAsyncDialect";
|
|
11021
|
+
async migrate(migrations, session, config) {
|
|
11022
|
+
const migrationsTable = config === void 0 ? "__drizzle_migrations" : typeof config === "string" ? "__drizzle_migrations" : config.migrationsTable ?? "__drizzle_migrations";
|
|
11023
|
+
const migrationTableCreate = sql`
|
|
11024
|
+
CREATE TABLE IF NOT EXISTS ${sql.identifier(migrationsTable)} (
|
|
11025
|
+
id SERIAL PRIMARY KEY,
|
|
11026
|
+
hash text NOT NULL,
|
|
11027
|
+
created_at numeric
|
|
11028
|
+
)
|
|
11029
|
+
`;
|
|
11030
|
+
await session.run(migrationTableCreate);
|
|
11031
|
+
const dbMigrations = await session.values(
|
|
11032
|
+
sql`SELECT id, hash, created_at FROM ${sql.identifier(migrationsTable)} ORDER BY created_at DESC LIMIT 1`
|
|
11033
|
+
);
|
|
11034
|
+
const lastDbMigration = dbMigrations[0] ?? void 0;
|
|
11035
|
+
await session.transaction(async (tx) => {
|
|
11036
|
+
for (const migration of migrations) {
|
|
11037
|
+
if (!lastDbMigration || Number(lastDbMigration[2]) < migration.folderMillis) {
|
|
11038
|
+
for (const stmt of migration.sql) {
|
|
11039
|
+
await tx.run(sql.raw(stmt));
|
|
11040
|
+
}
|
|
11041
|
+
await tx.run(
|
|
11042
|
+
sql`INSERT INTO ${sql.identifier(migrationsTable)} ("hash", "created_at") VALUES(${migration.hash}, ${migration.folderMillis})`
|
|
11043
|
+
);
|
|
11044
|
+
}
|
|
11045
|
+
}
|
|
11046
|
+
});
|
|
11047
|
+
}
|
|
11048
|
+
}
|
|
11049
|
+
class TypedQueryBuilder {
|
|
11050
|
+
static [entityKind] = "TypedQueryBuilder";
|
|
11051
|
+
/** @internal */
|
|
11052
|
+
getSelectedFields() {
|
|
11053
|
+
return this._.selectedFields;
|
|
11054
|
+
}
|
|
11055
|
+
}
|
|
11056
|
+
class SQLiteSelectBuilder {
|
|
11057
|
+
static [entityKind] = "SQLiteSelectBuilder";
|
|
11058
|
+
fields;
|
|
11059
|
+
session;
|
|
11060
|
+
dialect;
|
|
11061
|
+
withList;
|
|
11062
|
+
distinct;
|
|
11063
|
+
constructor(config) {
|
|
11064
|
+
this.fields = config.fields;
|
|
11065
|
+
this.session = config.session;
|
|
11066
|
+
this.dialect = config.dialect;
|
|
11067
|
+
this.withList = config.withList;
|
|
11068
|
+
this.distinct = config.distinct;
|
|
11069
|
+
}
|
|
11070
|
+
from(source) {
|
|
11071
|
+
const isPartialSelect = !!this.fields;
|
|
11072
|
+
let fields;
|
|
11073
|
+
if (this.fields) {
|
|
11074
|
+
fields = this.fields;
|
|
11075
|
+
} else if (is(source, Subquery)) {
|
|
11076
|
+
fields = Object.fromEntries(
|
|
11077
|
+
Object.keys(source._.selectedFields).map((key) => [key, source[key]])
|
|
11078
|
+
);
|
|
11079
|
+
} else if (is(source, SQLiteViewBase)) {
|
|
11080
|
+
fields = source[ViewBaseConfig].selectedFields;
|
|
11081
|
+
} else if (is(source, SQL)) {
|
|
11082
|
+
fields = {};
|
|
11083
|
+
} else {
|
|
11084
|
+
fields = getTableColumns(source);
|
|
11085
|
+
}
|
|
11086
|
+
return new SQLiteSelectBase({
|
|
11087
|
+
table: source,
|
|
11088
|
+
fields,
|
|
11089
|
+
isPartialSelect,
|
|
11090
|
+
session: this.session,
|
|
11091
|
+
dialect: this.dialect,
|
|
11092
|
+
withList: this.withList,
|
|
11093
|
+
distinct: this.distinct
|
|
11094
|
+
});
|
|
11095
|
+
}
|
|
11096
|
+
}
|
|
11097
|
+
class SQLiteSelectQueryBuilderBase extends TypedQueryBuilder {
|
|
11098
|
+
static [entityKind] = "SQLiteSelectQueryBuilder";
|
|
11099
|
+
_;
|
|
11100
|
+
/** @internal */
|
|
11101
|
+
config;
|
|
11102
|
+
joinsNotNullableMap;
|
|
11103
|
+
tableName;
|
|
11104
|
+
isPartialSelect;
|
|
11105
|
+
session;
|
|
11106
|
+
dialect;
|
|
11107
|
+
constructor({ table, fields, isPartialSelect, session, dialect, withList, distinct }) {
|
|
11108
|
+
super();
|
|
11109
|
+
this.config = {
|
|
11110
|
+
withList,
|
|
11111
|
+
table,
|
|
11112
|
+
fields: { ...fields },
|
|
11113
|
+
distinct,
|
|
11114
|
+
setOperators: []
|
|
11115
|
+
};
|
|
11116
|
+
this.isPartialSelect = isPartialSelect;
|
|
11117
|
+
this.session = session;
|
|
11118
|
+
this.dialect = dialect;
|
|
11119
|
+
this._ = {
|
|
11120
|
+
selectedFields: fields
|
|
11121
|
+
};
|
|
11122
|
+
this.tableName = getTableLikeName(table);
|
|
11123
|
+
this.joinsNotNullableMap = typeof this.tableName === "string" ? { [this.tableName]: true } : {};
|
|
11124
|
+
}
|
|
11125
|
+
createJoin(joinType) {
|
|
11126
|
+
return (table, on) => {
|
|
11127
|
+
const baseTableName = this.tableName;
|
|
11128
|
+
const tableName = getTableLikeName(table);
|
|
11129
|
+
if (typeof tableName === "string" && this.config.joins?.some((join2) => join2.alias === tableName)) {
|
|
11130
|
+
throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
11131
|
+
}
|
|
11132
|
+
if (!this.isPartialSelect) {
|
|
11133
|
+
if (Object.keys(this.joinsNotNullableMap).length === 1 && typeof baseTableName === "string") {
|
|
11134
|
+
this.config.fields = {
|
|
11135
|
+
[baseTableName]: this.config.fields
|
|
11136
|
+
};
|
|
11137
|
+
}
|
|
11138
|
+
if (typeof tableName === "string" && !is(table, SQL)) {
|
|
11139
|
+
const selection = is(table, Subquery) ? table._.selectedFields : is(table, View) ? table[ViewBaseConfig].selectedFields : table[Table.Symbol.Columns];
|
|
11140
|
+
this.config.fields[tableName] = selection;
|
|
11141
|
+
}
|
|
11142
|
+
}
|
|
11143
|
+
if (typeof on === "function") {
|
|
11144
|
+
on = on(
|
|
11145
|
+
new Proxy(
|
|
11146
|
+
this.config.fields,
|
|
11147
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
|
11148
|
+
)
|
|
11149
|
+
);
|
|
11150
|
+
}
|
|
11151
|
+
if (!this.config.joins) {
|
|
11152
|
+
this.config.joins = [];
|
|
11153
|
+
}
|
|
11154
|
+
this.config.joins.push({ on, table, joinType, alias: tableName });
|
|
11155
|
+
if (typeof tableName === "string") {
|
|
11156
|
+
switch (joinType) {
|
|
11157
|
+
case "left": {
|
|
11158
|
+
this.joinsNotNullableMap[tableName] = false;
|
|
11159
|
+
break;
|
|
11160
|
+
}
|
|
11161
|
+
case "right": {
|
|
11162
|
+
this.joinsNotNullableMap = Object.fromEntries(
|
|
11163
|
+
Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false])
|
|
11164
|
+
);
|
|
11165
|
+
this.joinsNotNullableMap[tableName] = true;
|
|
11166
|
+
break;
|
|
11167
|
+
}
|
|
11168
|
+
case "inner": {
|
|
11169
|
+
this.joinsNotNullableMap[tableName] = true;
|
|
11170
|
+
break;
|
|
11171
|
+
}
|
|
11172
|
+
case "full": {
|
|
11173
|
+
this.joinsNotNullableMap = Object.fromEntries(
|
|
11174
|
+
Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false])
|
|
11175
|
+
);
|
|
11176
|
+
this.joinsNotNullableMap[tableName] = false;
|
|
11177
|
+
break;
|
|
11178
|
+
}
|
|
11179
|
+
}
|
|
11180
|
+
}
|
|
11181
|
+
return this;
|
|
11182
|
+
};
|
|
11183
|
+
}
|
|
11184
|
+
/**
|
|
11185
|
+
* Executes a `left join` operation by adding another table to the current query.
|
|
11186
|
+
*
|
|
11187
|
+
* 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.
|
|
11188
|
+
*
|
|
11189
|
+
* See docs: {@link https://orm.drizzle.team/docs/joins#left-join}
|
|
11190
|
+
*
|
|
11191
|
+
* @param table the table to join.
|
|
11192
|
+
* @param on the `on` clause.
|
|
11193
|
+
*
|
|
11194
|
+
* @example
|
|
11195
|
+
*
|
|
11196
|
+
* ```ts
|
|
11197
|
+
* // Select all users and their pets
|
|
11198
|
+
* const usersWithPets: { user: User; pets: Pet | null }[] = await db.select()
|
|
11199
|
+
* .from(users)
|
|
11200
|
+
* .leftJoin(pets, eq(users.id, pets.ownerId))
|
|
11201
|
+
*
|
|
11202
|
+
* // Select userId and petId
|
|
11203
|
+
* const usersIdsAndPetIds: { userId: number; petId: number | null }[] = await db.select({
|
|
11204
|
+
* userId: users.id,
|
|
11205
|
+
* petId: pets.id,
|
|
11206
|
+
* })
|
|
11207
|
+
* .from(users)
|
|
11208
|
+
* .leftJoin(pets, eq(users.id, pets.ownerId))
|
|
11209
|
+
* ```
|
|
11210
|
+
*/
|
|
11211
|
+
leftJoin = this.createJoin("left");
|
|
11212
|
+
/**
|
|
11213
|
+
* Executes a `right join` operation by adding another table to the current query.
|
|
11214
|
+
*
|
|
11215
|
+
* 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.
|
|
11216
|
+
*
|
|
11217
|
+
* See docs: {@link https://orm.drizzle.team/docs/joins#right-join}
|
|
11218
|
+
*
|
|
11219
|
+
* @param table the table to join.
|
|
11220
|
+
* @param on the `on` clause.
|
|
11221
|
+
*
|
|
11222
|
+
* @example
|
|
11223
|
+
*
|
|
11224
|
+
* ```ts
|
|
11225
|
+
* // Select all users and their pets
|
|
11226
|
+
* const usersWithPets: { user: User | null; pets: Pet }[] = await db.select()
|
|
11227
|
+
* .from(users)
|
|
11228
|
+
* .rightJoin(pets, eq(users.id, pets.ownerId))
|
|
11229
|
+
*
|
|
11230
|
+
* // Select userId and petId
|
|
11231
|
+
* const usersIdsAndPetIds: { userId: number | null; petId: number }[] = await db.select({
|
|
11232
|
+
* userId: users.id,
|
|
11233
|
+
* petId: pets.id,
|
|
11234
|
+
* })
|
|
11235
|
+
* .from(users)
|
|
11236
|
+
* .rightJoin(pets, eq(users.id, pets.ownerId))
|
|
11237
|
+
* ```
|
|
11238
|
+
*/
|
|
11239
|
+
rightJoin = this.createJoin("right");
|
|
11240
|
+
/**
|
|
11241
|
+
* Executes an `inner join` operation, creating a new table by combining rows from two tables that have matching values.
|
|
11242
|
+
*
|
|
11243
|
+
* 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.
|
|
11244
|
+
*
|
|
11245
|
+
* See docs: {@link https://orm.drizzle.team/docs/joins#inner-join}
|
|
11246
|
+
*
|
|
11247
|
+
* @param table the table to join.
|
|
11248
|
+
* @param on the `on` clause.
|
|
11249
|
+
*
|
|
11250
|
+
* @example
|
|
11251
|
+
*
|
|
11252
|
+
* ```ts
|
|
11253
|
+
* // Select all users and their pets
|
|
11254
|
+
* const usersWithPets: { user: User; pets: Pet }[] = await db.select()
|
|
11255
|
+
* .from(users)
|
|
11256
|
+
* .innerJoin(pets, eq(users.id, pets.ownerId))
|
|
11257
|
+
*
|
|
11258
|
+
* // Select userId and petId
|
|
11259
|
+
* const usersIdsAndPetIds: { userId: number; petId: number }[] = await db.select({
|
|
11260
|
+
* userId: users.id,
|
|
11261
|
+
* petId: pets.id,
|
|
11262
|
+
* })
|
|
11263
|
+
* .from(users)
|
|
11264
|
+
* .innerJoin(pets, eq(users.id, pets.ownerId))
|
|
11265
|
+
* ```
|
|
11266
|
+
*/
|
|
11267
|
+
innerJoin = this.createJoin("inner");
|
|
11268
|
+
/**
|
|
11269
|
+
* Executes a `full join` operation by combining rows from two tables into a new table.
|
|
11270
|
+
*
|
|
11271
|
+
* 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.
|
|
11272
|
+
*
|
|
11273
|
+
* See docs: {@link https://orm.drizzle.team/docs/joins#full-join}
|
|
11274
|
+
*
|
|
11275
|
+
* @param table the table to join.
|
|
11276
|
+
* @param on the `on` clause.
|
|
11277
|
+
*
|
|
11278
|
+
* @example
|
|
11279
|
+
*
|
|
11280
|
+
* ```ts
|
|
11281
|
+
* // Select all users and their pets
|
|
11282
|
+
* const usersWithPets: { user: User | null; pets: Pet | null }[] = await db.select()
|
|
11283
|
+
* .from(users)
|
|
11284
|
+
* .fullJoin(pets, eq(users.id, pets.ownerId))
|
|
11285
|
+
*
|
|
11286
|
+
* // Select userId and petId
|
|
11287
|
+
* const usersIdsAndPetIds: { userId: number | null; petId: number | null }[] = await db.select({
|
|
11288
|
+
* userId: users.id,
|
|
11289
|
+
* petId: pets.id,
|
|
11290
|
+
* })
|
|
11291
|
+
* .from(users)
|
|
11292
|
+
* .fullJoin(pets, eq(users.id, pets.ownerId))
|
|
11293
|
+
* ```
|
|
11294
|
+
*/
|
|
11295
|
+
fullJoin = this.createJoin("full");
|
|
11296
|
+
createSetOperator(type, isAll) {
|
|
11297
|
+
return (rightSelection) => {
|
|
11298
|
+
const rightSelect = typeof rightSelection === "function" ? rightSelection(getSQLiteSetOperators()) : rightSelection;
|
|
11299
|
+
if (!haveSameKeys(this.getSelectedFields(), rightSelect.getSelectedFields())) {
|
|
11300
|
+
throw new Error(
|
|
11301
|
+
"Set operator error (union / intersect / except): selected fields are not the same or are in a different order"
|
|
11302
|
+
);
|
|
11303
|
+
}
|
|
11304
|
+
this.config.setOperators.push({ type, isAll, rightSelect });
|
|
11305
|
+
return this;
|
|
11306
|
+
};
|
|
11307
|
+
}
|
|
11308
|
+
/**
|
|
11309
|
+
* Adds `union` set operator to the query.
|
|
11310
|
+
*
|
|
11311
|
+
* Calling this method will combine the result sets of the `select` statements and remove any duplicate rows that appear across them.
|
|
11312
|
+
*
|
|
11313
|
+
* See docs: {@link https://orm.drizzle.team/docs/set-operations#union}
|
|
11314
|
+
*
|
|
11315
|
+
* @example
|
|
11316
|
+
*
|
|
11317
|
+
* ```ts
|
|
11318
|
+
* // Select all unique names from customers and users tables
|
|
11319
|
+
* await db.select({ name: users.name })
|
|
11320
|
+
* .from(users)
|
|
11321
|
+
* .union(
|
|
11322
|
+
* db.select({ name: customers.name }).from(customers)
|
|
11323
|
+
* );
|
|
11324
|
+
* // or
|
|
11325
|
+
* import { union } from 'drizzle-orm/sqlite-core'
|
|
11326
|
+
*
|
|
11327
|
+
* await union(
|
|
11328
|
+
* db.select({ name: users.name }).from(users),
|
|
11329
|
+
* db.select({ name: customers.name }).from(customers)
|
|
11330
|
+
* );
|
|
11331
|
+
* ```
|
|
11332
|
+
*/
|
|
11333
|
+
union = this.createSetOperator("union", false);
|
|
11334
|
+
/**
|
|
11335
|
+
* Adds `union all` set operator to the query.
|
|
11336
|
+
*
|
|
11337
|
+
* Calling this method will combine the result-set of the `select` statements and keep all duplicate rows that appear across them.
|
|
11338
|
+
*
|
|
11339
|
+
* See docs: {@link https://orm.drizzle.team/docs/set-operations#union-all}
|
|
11340
|
+
*
|
|
11341
|
+
* @example
|
|
11342
|
+
*
|
|
11343
|
+
* ```ts
|
|
11344
|
+
* // Select all transaction ids from both online and in-store sales
|
|
11345
|
+
* await db.select({ transaction: onlineSales.transactionId })
|
|
11346
|
+
* .from(onlineSales)
|
|
11347
|
+
* .unionAll(
|
|
11348
|
+
* db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
|
|
11349
|
+
* );
|
|
11350
|
+
* // or
|
|
11351
|
+
* import { unionAll } from 'drizzle-orm/sqlite-core'
|
|
11352
|
+
*
|
|
11353
|
+
* await unionAll(
|
|
11354
|
+
* db.select({ transaction: onlineSales.transactionId }).from(onlineSales),
|
|
11355
|
+
* db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
|
|
11356
|
+
* );
|
|
11357
|
+
* ```
|
|
11358
|
+
*/
|
|
11359
|
+
unionAll = this.createSetOperator("union", true);
|
|
11360
|
+
/**
|
|
11361
|
+
* Adds `intersect` set operator to the query.
|
|
11362
|
+
*
|
|
11363
|
+
* Calling this method will retain only the rows that are present in both result sets and eliminate duplicates.
|
|
11364
|
+
*
|
|
11365
|
+
* See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect}
|
|
11366
|
+
*
|
|
11367
|
+
* @example
|
|
11368
|
+
*
|
|
11369
|
+
* ```ts
|
|
11370
|
+
* // Select course names that are offered in both departments A and B
|
|
11371
|
+
* await db.select({ courseName: depA.courseName })
|
|
11372
|
+
* .from(depA)
|
|
11373
|
+
* .intersect(
|
|
11374
|
+
* db.select({ courseName: depB.courseName }).from(depB)
|
|
11375
|
+
* );
|
|
11376
|
+
* // or
|
|
11377
|
+
* import { intersect } from 'drizzle-orm/sqlite-core'
|
|
11378
|
+
*
|
|
11379
|
+
* await intersect(
|
|
11380
|
+
* db.select({ courseName: depA.courseName }).from(depA),
|
|
11381
|
+
* db.select({ courseName: depB.courseName }).from(depB)
|
|
11382
|
+
* );
|
|
11383
|
+
* ```
|
|
11384
|
+
*/
|
|
11385
|
+
intersect = this.createSetOperator("intersect", false);
|
|
11386
|
+
/**
|
|
11387
|
+
* Adds `except` set operator to the query.
|
|
11388
|
+
*
|
|
11389
|
+
* 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.
|
|
11390
|
+
*
|
|
11391
|
+
* See docs: {@link https://orm.drizzle.team/docs/set-operations#except}
|
|
11392
|
+
*
|
|
11393
|
+
* @example
|
|
11394
|
+
*
|
|
11395
|
+
* ```ts
|
|
11396
|
+
* // Select all courses offered in department A but not in department B
|
|
11397
|
+
* await db.select({ courseName: depA.courseName })
|
|
11398
|
+
* .from(depA)
|
|
11399
|
+
* .except(
|
|
11400
|
+
* db.select({ courseName: depB.courseName }).from(depB)
|
|
11401
|
+
* );
|
|
11402
|
+
* // or
|
|
11403
|
+
* import { except } from 'drizzle-orm/sqlite-core'
|
|
11404
|
+
*
|
|
11405
|
+
* await except(
|
|
11406
|
+
* db.select({ courseName: depA.courseName }).from(depA),
|
|
11407
|
+
* db.select({ courseName: depB.courseName }).from(depB)
|
|
11408
|
+
* );
|
|
11409
|
+
* ```
|
|
11410
|
+
*/
|
|
11411
|
+
except = this.createSetOperator("except", false);
|
|
11412
|
+
/** @internal */
|
|
11413
|
+
addSetOperators(setOperators) {
|
|
11414
|
+
this.config.setOperators.push(...setOperators);
|
|
11415
|
+
return this;
|
|
11416
|
+
}
|
|
11417
|
+
/**
|
|
11418
|
+
* Adds a `where` clause to the query.
|
|
11419
|
+
*
|
|
11420
|
+
* Calling this method will select only those rows that fulfill a specified condition.
|
|
11421
|
+
*
|
|
11422
|
+
* See docs: {@link https://orm.drizzle.team/docs/select#filtering}
|
|
11423
|
+
*
|
|
11424
|
+
* @param where the `where` clause.
|
|
11425
|
+
*
|
|
11426
|
+
* @example
|
|
11427
|
+
* You can use conditional operators and `sql function` to filter the rows to be selected.
|
|
11428
|
+
*
|
|
11429
|
+
* ```ts
|
|
11430
|
+
* // Select all cars with green color
|
|
11431
|
+
* await db.select().from(cars).where(eq(cars.color, 'green'));
|
|
11432
|
+
* // or
|
|
11433
|
+
* await db.select().from(cars).where(sql`${cars.color} = 'green'`)
|
|
11434
|
+
* ```
|
|
11435
|
+
*
|
|
11436
|
+
* You can logically combine conditional operators with `and()` and `or()` operators:
|
|
11437
|
+
*
|
|
11438
|
+
* ```ts
|
|
11439
|
+
* // Select all BMW cars with a green color
|
|
11440
|
+
* await db.select().from(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
|
11441
|
+
*
|
|
11442
|
+
* // Select all cars with the green or blue color
|
|
11443
|
+
* await db.select().from(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
|
11444
|
+
* ```
|
|
11445
|
+
*/
|
|
11446
|
+
where(where) {
|
|
11447
|
+
if (typeof where === "function") {
|
|
11448
|
+
where = where(
|
|
11449
|
+
new Proxy(
|
|
11450
|
+
this.config.fields,
|
|
11451
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
|
11452
|
+
)
|
|
11453
|
+
);
|
|
11454
|
+
}
|
|
11455
|
+
this.config.where = where;
|
|
11456
|
+
return this;
|
|
11457
|
+
}
|
|
11458
|
+
/**
|
|
11459
|
+
* Adds a `having` clause to the query.
|
|
11460
|
+
*
|
|
11461
|
+
* 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.
|
|
11462
|
+
*
|
|
11463
|
+
* See docs: {@link https://orm.drizzle.team/docs/select#aggregations}
|
|
11464
|
+
*
|
|
11465
|
+
* @param having the `having` clause.
|
|
11466
|
+
*
|
|
11467
|
+
* @example
|
|
11468
|
+
*
|
|
11469
|
+
* ```ts
|
|
11470
|
+
* // Select all brands with more than one car
|
|
11471
|
+
* await db.select({
|
|
11472
|
+
* brand: cars.brand,
|
|
11473
|
+
* count: sql<number>`cast(count(${cars.id}) as int)`,
|
|
11474
|
+
* })
|
|
11475
|
+
* .from(cars)
|
|
11476
|
+
* .groupBy(cars.brand)
|
|
11477
|
+
* .having(({ count }) => gt(count, 1));
|
|
11478
|
+
* ```
|
|
11479
|
+
*/
|
|
11480
|
+
having(having) {
|
|
11481
|
+
if (typeof having === "function") {
|
|
11482
|
+
having = having(
|
|
11483
|
+
new Proxy(
|
|
11484
|
+
this.config.fields,
|
|
11485
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
|
11486
|
+
)
|
|
11487
|
+
);
|
|
11488
|
+
}
|
|
11489
|
+
this.config.having = having;
|
|
11490
|
+
return this;
|
|
11491
|
+
}
|
|
11492
|
+
groupBy(...columns) {
|
|
11493
|
+
if (typeof columns[0] === "function") {
|
|
11494
|
+
const groupBy = columns[0](
|
|
11495
|
+
new Proxy(
|
|
11496
|
+
this.config.fields,
|
|
11497
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "alias", sqlBehavior: "sql" })
|
|
11498
|
+
)
|
|
11499
|
+
);
|
|
11500
|
+
this.config.groupBy = Array.isArray(groupBy) ? groupBy : [groupBy];
|
|
11501
|
+
} else {
|
|
11502
|
+
this.config.groupBy = columns;
|
|
11503
|
+
}
|
|
11504
|
+
return this;
|
|
11505
|
+
}
|
|
11506
|
+
orderBy(...columns) {
|
|
11507
|
+
if (typeof columns[0] === "function") {
|
|
11508
|
+
const orderBy = columns[0](
|
|
11509
|
+
new Proxy(
|
|
11510
|
+
this.config.fields,
|
|
11511
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "alias", sqlBehavior: "sql" })
|
|
11512
|
+
)
|
|
11513
|
+
);
|
|
11514
|
+
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
|
11515
|
+
if (this.config.setOperators.length > 0) {
|
|
11516
|
+
this.config.setOperators.at(-1).orderBy = orderByArray;
|
|
11517
|
+
} else {
|
|
11518
|
+
this.config.orderBy = orderByArray;
|
|
11519
|
+
}
|
|
11520
|
+
} else {
|
|
11521
|
+
const orderByArray = columns;
|
|
11522
|
+
if (this.config.setOperators.length > 0) {
|
|
11523
|
+
this.config.setOperators.at(-1).orderBy = orderByArray;
|
|
11524
|
+
} else {
|
|
11525
|
+
this.config.orderBy = orderByArray;
|
|
11526
|
+
}
|
|
11527
|
+
}
|
|
11528
|
+
return this;
|
|
11529
|
+
}
|
|
11530
|
+
/**
|
|
11531
|
+
* Adds a `limit` clause to the query.
|
|
11532
|
+
*
|
|
11533
|
+
* Calling this method will set the maximum number of rows that will be returned by this query.
|
|
11534
|
+
*
|
|
11535
|
+
* See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}
|
|
11536
|
+
*
|
|
11537
|
+
* @param limit the `limit` clause.
|
|
11538
|
+
*
|
|
11539
|
+
* @example
|
|
11540
|
+
*
|
|
11541
|
+
* ```ts
|
|
11542
|
+
* // Get the first 10 people from this query.
|
|
11543
|
+
* await db.select().from(people).limit(10);
|
|
11544
|
+
* ```
|
|
11545
|
+
*/
|
|
11546
|
+
limit(limit) {
|
|
11547
|
+
if (this.config.setOperators.length > 0) {
|
|
11548
|
+
this.config.setOperators.at(-1).limit = limit;
|
|
11549
|
+
} else {
|
|
11550
|
+
this.config.limit = limit;
|
|
11551
|
+
}
|
|
11552
|
+
return this;
|
|
11553
|
+
}
|
|
11554
|
+
/**
|
|
11555
|
+
* Adds an `offset` clause to the query.
|
|
11556
|
+
*
|
|
11557
|
+
* Calling this method will skip a number of rows when returning results from this query.
|
|
11558
|
+
*
|
|
11559
|
+
* See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}
|
|
11560
|
+
*
|
|
11561
|
+
* @param offset the `offset` clause.
|
|
11562
|
+
*
|
|
11563
|
+
* @example
|
|
11564
|
+
*
|
|
11565
|
+
* ```ts
|
|
11566
|
+
* // Get the 10th-20th people from this query.
|
|
11567
|
+
* await db.select().from(people).offset(10).limit(10);
|
|
11568
|
+
* ```
|
|
11569
|
+
*/
|
|
11570
|
+
offset(offset) {
|
|
11571
|
+
if (this.config.setOperators.length > 0) {
|
|
11572
|
+
this.config.setOperators.at(-1).offset = offset;
|
|
11573
|
+
} else {
|
|
11574
|
+
this.config.offset = offset;
|
|
11575
|
+
}
|
|
11576
|
+
return this;
|
|
11577
|
+
}
|
|
11578
|
+
/** @internal */
|
|
11579
|
+
getSQL() {
|
|
11580
|
+
return this.dialect.buildSelectQuery(this.config);
|
|
11581
|
+
}
|
|
11582
|
+
toSQL() {
|
|
11583
|
+
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
|
11584
|
+
return rest;
|
|
11585
|
+
}
|
|
11586
|
+
as(alias) {
|
|
11587
|
+
return new Proxy(
|
|
11588
|
+
new Subquery(this.getSQL(), this.config.fields, alias),
|
|
11589
|
+
new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
|
|
11590
|
+
);
|
|
11591
|
+
}
|
|
11592
|
+
/** @internal */
|
|
11593
|
+
getSelectedFields() {
|
|
11594
|
+
return new Proxy(
|
|
11595
|
+
this.config.fields,
|
|
11596
|
+
new SelectionProxyHandler({ alias: this.tableName, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
|
|
11597
|
+
);
|
|
11598
|
+
}
|
|
11599
|
+
$dynamic() {
|
|
11600
|
+
return this;
|
|
11601
|
+
}
|
|
11602
|
+
}
|
|
11603
|
+
class SQLiteSelectBase extends SQLiteSelectQueryBuilderBase {
|
|
11604
|
+
static [entityKind] = "SQLiteSelect";
|
|
11605
|
+
/** @internal */
|
|
11606
|
+
_prepare(isOneTimeQuery = true) {
|
|
11607
|
+
if (!this.session) {
|
|
11608
|
+
throw new Error("Cannot execute a query on a query builder. Please use a database instance instead.");
|
|
11609
|
+
}
|
|
11610
|
+
const fieldsList = orderSelectedFields(this.config.fields);
|
|
11611
|
+
const query = this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
|
|
11612
|
+
this.dialect.sqlToQuery(this.getSQL()),
|
|
11613
|
+
fieldsList,
|
|
11614
|
+
"all",
|
|
11615
|
+
true
|
|
11616
|
+
);
|
|
11617
|
+
query.joinsNotNullableMap = this.joinsNotNullableMap;
|
|
11618
|
+
return query;
|
|
11619
|
+
}
|
|
11620
|
+
prepare() {
|
|
11621
|
+
return this._prepare(false);
|
|
11622
|
+
}
|
|
11623
|
+
run = (placeholderValues) => {
|
|
11624
|
+
return this._prepare().run(placeholderValues);
|
|
11625
|
+
};
|
|
11626
|
+
all = (placeholderValues) => {
|
|
11627
|
+
return this._prepare().all(placeholderValues);
|
|
11628
|
+
};
|
|
11629
|
+
get = (placeholderValues) => {
|
|
11630
|
+
return this._prepare().get(placeholderValues);
|
|
11631
|
+
};
|
|
11632
|
+
values = (placeholderValues) => {
|
|
11633
|
+
return this._prepare().values(placeholderValues);
|
|
11634
|
+
};
|
|
11635
|
+
async execute() {
|
|
11636
|
+
return this.all();
|
|
11637
|
+
}
|
|
11638
|
+
}
|
|
11639
|
+
applyMixins(SQLiteSelectBase, [QueryPromise]);
|
|
11640
|
+
function createSetOperator(type, isAll) {
|
|
11641
|
+
return (leftSelect, rightSelect, ...restSelects) => {
|
|
11642
|
+
const setOperators = [rightSelect, ...restSelects].map((select) => ({
|
|
11643
|
+
type,
|
|
11644
|
+
isAll,
|
|
11645
|
+
rightSelect: select
|
|
11646
|
+
}));
|
|
11647
|
+
for (const setOperator of setOperators) {
|
|
11648
|
+
if (!haveSameKeys(leftSelect.getSelectedFields(), setOperator.rightSelect.getSelectedFields())) {
|
|
11649
|
+
throw new Error(
|
|
11650
|
+
"Set operator error (union / intersect / except): selected fields are not the same or are in a different order"
|
|
11651
|
+
);
|
|
11652
|
+
}
|
|
11653
|
+
}
|
|
11654
|
+
return leftSelect.addSetOperators(setOperators);
|
|
11655
|
+
};
|
|
11656
|
+
}
|
|
11657
|
+
const getSQLiteSetOperators = () => ({
|
|
11658
|
+
union,
|
|
11659
|
+
unionAll,
|
|
11660
|
+
intersect,
|
|
11661
|
+
except
|
|
11662
|
+
});
|
|
11663
|
+
const union = createSetOperator("union", false);
|
|
11664
|
+
const unionAll = createSetOperator("union", true);
|
|
11665
|
+
const intersect = createSetOperator("intersect", false);
|
|
11666
|
+
const except = createSetOperator("except", false);
|
|
11667
|
+
class QueryBuilder {
|
|
11668
|
+
static [entityKind] = "SQLiteQueryBuilder";
|
|
11669
|
+
dialect;
|
|
11670
|
+
dialectConfig;
|
|
11671
|
+
constructor(dialect) {
|
|
11672
|
+
this.dialect = is(dialect, SQLiteDialect) ? dialect : void 0;
|
|
11673
|
+
this.dialectConfig = is(dialect, SQLiteDialect) ? void 0 : dialect;
|
|
11674
|
+
}
|
|
11675
|
+
$with(alias) {
|
|
11676
|
+
const queryBuilder = this;
|
|
11677
|
+
return {
|
|
11678
|
+
as(qb) {
|
|
11679
|
+
if (typeof qb === "function") {
|
|
11680
|
+
qb = qb(queryBuilder);
|
|
11681
|
+
}
|
|
11682
|
+
return new Proxy(
|
|
11683
|
+
new WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true),
|
|
11684
|
+
new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
|
|
11685
|
+
);
|
|
11686
|
+
}
|
|
11687
|
+
};
|
|
11688
|
+
}
|
|
11689
|
+
with(...queries) {
|
|
11690
|
+
const self = this;
|
|
11691
|
+
function select(fields) {
|
|
11692
|
+
return new SQLiteSelectBuilder({
|
|
11693
|
+
fields: fields ?? void 0,
|
|
11694
|
+
session: void 0,
|
|
11695
|
+
dialect: self.getDialect(),
|
|
11696
|
+
withList: queries
|
|
11697
|
+
});
|
|
11698
|
+
}
|
|
11699
|
+
function selectDistinct(fields) {
|
|
11700
|
+
return new SQLiteSelectBuilder({
|
|
11701
|
+
fields: fields ?? void 0,
|
|
11702
|
+
session: void 0,
|
|
11703
|
+
dialect: self.getDialect(),
|
|
11704
|
+
withList: queries,
|
|
11705
|
+
distinct: true
|
|
11706
|
+
});
|
|
11707
|
+
}
|
|
11708
|
+
return { select, selectDistinct };
|
|
11709
|
+
}
|
|
11710
|
+
select(fields) {
|
|
11711
|
+
return new SQLiteSelectBuilder({ fields: fields ?? void 0, session: void 0, dialect: this.getDialect() });
|
|
11712
|
+
}
|
|
11713
|
+
selectDistinct(fields) {
|
|
11714
|
+
return new SQLiteSelectBuilder({
|
|
11715
|
+
fields: fields ?? void 0,
|
|
11716
|
+
session: void 0,
|
|
11717
|
+
dialect: this.getDialect(),
|
|
11718
|
+
distinct: true
|
|
11719
|
+
});
|
|
11720
|
+
}
|
|
11721
|
+
// Lazy load dialect to avoid circular dependency
|
|
11722
|
+
getDialect() {
|
|
11723
|
+
if (!this.dialect) {
|
|
11724
|
+
this.dialect = new SQLiteSyncDialect(this.dialectConfig);
|
|
11725
|
+
}
|
|
11726
|
+
return this.dialect;
|
|
11727
|
+
}
|
|
11728
|
+
}
|
|
11729
|
+
class SQLiteInsertBuilder {
|
|
11730
|
+
constructor(table, session, dialect, withList) {
|
|
11731
|
+
this.table = table;
|
|
11732
|
+
this.session = session;
|
|
11733
|
+
this.dialect = dialect;
|
|
11734
|
+
this.withList = withList;
|
|
11735
|
+
}
|
|
11736
|
+
static [entityKind] = "SQLiteInsertBuilder";
|
|
11737
|
+
values(values) {
|
|
11738
|
+
values = Array.isArray(values) ? values : [values];
|
|
11739
|
+
if (values.length === 0) {
|
|
11740
|
+
throw new Error("values() must be called with at least one value");
|
|
11741
|
+
}
|
|
11742
|
+
const mappedValues = values.map((entry) => {
|
|
11743
|
+
const result = {};
|
|
11744
|
+
const cols = this.table[Table.Symbol.Columns];
|
|
11745
|
+
for (const colKey of Object.keys(entry)) {
|
|
11746
|
+
const colValue = entry[colKey];
|
|
11747
|
+
result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
|
|
11748
|
+
}
|
|
11749
|
+
return result;
|
|
11750
|
+
});
|
|
11751
|
+
return new SQLiteInsertBase(this.table, mappedValues, this.session, this.dialect, this.withList);
|
|
11752
|
+
}
|
|
11753
|
+
select(selectQuery) {
|
|
11754
|
+
const select = typeof selectQuery === "function" ? selectQuery(new QueryBuilder()) : selectQuery;
|
|
11755
|
+
if (!is(select, SQL) && !haveSameKeys(this.table[Columns], select._.selectedFields)) {
|
|
11756
|
+
throw new Error(
|
|
11757
|
+
"Insert select error: selected fields are not the same or are in a different order compared to the table definition"
|
|
11758
|
+
);
|
|
11759
|
+
}
|
|
11760
|
+
return new SQLiteInsertBase(this.table, select, this.session, this.dialect, this.withList, true);
|
|
11761
|
+
}
|
|
11762
|
+
}
|
|
11763
|
+
class SQLiteInsertBase extends QueryPromise {
|
|
11764
|
+
constructor(table, values, session, dialect, withList, select) {
|
|
11765
|
+
super();
|
|
11766
|
+
this.session = session;
|
|
11767
|
+
this.dialect = dialect;
|
|
11768
|
+
this.config = { table, values, withList, select };
|
|
11769
|
+
}
|
|
11770
|
+
static [entityKind] = "SQLiteInsert";
|
|
11771
|
+
/** @internal */
|
|
11772
|
+
config;
|
|
11773
|
+
returning(fields = this.config.table[SQLiteTable.Symbol.Columns]) {
|
|
11774
|
+
this.config.returning = orderSelectedFields(fields);
|
|
11775
|
+
return this;
|
|
11776
|
+
}
|
|
11777
|
+
/**
|
|
11778
|
+
* Adds an `on conflict do nothing` clause to the query.
|
|
11779
|
+
*
|
|
11780
|
+
* Calling this method simply avoids inserting a row as its alternative action.
|
|
11781
|
+
*
|
|
11782
|
+
* See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
|
|
11783
|
+
*
|
|
11784
|
+
* @param config The `target` and `where` clauses.
|
|
11785
|
+
*
|
|
11786
|
+
* @example
|
|
11787
|
+
* ```ts
|
|
11788
|
+
* // Insert one row and cancel the insert if there's a conflict
|
|
11789
|
+
* await db.insert(cars)
|
|
11790
|
+
* .values({ id: 1, brand: 'BMW' })
|
|
11791
|
+
* .onConflictDoNothing();
|
|
11792
|
+
*
|
|
11793
|
+
* // Explicitly specify conflict target
|
|
11794
|
+
* await db.insert(cars)
|
|
11795
|
+
* .values({ id: 1, brand: 'BMW' })
|
|
11796
|
+
* .onConflictDoNothing({ target: cars.id });
|
|
11797
|
+
* ```
|
|
11798
|
+
*/
|
|
11799
|
+
onConflictDoNothing(config = {}) {
|
|
11800
|
+
if (config.target === void 0) {
|
|
11801
|
+
this.config.onConflict = sql`do nothing`;
|
|
11802
|
+
} else {
|
|
11803
|
+
const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
|
|
11804
|
+
const whereSql = config.where ? sql` where ${config.where}` : sql``;
|
|
11805
|
+
this.config.onConflict = sql`${targetSql} do nothing${whereSql}`;
|
|
11806
|
+
}
|
|
11807
|
+
return this;
|
|
11808
|
+
}
|
|
11809
|
+
/**
|
|
11810
|
+
* Adds an `on conflict do update` clause to the query.
|
|
11811
|
+
*
|
|
11812
|
+
* Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
|
|
11813
|
+
*
|
|
11814
|
+
* See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
|
|
11815
|
+
*
|
|
11816
|
+
* @param config The `target`, `set` and `where` clauses.
|
|
11817
|
+
*
|
|
11818
|
+
* @example
|
|
11819
|
+
* ```ts
|
|
11820
|
+
* // Update the row if there's a conflict
|
|
11821
|
+
* await db.insert(cars)
|
|
11822
|
+
* .values({ id: 1, brand: 'BMW' })
|
|
11823
|
+
* .onConflictDoUpdate({
|
|
11824
|
+
* target: cars.id,
|
|
11825
|
+
* set: { brand: 'Porsche' }
|
|
11826
|
+
* });
|
|
11827
|
+
*
|
|
11828
|
+
* // Upsert with 'where' clause
|
|
11829
|
+
* await db.insert(cars)
|
|
11830
|
+
* .values({ id: 1, brand: 'BMW' })
|
|
11831
|
+
* .onConflictDoUpdate({
|
|
11832
|
+
* target: cars.id,
|
|
11833
|
+
* set: { brand: 'newBMW' },
|
|
11834
|
+
* where: sql`${cars.createdAt} > '2023-01-01'::date`,
|
|
11835
|
+
* });
|
|
11836
|
+
* ```
|
|
11837
|
+
*/
|
|
11838
|
+
onConflictDoUpdate(config) {
|
|
11839
|
+
if (config.where && (config.targetWhere || config.setWhere)) {
|
|
11840
|
+
throw new Error(
|
|
11841
|
+
'You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.'
|
|
11842
|
+
);
|
|
11843
|
+
}
|
|
11844
|
+
const whereSql = config.where ? sql` where ${config.where}` : void 0;
|
|
11845
|
+
const targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : void 0;
|
|
11846
|
+
const setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : void 0;
|
|
11847
|
+
const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
|
|
11848
|
+
const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
|
|
11849
|
+
this.config.onConflict = sql`${targetSql}${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`;
|
|
11850
|
+
return this;
|
|
11851
|
+
}
|
|
11852
|
+
/** @internal */
|
|
11853
|
+
getSQL() {
|
|
11854
|
+
return this.dialect.buildInsertQuery(this.config);
|
|
9246
11855
|
}
|
|
9247
|
-
|
|
9248
|
-
|
|
11856
|
+
toSQL() {
|
|
11857
|
+
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
|
11858
|
+
return rest;
|
|
9249
11859
|
}
|
|
9250
|
-
|
|
9251
|
-
|
|
9252
|
-
|
|
9253
|
-
|
|
9254
|
-
|
|
9255
|
-
|
|
9256
|
-
|
|
9257
|
-
customTypeParams
|
|
11860
|
+
/** @internal */
|
|
11861
|
+
_prepare(isOneTimeQuery = true) {
|
|
11862
|
+
return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
|
|
11863
|
+
this.dialect.sqlToQuery(this.getSQL()),
|
|
11864
|
+
this.config.returning,
|
|
11865
|
+
this.config.returning ? "all" : "run",
|
|
11866
|
+
true
|
|
9258
11867
|
);
|
|
11868
|
+
}
|
|
11869
|
+
prepare() {
|
|
11870
|
+
return this._prepare(false);
|
|
11871
|
+
}
|
|
11872
|
+
run = (placeholderValues) => {
|
|
11873
|
+
return this._prepare().run(placeholderValues);
|
|
9259
11874
|
};
|
|
9260
|
-
|
|
9261
|
-
|
|
9262
|
-
|
|
9263
|
-
|
|
9264
|
-
|
|
9265
|
-
|
|
11875
|
+
all = (placeholderValues) => {
|
|
11876
|
+
return this._prepare().all(placeholderValues);
|
|
11877
|
+
};
|
|
11878
|
+
get = (placeholderValues) => {
|
|
11879
|
+
return this._prepare().get(placeholderValues);
|
|
11880
|
+
};
|
|
11881
|
+
values = (placeholderValues) => {
|
|
11882
|
+
return this._prepare().values(placeholderValues);
|
|
11883
|
+
};
|
|
11884
|
+
async execute() {
|
|
11885
|
+
return this.config.returning ? this.all() : this.run();
|
|
9266
11886
|
}
|
|
9267
|
-
|
|
9268
|
-
|
|
9269
|
-
this.config.autoIncrement = true;
|
|
9270
|
-
}
|
|
9271
|
-
this.config.hasDefault = true;
|
|
9272
|
-
return super.primaryKey();
|
|
11887
|
+
$dynamic() {
|
|
11888
|
+
return this;
|
|
9273
11889
|
}
|
|
9274
11890
|
}
|
|
9275
|
-
class
|
|
9276
|
-
|
|
9277
|
-
|
|
9278
|
-
|
|
9279
|
-
|
|
11891
|
+
class SQLiteUpdateBuilder {
|
|
11892
|
+
constructor(table, session, dialect, withList) {
|
|
11893
|
+
this.table = table;
|
|
11894
|
+
this.session = session;
|
|
11895
|
+
this.dialect = dialect;
|
|
11896
|
+
this.withList = withList;
|
|
11897
|
+
}
|
|
11898
|
+
static [entityKind] = "SQLiteUpdateBuilder";
|
|
11899
|
+
set(values) {
|
|
11900
|
+
return new SQLiteUpdateBase(
|
|
11901
|
+
this.table,
|
|
11902
|
+
mapUpdateSet(this.table, values),
|
|
11903
|
+
this.session,
|
|
11904
|
+
this.dialect,
|
|
11905
|
+
this.withList
|
|
11906
|
+
);
|
|
9280
11907
|
}
|
|
9281
11908
|
}
|
|
9282
|
-
class
|
|
9283
|
-
|
|
9284
|
-
|
|
9285
|
-
|
|
11909
|
+
class SQLiteUpdateBase extends QueryPromise {
|
|
11910
|
+
constructor(table, set2, session, dialect, withList) {
|
|
11911
|
+
super();
|
|
11912
|
+
this.session = session;
|
|
11913
|
+
this.dialect = dialect;
|
|
11914
|
+
this.config = { set: set2, table, withList, joins: [] };
|
|
9286
11915
|
}
|
|
9287
|
-
|
|
9288
|
-
|
|
9289
|
-
|
|
9290
|
-
|
|
9291
|
-
|
|
11916
|
+
static [entityKind] = "SQLiteUpdate";
|
|
11917
|
+
/** @internal */
|
|
11918
|
+
config;
|
|
11919
|
+
from(source) {
|
|
11920
|
+
this.config.from = source;
|
|
11921
|
+
return this;
|
|
9292
11922
|
}
|
|
9293
|
-
|
|
9294
|
-
|
|
9295
|
-
|
|
9296
|
-
|
|
9297
|
-
|
|
9298
|
-
|
|
9299
|
-
|
|
9300
|
-
|
|
9301
|
-
|
|
11923
|
+
createJoin(joinType) {
|
|
11924
|
+
return (table, on) => {
|
|
11925
|
+
const tableName = getTableLikeName(table);
|
|
11926
|
+
if (typeof tableName === "string" && this.config.joins.some((join2) => join2.alias === tableName)) {
|
|
11927
|
+
throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
11928
|
+
}
|
|
11929
|
+
if (typeof on === "function") {
|
|
11930
|
+
const from = this.config.from ? is(table, SQLiteTable) ? table[Table.Symbol.Columns] : is(table, Subquery) ? table._.selectedFields : is(table, SQLiteViewBase) ? table[ViewBaseConfig].selectedFields : void 0 : void 0;
|
|
11931
|
+
on = on(
|
|
11932
|
+
new Proxy(
|
|
11933
|
+
this.config.table[Table.Symbol.Columns],
|
|
11934
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
|
11935
|
+
),
|
|
11936
|
+
from && new Proxy(
|
|
11937
|
+
from,
|
|
11938
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
|
11939
|
+
)
|
|
11940
|
+
);
|
|
11941
|
+
}
|
|
11942
|
+
this.config.joins.push({ on, table, joinType, alias: tableName });
|
|
11943
|
+
return this;
|
|
11944
|
+
};
|
|
9302
11945
|
}
|
|
11946
|
+
leftJoin = this.createJoin("left");
|
|
11947
|
+
rightJoin = this.createJoin("right");
|
|
11948
|
+
innerJoin = this.createJoin("inner");
|
|
11949
|
+
fullJoin = this.createJoin("full");
|
|
9303
11950
|
/**
|
|
9304
|
-
*
|
|
11951
|
+
* Adds a 'where' clause to the query.
|
|
9305
11952
|
*
|
|
9306
|
-
*
|
|
11953
|
+
* Calling this method will update only those rows that fulfill a specified condition.
|
|
11954
|
+
*
|
|
11955
|
+
* See docs: {@link https://orm.drizzle.team/docs/update}
|
|
11956
|
+
*
|
|
11957
|
+
* @param where the 'where' clause.
|
|
11958
|
+
*
|
|
11959
|
+
* @example
|
|
11960
|
+
* You can use conditional operators and `sql function` to filter the rows to be updated.
|
|
11961
|
+
*
|
|
11962
|
+
* ```ts
|
|
11963
|
+
* // Update all cars with green color
|
|
11964
|
+
* db.update(cars).set({ color: 'red' })
|
|
11965
|
+
* .where(eq(cars.color, 'green'));
|
|
11966
|
+
* // or
|
|
11967
|
+
* db.update(cars).set({ color: 'red' })
|
|
11968
|
+
* .where(sql`${cars.color} = 'green'`)
|
|
11969
|
+
* ```
|
|
11970
|
+
*
|
|
11971
|
+
* You can logically combine conditional operators with `and()` and `or()` operators:
|
|
11972
|
+
*
|
|
11973
|
+
* ```ts
|
|
11974
|
+
* // Update all BMW cars with a green color
|
|
11975
|
+
* db.update(cars).set({ color: 'red' })
|
|
11976
|
+
* .where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
|
11977
|
+
*
|
|
11978
|
+
* // Update all cars with the green or blue color
|
|
11979
|
+
* db.update(cars).set({ color: 'red' })
|
|
11980
|
+
* .where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
|
11981
|
+
* ```
|
|
9307
11982
|
*/
|
|
9308
|
-
|
|
9309
|
-
|
|
11983
|
+
where(where) {
|
|
11984
|
+
this.config.where = where;
|
|
11985
|
+
return this;
|
|
9310
11986
|
}
|
|
9311
|
-
|
|
9312
|
-
|
|
9313
|
-
|
|
9314
|
-
|
|
11987
|
+
orderBy(...columns) {
|
|
11988
|
+
if (typeof columns[0] === "function") {
|
|
11989
|
+
const orderBy = columns[0](
|
|
11990
|
+
new Proxy(
|
|
11991
|
+
this.config.table[Table.Symbol.Columns],
|
|
11992
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "alias", sqlBehavior: "sql" })
|
|
11993
|
+
)
|
|
11994
|
+
);
|
|
11995
|
+
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
|
11996
|
+
this.config.orderBy = orderByArray;
|
|
11997
|
+
} else {
|
|
11998
|
+
const orderByArray = columns;
|
|
11999
|
+
this.config.orderBy = orderByArray;
|
|
12000
|
+
}
|
|
12001
|
+
return this;
|
|
12002
|
+
}
|
|
12003
|
+
limit(limit) {
|
|
12004
|
+
this.config.limit = limit;
|
|
12005
|
+
return this;
|
|
12006
|
+
}
|
|
12007
|
+
returning(fields = this.config.table[SQLiteTable.Symbol.Columns]) {
|
|
12008
|
+
this.config.returning = orderSelectedFields(fields);
|
|
12009
|
+
return this;
|
|
12010
|
+
}
|
|
12011
|
+
/** @internal */
|
|
12012
|
+
getSQL() {
|
|
12013
|
+
return this.dialect.buildUpdateQuery(this.config);
|
|
12014
|
+
}
|
|
12015
|
+
toSQL() {
|
|
12016
|
+
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
|
12017
|
+
return rest;
|
|
12018
|
+
}
|
|
12019
|
+
/** @internal */
|
|
12020
|
+
_prepare(isOneTimeQuery = true) {
|
|
12021
|
+
return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
|
|
12022
|
+
this.dialect.sqlToQuery(this.getSQL()),
|
|
12023
|
+
this.config.returning,
|
|
12024
|
+
this.config.returning ? "all" : "run",
|
|
12025
|
+
true
|
|
9315
12026
|
);
|
|
9316
12027
|
}
|
|
9317
|
-
|
|
9318
|
-
|
|
9319
|
-
static [entityKind] = "SQLiteTimestamp";
|
|
9320
|
-
mode = this.config.mode;
|
|
9321
|
-
mapFromDriverValue(value) {
|
|
9322
|
-
if (this.config.mode === "timestamp") {
|
|
9323
|
-
return new Date(value * 1e3);
|
|
9324
|
-
}
|
|
9325
|
-
return new Date(value);
|
|
12028
|
+
prepare() {
|
|
12029
|
+
return this._prepare(false);
|
|
9326
12030
|
}
|
|
9327
|
-
|
|
9328
|
-
|
|
9329
|
-
|
|
9330
|
-
|
|
9331
|
-
|
|
9332
|
-
|
|
12031
|
+
run = (placeholderValues) => {
|
|
12032
|
+
return this._prepare().run(placeholderValues);
|
|
12033
|
+
};
|
|
12034
|
+
all = (placeholderValues) => {
|
|
12035
|
+
return this._prepare().all(placeholderValues);
|
|
12036
|
+
};
|
|
12037
|
+
get = (placeholderValues) => {
|
|
12038
|
+
return this._prepare().get(placeholderValues);
|
|
12039
|
+
};
|
|
12040
|
+
values = (placeholderValues) => {
|
|
12041
|
+
return this._prepare().values(placeholderValues);
|
|
12042
|
+
};
|
|
12043
|
+
async execute() {
|
|
12044
|
+
return this.config.returning ? this.all() : this.run();
|
|
12045
|
+
}
|
|
12046
|
+
$dynamic() {
|
|
12047
|
+
return this;
|
|
9333
12048
|
}
|
|
9334
12049
|
}
|
|
9335
|
-
class
|
|
9336
|
-
|
|
9337
|
-
|
|
9338
|
-
|
|
9339
|
-
this.
|
|
12050
|
+
class SQLiteCountBuilder extends SQL {
|
|
12051
|
+
constructor(params) {
|
|
12052
|
+
super(SQLiteCountBuilder.buildEmbeddedCount(params.source, params.filters).queryChunks);
|
|
12053
|
+
this.params = params;
|
|
12054
|
+
this.session = params.session;
|
|
12055
|
+
this.sql = SQLiteCountBuilder.buildCount(
|
|
12056
|
+
params.source,
|
|
12057
|
+
params.filters
|
|
12058
|
+
);
|
|
9340
12059
|
}
|
|
9341
|
-
|
|
9342
|
-
|
|
9343
|
-
|
|
9344
|
-
|
|
12060
|
+
sql;
|
|
12061
|
+
static [entityKind] = "SQLiteCountBuilderAsync";
|
|
12062
|
+
[Symbol.toStringTag] = "SQLiteCountBuilderAsync";
|
|
12063
|
+
session;
|
|
12064
|
+
static buildEmbeddedCount(source, filters) {
|
|
12065
|
+
return sql`(select count(*) from ${source}${sql.raw(" where ").if(filters)}${filters})`;
|
|
12066
|
+
}
|
|
12067
|
+
static buildCount(source, filters) {
|
|
12068
|
+
return sql`select count(*) from ${source}${sql.raw(" where ").if(filters)}${filters}`;
|
|
12069
|
+
}
|
|
12070
|
+
then(onfulfilled, onrejected) {
|
|
12071
|
+
return Promise.resolve(this.session.count(this.sql)).then(
|
|
12072
|
+
onfulfilled,
|
|
12073
|
+
onrejected
|
|
9345
12074
|
);
|
|
9346
12075
|
}
|
|
9347
|
-
|
|
9348
|
-
|
|
9349
|
-
static [entityKind] = "SQLiteBoolean";
|
|
9350
|
-
mode = this.config.mode;
|
|
9351
|
-
mapFromDriverValue(value) {
|
|
9352
|
-
return Number(value) === 1;
|
|
12076
|
+
catch(onRejected) {
|
|
12077
|
+
return this.then(void 0, onRejected);
|
|
9353
12078
|
}
|
|
9354
|
-
|
|
9355
|
-
return
|
|
12079
|
+
finally(onFinally) {
|
|
12080
|
+
return this.then(
|
|
12081
|
+
(value) => {
|
|
12082
|
+
onFinally?.();
|
|
12083
|
+
return value;
|
|
12084
|
+
},
|
|
12085
|
+
(reason) => {
|
|
12086
|
+
onFinally?.();
|
|
12087
|
+
throw reason;
|
|
12088
|
+
}
|
|
12089
|
+
);
|
|
9356
12090
|
}
|
|
9357
12091
|
}
|
|
9358
|
-
|
|
9359
|
-
|
|
9360
|
-
|
|
9361
|
-
|
|
12092
|
+
class RelationalQueryBuilder {
|
|
12093
|
+
constructor(mode, fullSchema, schema2, tableNamesMap, table, tableConfig, dialect, session) {
|
|
12094
|
+
this.mode = mode;
|
|
12095
|
+
this.fullSchema = fullSchema;
|
|
12096
|
+
this.schema = schema2;
|
|
12097
|
+
this.tableNamesMap = tableNamesMap;
|
|
12098
|
+
this.table = table;
|
|
12099
|
+
this.tableConfig = tableConfig;
|
|
12100
|
+
this.dialect = dialect;
|
|
12101
|
+
this.session = session;
|
|
12102
|
+
}
|
|
12103
|
+
static [entityKind] = "SQLiteAsyncRelationalQueryBuilder";
|
|
12104
|
+
findMany(config) {
|
|
12105
|
+
return this.mode === "sync" ? new SQLiteSyncRelationalQuery(
|
|
12106
|
+
this.fullSchema,
|
|
12107
|
+
this.schema,
|
|
12108
|
+
this.tableNamesMap,
|
|
12109
|
+
this.table,
|
|
12110
|
+
this.tableConfig,
|
|
12111
|
+
this.dialect,
|
|
12112
|
+
this.session,
|
|
12113
|
+
config ? config : {},
|
|
12114
|
+
"many"
|
|
12115
|
+
) : new SQLiteRelationalQuery(
|
|
12116
|
+
this.fullSchema,
|
|
12117
|
+
this.schema,
|
|
12118
|
+
this.tableNamesMap,
|
|
12119
|
+
this.table,
|
|
12120
|
+
this.tableConfig,
|
|
12121
|
+
this.dialect,
|
|
12122
|
+
this.session,
|
|
12123
|
+
config ? config : {},
|
|
12124
|
+
"many"
|
|
12125
|
+
);
|
|
9362
12126
|
}
|
|
9363
|
-
|
|
9364
|
-
return new
|
|
12127
|
+
findFirst(config) {
|
|
12128
|
+
return this.mode === "sync" ? new SQLiteSyncRelationalQuery(
|
|
12129
|
+
this.fullSchema,
|
|
12130
|
+
this.schema,
|
|
12131
|
+
this.tableNamesMap,
|
|
12132
|
+
this.table,
|
|
12133
|
+
this.tableConfig,
|
|
12134
|
+
this.dialect,
|
|
12135
|
+
this.session,
|
|
12136
|
+
config ? { ...config, limit: 1 } : { limit: 1 },
|
|
12137
|
+
"first"
|
|
12138
|
+
) : new SQLiteRelationalQuery(
|
|
12139
|
+
this.fullSchema,
|
|
12140
|
+
this.schema,
|
|
12141
|
+
this.tableNamesMap,
|
|
12142
|
+
this.table,
|
|
12143
|
+
this.tableConfig,
|
|
12144
|
+
this.dialect,
|
|
12145
|
+
this.session,
|
|
12146
|
+
config ? { ...config, limit: 1 } : { limit: 1 },
|
|
12147
|
+
"first"
|
|
12148
|
+
);
|
|
9365
12149
|
}
|
|
9366
|
-
return new SQLiteIntegerBuilder(name);
|
|
9367
12150
|
}
|
|
9368
|
-
class
|
|
9369
|
-
|
|
9370
|
-
|
|
9371
|
-
|
|
12151
|
+
class SQLiteRelationalQuery extends QueryPromise {
|
|
12152
|
+
constructor(fullSchema, schema2, tableNamesMap, table, tableConfig, dialect, session, config, mode) {
|
|
12153
|
+
super();
|
|
12154
|
+
this.fullSchema = fullSchema;
|
|
12155
|
+
this.schema = schema2;
|
|
12156
|
+
this.tableNamesMap = tableNamesMap;
|
|
12157
|
+
this.table = table;
|
|
12158
|
+
this.tableConfig = tableConfig;
|
|
12159
|
+
this.dialect = dialect;
|
|
12160
|
+
this.session = session;
|
|
12161
|
+
this.config = config;
|
|
12162
|
+
this.mode = mode;
|
|
9372
12163
|
}
|
|
12164
|
+
static [entityKind] = "SQLiteAsyncRelationalQuery";
|
|
9373
12165
|
/** @internal */
|
|
9374
|
-
|
|
9375
|
-
|
|
9376
|
-
|
|
9377
|
-
|
|
12166
|
+
mode;
|
|
12167
|
+
/** @internal */
|
|
12168
|
+
getSQL() {
|
|
12169
|
+
return this.dialect.buildRelationalQuery({
|
|
12170
|
+
fullSchema: this.fullSchema,
|
|
12171
|
+
schema: this.schema,
|
|
12172
|
+
tableNamesMap: this.tableNamesMap,
|
|
12173
|
+
table: this.table,
|
|
12174
|
+
tableConfig: this.tableConfig,
|
|
12175
|
+
queryConfig: this.config,
|
|
12176
|
+
tableAlias: this.tableConfig.tsName
|
|
12177
|
+
}).sql;
|
|
12178
|
+
}
|
|
12179
|
+
/** @internal */
|
|
12180
|
+
_prepare(isOneTimeQuery = false) {
|
|
12181
|
+
const { query, builtQuery } = this._toSQL();
|
|
12182
|
+
return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
|
|
12183
|
+
builtQuery,
|
|
12184
|
+
void 0,
|
|
12185
|
+
this.mode === "first" ? "get" : "all",
|
|
12186
|
+
true,
|
|
12187
|
+
(rawRows, mapColumnValue) => {
|
|
12188
|
+
const rows = rawRows.map(
|
|
12189
|
+
(row) => mapRelationalRow(this.schema, this.tableConfig, row, query.selection, mapColumnValue)
|
|
12190
|
+
);
|
|
12191
|
+
if (this.mode === "first") {
|
|
12192
|
+
return rows[0];
|
|
12193
|
+
}
|
|
12194
|
+
return rows;
|
|
12195
|
+
}
|
|
9378
12196
|
);
|
|
9379
12197
|
}
|
|
9380
|
-
|
|
9381
|
-
|
|
9382
|
-
|
|
9383
|
-
|
|
9384
|
-
|
|
12198
|
+
prepare() {
|
|
12199
|
+
return this._prepare(false);
|
|
12200
|
+
}
|
|
12201
|
+
_toSQL() {
|
|
12202
|
+
const query = this.dialect.buildRelationalQuery({
|
|
12203
|
+
fullSchema: this.fullSchema,
|
|
12204
|
+
schema: this.schema,
|
|
12205
|
+
tableNamesMap: this.tableNamesMap,
|
|
12206
|
+
table: this.table,
|
|
12207
|
+
tableConfig: this.tableConfig,
|
|
12208
|
+
queryConfig: this.config,
|
|
12209
|
+
tableAlias: this.tableConfig.tsName
|
|
12210
|
+
});
|
|
12211
|
+
const builtQuery = this.dialect.sqlToQuery(query.sql);
|
|
12212
|
+
return { query, builtQuery };
|
|
9385
12213
|
}
|
|
9386
|
-
|
|
9387
|
-
|
|
9388
|
-
return new SQLiteNumericBuilder(name ?? "");
|
|
9389
|
-
}
|
|
9390
|
-
class SQLiteRealBuilder extends SQLiteColumnBuilder {
|
|
9391
|
-
static [entityKind] = "SQLiteRealBuilder";
|
|
9392
|
-
constructor(name) {
|
|
9393
|
-
super(name, "number", "SQLiteReal");
|
|
12214
|
+
toSQL() {
|
|
12215
|
+
return this._toSQL().builtQuery;
|
|
9394
12216
|
}
|
|
9395
12217
|
/** @internal */
|
|
9396
|
-
|
|
9397
|
-
|
|
12218
|
+
executeRaw() {
|
|
12219
|
+
if (this.mode === "first") {
|
|
12220
|
+
return this._prepare(false).get();
|
|
12221
|
+
}
|
|
12222
|
+
return this._prepare(false).all();
|
|
9398
12223
|
}
|
|
9399
|
-
|
|
9400
|
-
|
|
9401
|
-
static [entityKind] = "SQLiteReal";
|
|
9402
|
-
getSQLType() {
|
|
9403
|
-
return "real";
|
|
12224
|
+
async execute() {
|
|
12225
|
+
return this.executeRaw();
|
|
9404
12226
|
}
|
|
9405
12227
|
}
|
|
9406
|
-
|
|
9407
|
-
|
|
12228
|
+
class SQLiteSyncRelationalQuery extends SQLiteRelationalQuery {
|
|
12229
|
+
static [entityKind] = "SQLiteSyncRelationalQuery";
|
|
12230
|
+
sync() {
|
|
12231
|
+
return this.executeRaw();
|
|
12232
|
+
}
|
|
9408
12233
|
}
|
|
9409
|
-
class
|
|
9410
|
-
|
|
9411
|
-
|
|
9412
|
-
|
|
9413
|
-
this.
|
|
9414
|
-
this.
|
|
12234
|
+
class SQLiteRaw extends QueryPromise {
|
|
12235
|
+
constructor(execute, getSQL, action, dialect, mapBatchResult) {
|
|
12236
|
+
super();
|
|
12237
|
+
this.execute = execute;
|
|
12238
|
+
this.getSQL = getSQL;
|
|
12239
|
+
this.dialect = dialect;
|
|
12240
|
+
this.mapBatchResult = mapBatchResult;
|
|
12241
|
+
this.config = { action };
|
|
9415
12242
|
}
|
|
12243
|
+
static [entityKind] = "SQLiteRaw";
|
|
9416
12244
|
/** @internal */
|
|
9417
|
-
|
|
9418
|
-
|
|
9419
|
-
|
|
9420
|
-
|
|
9421
|
-
|
|
12245
|
+
config;
|
|
12246
|
+
getQuery() {
|
|
12247
|
+
return { ...this.dialect.sqlToQuery(this.getSQL()), method: this.config.action };
|
|
12248
|
+
}
|
|
12249
|
+
mapResult(result, isFromBatch) {
|
|
12250
|
+
return isFromBatch ? this.mapBatchResult(result) : result;
|
|
12251
|
+
}
|
|
12252
|
+
_prepare() {
|
|
12253
|
+
return this;
|
|
12254
|
+
}
|
|
12255
|
+
/** @internal */
|
|
12256
|
+
isResponseInArrayMode() {
|
|
12257
|
+
return false;
|
|
9422
12258
|
}
|
|
9423
12259
|
}
|
|
9424
|
-
class
|
|
9425
|
-
|
|
9426
|
-
|
|
9427
|
-
|
|
9428
|
-
|
|
9429
|
-
|
|
12260
|
+
class BaseSQLiteDatabase {
|
|
12261
|
+
constructor(resultKind, dialect, session, schema2) {
|
|
12262
|
+
this.resultKind = resultKind;
|
|
12263
|
+
this.dialect = dialect;
|
|
12264
|
+
this.session = session;
|
|
12265
|
+
this._ = schema2 ? {
|
|
12266
|
+
schema: schema2.schema,
|
|
12267
|
+
fullSchema: schema2.fullSchema,
|
|
12268
|
+
tableNamesMap: schema2.tableNamesMap
|
|
12269
|
+
} : {
|
|
12270
|
+
schema: void 0,
|
|
12271
|
+
fullSchema: {},
|
|
12272
|
+
tableNamesMap: {}
|
|
12273
|
+
};
|
|
12274
|
+
this.query = {};
|
|
12275
|
+
const query = this.query;
|
|
12276
|
+
if (this._.schema) {
|
|
12277
|
+
for (const [tableName, columns] of Object.entries(this._.schema)) {
|
|
12278
|
+
query[tableName] = new RelationalQueryBuilder(
|
|
12279
|
+
resultKind,
|
|
12280
|
+
schema2.fullSchema,
|
|
12281
|
+
this._.schema,
|
|
12282
|
+
this._.tableNamesMap,
|
|
12283
|
+
schema2.fullSchema[tableName],
|
|
12284
|
+
columns,
|
|
12285
|
+
dialect,
|
|
12286
|
+
session
|
|
12287
|
+
);
|
|
12288
|
+
}
|
|
12289
|
+
}
|
|
9430
12290
|
}
|
|
9431
|
-
|
|
9432
|
-
|
|
12291
|
+
static [entityKind] = "BaseSQLiteDatabase";
|
|
12292
|
+
query;
|
|
12293
|
+
/**
|
|
12294
|
+
* Creates a subquery that defines a temporary named result set as a CTE.
|
|
12295
|
+
*
|
|
12296
|
+
* It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
|
|
12297
|
+
*
|
|
12298
|
+
* See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
|
|
12299
|
+
*
|
|
12300
|
+
* @param alias The alias for the subquery.
|
|
12301
|
+
*
|
|
12302
|
+
* Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
|
|
12303
|
+
*
|
|
12304
|
+
* @example
|
|
12305
|
+
*
|
|
12306
|
+
* ```ts
|
|
12307
|
+
* // Create a subquery with alias 'sq' and use it in the select query
|
|
12308
|
+
* const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
|
|
12309
|
+
*
|
|
12310
|
+
* const result = await db.with(sq).select().from(sq);
|
|
12311
|
+
* ```
|
|
12312
|
+
*
|
|
12313
|
+
* 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:
|
|
12314
|
+
*
|
|
12315
|
+
* ```ts
|
|
12316
|
+
* // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
|
|
12317
|
+
* const sq = db.$with('sq').as(db.select({
|
|
12318
|
+
* name: sql<string>`upper(${users.name})`.as('name'),
|
|
12319
|
+
* })
|
|
12320
|
+
* .from(users));
|
|
12321
|
+
*
|
|
12322
|
+
* const result = await db.with(sq).select({ name: sq.name }).from(sq);
|
|
12323
|
+
* ```
|
|
12324
|
+
*/
|
|
12325
|
+
$with(alias) {
|
|
12326
|
+
const self = this;
|
|
12327
|
+
return {
|
|
12328
|
+
as(qb) {
|
|
12329
|
+
if (typeof qb === "function") {
|
|
12330
|
+
qb = qb(new QueryBuilder(self.dialect));
|
|
12331
|
+
}
|
|
12332
|
+
return new Proxy(
|
|
12333
|
+
new WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true),
|
|
12334
|
+
new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
|
|
12335
|
+
);
|
|
12336
|
+
}
|
|
12337
|
+
};
|
|
9433
12338
|
}
|
|
9434
|
-
|
|
9435
|
-
|
|
9436
|
-
static [entityKind] = "SQLiteTextJsonBuilder";
|
|
9437
|
-
constructor(name) {
|
|
9438
|
-
super(name, "json", "SQLiteTextJson");
|
|
12339
|
+
$count(source, filters) {
|
|
12340
|
+
return new SQLiteCountBuilder({ source, filters, session: this.session });
|
|
9439
12341
|
}
|
|
9440
|
-
/**
|
|
9441
|
-
|
|
9442
|
-
|
|
9443
|
-
|
|
9444
|
-
|
|
9445
|
-
|
|
12342
|
+
/**
|
|
12343
|
+
* Incorporates a previously defined CTE (using `$with`) into the main query.
|
|
12344
|
+
*
|
|
12345
|
+
* This method allows the main query to reference a temporary named result set.
|
|
12346
|
+
*
|
|
12347
|
+
* See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
|
|
12348
|
+
*
|
|
12349
|
+
* @param queries The CTEs to incorporate into the main query.
|
|
12350
|
+
*
|
|
12351
|
+
* @example
|
|
12352
|
+
*
|
|
12353
|
+
* ```ts
|
|
12354
|
+
* // Define a subquery 'sq' as a CTE using $with
|
|
12355
|
+
* const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
|
|
12356
|
+
*
|
|
12357
|
+
* // Incorporate the CTE 'sq' into the main query and select from it
|
|
12358
|
+
* const result = await db.with(sq).select().from(sq);
|
|
12359
|
+
* ```
|
|
12360
|
+
*/
|
|
12361
|
+
with(...queries) {
|
|
12362
|
+
const self = this;
|
|
12363
|
+
function select(fields) {
|
|
12364
|
+
return new SQLiteSelectBuilder({
|
|
12365
|
+
fields: fields ?? void 0,
|
|
12366
|
+
session: self.session,
|
|
12367
|
+
dialect: self.dialect,
|
|
12368
|
+
withList: queries
|
|
12369
|
+
});
|
|
12370
|
+
}
|
|
12371
|
+
function selectDistinct(fields) {
|
|
12372
|
+
return new SQLiteSelectBuilder({
|
|
12373
|
+
fields: fields ?? void 0,
|
|
12374
|
+
session: self.session,
|
|
12375
|
+
dialect: self.dialect,
|
|
12376
|
+
withList: queries,
|
|
12377
|
+
distinct: true
|
|
12378
|
+
});
|
|
12379
|
+
}
|
|
12380
|
+
function update(table) {
|
|
12381
|
+
return new SQLiteUpdateBuilder(table, self.session, self.dialect, queries);
|
|
12382
|
+
}
|
|
12383
|
+
function insert(into) {
|
|
12384
|
+
return new SQLiteInsertBuilder(into, self.session, self.dialect, queries);
|
|
12385
|
+
}
|
|
12386
|
+
function delete_(from) {
|
|
12387
|
+
return new SQLiteDeleteBase(from, self.session, self.dialect, queries);
|
|
12388
|
+
}
|
|
12389
|
+
return { select, selectDistinct, update, insert, delete: delete_ };
|
|
9446
12390
|
}
|
|
9447
|
-
|
|
9448
|
-
|
|
9449
|
-
static [entityKind] = "SQLiteTextJson";
|
|
9450
|
-
getSQLType() {
|
|
9451
|
-
return "text";
|
|
12391
|
+
select(fields) {
|
|
12392
|
+
return new SQLiteSelectBuilder({ fields: fields ?? void 0, session: this.session, dialect: this.dialect });
|
|
9452
12393
|
}
|
|
9453
|
-
|
|
9454
|
-
return
|
|
12394
|
+
selectDistinct(fields) {
|
|
12395
|
+
return new SQLiteSelectBuilder({
|
|
12396
|
+
fields: fields ?? void 0,
|
|
12397
|
+
session: this.session,
|
|
12398
|
+
dialect: this.dialect,
|
|
12399
|
+
distinct: true
|
|
12400
|
+
});
|
|
9455
12401
|
}
|
|
9456
|
-
|
|
9457
|
-
|
|
12402
|
+
/**
|
|
12403
|
+
* Creates an update query.
|
|
12404
|
+
*
|
|
12405
|
+
* Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.
|
|
12406
|
+
*
|
|
12407
|
+
* Use `.set()` method to specify which values to update.
|
|
12408
|
+
*
|
|
12409
|
+
* See docs: {@link https://orm.drizzle.team/docs/update}
|
|
12410
|
+
*
|
|
12411
|
+
* @param table The table to update.
|
|
12412
|
+
*
|
|
12413
|
+
* @example
|
|
12414
|
+
*
|
|
12415
|
+
* ```ts
|
|
12416
|
+
* // Update all rows in the 'cars' table
|
|
12417
|
+
* await db.update(cars).set({ color: 'red' });
|
|
12418
|
+
*
|
|
12419
|
+
* // Update rows with filters and conditions
|
|
12420
|
+
* await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));
|
|
12421
|
+
*
|
|
12422
|
+
* // Update with returning clause
|
|
12423
|
+
* const updatedCar: Car[] = await db.update(cars)
|
|
12424
|
+
* .set({ color: 'red' })
|
|
12425
|
+
* .where(eq(cars.id, 1))
|
|
12426
|
+
* .returning();
|
|
12427
|
+
* ```
|
|
12428
|
+
*/
|
|
12429
|
+
update(table) {
|
|
12430
|
+
return new SQLiteUpdateBuilder(table, this.session, this.dialect);
|
|
9458
12431
|
}
|
|
9459
|
-
|
|
9460
|
-
|
|
9461
|
-
|
|
9462
|
-
|
|
9463
|
-
|
|
12432
|
+
/**
|
|
12433
|
+
* Creates an insert query.
|
|
12434
|
+
*
|
|
12435
|
+
* Calling this method will create new rows in a table. Use `.values()` method to specify which values to insert.
|
|
12436
|
+
*
|
|
12437
|
+
* See docs: {@link https://orm.drizzle.team/docs/insert}
|
|
12438
|
+
*
|
|
12439
|
+
* @param table The table to insert into.
|
|
12440
|
+
*
|
|
12441
|
+
* @example
|
|
12442
|
+
*
|
|
12443
|
+
* ```ts
|
|
12444
|
+
* // Insert one row
|
|
12445
|
+
* await db.insert(cars).values({ brand: 'BMW' });
|
|
12446
|
+
*
|
|
12447
|
+
* // Insert multiple rows
|
|
12448
|
+
* await db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);
|
|
12449
|
+
*
|
|
12450
|
+
* // Insert with returning clause
|
|
12451
|
+
* const insertedCar: Car[] = await db.insert(cars)
|
|
12452
|
+
* .values({ brand: 'BMW' })
|
|
12453
|
+
* .returning();
|
|
12454
|
+
* ```
|
|
12455
|
+
*/
|
|
12456
|
+
insert(into) {
|
|
12457
|
+
return new SQLiteInsertBuilder(into, this.session, this.dialect);
|
|
9464
12458
|
}
|
|
9465
|
-
|
|
9466
|
-
|
|
9467
|
-
|
|
9468
|
-
|
|
9469
|
-
|
|
9470
|
-
|
|
9471
|
-
|
|
9472
|
-
|
|
9473
|
-
|
|
9474
|
-
|
|
9475
|
-
|
|
9476
|
-
|
|
9477
|
-
|
|
9478
|
-
|
|
9479
|
-
|
|
9480
|
-
|
|
9481
|
-
|
|
9482
|
-
|
|
9483
|
-
|
|
9484
|
-
|
|
9485
|
-
|
|
9486
|
-
|
|
9487
|
-
|
|
9488
|
-
|
|
9489
|
-
|
|
9490
|
-
|
|
9491
|
-
|
|
9492
|
-
|
|
9493
|
-
|
|
9494
|
-
|
|
9495
|
-
|
|
9496
|
-
|
|
9497
|
-
|
|
9498
|
-
|
|
9499
|
-
|
|
9500
|
-
|
|
9501
|
-
|
|
9502
|
-
|
|
9503
|
-
|
|
9504
|
-
|
|
9505
|
-
|
|
9506
|
-
|
|
9507
|
-
|
|
12459
|
+
/**
|
|
12460
|
+
* Creates a delete query.
|
|
12461
|
+
*
|
|
12462
|
+
* Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.
|
|
12463
|
+
*
|
|
12464
|
+
* See docs: {@link https://orm.drizzle.team/docs/delete}
|
|
12465
|
+
*
|
|
12466
|
+
* @param table The table to delete from.
|
|
12467
|
+
*
|
|
12468
|
+
* @example
|
|
12469
|
+
*
|
|
12470
|
+
* ```ts
|
|
12471
|
+
* // Delete all rows in the 'cars' table
|
|
12472
|
+
* await db.delete(cars);
|
|
12473
|
+
*
|
|
12474
|
+
* // Delete rows with filters and conditions
|
|
12475
|
+
* await db.delete(cars).where(eq(cars.color, 'green'));
|
|
12476
|
+
*
|
|
12477
|
+
* // Delete with returning clause
|
|
12478
|
+
* const deletedCar: Car[] = await db.delete(cars)
|
|
12479
|
+
* .where(eq(cars.id, 1))
|
|
12480
|
+
* .returning();
|
|
12481
|
+
* ```
|
|
12482
|
+
*/
|
|
12483
|
+
delete(from) {
|
|
12484
|
+
return new SQLiteDeleteBase(from, this.session, this.dialect);
|
|
12485
|
+
}
|
|
12486
|
+
run(query) {
|
|
12487
|
+
const sequel = typeof query === "string" ? sql.raw(query) : query.getSQL();
|
|
12488
|
+
if (this.resultKind === "async") {
|
|
12489
|
+
return new SQLiteRaw(
|
|
12490
|
+
async () => this.session.run(sequel),
|
|
12491
|
+
() => sequel,
|
|
12492
|
+
"run",
|
|
12493
|
+
this.dialect,
|
|
12494
|
+
this.session.extractRawRunValueFromBatchResult.bind(this.session)
|
|
12495
|
+
);
|
|
12496
|
+
}
|
|
12497
|
+
return this.session.run(sequel);
|
|
12498
|
+
}
|
|
12499
|
+
all(query) {
|
|
12500
|
+
const sequel = typeof query === "string" ? sql.raw(query) : query.getSQL();
|
|
12501
|
+
if (this.resultKind === "async") {
|
|
12502
|
+
return new SQLiteRaw(
|
|
12503
|
+
async () => this.session.all(sequel),
|
|
12504
|
+
() => sequel,
|
|
12505
|
+
"all",
|
|
12506
|
+
this.dialect,
|
|
12507
|
+
this.session.extractRawAllValueFromBatchResult.bind(this.session)
|
|
12508
|
+
);
|
|
12509
|
+
}
|
|
12510
|
+
return this.session.all(sequel);
|
|
12511
|
+
}
|
|
12512
|
+
get(query) {
|
|
12513
|
+
const sequel = typeof query === "string" ? sql.raw(query) : query.getSQL();
|
|
12514
|
+
if (this.resultKind === "async") {
|
|
12515
|
+
return new SQLiteRaw(
|
|
12516
|
+
async () => this.session.get(sequel),
|
|
12517
|
+
() => sequel,
|
|
12518
|
+
"get",
|
|
12519
|
+
this.dialect,
|
|
12520
|
+
this.session.extractRawGetValueFromBatchResult.bind(this.session)
|
|
12521
|
+
);
|
|
12522
|
+
}
|
|
12523
|
+
return this.session.get(sequel);
|
|
12524
|
+
}
|
|
12525
|
+
values(query) {
|
|
12526
|
+
const sequel = typeof query === "string" ? sql.raw(query) : query.getSQL();
|
|
12527
|
+
if (this.resultKind === "async") {
|
|
12528
|
+
return new SQLiteRaw(
|
|
12529
|
+
async () => this.session.values(sequel),
|
|
12530
|
+
() => sequel,
|
|
12531
|
+
"values",
|
|
12532
|
+
this.dialect,
|
|
12533
|
+
this.session.extractRawValuesValueFromBatchResult.bind(this.session)
|
|
12534
|
+
);
|
|
12535
|
+
}
|
|
12536
|
+
return this.session.values(sequel);
|
|
12537
|
+
}
|
|
12538
|
+
transaction(transaction, config) {
|
|
12539
|
+
return this.session.transaction(transaction, config);
|
|
9508
12540
|
}
|
|
9509
|
-
return table;
|
|
9510
12541
|
}
|
|
9511
|
-
const sqliteTable = (name, columns, extraConfig) => {
|
|
9512
|
-
return sqliteTableBase(name, columns, extraConfig);
|
|
9513
|
-
};
|
|
9514
12542
|
class IndexBuilderOn {
|
|
9515
12543
|
constructor(name, unique) {
|
|
9516
12544
|
this.name = name;
|
|
@@ -9557,11 +12585,11 @@ function index(name) {
|
|
|
9557
12585
|
}
|
|
9558
12586
|
function primaryKey(...config) {
|
|
9559
12587
|
if (config[0].columns) {
|
|
9560
|
-
return new
|
|
12588
|
+
return new PrimaryKeyBuilder2(config[0].columns, config[0].name);
|
|
9561
12589
|
}
|
|
9562
|
-
return new
|
|
12590
|
+
return new PrimaryKeyBuilder2(config);
|
|
9563
12591
|
}
|
|
9564
|
-
class
|
|
12592
|
+
class PrimaryKeyBuilder2 {
|
|
9565
12593
|
static [entityKind] = "SQLitePrimaryKeyBuilder";
|
|
9566
12594
|
/** @internal */
|
|
9567
12595
|
columns;
|
|
@@ -9573,10 +12601,10 @@ class PrimaryKeyBuilder {
|
|
|
9573
12601
|
}
|
|
9574
12602
|
/** @internal */
|
|
9575
12603
|
build(table) {
|
|
9576
|
-
return new
|
|
12604
|
+
return new PrimaryKey2(table, this.columns, this.name);
|
|
9577
12605
|
}
|
|
9578
12606
|
}
|
|
9579
|
-
class
|
|
12607
|
+
class PrimaryKey2 {
|
|
9580
12608
|
constructor(table, columns, name) {
|
|
9581
12609
|
this.table = table;
|
|
9582
12610
|
this.columns = columns;
|
|
@@ -9589,12 +12617,322 @@ class PrimaryKey {
|
|
|
9589
12617
|
return this.name ?? `${this.table[SQLiteTable.Symbol.Name]}_${this.columns.map((column) => column.name).join("_")}_pk`;
|
|
9590
12618
|
}
|
|
9591
12619
|
}
|
|
9592
|
-
|
|
12620
|
+
class ExecuteResultSync extends QueryPromise {
|
|
12621
|
+
constructor(resultCb) {
|
|
12622
|
+
super();
|
|
12623
|
+
this.resultCb = resultCb;
|
|
12624
|
+
}
|
|
12625
|
+
static [entityKind] = "ExecuteResultSync";
|
|
12626
|
+
async execute() {
|
|
12627
|
+
return this.resultCb();
|
|
12628
|
+
}
|
|
12629
|
+
sync() {
|
|
12630
|
+
return this.resultCb();
|
|
12631
|
+
}
|
|
12632
|
+
}
|
|
12633
|
+
class SQLitePreparedQuery {
|
|
12634
|
+
constructor(mode, executeMethod, query) {
|
|
12635
|
+
this.mode = mode;
|
|
12636
|
+
this.executeMethod = executeMethod;
|
|
12637
|
+
this.query = query;
|
|
12638
|
+
}
|
|
12639
|
+
static [entityKind] = "PreparedQuery";
|
|
12640
|
+
/** @internal */
|
|
12641
|
+
joinsNotNullableMap;
|
|
12642
|
+
getQuery() {
|
|
12643
|
+
return this.query;
|
|
12644
|
+
}
|
|
12645
|
+
mapRunResult(result, _isFromBatch) {
|
|
12646
|
+
return result;
|
|
12647
|
+
}
|
|
12648
|
+
mapAllResult(_result, _isFromBatch) {
|
|
12649
|
+
throw new Error("Not implemented");
|
|
12650
|
+
}
|
|
12651
|
+
mapGetResult(_result, _isFromBatch) {
|
|
12652
|
+
throw new Error("Not implemented");
|
|
12653
|
+
}
|
|
12654
|
+
execute(placeholderValues) {
|
|
12655
|
+
if (this.mode === "async") {
|
|
12656
|
+
return this[this.executeMethod](placeholderValues);
|
|
12657
|
+
}
|
|
12658
|
+
return new ExecuteResultSync(() => this[this.executeMethod](placeholderValues));
|
|
12659
|
+
}
|
|
12660
|
+
mapResult(response, isFromBatch) {
|
|
12661
|
+
switch (this.executeMethod) {
|
|
12662
|
+
case "run": {
|
|
12663
|
+
return this.mapRunResult(response, isFromBatch);
|
|
12664
|
+
}
|
|
12665
|
+
case "all": {
|
|
12666
|
+
return this.mapAllResult(response, isFromBatch);
|
|
12667
|
+
}
|
|
12668
|
+
case "get": {
|
|
12669
|
+
return this.mapGetResult(response, isFromBatch);
|
|
12670
|
+
}
|
|
12671
|
+
}
|
|
12672
|
+
}
|
|
12673
|
+
}
|
|
12674
|
+
class SQLiteSession {
|
|
12675
|
+
constructor(dialect) {
|
|
12676
|
+
this.dialect = dialect;
|
|
12677
|
+
}
|
|
12678
|
+
static [entityKind] = "SQLiteSession";
|
|
12679
|
+
prepareOneTimeQuery(query, fields, executeMethod, isResponseInArrayMode) {
|
|
12680
|
+
return this.prepareQuery(query, fields, executeMethod, isResponseInArrayMode);
|
|
12681
|
+
}
|
|
12682
|
+
run(query) {
|
|
12683
|
+
const staticQuery = this.dialect.sqlToQuery(query);
|
|
12684
|
+
try {
|
|
12685
|
+
return this.prepareOneTimeQuery(staticQuery, void 0, "run", false).run();
|
|
12686
|
+
} catch (err) {
|
|
12687
|
+
throw new DrizzleError({ cause: err, message: `Failed to run the query '${staticQuery.sql}'` });
|
|
12688
|
+
}
|
|
12689
|
+
}
|
|
12690
|
+
/** @internal */
|
|
12691
|
+
extractRawRunValueFromBatchResult(result) {
|
|
12692
|
+
return result;
|
|
12693
|
+
}
|
|
12694
|
+
all(query) {
|
|
12695
|
+
return this.prepareOneTimeQuery(this.dialect.sqlToQuery(query), void 0, "run", false).all();
|
|
12696
|
+
}
|
|
12697
|
+
/** @internal */
|
|
12698
|
+
extractRawAllValueFromBatchResult(_result) {
|
|
12699
|
+
throw new Error("Not implemented");
|
|
12700
|
+
}
|
|
12701
|
+
get(query) {
|
|
12702
|
+
return this.prepareOneTimeQuery(this.dialect.sqlToQuery(query), void 0, "run", false).get();
|
|
12703
|
+
}
|
|
12704
|
+
/** @internal */
|
|
12705
|
+
extractRawGetValueFromBatchResult(_result) {
|
|
12706
|
+
throw new Error("Not implemented");
|
|
12707
|
+
}
|
|
12708
|
+
values(query) {
|
|
12709
|
+
return this.prepareOneTimeQuery(this.dialect.sqlToQuery(query), void 0, "run", false).values();
|
|
12710
|
+
}
|
|
12711
|
+
async count(sql2) {
|
|
12712
|
+
const result = await this.values(sql2);
|
|
12713
|
+
return result[0][0];
|
|
12714
|
+
}
|
|
12715
|
+
/** @internal */
|
|
12716
|
+
extractRawValuesValueFromBatchResult(_result) {
|
|
12717
|
+
throw new Error("Not implemented");
|
|
12718
|
+
}
|
|
12719
|
+
}
|
|
12720
|
+
class SQLiteTransaction extends BaseSQLiteDatabase {
|
|
12721
|
+
constructor(resultType, dialect, session, schema2, nestedIndex = 0) {
|
|
12722
|
+
super(resultType, dialect, session, schema2);
|
|
12723
|
+
this.schema = schema2;
|
|
12724
|
+
this.nestedIndex = nestedIndex;
|
|
12725
|
+
}
|
|
12726
|
+
static [entityKind] = "SQLiteTransaction";
|
|
12727
|
+
rollback() {
|
|
12728
|
+
throw new TransactionRollbackError();
|
|
12729
|
+
}
|
|
12730
|
+
}
|
|
12731
|
+
class SQLiteD1Session extends SQLiteSession {
|
|
12732
|
+
constructor(client, dialect, schema2, options = {}) {
|
|
12733
|
+
super(dialect);
|
|
12734
|
+
this.client = client;
|
|
12735
|
+
this.schema = schema2;
|
|
12736
|
+
this.options = options;
|
|
12737
|
+
this.logger = options.logger ?? new NoopLogger();
|
|
12738
|
+
}
|
|
12739
|
+
static [entityKind] = "SQLiteD1Session";
|
|
12740
|
+
logger;
|
|
12741
|
+
prepareQuery(query, fields, executeMethod, isResponseInArrayMode, customResultMapper) {
|
|
12742
|
+
const stmt = this.client.prepare(query.sql);
|
|
12743
|
+
return new D1PreparedQuery(
|
|
12744
|
+
stmt,
|
|
12745
|
+
query,
|
|
12746
|
+
this.logger,
|
|
12747
|
+
fields,
|
|
12748
|
+
executeMethod,
|
|
12749
|
+
isResponseInArrayMode,
|
|
12750
|
+
customResultMapper
|
|
12751
|
+
);
|
|
12752
|
+
}
|
|
12753
|
+
async batch(queries) {
|
|
12754
|
+
const preparedQueries = [];
|
|
12755
|
+
const builtQueries = [];
|
|
12756
|
+
for (const query of queries) {
|
|
12757
|
+
const preparedQuery = query._prepare();
|
|
12758
|
+
const builtQuery = preparedQuery.getQuery();
|
|
12759
|
+
preparedQueries.push(preparedQuery);
|
|
12760
|
+
if (builtQuery.params.length > 0) {
|
|
12761
|
+
builtQueries.push(preparedQuery.stmt.bind(...builtQuery.params));
|
|
12762
|
+
} else {
|
|
12763
|
+
const builtQuery2 = preparedQuery.getQuery();
|
|
12764
|
+
builtQueries.push(
|
|
12765
|
+
this.client.prepare(builtQuery2.sql).bind(...builtQuery2.params)
|
|
12766
|
+
);
|
|
12767
|
+
}
|
|
12768
|
+
}
|
|
12769
|
+
const batchResults = await this.client.batch(builtQueries);
|
|
12770
|
+
return batchResults.map((result, i) => preparedQueries[i].mapResult(result, true));
|
|
12771
|
+
}
|
|
12772
|
+
extractRawAllValueFromBatchResult(result) {
|
|
12773
|
+
return result.results;
|
|
12774
|
+
}
|
|
12775
|
+
extractRawGetValueFromBatchResult(result) {
|
|
12776
|
+
return result.results[0];
|
|
12777
|
+
}
|
|
12778
|
+
extractRawValuesValueFromBatchResult(result) {
|
|
12779
|
+
return d1ToRawMapping(result.results);
|
|
12780
|
+
}
|
|
12781
|
+
async transaction(transaction, config) {
|
|
12782
|
+
const tx = new D1Transaction("async", this.dialect, this, this.schema);
|
|
12783
|
+
await this.run(sql.raw(`begin${config?.behavior ? " " + config.behavior : ""}`));
|
|
12784
|
+
try {
|
|
12785
|
+
const result = await transaction(tx);
|
|
12786
|
+
await this.run(sql`commit`);
|
|
12787
|
+
return result;
|
|
12788
|
+
} catch (err) {
|
|
12789
|
+
await this.run(sql`rollback`);
|
|
12790
|
+
throw err;
|
|
12791
|
+
}
|
|
12792
|
+
}
|
|
12793
|
+
}
|
|
12794
|
+
class D1Transaction extends SQLiteTransaction {
|
|
12795
|
+
static [entityKind] = "D1Transaction";
|
|
12796
|
+
async transaction(transaction) {
|
|
12797
|
+
const savepointName = `sp${this.nestedIndex}`;
|
|
12798
|
+
const tx = new D1Transaction("async", this.dialect, this.session, this.schema, this.nestedIndex + 1);
|
|
12799
|
+
await this.session.run(sql.raw(`savepoint ${savepointName}`));
|
|
12800
|
+
try {
|
|
12801
|
+
const result = await transaction(tx);
|
|
12802
|
+
await this.session.run(sql.raw(`release savepoint ${savepointName}`));
|
|
12803
|
+
return result;
|
|
12804
|
+
} catch (err) {
|
|
12805
|
+
await this.session.run(sql.raw(`rollback to savepoint ${savepointName}`));
|
|
12806
|
+
throw err;
|
|
12807
|
+
}
|
|
12808
|
+
}
|
|
12809
|
+
}
|
|
12810
|
+
function d1ToRawMapping(results) {
|
|
12811
|
+
const rows = [];
|
|
12812
|
+
for (const row of results) {
|
|
12813
|
+
const entry = Object.keys(row).map((k) => row[k]);
|
|
12814
|
+
rows.push(entry);
|
|
12815
|
+
}
|
|
12816
|
+
return rows;
|
|
12817
|
+
}
|
|
12818
|
+
class D1PreparedQuery extends SQLitePreparedQuery {
|
|
12819
|
+
constructor(stmt, query, logger, fields, executeMethod, _isResponseInArrayMode, customResultMapper) {
|
|
12820
|
+
super("async", executeMethod, query);
|
|
12821
|
+
this.logger = logger;
|
|
12822
|
+
this._isResponseInArrayMode = _isResponseInArrayMode;
|
|
12823
|
+
this.customResultMapper = customResultMapper;
|
|
12824
|
+
this.fields = fields;
|
|
12825
|
+
this.stmt = stmt;
|
|
12826
|
+
}
|
|
12827
|
+
static [entityKind] = "D1PreparedQuery";
|
|
12828
|
+
/** @internal */
|
|
12829
|
+
customResultMapper;
|
|
12830
|
+
/** @internal */
|
|
12831
|
+
fields;
|
|
12832
|
+
/** @internal */
|
|
12833
|
+
stmt;
|
|
12834
|
+
run(placeholderValues) {
|
|
12835
|
+
const params = fillPlaceholders(this.query.params, placeholderValues ?? {});
|
|
12836
|
+
this.logger.logQuery(this.query.sql, params);
|
|
12837
|
+
return this.stmt.bind(...params).run();
|
|
12838
|
+
}
|
|
12839
|
+
async all(placeholderValues) {
|
|
12840
|
+
const { fields, query, logger, stmt, customResultMapper } = this;
|
|
12841
|
+
if (!fields && !customResultMapper) {
|
|
12842
|
+
const params = fillPlaceholders(query.params, placeholderValues ?? {});
|
|
12843
|
+
logger.logQuery(query.sql, params);
|
|
12844
|
+
return stmt.bind(...params).all().then(({ results }) => this.mapAllResult(results));
|
|
12845
|
+
}
|
|
12846
|
+
const rows = await this.values(placeholderValues);
|
|
12847
|
+
return this.mapAllResult(rows);
|
|
12848
|
+
}
|
|
12849
|
+
mapAllResult(rows, isFromBatch) {
|
|
12850
|
+
if (isFromBatch) {
|
|
12851
|
+
rows = d1ToRawMapping(rows.results);
|
|
12852
|
+
}
|
|
12853
|
+
if (!this.fields && !this.customResultMapper) {
|
|
12854
|
+
return rows;
|
|
12855
|
+
}
|
|
12856
|
+
if (this.customResultMapper) {
|
|
12857
|
+
return this.customResultMapper(rows);
|
|
12858
|
+
}
|
|
12859
|
+
return rows.map((row) => mapResultRow(this.fields, row, this.joinsNotNullableMap));
|
|
12860
|
+
}
|
|
12861
|
+
async get(placeholderValues) {
|
|
12862
|
+
const { fields, joinsNotNullableMap, query, logger, stmt, customResultMapper } = this;
|
|
12863
|
+
if (!fields && !customResultMapper) {
|
|
12864
|
+
const params = fillPlaceholders(query.params, placeholderValues ?? {});
|
|
12865
|
+
logger.logQuery(query.sql, params);
|
|
12866
|
+
return stmt.bind(...params).all().then(({ results }) => results[0]);
|
|
12867
|
+
}
|
|
12868
|
+
const rows = await this.values(placeholderValues);
|
|
12869
|
+
if (!rows[0]) {
|
|
12870
|
+
return void 0;
|
|
12871
|
+
}
|
|
12872
|
+
if (customResultMapper) {
|
|
12873
|
+
return customResultMapper(rows);
|
|
12874
|
+
}
|
|
12875
|
+
return mapResultRow(fields, rows[0], joinsNotNullableMap);
|
|
12876
|
+
}
|
|
12877
|
+
mapGetResult(result, isFromBatch) {
|
|
12878
|
+
if (isFromBatch) {
|
|
12879
|
+
result = d1ToRawMapping(result.results)[0];
|
|
12880
|
+
}
|
|
12881
|
+
if (!this.fields && !this.customResultMapper) {
|
|
12882
|
+
return result;
|
|
12883
|
+
}
|
|
12884
|
+
if (this.customResultMapper) {
|
|
12885
|
+
return this.customResultMapper([result]);
|
|
12886
|
+
}
|
|
12887
|
+
return mapResultRow(this.fields, result, this.joinsNotNullableMap);
|
|
12888
|
+
}
|
|
12889
|
+
values(placeholderValues) {
|
|
12890
|
+
const params = fillPlaceholders(this.query.params, placeholderValues ?? {});
|
|
12891
|
+
this.logger.logQuery(this.query.sql, params);
|
|
12892
|
+
return this.stmt.bind(...params).raw();
|
|
12893
|
+
}
|
|
12894
|
+
/** @internal */
|
|
12895
|
+
isResponseInArrayMode() {
|
|
12896
|
+
return this._isResponseInArrayMode;
|
|
12897
|
+
}
|
|
12898
|
+
}
|
|
12899
|
+
class DrizzleD1Database extends BaseSQLiteDatabase {
|
|
12900
|
+
static [entityKind] = "D1Database";
|
|
12901
|
+
async batch(batch) {
|
|
12902
|
+
return this.session.batch(batch);
|
|
12903
|
+
}
|
|
12904
|
+
}
|
|
12905
|
+
function drizzle(client, config = {}) {
|
|
12906
|
+
const dialect = new SQLiteAsyncDialect({ casing: config.casing });
|
|
12907
|
+
let logger;
|
|
12908
|
+
if (config.logger === true) {
|
|
12909
|
+
logger = new DefaultLogger();
|
|
12910
|
+
} else if (config.logger !== false) {
|
|
12911
|
+
logger = config.logger;
|
|
12912
|
+
}
|
|
12913
|
+
let schema2;
|
|
12914
|
+
if (config.schema) {
|
|
12915
|
+
const tablesConfig = extractTablesRelationalConfig(
|
|
12916
|
+
config.schema,
|
|
12917
|
+
createTableRelationsHelpers
|
|
12918
|
+
);
|
|
12919
|
+
schema2 = {
|
|
12920
|
+
fullSchema: config.schema,
|
|
12921
|
+
schema: tablesConfig.tables,
|
|
12922
|
+
tableNamesMap: tablesConfig.tableNamesMap
|
|
12923
|
+
};
|
|
12924
|
+
}
|
|
12925
|
+
const session = new SQLiteD1Session(client, dialect, schema2, { logger });
|
|
12926
|
+
const db = new DrizzleD1Database("async", dialect, session, schema2);
|
|
12927
|
+
db.$client = client;
|
|
12928
|
+
return db;
|
|
12929
|
+
}
|
|
12930
|
+
const sources = sqliteTable("sources", {
|
|
9593
12931
|
key: text("key").primaryKey(),
|
|
9594
12932
|
text: text("text").notNull(),
|
|
9595
12933
|
type: text("type").notNull().default("paragraph")
|
|
9596
12934
|
});
|
|
9597
|
-
sqliteTable(
|
|
12935
|
+
const sourceFiles = sqliteTable(
|
|
9598
12936
|
"source_files",
|
|
9599
12937
|
{
|
|
9600
12938
|
key: text("key").notNull(),
|
|
@@ -9608,7 +12946,7 @@ sqliteTable(
|
|
|
9608
12946
|
index("idx_source_files_file").on(table.version, table.file)
|
|
9609
12947
|
]
|
|
9610
12948
|
);
|
|
9611
|
-
sqliteTable(
|
|
12949
|
+
const translations = sqliteTable(
|
|
9612
12950
|
"translations",
|
|
9613
12951
|
{
|
|
9614
12952
|
lang: text("lang").notNull(),
|
|
@@ -9622,7 +12960,7 @@ sqliteTable(
|
|
|
9622
12960
|
index("idx_translations_lang").on(table.lang)
|
|
9623
12961
|
]
|
|
9624
12962
|
);
|
|
9625
|
-
sqliteTable("content", {
|
|
12963
|
+
const content = sqliteTable("content", {
|
|
9626
12964
|
path: text("path").primaryKey(),
|
|
9627
12965
|
body: text("body").notNull(),
|
|
9628
12966
|
project: text("project").notNull(),
|
|
@@ -9630,6 +12968,16 @@ sqliteTable("content", {
|
|
|
9630
12968
|
lang: text("lang").notNull(),
|
|
9631
12969
|
updatedAt: integer("updated_at")
|
|
9632
12970
|
});
|
|
12971
|
+
const schema = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
12972
|
+
__proto__: null,
|
|
12973
|
+
content,
|
|
12974
|
+
sourceFiles,
|
|
12975
|
+
sources,
|
|
12976
|
+
translations
|
|
12977
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
12978
|
+
function createDb(d1) {
|
|
12979
|
+
return drizzle(d1, { schema });
|
|
12980
|
+
}
|
|
9633
12981
|
let _translationCache = null;
|
|
9634
12982
|
function getTranslationCache(projectRoot) {
|
|
9635
12983
|
if (_translationCache) return _translationCache;
|
|
@@ -9698,9 +13046,9 @@ function createFsLoader(projectRoot, docsRoot = "content", urlMapper) {
|
|
|
9698
13046
|
return null;
|
|
9699
13047
|
}
|
|
9700
13048
|
function parseRawDoc(raw, filePath, locale, isFallback) {
|
|
9701
|
-
const { data, content } = matter(raw);
|
|
13049
|
+
const { data, content: content2 } = matter(raw);
|
|
9702
13050
|
return {
|
|
9703
|
-
content,
|
|
13051
|
+
content: content2,
|
|
9704
13052
|
meta: { title: data.title || "", ...data },
|
|
9705
13053
|
locale,
|
|
9706
13054
|
isFallback,
|
|
@@ -9758,9 +13106,9 @@ function createFsLoader(projectRoot, docsRoot = "content", urlMapper) {
|
|
|
9758
13106
|
// fallbackToSource — use EN text for untranslated nodes
|
|
9759
13107
|
);
|
|
9760
13108
|
if (result.cachedCount > 0) {
|
|
9761
|
-
const { data, content } = matter(result.content);
|
|
13109
|
+
const { data, content: content2 } = matter(result.content);
|
|
9762
13110
|
return {
|
|
9763
|
-
content,
|
|
13111
|
+
content: content2,
|
|
9764
13112
|
meta: { title: data.title || "", ...data },
|
|
9765
13113
|
locale: lang,
|
|
9766
13114
|
isFallback: false,
|
|
@@ -9811,6 +13159,77 @@ function createFsLoader(projectRoot, docsRoot = "content", urlMapper) {
|
|
|
9811
13159
|
}
|
|
9812
13160
|
};
|
|
9813
13161
|
}
|
|
13162
|
+
function createD1Loader(db) {
|
|
13163
|
+
async function loadBySlug(prefix, slug) {
|
|
13164
|
+
for (const ext of [".mdx", ".md"]) {
|
|
13165
|
+
const path2 = `${prefix}/${slug}${ext}`;
|
|
13166
|
+
const row = await db.select().from(content).where(eq(content.path, path2)).get();
|
|
13167
|
+
if (row) return { row: { body: row.body, path: path2 } };
|
|
13168
|
+
}
|
|
13169
|
+
return null;
|
|
13170
|
+
}
|
|
13171
|
+
return {
|
|
13172
|
+
async loadDoc(project, version, lang, slug) {
|
|
13173
|
+
const result = await loadBySlug(`${project}/${version}/${lang}`, slug);
|
|
13174
|
+
if (result) {
|
|
13175
|
+
const { data, content: content2 } = matter(result.row.body);
|
|
13176
|
+
return {
|
|
13177
|
+
content: content2,
|
|
13178
|
+
meta: { title: data.title || "", ...data },
|
|
13179
|
+
locale: lang,
|
|
13180
|
+
isFallback: false,
|
|
13181
|
+
filePath: result.row.path
|
|
13182
|
+
};
|
|
13183
|
+
}
|
|
13184
|
+
if (lang !== "en") {
|
|
13185
|
+
const enResult = await loadBySlug(`${project}/${version}/en`, slug);
|
|
13186
|
+
if (enResult) {
|
|
13187
|
+
const { data, content: content2 } = matter(enResult.row.body);
|
|
13188
|
+
return {
|
|
13189
|
+
content: content2,
|
|
13190
|
+
meta: { title: data.title || "", ...data },
|
|
13191
|
+
locale: "en",
|
|
13192
|
+
isFallback: true,
|
|
13193
|
+
filePath: enResult.row.path
|
|
13194
|
+
};
|
|
13195
|
+
}
|
|
13196
|
+
}
|
|
13197
|
+
throw new Error(
|
|
13198
|
+
`Document not found: ${project}/${version}/${lang}/${slug}`
|
|
13199
|
+
);
|
|
13200
|
+
},
|
|
13201
|
+
async loadDocsConfig(project, version) {
|
|
13202
|
+
const configPath = `${project}/${version}/en/config.json`;
|
|
13203
|
+
const row = await db.select().from(content).where(eq(content.path, configPath)).get();
|
|
13204
|
+
if (row) {
|
|
13205
|
+
return JSON.parse(row.body);
|
|
13206
|
+
}
|
|
13207
|
+
const docsConfigPath = `${project}/docs.config.json`;
|
|
13208
|
+
const row1b = await db.select().from(content).where(eq(content.path, docsConfigPath)).get();
|
|
13209
|
+
if (row1b) {
|
|
13210
|
+
return JSON.parse(row1b.body);
|
|
13211
|
+
}
|
|
13212
|
+
const projectConfigPath = `${project}/config.json`;
|
|
13213
|
+
const row2 = await db.select().from(content).where(eq(content.path, projectConfigPath)).get();
|
|
13214
|
+
if (row2) {
|
|
13215
|
+
return JSON.parse(row2.body);
|
|
13216
|
+
}
|
|
13217
|
+
return null;
|
|
13218
|
+
},
|
|
13219
|
+
async listDocs(project, version, lang, dir) {
|
|
13220
|
+
const prefix = dir ? `${project}/${version}/${lang}/${dir}/` : `${project}/${version}/${lang}/`;
|
|
13221
|
+
const rows = await db.select({ path: content.path }).from(content).where(
|
|
13222
|
+
and(
|
|
13223
|
+
like(content.path, `${prefix}%`),
|
|
13224
|
+
eq(content.project, project),
|
|
13225
|
+
eq(content.version, version),
|
|
13226
|
+
eq(content.lang, lang)
|
|
13227
|
+
)
|
|
13228
|
+
).all();
|
|
13229
|
+
return rows.map((r) => r.path.replace(prefix, "").replace(/\.mdx?$/, "")).filter((s) => s.length > 0);
|
|
13230
|
+
}
|
|
13231
|
+
};
|
|
13232
|
+
}
|
|
9814
13233
|
function toTitleCase(name) {
|
|
9815
13234
|
return name.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
|
|
9816
13235
|
}
|
|
@@ -9919,9 +13338,30 @@ function getProjectRoot() {
|
|
|
9919
13338
|
}
|
|
9920
13339
|
return cwd;
|
|
9921
13340
|
}
|
|
13341
|
+
let _d1Cache;
|
|
13342
|
+
function getD1() {
|
|
13343
|
+
if (_d1Cache !== void 0) return _d1Cache || null;
|
|
13344
|
+
try {
|
|
13345
|
+
const db = globalThis.__D1_DB;
|
|
13346
|
+
if (db) {
|
|
13347
|
+
_d1Cache = db;
|
|
13348
|
+
return db;
|
|
13349
|
+
}
|
|
13350
|
+
} catch {
|
|
13351
|
+
}
|
|
13352
|
+
_d1Cache = false;
|
|
13353
|
+
return null;
|
|
13354
|
+
}
|
|
13355
|
+
function getContentLoader(docsRoot, urlMapper) {
|
|
13356
|
+
const d1 = getD1();
|
|
13357
|
+
if (d1) {
|
|
13358
|
+
return createD1Loader(createDb(d1));
|
|
13359
|
+
}
|
|
13360
|
+
return createFsLoader(getProjectRoot(), docsRoot, urlMapper);
|
|
13361
|
+
}
|
|
9922
13362
|
async function loadDoc(project, version, lang, slug, projectConfig) {
|
|
9923
13363
|
const docsRoot = projectConfig?.docsRoot || "content";
|
|
9924
|
-
const loader =
|
|
13364
|
+
const loader = getContentLoader(docsRoot, projectConfig?.urlMapper);
|
|
9925
13365
|
return loader.loadDoc(project, version, lang, slug);
|
|
9926
13366
|
}
|
|
9927
13367
|
async function loadDocsConfig(project, version, projectConfig) {
|
|
@@ -9929,7 +13369,7 @@ async function loadDocsConfig(project, version, projectConfig) {
|
|
|
9929
13369
|
return loadFilesystemSidebar(project, version, projectConfig);
|
|
9930
13370
|
}
|
|
9931
13371
|
const docsRoot = projectConfig?.docsRoot || "content";
|
|
9932
|
-
const loader =
|
|
13372
|
+
const loader = getContentLoader(docsRoot);
|
|
9933
13373
|
const config = await loader.loadDocsConfig(project, version);
|
|
9934
13374
|
if (config) return config;
|
|
9935
13375
|
return autoScanDocs(getProjectRoot(), docsRoot, project, version);
|