@shumai-one/shumai 0.6.2 → 0.6.3

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.
Files changed (165) hide show
  1. package/bin/chunk-02b5bcmc.js +1 -0
  2. package/bin/{chunk-m0q2cgfg.js → chunk-09mj32d7.js} +1 -1
  3. package/bin/{chunk-b7bnp021.js → chunk-09mpcg9x.js} +2 -2
  4. package/bin/{chunk-257dcd2f.js → chunk-0a298n62.js} +2 -2
  5. package/bin/{chunk-cz13a82m.js → chunk-0rgbxp24.js} +2 -2
  6. package/bin/{chunk-mwktrwtx.js → chunk-19zbh4fr.js} +1 -1
  7. package/bin/{chunk-v05rrxp5.js → chunk-1e1q1hyg.js} +2 -2
  8. package/bin/{chunk-fatmqnp1.js → chunk-1ja2zw4w.js} +1 -1
  9. package/bin/chunk-1tar0x8s.js +7 -0
  10. package/bin/{chunk-1nvd90g2.js → chunk-1y6h4vge.js} +1 -1
  11. package/bin/{chunk-tekwpkjf.js → chunk-20bamhwa.js} +2 -2
  12. package/bin/{chunk-8mqbztj8.js → chunk-20w1w9x7.js} +2 -2
  13. package/bin/{chunk-qwpkcp8d.js → chunk-25npafhz.js} +2 -2
  14. package/bin/{chunk-km4gn6b6.js → chunk-2qgagdb7.js} +1 -1
  15. package/bin/chunk-2t6g3pny.js +3 -0
  16. package/bin/{chunk-ns33grgx.js → chunk-34f64q0q.js} +1 -1
  17. package/bin/{chunk-1wfg56z3.js → chunk-3hgrw1m0.js} +4 -4
  18. package/bin/{chunk-p3f5aevs.js → chunk-3s2ga6mt.js} +1 -1
  19. package/bin/{chunk-hzkjgcre.js → chunk-3vpz5nat.js} +1 -1
  20. package/bin/{chunk-2jj4j8cn.js → chunk-4p31kxjh.js} +2 -2
  21. package/bin/{chunk-9t3p4xp6.js → chunk-4vjgdj0h.js} +1 -1
  22. package/bin/{chunk-96qpjght.js → chunk-50pfmxt1.js} +2 -2
  23. package/bin/{chunk-2cdxm1cp.js → chunk-5ddg5ezb.js} +9 -9
  24. package/bin/chunk-5ngftxjb.js +218 -0
  25. package/bin/{chunk-r1xer8gn.js → chunk-6f3zhq64.js} +3 -3
  26. package/bin/chunk-6nqqe7w9.js +1 -0
  27. package/bin/{chunk-h1n7jqnw.js → chunk-6t525bmg.js} +1 -1
  28. package/bin/{chunk-01052ssf.js → chunk-7546ptwg.js} +11 -11
  29. package/bin/{chunk-82tps5n1.js → chunk-7jz3cmq6.js} +1 -1
  30. package/bin/{chunk-v5cn90cf.js → chunk-7kah3zb5.js} +2 -2
  31. package/bin/{chunk-73yncv54.js → chunk-7mawxsk3.js} +2 -2
  32. package/bin/chunk-8ww98y1m.js +2 -0
  33. package/bin/{chunk-55h9ze53.js → chunk-9405hzv2.js} +2 -2
  34. package/bin/{chunk-cgmebxx6.js → chunk-95b4mwyq.js} +1 -1
  35. package/bin/chunk-9vxmgvc8.js +2 -0
  36. package/bin/{chunk-knj2s8mg.js → chunk-9x42vgeq.js} +5 -5
  37. package/bin/{chunk-7sgrtxbt.js → chunk-a859y4e1.js} +2 -2
  38. package/bin/{chunk-y241cxff.js → chunk-addssm8d.js} +1 -1
  39. package/bin/{chunk-f6avg5qe.js → chunk-ajq9sxg0.js} +33 -33
  40. package/bin/chunk-amp9h878.js +2 -0
  41. package/bin/{chunk-yk12hydf.js → chunk-atdfqdkj.js} +4 -4
  42. package/bin/{chunk-5wapd171.js → chunk-atpt99h4.js} +10 -10
  43. package/bin/chunk-awshe30f.js +1 -0
  44. package/bin/chunk-b3t7gbhm.js +2 -0
  45. package/bin/{chunk-e4f56spj.js → chunk-bbxwyhz3.js} +3 -3
  46. package/bin/{chunk-a411xhmm.js → chunk-bd3v8mp1.js} +4 -4
  47. package/bin/{chunk-167z646e.js → chunk-brgns7hv.js} +1 -1
  48. package/bin/{chunk-576nj64j.js → chunk-c02727j9.js} +2 -2
  49. package/bin/{chunk-8yjsmr7g.js → chunk-c1wvs81k.js} +1 -1
  50. package/bin/chunk-c8frmqsk.js +2 -0
  51. package/bin/{chunk-xc54vhfz.js → chunk-cagzye3j.js} +1 -1
  52. package/bin/{chunk-s9ksftq2.js → chunk-cp96e9pq.js} +1 -1
  53. package/bin/{chunk-q5vkxee3.js → chunk-d55138xx.js} +2 -2
  54. package/bin/{chunk-7v7mypc6.js → chunk-ddmf9gqv.js} +2 -2
  55. package/bin/chunk-djb65frk.js +1 -0
  56. package/bin/{chunk-q83h0hkx.js → chunk-dkhdn92k.js} +2 -2
  57. package/bin/chunk-dx9f5wab.js +1 -0
  58. package/bin/{chunk-f25fe9th.js → chunk-dygj751y.js} +11 -11
  59. package/bin/{chunk-m9adtgzk.js → chunk-e55sgg8t.js} +1 -1
  60. package/bin/{chunk-q8w4mbw4.js → chunk-enax4303.js} +2 -2
  61. package/bin/{chunk-vcrmjtcz.js → chunk-erfkd3z9.js} +2 -2
  62. package/bin/{chunk-8cjet7pp.js → chunk-esj0kwe5.js} +5 -5
  63. package/bin/{chunk-atfz7g7e.js → chunk-etrm28sy.js} +1 -1
  64. package/bin/chunk-ex3174e3.js +2 -0
  65. package/bin/{chunk-9n1w5dw1.js → chunk-ezjxx44x.js} +3 -3
  66. package/bin/{chunk-cf5axr8c.js → chunk-f4xnx4n6.js} +1 -1
  67. package/bin/{chunk-7naa7tpn.js → chunk-f8hgy69t.js} +2 -2
  68. package/bin/chunk-fakph5jp.js +1 -0
  69. package/bin/{chunk-kvhf12b4.js → chunk-femnbfkj.js} +1 -1
  70. package/bin/{chunk-ah8fjb6f.js → chunk-ffjdkdcv.js} +2 -2
  71. package/bin/{chunk-vkzasgxw.js → chunk-gd016e9p.js} +2 -2
  72. package/bin/{chunk-ympbfzz4.js → chunk-gyv3yrhj.js} +1 -1
  73. package/bin/{chunk-jzgbxqdg.js → chunk-h2bphev9.js} +2 -2
  74. package/bin/chunk-h3atwgx2.js +1 -0
  75. package/bin/chunk-h7xny3de.js +2 -0
  76. package/bin/{chunk-m82tkhaa.js → chunk-hg3rkp41.js} +5 -5
  77. package/bin/{chunk-3z85zxkn.js → chunk-hpzk9k55.js} +1 -1
  78. package/bin/{chunk-9zsv6d2f.js → chunk-hsyfrzdd.js} +1 -1
  79. package/bin/chunk-hvyy8vct.js +3 -0
  80. package/bin/{chunk-b5rhvzv9.js → chunk-j2txsbxz.js} +2 -2
  81. package/bin/chunk-j6x53e33.js +1 -0
  82. package/bin/chunk-jacanzp7.js +1 -0
  83. package/bin/{chunk-g6sdezec.js → chunk-jc7dycy6.js} +1 -1
  84. package/bin/{chunk-cwat1jwx.js → chunk-k7vbk8v4.js} +1 -1
  85. package/bin/{chunk-zrszykjf.js → chunk-mn0kt3p6.js} +1 -1
  86. package/bin/chunk-mn71dffh.js +4 -0
  87. package/bin/{chunk-vp3czaeh.js → chunk-npeapp7e.js} +2 -2
  88. package/bin/{chunk-2nhgdqdg.js → chunk-p2vsdnd1.js} +2 -2
  89. package/bin/chunk-pdw77q09.js +2 -0
  90. package/bin/{chunk-zezje74z.js → chunk-pq6kdp83.js} +3 -3
  91. package/bin/chunk-ptcz4ed3.js +2 -0
  92. package/bin/{chunk-z1p13dnc.js → chunk-q1fzgqsv.js} +2 -2
  93. package/bin/chunk-q4ny4hpt.js +2 -0
  94. package/bin/{chunk-mzsw9var.js → chunk-q5x0yywj.js} +2 -2
  95. package/bin/{chunk-g22wmpk1.js → chunk-q8xr1a8j.js} +2 -2
  96. package/bin/chunk-q8ysc5ex.js +1 -0
  97. package/bin/{chunk-1ktk6764.js → chunk-qm50g4n5.js} +4 -4
  98. package/bin/{chunk-q2bew2vc.js → chunk-qvp24w0q.js} +2 -2
  99. package/bin/{chunk-9xhjy897.js → chunk-r6t0j0jx.js} +3 -3
  100. package/bin/chunk-s1j4v33x.js +2 -0
  101. package/bin/{chunk-yq32evnn.js → chunk-s6pk2zyg.js} +5 -5
  102. package/bin/{chunk-hnkcgvcj.js → chunk-s74g9vsk.js} +1 -1
  103. package/bin/{chunk-gxepkvt2.js → chunk-sz19nn1x.js} +1 -1
  104. package/bin/{chunk-hpbn0k9n.js → chunk-sz5zawfw.js} +1 -1
  105. package/bin/chunk-t68y25gf.js +1 -0
  106. package/bin/{chunk-mcw198kg.js → chunk-te484xtb.js} +8 -8
  107. package/bin/{chunk-jt0ykktx.js → chunk-tfrevef9.js} +1 -1
  108. package/bin/chunk-thpw6tcj.js +2 -0
  109. package/bin/{chunk-02fvcrej.js → chunk-v0yevesp.js} +7 -7
  110. package/bin/chunk-vj4gamdn.js +2 -0
  111. package/bin/{chunk-p4s95471.js → chunk-vmwys2ch.js} +1 -1
  112. package/bin/{chunk-e4yscwen.js → chunk-vnmggrd6.js} +7 -7
  113. package/bin/{chunk-hpwv4am3.js → chunk-vv0m0m2f.js} +4 -4
  114. package/bin/{chunk-x03jwaga.js → chunk-w6g84d59.js} +4 -4
  115. package/bin/{chunk-3ckkwdjx.js → chunk-wgvgtttc.js} +3 -3
  116. package/bin/chunk-xy9qpn6b.js +1 -0
  117. package/bin/{chunk-mcj1xpcc.js → chunk-y3haqtr8.js} +2 -2
  118. package/bin/chunk-y5dv67mg.js +2 -0
  119. package/bin/{chunk-4mws03es.js → chunk-yb4mzqrd.js} +2 -2
  120. package/bin/{chunk-x8mjh387.js → chunk-z0de127n.js} +4 -4
  121. package/bin/chunk-z8t6e0ee.js +1 -0
  122. package/bin/chunk-zfg4yy3c.js +2 -0
  123. package/bin/{chunk-hw6czrya.js → chunk-zkvezz89.js} +1 -1
  124. package/bin/chunk-zrrnvdxq.js +3 -0
  125. package/bin/{chunk-srxp5jav.js → chunk-zx1c4vm5.js} +30 -30
  126. package/bin/chunk-zzqse5qc.js +2 -0
  127. package/bin/shumai-app.html +1 -1
  128. package/bin/shumai-app.js +328 -328
  129. package/package.json +7 -7
  130. package/bin/chunk-0bj887zm.js +0 -2
  131. package/bin/chunk-26qn7fek.js +0 -2
  132. package/bin/chunk-2ne2b54t.js +0 -2
  133. package/bin/chunk-2vbeqczj.js +0 -1
  134. package/bin/chunk-37p6bcx2.js +0 -1
  135. package/bin/chunk-3knfx6dm.js +0 -1
  136. package/bin/chunk-54tbfvya.js +0 -2
  137. package/bin/chunk-56kh5fxc.js +0 -1
  138. package/bin/chunk-6cnqjngz.js +0 -1
  139. package/bin/chunk-7g46e1wy.js +0 -3
  140. package/bin/chunk-84x8p7v5.js +0 -1
  141. package/bin/chunk-8fyg9dy4.js +0 -2
  142. package/bin/chunk-8gtfgkrn.js +0 -2
  143. package/bin/chunk-8xb6yz11.js +0 -2
  144. package/bin/chunk-91rb0jpb.js +0 -2
  145. package/bin/chunk-9f1xk1nt.js +0 -1
  146. package/bin/chunk-9mk9cvbk.js +0 -1
  147. package/bin/chunk-9nw5w8vh.js +0 -1
  148. package/bin/chunk-dk42gf7v.js +0 -2
  149. package/bin/chunk-eb7mzbfm.js +0 -1
  150. package/bin/chunk-er14d498.js +0 -3
  151. package/bin/chunk-fvx9k1dc.js +0 -2
  152. package/bin/chunk-gtf19jc1.js +0 -2
  153. package/bin/chunk-hfm82066.js +0 -2
  154. package/bin/chunk-kj6h5j5a.js +0 -4
  155. package/bin/chunk-ny1kbmxt.js +0 -2
  156. package/bin/chunk-p3j6ydk1.js +0 -1
  157. package/bin/chunk-pk406dgy.js +0 -2
  158. package/bin/chunk-s1e4qy3q.js +0 -14
  159. package/bin/chunk-swtwaaqe.js +0 -1
  160. package/bin/chunk-tagdrg7p.js +0 -1
  161. package/bin/chunk-twtxnzbv.js +0 -2
  162. package/bin/chunk-v5mcjwxy.js +0 -2
  163. package/bin/chunk-x342vzdx.js +0 -2
  164. package/bin/chunk-xvkwbczx.js +0 -3
  165. package/bin/chunk-zarz3sqn.js +0 -211
@@ -1,7 +1,7 @@
1
1
  // @bun
2
- function So(e){return typeof e>"u"||e===void 0}function dr(e){return typeof e==="string"}function zs(e){return typeof e==="number"}function Vi(e){return typeof e==="boolean"}function Fa(e){return e===null}function rf(e){return e instanceof Date}function La(e){return typeof e==="bigint"}function zg(e){return typeof Buffer<"u"&&Buffer.isBuffer(e)}function fr(e){return typeof e==="function"}function sn(e){return typeof e==="object"&&e!==null}function C(e){return Object.freeze(e)}function xe(e){if(x(e))return e;else return[e]}function x(e){return Array.isArray(e)}function Io(e){return e}var st=C({is(e){return e.kind==="IdentifierNode"},create(e){return C({kind:"IdentifierNode",name:e})}});var jg=["preserve rows","delete rows","drop"],fo=C({is(e){return e.kind==="CreateTableNode"},create(e){return C({kind:"CreateTableNode",table:e,columns:C([])})},cloneWithColumn(e,t){return C({...e,columns:C([...e.columns,t])})},cloneWithConstraint(e,t){return C({...e,constraints:e.constraints?C([...e.constraints,t]):C([t])})},cloneWithFrontModifier(e,t){return C({...e,frontModifiers:e.frontModifiers?C([...e.frontModifiers,t]):C([t])})},cloneWithEndModifier(e,t){return C({...e,endModifiers:e.endModifiers?C([...e.endModifiers,t]):C([t])})},cloneWith(e,t){return C({...e,...t})}});var po=C({is(e){return e.kind==="SchemableIdentifierNode"},create(e){return C({kind:"SchemableIdentifierNode",identifier:st.create(e)})},createWithSchema(e,t){return C({kind:"SchemableIdentifierNode",schema:st.create(e),identifier:st.create(t)})}});var l=C({is(e){return e.kind==="AliasNode"},create(e,t){return C({kind:"AliasNode",node:e,alias:t})}});var mo=C({is(e){return e.kind==="TableNode"},create(e){return C({kind:"TableNode",table:po.create(e)})},createWithSchema(e,t){return C({kind:"TableNode",table:po.createWithSchema(e,t)})}});function Rr(e){return sn(e)&&fr(e.toOperationNode)}function Le(e){return sn(e)&&"expressionType"in e&&Rr(e)}function Ct(e){return sn(e)&&"expression"in e&&dr(e.alias)&&Rr(e)}var I=C({is(e){return e.kind==="SelectModifierNode"},create(e,t){return C({kind:"SelectModifierNode",modifier:e,of:t})},createWithExpression(e){return C({kind:"SelectModifierNode",rawModifier:e})}});var v=C({is(e){return e.kind==="AndNode"},create(e,t){return C({kind:"AndNode",left:e,right:t})}});var T=C({is(e){return e.kind==="OrNode"},create(e,t){return C({kind:"OrNode",left:e,right:t})}});var De=C({is(e){return e.kind==="OnNode"},create(e){return C({kind:"OnNode",on:e})},cloneWithOperation(e,t,r){return C({...e,on:t==="And"?v.create(e.on,r):T.create(e.on,r)})}});var L=C({is(e){return e.kind==="JoinNode"},create(e,t){return C({kind:"JoinNode",joinType:e,table:t,on:void 0})},createWithOn(e,t,r){return C({kind:"JoinNode",joinType:e,table:t,on:De.create(r)})},cloneWithOn(e,t){return C({...e,on:e.on?De.cloneWithOperation(e.on,"And",t):De.create(t)})}});var X=C({is(e){return e.kind==="BinaryOperationNode"},create(e,t,r){return C({kind:"BinaryOperationNode",leftOperand:e,operator:t,rightOperand:r})}});var Lr=["=","==","!=","<>",">",">=","<","<=","in","not in","is","is not","like","not like","match","ilike","not ilike","@>","<@","^@","&&","?","?&","?|","!<","!>","<=>","!~","~","~*","!~*","@@","@@@","!!","<->","regexp","is distinct from","is not distinct from"],Dr=["+","-","*","/","%","^","&","|","#","<<",">>"],kt=["->","->>"],Br=[...Lr,...Dr,"&&","||"],qr=["exists","not exists"],Mr=["not","-",...qr],Et=[...Br,...kt,...Mr,"between","between symmetric"],S=C({is(e){return e.kind==="OperatorNode"},create(e){return C({kind:"OperatorNode",operator:e})}});function Ke(e){return dr(e)&&kt.includes(e)}var Wt=C({is(e){return e.kind==="ColumnNode"},create(e){return C({kind:"ColumnNode",column:st.create(e)})}});var dc=C({is(e){return e.kind==="SelectAllNode"},create(){return C({kind:"SelectAllNode"})}});var Za=C({is(e){return e.kind==="ReferenceNode"},create(e,t){return C({kind:"ReferenceNode",table:t,column:e})},createSelectAll(e){return C({kind:"ReferenceNode",table:e,column:dc.create()})}});class pm{#e;get dynamicReference(){return this.#e}get refType(){return}constructor(e){this.#e=e}toOperationNode(){return He(this.#e)}}function Be(e){return sn(e)&&Rr(e)&&dr(e.dynamicReference)}var D=C({is(e){return e.kind==="OrderByItemNode"},create(e,t){return C({kind:"OrderByItemNode",orderBy:e,direction:t})},cloneWith(e,t){return C({...e,...t})}});var tr=C({is(e){return e.kind==="RawNode"},create(e,t){return C({kind:"RawNode",sqlFragments:C(e),parameters:C(t)})},createWithSql(e){return tr.create([e],[])},createWithChild(e){return tr.create(["",""],[e])},createWithChildren(e){return tr.create(Array(e.length+1).fill(""),e)}});var At=C({is(e){return e.kind==="CollateNode"},create(e){return C({kind:"CollateNode",collation:st.create(e)})}});class Z{#e;constructor(e){this.#e=C(e)}desc(){return new Z({node:D.cloneWith(this.#e.node,{direction:tr.createWithSql("desc")})})}asc(){return new Z({node:D.cloneWith(this.#e.node,{direction:tr.createWithSql("asc")})})}nullsLast(){return new Z({node:D.cloneWith(this.#e.node,{nulls:"last"})})}nullsFirst(){return new Z({node:D.cloneWith(this.#e.node,{nulls:"first"})})}collate(e){return new Z({node:D.cloneWith(this.#e.node,{collation:At.create(e)})})}toOperationNode(){return this.#e.node}}var Rt=new Set;function hi(e){if(Rt.has(e))return;Rt.add(e),console.log(e)}function Xe(e){return e==="asc"||e==="desc"}function k(e){if(e.length===2)return[Ye(e[0],e[1])];if(e.length===1){let[t]=e;if(Array.isArray(t))return hi("orderBy(array) is deprecated, use multiple orderBy calls instead."),t.map((r)=>Ye(r));return[Ye(t)]}throw Error(`Invalid number of arguments at order by! expected 1-2, received ${e.length}`)}function Ye(e,t){let r=Pr(e);if(D.is(r)){if(t)throw Error("Cannot specify direction twice!");return r}return Tt(r,t)}function Pr(e){if(J(e))return Ho(e);if(Be(e))return e.toOperationNode();let[t,r]=e.split(" ");if(r)return hi("`orderBy('column asc')` is deprecated. Use `orderBy('column', 'asc')` instead."),Tt(is(t),r);return is(e)}function Tt(e,t){if(typeof t==="string"){if(!Xe(t))throw Error(`Invalid order by direction: ${t}`);return D.create(e,tr.createWithSql(t))}if(Le(t))return hi("`orderBy(..., expr)` is deprecated. Use `orderBy(..., 'asc')` or `orderBy(..., (ob) => ...)` instead."),D.create(e,t.toOperationNode());let r=D.create(e);if(!t)return r;return t(new Z({node:r})).toOperationNode()}var pe=C({is(e){return e.kind==="JSONReferenceNode"},create(e,t){return C({kind:"JSONReferenceNode",reference:e,traversal:t})},cloneWithTraversal(e,t){return C({...e,traversal:t})}});var qe=C({is(e){return e.kind==="JSONOperatorChainNode"},create(e){return C({kind:"JSONOperatorChainNode",operator:e,values:C([])})},cloneWithValue(e,t){return C({...e,values:C([...e.values,t])})}});var ee=C({is(e){return e.kind==="JSONPathNode"},create(e){return C({kind:"JSONPathNode",inOperator:e,pathLegs:C([])})},cloneWithLeg(e,t){return C({...e,pathLegs:C([...e.pathLegs,t])})}});function He(e){if(dr(e))return is(e);return e.toOperationNode()}function Q(e){if(x(e))return e.map((t)=>w(t));else return[w(e)]}function w(e){if(J(e))return Ho(e);return He(e)}function Lt(e,t){let r=is(e);if(Ke(t))return pe.create(r,qe.create(S.create(t)));let i=t.slice(0,-1);if(Ke(i))return pe.create(r,ee.create(S.create(i)));throw Error(`Invalid JSON operator: ${t}`)}function is(e){if(!e.includes("."))return Za.create(Wt.create(e));let r=e.split(".").map(Ze);if(r.length===3)return Ir(r);if(r.length===2)return Fr(r);throw Error(`invalid column reference ${e}`)}function Dt(e){if(e.includes(" as ")){let[r,i]=e.split(" as ").map(Ze);return l.create(is(r),st.create(i))}else return is(e)}function mm(e){return Wt.create(e)}function fc(e){if(e.includes(" ")){let[r,i]=e.split(" ").map(Ze);if(!Xe(i))throw Error(`invalid order direction "${i}" next to "${r}"`);return k([r,i])[0]}else return mm(e)}function Ir(e){let[t,r,i]=e;return Za.create(Wt.create(i),mo.createWithSchema(t,r))}function Fr(e){let[t,r]=e;return Za.create(Wt.create(r),mo.create(t))}function Ze(e){return e.trim()}var Me=C({is(e){return e.kind==="PrimitiveValueListNode"},create(e){return C({kind:"PrimitiveValueListNode",values:C([...e])})}});var Ba=C({is(e){return e.kind==="ValueListNode"},create(e){return C({kind:"ValueListNode",values:C(e)})}});var _n=C({is(e){return e.kind==="ValueNode"},create(e){return C({kind:"ValueNode",value:e})},createImmediate(e){return C({kind:"ValueNode",value:e,immediate:!0})}});function Bt(e){if(x(e))return Vr(e);return d(e)}function d(e){if(J(e))return Ho(e);return _n.create(e)}function Pe(e){return zs(e)||Vi(e)||Fa(e)}function ge(e){if(!Pe(e))throw Error(`unsafe immediate value ${JSON.stringify(e)}`);return _n.createImmediate(e)}function Vr(e){if(e.some(J))return Ba.create(e.map((t)=>d(t)));return Me.create(e)}var E=C({is(e){return e.kind==="ParensNode"},create(e){return C({kind:"ParensNode",node:e})}});function yr(e){if(e.length===3)return Ie(e[0],e[1],e[2]);else if(e.length===1)return d(e[0]);throw Error(`invalid arguments: ${JSON.stringify(e)}`)}function Ie(e,t,r){if(Ur(t)&&Mt(r))return X.create(w(e),et(t),_n.createImmediate(r));return X.create(w(e),et(t),Bt(r))}function N(e,t,r){return X.create(w(e),et(t),w(r))}function tt(e,t){return de(Object.entries(e).filter(([,r])=>!So(r)).map(([r,i])=>Ie(r,Mt(i)?"is":"=",i)),t)}function de(e,t,r=!0){let i=t==="and"?v.create:T.create;if(e.length===0)return X.create(_n.createImmediate(1),S.create("="),_n.createImmediate(t==="and"?1:0));let n=qt(e[0]);for(let a=1;a<e.length;++a)n=i(n,qt(e[a]));if(e.length>1&&r)return E.create(n);return n}function Ur(e){return e==="is"||e==="is not"}function Mt(e){return Fa(e)||Vi(e)}function et(e){if(dr(e)&&Et.includes(e))return S.create(e);if(Rr(e))return e.toOperationNode();throw Error(`invalid operator ${JSON.stringify(e)}`)}function qt(e){return Rr(e)?e.toOperationNode():e}var _=C({is(e){return e.kind==="OrderByNode"},create(e){return C({kind:"OrderByNode",items:C([...e])})},cloneWithItems(e,t){return C({...e,items:C([...e.items,...t])})}});var rt=C({is(e){return e.kind==="PartitionByNode"},create(e){return C({kind:"PartitionByNode",items:C(e)})},cloneWithItems(e,t){return C({...e,items:C([...e.items,...t])})}});var ve=C({is(e){return e.kind==="OverNode"},create(){return C({kind:"OverNode"})},cloneWithOrderByItems(e,t){return C({...e,orderBy:e.orderBy?_.cloneWithItems(e.orderBy,t):_.create(t)})},cloneWithPartitionByItems(e,t){return C({...e,partitionBy:e.partitionBy?rt.cloneWithItems(e.partitionBy,t):rt.create(t)})}});var oe=C({is(e){return e.kind==="FromNode"},create(e){return C({kind:"FromNode",froms:C(e)})},cloneWithFroms(e,t){return C({...e,froms:C([...e.froms,...t])})}});var it=C({is(e){return e.kind==="GroupByNode"},create(e){return C({kind:"GroupByNode",items:C(e)})},cloneWithItems(e,t){return C({...e,items:C([...e.items,...t])})}});var ot=C({is(e){return e.kind==="HavingNode"},create(e){return C({kind:"HavingNode",having:e})},cloneWithOperation(e,t,r){return C({...e,having:t==="And"?v.create(e.having,r):T.create(e.having,r)})}});var u=C({is(e){return e.kind==="InsertQueryNode"},create(e,t,r){return C({kind:"InsertQueryNode",into:e,...t&&{with:t},replace:r})},createWithoutInto(){return C({kind:"InsertQueryNode"})},cloneWith(e,t){return C({...e,...t})}});var Fe=C({is(e){return e.kind==="ListNode"},create(e){return C({kind:"ListNode",items:C(e)})}});var F=C({is(e){return e.kind==="UpdateQueryNode"},create(e,t){return C({kind:"UpdateQueryNode",table:e.length===1?e[0]:Fe.create(e),...t&&{with:t}})},createWithoutTable(){return C({kind:"UpdateQueryNode"})},cloneWithFromItems(e,t){return C({...e,from:e.from?oe.cloneWithFroms(e.from,t):oe.create(t)})},cloneWithUpdates(e,t){return C({...e,updates:e.updates?C([...e.updates,...t]):t})},cloneWithLimit(e,t){return C({...e,limit:t})}});var be=C({is(e){return e.kind==="UsingNode"},create(e){return C({kind:"UsingNode",tables:C(e)})},cloneWithTables(e,t){return C({...e,tables:C([...e.tables,...t])})}});var te=C({is(e){return e.kind==="DeleteQueryNode"},create(e,t){return C({kind:"DeleteQueryNode",from:oe.create(e),...t&&{with:t}})},cloneWithOrderByItems:(e,t)=>Oe.cloneWithOrderByItems(e,t),cloneWithoutOrderBy:(e)=>Oe.cloneWithoutOrderBy(e),cloneWithLimit(e,t){return C({...e,limit:t})},cloneWithoutLimit(e){return C({...e,limit:void 0})},cloneWithUsing(e,t){return C({...e,using:e.using!==void 0?be.cloneWithTables(e.using,t):be.create(t)})}});var O=C({is(e){return e.kind==="WhereNode"},create(e){return C({kind:"WhereNode",where:e})},cloneWithOperation(e,t,r){return C({...e,where:t==="And"?v.create(e.where,r):T.create(e.where,r)})}});var nt=C({is(e){return e.kind==="ReturningNode"},create(e){return C({kind:"ReturningNode",selections:C(e)})},cloneWithSelections(e,t){return C({...e,selections:e.selections?C([...e.selections,...t]):C(t)})}});var Pt=C({is(e){return e.kind==="ExplainNode"},create(e,t){return C({kind:"ExplainNode",format:e,options:t})}});var R=C({is(e){return e.kind==="WhenNode"},create(e){return C({kind:"WhenNode",condition:e})},cloneWithResult(e,t){return C({...e,result:t})}});var A=C({is(e){return e.kind==="MergeQueryNode"},create(e,t){return C({kind:"MergeQueryNode",into:e,...t&&{with:t}})},cloneWithUsing(e,t){return C({...e,using:t})},cloneWithWhen(e,t){return C({...e,whens:e.whens?C([...e.whens,t]):C([t])})},cloneWithThen(e,t){return C({...e,whens:e.whens?C([...e.whens.slice(0,-1),R.cloneWithResult(e.whens[e.whens.length-1],t)]):void 0})}});var at=C({is(e){return e.kind==="OutputNode"},create(e){return C({kind:"OutputNode",selections:C(e)})},cloneWithSelections(e,t){return C({...e,selections:e.selections?C([...e.selections,...t]):C(t)})}});var Oe=C({is(e){return nr.is(e)||u.is(e)||F.is(e)||te.is(e)||A.is(e)},cloneWithEndModifier(e,t){return C({...e,endModifiers:e.endModifiers?C([...e.endModifiers,t]):C([t])})},cloneWithWhere(e,t){return C({...e,where:e.where?O.cloneWithOperation(e.where,"And",t):O.create(t)})},cloneWithJoin(e,t){return C({...e,joins:e.joins?C([...e.joins,t]):C([t])})},cloneWithReturning(e,t){return C({...e,returning:e.returning?nt.cloneWithSelections(e.returning,t):nt.create(t)})},cloneWithoutReturning(e){return C({...e,returning:void 0})},cloneWithoutWhere(e){return C({...e,where:void 0})},cloneWithExplain(e,t,r){return C({...e,explain:Pt.create(t,r?.toOperationNode())})},cloneWithTop(e,t){return C({...e,top:t})},cloneWithOutput(e,t){return C({...e,output:e.output?at.cloneWithSelections(e.output,t):at.create(t)})},cloneWithOrderByItems(e,t){return C({...e,orderBy:e.orderBy?_.cloneWithItems(e.orderBy,t):_.create(t)})},cloneWithoutOrderBy(e){return C({...e,orderBy:void 0})}});var nr=C({is(e){return e.kind==="SelectQueryNode"},create(e){return C({kind:"SelectQueryNode",...e&&{with:e}})},createFrom(e,t){return C({kind:"SelectQueryNode",from:oe.create(e),...t&&{with:t}})},cloneWithSelections(e,t){return C({...e,selections:e.selections?C([...e.selections,...t]):C(t)})},cloneWithDistinctOn(e,t){return C({...e,distinctOn:e.distinctOn?C([...e.distinctOn,...t]):C(t)})},cloneWithFrontModifier(e,t){return C({...e,frontModifiers:e.frontModifiers?C([...e.frontModifiers,t]):C([t])})},cloneWithOrderByItems:(e,t)=>Oe.cloneWithOrderByItems(e,t),cloneWithGroupByItems(e,t){return C({...e,groupBy:e.groupBy?it.cloneWithItems(e.groupBy,t):it.create(t)})},cloneWithLimit(e,t){return C({...e,limit:t})},cloneWithOffset(e,t){return C({...e,offset:t})},cloneWithFetch(e,t){return C({...e,fetch:t})},cloneWithHaving(e,t){return C({...e,having:e.having?ot.cloneWithOperation(e.having,"And",t):ot.create(t)})},cloneWithSetOperations(e,t){return C({...e,setOperations:e.setOperations?C([...e.setOperations,...t]):C([...t])})},cloneWithoutSelections(e){return C({...e,selections:[]})},cloneWithoutLimit(e){return C({...e,limit:void 0})},cloneWithoutOffset(e){return C({...e,offset:void 0})},cloneWithoutOrderBy:(e)=>Oe.cloneWithoutOrderBy(e),cloneWithoutGroupBy(e){return C({...e,groupBy:void 0})}});class he{#e;constructor(e){this.#e=C(e)}on(...e){return new he({...this.#e,joinNode:L.cloneWithOn(this.#e.joinNode,yr(e))})}onRef(e,t,r){return new he({...this.#e,joinNode:L.cloneWithOn(this.#e.joinNode,N(e,t,r))})}onTrue(){return new he({...this.#e,joinNode:L.cloneWithOn(this.#e.joinNode,tr.createWithSql("true"))})}$call(e){return e(this)}toOperationNode(){return this.#e.joinNode}}var Ft=C({is(e){return e.kind==="PartitionByItemNode"},create(e){return C({kind:"PartitionByItemNode",partitionBy:e})}});function Vt(e){return Q(e).map(Ft.create)}class ue{#e;constructor(e){this.#e=C(e)}orderBy(...e){return new ue({overNode:ve.cloneWithOrderByItems(this.#e.overNode,k(e))})}clearOrderBy(){return new ue({overNode:Oe.cloneWithoutOrderBy(this.#e.overNode)})}partitionBy(e){return new ue({overNode:ve.cloneWithPartitionByItems(this.#e.overNode,Vt(e))})}$call(e){return e(this)}toOperationNode(){return this.#e.overNode}}var me=C({is(e){return e.kind==="SelectionNode"},create(e){return C({kind:"SelectionNode",selection:e})},createSelectAll(){return C({kind:"SelectionNode",selection:dc.create()})},createSelectAllFromTable(e){return C({kind:"SelectionNode",selection:Za.createSelectAll(e)})}});function c(e){if(fr(e))return c(e(B()));else if(x(e))return e.map((t)=>Ut(t));else return[Ut(e)]}function Ut(e){if(dr(e))return me.create(Dt(e));else if(Be(e))return me.create(e.toOperationNode());else return me.create(Ve(e))}function y(e){if(!e)return[me.createSelectAll()];else if(Array.isArray(e))return e.map(zt);else return[zt(e)]}function zt(e){if(dr(e))return me.createSelectAllFromTable(or(e));throw Error(`invalid value selectAll expression: ${JSON.stringify(e)}`)}var Jt=C({is(e){return e.kind==="ValuesNode"},create(e){return C({kind:"ValuesNode",values:C(e)})}});var Qt=C({is(e){return e.kind==="DefaultInsertValueNode"},create(){return C({kind:"DefaultInsertValueNode"})}});function Ue(e){let t=fr(e)?e(B()):e,r=x(t)?t:C([t]);return zr(r)}function zr(e){let t=Jr(e);return[C([...t.keys()].map(Wt.create)),Jt.create(e.map((r)=>Qr(r,t)))]}function Jr(e){let t=new Map;for(let r of e){let i=Object.keys(r);for(let n of i)if(!t.has(n)&&r[n]!==void 0)t.set(n,t.size)}return t}function Qr(e,t){let r=Object.keys(e),i=Array.from({length:t.size}),n=!1,a=r.length;for(let H of r){let Y=t.get(H);if(So(Y)){a--;continue}let we=e[H];if(So(we)||J(we))n=!0;i[Y]=we}if(a<t.size||n){let H=Qt.create();return Ba.create(i.map((Y)=>So(Y)?H:d(Y)))}return Me.create(i)}var pt=C({is(e){return e.kind==="ColumnUpdateNode"},create(e,t){return C({kind:"ColumnUpdateNode",column:e,value:t})}});function _t(...e){if(e.length===2)return[pt.create(w(e[0]),d(e[1]))];return We(e[0])}function We(e){let t=fr(e)?e(B()):e;return Object.entries(t).filter(([r,i])=>i!==void 0).map(([r,i])=>pt.create(Wt.create(r),d(i)))}var $t=C({is(e){return e.kind==="OnDuplicateKeyNode"},create(e){return C({kind:"OnDuplicateKeyNode",updates:e})}});class dt{insertId;numInsertedOrUpdatedRows;constructor(e,t){this.insertId=e,this.numInsertedOrUpdatedRows=t}}class q extends Error{node;constructor(e){super("no result");this.node=e}}function V(e){return Object.prototype.hasOwnProperty.call(e,"prototype")}var g=C({is(e){return e.kind==="OnConflictNode"},create(){return C({kind:"OnConflictNode"})},cloneWith(e,t){return C({...e,...t})},cloneWithIndexWhere(e,t){return C({...e,indexWhere:e.indexWhere?O.cloneWithOperation(e.indexWhere,"And",t):O.create(t)})},cloneWithIndexOrWhere(e,t){return C({...e,indexWhere:e.indexWhere?O.cloneWithOperation(e.indexWhere,"Or",t):O.create(t)})},cloneWithUpdateWhere(e,t){return C({...e,updateWhere:e.updateWhere?O.cloneWithOperation(e.updateWhere,"And",t):O.create(t)})},cloneWithUpdateOrWhere(e,t){return C({...e,updateWhere:e.updateWhere?O.cloneWithOperation(e.updateWhere,"Or",t):O.create(t)})},cloneWithoutIndexWhere(e){return C({...e,indexWhere:void 0})},cloneWithoutUpdateWhere(e){return C({...e,updateWhere:void 0})}});class U{#e;constructor(e){this.#e=C(e)}column(e){let t=Wt.create(e);return new U({...this.#e,onConflictNode:g.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?C([...this.#e.onConflictNode.columns,t]):C([t])})})}columns(e){let t=e.map(Wt.create);return new U({...this.#e,onConflictNode:g.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?C([...this.#e.onConflictNode.columns,...t]):C(t)})})}constraint(e){return new U({...this.#e,onConflictNode:g.cloneWith(this.#e.onConflictNode,{constraint:st.create(e)})})}expression(e){return new U({...this.#e,onConflictNode:g.cloneWith(this.#e.onConflictNode,{indexExpression:e.toOperationNode()})})}where(...e){return new U({...this.#e,onConflictNode:g.cloneWithIndexWhere(this.#e.onConflictNode,yr(e))})}whereRef(e,t,r){return new U({...this.#e,onConflictNode:g.cloneWithIndexWhere(this.#e.onConflictNode,N(e,t,r))})}clearWhere(){return new U({...this.#e,onConflictNode:g.cloneWithoutIndexWhere(this.#e.onConflictNode)})}doNothing(){return new Gt({...this.#e,onConflictNode:g.cloneWith(this.#e.onConflictNode,{doNothing:!0})})}doUpdateSet(e){return new Se({...this.#e,onConflictNode:g.cloneWith(this.#e.onConflictNode,{updates:We(e)})})}$call(e){return e(this)}}class Gt{#e;constructor(e){this.#e=C(e)}toOperationNode(){return this.#e.onConflictNode}}class Se{#e;constructor(e){this.#e=C(e)}where(...e){return new Se({...this.#e,onConflictNode:g.cloneWithUpdateWhere(this.#e.onConflictNode,yr(e))})}whereRef(e,t,r){return new Se({...this.#e,onConflictNode:g.cloneWithUpdateWhere(this.#e.onConflictNode,N(e,t,r))})}clearWhere(){return new Se({...this.#e,onConflictNode:g.cloneWithoutUpdateWhere(this.#e.onConflictNode)})}$call(e){return e(this)}toOperationNode(){return this.#e.onConflictNode}}var Kt=C({is(e){return e.kind==="TopNode"},create(e,t){return C({kind:"TopNode",expression:e,modifiers:t})}});function M(e,t){if(!zs(e)&&!La(e))throw Error(`Invalid top expression: ${e}`);if(!So(t)&&!_r(t))throw Error(`Invalid top modifiers: ${t}`);return Kt.create(e,t)}function _r(e){return e==="percent"||e==="with ties"||e==="percent with ties"}var ne=C({is(e){return e.kind==="OrActionNode"},create(e){return C({kind:"OrActionNode",action:e})}});class h{#e;constructor(e){this.#e=C(e)}values(e){let[t,r]=Ue(e);return new h({...this.#e,queryNode:u.cloneWith(this.#e.queryNode,{columns:t,values:r})})}columns(e){return new h({...this.#e,queryNode:u.cloneWith(this.#e.queryNode,{columns:C(e.map(Wt.create))})})}expression(e){return new h({...this.#e,queryNode:u.cloneWith(this.#e.queryNode,{values:Ho(e)})})}defaultValues(){return new h({...this.#e,queryNode:u.cloneWith(this.#e.queryNode,{defaultValues:!0})})}modifyEnd(e){return new h({...this.#e,queryNode:Oe.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}ignore(){return new h({...this.#e,queryNode:u.cloneWith(this.#e.queryNode,{orAction:ne.create("ignore")})})}orIgnore(){return new h({...this.#e,queryNode:u.cloneWith(this.#e.queryNode,{orAction:ne.create("ignore")})})}orAbort(){return new h({...this.#e,queryNode:u.cloneWith(this.#e.queryNode,{orAction:ne.create("abort")})})}orFail(){return new h({...this.#e,queryNode:u.cloneWith(this.#e.queryNode,{orAction:ne.create("fail")})})}orReplace(){return new h({...this.#e,queryNode:u.cloneWith(this.#e.queryNode,{orAction:ne.create("replace")})})}orRollback(){return new h({...this.#e,queryNode:u.cloneWith(this.#e.queryNode,{orAction:ne.create("rollback")})})}top(e,t){return new h({...this.#e,queryNode:Oe.cloneWithTop(this.#e.queryNode,M(e,t))})}onConflict(e){return new h({...this.#e,queryNode:u.cloneWith(this.#e.queryNode,{onConflict:e(new U({onConflictNode:g.create()})).toOperationNode()})})}onDuplicateKeyUpdate(e){return new h({...this.#e,queryNode:u.cloneWith(this.#e.queryNode,{onDuplicateKey:$t.create(We(e))})})}returning(e){return new h({...this.#e,queryNode:Oe.cloneWithReturning(this.#e.queryNode,c(e))})}returningAll(){return new h({...this.#e,queryNode:Oe.cloneWithReturning(this.#e.queryNode,y())})}output(e){return new h({...this.#e,queryNode:Oe.cloneWithOutput(this.#e.queryNode,c(e))})}outputAll(e){return new h({...this.#e,queryNode:Oe.cloneWithOutput(this.#e.queryNode,y(e))})}clearReturning(){return new h({...this.#e,queryNode:Oe.cloneWithoutReturning(this.#e.queryNode)})}$call(e){return e(this)}$if(e,t){if(e)return t(this);return new h({...this.#e})}$castTo(){return new h(this.#e)}$narrowType(){return new h(this.#e)}$assertType(){return new h(this.#e)}withPlugin(e){return new h({...this.#e,executor:this.#e.executor.withPlugin(e)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile(),t=await this.#e.executor.executeQuery(e),{adapter:r}=this.#e.executor,i=e.query;if(i.returning&&r.supportsReturning||i.output&&r.supportsOutput)return t.rows;return[new dt(t.insertId,t.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=q){let t=await this.executeTakeFirst();if(t===void 0)throw V(e)?new e(this.toOperationNode()):e(this.toOperationNode());return t}async*stream(e=100){let t=this.compile(),r=this.#e.executor.stream(t,e);for await(let i of r)yield*i.rows}async explain(e,t){return await new h({...this.#e,queryNode:Oe.cloneWithExplain(this.#e.queryNode,e,t)}).execute()}}class ht{numDeletedRows;constructor(e){this.numDeletedRows=e}}var fe=C({is(e){return e.kind==="LimitNode"},create(e){return C({kind:"LimitNode",limit:e})}});var m;class ze{#e;constructor(e){this.#e=C(e)}where(...e){return new m({...this.#e,queryNode:Oe.cloneWithWhere(this.#e.queryNode,yr(e))})}whereRef(e,t,r){return new m({...this.#e,queryNode:Oe.cloneWithWhere(this.#e.queryNode,N(e,t,r))})}clearWhere(){return new m({...this.#e,queryNode:Oe.cloneWithoutWhere(this.#e.queryNode)})}top(e,t){return new m({...this.#e,queryNode:Oe.cloneWithTop(this.#e.queryNode,M(e,t))})}using(e){return new m({...this.#e,queryNode:te.cloneWithUsing(this.#e.queryNode,P(e))})}innerJoin(...e){return this.#t("InnerJoin",e)}leftJoin(...e){return this.#t("LeftJoin",e)}rightJoin(...e){return this.#t("RightJoin",e)}fullJoin(...e){return this.#t("FullJoin",e)}#t(e,t){return new m({...this.#e,queryNode:Oe.cloneWithJoin(this.#e.queryNode,re(e,t))})}returning(e){return new m({...this.#e,queryNode:Oe.cloneWithReturning(this.#e.queryNode,c(e))})}returningAll(e){return new m({...this.#e,queryNode:Oe.cloneWithReturning(this.#e.queryNode,y(e))})}output(e){return new m({...this.#e,queryNode:Oe.cloneWithOutput(this.#e.queryNode,c(e))})}outputAll(e){return new m({...this.#e,queryNode:Oe.cloneWithOutput(this.#e.queryNode,y(e))})}clearReturning(){return new m({...this.#e,queryNode:Oe.cloneWithoutReturning(this.#e.queryNode)})}clearLimit(){return new m({...this.#e,queryNode:te.cloneWithoutLimit(this.#e.queryNode)})}orderBy(...e){return new m({...this.#e,queryNode:Oe.cloneWithOrderByItems(this.#e.queryNode,k(e))})}clearOrderBy(){return new m({...this.#e,queryNode:Oe.cloneWithoutOrderBy(this.#e.queryNode)})}limit(e){return new m({...this.#e,queryNode:te.cloneWithLimit(this.#e.queryNode,fe.create(d(e)))})}modifyEnd(e){return new m({...this.#e,queryNode:Oe.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}$call(e){return e(this)}$if(e,t){if(e)return t(this);return new m({...this.#e})}$castTo(){return new m(this.#e)}$narrowType(){return new m(this.#e)}$assertType(){return new m(this.#e)}withPlugin(e){return new m({...this.#e,executor:this.#e.executor.withPlugin(e)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile(),t=await this.#e.executor.executeQuery(e),{adapter:r}=this.#e.executor,i=e.query;if(i.returning&&r.supportsReturning||i.output&&r.supportsOutput)return t.rows;return[new ht(t.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=q){let t=await this.executeTakeFirst();if(t===void 0)throw V(e)?new e(this.toOperationNode()):e(this.toOperationNode());return t}async*stream(e=100){let t=this.compile(),r=this.#e.executor.stream(t,e);for await(let i of r)yield*i.rows}async explain(e,t){return await new m({...this.#e,queryNode:Oe.cloneWithExplain(this.#e.queryNode,e,t)}).execute()}}m=ze;class ut{numUpdatedRows;numChangedRows;constructor(e,t){this.numUpdatedRows=e,this.numChangedRows=t}}var f;class ce{#e;constructor(e){this.#e=C(e)}where(...e){return new f({...this.#e,queryNode:Oe.cloneWithWhere(this.#e.queryNode,yr(e))})}whereRef(e,t,r){return new f({...this.#e,queryNode:Oe.cloneWithWhere(this.#e.queryNode,N(e,t,r))})}clearWhere(){return new f({...this.#e,queryNode:Oe.cloneWithoutWhere(this.#e.queryNode)})}top(e,t){return new f({...this.#e,queryNode:Oe.cloneWithTop(this.#e.queryNode,M(e,t))})}from(e){return new f({...this.#e,queryNode:F.cloneWithFromItems(this.#e.queryNode,P(e))})}innerJoin(...e){return this.#t("InnerJoin",e)}leftJoin(...e){return this.#t("LeftJoin",e)}rightJoin(...e){return this.#t("RightJoin",e)}fullJoin(...e){return this.#t("FullJoin",e)}#t(e,t){return new f({...this.#e,queryNode:Oe.cloneWithJoin(this.#e.queryNode,re(e,t))})}orderBy(...e){return new f({...this.#e,queryNode:Oe.cloneWithOrderByItems(this.#e.queryNode,k(e))})}clearOrderBy(){return new f({...this.#e,queryNode:Oe.cloneWithoutOrderBy(this.#e.queryNode)})}limit(e){return new f({...this.#e,queryNode:F.cloneWithLimit(this.#e.queryNode,fe.create(d(e)))})}set(...e){return new f({...this.#e,queryNode:F.cloneWithUpdates(this.#e.queryNode,_t(...e))})}returning(e){return new f({...this.#e,queryNode:Oe.cloneWithReturning(this.#e.queryNode,c(e))})}returningAll(e){return new f({...this.#e,queryNode:Oe.cloneWithReturning(this.#e.queryNode,y(e))})}output(e){return new f({...this.#e,queryNode:Oe.cloneWithOutput(this.#e.queryNode,c(e))})}outputAll(e){return new f({...this.#e,queryNode:Oe.cloneWithOutput(this.#e.queryNode,y(e))})}modifyEnd(e){return new f({...this.#e,queryNode:Oe.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}clearReturning(){return new f({...this.#e,queryNode:Oe.cloneWithoutReturning(this.#e.queryNode)})}$call(e){return e(this)}$if(e,t){if(e)return t(this);return new f({...this.#e})}$castTo(){return new f(this.#e)}$narrowType(){return new f(this.#e)}$assertType(){return new f(this.#e)}withPlugin(e){return new f({...this.#e,executor:this.#e.executor.withPlugin(e)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile(),t=await this.#e.executor.executeQuery(e),{adapter:r}=this.#e.executor,i=e.query;if(i.returning&&r.supportsReturning||i.output&&r.supportsOutput)return t.rows;return[new ut(t.numAffectedRows??BigInt(0),t.numChangedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=q){let t=await this.executeTakeFirst();if(t===void 0)throw V(e)?new e(this.toOperationNode()):e(this.toOperationNode());return t}async*stream(e=100){let t=this.compile(),r=this.#e.executor.stream(t,e);for await(let i of r)yield*i.rows}async explain(e,t){return await new f({...this.#e,queryNode:Oe.cloneWithExplain(this.#e.queryNode,e,t)}).execute()}}f=ce;var mt=C({is(e){return e.kind==="CommonTableExpressionNameNode"},create(e,t){return C({kind:"CommonTableExpressionNameNode",table:mo.create(e),columns:t?C(t.map(Wt.create)):void 0})}});var le=C({is(e){return e.kind==="CommonTableExpressionNode"},create(e,t){return C({kind:"CommonTableExpressionNode",name:e,expression:t})},cloneWith(e,t){return C({...e,...t})}});class Ce{#e;constructor(e){this.#e=C(e)}materialized(){return new Ce({...this.#e,node:le.cloneWith(this.#e.node,{materialized:!0})})}notMaterialized(){return new Ce({...this.#e,node:le.cloneWith(this.#e.node,{materialized:!1})})}toOperationNode(){return this.#e.node}}function ft(e,t){let r=t(Ht()).toOperationNode();if(fr(e))return e($r(r)).toOperationNode();return le.create(jt(e),r)}function $r(e){return(t)=>new Ce({node:le.create(jt(t),e)})}function jt(e){if(e.includes("(")){let t=e.split(/[\(\)]/),r=t[0],i=t[1].split(",").map((n)=>n.trim());return mt.create(r,i)}else return mt.create(e)}var ke=C({is(e){return e.kind==="WithNode"},create(e,t){return C({kind:"WithNode",expressions:C([e]),...t})},cloneWithExpression(e,t){return C({...e,expressions:C([...e.expressions,t])})}});var Yt=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"];function nf(e){let t="";for(let r=0;r<e;++r)t+=Gr();return t}function Gr(){return Yt[~~(Math.random()*Yt.length)]}function It(){return new Xt}class Xt{#e;get queryId(){if(this.#e===void 0)this.#e=nf(8);return this.#e}}function o(e){return e}class Du{nodeStack=[];#e=C({AliasNode:this.transformAlias.bind(this),ColumnNode:this.transformColumn.bind(this),IdentifierNode:this.transformIdentifier.bind(this),SchemableIdentifierNode:this.transformSchemableIdentifier.bind(this),RawNode:this.transformRaw.bind(this),ReferenceNode:this.transformReference.bind(this),SelectQueryNode:this.transformSelectQuery.bind(this),SelectionNode:this.transformSelection.bind(this),TableNode:this.transformTable.bind(this),FromNode:this.transformFrom.bind(this),SelectAllNode:this.transformSelectAll.bind(this),AndNode:this.transformAnd.bind(this),OrNode:this.transformOr.bind(this),ValueNode:this.transformValue.bind(this),ValueListNode:this.transformValueList.bind(this),PrimitiveValueListNode:this.transformPrimitiveValueList.bind(this),ParensNode:this.transformParens.bind(this),JoinNode:this.transformJoin.bind(this),OperatorNode:this.transformOperator.bind(this),WhereNode:this.transformWhere.bind(this),InsertQueryNode:this.transformInsertQuery.bind(this),DeleteQueryNode:this.transformDeleteQuery.bind(this),ReturningNode:this.transformReturning.bind(this),CreateTableNode:this.transformCreateTable.bind(this),AddColumnNode:this.transformAddColumn.bind(this),ColumnDefinitionNode:this.transformColumnDefinition.bind(this),DropTableNode:this.transformDropTable.bind(this),DataTypeNode:this.transformDataType.bind(this),OrderByNode:this.transformOrderBy.bind(this),OrderByItemNode:this.transformOrderByItem.bind(this),GroupByNode:this.transformGroupBy.bind(this),GroupByItemNode:this.transformGroupByItem.bind(this),UpdateQueryNode:this.transformUpdateQuery.bind(this),ColumnUpdateNode:this.transformColumnUpdate.bind(this),LimitNode:this.transformLimit.bind(this),OffsetNode:this.transformOffset.bind(this),OnConflictNode:this.transformOnConflict.bind(this),OnDuplicateKeyNode:this.transformOnDuplicateKey.bind(this),CreateIndexNode:this.transformCreateIndex.bind(this),DropIndexNode:this.transformDropIndex.bind(this),ListNode:this.transformList.bind(this),PrimaryKeyConstraintNode:this.transformPrimaryKeyConstraint.bind(this),UniqueConstraintNode:this.transformUniqueConstraint.bind(this),ReferencesNode:this.transformReferences.bind(this),CheckConstraintNode:this.transformCheckConstraint.bind(this),WithNode:this.transformWith.bind(this),CommonTableExpressionNode:this.transformCommonTableExpression.bind(this),CommonTableExpressionNameNode:this.transformCommonTableExpressionName.bind(this),HavingNode:this.transformHaving.bind(this),CreateSchemaNode:this.transformCreateSchema.bind(this),DropSchemaNode:this.transformDropSchema.bind(this),AlterTableNode:this.transformAlterTable.bind(this),DropColumnNode:this.transformDropColumn.bind(this),RenameColumnNode:this.transformRenameColumn.bind(this),AlterColumnNode:this.transformAlterColumn.bind(this),ModifyColumnNode:this.transformModifyColumn.bind(this),AddConstraintNode:this.transformAddConstraint.bind(this),DropConstraintNode:this.transformDropConstraint.bind(this),RenameConstraintNode:this.transformRenameConstraint.bind(this),ForeignKeyConstraintNode:this.transformForeignKeyConstraint.bind(this),CreateViewNode:this.transformCreateView.bind(this),RefreshMaterializedViewNode:this.transformRefreshMaterializedView.bind(this),DropViewNode:this.transformDropView.bind(this),GeneratedNode:this.transformGenerated.bind(this),DefaultValueNode:this.transformDefaultValue.bind(this),OnNode:this.transformOn.bind(this),ValuesNode:this.transformValues.bind(this),SelectModifierNode:this.transformSelectModifier.bind(this),CreateTypeNode:this.transformCreateType.bind(this),DropTypeNode:this.transformDropType.bind(this),ExplainNode:this.transformExplain.bind(this),DefaultInsertValueNode:this.transformDefaultInsertValue.bind(this),AggregateFunctionNode:this.transformAggregateFunction.bind(this),OverNode:this.transformOver.bind(this),PartitionByNode:this.transformPartitionBy.bind(this),PartitionByItemNode:this.transformPartitionByItem.bind(this),SetOperationNode:this.transformSetOperation.bind(this),BinaryOperationNode:this.transformBinaryOperation.bind(this),UnaryOperationNode:this.transformUnaryOperation.bind(this),UsingNode:this.transformUsing.bind(this),FunctionNode:this.transformFunction.bind(this),CaseNode:this.transformCase.bind(this),WhenNode:this.transformWhen.bind(this),JSONReferenceNode:this.transformJSONReference.bind(this),JSONPathNode:this.transformJSONPath.bind(this),JSONPathLegNode:this.transformJSONPathLeg.bind(this),JSONOperatorChainNode:this.transformJSONOperatorChain.bind(this),TupleNode:this.transformTuple.bind(this),MergeQueryNode:this.transformMergeQuery.bind(this),MatchedNode:this.transformMatched.bind(this),AddIndexNode:this.transformAddIndex.bind(this),CastNode:this.transformCast.bind(this),FetchNode:this.transformFetch.bind(this),TopNode:this.transformTop.bind(this),OutputNode:this.transformOutput.bind(this),OrActionNode:this.transformOrAction.bind(this),CollateNode:this.transformCollate.bind(this)});transformNode(e,t){if(!e)return e;this.nodeStack.push(e);let r=this.transformNodeImpl(e,t);return this.nodeStack.pop(),C(r)}transformNodeImpl(e,t){return this.#e[e.kind](e,t)}transformNodeList(e,t){if(!e)return e;return C(e.map((r)=>this.transformNode(r,t)))}transformSelectQuery(e,t){return o({kind:"SelectQueryNode",from:this.transformNode(e.from,t),selections:this.transformNodeList(e.selections,t),distinctOn:this.transformNodeList(e.distinctOn,t),joins:this.transformNodeList(e.joins,t),groupBy:this.transformNode(e.groupBy,t),orderBy:this.transformNode(e.orderBy,t),where:this.transformNode(e.where,t),frontModifiers:this.transformNodeList(e.frontModifiers,t),endModifiers:this.transformNodeList(e.endModifiers,t),limit:this.transformNode(e.limit,t),offset:this.transformNode(e.offset,t),with:this.transformNode(e.with,t),having:this.transformNode(e.having,t),explain:this.transformNode(e.explain,t),setOperations:this.transformNodeList(e.setOperations,t),fetch:this.transformNode(e.fetch,t),top:this.transformNode(e.top,t)})}transformSelection(e,t){return o({kind:"SelectionNode",selection:this.transformNode(e.selection,t)})}transformColumn(e,t){return o({kind:"ColumnNode",column:this.transformNode(e.column,t)})}transformAlias(e,t){return o({kind:"AliasNode",node:this.transformNode(e.node,t),alias:this.transformNode(e.alias,t)})}transformTable(e,t){return o({kind:"TableNode",table:this.transformNode(e.table,t)})}transformFrom(e,t){return o({kind:"FromNode",froms:this.transformNodeList(e.froms,t)})}transformReference(e,t){return o({kind:"ReferenceNode",column:this.transformNode(e.column,t),table:this.transformNode(e.table,t)})}transformAnd(e,t){return o({kind:"AndNode",left:this.transformNode(e.left,t),right:this.transformNode(e.right,t)})}transformOr(e,t){return o({kind:"OrNode",left:this.transformNode(e.left,t),right:this.transformNode(e.right,t)})}transformValueList(e,t){return o({kind:"ValueListNode",values:this.transformNodeList(e.values,t)})}transformParens(e,t){return o({kind:"ParensNode",node:this.transformNode(e.node,t)})}transformJoin(e,t){return o({kind:"JoinNode",joinType:e.joinType,table:this.transformNode(e.table,t),on:this.transformNode(e.on,t)})}transformRaw(e,t){return o({kind:"RawNode",sqlFragments:C([...e.sqlFragments]),parameters:this.transformNodeList(e.parameters,t)})}transformWhere(e,t){return o({kind:"WhereNode",where:this.transformNode(e.where,t)})}transformInsertQuery(e,t){return o({kind:"InsertQueryNode",into:this.transformNode(e.into,t),columns:this.transformNodeList(e.columns,t),values:this.transformNode(e.values,t),returning:this.transformNode(e.returning,t),onConflict:this.transformNode(e.onConflict,t),onDuplicateKey:this.transformNode(e.onDuplicateKey,t),endModifiers:this.transformNodeList(e.endModifiers,t),with:this.transformNode(e.with,t),ignore:e.ignore,orAction:this.transformNode(e.orAction,t),replace:e.replace,explain:this.transformNode(e.explain,t),defaultValues:e.defaultValues,top:this.transformNode(e.top,t),output:this.transformNode(e.output,t)})}transformValues(e,t){return o({kind:"ValuesNode",values:this.transformNodeList(e.values,t)})}transformDeleteQuery(e,t){return o({kind:"DeleteQueryNode",from:this.transformNode(e.from,t),using:this.transformNode(e.using,t),joins:this.transformNodeList(e.joins,t),where:this.transformNode(e.where,t),returning:this.transformNode(e.returning,t),endModifiers:this.transformNodeList(e.endModifiers,t),with:this.transformNode(e.with,t),orderBy:this.transformNode(e.orderBy,t),limit:this.transformNode(e.limit,t),explain:this.transformNode(e.explain,t),top:this.transformNode(e.top,t),output:this.transformNode(e.output,t)})}transformReturning(e,t){return o({kind:"ReturningNode",selections:this.transformNodeList(e.selections,t)})}transformCreateTable(e,t){return o({kind:"CreateTableNode",table:this.transformNode(e.table,t),columns:this.transformNodeList(e.columns,t),constraints:this.transformNodeList(e.constraints,t),temporary:e.temporary,ifNotExists:e.ifNotExists,onCommit:e.onCommit,frontModifiers:this.transformNodeList(e.frontModifiers,t),endModifiers:this.transformNodeList(e.endModifiers,t),selectQuery:this.transformNode(e.selectQuery,t)})}transformColumnDefinition(e,t){return o({kind:"ColumnDefinitionNode",column:this.transformNode(e.column,t),dataType:this.transformNode(e.dataType,t),references:this.transformNode(e.references,t),primaryKey:e.primaryKey,autoIncrement:e.autoIncrement,unique:e.unique,notNull:e.notNull,unsigned:e.unsigned,defaultTo:this.transformNode(e.defaultTo,t),check:this.transformNode(e.check,t),generated:this.transformNode(e.generated,t),frontModifiers:this.transformNodeList(e.frontModifiers,t),endModifiers:this.transformNodeList(e.endModifiers,t),nullsNotDistinct:e.nullsNotDistinct,identity:e.identity,ifNotExists:e.ifNotExists})}transformAddColumn(e,t){return o({kind:"AddColumnNode",column:this.transformNode(e.column,t)})}transformDropTable(e,t){return o({kind:"DropTableNode",table:this.transformNode(e.table,t),ifExists:e.ifExists,cascade:e.cascade})}transformOrderBy(e,t){return o({kind:"OrderByNode",items:this.transformNodeList(e.items,t)})}transformOrderByItem(e,t){return o({kind:"OrderByItemNode",orderBy:this.transformNode(e.orderBy,t),direction:this.transformNode(e.direction,t),collation:this.transformNode(e.collation,t),nulls:e.nulls})}transformGroupBy(e,t){return o({kind:"GroupByNode",items:this.transformNodeList(e.items,t)})}transformGroupByItem(e,t){return o({kind:"GroupByItemNode",groupBy:this.transformNode(e.groupBy,t)})}transformUpdateQuery(e,t){return o({kind:"UpdateQueryNode",table:this.transformNode(e.table,t),from:this.transformNode(e.from,t),joins:this.transformNodeList(e.joins,t),where:this.transformNode(e.where,t),updates:this.transformNodeList(e.updates,t),returning:this.transformNode(e.returning,t),endModifiers:this.transformNodeList(e.endModifiers,t),with:this.transformNode(e.with,t),explain:this.transformNode(e.explain,t),limit:this.transformNode(e.limit,t),top:this.transformNode(e.top,t),output:this.transformNode(e.output,t),orderBy:this.transformNode(e.orderBy,t)})}transformColumnUpdate(e,t){return o({kind:"ColumnUpdateNode",column:this.transformNode(e.column,t),value:this.transformNode(e.value,t)})}transformLimit(e,t){return o({kind:"LimitNode",limit:this.transformNode(e.limit,t)})}transformOffset(e,t){return o({kind:"OffsetNode",offset:this.transformNode(e.offset,t)})}transformOnConflict(e,t){return o({kind:"OnConflictNode",columns:this.transformNodeList(e.columns,t),constraint:this.transformNode(e.constraint,t),indexExpression:this.transformNode(e.indexExpression,t),indexWhere:this.transformNode(e.indexWhere,t),updates:this.transformNodeList(e.updates,t),updateWhere:this.transformNode(e.updateWhere,t),doNothing:e.doNothing})}transformOnDuplicateKey(e,t){return o({kind:"OnDuplicateKeyNode",updates:this.transformNodeList(e.updates,t)})}transformCreateIndex(e,t){return o({kind:"CreateIndexNode",name:this.transformNode(e.name,t),table:this.transformNode(e.table,t),columns:this.transformNodeList(e.columns,t),unique:e.unique,using:this.transformNode(e.using,t),ifNotExists:e.ifNotExists,where:this.transformNode(e.where,t),nullsNotDistinct:e.nullsNotDistinct})}transformList(e,t){return o({kind:"ListNode",items:this.transformNodeList(e.items,t)})}transformDropIndex(e,t){return o({kind:"DropIndexNode",name:this.transformNode(e.name,t),table:this.transformNode(e.table,t),ifExists:e.ifExists,cascade:e.cascade})}transformPrimaryKeyConstraint(e,t){return o({kind:"PrimaryKeyConstraintNode",columns:this.transformNodeList(e.columns,t),name:this.transformNode(e.name,t),deferrable:e.deferrable,initiallyDeferred:e.initiallyDeferred})}transformUniqueConstraint(e,t){return o({kind:"UniqueConstraintNode",columns:this.transformNodeList(e.columns,t),name:this.transformNode(e.name,t),nullsNotDistinct:e.nullsNotDistinct,deferrable:e.deferrable,initiallyDeferred:e.initiallyDeferred})}transformForeignKeyConstraint(e,t){return o({kind:"ForeignKeyConstraintNode",columns:this.transformNodeList(e.columns,t),references:this.transformNode(e.references,t),name:this.transformNode(e.name,t),onDelete:e.onDelete,onUpdate:e.onUpdate,deferrable:e.deferrable,initiallyDeferred:e.initiallyDeferred})}transformSetOperation(e,t){return o({kind:"SetOperationNode",operator:e.operator,expression:this.transformNode(e.expression,t),all:e.all})}transformReferences(e,t){return o({kind:"ReferencesNode",table:this.transformNode(e.table,t),columns:this.transformNodeList(e.columns,t),onDelete:e.onDelete,onUpdate:e.onUpdate})}transformCheckConstraint(e,t){return o({kind:"CheckConstraintNode",expression:this.transformNode(e.expression,t),name:this.transformNode(e.name,t)})}transformWith(e,t){return o({kind:"WithNode",expressions:this.transformNodeList(e.expressions,t),recursive:e.recursive})}transformCommonTableExpression(e,t){return o({kind:"CommonTableExpressionNode",name:this.transformNode(e.name,t),materialized:e.materialized,expression:this.transformNode(e.expression,t)})}transformCommonTableExpressionName(e,t){return o({kind:"CommonTableExpressionNameNode",table:this.transformNode(e.table,t),columns:this.transformNodeList(e.columns,t)})}transformHaving(e,t){return o({kind:"HavingNode",having:this.transformNode(e.having,t)})}transformCreateSchema(e,t){return o({kind:"CreateSchemaNode",schema:this.transformNode(e.schema,t),ifNotExists:e.ifNotExists})}transformDropSchema(e,t){return o({kind:"DropSchemaNode",schema:this.transformNode(e.schema,t),ifExists:e.ifExists,cascade:e.cascade})}transformAlterTable(e,t){return o({kind:"AlterTableNode",table:this.transformNode(e.table,t),renameTo:this.transformNode(e.renameTo,t),setSchema:this.transformNode(e.setSchema,t),columnAlterations:this.transformNodeList(e.columnAlterations,t),addConstraint:this.transformNode(e.addConstraint,t),dropConstraint:this.transformNode(e.dropConstraint,t),renameConstraint:this.transformNode(e.renameConstraint,t),addIndex:this.transformNode(e.addIndex,t),dropIndex:this.transformNode(e.dropIndex,t)})}transformDropColumn(e,t){return o({kind:"DropColumnNode",column:this.transformNode(e.column,t)})}transformRenameColumn(e,t){return o({kind:"RenameColumnNode",column:this.transformNode(e.column,t),renameTo:this.transformNode(e.renameTo,t)})}transformAlterColumn(e,t){return o({kind:"AlterColumnNode",column:this.transformNode(e.column,t),dataType:this.transformNode(e.dataType,t),dataTypeExpression:this.transformNode(e.dataTypeExpression,t),setDefault:this.transformNode(e.setDefault,t),dropDefault:e.dropDefault,setNotNull:e.setNotNull,dropNotNull:e.dropNotNull})}transformModifyColumn(e,t){return o({kind:"ModifyColumnNode",column:this.transformNode(e.column,t)})}transformAddConstraint(e,t){return o({kind:"AddConstraintNode",constraint:this.transformNode(e.constraint,t)})}transformDropConstraint(e,t){return o({kind:"DropConstraintNode",constraintName:this.transformNode(e.constraintName,t),ifExists:e.ifExists,modifier:e.modifier})}transformRenameConstraint(e,t){return o({kind:"RenameConstraintNode",oldName:this.transformNode(e.oldName,t),newName:this.transformNode(e.newName,t)})}transformCreateView(e,t){return o({kind:"CreateViewNode",name:this.transformNode(e.name,t),temporary:e.temporary,orReplace:e.orReplace,ifNotExists:e.ifNotExists,materialized:e.materialized,columns:this.transformNodeList(e.columns,t),as:this.transformNode(e.as,t)})}transformRefreshMaterializedView(e,t){return o({kind:"RefreshMaterializedViewNode",name:this.transformNode(e.name,t),concurrently:e.concurrently,withNoData:e.withNoData})}transformDropView(e,t){return o({kind:"DropViewNode",name:this.transformNode(e.name,t),ifExists:e.ifExists,materialized:e.materialized,cascade:e.cascade})}transformGenerated(e,t){return o({kind:"GeneratedNode",byDefault:e.byDefault,always:e.always,identity:e.identity,stored:e.stored,expression:this.transformNode(e.expression,t)})}transformDefaultValue(e,t){return o({kind:"DefaultValueNode",defaultValue:this.transformNode(e.defaultValue,t)})}transformOn(e,t){return o({kind:"OnNode",on:this.transformNode(e.on,t)})}transformSelectModifier(e,t){return o({kind:"SelectModifierNode",modifier:e.modifier,rawModifier:this.transformNode(e.rawModifier,t),of:this.transformNodeList(e.of,t)})}transformCreateType(e,t){return o({kind:"CreateTypeNode",name:this.transformNode(e.name,t),enum:this.transformNode(e.enum,t)})}transformDropType(e,t){return o({kind:"DropTypeNode",name:this.transformNode(e.name,t),ifExists:e.ifExists})}transformExplain(e,t){return o({kind:"ExplainNode",format:e.format,options:this.transformNode(e.options,t)})}transformSchemableIdentifier(e,t){return o({kind:"SchemableIdentifierNode",schema:this.transformNode(e.schema,t),identifier:this.transformNode(e.identifier,t)})}transformAggregateFunction(e,t){return o({kind:"AggregateFunctionNode",func:e.func,aggregated:this.transformNodeList(e.aggregated,t),distinct:e.distinct,orderBy:this.transformNode(e.orderBy,t),withinGroup:this.transformNode(e.withinGroup,t),filter:this.transformNode(e.filter,t),over:this.transformNode(e.over,t)})}transformOver(e,t){return o({kind:"OverNode",orderBy:this.transformNode(e.orderBy,t),partitionBy:this.transformNode(e.partitionBy,t)})}transformPartitionBy(e,t){return o({kind:"PartitionByNode",items:this.transformNodeList(e.items,t)})}transformPartitionByItem(e,t){return o({kind:"PartitionByItemNode",partitionBy:this.transformNode(e.partitionBy,t)})}transformBinaryOperation(e,t){return o({kind:"BinaryOperationNode",leftOperand:this.transformNode(e.leftOperand,t),operator:this.transformNode(e.operator,t),rightOperand:this.transformNode(e.rightOperand,t)})}transformUnaryOperation(e,t){return o({kind:"UnaryOperationNode",operator:this.transformNode(e.operator,t),operand:this.transformNode(e.operand,t)})}transformUsing(e,t){return o({kind:"UsingNode",tables:this.transformNodeList(e.tables,t)})}transformFunction(e,t){return o({kind:"FunctionNode",func:e.func,arguments:this.transformNodeList(e.arguments,t)})}transformCase(e,t){return o({kind:"CaseNode",value:this.transformNode(e.value,t),when:this.transformNodeList(e.when,t),else:this.transformNode(e.else,t),isStatement:e.isStatement})}transformWhen(e,t){return o({kind:"WhenNode",condition:this.transformNode(e.condition,t),result:this.transformNode(e.result,t)})}transformJSONReference(e,t){return o({kind:"JSONReferenceNode",reference:this.transformNode(e.reference,t),traversal:this.transformNode(e.traversal,t)})}transformJSONPath(e,t){return o({kind:"JSONPathNode",inOperator:this.transformNode(e.inOperator,t),pathLegs:this.transformNodeList(e.pathLegs,t)})}transformJSONPathLeg(e,t){return o({kind:"JSONPathLegNode",type:e.type,value:e.value})}transformJSONOperatorChain(e,t){return o({kind:"JSONOperatorChainNode",operator:this.transformNode(e.operator,t),values:this.transformNodeList(e.values,t)})}transformTuple(e,t){return o({kind:"TupleNode",values:this.transformNodeList(e.values,t)})}transformMergeQuery(e,t){return o({kind:"MergeQueryNode",into:this.transformNode(e.into,t),using:this.transformNode(e.using,t),whens:this.transformNodeList(e.whens,t),with:this.transformNode(e.with,t),top:this.transformNode(e.top,t),endModifiers:this.transformNodeList(e.endModifiers,t),output:this.transformNode(e.output,t),returning:this.transformNode(e.returning,t)})}transformMatched(e,t){return o({kind:"MatchedNode",not:e.not,bySource:e.bySource})}transformAddIndex(e,t){return o({kind:"AddIndexNode",name:this.transformNode(e.name,t),columns:this.transformNodeList(e.columns,t),unique:e.unique,using:this.transformNode(e.using,t),ifNotExists:e.ifNotExists})}transformCast(e,t){return o({kind:"CastNode",expression:this.transformNode(e.expression,t),dataType:this.transformNode(e.dataType,t)})}transformFetch(e,t){return o({kind:"FetchNode",rowCount:this.transformNode(e.rowCount,t),modifier:e.modifier})}transformTop(e,t){return o({kind:"TopNode",expression:e.expression,modifiers:e.modifiers})}transformOutput(e,t){return o({kind:"OutputNode",selections:this.transformNodeList(e.selections,t)})}transformDataType(e,t){return e}transformSelectAll(e,t){return e}transformIdentifier(e,t){return e}transformValue(e,t){return e}transformPrimitiveValueList(e,t){return e}transformOperator(e,t){return e}transformDefaultInsertValue(e,t){return e}transformOrAction(e,t){return e}transformCollate(e,t){return e}}var Kr=C({AlterTableNode:!0,CreateIndexNode:!0,CreateSchemaNode:!0,CreateTableNode:!0,CreateTypeNode:!0,CreateViewNode:!0,RefreshMaterializedViewNode:!0,DeleteQueryNode:!0,DropIndexNode:!0,DropSchemaNode:!0,DropTableNode:!0,DropTypeNode:!0,DropViewNode:!0,InsertQueryNode:!0,RawNode:!0,SelectQueryNode:!0,UpdateQueryNode:!0,MergeQueryNode:!0}),jr={json_agg:!0,to_json:!0};class ct extends Du{#e;#t=new Set;#r=new Set;constructor(e){super();this.#e=e}transformNodeImpl(e,t){if(!this.#s(e))return super.transformNodeImpl(e,t);let r=this.#p(e);for(let a of r)this.#r.add(a);let i=this.#a(e);for(let a of i)this.#t.add(a);let n=super.transformNodeImpl(e,t);for(let a of i)this.#t.delete(a);for(let a of r)this.#r.delete(a);return n}transformSchemableIdentifier(e,t){let r=super.transformSchemableIdentifier(e,t);if(r.schema||!this.#t.has(e.identifier.name))return r;return{...r,schema:st.create(this.#e)}}transformReferences(e,t){let r=super.transformReferences(e,t);if(r.table.table.schema)return r;return{...r,table:mo.createWithSchema(this.#e,r.table.table.identifier.name)}}transformAggregateFunction(e,t){return{...super.transformAggregateFunction({...e,aggregated:[]},t),aggregated:this.#o(e,t,"aggregated")}}transformFunction(e,t){return{...super.transformFunction({...e,arguments:[]},t),arguments:this.#o(e,t,"arguments")}}transformSelectModifier(e,t){return{...super.transformSelectModifier({...e,of:void 0},t),of:e.of?.map((r)=>mo.is(r)&&!r.table.schema?{...r,table:this.transformIdentifier(r.table.identifier,t)}:this.transformNode(r,t))}}#o(e,t,r){return jr[e.func]?e[r].map((i)=>!mo.is(i)||i.table.schema?this.transformNode(i,t):{...i,table:this.transformIdentifier(i.table.identifier,t)}):this.transformNodeList(e[r],t)}#s(e){return e.kind in Kr}#a(e){let t=new Set;if("name"in e&&e.name&&po.is(e.name))this.#n(e.name,t);if("from"in e&&e.from)for(let r of e.from.froms)this.#i(r,t);if("into"in e&&e.into)this.#i(e.into,t);if("table"in e&&e.table)this.#i(e.table,t);if("joins"in e&&e.joins)for(let r of e.joins)this.#i(r.table,t);if("using"in e&&e.using)if(L.is(e.using))this.#i(e.using.table,t);else this.#i(e.using,t);return t}#p(e){let t=new Set;if("with"in e&&e.with)this.#d(e.with,t);return t}#i(e,t){if(mo.is(e))return this.#n(e.table,t);if(l.is(e)&&mo.is(e.node))return this.#n(e.node.table,t);if(Fe.is(e)){for(let r of e.items)this.#i(r,t);return}if(be.is(e)){for(let r of e.tables)this.#i(r,t);return}}#n(e,t){let r=e.identifier.name;if(!this.#t.has(r)&&!this.#r.has(r))t.add(r)}#d(e,t){for(let r of e.expressions){let i=r.name.table.table.identifier.name;if(!this.#r.has(i))t.add(i)}}}class js{#e;constructor(e){this.#e=new ct(e)}transformQuery(e){return this.#e.transformNode(e.node,e.queryId)}async transformResult(e){return e.result}}var Zt=C({is(e){return e.kind==="MatchedNode"},create(e,t=!1){return C({kind:"MatchedNode",not:e,bySource:t})}});function lt(e,t,r){return R.create(de([Zt.create(!e.isMatched,e.bySource),...t&&t.length>0?[t.length===3&&r?N(t[0],t[1],t[2]):yr(t)]:[]],"and",!1))}function Ne(e){if(dr(e))return tr.create([e],[]);if(Rr(e))return e.toOperationNode();return e}class Ua{#e;#t;#r;constructor(){this.#e=new Promise((e,t)=>{this.#r=t,this.#t=e})}get promise(){return this.#e}resolve=(e)=>{if(this.#t)this.#t(e)};reject=(e)=>{if(this.#r)this.#r(e)}}async function of(e){let t=new Ua,r=new Ua;return e.provideConnection(async(i)=>(t.resolve(i),await r.promise)).catch((i)=>t.reject(i)),C({connection:await t.promise,release:r.resolve})}var Hr=C([]);class Nu{#e;constructor(e=Hr){this.#e=e}get plugins(){return this.#e}transformQuery(e,t){for(let r of this.#e){let i=r.transformQuery({node:e,queryId:t});if(i.kind===e.kind)e=i;else throw Error(["KyselyPlugin.transformQuery must return a node","of the same kind that was given to it.",`The plugin was given a ${e.kind}`,`but it returned a ${i.kind}`].join(" "))}return e}async executeQuery(e){return await this.provideConnection(async(t)=>{let r=await t.executeQuery(e);if("numUpdatedOrDeletedRows"in r)hi("kysely:warning: outdated driver/plugin detected! `QueryResult.numUpdatedOrDeletedRows` has been replaced with `QueryResult.numAffectedRows`.");return await this.#t(r,e.queryId)})}async*stream(e,t){let{connection:r,release:i}=await of(this);try{for await(let n of r.streamQuery(e,t))yield await this.#t(n,e.queryId)}finally{i()}}async#t(e,t){for(let r of this.#e)e=await r.transformResult({result:e,queryId:t});return e}}class ye extends Nu{get adapter(){throw Error("this query cannot be compiled to SQL")}compileQuery(){throw Error("this query cannot be compiled to SQL")}provideConnection(){throw Error("this query cannot be executed")}withConnectionProvider(){throw Error("this query cannot have a connection provider")}withPlugin(e){return new ye([...this.plugins,e])}withPlugins(e){return new ye([...this.plugins,...e])}withPluginAtFront(e){return new ye([e,...this.plugins])}withoutPlugins(){return new ye([])}}var ie=new ye;class Nt{numChangedRows;constructor(e){this.numChangedRows=e}}class G{#e;constructor(e){this.#e=C(e)}modifyEnd(e){return new G({...this.#e,queryNode:Oe.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}top(e,t){return new G({...this.#e,queryNode:Oe.cloneWithTop(this.#e.queryNode,M(e,t))})}using(...e){return new b({...this.#e,queryNode:A.cloneWithUsing(this.#e.queryNode,re("Using",e))})}returning(e){return new G({...this.#e,queryNode:Oe.cloneWithReturning(this.#e.queryNode,c(e))})}returningAll(e){return new G({...this.#e,queryNode:Oe.cloneWithReturning(this.#e.queryNode,y(e))})}output(e){return new G({...this.#e,queryNode:Oe.cloneWithOutput(this.#e.queryNode,c(e))})}outputAll(e){return new G({...this.#e,queryNode:Oe.cloneWithOutput(this.#e.queryNode,y(e))})}}class b{#e;constructor(e){this.#e=C(e)}modifyEnd(e){return new b({...this.#e,queryNode:Oe.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}top(e,t){return new b({...this.#e,queryNode:Oe.cloneWithTop(this.#e.queryNode,M(e,t))})}whenMatched(){return this.#t([])}whenMatchedAnd(...e){return this.#t(e)}whenMatchedAndRef(e,t,r){return this.#t([e,t,r],!0)}#t(e,t){return new yt({...this.#e,queryNode:A.cloneWithWhen(this.#e.queryNode,lt({isMatched:!0},e,t))})}whenNotMatched(){return this.#r([])}whenNotMatchedAnd(...e){return this.#r(e)}whenNotMatchedAndRef(e,t,r){return this.#r([e,t,r],!0)}whenNotMatchedBySource(){return this.#r([],!1,!0)}whenNotMatchedBySourceAnd(...e){return this.#r(e,!1,!0)}whenNotMatchedBySourceAndRef(e,t,r){return this.#r([e,t,r],!0,!0)}returning(e){return new b({...this.#e,queryNode:Oe.cloneWithReturning(this.#e.queryNode,c(e))})}returningAll(e){return new b({...this.#e,queryNode:Oe.cloneWithReturning(this.#e.queryNode,y(e))})}output(e){return new b({...this.#e,queryNode:Oe.cloneWithOutput(this.#e.queryNode,c(e))})}outputAll(e){return new b({...this.#e,queryNode:Oe.cloneWithOutput(this.#e.queryNode,y(e))})}#r(e,t=!1,r=!1){let i={...this.#e,queryNode:A.cloneWithWhen(this.#e.queryNode,lt({isMatched:!1,bySource:r},e,t))};return new(r?yt:er)(i)}$call(e){return e(this)}$if(e,t){if(e)return t(this);return new b({...this.#e})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile(),t=await this.#e.executor.executeQuery(e),{adapter:r}=this.#e.executor,i=e.query;if(i.returning&&r.supportsReturning||i.output&&r.supportsOutput)return t.rows;return[new Nt(t.numAffectedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=q){let t=await this.executeTakeFirst();if(t===void 0)throw V(e)?new e(this.toOperationNode()):e(this.toOperationNode());return t}}class yt{#e;constructor(e){this.#e=C(e)}thenDelete(){return new b({...this.#e,queryNode:A.cloneWithThen(this.#e.queryNode,Ne("delete"))})}thenDoNothing(){return new b({...this.#e,queryNode:A.cloneWithThen(this.#e.queryNode,Ne("do nothing"))})}thenUpdate(e){return new b({...this.#e,queryNode:A.cloneWithThen(this.#e.queryNode,Ne(e(new ce({queryId:this.#e.queryId,executor:ie,queryNode:F.createWithoutTable()}))))})}thenUpdateSet(...e){return this.thenUpdate((t)=>t.set(...e))}}class er{#e;constructor(e){this.#e=C(e)}thenDoNothing(){return new b({...this.#e,queryNode:A.cloneWithThen(this.#e.queryNode,Ne("do nothing"))})}thenInsertValues(e){let[t,r]=Ue(e);return new b({...this.#e,queryNode:A.cloneWithThen(this.#e.queryNode,Ne(u.cloneWith(u.createWithoutInto(),{columns:t,values:r})))})}}class gi{#e;constructor(e){this.#e=C(e)}selectFrom(e){return Ee({queryId:It(),executor:this.#e.executor,queryNode:nr.createFrom(P(e),this.#e.withNode)})}selectNoFrom(e){return Ee({queryId:It(),executor:this.#e.executor,queryNode:nr.cloneWithSelections(nr.create(this.#e.withNode),c(e))})}insertInto(e){return new h({queryId:It(),executor:this.#e.executor,queryNode:u.create(or(e),this.#e.withNode)})}replaceInto(e){return new h({queryId:It(),executor:this.#e.executor,queryNode:u.create(or(e),this.#e.withNode,!0)})}deleteFrom(e){return new ze({queryId:It(),executor:this.#e.executor,queryNode:te.create(P(e),this.#e.withNode)})}updateTable(e){return new ce({queryId:It(),executor:this.#e.executor,queryNode:F.create(P(e),this.#e.withNode)})}mergeInto(e){return new G({queryId:It(),executor:this.#e.executor,queryNode:A.create(wt(e),this.#e.withNode)})}with(e,t){let r=ft(e,t);return new gi({...this.#e,withNode:this.#e.withNode?ke.cloneWithExpression(this.#e.withNode,r):ke.create(r)})}withRecursive(e,t){let r=ft(e,t);return new gi({...this.#e,withNode:this.#e.withNode?ke.cloneWithExpression(this.#e.withNode,r):ke.create(r,{recursive:!0})})}withPlugin(e){return new gi({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new gi({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new gi({...this.#e,executor:this.#e.executor.withPluginAtFront(new js(e))})}}function Ht(){return new gi({executor:ie})}function rr(e,t){return new he({joinNode:L.create(e,se(t))})}function ir(){return new ue({overNode:ve.create()})}function re(e,t){if(t.length===3)return Xr(e,t[0],t[1],t[2]);else if(t.length===2)return Yr(e,t[0],t[1]);else if(t.length===1)return Zr(e,t[0]);else throw Error("not implemented")}function Yr(e,t,r){return r(rr(e,t)).toOperationNode()}function Xr(e,t,r,i){return L.createWithOn(e,se(t),N(r,"=",i))}function Zr(e,t){return L.create(e,se(t))}var sr=C({is(e){return e.kind==="OffsetNode"},create(e){return C({kind:"OffsetNode",offset:e})}});var ar=C({is(e){return e.kind==="GroupByItemNode"},create(e){return C({kind:"GroupByItemNode",groupBy:e})}});function pr(e){return e=fr(e)?e(B()):e,Q(e).map(ar.create)}var Je=C({is(e){return e.kind==="SetOperationNode"},create(e,t,r){return C({kind:"SetOperationNode",operator:e,expression:t,all:r})}});function ae(e,t,r){if(fr(t))t=t(Qe());if(!x(t))t=[t];return t.map((i)=>Je.create(e,Ho(i),r))}class p{#e;constructor(e){this.#e=e}get expressionType(){return}as(e){return new Ge(this,e)}or(...e){return new _e(T.create(this.#e,yr(e)))}and(...e){return new $e(v.create(this.#e,yr(e)))}$castTo(){return new p(this.#e)}$notNull(){return new p(this.#e)}toOperationNode(){return this.#e}}class Ge{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return l.create(this.#e.toOperationNode(),Rr(this.#t)?this.#t.toOperationNode():st.create(this.#t))}}class _e{#e;constructor(e){this.#e=e}get expressionType(){return}as(e){return new Ge(this,e)}or(...e){return new _e(T.create(this.#e,yr(e)))}$castTo(){return new _e(this.#e)}toOperationNode(){return E.create(this.#e)}}class $e{#e;constructor(e){this.#e=e}get expressionType(){return}as(e){return new Ge(this,e)}and(...e){return new $e(v.create(this.#e,yr(e)))}$castTo(){return new $e(this.#e)}toOperationNode(){return E.create(this.#e)}}var hr=C({is(e){return e.kind==="FetchNode"},create(e,t){return{kind:"FetchNode",rowCount:_n.create(e),modifier:t}}});function ur(e,t){if(!zs(e)&&!La(e))throw Error(`Invalid fetch row count: ${e}`);if(!ei(t))throw Error(`Invalid fetch modifier: ${t}`);return hr.create(e,t)}function ei(e){return e==="only"||e==="with ties"}var s;class Ot{#e;constructor(e){this.#e=C(e)}get expressionType(){return}get isSelectQueryBuilder(){return!0}where(...e){return new s({...this.#e,queryNode:Oe.cloneWithWhere(this.#e.queryNode,yr(e))})}whereRef(e,t,r){return new s({...this.#e,queryNode:Oe.cloneWithWhere(this.#e.queryNode,N(e,t,r))})}having(...e){return new s({...this.#e,queryNode:nr.cloneWithHaving(this.#e.queryNode,yr(e))})}havingRef(e,t,r){return new s({...this.#e,queryNode:nr.cloneWithHaving(this.#e.queryNode,N(e,t,r))})}select(e){return new s({...this.#e,queryNode:nr.cloneWithSelections(this.#e.queryNode,c(e))})}distinctOn(e){return new s({...this.#e,queryNode:nr.cloneWithDistinctOn(this.#e.queryNode,Q(e))})}modifyFront(e){return new s({...this.#e,queryNode:nr.cloneWithFrontModifier(this.#e.queryNode,I.createWithExpression(e.toOperationNode()))})}modifyEnd(e){return new s({...this.#e,queryNode:Oe.cloneWithEndModifier(this.#e.queryNode,I.createWithExpression(e.toOperationNode()))})}distinct(){return new s({...this.#e,queryNode:nr.cloneWithFrontModifier(this.#e.queryNode,I.create("Distinct"))})}forUpdate(e){return new s({...this.#e,queryNode:Oe.cloneWithEndModifier(this.#e.queryNode,I.create("ForUpdate",e?xe(e).map(or):void 0))})}forShare(e){return new s({...this.#e,queryNode:Oe.cloneWithEndModifier(this.#e.queryNode,I.create("ForShare",e?xe(e).map(or):void 0))})}forKeyShare(e){return new s({...this.#e,queryNode:Oe.cloneWithEndModifier(this.#e.queryNode,I.create("ForKeyShare",e?xe(e).map(or):void 0))})}forNoKeyUpdate(e){return new s({...this.#e,queryNode:Oe.cloneWithEndModifier(this.#e.queryNode,I.create("ForNoKeyUpdate",e?xe(e).map(or):void 0))})}skipLocked(){return new s({...this.#e,queryNode:Oe.cloneWithEndModifier(this.#e.queryNode,I.create("SkipLocked"))})}noWait(){return new s({...this.#e,queryNode:Oe.cloneWithEndModifier(this.#e.queryNode,I.create("NoWait"))})}selectAll(e){return new s({...this.#e,queryNode:nr.cloneWithSelections(this.#e.queryNode,y(e))})}innerJoin(...e){return this.#t("InnerJoin",e)}leftJoin(...e){return this.#t("LeftJoin",e)}rightJoin(...e){return this.#t("RightJoin",e)}fullJoin(...e){return this.#t("FullJoin",e)}crossJoin(...e){return this.#t("CrossJoin",e)}innerJoinLateral(...e){return this.#t("LateralInnerJoin",e)}leftJoinLateral(...e){return this.#t("LateralLeftJoin",e)}crossJoinLateral(...e){return this.#t("LateralCrossJoin",e)}crossApply(...e){return this.#t("CrossApply",e)}outerApply(...e){return this.#t("OuterApply",e)}#t(e,t){return new s({...this.#e,queryNode:Oe.cloneWithJoin(this.#e.queryNode,re(e,t))})}orderBy(...e){return new s({...this.#e,queryNode:Oe.cloneWithOrderByItems(this.#e.queryNode,k(e))})}groupBy(e){return new s({...this.#e,queryNode:nr.cloneWithGroupByItems(this.#e.queryNode,pr(e))})}limit(e){return new s({...this.#e,queryNode:nr.cloneWithLimit(this.#e.queryNode,fe.create(d(e)))})}offset(e){return new s({...this.#e,queryNode:nr.cloneWithOffset(this.#e.queryNode,sr.create(d(e)))})}fetch(e,t="only"){return new s({...this.#e,queryNode:nr.cloneWithFetch(this.#e.queryNode,ur(e,t))})}top(e,t){return new s({...this.#e,queryNode:Oe.cloneWithTop(this.#e.queryNode,M(e,t))})}union(e){return new s({...this.#e,queryNode:nr.cloneWithSetOperations(this.#e.queryNode,ae("union",e,!1))})}unionAll(e){return new s({...this.#e,queryNode:nr.cloneWithSetOperations(this.#e.queryNode,ae("union",e,!0))})}intersect(e){return new s({...this.#e,queryNode:nr.cloneWithSetOperations(this.#e.queryNode,ae("intersect",e,!1))})}intersectAll(e){return new s({...this.#e,queryNode:nr.cloneWithSetOperations(this.#e.queryNode,ae("intersect",e,!0))})}except(e){return new s({...this.#e,queryNode:nr.cloneWithSetOperations(this.#e.queryNode,ae("except",e,!1))})}exceptAll(e){return new s({...this.#e,queryNode:nr.cloneWithSetOperations(this.#e.queryNode,ae("except",e,!0))})}as(e){return new mr(this,e)}clearSelect(){return new s({...this.#e,queryNode:nr.cloneWithoutSelections(this.#e.queryNode)})}clearWhere(){return new s({...this.#e,queryNode:Oe.cloneWithoutWhere(this.#e.queryNode)})}clearLimit(){return new s({...this.#e,queryNode:nr.cloneWithoutLimit(this.#e.queryNode)})}clearOffset(){return new s({...this.#e,queryNode:nr.cloneWithoutOffset(this.#e.queryNode)})}clearOrderBy(){return new s({...this.#e,queryNode:Oe.cloneWithoutOrderBy(this.#e.queryNode)})}clearGroupBy(){return new s({...this.#e,queryNode:nr.cloneWithoutGroupBy(this.#e.queryNode)})}$call(e){return e(this)}$if(e,t){if(e)return t(this);return new s({...this.#e})}$castTo(){return new s(this.#e)}$narrowType(){return new s(this.#e)}$assertType(){return new s(this.#e)}$asTuple(){return new p(this.toOperationNode())}$asScalar(){return new p(this.toOperationNode())}withPlugin(e){return new s({...this.#e,executor:this.#e.executor.withPlugin(e)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile();return(await this.#e.executor.executeQuery(e)).rows}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=q){let t=await this.executeTakeFirst();if(t===void 0)throw V(e)?new e(this.toOperationNode()):e(this.toOperationNode());return t}async*stream(e=100){let t=this.compile(),r=this.#e.executor.stream(t,e);for await(let i of r)yield*i.rows}async explain(e,t){return await new s({...this.#e,queryNode:Oe.cloneWithExplain(this.#e.queryNode,e,t)}).execute()}}s=Ot;function Ee(e){return new Ot(e)}class mr{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get expression(){return this.#e}get alias(){return this.#t}get isAliasedSelectQueryBuilder(){return!0}toOperationNode(){return l.create(this.#e.toOperationNode(),st.create(this.#t))}}var z=C({is(e){return e.kind==="AggregateFunctionNode"},create(e,t=[]){return C({kind:"AggregateFunctionNode",func:e,aggregated:t})},cloneWithDistinct(e){return C({...e,distinct:!0})},cloneWithOrderBy(e,t,r=!1){let i=r?"withinGroup":"orderBy";return C({...e,[i]:e[i]?_.cloneWithItems(e[i],t):_.create(t)})},cloneWithFilter(e,t){return C({...e,filter:e.filter?O.cloneWithOperation(e.filter,"And",t):O.create(t)})},cloneWithOrFilter(e,t){return C({...e,filter:e.filter?O.cloneWithOperation(e.filter,"Or",t):O.create(t)})},cloneWithOver(e,t){return C({...e,over:t})}});var xt=C({is(e){return e.kind==="FunctionNode"},create(e,t){return C({kind:"FunctionNode",func:e,arguments:t})}});class W{#e;constructor(e){this.#e=C(e)}get expressionType(){return}as(e){return new cr(this,e)}distinct(){return new W({...this.#e,aggregateFunctionNode:z.cloneWithDistinct(this.#e.aggregateFunctionNode)})}orderBy(...e){return new W({...this.#e,aggregateFunctionNode:Oe.cloneWithOrderByItems(this.#e.aggregateFunctionNode,k(e))})}clearOrderBy(){return new W({...this.#e,aggregateFunctionNode:Oe.cloneWithoutOrderBy(this.#e.aggregateFunctionNode)})}withinGroupOrderBy(...e){return new W({...this.#e,aggregateFunctionNode:z.cloneWithOrderBy(this.#e.aggregateFunctionNode,k(e),!0)})}filterWhere(...e){return new W({...this.#e,aggregateFunctionNode:z.cloneWithFilter(this.#e.aggregateFunctionNode,yr(e))})}filterWhereRef(e,t,r){return new W({...this.#e,aggregateFunctionNode:z.cloneWithFilter(this.#e.aggregateFunctionNode,N(e,t,r))})}over(e){let t=ir();return new W({...this.#e,aggregateFunctionNode:z.cloneWithOver(this.#e.aggregateFunctionNode,(e?e(t):t).toOperationNode())})}$call(e){return e(this)}$castTo(){return new W(this.#e)}$notNull(){return new W(this.#e)}toOperationNode(){return this.#e.aggregateFunctionNode}}class cr{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return l.create(this.#e.toOperationNode(),st.create(this.#t))}}function sf(){let e=(r,i)=>new p(xt.create(r,Q(i??[]))),t=(r,i)=>new W({aggregateFunctionNode:z.create(r,i?Q(i):void 0)});return Object.assign(e,{agg:t,avg(r){return t("avg",[r])},coalesce(...r){return e("coalesce",r)},count(r){return t("count",[r])},countAll(r){return new W({aggregateFunctionNode:z.create("count",y(r))})},max(r){return t("max",[r])},min(r){return t("min",[r])},sum(r){return t("sum",[r])},any(r){return e("any",[r])},jsonAgg(r){return new W({aggregateFunctionNode:z.create("json_agg",[dr(r)?or(r):r.toOperationNode()])})},toJson(r){return new p(xt.create("to_json",[dr(r)?or(r):r.toOperationNode()]))}})}var lr=C({is(e){return e.kind==="UnaryOperationNode"},create(e,t){return C({kind:"UnaryOperationNode",operator:e,operand:t})}});function Nr(e,t){return lr.create(S.create(e),w(t))}var as=C({is(e){return e.kind==="CaseNode"},create(e){return C({kind:"CaseNode",value:e})},cloneWithWhen(e,t){return C({...e,when:C(e.when?[...e.when,t]:[t])})},cloneWithThen(e,t){return C({...e,when:e.when?C([...e.when.slice(0,-1),R.cloneWithResult(e.when[e.when.length-1],t)]):void 0})},cloneWith(e,t){return C({...e,...t})}});class Fu{#e;constructor(e){this.#e=C(e)}when(...e){return new gt({...this.#e,node:as.cloneWithWhen(this.#e.node,R.create(yr(e)))})}}class gt{#e;constructor(e){this.#e=C(e)}then(e){return new wr({...this.#e,node:as.cloneWithThen(this.#e.node,Pe(e)?ge(e):d(e))})}}class wr{#e;constructor(e){this.#e=C(e)}when(...e){return new gt({...this.#e,node:as.cloneWithWhen(this.#e.node,R.create(yr(e)))})}else(e){return new Or({...this.#e,node:as.cloneWith(this.#e.node,{else:Pe(e)?ge(e):d(e)})})}end(){return new p(as.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new p(as.cloneWith(this.#e.node,{isStatement:!0}))}}class Or{#e;constructor(e){this.#e=C(e)}end(){return new p(as.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new p(as.cloneWith(this.#e.node,{isStatement:!0}))}}var vt=C({is(e){return e.kind==="JSONPathLegNode"},create(e,t){return C({kind:"JSONPathLegNode",type:e,value:t})}});var ti=/^#-\d+$/;class Re{#e;constructor(e){this.#e=e}at(e){if(typeof e!=="number"&&typeof e!=="string"||typeof e==="number"&&!Number.isInteger(e)||typeof e==="string"&&e!=="last"&&!ti.test(e))throw Error(`Unexpected index value in .at(...): ${e}`);return this.#t("ArrayLocation",e)}key(e){return this.#t("Member",e)}#t(e,t){if(pe.is(this.#e))return new Ae(pe.cloneWithTraversal(this.#e,ee.is(this.#e.traversal)?ee.cloneWithLeg(this.#e.traversal,vt.create(e,t)):qe.cloneWithValue(this.#e.traversal,_n.createImmediate(t))));return new Ae(ee.cloneWithLeg(this.#e,vt.create(e,t)))}}class Ae extends Re{#e;constructor(e){super(e);this.#e=e}get expressionType(){return}as(e){return new xr(this,e)}$castTo(){return new Ae(this.#e)}$notNull(){return new Ae(this.#e)}toOperationNode(){return this.#e}}class xr{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return l.create(this.#e.toOperationNode(),Rr(this.#t)?this.#t.toOperationNode():st.create(this.#t))}}var bt=C({is(e){return e.kind==="TupleNode"},create(e){return C({kind:"TupleNode",values:C(e)})}});var ri=["varchar","char","text","integer","int2","int4","int8","smallint","bigint","boolean","real","double precision","float4","float8","decimal","numeric","binary","bytea","date","datetime","time","timetz","timestamp","timestamptz","serial","bigserial","uuid","json","jsonb","blob","varbinary","int4range","int4multirange","int8range","int8multirange","numrange","nummultirange","tsrange","tsmultirange","tstzrange","tstzmultirange","daterange","datemultirange"],ii=[/^varchar\(\d+\)$/,/^char\(\d+\)$/,/^decimal\(\d+, \d+\)$/,/^numeric\(\d+, \d+\)$/,/^binary\(\d+\)$/,/^datetime\(\d+\)$/,/^time\(\d+\)$/,/^timetz\(\d+\)$/,/^timestamp\(\d+\)$/,/^timestamptz\(\d+\)$/,/^varbinary\(\d+\)$/],gr=C({is(e){return e.kind==="DataTypeNode"},create(e){return C({kind:"DataTypeNode",dataType:e})}});function vr(e){if(ri.includes(e))return!0;if(ii.some((t)=>t.test(e)))return!0;return!1}function qs(e){if(Rr(e))return e.toOperationNode();if(vr(e))return gr.create(e);throw Error(`invalid column data type ${JSON.stringify(e)}`)}var br=C({is(e){return e.kind==="CastNode"},create(e,t){return C({kind:"CastNode",expression:e,dataType:t})}});function Qe(e=ie){function t(n,a,j){return new p(Ie(n,a,j))}function r(n,a){return new p(Nr(n,a))}let i=Object.assign(t,{fn:void 0,eb:void 0,selectFrom(n){return Ee({queryId:It(),executor:e,queryNode:nr.createFrom(P(n))})},case(n){return new Fu({node:as.create(So(n)?void 0:w(n))})},ref(n,a){if(So(a))return new p(is(n));return new Re(Lt(n,a))},jsonPath(){return new Re(ee.create())},table(n){return new p(or(n))},val(n){return new p(d(n))},refTuple(...n){return new p(bt.create(n.map(w)))},tuple(...n){return new p(bt.create(n.map(d)))},lit(n){return new p(ge(n))},unary:r,not(n){return r("not",n)},exists(n){return r("exists",n)},neg(n){return r("-",n)},between(n,a,j){return new p(X.create(w(n),S.create("between"),v.create(d(a),d(j))))},betweenSymmetric(n,a,j){return new p(X.create(w(n),S.create("between symmetric"),v.create(d(a),d(j))))},and(n){if(x(n))return new p(de(n,"and"));return new p(tt(n,"and"))},or(n){if(x(n))return new p(de(n,"or"));return new p(tt(n,"or"))},parens(...n){let a=yr(n);if(E.is(a))return new p(a);else return new p(E.create(a))},cast(n,a){return new p(br.create(w(n),qs(a)))},withSchema(n){return Qe(e.withPluginAtFront(new js(n)))}});return i.fn=sf(),i.eb=i,i}function B(e){return Qe()}function Ho(e){if(Rr(e))return e.toOperationNode();else if(fr(e))return e(B()).toOperationNode();throw Error(`invalid expression: ${JSON.stringify(e)}`)}function Ve(e){if(Rr(e))return e.toOperationNode();else if(fr(e))return e(B()).toOperationNode();throw Error(`invalid aliased expression: ${JSON.stringify(e)}`)}function J(e){return Le(e)||Ct(e)||fr(e)}class hm{#e;get table(){return this.#e}constructor(e){this.#e=e}as(e){return new Wr(this.#e,e)}}class Wr{#e;#t;get table(){return this.#e}get alias(){return this.#t}constructor(e,t){this.#e=e,this.#t=t}toOperationNode(){return l.create(or(this.#e),st.create(this.#t))}}function Sr(e){return sn(e)&&Rr(e)&&dr(e.table)&&dr(e.alias)}function P(e){if(x(e))return e.map((t)=>se(t));else return[se(e)]}function se(e){if(dr(e))return wt(e);else if(Sr(e))return e.toOperationNode();else return Ve(e)}function wt(e){if(e.includes(" as ")){let[r,i]=e.split(" as ").map(Cr);return l.create(or(r),st.create(i))}else return or(e)}function or(e){if(e.includes(".")){let[r,i]=e.split(".").map(Cr);return mo.createWithSchema(r,i)}else return mo.create(e)}function Cr(e){return e.trim()}var $s=C({is(e){return e.kind==="CreateViewNode"},create(e){return C({kind:"CreateViewNode",name:po.create(e)})},cloneWith(e,t){return C({...e,...t})}});class Te{#e;constructor(e){this.#e=C(e)}get expressionType(){return}get isRawBuilder(){return!0}as(e){return new kr(this,e)}$castTo(){return new Te({...this.#e})}$notNull(){return new Te(this.#e)}withPlugin(e){return new Te({...this.#e,plugins:this.#e.plugins!==void 0?C([...this.#e.plugins,e]):C([e])})}toOperationNode(){return this.#r(this.#t())}compile(e){return this.#o(this.#t(e))}async execute(e){let t=this.#t(e);return t.executeQuery(this.#o(t))}#t(e){let t=e!==void 0?e.getExecutor():ie;return this.#e.plugins!==void 0?t.withPlugins(this.#e.plugins):t}#r(e){return e.transformQuery(this.#e.rawNode,this.#e.queryId)}#o(e){return e.compileQuery(this.#r(e),this.#e.queryId)}}function K(e){return new Te(e)}class kr{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get expression(){return this.#e}get alias(){return this.#t}get rawBuilder(){return this.#e}toOperationNode(){return l.create(this.#e.toOperationNode(),Rr(this.#t)?this.#t.toOperationNode():st.create(this.#t))}}var je=Object.assign((e,...t)=>K({queryId:It(),rawNode:tr.create(e,t?.map(Er)??[])}),{ref(e){return K({queryId:It(),rawNode:tr.createWithChild(is(e))})},val(e){return K({queryId:It(),rawNode:tr.createWithChild(d(e))})},value(e){return this.val(e)},table(e){return K({queryId:It(),rawNode:tr.createWithChild(or(e))})},id(...e){let t=Array(e.length+1).fill(".");return t[0]="",t[t.length-1]="",K({queryId:It(),rawNode:tr.create(t,e.map(st.create))})},lit(e){return K({queryId:It(),rawNode:tr.createWithChild(_n.createImmediate(e))})},literal(e){return this.lit(e)},raw(e){return K({queryId:It(),rawNode:tr.createWithSql(e)})},join(e,t=je`, `){let r=Array(Math.max(2*e.length-1,0)),i=t.toOperationNode();for(let n=0;n<e.length;++n)if(r[2*n]=Er(e[n]),n!==e.length-1)r[2*n+1]=i;return K({queryId:It(),rawNode:tr.createWithChildren(r)})}});function Er(e){if(Rr(e))return e.toOperationNode();return d(e)}class St{nodeStack=[];get parentNode(){return this.nodeStack[this.nodeStack.length-2]}#e=C({AliasNode:this.visitAlias.bind(this),ColumnNode:this.visitColumn.bind(this),IdentifierNode:this.visitIdentifier.bind(this),SchemableIdentifierNode:this.visitSchemableIdentifier.bind(this),RawNode:this.visitRaw.bind(this),ReferenceNode:this.visitReference.bind(this),SelectQueryNode:this.visitSelectQuery.bind(this),SelectionNode:this.visitSelection.bind(this),TableNode:this.visitTable.bind(this),FromNode:this.visitFrom.bind(this),SelectAllNode:this.visitSelectAll.bind(this),AndNode:this.visitAnd.bind(this),OrNode:this.visitOr.bind(this),ValueNode:this.visitValue.bind(this),ValueListNode:this.visitValueList.bind(this),PrimitiveValueListNode:this.visitPrimitiveValueList.bind(this),ParensNode:this.visitParens.bind(this),JoinNode:this.visitJoin.bind(this),OperatorNode:this.visitOperator.bind(this),WhereNode:this.visitWhere.bind(this),InsertQueryNode:this.visitInsertQuery.bind(this),DeleteQueryNode:this.visitDeleteQuery.bind(this),ReturningNode:this.visitReturning.bind(this),CreateTableNode:this.visitCreateTable.bind(this),AddColumnNode:this.visitAddColumn.bind(this),ColumnDefinitionNode:this.visitColumnDefinition.bind(this),DropTableNode:this.visitDropTable.bind(this),DataTypeNode:this.visitDataType.bind(this),OrderByNode:this.visitOrderBy.bind(this),OrderByItemNode:this.visitOrderByItem.bind(this),GroupByNode:this.visitGroupBy.bind(this),GroupByItemNode:this.visitGroupByItem.bind(this),UpdateQueryNode:this.visitUpdateQuery.bind(this),ColumnUpdateNode:this.visitColumnUpdate.bind(this),LimitNode:this.visitLimit.bind(this),OffsetNode:this.visitOffset.bind(this),OnConflictNode:this.visitOnConflict.bind(this),OnDuplicateKeyNode:this.visitOnDuplicateKey.bind(this),CreateIndexNode:this.visitCreateIndex.bind(this),DropIndexNode:this.visitDropIndex.bind(this),ListNode:this.visitList.bind(this),PrimaryKeyConstraintNode:this.visitPrimaryKeyConstraint.bind(this),UniqueConstraintNode:this.visitUniqueConstraint.bind(this),ReferencesNode:this.visitReferences.bind(this),CheckConstraintNode:this.visitCheckConstraint.bind(this),WithNode:this.visitWith.bind(this),CommonTableExpressionNode:this.visitCommonTableExpression.bind(this),CommonTableExpressionNameNode:this.visitCommonTableExpressionName.bind(this),HavingNode:this.visitHaving.bind(this),CreateSchemaNode:this.visitCreateSchema.bind(this),DropSchemaNode:this.visitDropSchema.bind(this),AlterTableNode:this.visitAlterTable.bind(this),DropColumnNode:this.visitDropColumn.bind(this),RenameColumnNode:this.visitRenameColumn.bind(this),AlterColumnNode:this.visitAlterColumn.bind(this),ModifyColumnNode:this.visitModifyColumn.bind(this),AddConstraintNode:this.visitAddConstraint.bind(this),DropConstraintNode:this.visitDropConstraint.bind(this),RenameConstraintNode:this.visitRenameConstraint.bind(this),ForeignKeyConstraintNode:this.visitForeignKeyConstraint.bind(this),CreateViewNode:this.visitCreateView.bind(this),RefreshMaterializedViewNode:this.visitRefreshMaterializedView.bind(this),DropViewNode:this.visitDropView.bind(this),GeneratedNode:this.visitGenerated.bind(this),DefaultValueNode:this.visitDefaultValue.bind(this),OnNode:this.visitOn.bind(this),ValuesNode:this.visitValues.bind(this),SelectModifierNode:this.visitSelectModifier.bind(this),CreateTypeNode:this.visitCreateType.bind(this),DropTypeNode:this.visitDropType.bind(this),ExplainNode:this.visitExplain.bind(this),DefaultInsertValueNode:this.visitDefaultInsertValue.bind(this),AggregateFunctionNode:this.visitAggregateFunction.bind(this),OverNode:this.visitOver.bind(this),PartitionByNode:this.visitPartitionBy.bind(this),PartitionByItemNode:this.visitPartitionByItem.bind(this),SetOperationNode:this.visitSetOperation.bind(this),BinaryOperationNode:this.visitBinaryOperation.bind(this),UnaryOperationNode:this.visitUnaryOperation.bind(this),UsingNode:this.visitUsing.bind(this),FunctionNode:this.visitFunction.bind(this),CaseNode:this.visitCase.bind(this),WhenNode:this.visitWhen.bind(this),JSONReferenceNode:this.visitJSONReference.bind(this),JSONPathNode:this.visitJSONPath.bind(this),JSONPathLegNode:this.visitJSONPathLeg.bind(this),JSONOperatorChainNode:this.visitJSONOperatorChain.bind(this),TupleNode:this.visitTuple.bind(this),MergeQueryNode:this.visitMergeQuery.bind(this),MatchedNode:this.visitMatched.bind(this),AddIndexNode:this.visitAddIndex.bind(this),CastNode:this.visitCast.bind(this),FetchNode:this.visitFetch.bind(this),TopNode:this.visitTop.bind(this),OutputNode:this.visitOutput.bind(this),OrActionNode:this.visitOrAction.bind(this),CollateNode:this.visitCollate.bind(this)});visitNode=(e)=>{this.nodeStack.push(e),this.#e[e.kind](e),this.nodeStack.pop()}}var oi=/'/g,ni=/['"]/g;class ho extends St{#e="";#t=[];get numParameters(){return this.#t.length}compileQuery(e,t){return this.#e="",this.#t=[],this.nodeStack.splice(0,this.nodeStack.length),this.visitNode(e),C({query:e,queryId:t,sql:this.getSql(),parameters:[...this.#t]})}getSql(){return this.#e}visitSelectQuery(e){let t=this.parentNode!==void 0&&!E.is(this.parentNode)&&!u.is(this.parentNode)&&!fo.is(this.parentNode)&&!$s.is(this.parentNode)&&!Je.is(this.parentNode);if(this.parentNode===void 0&&e.explain)this.visitNode(e.explain),this.append(" ");if(t)this.append("(");if(e.with)this.visitNode(e.with),this.append(" ");if(this.append("select"),e.distinctOn)this.append(" "),this.compileDistinctOn(e.distinctOn);if(e.frontModifiers?.length)this.append(" "),this.compileList(e.frontModifiers," ");if(e.top)this.append(" "),this.visitNode(e.top);if(e.selections)this.append(" "),this.compileList(e.selections);if(e.from)this.append(" "),this.visitNode(e.from);if(e.joins)this.append(" "),this.compileList(e.joins," ");if(e.where)this.append(" "),this.visitNode(e.where);if(e.groupBy)this.append(" "),this.visitNode(e.groupBy);if(e.having)this.append(" "),this.visitNode(e.having);if(e.setOperations)this.append(" "),this.compileList(e.setOperations," ");if(e.orderBy)this.append(" "),this.visitNode(e.orderBy);if(e.limit)this.append(" "),this.visitNode(e.limit);if(e.offset)this.append(" "),this.visitNode(e.offset);if(e.fetch)this.append(" "),this.visitNode(e.fetch);if(e.endModifiers?.length)this.append(" "),this.compileList(this.sortSelectModifiers([...e.endModifiers])," ");if(t)this.append(")")}visitFrom(e){this.append("from "),this.compileList(e.froms)}visitSelection(e){this.visitNode(e.selection)}visitColumn(e){this.visitNode(e.column)}compileDistinctOn(e){this.append("distinct on ("),this.compileList(e),this.append(")")}compileList(e,t=", "){let r=e.length-1;for(let i=0;i<=r;i++)if(this.visitNode(e[i]),i<r)this.append(t)}visitWhere(e){this.append("where "),this.visitNode(e.where)}visitHaving(e){this.append("having "),this.visitNode(e.having)}visitInsertQuery(e){let t=this.parentNode!==void 0&&!E.is(this.parentNode)&&!tr.is(this.parentNode)&&!R.is(this.parentNode);if(this.parentNode===void 0&&e.explain)this.visitNode(e.explain),this.append(" ");if(t)this.append("(");if(e.with)this.visitNode(e.with),this.append(" ");if(this.append(e.replace?"replace":"insert"),e.ignore)hi("`InsertQueryNode.ignore` is deprecated. Use `InsertQueryNode.orAction` instead."),this.append(" ignore");if(e.orAction)this.append(" "),this.visitNode(e.orAction);if(e.top)this.append(" "),this.visitNode(e.top);if(e.into)this.append(" into "),this.visitNode(e.into);if(e.columns)this.append(" ("),this.compileList(e.columns),this.append(")");if(e.output)this.append(" "),this.visitNode(e.output);if(e.values)this.append(" "),this.visitNode(e.values);if(e.defaultValues)this.append(" "),this.append("default values");if(e.onConflict)this.append(" "),this.visitNode(e.onConflict);if(e.onDuplicateKey)this.append(" "),this.visitNode(e.onDuplicateKey);if(e.returning)this.append(" "),this.visitNode(e.returning);if(t)this.append(")");if(e.endModifiers?.length)this.append(" "),this.compileList(e.endModifiers," ")}visitValues(e){this.append("values "),this.compileList(e.values)}visitDeleteQuery(e){let t=this.parentNode!==void 0&&!E.is(this.parentNode)&&!tr.is(this.parentNode);if(this.parentNode===void 0&&e.explain)this.visitNode(e.explain),this.append(" ");if(t)this.append("(");if(e.with)this.visitNode(e.with),this.append(" ");if(this.append("delete "),e.top)this.visitNode(e.top),this.append(" ");if(this.visitNode(e.from),e.output)this.append(" "),this.visitNode(e.output);if(e.using)this.append(" "),this.visitNode(e.using);if(e.joins)this.append(" "),this.compileList(e.joins," ");if(e.where)this.append(" "),this.visitNode(e.where);if(e.orderBy)this.append(" "),this.visitNode(e.orderBy);if(e.limit)this.append(" "),this.visitNode(e.limit);if(e.returning)this.append(" "),this.visitNode(e.returning);if(t)this.append(")");if(e.endModifiers?.length)this.append(" "),this.compileList(e.endModifiers," ")}visitReturning(e){this.append("returning "),this.compileList(e.selections)}visitAlias(e){this.visitNode(e.node),this.append(" as "),this.visitNode(e.alias)}visitReference(e){if(e.table)this.visitNode(e.table),this.append(".");this.visitNode(e.column)}visitSelectAll(e){this.append("*")}visitIdentifier(e){this.append(this.getLeftIdentifierWrapper()),this.compileUnwrappedIdentifier(e),this.append(this.getRightIdentifierWrapper())}compileUnwrappedIdentifier(e){if(!dr(e.name))throw Error("a non-string identifier was passed to compileUnwrappedIdentifier.");this.append(this.sanitizeIdentifier(e.name))}visitAnd(e){this.visitNode(e.left),this.append(" and "),this.visitNode(e.right)}visitOr(e){this.visitNode(e.left),this.append(" or "),this.visitNode(e.right)}visitValue(e){if(e.immediate)this.appendImmediateValue(e.value);else this.appendValue(e.value)}visitValueList(e){this.append("("),this.compileList(e.values),this.append(")")}visitTuple(e){this.append("("),this.compileList(e.values),this.append(")")}visitPrimitiveValueList(e){this.append("(");let{values:t}=e;for(let r=0;r<t.length;++r)if(this.appendValue(t[r]),r!==t.length-1)this.append(", ");this.append(")")}visitParens(e){this.append("("),this.visitNode(e.node),this.append(")")}visitJoin(e){if(this.append(ai[e.joinType]),this.append(" "),this.visitNode(e.table),e.on)this.append(" "),this.visitNode(e.on)}visitOn(e){this.append("on "),this.visitNode(e.on)}visitRaw(e){let{sqlFragments:t,parameters:r}=e;for(let i=0;i<t.length;++i)if(this.append(t[i]),r.length>i)this.visitNode(r[i])}visitOperator(e){this.append(e.operator)}visitTable(e){this.visitNode(e.table)}visitSchemableIdentifier(e){if(e.schema)this.visitNode(e.schema),this.append(".");this.visitNode(e.identifier)}visitCreateTable(e){if(this.append("create "),e.frontModifiers?.length)this.compileList(e.frontModifiers," "),this.append(" ");if(e.temporary)this.append("temporary ");if(this.append("table "),e.ifNotExists)this.append("if not exists ");if(this.visitNode(e.table),!e.selectQuery)this.append(" ("),this.compileList([...e.columns,...e.constraints??[]]),this.append(")");if(e.onCommit)this.append(" on commit "),this.append(e.onCommit);if(e.endModifiers?.length)this.append(" "),this.compileList(e.endModifiers," ");if(e.selectQuery)this.append(" as "),this.visitNode(e.selectQuery)}visitColumnDefinition(e){if(e.ifNotExists)this.append("if not exists ");if(this.visitNode(e.column),this.append(" "),this.visitNode(e.dataType),e.unsigned)this.append(" unsigned");if(e.frontModifiers&&e.frontModifiers.length>0)this.append(" "),this.compileList(e.frontModifiers," ");if(e.generated)this.append(" "),this.visitNode(e.generated);if(e.identity)this.append(" identity");if(e.defaultTo)this.append(" "),this.visitNode(e.defaultTo);if(e.notNull)this.append(" not null");if(e.unique)this.append(" unique");if(e.nullsNotDistinct)this.append(" nulls not distinct");if(e.primaryKey)this.append(" primary key");if(e.autoIncrement)this.append(" "),this.append(this.getAutoIncrement());if(e.references)this.append(" "),this.visitNode(e.references);if(e.check)this.append(" "),this.visitNode(e.check);if(e.endModifiers&&e.endModifiers.length>0)this.append(" "),this.compileList(e.endModifiers," ")}getAutoIncrement(){return"auto_increment"}visitReferences(e){if(this.append("references "),this.visitNode(e.table),this.append(" ("),this.compileList(e.columns),this.append(")"),e.onDelete)this.append(" on delete "),this.append(e.onDelete);if(e.onUpdate)this.append(" on update "),this.append(e.onUpdate)}visitDropTable(e){if(this.append("drop table "),e.ifExists)this.append("if exists ");if(this.visitNode(e.table),e.cascade)this.append(" cascade")}visitDataType(e){this.append(e.dataType)}visitOrderBy(e){this.append("order by "),this.compileList(e.items)}visitOrderByItem(e){if(this.visitNode(e.orderBy),e.collation)this.append(" "),this.visitNode(e.collation);if(e.direction)this.append(" "),this.visitNode(e.direction);if(e.nulls)this.append(" nulls "),this.append(e.nulls)}visitGroupBy(e){this.append("group by "),this.compileList(e.items)}visitGroupByItem(e){this.visitNode(e.groupBy)}visitUpdateQuery(e){let t=this.parentNode!==void 0&&!E.is(this.parentNode)&&!tr.is(this.parentNode)&&!R.is(this.parentNode);if(this.parentNode===void 0&&e.explain)this.visitNode(e.explain),this.append(" ");if(t)this.append("(");if(e.with)this.visitNode(e.with),this.append(" ");if(this.append("update "),e.top)this.visitNode(e.top),this.append(" ");if(e.table)this.visitNode(e.table),this.append(" ");if(this.append("set "),e.updates)this.compileList(e.updates);if(e.output)this.append(" "),this.visitNode(e.output);if(e.from)this.append(" "),this.visitNode(e.from);if(e.joins){if(!e.from)throw Error("Joins in an update query are only supported as a part of a PostgreSQL 'update set from join' query. If you want to create a MySQL 'update join set' query, see https://kysely.dev/docs/examples/update/my-sql-joins");this.append(" "),this.compileList(e.joins," ")}if(e.where)this.append(" "),this.visitNode(e.where);if(e.returning)this.append(" "),this.visitNode(e.returning);if(e.orderBy)this.append(" "),this.visitNode(e.orderBy);if(e.limit)this.append(" "),this.visitNode(e.limit);if(t)this.append(")");if(e.endModifiers?.length)this.append(" "),this.compileList(e.endModifiers," ")}visitColumnUpdate(e){this.visitNode(e.column),this.append(" = "),this.visitNode(e.value)}visitLimit(e){this.append("limit "),this.visitNode(e.limit)}visitOffset(e){this.append("offset "),this.visitNode(e.offset)}visitOnConflict(e){if(this.append("on conflict"),e.columns)this.append(" ("),this.compileList(e.columns),this.append(")");else if(e.constraint)this.append(" on constraint "),this.visitNode(e.constraint);else if(e.indexExpression)this.append(" ("),this.visitNode(e.indexExpression),this.append(")");if(e.indexWhere)this.append(" "),this.visitNode(e.indexWhere);if(e.doNothing===!0)this.append(" do nothing");else if(e.updates){if(this.append(" do update set "),this.compileList(e.updates),e.updateWhere)this.append(" "),this.visitNode(e.updateWhere)}}visitOnDuplicateKey(e){this.append("on duplicate key update "),this.compileList(e.updates)}visitCreateIndex(e){if(this.append("create "),e.unique)this.append("unique ");if(this.append("index "),e.ifNotExists)this.append("if not exists ");if(this.visitNode(e.name),e.table)this.append(" on "),this.visitNode(e.table);if(e.using)this.append(" using "),this.visitNode(e.using);if(e.columns)this.append(" ("),this.compileList(e.columns),this.append(")");if(e.nullsNotDistinct)this.append(" nulls not distinct");if(e.where)this.append(" "),this.visitNode(e.where)}visitDropIndex(e){if(this.append("drop index "),e.ifExists)this.append("if exists ");if(this.visitNode(e.name),e.table)this.append(" on "),this.visitNode(e.table);if(e.cascade)this.append(" cascade")}visitCreateSchema(e){if(this.append("create schema "),e.ifNotExists)this.append("if not exists ");this.visitNode(e.schema)}visitDropSchema(e){if(this.append("drop schema "),e.ifExists)this.append("if exists ");if(this.visitNode(e.schema),e.cascade)this.append(" cascade")}visitPrimaryKeyConstraint(e){if(e.name)this.append("constraint "),this.visitNode(e.name),this.append(" ");this.append("primary key ("),this.compileList(e.columns),this.append(")"),this.buildDeferrable(e)}buildDeferrable(e){if(e.deferrable!==void 0)if(e.deferrable)this.append(" deferrable");else this.append(" not deferrable");if(e.initiallyDeferred!==void 0)if(e.initiallyDeferred)this.append(" initially deferred");else this.append(" initially immediate")}visitUniqueConstraint(e){if(e.name)this.append("constraint "),this.visitNode(e.name),this.append(" ");if(this.append("unique"),e.nullsNotDistinct)this.append(" nulls not distinct");this.append(" ("),this.compileList(e.columns),this.append(")"),this.buildDeferrable(e)}visitCheckConstraint(e){if(e.name)this.append("constraint "),this.visitNode(e.name),this.append(" ");this.append("check ("),this.visitNode(e.expression),this.append(")")}visitForeignKeyConstraint(e){if(e.name)this.append("constraint "),this.visitNode(e.name),this.append(" ");if(this.append("foreign key ("),this.compileList(e.columns),this.append(") "),this.visitNode(e.references),e.onDelete)this.append(" on delete "),this.append(e.onDelete);if(e.onUpdate)this.append(" on update "),this.append(e.onUpdate);this.buildDeferrable(e)}visitList(e){this.compileList(e.items)}visitWith(e){if(this.append("with "),e.recursive)this.append("recursive ");this.compileList(e.expressions)}visitCommonTableExpression(e){if(this.visitNode(e.name),this.append(" as "),Vi(e.materialized)){if(!e.materialized)this.append("not ");this.append("materialized ")}this.visitNode(e.expression)}visitCommonTableExpressionName(e){if(this.visitNode(e.table),e.columns)this.append("("),this.compileList(e.columns),this.append(")")}visitAlterTable(e){if(this.append("alter table "),this.visitNode(e.table),this.append(" "),e.renameTo)this.append("rename to "),this.visitNode(e.renameTo);if(e.setSchema)this.append("set schema "),this.visitNode(e.setSchema);if(e.addConstraint)this.visitNode(e.addConstraint);if(e.dropConstraint)this.visitNode(e.dropConstraint);if(e.renameConstraint)this.visitNode(e.renameConstraint);if(e.columnAlterations)this.compileColumnAlterations(e.columnAlterations);if(e.addIndex)this.visitNode(e.addIndex);if(e.dropIndex)this.visitNode(e.dropIndex)}visitAddColumn(e){this.append("add column "),this.visitNode(e.column)}visitRenameColumn(e){this.append("rename column "),this.visitNode(e.column),this.append(" to "),this.visitNode(e.renameTo)}visitDropColumn(e){this.append("drop column "),this.visitNode(e.column)}visitAlterColumn(e){if(this.append("alter column "),this.visitNode(e.column),this.append(" "),e.dataType){if(this.announcesNewColumnDataType())this.append("type ");if(this.visitNode(e.dataType),e.dataTypeExpression)this.append("using "),this.visitNode(e.dataTypeExpression)}if(e.setDefault)this.append("set default "),this.visitNode(e.setDefault);if(e.dropDefault)this.append("drop default");if(e.setNotNull)this.append("set not null");if(e.dropNotNull)this.append("drop not null")}visitModifyColumn(e){this.append("modify column "),this.visitNode(e.column)}visitAddConstraint(e){this.append("add "),this.visitNode(e.constraint)}visitDropConstraint(e){if(this.append("drop constraint "),e.ifExists)this.append("if exists ");if(this.visitNode(e.constraintName),e.modifier==="cascade")this.append(" cascade");else if(e.modifier==="restrict")this.append(" restrict")}visitRenameConstraint(e){this.append("rename constraint "),this.visitNode(e.oldName),this.append(" to "),this.visitNode(e.newName)}visitSetOperation(e){if(this.append(e.operator),this.append(" "),e.all)this.append("all ");this.visitNode(e.expression)}visitCreateView(e){if(this.append("create "),e.orReplace)this.append("or replace ");if(e.materialized)this.append("materialized ");if(e.temporary)this.append("temporary ");if(this.append("view "),e.ifNotExists)this.append("if not exists ");if(this.visitNode(e.name),this.append(" "),e.columns)this.append("("),this.compileList(e.columns),this.append(") ");if(e.as)this.append("as "),this.visitNode(e.as)}visitRefreshMaterializedView(e){if(this.append("refresh materialized view "),e.concurrently)this.append("concurrently ");if(this.visitNode(e.name),e.withNoData)this.append(" with no data");else this.append(" with data")}visitDropView(e){if(this.append("drop "),e.materialized)this.append("materialized ");if(this.append("view "),e.ifExists)this.append("if exists ");if(this.visitNode(e.name),e.cascade)this.append(" cascade")}visitGenerated(e){if(this.append("generated "),e.always)this.append("always ");if(e.byDefault)this.append("by default ");if(this.append("as "),e.identity)this.append("identity");if(e.expression)this.append("("),this.visitNode(e.expression),this.append(")");if(e.stored)this.append(" stored")}visitDefaultValue(e){this.append("default "),this.visitNode(e.defaultValue)}visitSelectModifier(e){if(e.rawModifier)this.visitNode(e.rawModifier);else this.append(si[e.modifier]);if(e.of)this.append(" of "),this.compileList(e.of,", ")}visitCreateType(e){if(this.append("create type "),this.visitNode(e.name),e.enum)this.append(" as enum "),this.visitNode(e.enum)}visitDropType(e){if(this.append("drop type "),e.ifExists)this.append("if exists ");this.visitNode(e.name)}visitExplain(e){if(this.append("explain"),e.options||e.format){if(this.append(" "),this.append(this.getLeftExplainOptionsWrapper()),e.options){if(this.visitNode(e.options),e.format)this.append(this.getExplainOptionsDelimiter())}if(e.format)this.append("format"),this.append(this.getExplainOptionAssignment()),this.append(e.format);this.append(this.getRightExplainOptionsWrapper())}}visitDefaultInsertValue(e){this.append("default")}visitAggregateFunction(e){if(this.append(e.func),this.append("("),e.distinct)this.append("distinct ");if(this.compileList(e.aggregated),e.orderBy)this.append(" "),this.visitNode(e.orderBy);if(this.append(")"),e.withinGroup)this.append(" within group ("),this.visitNode(e.withinGroup),this.append(")");if(e.filter)this.append(" filter("),this.visitNode(e.filter),this.append(")");if(e.over)this.append(" "),this.visitNode(e.over)}visitOver(e){if(this.append("over("),e.partitionBy){if(this.visitNode(e.partitionBy),e.orderBy)this.append(" ")}if(e.orderBy)this.visitNode(e.orderBy);this.append(")")}visitPartitionBy(e){this.append("partition by "),this.compileList(e.items)}visitPartitionByItem(e){this.visitNode(e.partitionBy)}visitBinaryOperation(e){this.visitNode(e.leftOperand),this.append(" "),this.visitNode(e.operator),this.append(" "),this.visitNode(e.rightOperand)}visitUnaryOperation(e){if(this.visitNode(e.operator),!this.isMinusOperator(e.operator))this.append(" ");this.visitNode(e.operand)}isMinusOperator(e){return S.is(e)&&e.operator==="-"}visitUsing(e){this.append("using "),this.compileList(e.tables)}visitFunction(e){this.append(e.func),this.append("("),this.compileList(e.arguments),this.append(")")}visitCase(e){if(this.append("case"),e.value)this.append(" "),this.visitNode(e.value);if(e.when)this.append(" "),this.compileList(e.when," ");if(e.else)this.append(" else "),this.visitNode(e.else);if(this.append(" end"),e.isStatement)this.append(" case")}visitWhen(e){if(this.append("when "),this.visitNode(e.condition),e.result)this.append(" then "),this.visitNode(e.result)}visitJSONReference(e){this.visitNode(e.reference),this.visitNode(e.traversal)}visitJSONPath(e){if(e.inOperator)this.visitNode(e.inOperator);this.append("'$");for(let t of e.pathLegs)this.visitNode(t);this.append("'")}visitJSONPathLeg(e){let t=e.type==="ArrayLocation",r=String(e.value);if(t)this.append("["),this.append(this.sanitizeStringLiteral(r)),this.append("]");else this.append('."'),this.append(this.sanitizeJSONPathMemberValue(r)),this.append('"')}visitJSONOperatorChain(e){for(let t=0,r=e.values.length;t<r;t++){if(t===r-1)this.visitNode(e.operator);else this.append("->");this.visitNode(e.values[t])}}visitMergeQuery(e){if(e.with)this.visitNode(e.with),this.append(" ");if(this.append("merge "),e.top)this.visitNode(e.top),this.append(" ");if(this.append("into "),this.visitNode(e.into),e.using)this.append(" "),this.visitNode(e.using);if(e.whens)this.append(" "),this.compileList(e.whens," ");if(e.returning)this.append(" "),this.visitNode(e.returning);if(e.output)this.append(" "),this.visitNode(e.output);if(e.endModifiers?.length)this.append(" "),this.compileList(e.endModifiers," ")}visitMatched(e){if(e.not)this.append("not ");if(this.append("matched"),e.bySource)this.append(" by source")}visitAddIndex(e){if(this.append("add "),e.unique)this.append("unique ");if(this.append("index "),this.visitNode(e.name),e.columns)this.append(" ("),this.compileList(e.columns),this.append(")");if(e.using)this.append(" using "),this.visitNode(e.using)}visitCast(e){this.append("cast("),this.visitNode(e.expression),this.append(" as "),this.visitNode(e.dataType),this.append(")")}visitFetch(e){this.append("fetch next "),this.visitNode(e.rowCount),this.append(` rows ${e.modifier}`)}visitOutput(e){this.append("output "),this.compileList(e.selections)}visitTop(e){if(this.append(`top(${e.expression})`),e.modifiers)this.append(` ${e.modifiers}`)}visitOrAction(e){this.append(e.action)}visitCollate(e){this.append("collate "),this.visitNode(e.collation)}append(e){this.#e+=e}appendValue(e){this.addParameter(e),this.append(this.getCurrentParameterPlaceholder())}getLeftIdentifierWrapper(){return'"'}getRightIdentifierWrapper(){return'"'}getCurrentParameterPlaceholder(){return"$"+this.numParameters}getLeftExplainOptionsWrapper(){return"("}getExplainOptionAssignment(){return" "}getExplainOptionsDelimiter(){return", "}getRightExplainOptionsWrapper(){return")"}sanitizeIdentifier(e){let t=this.getLeftIdentifierWrapper(),r=this.getRightIdentifierWrapper(),i="";for(let n of e)if(i+=n,n===t)i+=t;else if(n===r)i+=r;return i}sanitizeStringLiteral(e){return e.replace(oi,"''")}sanitizeJSONPathMemberValue(e){return e.replace(ni,(t)=>t==="'"?"''":"\\\"")}addParameter(e){this.#t.push(e)}appendImmediateValue(e){if(dr(e))this.appendStringLiteral(e);else if(zs(e)||Vi(e)||La(e))this.append(e.toString());else if(Fa(e))this.append("null");else if(rf(e))this.appendImmediateValue(e.toISOString());else throw Error(`invalid immediate value ${e}`)}appendStringLiteral(e){this.append("'"),this.append(this.sanitizeStringLiteral(e)),this.append("'")}sortSelectModifiers(e){return e.sort((t,r)=>t.modifier&&r.modifier?Ar[t.modifier]-Ar[r.modifier]:1),C(e)}compileColumnAlterations(e){this.compileList(e)}announcesNewColumnDataType(){return!0}}var si=C({ForKeyShare:"for key share",ForNoKeyUpdate:"for no key update",ForUpdate:"for update",ForShare:"for share",NoWait:"nowait",SkipLocked:"skip locked",Distinct:"distinct"}),Ar=C({ForKeyShare:1,ForNoKeyUpdate:1,ForUpdate:1,ForShare:1,NoWait:2,SkipLocked:2,Distinct:0}),ai=C({InnerJoin:"inner join",LeftJoin:"left join",RightJoin:"right join",FullJoin:"full join",CrossJoin:"cross join",LateralInnerJoin:"inner join lateral",LateralLeftJoin:"left join lateral",LateralCrossJoin:"cross join lateral",OuterApply:"outer apply",CrossApply:"cross apply",Using:"using"});var gm="kysely_migration",Am="kysely_migration_lock";function _m(e){let t=e.filter((i)=>i.pk>0),r=t.length===1?t[0]:void 0;return r?.type.toLowerCase()==="integer"?r.name:void 0}async function Tr(e,t,r){let i=_m(r);if(!i)return;let{rows:n}=await je`
2
+ function So(e){return typeof e>"u"||e===void 0}function fr(e){return typeof e==="string"}function zs(e){return typeof e==="number"}function Vi(e){return typeof e==="boolean"}function La(e){return e===null}function nf(e){return e instanceof Date}function Za(e){return typeof e==="bigint"}function qg(e){return typeof Buffer<"u"&&Buffer.isBuffer(e)}function pr(e){return typeof e==="function"}function sn(e){return typeof e==="object"&&e!==null}function C(e){return Object.freeze(e)}function xe(e){if(x(e))return e;else return[e]}function x(e){return Array.isArray(e)}function Io(e){return e}var st=C({is(e){return e.kind==="IdentifierNode"},create(e){return C({kind:"IdentifierNode",name:e})}});var $g=["preserve rows","delete rows","drop"],fo=C({is(e){return e.kind==="CreateTableNode"},create(e){return C({kind:"CreateTableNode",table:e,columns:C([])})},cloneWithColumn(e,t){return C({...e,columns:C([...e.columns,t])})},cloneWithConstraint(e,t){return C({...e,constraints:e.constraints?C([...e.constraints,t]):C([t])})},cloneWithFrontModifier(e,t){return C({...e,frontModifiers:e.frontModifiers?C([...e.frontModifiers,t]):C([t])})},cloneWithEndModifier(e,t){return C({...e,endModifiers:e.endModifiers?C([...e.endModifiers,t]):C([t])})},cloneWith(e,t){return C({...e,...t})}});var po=C({is(e){return e.kind==="SchemableIdentifierNode"},create(e){return C({kind:"SchemableIdentifierNode",identifier:st.create(e)})},createWithSchema(e,t){return C({kind:"SchemableIdentifierNode",schema:st.create(e),identifier:st.create(t)})}});var l=C({is(e){return e.kind==="AliasNode"},create(e,t){return C({kind:"AliasNode",node:e,alias:t})}});var mo=C({is(e){return e.kind==="TableNode"},create(e){return C({kind:"TableNode",table:po.create(e)})},createWithSchema(e,t){return C({kind:"TableNode",table:po.createWithSchema(e,t)})}});function Rr(e){return sn(e)&&pr(e.toOperationNode)}function Le(e){return sn(e)&&"expressionType"in e&&Rr(e)}function Ct(e){return sn(e)&&"expression"in e&&fr(e.alias)&&Rr(e)}var I=C({is(e){return e.kind==="SelectModifierNode"},create(e,t){return C({kind:"SelectModifierNode",modifier:e,of:t})},createWithExpression(e){return C({kind:"SelectModifierNode",rawModifier:e})}});var v=C({is(e){return e.kind==="AndNode"},create(e,t){return C({kind:"AndNode",left:e,right:t})}});var T=C({is(e){return e.kind==="OrNode"},create(e,t){return C({kind:"OrNode",left:e,right:t})}});var De=C({is(e){return e.kind==="OnNode"},create(e){return C({kind:"OnNode",on:e})},cloneWithOperation(e,t,r){return C({...e,on:t==="And"?v.create(e.on,r):T.create(e.on,r)})}});var L=C({is(e){return e.kind==="JoinNode"},create(e,t){return C({kind:"JoinNode",joinType:e,table:t,on:void 0})},createWithOn(e,t,r){return C({kind:"JoinNode",joinType:e,table:t,on:De.create(r)})},cloneWithOn(e,t){return C({...e,on:e.on?De.cloneWithOperation(e.on,"And",t):De.create(t)})}});var X=C({is(e){return e.kind==="BinaryOperationNode"},create(e,t,r){return C({kind:"BinaryOperationNode",leftOperand:e,operator:t,rightOperand:r})}});var Lr=["=","==","!=","<>",">",">=","<","<=","in","not in","is","is not","like","not like","match","ilike","not ilike","@>","<@","^@","&&","?","?&","?|","!<","!>","<=>","!~","~","~*","!~*","@@","@@@","!!","<->","regexp","is distinct from","is not distinct from"],Dr=["+","-","*","/","%","^","&","|","#","<<",">>"],kt=["->","->>"],Br=[...Lr,...Dr,"&&","||"],qr=["exists","not exists"],Mr=["not","-",...qr],Et=[...Br,...kt,...Mr,"between","between symmetric"],S=C({is(e){return e.kind==="OperatorNode"},create(e){return C({kind:"OperatorNode",operator:e})}});function Ke(e){return fr(e)&&kt.includes(e)}var Wt=C({is(e){return e.kind==="ColumnNode"},create(e){return C({kind:"ColumnNode",column:st.create(e)})}});var fc=C({is(e){return e.kind==="SelectAllNode"},create(){return C({kind:"SelectAllNode"})}});var Ba=C({is(e){return e.kind==="ReferenceNode"},create(e,t){return C({kind:"ReferenceNode",table:t,column:e})},createSelectAll(e){return C({kind:"ReferenceNode",table:e,column:fc.create()})}});class hm{#e;get dynamicReference(){return this.#e}get refType(){return}constructor(e){this.#e=e}toOperationNode(){return He(this.#e)}}function Be(e){return sn(e)&&Rr(e)&&fr(e.dynamicReference)}var D=C({is(e){return e.kind==="OrderByItemNode"},create(e,t){return C({kind:"OrderByItemNode",orderBy:e,direction:t})},cloneWith(e,t){return C({...e,...t})}});var rr=C({is(e){return e.kind==="RawNode"},create(e,t){return C({kind:"RawNode",sqlFragments:C(e),parameters:C(t)})},createWithSql(e){return rr.create([e],[])},createWithChild(e){return rr.create(["",""],[e])},createWithChildren(e){return rr.create(Array(e.length+1).fill(""),e)}});var At=C({is(e){return e.kind==="CollateNode"},create(e){return C({kind:"CollateNode",collation:st.create(e)})}});class Z{#e;constructor(e){this.#e=C(e)}desc(){return new Z({node:D.cloneWith(this.#e.node,{direction:rr.createWithSql("desc")})})}asc(){return new Z({node:D.cloneWith(this.#e.node,{direction:rr.createWithSql("asc")})})}nullsLast(){return new Z({node:D.cloneWith(this.#e.node,{nulls:"last"})})}nullsFirst(){return new Z({node:D.cloneWith(this.#e.node,{nulls:"first"})})}collate(e){return new Z({node:D.cloneWith(this.#e.node,{collation:At.create(e)})})}toOperationNode(){return this.#e.node}}var Rt=new Set;function hi(e){if(Rt.has(e))return;Rt.add(e),console.log(e)}function Xe(e){return e==="asc"||e==="desc"}function k(e){if(e.length===2)return[Ye(e[0],e[1])];if(e.length===1){let[t]=e;if(Array.isArray(t))return hi("orderBy(array) is deprecated, use multiple orderBy calls instead."),t.map((r)=>Ye(r));return[Ye(t)]}throw Error(`Invalid number of arguments at order by! expected 1-2, received ${e.length}`)}function Ye(e,t){let r=Pr(e);if(D.is(r)){if(t)throw Error("Cannot specify direction twice!");return r}return Tt(r,t)}function Pr(e){if(J(e))return Ho(e);if(Be(e))return e.toOperationNode();let[t,r]=e.split(" ");if(r)return hi("`orderBy('column asc')` is deprecated. Use `orderBy('column', 'asc')` instead."),Tt(is(t),r);return is(e)}function Tt(e,t){if(typeof t==="string"){if(!Xe(t))throw Error(`Invalid order by direction: ${t}`);return D.create(e,rr.createWithSql(t))}if(Le(t))return hi("`orderBy(..., expr)` is deprecated. Use `orderBy(..., 'asc')` or `orderBy(..., (ob) => ...)` instead."),D.create(e,t.toOperationNode());let r=D.create(e);if(!t)return r;return t(new Z({node:r})).toOperationNode()}var pe=C({is(e){return e.kind==="JSONReferenceNode"},create(e,t){return C({kind:"JSONReferenceNode",reference:e,traversal:t})},cloneWithTraversal(e,t){return C({...e,traversal:t})}});var qe=C({is(e){return e.kind==="JSONOperatorChainNode"},create(e){return C({kind:"JSONOperatorChainNode",operator:e,values:C([])})},cloneWithValue(e,t){return C({...e,values:C([...e.values,t])})}});var ee=C({is(e){return e.kind==="JSONPathNode"},create(e){return C({kind:"JSONPathNode",inOperator:e,pathLegs:C([])})},cloneWithLeg(e,t){return C({...e,pathLegs:C([...e.pathLegs,t])})}});function He(e){if(fr(e))return is(e);return e.toOperationNode()}function Q(e){if(x(e))return e.map((t)=>w(t));else return[w(e)]}function w(e){if(J(e))return Ho(e);return He(e)}function Lt(e,t){let r=is(e);if(Ke(t))return pe.create(r,qe.create(S.create(t)));let i=t.slice(0,-1);if(Ke(i))return pe.create(r,ee.create(S.create(i)));throw Error(`Invalid JSON operator: ${t}`)}function is(e){if(!e.includes("."))return Ba.create(Wt.create(e));let r=e.split(".").map(Ze);if(r.length===3)return Ir(r);if(r.length===2)return Fr(r);throw Error(`invalid column reference ${e}`)}function Dt(e){if(e.includes(" as ")){let[r,i]=e.split(" as ").map(Ze);return l.create(is(r),st.create(i))}else return is(e)}function gm(e){return Wt.create(e)}function pc(e){if(e.includes(" ")){let[r,i]=e.split(" ").map(Ze);if(!Xe(i))throw Error(`invalid order direction "${i}" next to "${r}"`);return k([r,i])[0]}else return gm(e)}function Ir(e){let[t,r,i]=e;return Ba.create(Wt.create(i),mo.createWithSchema(t,r))}function Fr(e){let[t,r]=e;return Ba.create(Wt.create(r),mo.create(t))}function Ze(e){return e.trim()}var Me=C({is(e){return e.kind==="PrimitiveValueListNode"},create(e){return C({kind:"PrimitiveValueListNode",values:C([...e])})}});var Ua=C({is(e){return e.kind==="ValueListNode"},create(e){return C({kind:"ValueListNode",values:C(e)})}});var yn=C({is(e){return e.kind==="ValueNode"},create(e){return C({kind:"ValueNode",value:e})},createImmediate(e){return C({kind:"ValueNode",value:e,immediate:!0})}});function Bt(e){if(x(e))return Vr(e);return d(e)}function d(e){if(J(e))return Ho(e);return yn.create(e)}function Pe(e){return zs(e)||Vi(e)||La(e)}function ge(e){if(!Pe(e))throw Error(`unsafe immediate value ${JSON.stringify(e)}`);return yn.createImmediate(e)}function Vr(e){if(e.some(J))return Ua.create(e.map((t)=>d(t)));return Me.create(e)}var E=C({is(e){return e.kind==="ParensNode"},create(e){return C({kind:"ParensNode",node:e})}});function yr(e){if(e.length===3)return Ie(e[0],e[1],e[2]);else if(e.length===1)return d(e[0]);throw Error(`invalid arguments: ${JSON.stringify(e)}`)}function Ie(e,t,r){if(Ur(t)&&Mt(r))return X.create(w(e),et(t),yn.createImmediate(r));return X.create(w(e),et(t),Bt(r))}function N(e,t,r){return X.create(w(e),et(t),w(r))}function tt(e,t){return de(Object.entries(e).filter(([,r])=>!So(r)).map(([r,i])=>Ie(r,Mt(i)?"is":"=",i)),t)}function de(e,t,r=!0){let i=t==="and"?v.create:T.create;if(e.length===0)return X.create(yn.createImmediate(1),S.create("="),yn.createImmediate(t==="and"?1:0));let n=qt(e[0]);for(let a=1;a<e.length;++a)n=i(n,qt(e[a]));if(e.length>1&&r)return E.create(n);return n}function Ur(e){return e==="is"||e==="is not"}function Mt(e){return La(e)||Vi(e)}function et(e){if(fr(e)&&Et.includes(e))return S.create(e);if(Rr(e))return e.toOperationNode();throw Error(`invalid operator ${JSON.stringify(e)}`)}function qt(e){return Rr(e)?e.toOperationNode():e}var _=C({is(e){return e.kind==="OrderByNode"},create(e){return C({kind:"OrderByNode",items:C([...e])})},cloneWithItems(e,t){return C({...e,items:C([...e.items,...t])})}});var rt=C({is(e){return e.kind==="PartitionByNode"},create(e){return C({kind:"PartitionByNode",items:C(e)})},cloneWithItems(e,t){return C({...e,items:C([...e.items,...t])})}});var ve=C({is(e){return e.kind==="OverNode"},create(){return C({kind:"OverNode"})},cloneWithOrderByItems(e,t){return C({...e,orderBy:e.orderBy?_.cloneWithItems(e.orderBy,t):_.create(t)})},cloneWithPartitionByItems(e,t){return C({...e,partitionBy:e.partitionBy?rt.cloneWithItems(e.partitionBy,t):rt.create(t)})}});var oe=C({is(e){return e.kind==="FromNode"},create(e){return C({kind:"FromNode",froms:C(e)})},cloneWithFroms(e,t){return C({...e,froms:C([...e.froms,...t])})}});var it=C({is(e){return e.kind==="GroupByNode"},create(e){return C({kind:"GroupByNode",items:C(e)})},cloneWithItems(e,t){return C({...e,items:C([...e.items,...t])})}});var ot=C({is(e){return e.kind==="HavingNode"},create(e){return C({kind:"HavingNode",having:e})},cloneWithOperation(e,t,r){return C({...e,having:t==="And"?v.create(e.having,r):T.create(e.having,r)})}});var u=C({is(e){return e.kind==="InsertQueryNode"},create(e,t,r){return C({kind:"InsertQueryNode",into:e,...t&&{with:t},replace:r})},createWithoutInto(){return C({kind:"InsertQueryNode"})},cloneWith(e,t){return C({...e,...t})}});var Fe=C({is(e){return e.kind==="ListNode"},create(e){return C({kind:"ListNode",items:C(e)})}});var F=C({is(e){return e.kind==="UpdateQueryNode"},create(e,t){return C({kind:"UpdateQueryNode",table:e.length===1?e[0]:Fe.create(e),...t&&{with:t}})},createWithoutTable(){return C({kind:"UpdateQueryNode"})},cloneWithFromItems(e,t){return C({...e,from:e.from?oe.cloneWithFroms(e.from,t):oe.create(t)})},cloneWithUpdates(e,t){return C({...e,updates:e.updates?C([...e.updates,...t]):t})},cloneWithLimit(e,t){return C({...e,limit:t})}});var be=C({is(e){return e.kind==="UsingNode"},create(e){return C({kind:"UsingNode",tables:C(e)})},cloneWithTables(e,t){return C({...e,tables:C([...e.tables,...t])})}});var te=C({is(e){return e.kind==="DeleteQueryNode"},create(e,t){return C({kind:"DeleteQueryNode",from:oe.create(e),...t&&{with:t}})},cloneWithOrderByItems:(e,t)=>Oe.cloneWithOrderByItems(e,t),cloneWithoutOrderBy:(e)=>Oe.cloneWithoutOrderBy(e),cloneWithLimit(e,t){return C({...e,limit:t})},cloneWithoutLimit(e){return C({...e,limit:void 0})},cloneWithUsing(e,t){return C({...e,using:e.using!==void 0?be.cloneWithTables(e.using,t):be.create(t)})}});var O=C({is(e){return e.kind==="WhereNode"},create(e){return C({kind:"WhereNode",where:e})},cloneWithOperation(e,t,r){return C({...e,where:t==="And"?v.create(e.where,r):T.create(e.where,r)})}});var nt=C({is(e){return e.kind==="ReturningNode"},create(e){return C({kind:"ReturningNode",selections:C(e)})},cloneWithSelections(e,t){return C({...e,selections:e.selections?C([...e.selections,...t]):C(t)})}});var Pt=C({is(e){return e.kind==="ExplainNode"},create(e,t){return C({kind:"ExplainNode",format:e,options:t})}});var R=C({is(e){return e.kind==="WhenNode"},create(e){return C({kind:"WhenNode",condition:e})},cloneWithResult(e,t){return C({...e,result:t})}});var A=C({is(e){return e.kind==="MergeQueryNode"},create(e,t){return C({kind:"MergeQueryNode",into:e,...t&&{with:t}})},cloneWithUsing(e,t){return C({...e,using:t})},cloneWithWhen(e,t){return C({...e,whens:e.whens?C([...e.whens,t]):C([t])})},cloneWithThen(e,t){return C({...e,whens:e.whens?C([...e.whens.slice(0,-1),R.cloneWithResult(e.whens[e.whens.length-1],t)]):void 0})}});var at=C({is(e){return e.kind==="OutputNode"},create(e){return C({kind:"OutputNode",selections:C(e)})},cloneWithSelections(e,t){return C({...e,selections:e.selections?C([...e.selections,...t]):C(t)})}});var Oe=C({is(e){return or.is(e)||u.is(e)||F.is(e)||te.is(e)||A.is(e)},cloneWithEndModifier(e,t){return C({...e,endModifiers:e.endModifiers?C([...e.endModifiers,t]):C([t])})},cloneWithWhere(e,t){return C({...e,where:e.where?O.cloneWithOperation(e.where,"And",t):O.create(t)})},cloneWithJoin(e,t){return C({...e,joins:e.joins?C([...e.joins,t]):C([t])})},cloneWithReturning(e,t){return C({...e,returning:e.returning?nt.cloneWithSelections(e.returning,t):nt.create(t)})},cloneWithoutReturning(e){return C({...e,returning:void 0})},cloneWithoutWhere(e){return C({...e,where:void 0})},cloneWithExplain(e,t,r){return C({...e,explain:Pt.create(t,r?.toOperationNode())})},cloneWithTop(e,t){return C({...e,top:t})},cloneWithOutput(e,t){return C({...e,output:e.output?at.cloneWithSelections(e.output,t):at.create(t)})},cloneWithOrderByItems(e,t){return C({...e,orderBy:e.orderBy?_.cloneWithItems(e.orderBy,t):_.create(t)})},cloneWithoutOrderBy(e){return C({...e,orderBy:void 0})}});var or=C({is(e){return e.kind==="SelectQueryNode"},create(e){return C({kind:"SelectQueryNode",...e&&{with:e}})},createFrom(e,t){return C({kind:"SelectQueryNode",from:oe.create(e),...t&&{with:t}})},cloneWithSelections(e,t){return C({...e,selections:e.selections?C([...e.selections,...t]):C(t)})},cloneWithDistinctOn(e,t){return C({...e,distinctOn:e.distinctOn?C([...e.distinctOn,...t]):C(t)})},cloneWithFrontModifier(e,t){return C({...e,frontModifiers:e.frontModifiers?C([...e.frontModifiers,t]):C([t])})},cloneWithOrderByItems:(e,t)=>Oe.cloneWithOrderByItems(e,t),cloneWithGroupByItems(e,t){return C({...e,groupBy:e.groupBy?it.cloneWithItems(e.groupBy,t):it.create(t)})},cloneWithLimit(e,t){return C({...e,limit:t})},cloneWithOffset(e,t){return C({...e,offset:t})},cloneWithFetch(e,t){return C({...e,fetch:t})},cloneWithHaving(e,t){return C({...e,having:e.having?ot.cloneWithOperation(e.having,"And",t):ot.create(t)})},cloneWithSetOperations(e,t){return C({...e,setOperations:e.setOperations?C([...e.setOperations,...t]):C([...t])})},cloneWithoutSelections(e){return C({...e,selections:[]})},cloneWithoutLimit(e){return C({...e,limit:void 0})},cloneWithoutOffset(e){return C({...e,offset:void 0})},cloneWithoutOrderBy:(e)=>Oe.cloneWithoutOrderBy(e),cloneWithoutGroupBy(e){return C({...e,groupBy:void 0})}});class he{#e;constructor(e){this.#e=C(e)}on(...e){return new he({...this.#e,joinNode:L.cloneWithOn(this.#e.joinNode,yr(e))})}onRef(e,t,r){return new he({...this.#e,joinNode:L.cloneWithOn(this.#e.joinNode,N(e,t,r))})}onTrue(){return new he({...this.#e,joinNode:L.cloneWithOn(this.#e.joinNode,rr.createWithSql("true"))})}$call(e){return e(this)}toOperationNode(){return this.#e.joinNode}}var Ft=C({is(e){return e.kind==="PartitionByItemNode"},create(e){return C({kind:"PartitionByItemNode",partitionBy:e})}});function Vt(e){return Q(e).map(Ft.create)}class ue{#e;constructor(e){this.#e=C(e)}orderBy(...e){return new ue({overNode:ve.cloneWithOrderByItems(this.#e.overNode,k(e))})}clearOrderBy(){return new ue({overNode:Oe.cloneWithoutOrderBy(this.#e.overNode)})}partitionBy(e){return new ue({overNode:ve.cloneWithPartitionByItems(this.#e.overNode,Vt(e))})}$call(e){return e(this)}toOperationNode(){return this.#e.overNode}}var me=C({is(e){return e.kind==="SelectionNode"},create(e){return C({kind:"SelectionNode",selection:e})},createSelectAll(){return C({kind:"SelectionNode",selection:fc.create()})},createSelectAllFromTable(e){return C({kind:"SelectionNode",selection:Ba.createSelectAll(e)})}});function c(e){if(pr(e))return c(e(B()));else if(x(e))return e.map((t)=>Ut(t));else return[Ut(e)]}function Ut(e){if(fr(e))return me.create(Dt(e));else if(Be(e))return me.create(e.toOperationNode());else return me.create(Ve(e))}function y(e){if(!e)return[me.createSelectAll()];else if(Array.isArray(e))return e.map(zt);else return[zt(e)]}function zt(e){if(fr(e))return me.createSelectAllFromTable(sr(e));throw Error(`invalid value selectAll expression: ${JSON.stringify(e)}`)}var Jt=C({is(e){return e.kind==="ValuesNode"},create(e){return C({kind:"ValuesNode",values:C(e)})}});var Qt=C({is(e){return e.kind==="DefaultInsertValueNode"},create(){return C({kind:"DefaultInsertValueNode"})}});function Ue(e){let t=pr(e)?e(B()):e,r=x(t)?t:C([t]);return zr(r)}function zr(e){let t=Jr(e);return[C([...t.keys()].map(Wt.create)),Jt.create(e.map((r)=>Qr(r,t)))]}function Jr(e){let t=new Map;for(let r of e){let i=Object.keys(r);for(let n of i)if(!t.has(n)&&r[n]!==void 0)t.set(n,t.size)}return t}function Qr(e,t){let r=Object.keys(e),i=Array.from({length:t.size}),n=!1,a=r.length;for(let H of r){let Y=t.get(H);if(So(Y)){a--;continue}let we=e[H];if(So(we)||J(we))n=!0;i[Y]=we}if(a<t.size||n){let H=Qt.create();return Ua.create(i.map((Y)=>So(Y)?H:d(Y)))}return Me.create(i)}var pt=C({is(e){return e.kind==="ColumnUpdateNode"},create(e,t){return C({kind:"ColumnUpdateNode",column:e,value:t})}});function _t(...e){if(e.length===2)return[pt.create(w(e[0]),d(e[1]))];return We(e[0])}function We(e){let t=pr(e)?e(B()):e;return Object.entries(t).filter(([r,i])=>i!==void 0).map(([r,i])=>pt.create(Wt.create(r),d(i)))}var $t=C({is(e){return e.kind==="OnDuplicateKeyNode"},create(e){return C({kind:"OnDuplicateKeyNode",updates:e})}});class dt{insertId;numInsertedOrUpdatedRows;constructor(e,t){this.insertId=e,this.numInsertedOrUpdatedRows=t}}class q extends Error{node;constructor(e){super("no result");this.node=e}}function V(e){return Object.prototype.hasOwnProperty.call(e,"prototype")}var g=C({is(e){return e.kind==="OnConflictNode"},create(){return C({kind:"OnConflictNode"})},cloneWith(e,t){return C({...e,...t})},cloneWithIndexWhere(e,t){return C({...e,indexWhere:e.indexWhere?O.cloneWithOperation(e.indexWhere,"And",t):O.create(t)})},cloneWithIndexOrWhere(e,t){return C({...e,indexWhere:e.indexWhere?O.cloneWithOperation(e.indexWhere,"Or",t):O.create(t)})},cloneWithUpdateWhere(e,t){return C({...e,updateWhere:e.updateWhere?O.cloneWithOperation(e.updateWhere,"And",t):O.create(t)})},cloneWithUpdateOrWhere(e,t){return C({...e,updateWhere:e.updateWhere?O.cloneWithOperation(e.updateWhere,"Or",t):O.create(t)})},cloneWithoutIndexWhere(e){return C({...e,indexWhere:void 0})},cloneWithoutUpdateWhere(e){return C({...e,updateWhere:void 0})}});class U{#e;constructor(e){this.#e=C(e)}column(e){let t=Wt.create(e);return new U({...this.#e,onConflictNode:g.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?C([...this.#e.onConflictNode.columns,t]):C([t])})})}columns(e){let t=e.map(Wt.create);return new U({...this.#e,onConflictNode:g.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?C([...this.#e.onConflictNode.columns,...t]):C(t)})})}constraint(e){return new U({...this.#e,onConflictNode:g.cloneWith(this.#e.onConflictNode,{constraint:st.create(e)})})}expression(e){return new U({...this.#e,onConflictNode:g.cloneWith(this.#e.onConflictNode,{indexExpression:e.toOperationNode()})})}where(...e){return new U({...this.#e,onConflictNode:g.cloneWithIndexWhere(this.#e.onConflictNode,yr(e))})}whereRef(e,t,r){return new U({...this.#e,onConflictNode:g.cloneWithIndexWhere(this.#e.onConflictNode,N(e,t,r))})}clearWhere(){return new U({...this.#e,onConflictNode:g.cloneWithoutIndexWhere(this.#e.onConflictNode)})}doNothing(){return new Gt({...this.#e,onConflictNode:g.cloneWith(this.#e.onConflictNode,{doNothing:!0})})}doUpdateSet(e){return new Se({...this.#e,onConflictNode:g.cloneWith(this.#e.onConflictNode,{updates:We(e)})})}$call(e){return e(this)}}class Gt{#e;constructor(e){this.#e=C(e)}toOperationNode(){return this.#e.onConflictNode}}class Se{#e;constructor(e){this.#e=C(e)}where(...e){return new Se({...this.#e,onConflictNode:g.cloneWithUpdateWhere(this.#e.onConflictNode,yr(e))})}whereRef(e,t,r){return new Se({...this.#e,onConflictNode:g.cloneWithUpdateWhere(this.#e.onConflictNode,N(e,t,r))})}clearWhere(){return new Se({...this.#e,onConflictNode:g.cloneWithoutUpdateWhere(this.#e.onConflictNode)})}$call(e){return e(this)}toOperationNode(){return this.#e.onConflictNode}}var Kt=C({is(e){return e.kind==="TopNode"},create(e,t){return C({kind:"TopNode",expression:e,modifiers:t})}});function M(e,t){if(!zs(e)&&!Za(e))throw Error(`Invalid top expression: ${e}`);if(!So(t)&&!_r(t))throw Error(`Invalid top modifiers: ${t}`);return Kt.create(e,t)}function _r(e){return e==="percent"||e==="with ties"||e==="percent with ties"}var ne=C({is(e){return e.kind==="OrActionNode"},create(e){return C({kind:"OrActionNode",action:e})}});class h{#e;constructor(e){this.#e=C(e)}values(e){let[t,r]=Ue(e);return new h({...this.#e,queryNode:u.cloneWith(this.#e.queryNode,{columns:t,values:r})})}columns(e){return new h({...this.#e,queryNode:u.cloneWith(this.#e.queryNode,{columns:C(e.map(Wt.create))})})}expression(e){return new h({...this.#e,queryNode:u.cloneWith(this.#e.queryNode,{values:Ho(e)})})}defaultValues(){return new h({...this.#e,queryNode:u.cloneWith(this.#e.queryNode,{defaultValues:!0})})}modifyEnd(e){return new h({...this.#e,queryNode:Oe.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}ignore(){return new h({...this.#e,queryNode:u.cloneWith(this.#e.queryNode,{orAction:ne.create("ignore")})})}orIgnore(){return new h({...this.#e,queryNode:u.cloneWith(this.#e.queryNode,{orAction:ne.create("ignore")})})}orAbort(){return new h({...this.#e,queryNode:u.cloneWith(this.#e.queryNode,{orAction:ne.create("abort")})})}orFail(){return new h({...this.#e,queryNode:u.cloneWith(this.#e.queryNode,{orAction:ne.create("fail")})})}orReplace(){return new h({...this.#e,queryNode:u.cloneWith(this.#e.queryNode,{orAction:ne.create("replace")})})}orRollback(){return new h({...this.#e,queryNode:u.cloneWith(this.#e.queryNode,{orAction:ne.create("rollback")})})}top(e,t){return new h({...this.#e,queryNode:Oe.cloneWithTop(this.#e.queryNode,M(e,t))})}onConflict(e){return new h({...this.#e,queryNode:u.cloneWith(this.#e.queryNode,{onConflict:e(new U({onConflictNode:g.create()})).toOperationNode()})})}onDuplicateKeyUpdate(e){return new h({...this.#e,queryNode:u.cloneWith(this.#e.queryNode,{onDuplicateKey:$t.create(We(e))})})}returning(e){return new h({...this.#e,queryNode:Oe.cloneWithReturning(this.#e.queryNode,c(e))})}returningAll(){return new h({...this.#e,queryNode:Oe.cloneWithReturning(this.#e.queryNode,y())})}output(e){return new h({...this.#e,queryNode:Oe.cloneWithOutput(this.#e.queryNode,c(e))})}outputAll(e){return new h({...this.#e,queryNode:Oe.cloneWithOutput(this.#e.queryNode,y(e))})}clearReturning(){return new h({...this.#e,queryNode:Oe.cloneWithoutReturning(this.#e.queryNode)})}$call(e){return e(this)}$if(e,t){if(e)return t(this);return new h({...this.#e})}$castTo(){return new h(this.#e)}$narrowType(){return new h(this.#e)}$assertType(){return new h(this.#e)}withPlugin(e){return new h({...this.#e,executor:this.#e.executor.withPlugin(e)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile(),t=await this.#e.executor.executeQuery(e),{adapter:r}=this.#e.executor,i=e.query;if(i.returning&&r.supportsReturning||i.output&&r.supportsOutput)return t.rows;return[new dt(t.insertId,t.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=q){let t=await this.executeTakeFirst();if(t===void 0)throw V(e)?new e(this.toOperationNode()):e(this.toOperationNode());return t}async*stream(e=100){let t=this.compile(),r=this.#e.executor.stream(t,e);for await(let i of r)yield*i.rows}async explain(e,t){return await new h({...this.#e,queryNode:Oe.cloneWithExplain(this.#e.queryNode,e,t)}).execute()}}class ht{numDeletedRows;constructor(e){this.numDeletedRows=e}}var fe=C({is(e){return e.kind==="LimitNode"},create(e){return C({kind:"LimitNode",limit:e})}});var m;class ze{#e;constructor(e){this.#e=C(e)}where(...e){return new m({...this.#e,queryNode:Oe.cloneWithWhere(this.#e.queryNode,yr(e))})}whereRef(e,t,r){return new m({...this.#e,queryNode:Oe.cloneWithWhere(this.#e.queryNode,N(e,t,r))})}clearWhere(){return new m({...this.#e,queryNode:Oe.cloneWithoutWhere(this.#e.queryNode)})}top(e,t){return new m({...this.#e,queryNode:Oe.cloneWithTop(this.#e.queryNode,M(e,t))})}using(e){return new m({...this.#e,queryNode:te.cloneWithUsing(this.#e.queryNode,P(e))})}innerJoin(...e){return this.#t("InnerJoin",e)}leftJoin(...e){return this.#t("LeftJoin",e)}rightJoin(...e){return this.#t("RightJoin",e)}fullJoin(...e){return this.#t("FullJoin",e)}#t(e,t){return new m({...this.#e,queryNode:Oe.cloneWithJoin(this.#e.queryNode,re(e,t))})}returning(e){return new m({...this.#e,queryNode:Oe.cloneWithReturning(this.#e.queryNode,c(e))})}returningAll(e){return new m({...this.#e,queryNode:Oe.cloneWithReturning(this.#e.queryNode,y(e))})}output(e){return new m({...this.#e,queryNode:Oe.cloneWithOutput(this.#e.queryNode,c(e))})}outputAll(e){return new m({...this.#e,queryNode:Oe.cloneWithOutput(this.#e.queryNode,y(e))})}clearReturning(){return new m({...this.#e,queryNode:Oe.cloneWithoutReturning(this.#e.queryNode)})}clearLimit(){return new m({...this.#e,queryNode:te.cloneWithoutLimit(this.#e.queryNode)})}orderBy(...e){return new m({...this.#e,queryNode:Oe.cloneWithOrderByItems(this.#e.queryNode,k(e))})}clearOrderBy(){return new m({...this.#e,queryNode:Oe.cloneWithoutOrderBy(this.#e.queryNode)})}limit(e){return new m({...this.#e,queryNode:te.cloneWithLimit(this.#e.queryNode,fe.create(d(e)))})}modifyEnd(e){return new m({...this.#e,queryNode:Oe.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}$call(e){return e(this)}$if(e,t){if(e)return t(this);return new m({...this.#e})}$castTo(){return new m(this.#e)}$narrowType(){return new m(this.#e)}$assertType(){return new m(this.#e)}withPlugin(e){return new m({...this.#e,executor:this.#e.executor.withPlugin(e)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile(),t=await this.#e.executor.executeQuery(e),{adapter:r}=this.#e.executor,i=e.query;if(i.returning&&r.supportsReturning||i.output&&r.supportsOutput)return t.rows;return[new ht(t.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=q){let t=await this.executeTakeFirst();if(t===void 0)throw V(e)?new e(this.toOperationNode()):e(this.toOperationNode());return t}async*stream(e=100){let t=this.compile(),r=this.#e.executor.stream(t,e);for await(let i of r)yield*i.rows}async explain(e,t){return await new m({...this.#e,queryNode:Oe.cloneWithExplain(this.#e.queryNode,e,t)}).execute()}}m=ze;class ut{numUpdatedRows;numChangedRows;constructor(e,t){this.numUpdatedRows=e,this.numChangedRows=t}}var f;class ce{#e;constructor(e){this.#e=C(e)}where(...e){return new f({...this.#e,queryNode:Oe.cloneWithWhere(this.#e.queryNode,yr(e))})}whereRef(e,t,r){return new f({...this.#e,queryNode:Oe.cloneWithWhere(this.#e.queryNode,N(e,t,r))})}clearWhere(){return new f({...this.#e,queryNode:Oe.cloneWithoutWhere(this.#e.queryNode)})}top(e,t){return new f({...this.#e,queryNode:Oe.cloneWithTop(this.#e.queryNode,M(e,t))})}from(e){return new f({...this.#e,queryNode:F.cloneWithFromItems(this.#e.queryNode,P(e))})}innerJoin(...e){return this.#t("InnerJoin",e)}leftJoin(...e){return this.#t("LeftJoin",e)}rightJoin(...e){return this.#t("RightJoin",e)}fullJoin(...e){return this.#t("FullJoin",e)}#t(e,t){return new f({...this.#e,queryNode:Oe.cloneWithJoin(this.#e.queryNode,re(e,t))})}orderBy(...e){return new f({...this.#e,queryNode:Oe.cloneWithOrderByItems(this.#e.queryNode,k(e))})}clearOrderBy(){return new f({...this.#e,queryNode:Oe.cloneWithoutOrderBy(this.#e.queryNode)})}limit(e){return new f({...this.#e,queryNode:F.cloneWithLimit(this.#e.queryNode,fe.create(d(e)))})}set(...e){return new f({...this.#e,queryNode:F.cloneWithUpdates(this.#e.queryNode,_t(...e))})}returning(e){return new f({...this.#e,queryNode:Oe.cloneWithReturning(this.#e.queryNode,c(e))})}returningAll(e){return new f({...this.#e,queryNode:Oe.cloneWithReturning(this.#e.queryNode,y(e))})}output(e){return new f({...this.#e,queryNode:Oe.cloneWithOutput(this.#e.queryNode,c(e))})}outputAll(e){return new f({...this.#e,queryNode:Oe.cloneWithOutput(this.#e.queryNode,y(e))})}modifyEnd(e){return new f({...this.#e,queryNode:Oe.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}clearReturning(){return new f({...this.#e,queryNode:Oe.cloneWithoutReturning(this.#e.queryNode)})}$call(e){return e(this)}$if(e,t){if(e)return t(this);return new f({...this.#e})}$castTo(){return new f(this.#e)}$narrowType(){return new f(this.#e)}$assertType(){return new f(this.#e)}withPlugin(e){return new f({...this.#e,executor:this.#e.executor.withPlugin(e)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile(),t=await this.#e.executor.executeQuery(e),{adapter:r}=this.#e.executor,i=e.query;if(i.returning&&r.supportsReturning||i.output&&r.supportsOutput)return t.rows;return[new ut(t.numAffectedRows??BigInt(0),t.numChangedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=q){let t=await this.executeTakeFirst();if(t===void 0)throw V(e)?new e(this.toOperationNode()):e(this.toOperationNode());return t}async*stream(e=100){let t=this.compile(),r=this.#e.executor.stream(t,e);for await(let i of r)yield*i.rows}async explain(e,t){return await new f({...this.#e,queryNode:Oe.cloneWithExplain(this.#e.queryNode,e,t)}).execute()}}f=ce;var mt=C({is(e){return e.kind==="CommonTableExpressionNameNode"},create(e,t){return C({kind:"CommonTableExpressionNameNode",table:mo.create(e),columns:t?C(t.map(Wt.create)):void 0})}});var le=C({is(e){return e.kind==="CommonTableExpressionNode"},create(e,t){return C({kind:"CommonTableExpressionNode",name:e,expression:t})},cloneWith(e,t){return C({...e,...t})}});class Ce{#e;constructor(e){this.#e=C(e)}materialized(){return new Ce({...this.#e,node:le.cloneWith(this.#e.node,{materialized:!0})})}notMaterialized(){return new Ce({...this.#e,node:le.cloneWith(this.#e.node,{materialized:!1})})}toOperationNode(){return this.#e.node}}function ft(e,t){let r=t(Ht()).toOperationNode();if(pr(e))return e($r(r)).toOperationNode();return le.create(jt(e),r)}function $r(e){return(t)=>new Ce({node:le.create(jt(t),e)})}function jt(e){if(e.includes("(")){let t=e.split(/[\(\)]/),r=t[0],i=t[1].split(",").map((n)=>n.trim());return mt.create(r,i)}else return mt.create(e)}var ke=C({is(e){return e.kind==="WithNode"},create(e,t){return C({kind:"WithNode",expressions:C([e]),...t})},cloneWithExpression(e,t){return C({...e,expressions:C([...e.expressions,t])})}});var Yt=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"];function of(e){let t="";for(let r=0;r<e;++r)t+=Gr();return t}function Gr(){return Yt[~~(Math.random()*Yt.length)]}function It(){return new Xt}class Xt{#e;get queryId(){if(this.#e===void 0)this.#e=of(8);return this.#e}}function o(e){return e}class Fu{nodeStack=[];#e=C({AliasNode:this.transformAlias.bind(this),ColumnNode:this.transformColumn.bind(this),IdentifierNode:this.transformIdentifier.bind(this),SchemableIdentifierNode:this.transformSchemableIdentifier.bind(this),RawNode:this.transformRaw.bind(this),ReferenceNode:this.transformReference.bind(this),SelectQueryNode:this.transformSelectQuery.bind(this),SelectionNode:this.transformSelection.bind(this),TableNode:this.transformTable.bind(this),FromNode:this.transformFrom.bind(this),SelectAllNode:this.transformSelectAll.bind(this),AndNode:this.transformAnd.bind(this),OrNode:this.transformOr.bind(this),ValueNode:this.transformValue.bind(this),ValueListNode:this.transformValueList.bind(this),PrimitiveValueListNode:this.transformPrimitiveValueList.bind(this),ParensNode:this.transformParens.bind(this),JoinNode:this.transformJoin.bind(this),OperatorNode:this.transformOperator.bind(this),WhereNode:this.transformWhere.bind(this),InsertQueryNode:this.transformInsertQuery.bind(this),DeleteQueryNode:this.transformDeleteQuery.bind(this),ReturningNode:this.transformReturning.bind(this),CreateTableNode:this.transformCreateTable.bind(this),AddColumnNode:this.transformAddColumn.bind(this),ColumnDefinitionNode:this.transformColumnDefinition.bind(this),DropTableNode:this.transformDropTable.bind(this),DataTypeNode:this.transformDataType.bind(this),OrderByNode:this.transformOrderBy.bind(this),OrderByItemNode:this.transformOrderByItem.bind(this),GroupByNode:this.transformGroupBy.bind(this),GroupByItemNode:this.transformGroupByItem.bind(this),UpdateQueryNode:this.transformUpdateQuery.bind(this),ColumnUpdateNode:this.transformColumnUpdate.bind(this),LimitNode:this.transformLimit.bind(this),OffsetNode:this.transformOffset.bind(this),OnConflictNode:this.transformOnConflict.bind(this),OnDuplicateKeyNode:this.transformOnDuplicateKey.bind(this),CreateIndexNode:this.transformCreateIndex.bind(this),DropIndexNode:this.transformDropIndex.bind(this),ListNode:this.transformList.bind(this),PrimaryKeyConstraintNode:this.transformPrimaryKeyConstraint.bind(this),UniqueConstraintNode:this.transformUniqueConstraint.bind(this),ReferencesNode:this.transformReferences.bind(this),CheckConstraintNode:this.transformCheckConstraint.bind(this),WithNode:this.transformWith.bind(this),CommonTableExpressionNode:this.transformCommonTableExpression.bind(this),CommonTableExpressionNameNode:this.transformCommonTableExpressionName.bind(this),HavingNode:this.transformHaving.bind(this),CreateSchemaNode:this.transformCreateSchema.bind(this),DropSchemaNode:this.transformDropSchema.bind(this),AlterTableNode:this.transformAlterTable.bind(this),DropColumnNode:this.transformDropColumn.bind(this),RenameColumnNode:this.transformRenameColumn.bind(this),AlterColumnNode:this.transformAlterColumn.bind(this),ModifyColumnNode:this.transformModifyColumn.bind(this),AddConstraintNode:this.transformAddConstraint.bind(this),DropConstraintNode:this.transformDropConstraint.bind(this),RenameConstraintNode:this.transformRenameConstraint.bind(this),ForeignKeyConstraintNode:this.transformForeignKeyConstraint.bind(this),CreateViewNode:this.transformCreateView.bind(this),RefreshMaterializedViewNode:this.transformRefreshMaterializedView.bind(this),DropViewNode:this.transformDropView.bind(this),GeneratedNode:this.transformGenerated.bind(this),DefaultValueNode:this.transformDefaultValue.bind(this),OnNode:this.transformOn.bind(this),ValuesNode:this.transformValues.bind(this),SelectModifierNode:this.transformSelectModifier.bind(this),CreateTypeNode:this.transformCreateType.bind(this),DropTypeNode:this.transformDropType.bind(this),ExplainNode:this.transformExplain.bind(this),DefaultInsertValueNode:this.transformDefaultInsertValue.bind(this),AggregateFunctionNode:this.transformAggregateFunction.bind(this),OverNode:this.transformOver.bind(this),PartitionByNode:this.transformPartitionBy.bind(this),PartitionByItemNode:this.transformPartitionByItem.bind(this),SetOperationNode:this.transformSetOperation.bind(this),BinaryOperationNode:this.transformBinaryOperation.bind(this),UnaryOperationNode:this.transformUnaryOperation.bind(this),UsingNode:this.transformUsing.bind(this),FunctionNode:this.transformFunction.bind(this),CaseNode:this.transformCase.bind(this),WhenNode:this.transformWhen.bind(this),JSONReferenceNode:this.transformJSONReference.bind(this),JSONPathNode:this.transformJSONPath.bind(this),JSONPathLegNode:this.transformJSONPathLeg.bind(this),JSONOperatorChainNode:this.transformJSONOperatorChain.bind(this),TupleNode:this.transformTuple.bind(this),MergeQueryNode:this.transformMergeQuery.bind(this),MatchedNode:this.transformMatched.bind(this),AddIndexNode:this.transformAddIndex.bind(this),CastNode:this.transformCast.bind(this),FetchNode:this.transformFetch.bind(this),TopNode:this.transformTop.bind(this),OutputNode:this.transformOutput.bind(this),OrActionNode:this.transformOrAction.bind(this),CollateNode:this.transformCollate.bind(this)});transformNode(e,t){if(!e)return e;this.nodeStack.push(e);let r=this.transformNodeImpl(e,t);return this.nodeStack.pop(),C(r)}transformNodeImpl(e,t){return this.#e[e.kind](e,t)}transformNodeList(e,t){if(!e)return e;return C(e.map((r)=>this.transformNode(r,t)))}transformSelectQuery(e,t){return o({kind:"SelectQueryNode",from:this.transformNode(e.from,t),selections:this.transformNodeList(e.selections,t),distinctOn:this.transformNodeList(e.distinctOn,t),joins:this.transformNodeList(e.joins,t),groupBy:this.transformNode(e.groupBy,t),orderBy:this.transformNode(e.orderBy,t),where:this.transformNode(e.where,t),frontModifiers:this.transformNodeList(e.frontModifiers,t),endModifiers:this.transformNodeList(e.endModifiers,t),limit:this.transformNode(e.limit,t),offset:this.transformNode(e.offset,t),with:this.transformNode(e.with,t),having:this.transformNode(e.having,t),explain:this.transformNode(e.explain,t),setOperations:this.transformNodeList(e.setOperations,t),fetch:this.transformNode(e.fetch,t),top:this.transformNode(e.top,t)})}transformSelection(e,t){return o({kind:"SelectionNode",selection:this.transformNode(e.selection,t)})}transformColumn(e,t){return o({kind:"ColumnNode",column:this.transformNode(e.column,t)})}transformAlias(e,t){return o({kind:"AliasNode",node:this.transformNode(e.node,t),alias:this.transformNode(e.alias,t)})}transformTable(e,t){return o({kind:"TableNode",table:this.transformNode(e.table,t)})}transformFrom(e,t){return o({kind:"FromNode",froms:this.transformNodeList(e.froms,t)})}transformReference(e,t){return o({kind:"ReferenceNode",column:this.transformNode(e.column,t),table:this.transformNode(e.table,t)})}transformAnd(e,t){return o({kind:"AndNode",left:this.transformNode(e.left,t),right:this.transformNode(e.right,t)})}transformOr(e,t){return o({kind:"OrNode",left:this.transformNode(e.left,t),right:this.transformNode(e.right,t)})}transformValueList(e,t){return o({kind:"ValueListNode",values:this.transformNodeList(e.values,t)})}transformParens(e,t){return o({kind:"ParensNode",node:this.transformNode(e.node,t)})}transformJoin(e,t){return o({kind:"JoinNode",joinType:e.joinType,table:this.transformNode(e.table,t),on:this.transformNode(e.on,t)})}transformRaw(e,t){return o({kind:"RawNode",sqlFragments:C([...e.sqlFragments]),parameters:this.transformNodeList(e.parameters,t)})}transformWhere(e,t){return o({kind:"WhereNode",where:this.transformNode(e.where,t)})}transformInsertQuery(e,t){return o({kind:"InsertQueryNode",into:this.transformNode(e.into,t),columns:this.transformNodeList(e.columns,t),values:this.transformNode(e.values,t),returning:this.transformNode(e.returning,t),onConflict:this.transformNode(e.onConflict,t),onDuplicateKey:this.transformNode(e.onDuplicateKey,t),endModifiers:this.transformNodeList(e.endModifiers,t),with:this.transformNode(e.with,t),ignore:e.ignore,orAction:this.transformNode(e.orAction,t),replace:e.replace,explain:this.transformNode(e.explain,t),defaultValues:e.defaultValues,top:this.transformNode(e.top,t),output:this.transformNode(e.output,t)})}transformValues(e,t){return o({kind:"ValuesNode",values:this.transformNodeList(e.values,t)})}transformDeleteQuery(e,t){return o({kind:"DeleteQueryNode",from:this.transformNode(e.from,t),using:this.transformNode(e.using,t),joins:this.transformNodeList(e.joins,t),where:this.transformNode(e.where,t),returning:this.transformNode(e.returning,t),endModifiers:this.transformNodeList(e.endModifiers,t),with:this.transformNode(e.with,t),orderBy:this.transformNode(e.orderBy,t),limit:this.transformNode(e.limit,t),explain:this.transformNode(e.explain,t),top:this.transformNode(e.top,t),output:this.transformNode(e.output,t)})}transformReturning(e,t){return o({kind:"ReturningNode",selections:this.transformNodeList(e.selections,t)})}transformCreateTable(e,t){return o({kind:"CreateTableNode",table:this.transformNode(e.table,t),columns:this.transformNodeList(e.columns,t),constraints:this.transformNodeList(e.constraints,t),temporary:e.temporary,ifNotExists:e.ifNotExists,onCommit:e.onCommit,frontModifiers:this.transformNodeList(e.frontModifiers,t),endModifiers:this.transformNodeList(e.endModifiers,t),selectQuery:this.transformNode(e.selectQuery,t)})}transformColumnDefinition(e,t){return o({kind:"ColumnDefinitionNode",column:this.transformNode(e.column,t),dataType:this.transformNode(e.dataType,t),references:this.transformNode(e.references,t),primaryKey:e.primaryKey,autoIncrement:e.autoIncrement,unique:e.unique,notNull:e.notNull,unsigned:e.unsigned,defaultTo:this.transformNode(e.defaultTo,t),check:this.transformNode(e.check,t),generated:this.transformNode(e.generated,t),frontModifiers:this.transformNodeList(e.frontModifiers,t),endModifiers:this.transformNodeList(e.endModifiers,t),nullsNotDistinct:e.nullsNotDistinct,identity:e.identity,ifNotExists:e.ifNotExists})}transformAddColumn(e,t){return o({kind:"AddColumnNode",column:this.transformNode(e.column,t)})}transformDropTable(e,t){return o({kind:"DropTableNode",table:this.transformNode(e.table,t),ifExists:e.ifExists,cascade:e.cascade})}transformOrderBy(e,t){return o({kind:"OrderByNode",items:this.transformNodeList(e.items,t)})}transformOrderByItem(e,t){return o({kind:"OrderByItemNode",orderBy:this.transformNode(e.orderBy,t),direction:this.transformNode(e.direction,t),collation:this.transformNode(e.collation,t),nulls:e.nulls})}transformGroupBy(e,t){return o({kind:"GroupByNode",items:this.transformNodeList(e.items,t)})}transformGroupByItem(e,t){return o({kind:"GroupByItemNode",groupBy:this.transformNode(e.groupBy,t)})}transformUpdateQuery(e,t){return o({kind:"UpdateQueryNode",table:this.transformNode(e.table,t),from:this.transformNode(e.from,t),joins:this.transformNodeList(e.joins,t),where:this.transformNode(e.where,t),updates:this.transformNodeList(e.updates,t),returning:this.transformNode(e.returning,t),endModifiers:this.transformNodeList(e.endModifiers,t),with:this.transformNode(e.with,t),explain:this.transformNode(e.explain,t),limit:this.transformNode(e.limit,t),top:this.transformNode(e.top,t),output:this.transformNode(e.output,t),orderBy:this.transformNode(e.orderBy,t)})}transformColumnUpdate(e,t){return o({kind:"ColumnUpdateNode",column:this.transformNode(e.column,t),value:this.transformNode(e.value,t)})}transformLimit(e,t){return o({kind:"LimitNode",limit:this.transformNode(e.limit,t)})}transformOffset(e,t){return o({kind:"OffsetNode",offset:this.transformNode(e.offset,t)})}transformOnConflict(e,t){return o({kind:"OnConflictNode",columns:this.transformNodeList(e.columns,t),constraint:this.transformNode(e.constraint,t),indexExpression:this.transformNode(e.indexExpression,t),indexWhere:this.transformNode(e.indexWhere,t),updates:this.transformNodeList(e.updates,t),updateWhere:this.transformNode(e.updateWhere,t),doNothing:e.doNothing})}transformOnDuplicateKey(e,t){return o({kind:"OnDuplicateKeyNode",updates:this.transformNodeList(e.updates,t)})}transformCreateIndex(e,t){return o({kind:"CreateIndexNode",name:this.transformNode(e.name,t),table:this.transformNode(e.table,t),columns:this.transformNodeList(e.columns,t),unique:e.unique,using:this.transformNode(e.using,t),ifNotExists:e.ifNotExists,where:this.transformNode(e.where,t),nullsNotDistinct:e.nullsNotDistinct})}transformList(e,t){return o({kind:"ListNode",items:this.transformNodeList(e.items,t)})}transformDropIndex(e,t){return o({kind:"DropIndexNode",name:this.transformNode(e.name,t),table:this.transformNode(e.table,t),ifExists:e.ifExists,cascade:e.cascade})}transformPrimaryKeyConstraint(e,t){return o({kind:"PrimaryKeyConstraintNode",columns:this.transformNodeList(e.columns,t),name:this.transformNode(e.name,t),deferrable:e.deferrable,initiallyDeferred:e.initiallyDeferred})}transformUniqueConstraint(e,t){return o({kind:"UniqueConstraintNode",columns:this.transformNodeList(e.columns,t),name:this.transformNode(e.name,t),nullsNotDistinct:e.nullsNotDistinct,deferrable:e.deferrable,initiallyDeferred:e.initiallyDeferred})}transformForeignKeyConstraint(e,t){return o({kind:"ForeignKeyConstraintNode",columns:this.transformNodeList(e.columns,t),references:this.transformNode(e.references,t),name:this.transformNode(e.name,t),onDelete:e.onDelete,onUpdate:e.onUpdate,deferrable:e.deferrable,initiallyDeferred:e.initiallyDeferred})}transformSetOperation(e,t){return o({kind:"SetOperationNode",operator:e.operator,expression:this.transformNode(e.expression,t),all:e.all})}transformReferences(e,t){return o({kind:"ReferencesNode",table:this.transformNode(e.table,t),columns:this.transformNodeList(e.columns,t),onDelete:e.onDelete,onUpdate:e.onUpdate})}transformCheckConstraint(e,t){return o({kind:"CheckConstraintNode",expression:this.transformNode(e.expression,t),name:this.transformNode(e.name,t)})}transformWith(e,t){return o({kind:"WithNode",expressions:this.transformNodeList(e.expressions,t),recursive:e.recursive})}transformCommonTableExpression(e,t){return o({kind:"CommonTableExpressionNode",name:this.transformNode(e.name,t),materialized:e.materialized,expression:this.transformNode(e.expression,t)})}transformCommonTableExpressionName(e,t){return o({kind:"CommonTableExpressionNameNode",table:this.transformNode(e.table,t),columns:this.transformNodeList(e.columns,t)})}transformHaving(e,t){return o({kind:"HavingNode",having:this.transformNode(e.having,t)})}transformCreateSchema(e,t){return o({kind:"CreateSchemaNode",schema:this.transformNode(e.schema,t),ifNotExists:e.ifNotExists})}transformDropSchema(e,t){return o({kind:"DropSchemaNode",schema:this.transformNode(e.schema,t),ifExists:e.ifExists,cascade:e.cascade})}transformAlterTable(e,t){return o({kind:"AlterTableNode",table:this.transformNode(e.table,t),renameTo:this.transformNode(e.renameTo,t),setSchema:this.transformNode(e.setSchema,t),columnAlterations:this.transformNodeList(e.columnAlterations,t),addConstraint:this.transformNode(e.addConstraint,t),dropConstraint:this.transformNode(e.dropConstraint,t),renameConstraint:this.transformNode(e.renameConstraint,t),addIndex:this.transformNode(e.addIndex,t),dropIndex:this.transformNode(e.dropIndex,t)})}transformDropColumn(e,t){return o({kind:"DropColumnNode",column:this.transformNode(e.column,t)})}transformRenameColumn(e,t){return o({kind:"RenameColumnNode",column:this.transformNode(e.column,t),renameTo:this.transformNode(e.renameTo,t)})}transformAlterColumn(e,t){return o({kind:"AlterColumnNode",column:this.transformNode(e.column,t),dataType:this.transformNode(e.dataType,t),dataTypeExpression:this.transformNode(e.dataTypeExpression,t),setDefault:this.transformNode(e.setDefault,t),dropDefault:e.dropDefault,setNotNull:e.setNotNull,dropNotNull:e.dropNotNull})}transformModifyColumn(e,t){return o({kind:"ModifyColumnNode",column:this.transformNode(e.column,t)})}transformAddConstraint(e,t){return o({kind:"AddConstraintNode",constraint:this.transformNode(e.constraint,t)})}transformDropConstraint(e,t){return o({kind:"DropConstraintNode",constraintName:this.transformNode(e.constraintName,t),ifExists:e.ifExists,modifier:e.modifier})}transformRenameConstraint(e,t){return o({kind:"RenameConstraintNode",oldName:this.transformNode(e.oldName,t),newName:this.transformNode(e.newName,t)})}transformCreateView(e,t){return o({kind:"CreateViewNode",name:this.transformNode(e.name,t),temporary:e.temporary,orReplace:e.orReplace,ifNotExists:e.ifNotExists,materialized:e.materialized,columns:this.transformNodeList(e.columns,t),as:this.transformNode(e.as,t)})}transformRefreshMaterializedView(e,t){return o({kind:"RefreshMaterializedViewNode",name:this.transformNode(e.name,t),concurrently:e.concurrently,withNoData:e.withNoData})}transformDropView(e,t){return o({kind:"DropViewNode",name:this.transformNode(e.name,t),ifExists:e.ifExists,materialized:e.materialized,cascade:e.cascade})}transformGenerated(e,t){return o({kind:"GeneratedNode",byDefault:e.byDefault,always:e.always,identity:e.identity,stored:e.stored,expression:this.transformNode(e.expression,t)})}transformDefaultValue(e,t){return o({kind:"DefaultValueNode",defaultValue:this.transformNode(e.defaultValue,t)})}transformOn(e,t){return o({kind:"OnNode",on:this.transformNode(e.on,t)})}transformSelectModifier(e,t){return o({kind:"SelectModifierNode",modifier:e.modifier,rawModifier:this.transformNode(e.rawModifier,t),of:this.transformNodeList(e.of,t)})}transformCreateType(e,t){return o({kind:"CreateTypeNode",name:this.transformNode(e.name,t),enum:this.transformNode(e.enum,t)})}transformDropType(e,t){return o({kind:"DropTypeNode",name:this.transformNode(e.name,t),ifExists:e.ifExists})}transformExplain(e,t){return o({kind:"ExplainNode",format:e.format,options:this.transformNode(e.options,t)})}transformSchemableIdentifier(e,t){return o({kind:"SchemableIdentifierNode",schema:this.transformNode(e.schema,t),identifier:this.transformNode(e.identifier,t)})}transformAggregateFunction(e,t){return o({kind:"AggregateFunctionNode",func:e.func,aggregated:this.transformNodeList(e.aggregated,t),distinct:e.distinct,orderBy:this.transformNode(e.orderBy,t),withinGroup:this.transformNode(e.withinGroup,t),filter:this.transformNode(e.filter,t),over:this.transformNode(e.over,t)})}transformOver(e,t){return o({kind:"OverNode",orderBy:this.transformNode(e.orderBy,t),partitionBy:this.transformNode(e.partitionBy,t)})}transformPartitionBy(e,t){return o({kind:"PartitionByNode",items:this.transformNodeList(e.items,t)})}transformPartitionByItem(e,t){return o({kind:"PartitionByItemNode",partitionBy:this.transformNode(e.partitionBy,t)})}transformBinaryOperation(e,t){return o({kind:"BinaryOperationNode",leftOperand:this.transformNode(e.leftOperand,t),operator:this.transformNode(e.operator,t),rightOperand:this.transformNode(e.rightOperand,t)})}transformUnaryOperation(e,t){return o({kind:"UnaryOperationNode",operator:this.transformNode(e.operator,t),operand:this.transformNode(e.operand,t)})}transformUsing(e,t){return o({kind:"UsingNode",tables:this.transformNodeList(e.tables,t)})}transformFunction(e,t){return o({kind:"FunctionNode",func:e.func,arguments:this.transformNodeList(e.arguments,t)})}transformCase(e,t){return o({kind:"CaseNode",value:this.transformNode(e.value,t),when:this.transformNodeList(e.when,t),else:this.transformNode(e.else,t),isStatement:e.isStatement})}transformWhen(e,t){return o({kind:"WhenNode",condition:this.transformNode(e.condition,t),result:this.transformNode(e.result,t)})}transformJSONReference(e,t){return o({kind:"JSONReferenceNode",reference:this.transformNode(e.reference,t),traversal:this.transformNode(e.traversal,t)})}transformJSONPath(e,t){return o({kind:"JSONPathNode",inOperator:this.transformNode(e.inOperator,t),pathLegs:this.transformNodeList(e.pathLegs,t)})}transformJSONPathLeg(e,t){return o({kind:"JSONPathLegNode",type:e.type,value:e.value})}transformJSONOperatorChain(e,t){return o({kind:"JSONOperatorChainNode",operator:this.transformNode(e.operator,t),values:this.transformNodeList(e.values,t)})}transformTuple(e,t){return o({kind:"TupleNode",values:this.transformNodeList(e.values,t)})}transformMergeQuery(e,t){return o({kind:"MergeQueryNode",into:this.transformNode(e.into,t),using:this.transformNode(e.using,t),whens:this.transformNodeList(e.whens,t),with:this.transformNode(e.with,t),top:this.transformNode(e.top,t),endModifiers:this.transformNodeList(e.endModifiers,t),output:this.transformNode(e.output,t),returning:this.transformNode(e.returning,t)})}transformMatched(e,t){return o({kind:"MatchedNode",not:e.not,bySource:e.bySource})}transformAddIndex(e,t){return o({kind:"AddIndexNode",name:this.transformNode(e.name,t),columns:this.transformNodeList(e.columns,t),unique:e.unique,using:this.transformNode(e.using,t),ifNotExists:e.ifNotExists})}transformCast(e,t){return o({kind:"CastNode",expression:this.transformNode(e.expression,t),dataType:this.transformNode(e.dataType,t)})}transformFetch(e,t){return o({kind:"FetchNode",rowCount:this.transformNode(e.rowCount,t),modifier:e.modifier})}transformTop(e,t){return o({kind:"TopNode",expression:e.expression,modifiers:e.modifiers})}transformOutput(e,t){return o({kind:"OutputNode",selections:this.transformNodeList(e.selections,t)})}transformDataType(e,t){return e}transformSelectAll(e,t){return e}transformIdentifier(e,t){return e}transformValue(e,t){return e}transformPrimitiveValueList(e,t){return e}transformOperator(e,t){return e}transformDefaultInsertValue(e,t){return e}transformOrAction(e,t){return e}transformCollate(e,t){return e}}var Kr=C({AlterTableNode:!0,CreateIndexNode:!0,CreateSchemaNode:!0,CreateTableNode:!0,CreateTypeNode:!0,CreateViewNode:!0,RefreshMaterializedViewNode:!0,DeleteQueryNode:!0,DropIndexNode:!0,DropSchemaNode:!0,DropTableNode:!0,DropTypeNode:!0,DropViewNode:!0,InsertQueryNode:!0,RawNode:!0,SelectQueryNode:!0,UpdateQueryNode:!0,MergeQueryNode:!0}),jr={json_agg:!0,to_json:!0};class ct extends Fu{#e;#t=new Set;#r=new Set;constructor(e){super();this.#e=e}transformNodeImpl(e,t){if(!this.#s(e))return super.transformNodeImpl(e,t);let r=this.#p(e);for(let a of r)this.#r.add(a);let i=this.#a(e);for(let a of i)this.#t.add(a);let n=super.transformNodeImpl(e,t);for(let a of i)this.#t.delete(a);for(let a of r)this.#r.delete(a);return n}transformSchemableIdentifier(e,t){let r=super.transformSchemableIdentifier(e,t);if(r.schema||!this.#t.has(e.identifier.name))return r;return{...r,schema:st.create(this.#e)}}transformReferences(e,t){let r=super.transformReferences(e,t);if(r.table.table.schema)return r;return{...r,table:mo.createWithSchema(this.#e,r.table.table.identifier.name)}}transformAggregateFunction(e,t){return{...super.transformAggregateFunction({...e,aggregated:[]},t),aggregated:this.#o(e,t,"aggregated")}}transformFunction(e,t){return{...super.transformFunction({...e,arguments:[]},t),arguments:this.#o(e,t,"arguments")}}transformSelectModifier(e,t){return{...super.transformSelectModifier({...e,of:void 0},t),of:e.of?.map((r)=>mo.is(r)&&!r.table.schema?{...r,table:this.transformIdentifier(r.table.identifier,t)}:this.transformNode(r,t))}}#o(e,t,r){return jr[e.func]?e[r].map((i)=>!mo.is(i)||i.table.schema?this.transformNode(i,t):{...i,table:this.transformIdentifier(i.table.identifier,t)}):this.transformNodeList(e[r],t)}#s(e){return e.kind in Kr}#a(e){let t=new Set;if("name"in e&&e.name&&po.is(e.name))this.#n(e.name,t);if("from"in e&&e.from)for(let r of e.from.froms)this.#i(r,t);if("into"in e&&e.into)this.#i(e.into,t);if("table"in e&&e.table)this.#i(e.table,t);if("joins"in e&&e.joins)for(let r of e.joins)this.#i(r.table,t);if("using"in e&&e.using)if(L.is(e.using))this.#i(e.using.table,t);else this.#i(e.using,t);return t}#p(e){let t=new Set;if("with"in e&&e.with)this.#d(e.with,t);return t}#i(e,t){if(mo.is(e))return this.#n(e.table,t);if(l.is(e)&&mo.is(e.node))return this.#n(e.node.table,t);if(Fe.is(e)){for(let r of e.items)this.#i(r,t);return}if(be.is(e)){for(let r of e.tables)this.#i(r,t);return}}#n(e,t){let r=e.identifier.name;if(!this.#t.has(r)&&!this.#r.has(r))t.add(r)}#d(e,t){for(let r of e.expressions){let i=r.name.table.table.identifier.name;if(!this.#r.has(i))t.add(i)}}}class js{#e;constructor(e){this.#e=new ct(e)}transformQuery(e){return this.#e.transformNode(e.node,e.queryId)}async transformResult(e){return e.result}}var Zt=C({is(e){return e.kind==="MatchedNode"},create(e,t=!1){return C({kind:"MatchedNode",not:e,bySource:t})}});function lt(e,t,r){return R.create(de([Zt.create(!e.isMatched,e.bySource),...t&&t.length>0?[t.length===3&&r?N(t[0],t[1],t[2]):yr(t)]:[]],"and",!1))}function Ne(e){if(fr(e))return rr.create([e],[]);if(Rr(e))return e.toOperationNode();return e}class za{#e;#t;#r;constructor(){this.#e=new Promise((e,t)=>{this.#r=t,this.#t=e})}get promise(){return this.#e}resolve=(e)=>{if(this.#t)this.#t(e)};reject=(e)=>{if(this.#r)this.#r(e)}}async function sf(e){let t=new za,r=new za;return e.provideConnection(async(i)=>(t.resolve(i),await r.promise)).catch((i)=>t.reject(i)),C({connection:await t.promise,release:r.resolve})}var Hr=C([]);class Lu{#e;constructor(e=Hr){this.#e=e}get plugins(){return this.#e}transformQuery(e,t){for(let r of this.#e){let i=r.transformQuery({node:e,queryId:t});if(i.kind===e.kind)e=i;else throw Error(["KyselyPlugin.transformQuery must return a node","of the same kind that was given to it.",`The plugin was given a ${e.kind}`,`but it returned a ${i.kind}`].join(" "))}return e}async executeQuery(e){return await this.provideConnection(async(t)=>{let r=await t.executeQuery(e);if("numUpdatedOrDeletedRows"in r)hi("kysely:warning: outdated driver/plugin detected! `QueryResult.numUpdatedOrDeletedRows` has been replaced with `QueryResult.numAffectedRows`.");return await this.#t(r,e.queryId)})}async*stream(e,t){let{connection:r,release:i}=await sf(this);try{for await(let n of r.streamQuery(e,t))yield await this.#t(n,e.queryId)}finally{i()}}async#t(e,t){for(let r of this.#e)e=await r.transformResult({result:e,queryId:t});return e}}class ye extends Lu{get adapter(){throw Error("this query cannot be compiled to SQL")}compileQuery(){throw Error("this query cannot be compiled to SQL")}provideConnection(){throw Error("this query cannot be executed")}withConnectionProvider(){throw Error("this query cannot have a connection provider")}withPlugin(e){return new ye([...this.plugins,e])}withPlugins(e){return new ye([...this.plugins,...e])}withPluginAtFront(e){return new ye([e,...this.plugins])}withoutPlugins(){return new ye([])}}var ie=new ye;class Nt{numChangedRows;constructor(e){this.numChangedRows=e}}class G{#e;constructor(e){this.#e=C(e)}modifyEnd(e){return new G({...this.#e,queryNode:Oe.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}top(e,t){return new G({...this.#e,queryNode:Oe.cloneWithTop(this.#e.queryNode,M(e,t))})}using(...e){return new b({...this.#e,queryNode:A.cloneWithUsing(this.#e.queryNode,re("Using",e))})}returning(e){return new G({...this.#e,queryNode:Oe.cloneWithReturning(this.#e.queryNode,c(e))})}returningAll(e){return new G({...this.#e,queryNode:Oe.cloneWithReturning(this.#e.queryNode,y(e))})}output(e){return new G({...this.#e,queryNode:Oe.cloneWithOutput(this.#e.queryNode,c(e))})}outputAll(e){return new G({...this.#e,queryNode:Oe.cloneWithOutput(this.#e.queryNode,y(e))})}}class b{#e;constructor(e){this.#e=C(e)}modifyEnd(e){return new b({...this.#e,queryNode:Oe.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}top(e,t){return new b({...this.#e,queryNode:Oe.cloneWithTop(this.#e.queryNode,M(e,t))})}whenMatched(){return this.#t([])}whenMatchedAnd(...e){return this.#t(e)}whenMatchedAndRef(e,t,r){return this.#t([e,t,r],!0)}#t(e,t){return new yt({...this.#e,queryNode:A.cloneWithWhen(this.#e.queryNode,lt({isMatched:!0},e,t))})}whenNotMatched(){return this.#r([])}whenNotMatchedAnd(...e){return this.#r(e)}whenNotMatchedAndRef(e,t,r){return this.#r([e,t,r],!0)}whenNotMatchedBySource(){return this.#r([],!1,!0)}whenNotMatchedBySourceAnd(...e){return this.#r(e,!1,!0)}whenNotMatchedBySourceAndRef(e,t,r){return this.#r([e,t,r],!0,!0)}returning(e){return new b({...this.#e,queryNode:Oe.cloneWithReturning(this.#e.queryNode,c(e))})}returningAll(e){return new b({...this.#e,queryNode:Oe.cloneWithReturning(this.#e.queryNode,y(e))})}output(e){return new b({...this.#e,queryNode:Oe.cloneWithOutput(this.#e.queryNode,c(e))})}outputAll(e){return new b({...this.#e,queryNode:Oe.cloneWithOutput(this.#e.queryNode,y(e))})}#r(e,t=!1,r=!1){let i={...this.#e,queryNode:A.cloneWithWhen(this.#e.queryNode,lt({isMatched:!1,bySource:r},e,t))};return new(r?yt:er)(i)}$call(e){return e(this)}$if(e,t){if(e)return t(this);return new b({...this.#e})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile(),t=await this.#e.executor.executeQuery(e),{adapter:r}=this.#e.executor,i=e.query;if(i.returning&&r.supportsReturning||i.output&&r.supportsOutput)return t.rows;return[new Nt(t.numAffectedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=q){let t=await this.executeTakeFirst();if(t===void 0)throw V(e)?new e(this.toOperationNode()):e(this.toOperationNode());return t}}class yt{#e;constructor(e){this.#e=C(e)}thenDelete(){return new b({...this.#e,queryNode:A.cloneWithThen(this.#e.queryNode,Ne("delete"))})}thenDoNothing(){return new b({...this.#e,queryNode:A.cloneWithThen(this.#e.queryNode,Ne("do nothing"))})}thenUpdate(e){return new b({...this.#e,queryNode:A.cloneWithThen(this.#e.queryNode,Ne(e(new ce({queryId:this.#e.queryId,executor:ie,queryNode:F.createWithoutTable()}))))})}thenUpdateSet(...e){return this.thenUpdate((t)=>t.set(...e))}}class er{#e;constructor(e){this.#e=C(e)}thenDoNothing(){return new b({...this.#e,queryNode:A.cloneWithThen(this.#e.queryNode,Ne("do nothing"))})}thenInsertValues(e){let[t,r]=Ue(e);return new b({...this.#e,queryNode:A.cloneWithThen(this.#e.queryNode,Ne(u.cloneWith(u.createWithoutInto(),{columns:t,values:r})))})}}class gi{#e;constructor(e){this.#e=C(e)}selectFrom(e){return Ee({queryId:It(),executor:this.#e.executor,queryNode:or.createFrom(P(e),this.#e.withNode)})}selectNoFrom(e){return Ee({queryId:It(),executor:this.#e.executor,queryNode:or.cloneWithSelections(or.create(this.#e.withNode),c(e))})}insertInto(e){return new h({queryId:It(),executor:this.#e.executor,queryNode:u.create(sr(e),this.#e.withNode)})}replaceInto(e){return new h({queryId:It(),executor:this.#e.executor,queryNode:u.create(sr(e),this.#e.withNode,!0)})}deleteFrom(e){return new ze({queryId:It(),executor:this.#e.executor,queryNode:te.create(P(e),this.#e.withNode)})}updateTable(e){return new ce({queryId:It(),executor:this.#e.executor,queryNode:F.create(P(e),this.#e.withNode)})}mergeInto(e){return new G({queryId:It(),executor:this.#e.executor,queryNode:A.create(wt(e),this.#e.withNode)})}with(e,t){let r=ft(e,t);return new gi({...this.#e,withNode:this.#e.withNode?ke.cloneWithExpression(this.#e.withNode,r):ke.create(r)})}withRecursive(e,t){let r=ft(e,t);return new gi({...this.#e,withNode:this.#e.withNode?ke.cloneWithExpression(this.#e.withNode,r):ke.create(r,{recursive:!0})})}withPlugin(e){return new gi({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new gi({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new gi({...this.#e,executor:this.#e.executor.withPluginAtFront(new js(e))})}}function Ht(){return new gi({executor:ie})}function tr(e,t){return new he({joinNode:L.create(e,se(t))})}function ir(){return new ue({overNode:ve.create()})}function re(e,t){if(t.length===3)return Xr(e,t[0],t[1],t[2]);else if(t.length===2)return Yr(e,t[0],t[1]);else if(t.length===1)return Zr(e,t[0]);else throw Error("not implemented")}function Yr(e,t,r){return r(tr(e,t)).toOperationNode()}function Xr(e,t,r,i){return L.createWithOn(e,se(t),N(r,"=",i))}function Zr(e,t){return L.create(e,se(t))}var nr=C({is(e){return e.kind==="OffsetNode"},create(e){return C({kind:"OffsetNode",offset:e})}});var ar=C({is(e){return e.kind==="GroupByItemNode"},create(e){return C({kind:"GroupByItemNode",groupBy:e})}});function dr(e){return e=pr(e)?e(B()):e,Q(e).map(ar.create)}var Je=C({is(e){return e.kind==="SetOperationNode"},create(e,t,r){return C({kind:"SetOperationNode",operator:e,expression:t,all:r})}});function ae(e,t,r){if(pr(t))t=t(Qe());if(!x(t))t=[t];return t.map((i)=>Je.create(e,Ho(i),r))}class p{#e;constructor(e){this.#e=e}get expressionType(){return}as(e){return new Ge(this,e)}or(...e){return new _e(T.create(this.#e,yr(e)))}and(...e){return new $e(v.create(this.#e,yr(e)))}$castTo(){return new p(this.#e)}$notNull(){return new p(this.#e)}toOperationNode(){return this.#e}}class Ge{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return l.create(this.#e.toOperationNode(),Rr(this.#t)?this.#t.toOperationNode():st.create(this.#t))}}class _e{#e;constructor(e){this.#e=e}get expressionType(){return}as(e){return new Ge(this,e)}or(...e){return new _e(T.create(this.#e,yr(e)))}$castTo(){return new _e(this.#e)}toOperationNode(){return E.create(this.#e)}}class $e{#e;constructor(e){this.#e=e}get expressionType(){return}as(e){return new Ge(this,e)}and(...e){return new $e(v.create(this.#e,yr(e)))}$castTo(){return new $e(this.#e)}toOperationNode(){return E.create(this.#e)}}var hr=C({is(e){return e.kind==="FetchNode"},create(e,t){return{kind:"FetchNode",rowCount:yn.create(e),modifier:t}}});function ur(e,t){if(!zs(e)&&!Za(e))throw Error(`Invalid fetch row count: ${e}`);if(!ei(t))throw Error(`Invalid fetch modifier: ${t}`);return hr.create(e,t)}function ei(e){return e==="only"||e==="with ties"}var s;class Ot{#e;constructor(e){this.#e=C(e)}get expressionType(){return}get isSelectQueryBuilder(){return!0}where(...e){return new s({...this.#e,queryNode:Oe.cloneWithWhere(this.#e.queryNode,yr(e))})}whereRef(e,t,r){return new s({...this.#e,queryNode:Oe.cloneWithWhere(this.#e.queryNode,N(e,t,r))})}having(...e){return new s({...this.#e,queryNode:or.cloneWithHaving(this.#e.queryNode,yr(e))})}havingRef(e,t,r){return new s({...this.#e,queryNode:or.cloneWithHaving(this.#e.queryNode,N(e,t,r))})}select(e){return new s({...this.#e,queryNode:or.cloneWithSelections(this.#e.queryNode,c(e))})}distinctOn(e){return new s({...this.#e,queryNode:or.cloneWithDistinctOn(this.#e.queryNode,Q(e))})}modifyFront(e){return new s({...this.#e,queryNode:or.cloneWithFrontModifier(this.#e.queryNode,I.createWithExpression(e.toOperationNode()))})}modifyEnd(e){return new s({...this.#e,queryNode:Oe.cloneWithEndModifier(this.#e.queryNode,I.createWithExpression(e.toOperationNode()))})}distinct(){return new s({...this.#e,queryNode:or.cloneWithFrontModifier(this.#e.queryNode,I.create("Distinct"))})}forUpdate(e){return new s({...this.#e,queryNode:Oe.cloneWithEndModifier(this.#e.queryNode,I.create("ForUpdate",e?xe(e).map(sr):void 0))})}forShare(e){return new s({...this.#e,queryNode:Oe.cloneWithEndModifier(this.#e.queryNode,I.create("ForShare",e?xe(e).map(sr):void 0))})}forKeyShare(e){return new s({...this.#e,queryNode:Oe.cloneWithEndModifier(this.#e.queryNode,I.create("ForKeyShare",e?xe(e).map(sr):void 0))})}forNoKeyUpdate(e){return new s({...this.#e,queryNode:Oe.cloneWithEndModifier(this.#e.queryNode,I.create("ForNoKeyUpdate",e?xe(e).map(sr):void 0))})}skipLocked(){return new s({...this.#e,queryNode:Oe.cloneWithEndModifier(this.#e.queryNode,I.create("SkipLocked"))})}noWait(){return new s({...this.#e,queryNode:Oe.cloneWithEndModifier(this.#e.queryNode,I.create("NoWait"))})}selectAll(e){return new s({...this.#e,queryNode:or.cloneWithSelections(this.#e.queryNode,y(e))})}innerJoin(...e){return this.#t("InnerJoin",e)}leftJoin(...e){return this.#t("LeftJoin",e)}rightJoin(...e){return this.#t("RightJoin",e)}fullJoin(...e){return this.#t("FullJoin",e)}crossJoin(...e){return this.#t("CrossJoin",e)}innerJoinLateral(...e){return this.#t("LateralInnerJoin",e)}leftJoinLateral(...e){return this.#t("LateralLeftJoin",e)}crossJoinLateral(...e){return this.#t("LateralCrossJoin",e)}crossApply(...e){return this.#t("CrossApply",e)}outerApply(...e){return this.#t("OuterApply",e)}#t(e,t){return new s({...this.#e,queryNode:Oe.cloneWithJoin(this.#e.queryNode,re(e,t))})}orderBy(...e){return new s({...this.#e,queryNode:Oe.cloneWithOrderByItems(this.#e.queryNode,k(e))})}groupBy(e){return new s({...this.#e,queryNode:or.cloneWithGroupByItems(this.#e.queryNode,dr(e))})}limit(e){return new s({...this.#e,queryNode:or.cloneWithLimit(this.#e.queryNode,fe.create(d(e)))})}offset(e){return new s({...this.#e,queryNode:or.cloneWithOffset(this.#e.queryNode,nr.create(d(e)))})}fetch(e,t="only"){return new s({...this.#e,queryNode:or.cloneWithFetch(this.#e.queryNode,ur(e,t))})}top(e,t){return new s({...this.#e,queryNode:Oe.cloneWithTop(this.#e.queryNode,M(e,t))})}union(e){return new s({...this.#e,queryNode:or.cloneWithSetOperations(this.#e.queryNode,ae("union",e,!1))})}unionAll(e){return new s({...this.#e,queryNode:or.cloneWithSetOperations(this.#e.queryNode,ae("union",e,!0))})}intersect(e){return new s({...this.#e,queryNode:or.cloneWithSetOperations(this.#e.queryNode,ae("intersect",e,!1))})}intersectAll(e){return new s({...this.#e,queryNode:or.cloneWithSetOperations(this.#e.queryNode,ae("intersect",e,!0))})}except(e){return new s({...this.#e,queryNode:or.cloneWithSetOperations(this.#e.queryNode,ae("except",e,!1))})}exceptAll(e){return new s({...this.#e,queryNode:or.cloneWithSetOperations(this.#e.queryNode,ae("except",e,!0))})}as(e){return new mr(this,e)}clearSelect(){return new s({...this.#e,queryNode:or.cloneWithoutSelections(this.#e.queryNode)})}clearWhere(){return new s({...this.#e,queryNode:Oe.cloneWithoutWhere(this.#e.queryNode)})}clearLimit(){return new s({...this.#e,queryNode:or.cloneWithoutLimit(this.#e.queryNode)})}clearOffset(){return new s({...this.#e,queryNode:or.cloneWithoutOffset(this.#e.queryNode)})}clearOrderBy(){return new s({...this.#e,queryNode:Oe.cloneWithoutOrderBy(this.#e.queryNode)})}clearGroupBy(){return new s({...this.#e,queryNode:or.cloneWithoutGroupBy(this.#e.queryNode)})}$call(e){return e(this)}$if(e,t){if(e)return t(this);return new s({...this.#e})}$castTo(){return new s(this.#e)}$narrowType(){return new s(this.#e)}$assertType(){return new s(this.#e)}$asTuple(){return new p(this.toOperationNode())}$asScalar(){return new p(this.toOperationNode())}withPlugin(e){return new s({...this.#e,executor:this.#e.executor.withPlugin(e)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile();return(await this.#e.executor.executeQuery(e)).rows}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=q){let t=await this.executeTakeFirst();if(t===void 0)throw V(e)?new e(this.toOperationNode()):e(this.toOperationNode());return t}async*stream(e=100){let t=this.compile(),r=this.#e.executor.stream(t,e);for await(let i of r)yield*i.rows}async explain(e,t){return await new s({...this.#e,queryNode:Oe.cloneWithExplain(this.#e.queryNode,e,t)}).execute()}}s=Ot;function Ee(e){return new Ot(e)}class mr{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get expression(){return this.#e}get alias(){return this.#t}get isAliasedSelectQueryBuilder(){return!0}toOperationNode(){return l.create(this.#e.toOperationNode(),st.create(this.#t))}}var z=C({is(e){return e.kind==="AggregateFunctionNode"},create(e,t=[]){return C({kind:"AggregateFunctionNode",func:e,aggregated:t})},cloneWithDistinct(e){return C({...e,distinct:!0})},cloneWithOrderBy(e,t,r=!1){let i=r?"withinGroup":"orderBy";return C({...e,[i]:e[i]?_.cloneWithItems(e[i],t):_.create(t)})},cloneWithFilter(e,t){return C({...e,filter:e.filter?O.cloneWithOperation(e.filter,"And",t):O.create(t)})},cloneWithOrFilter(e,t){return C({...e,filter:e.filter?O.cloneWithOperation(e.filter,"Or",t):O.create(t)})},cloneWithOver(e,t){return C({...e,over:t})}});var xt=C({is(e){return e.kind==="FunctionNode"},create(e,t){return C({kind:"FunctionNode",func:e,arguments:t})}});class W{#e;constructor(e){this.#e=C(e)}get expressionType(){return}as(e){return new cr(this,e)}distinct(){return new W({...this.#e,aggregateFunctionNode:z.cloneWithDistinct(this.#e.aggregateFunctionNode)})}orderBy(...e){return new W({...this.#e,aggregateFunctionNode:Oe.cloneWithOrderByItems(this.#e.aggregateFunctionNode,k(e))})}clearOrderBy(){return new W({...this.#e,aggregateFunctionNode:Oe.cloneWithoutOrderBy(this.#e.aggregateFunctionNode)})}withinGroupOrderBy(...e){return new W({...this.#e,aggregateFunctionNode:z.cloneWithOrderBy(this.#e.aggregateFunctionNode,k(e),!0)})}filterWhere(...e){return new W({...this.#e,aggregateFunctionNode:z.cloneWithFilter(this.#e.aggregateFunctionNode,yr(e))})}filterWhereRef(e,t,r){return new W({...this.#e,aggregateFunctionNode:z.cloneWithFilter(this.#e.aggregateFunctionNode,N(e,t,r))})}over(e){let t=ir();return new W({...this.#e,aggregateFunctionNode:z.cloneWithOver(this.#e.aggregateFunctionNode,(e?e(t):t).toOperationNode())})}$call(e){return e(this)}$castTo(){return new W(this.#e)}$notNull(){return new W(this.#e)}toOperationNode(){return this.#e.aggregateFunctionNode}}class cr{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return l.create(this.#e.toOperationNode(),st.create(this.#t))}}function af(){let e=(r,i)=>new p(xt.create(r,Q(i??[]))),t=(r,i)=>new W({aggregateFunctionNode:z.create(r,i?Q(i):void 0)});return Object.assign(e,{agg:t,avg(r){return t("avg",[r])},coalesce(...r){return e("coalesce",r)},count(r){return t("count",[r])},countAll(r){return new W({aggregateFunctionNode:z.create("count",y(r))})},max(r){return t("max",[r])},min(r){return t("min",[r])},sum(r){return t("sum",[r])},any(r){return e("any",[r])},jsonAgg(r){return new W({aggregateFunctionNode:z.create("json_agg",[fr(r)?sr(r):r.toOperationNode()])})},toJson(r){return new p(xt.create("to_json",[fr(r)?sr(r):r.toOperationNode()]))}})}var lr=C({is(e){return e.kind==="UnaryOperationNode"},create(e,t){return C({kind:"UnaryOperationNode",operator:e,operand:t})}});function Nr(e,t){return lr.create(S.create(e),w(t))}var as=C({is(e){return e.kind==="CaseNode"},create(e){return C({kind:"CaseNode",value:e})},cloneWithWhen(e,t){return C({...e,when:C(e.when?[...e.when,t]:[t])})},cloneWithThen(e,t){return C({...e,when:e.when?C([...e.when.slice(0,-1),R.cloneWithResult(e.when[e.when.length-1],t)]):void 0})},cloneWith(e,t){return C({...e,...t})}});class Zu{#e;constructor(e){this.#e=C(e)}when(...e){return new gt({...this.#e,node:as.cloneWithWhen(this.#e.node,R.create(yr(e)))})}}class gt{#e;constructor(e){this.#e=C(e)}then(e){return new wr({...this.#e,node:as.cloneWithThen(this.#e.node,Pe(e)?ge(e):d(e))})}}class wr{#e;constructor(e){this.#e=C(e)}when(...e){return new gt({...this.#e,node:as.cloneWithWhen(this.#e.node,R.create(yr(e)))})}else(e){return new Or({...this.#e,node:as.cloneWith(this.#e.node,{else:Pe(e)?ge(e):d(e)})})}end(){return new p(as.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new p(as.cloneWith(this.#e.node,{isStatement:!0}))}}class Or{#e;constructor(e){this.#e=C(e)}end(){return new p(as.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new p(as.cloneWith(this.#e.node,{isStatement:!0}))}}var vt=C({is(e){return e.kind==="JSONPathLegNode"},create(e,t){return C({kind:"JSONPathLegNode",type:e,value:t})}});var ti=/^#-\d+$/;class Re{#e;constructor(e){this.#e=e}at(e){if(typeof e!=="number"&&typeof e!=="string"||typeof e==="number"&&!Number.isInteger(e)||typeof e==="string"&&e!=="last"&&!ti.test(e))throw Error(`Unexpected index value in .at(...): ${e}`);return this.#t("ArrayLocation",e)}key(e){return this.#t("Member",e)}#t(e,t){if(pe.is(this.#e))return new Ae(pe.cloneWithTraversal(this.#e,ee.is(this.#e.traversal)?ee.cloneWithLeg(this.#e.traversal,vt.create(e,t)):qe.cloneWithValue(this.#e.traversal,yn.createImmediate(t))));return new Ae(ee.cloneWithLeg(this.#e,vt.create(e,t)))}}class Ae extends Re{#e;constructor(e){super(e);this.#e=e}get expressionType(){return}as(e){return new xr(this,e)}$castTo(){return new Ae(this.#e)}$notNull(){return new Ae(this.#e)}toOperationNode(){return this.#e}}class xr{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return l.create(this.#e.toOperationNode(),Rr(this.#t)?this.#t.toOperationNode():st.create(this.#t))}}var bt=C({is(e){return e.kind==="TupleNode"},create(e){return C({kind:"TupleNode",values:C(e)})}});var ri=["varchar","char","text","integer","int2","int4","int8","smallint","bigint","boolean","real","double precision","float4","float8","decimal","numeric","binary","bytea","date","datetime","time","timetz","timestamp","timestamptz","serial","bigserial","uuid","json","jsonb","blob","varbinary","int4range","int4multirange","int8range","int8multirange","numrange","nummultirange","tsrange","tsmultirange","tstzrange","tstzmultirange","daterange","datemultirange"],ii=[/^varchar\(\d+\)$/,/^char\(\d+\)$/,/^decimal\(\d+, \d+\)$/,/^numeric\(\d+, \d+\)$/,/^binary\(\d+\)$/,/^datetime\(\d+\)$/,/^time\(\d+\)$/,/^timetz\(\d+\)$/,/^timestamp\(\d+\)$/,/^timestamptz\(\d+\)$/,/^varbinary\(\d+\)$/],gr=C({is(e){return e.kind==="DataTypeNode"},create(e){return C({kind:"DataTypeNode",dataType:e})}});function vr(e){if(ri.includes(e))return!0;if(ii.some((t)=>t.test(e)))return!0;return!1}function qs(e){if(Rr(e))return e.toOperationNode();if(vr(e))return gr.create(e);throw Error(`invalid column data type ${JSON.stringify(e)}`)}var br=C({is(e){return e.kind==="CastNode"},create(e,t){return C({kind:"CastNode",expression:e,dataType:t})}});function Qe(e=ie){function t(n,a,j){return new p(Ie(n,a,j))}function r(n,a){return new p(Nr(n,a))}let i=Object.assign(t,{fn:void 0,eb:void 0,selectFrom(n){return Ee({queryId:It(),executor:e,queryNode:or.createFrom(P(n))})},case(n){return new Zu({node:as.create(So(n)?void 0:w(n))})},ref(n,a){if(So(a))return new p(is(n));return new Re(Lt(n,a))},jsonPath(){return new Re(ee.create())},table(n){return new p(sr(n))},val(n){return new p(d(n))},refTuple(...n){return new p(bt.create(n.map(w)))},tuple(...n){return new p(bt.create(n.map(d)))},lit(n){return new p(ge(n))},unary:r,not(n){return r("not",n)},exists(n){return r("exists",n)},neg(n){return r("-",n)},between(n,a,j){return new p(X.create(w(n),S.create("between"),v.create(d(a),d(j))))},betweenSymmetric(n,a,j){return new p(X.create(w(n),S.create("between symmetric"),v.create(d(a),d(j))))},and(n){if(x(n))return new p(de(n,"and"));return new p(tt(n,"and"))},or(n){if(x(n))return new p(de(n,"or"));return new p(tt(n,"or"))},parens(...n){let a=yr(n);if(E.is(a))return new p(a);else return new p(E.create(a))},cast(n,a){return new p(br.create(w(n),qs(a)))},withSchema(n){return Qe(e.withPluginAtFront(new js(n)))}});return i.fn=af(),i.eb=i,i}function B(e){return Qe()}function Ho(e){if(Rr(e))return e.toOperationNode();else if(pr(e))return e(B()).toOperationNode();throw Error(`invalid expression: ${JSON.stringify(e)}`)}function Ve(e){if(Rr(e))return e.toOperationNode();else if(pr(e))return e(B()).toOperationNode();throw Error(`invalid aliased expression: ${JSON.stringify(e)}`)}function J(e){return Le(e)||Ct(e)||pr(e)}class Am{#e;get table(){return this.#e}constructor(e){this.#e=e}as(e){return new Wr(this.#e,e)}}class Wr{#e;#t;get table(){return this.#e}get alias(){return this.#t}constructor(e,t){this.#e=e,this.#t=t}toOperationNode(){return l.create(sr(this.#e),st.create(this.#t))}}function Sr(e){return sn(e)&&Rr(e)&&fr(e.table)&&fr(e.alias)}function P(e){if(x(e))return e.map((t)=>se(t));else return[se(e)]}function se(e){if(fr(e))return wt(e);else if(Sr(e))return e.toOperationNode();else return Ve(e)}function wt(e){if(e.includes(" as ")){let[r,i]=e.split(" as ").map(Cr);return l.create(sr(r),st.create(i))}else return sr(e)}function sr(e){if(e.includes(".")){let[r,i]=e.split(".").map(Cr);return mo.createWithSchema(r,i)}else return mo.create(e)}function Cr(e){return e.trim()}var $s=C({is(e){return e.kind==="CreateViewNode"},create(e){return C({kind:"CreateViewNode",name:po.create(e)})},cloneWith(e,t){return C({...e,...t})}});class Te{#e;constructor(e){this.#e=C(e)}get expressionType(){return}get isRawBuilder(){return!0}as(e){return new kr(this,e)}$castTo(){return new Te({...this.#e})}$notNull(){return new Te(this.#e)}withPlugin(e){return new Te({...this.#e,plugins:this.#e.plugins!==void 0?C([...this.#e.plugins,e]):C([e])})}toOperationNode(){return this.#r(this.#t())}compile(e){return this.#o(this.#t(e))}async execute(e){let t=this.#t(e);return t.executeQuery(this.#o(t))}#t(e){let t=e!==void 0?e.getExecutor():ie;return this.#e.plugins!==void 0?t.withPlugins(this.#e.plugins):t}#r(e){return e.transformQuery(this.#e.rawNode,this.#e.queryId)}#o(e){return e.compileQuery(this.#r(e),this.#e.queryId)}}function K(e){return new Te(e)}class kr{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get expression(){return this.#e}get alias(){return this.#t}get rawBuilder(){return this.#e}toOperationNode(){return l.create(this.#e.toOperationNode(),Rr(this.#t)?this.#t.toOperationNode():st.create(this.#t))}}var je=Object.assign((e,...t)=>K({queryId:It(),rawNode:rr.create(e,t?.map(Er)??[])}),{ref(e){return K({queryId:It(),rawNode:rr.createWithChild(is(e))})},val(e){return K({queryId:It(),rawNode:rr.createWithChild(d(e))})},value(e){return this.val(e)},table(e){return K({queryId:It(),rawNode:rr.createWithChild(sr(e))})},id(...e){let t=Array(e.length+1).fill(".");return t[0]="",t[t.length-1]="",K({queryId:It(),rawNode:rr.create(t,e.map(st.create))})},lit(e){return K({queryId:It(),rawNode:rr.createWithChild(yn.createImmediate(e))})},literal(e){return this.lit(e)},raw(e){return K({queryId:It(),rawNode:rr.createWithSql(e)})},join(e,t=je`, `){let r=Array(Math.max(2*e.length-1,0)),i=t.toOperationNode();for(let n=0;n<e.length;++n)if(r[2*n]=Er(e[n]),n!==e.length-1)r[2*n+1]=i;return K({queryId:It(),rawNode:rr.createWithChildren(r)})}});function Er(e){if(Rr(e))return e.toOperationNode();return d(e)}class St{nodeStack=[];get parentNode(){return this.nodeStack[this.nodeStack.length-2]}#e=C({AliasNode:this.visitAlias.bind(this),ColumnNode:this.visitColumn.bind(this),IdentifierNode:this.visitIdentifier.bind(this),SchemableIdentifierNode:this.visitSchemableIdentifier.bind(this),RawNode:this.visitRaw.bind(this),ReferenceNode:this.visitReference.bind(this),SelectQueryNode:this.visitSelectQuery.bind(this),SelectionNode:this.visitSelection.bind(this),TableNode:this.visitTable.bind(this),FromNode:this.visitFrom.bind(this),SelectAllNode:this.visitSelectAll.bind(this),AndNode:this.visitAnd.bind(this),OrNode:this.visitOr.bind(this),ValueNode:this.visitValue.bind(this),ValueListNode:this.visitValueList.bind(this),PrimitiveValueListNode:this.visitPrimitiveValueList.bind(this),ParensNode:this.visitParens.bind(this),JoinNode:this.visitJoin.bind(this),OperatorNode:this.visitOperator.bind(this),WhereNode:this.visitWhere.bind(this),InsertQueryNode:this.visitInsertQuery.bind(this),DeleteQueryNode:this.visitDeleteQuery.bind(this),ReturningNode:this.visitReturning.bind(this),CreateTableNode:this.visitCreateTable.bind(this),AddColumnNode:this.visitAddColumn.bind(this),ColumnDefinitionNode:this.visitColumnDefinition.bind(this),DropTableNode:this.visitDropTable.bind(this),DataTypeNode:this.visitDataType.bind(this),OrderByNode:this.visitOrderBy.bind(this),OrderByItemNode:this.visitOrderByItem.bind(this),GroupByNode:this.visitGroupBy.bind(this),GroupByItemNode:this.visitGroupByItem.bind(this),UpdateQueryNode:this.visitUpdateQuery.bind(this),ColumnUpdateNode:this.visitColumnUpdate.bind(this),LimitNode:this.visitLimit.bind(this),OffsetNode:this.visitOffset.bind(this),OnConflictNode:this.visitOnConflict.bind(this),OnDuplicateKeyNode:this.visitOnDuplicateKey.bind(this),CreateIndexNode:this.visitCreateIndex.bind(this),DropIndexNode:this.visitDropIndex.bind(this),ListNode:this.visitList.bind(this),PrimaryKeyConstraintNode:this.visitPrimaryKeyConstraint.bind(this),UniqueConstraintNode:this.visitUniqueConstraint.bind(this),ReferencesNode:this.visitReferences.bind(this),CheckConstraintNode:this.visitCheckConstraint.bind(this),WithNode:this.visitWith.bind(this),CommonTableExpressionNode:this.visitCommonTableExpression.bind(this),CommonTableExpressionNameNode:this.visitCommonTableExpressionName.bind(this),HavingNode:this.visitHaving.bind(this),CreateSchemaNode:this.visitCreateSchema.bind(this),DropSchemaNode:this.visitDropSchema.bind(this),AlterTableNode:this.visitAlterTable.bind(this),DropColumnNode:this.visitDropColumn.bind(this),RenameColumnNode:this.visitRenameColumn.bind(this),AlterColumnNode:this.visitAlterColumn.bind(this),ModifyColumnNode:this.visitModifyColumn.bind(this),AddConstraintNode:this.visitAddConstraint.bind(this),DropConstraintNode:this.visitDropConstraint.bind(this),RenameConstraintNode:this.visitRenameConstraint.bind(this),ForeignKeyConstraintNode:this.visitForeignKeyConstraint.bind(this),CreateViewNode:this.visitCreateView.bind(this),RefreshMaterializedViewNode:this.visitRefreshMaterializedView.bind(this),DropViewNode:this.visitDropView.bind(this),GeneratedNode:this.visitGenerated.bind(this),DefaultValueNode:this.visitDefaultValue.bind(this),OnNode:this.visitOn.bind(this),ValuesNode:this.visitValues.bind(this),SelectModifierNode:this.visitSelectModifier.bind(this),CreateTypeNode:this.visitCreateType.bind(this),DropTypeNode:this.visitDropType.bind(this),ExplainNode:this.visitExplain.bind(this),DefaultInsertValueNode:this.visitDefaultInsertValue.bind(this),AggregateFunctionNode:this.visitAggregateFunction.bind(this),OverNode:this.visitOver.bind(this),PartitionByNode:this.visitPartitionBy.bind(this),PartitionByItemNode:this.visitPartitionByItem.bind(this),SetOperationNode:this.visitSetOperation.bind(this),BinaryOperationNode:this.visitBinaryOperation.bind(this),UnaryOperationNode:this.visitUnaryOperation.bind(this),UsingNode:this.visitUsing.bind(this),FunctionNode:this.visitFunction.bind(this),CaseNode:this.visitCase.bind(this),WhenNode:this.visitWhen.bind(this),JSONReferenceNode:this.visitJSONReference.bind(this),JSONPathNode:this.visitJSONPath.bind(this),JSONPathLegNode:this.visitJSONPathLeg.bind(this),JSONOperatorChainNode:this.visitJSONOperatorChain.bind(this),TupleNode:this.visitTuple.bind(this),MergeQueryNode:this.visitMergeQuery.bind(this),MatchedNode:this.visitMatched.bind(this),AddIndexNode:this.visitAddIndex.bind(this),CastNode:this.visitCast.bind(this),FetchNode:this.visitFetch.bind(this),TopNode:this.visitTop.bind(this),OutputNode:this.visitOutput.bind(this),OrActionNode:this.visitOrAction.bind(this),CollateNode:this.visitCollate.bind(this)});visitNode=(e)=>{this.nodeStack.push(e),this.#e[e.kind](e),this.nodeStack.pop()}}var oi=/'/g,ni=/['"]/g;class ho extends St{#e="";#t=[];get numParameters(){return this.#t.length}compileQuery(e,t){return this.#e="",this.#t=[],this.nodeStack.splice(0,this.nodeStack.length),this.visitNode(e),C({query:e,queryId:t,sql:this.getSql(),parameters:[...this.#t]})}getSql(){return this.#e}visitSelectQuery(e){let t=this.parentNode!==void 0&&!E.is(this.parentNode)&&!u.is(this.parentNode)&&!fo.is(this.parentNode)&&!$s.is(this.parentNode)&&!Je.is(this.parentNode);if(this.parentNode===void 0&&e.explain)this.visitNode(e.explain),this.append(" ");if(t)this.append("(");if(e.with)this.visitNode(e.with),this.append(" ");if(this.append("select"),e.distinctOn)this.append(" "),this.compileDistinctOn(e.distinctOn);if(e.frontModifiers?.length)this.append(" "),this.compileList(e.frontModifiers," ");if(e.top)this.append(" "),this.visitNode(e.top);if(e.selections)this.append(" "),this.compileList(e.selections);if(e.from)this.append(" "),this.visitNode(e.from);if(e.joins)this.append(" "),this.compileList(e.joins," ");if(e.where)this.append(" "),this.visitNode(e.where);if(e.groupBy)this.append(" "),this.visitNode(e.groupBy);if(e.having)this.append(" "),this.visitNode(e.having);if(e.setOperations)this.append(" "),this.compileList(e.setOperations," ");if(e.orderBy)this.append(" "),this.visitNode(e.orderBy);if(e.limit)this.append(" "),this.visitNode(e.limit);if(e.offset)this.append(" "),this.visitNode(e.offset);if(e.fetch)this.append(" "),this.visitNode(e.fetch);if(e.endModifiers?.length)this.append(" "),this.compileList(this.sortSelectModifiers([...e.endModifiers])," ");if(t)this.append(")")}visitFrom(e){this.append("from "),this.compileList(e.froms)}visitSelection(e){this.visitNode(e.selection)}visitColumn(e){this.visitNode(e.column)}compileDistinctOn(e){this.append("distinct on ("),this.compileList(e),this.append(")")}compileList(e,t=", "){let r=e.length-1;for(let i=0;i<=r;i++)if(this.visitNode(e[i]),i<r)this.append(t)}visitWhere(e){this.append("where "),this.visitNode(e.where)}visitHaving(e){this.append("having "),this.visitNode(e.having)}visitInsertQuery(e){let t=this.parentNode!==void 0&&!E.is(this.parentNode)&&!rr.is(this.parentNode)&&!R.is(this.parentNode);if(this.parentNode===void 0&&e.explain)this.visitNode(e.explain),this.append(" ");if(t)this.append("(");if(e.with)this.visitNode(e.with),this.append(" ");if(this.append(e.replace?"replace":"insert"),e.ignore)hi("`InsertQueryNode.ignore` is deprecated. Use `InsertQueryNode.orAction` instead."),this.append(" ignore");if(e.orAction)this.append(" "),this.visitNode(e.orAction);if(e.top)this.append(" "),this.visitNode(e.top);if(e.into)this.append(" into "),this.visitNode(e.into);if(e.columns)this.append(" ("),this.compileList(e.columns),this.append(")");if(e.output)this.append(" "),this.visitNode(e.output);if(e.values)this.append(" "),this.visitNode(e.values);if(e.defaultValues)this.append(" "),this.append("default values");if(e.onConflict)this.append(" "),this.visitNode(e.onConflict);if(e.onDuplicateKey)this.append(" "),this.visitNode(e.onDuplicateKey);if(e.returning)this.append(" "),this.visitNode(e.returning);if(t)this.append(")");if(e.endModifiers?.length)this.append(" "),this.compileList(e.endModifiers," ")}visitValues(e){this.append("values "),this.compileList(e.values)}visitDeleteQuery(e){let t=this.parentNode!==void 0&&!E.is(this.parentNode)&&!rr.is(this.parentNode);if(this.parentNode===void 0&&e.explain)this.visitNode(e.explain),this.append(" ");if(t)this.append("(");if(e.with)this.visitNode(e.with),this.append(" ");if(this.append("delete "),e.top)this.visitNode(e.top),this.append(" ");if(this.visitNode(e.from),e.output)this.append(" "),this.visitNode(e.output);if(e.using)this.append(" "),this.visitNode(e.using);if(e.joins)this.append(" "),this.compileList(e.joins," ");if(e.where)this.append(" "),this.visitNode(e.where);if(e.orderBy)this.append(" "),this.visitNode(e.orderBy);if(e.limit)this.append(" "),this.visitNode(e.limit);if(e.returning)this.append(" "),this.visitNode(e.returning);if(t)this.append(")");if(e.endModifiers?.length)this.append(" "),this.compileList(e.endModifiers," ")}visitReturning(e){this.append("returning "),this.compileList(e.selections)}visitAlias(e){this.visitNode(e.node),this.append(" as "),this.visitNode(e.alias)}visitReference(e){if(e.table)this.visitNode(e.table),this.append(".");this.visitNode(e.column)}visitSelectAll(e){this.append("*")}visitIdentifier(e){this.append(this.getLeftIdentifierWrapper()),this.compileUnwrappedIdentifier(e),this.append(this.getRightIdentifierWrapper())}compileUnwrappedIdentifier(e){if(!fr(e.name))throw Error("a non-string identifier was passed to compileUnwrappedIdentifier.");this.append(this.sanitizeIdentifier(e.name))}visitAnd(e){this.visitNode(e.left),this.append(" and "),this.visitNode(e.right)}visitOr(e){this.visitNode(e.left),this.append(" or "),this.visitNode(e.right)}visitValue(e){if(e.immediate)this.appendImmediateValue(e.value);else this.appendValue(e.value)}visitValueList(e){this.append("("),this.compileList(e.values),this.append(")")}visitTuple(e){this.append("("),this.compileList(e.values),this.append(")")}visitPrimitiveValueList(e){this.append("(");let{values:t}=e;for(let r=0;r<t.length;++r)if(this.appendValue(t[r]),r!==t.length-1)this.append(", ");this.append(")")}visitParens(e){this.append("("),this.visitNode(e.node),this.append(")")}visitJoin(e){if(this.append(ai[e.joinType]),this.append(" "),this.visitNode(e.table),e.on)this.append(" "),this.visitNode(e.on)}visitOn(e){this.append("on "),this.visitNode(e.on)}visitRaw(e){let{sqlFragments:t,parameters:r}=e;for(let i=0;i<t.length;++i)if(this.append(t[i]),r.length>i)this.visitNode(r[i])}visitOperator(e){this.append(e.operator)}visitTable(e){this.visitNode(e.table)}visitSchemableIdentifier(e){if(e.schema)this.visitNode(e.schema),this.append(".");this.visitNode(e.identifier)}visitCreateTable(e){if(this.append("create "),e.frontModifiers?.length)this.compileList(e.frontModifiers," "),this.append(" ");if(e.temporary)this.append("temporary ");if(this.append("table "),e.ifNotExists)this.append("if not exists ");if(this.visitNode(e.table),!e.selectQuery)this.append(" ("),this.compileList([...e.columns,...e.constraints??[]]),this.append(")");if(e.onCommit)this.append(" on commit "),this.append(e.onCommit);if(e.endModifiers?.length)this.append(" "),this.compileList(e.endModifiers," ");if(e.selectQuery)this.append(" as "),this.visitNode(e.selectQuery)}visitColumnDefinition(e){if(e.ifNotExists)this.append("if not exists ");if(this.visitNode(e.column),this.append(" "),this.visitNode(e.dataType),e.unsigned)this.append(" unsigned");if(e.frontModifiers&&e.frontModifiers.length>0)this.append(" "),this.compileList(e.frontModifiers," ");if(e.generated)this.append(" "),this.visitNode(e.generated);if(e.identity)this.append(" identity");if(e.defaultTo)this.append(" "),this.visitNode(e.defaultTo);if(e.notNull)this.append(" not null");if(e.unique)this.append(" unique");if(e.nullsNotDistinct)this.append(" nulls not distinct");if(e.primaryKey)this.append(" primary key");if(e.autoIncrement)this.append(" "),this.append(this.getAutoIncrement());if(e.references)this.append(" "),this.visitNode(e.references);if(e.check)this.append(" "),this.visitNode(e.check);if(e.endModifiers&&e.endModifiers.length>0)this.append(" "),this.compileList(e.endModifiers," ")}getAutoIncrement(){return"auto_increment"}visitReferences(e){if(this.append("references "),this.visitNode(e.table),this.append(" ("),this.compileList(e.columns),this.append(")"),e.onDelete)this.append(" on delete "),this.append(e.onDelete);if(e.onUpdate)this.append(" on update "),this.append(e.onUpdate)}visitDropTable(e){if(this.append("drop table "),e.ifExists)this.append("if exists ");if(this.visitNode(e.table),e.cascade)this.append(" cascade")}visitDataType(e){this.append(e.dataType)}visitOrderBy(e){this.append("order by "),this.compileList(e.items)}visitOrderByItem(e){if(this.visitNode(e.orderBy),e.collation)this.append(" "),this.visitNode(e.collation);if(e.direction)this.append(" "),this.visitNode(e.direction);if(e.nulls)this.append(" nulls "),this.append(e.nulls)}visitGroupBy(e){this.append("group by "),this.compileList(e.items)}visitGroupByItem(e){this.visitNode(e.groupBy)}visitUpdateQuery(e){let t=this.parentNode!==void 0&&!E.is(this.parentNode)&&!rr.is(this.parentNode)&&!R.is(this.parentNode);if(this.parentNode===void 0&&e.explain)this.visitNode(e.explain),this.append(" ");if(t)this.append("(");if(e.with)this.visitNode(e.with),this.append(" ");if(this.append("update "),e.top)this.visitNode(e.top),this.append(" ");if(e.table)this.visitNode(e.table),this.append(" ");if(this.append("set "),e.updates)this.compileList(e.updates);if(e.output)this.append(" "),this.visitNode(e.output);if(e.from)this.append(" "),this.visitNode(e.from);if(e.joins){if(!e.from)throw Error("Joins in an update query are only supported as a part of a PostgreSQL 'update set from join' query. If you want to create a MySQL 'update join set' query, see https://kysely.dev/docs/examples/update/my-sql-joins");this.append(" "),this.compileList(e.joins," ")}if(e.where)this.append(" "),this.visitNode(e.where);if(e.returning)this.append(" "),this.visitNode(e.returning);if(e.orderBy)this.append(" "),this.visitNode(e.orderBy);if(e.limit)this.append(" "),this.visitNode(e.limit);if(t)this.append(")");if(e.endModifiers?.length)this.append(" "),this.compileList(e.endModifiers," ")}visitColumnUpdate(e){this.visitNode(e.column),this.append(" = "),this.visitNode(e.value)}visitLimit(e){this.append("limit "),this.visitNode(e.limit)}visitOffset(e){this.append("offset "),this.visitNode(e.offset)}visitOnConflict(e){if(this.append("on conflict"),e.columns)this.append(" ("),this.compileList(e.columns),this.append(")");else if(e.constraint)this.append(" on constraint "),this.visitNode(e.constraint);else if(e.indexExpression)this.append(" ("),this.visitNode(e.indexExpression),this.append(")");if(e.indexWhere)this.append(" "),this.visitNode(e.indexWhere);if(e.doNothing===!0)this.append(" do nothing");else if(e.updates){if(this.append(" do update set "),this.compileList(e.updates),e.updateWhere)this.append(" "),this.visitNode(e.updateWhere)}}visitOnDuplicateKey(e){this.append("on duplicate key update "),this.compileList(e.updates)}visitCreateIndex(e){if(this.append("create "),e.unique)this.append("unique ");if(this.append("index "),e.ifNotExists)this.append("if not exists ");if(this.visitNode(e.name),e.table)this.append(" on "),this.visitNode(e.table);if(e.using)this.append(" using "),this.visitNode(e.using);if(e.columns)this.append(" ("),this.compileList(e.columns),this.append(")");if(e.nullsNotDistinct)this.append(" nulls not distinct");if(e.where)this.append(" "),this.visitNode(e.where)}visitDropIndex(e){if(this.append("drop index "),e.ifExists)this.append("if exists ");if(this.visitNode(e.name),e.table)this.append(" on "),this.visitNode(e.table);if(e.cascade)this.append(" cascade")}visitCreateSchema(e){if(this.append("create schema "),e.ifNotExists)this.append("if not exists ");this.visitNode(e.schema)}visitDropSchema(e){if(this.append("drop schema "),e.ifExists)this.append("if exists ");if(this.visitNode(e.schema),e.cascade)this.append(" cascade")}visitPrimaryKeyConstraint(e){if(e.name)this.append("constraint "),this.visitNode(e.name),this.append(" ");this.append("primary key ("),this.compileList(e.columns),this.append(")"),this.buildDeferrable(e)}buildDeferrable(e){if(e.deferrable!==void 0)if(e.deferrable)this.append(" deferrable");else this.append(" not deferrable");if(e.initiallyDeferred!==void 0)if(e.initiallyDeferred)this.append(" initially deferred");else this.append(" initially immediate")}visitUniqueConstraint(e){if(e.name)this.append("constraint "),this.visitNode(e.name),this.append(" ");if(this.append("unique"),e.nullsNotDistinct)this.append(" nulls not distinct");this.append(" ("),this.compileList(e.columns),this.append(")"),this.buildDeferrable(e)}visitCheckConstraint(e){if(e.name)this.append("constraint "),this.visitNode(e.name),this.append(" ");this.append("check ("),this.visitNode(e.expression),this.append(")")}visitForeignKeyConstraint(e){if(e.name)this.append("constraint "),this.visitNode(e.name),this.append(" ");if(this.append("foreign key ("),this.compileList(e.columns),this.append(") "),this.visitNode(e.references),e.onDelete)this.append(" on delete "),this.append(e.onDelete);if(e.onUpdate)this.append(" on update "),this.append(e.onUpdate);this.buildDeferrable(e)}visitList(e){this.compileList(e.items)}visitWith(e){if(this.append("with "),e.recursive)this.append("recursive ");this.compileList(e.expressions)}visitCommonTableExpression(e){if(this.visitNode(e.name),this.append(" as "),Vi(e.materialized)){if(!e.materialized)this.append("not ");this.append("materialized ")}this.visitNode(e.expression)}visitCommonTableExpressionName(e){if(this.visitNode(e.table),e.columns)this.append("("),this.compileList(e.columns),this.append(")")}visitAlterTable(e){if(this.append("alter table "),this.visitNode(e.table),this.append(" "),e.renameTo)this.append("rename to "),this.visitNode(e.renameTo);if(e.setSchema)this.append("set schema "),this.visitNode(e.setSchema);if(e.addConstraint)this.visitNode(e.addConstraint);if(e.dropConstraint)this.visitNode(e.dropConstraint);if(e.renameConstraint)this.visitNode(e.renameConstraint);if(e.columnAlterations)this.compileColumnAlterations(e.columnAlterations);if(e.addIndex)this.visitNode(e.addIndex);if(e.dropIndex)this.visitNode(e.dropIndex)}visitAddColumn(e){this.append("add column "),this.visitNode(e.column)}visitRenameColumn(e){this.append("rename column "),this.visitNode(e.column),this.append(" to "),this.visitNode(e.renameTo)}visitDropColumn(e){this.append("drop column "),this.visitNode(e.column)}visitAlterColumn(e){if(this.append("alter column "),this.visitNode(e.column),this.append(" "),e.dataType){if(this.announcesNewColumnDataType())this.append("type ");if(this.visitNode(e.dataType),e.dataTypeExpression)this.append("using "),this.visitNode(e.dataTypeExpression)}if(e.setDefault)this.append("set default "),this.visitNode(e.setDefault);if(e.dropDefault)this.append("drop default");if(e.setNotNull)this.append("set not null");if(e.dropNotNull)this.append("drop not null")}visitModifyColumn(e){this.append("modify column "),this.visitNode(e.column)}visitAddConstraint(e){this.append("add "),this.visitNode(e.constraint)}visitDropConstraint(e){if(this.append("drop constraint "),e.ifExists)this.append("if exists ");if(this.visitNode(e.constraintName),e.modifier==="cascade")this.append(" cascade");else if(e.modifier==="restrict")this.append(" restrict")}visitRenameConstraint(e){this.append("rename constraint "),this.visitNode(e.oldName),this.append(" to "),this.visitNode(e.newName)}visitSetOperation(e){if(this.append(e.operator),this.append(" "),e.all)this.append("all ");this.visitNode(e.expression)}visitCreateView(e){if(this.append("create "),e.orReplace)this.append("or replace ");if(e.materialized)this.append("materialized ");if(e.temporary)this.append("temporary ");if(this.append("view "),e.ifNotExists)this.append("if not exists ");if(this.visitNode(e.name),this.append(" "),e.columns)this.append("("),this.compileList(e.columns),this.append(") ");if(e.as)this.append("as "),this.visitNode(e.as)}visitRefreshMaterializedView(e){if(this.append("refresh materialized view "),e.concurrently)this.append("concurrently ");if(this.visitNode(e.name),e.withNoData)this.append(" with no data");else this.append(" with data")}visitDropView(e){if(this.append("drop "),e.materialized)this.append("materialized ");if(this.append("view "),e.ifExists)this.append("if exists ");if(this.visitNode(e.name),e.cascade)this.append(" cascade")}visitGenerated(e){if(this.append("generated "),e.always)this.append("always ");if(e.byDefault)this.append("by default ");if(this.append("as "),e.identity)this.append("identity");if(e.expression)this.append("("),this.visitNode(e.expression),this.append(")");if(e.stored)this.append(" stored")}visitDefaultValue(e){this.append("default "),this.visitNode(e.defaultValue)}visitSelectModifier(e){if(e.rawModifier)this.visitNode(e.rawModifier);else this.append(si[e.modifier]);if(e.of)this.append(" of "),this.compileList(e.of,", ")}visitCreateType(e){if(this.append("create type "),this.visitNode(e.name),e.enum)this.append(" as enum "),this.visitNode(e.enum)}visitDropType(e){if(this.append("drop type "),e.ifExists)this.append("if exists ");this.visitNode(e.name)}visitExplain(e){if(this.append("explain"),e.options||e.format){if(this.append(" "),this.append(this.getLeftExplainOptionsWrapper()),e.options){if(this.visitNode(e.options),e.format)this.append(this.getExplainOptionsDelimiter())}if(e.format)this.append("format"),this.append(this.getExplainOptionAssignment()),this.append(e.format);this.append(this.getRightExplainOptionsWrapper())}}visitDefaultInsertValue(e){this.append("default")}visitAggregateFunction(e){if(this.append(e.func),this.append("("),e.distinct)this.append("distinct ");if(this.compileList(e.aggregated),e.orderBy)this.append(" "),this.visitNode(e.orderBy);if(this.append(")"),e.withinGroup)this.append(" within group ("),this.visitNode(e.withinGroup),this.append(")");if(e.filter)this.append(" filter("),this.visitNode(e.filter),this.append(")");if(e.over)this.append(" "),this.visitNode(e.over)}visitOver(e){if(this.append("over("),e.partitionBy){if(this.visitNode(e.partitionBy),e.orderBy)this.append(" ")}if(e.orderBy)this.visitNode(e.orderBy);this.append(")")}visitPartitionBy(e){this.append("partition by "),this.compileList(e.items)}visitPartitionByItem(e){this.visitNode(e.partitionBy)}visitBinaryOperation(e){this.visitNode(e.leftOperand),this.append(" "),this.visitNode(e.operator),this.append(" "),this.visitNode(e.rightOperand)}visitUnaryOperation(e){if(this.visitNode(e.operator),!this.isMinusOperator(e.operator))this.append(" ");this.visitNode(e.operand)}isMinusOperator(e){return S.is(e)&&e.operator==="-"}visitUsing(e){this.append("using "),this.compileList(e.tables)}visitFunction(e){this.append(e.func),this.append("("),this.compileList(e.arguments),this.append(")")}visitCase(e){if(this.append("case"),e.value)this.append(" "),this.visitNode(e.value);if(e.when)this.append(" "),this.compileList(e.when," ");if(e.else)this.append(" else "),this.visitNode(e.else);if(this.append(" end"),e.isStatement)this.append(" case")}visitWhen(e){if(this.append("when "),this.visitNode(e.condition),e.result)this.append(" then "),this.visitNode(e.result)}visitJSONReference(e){this.visitNode(e.reference),this.visitNode(e.traversal)}visitJSONPath(e){if(e.inOperator)this.visitNode(e.inOperator);this.append("'$");for(let t of e.pathLegs)this.visitNode(t);this.append("'")}visitJSONPathLeg(e){let t=e.type==="ArrayLocation",r=String(e.value);if(t)this.append("["),this.append(this.sanitizeStringLiteral(r)),this.append("]");else this.append('."'),this.append(this.sanitizeJSONPathMemberValue(r)),this.append('"')}visitJSONOperatorChain(e){for(let t=0,r=e.values.length;t<r;t++){if(t===r-1)this.visitNode(e.operator);else this.append("->");this.visitNode(e.values[t])}}visitMergeQuery(e){if(e.with)this.visitNode(e.with),this.append(" ");if(this.append("merge "),e.top)this.visitNode(e.top),this.append(" ");if(this.append("into "),this.visitNode(e.into),e.using)this.append(" "),this.visitNode(e.using);if(e.whens)this.append(" "),this.compileList(e.whens," ");if(e.returning)this.append(" "),this.visitNode(e.returning);if(e.output)this.append(" "),this.visitNode(e.output);if(e.endModifiers?.length)this.append(" "),this.compileList(e.endModifiers," ")}visitMatched(e){if(e.not)this.append("not ");if(this.append("matched"),e.bySource)this.append(" by source")}visitAddIndex(e){if(this.append("add "),e.unique)this.append("unique ");if(this.append("index "),this.visitNode(e.name),e.columns)this.append(" ("),this.compileList(e.columns),this.append(")");if(e.using)this.append(" using "),this.visitNode(e.using)}visitCast(e){this.append("cast("),this.visitNode(e.expression),this.append(" as "),this.visitNode(e.dataType),this.append(")")}visitFetch(e){this.append("fetch next "),this.visitNode(e.rowCount),this.append(` rows ${e.modifier}`)}visitOutput(e){this.append("output "),this.compileList(e.selections)}visitTop(e){if(this.append(`top(${e.expression})`),e.modifiers)this.append(` ${e.modifiers}`)}visitOrAction(e){this.append(e.action)}visitCollate(e){this.append("collate "),this.visitNode(e.collation)}append(e){this.#e+=e}appendValue(e){this.addParameter(e),this.append(this.getCurrentParameterPlaceholder())}getLeftIdentifierWrapper(){return'"'}getRightIdentifierWrapper(){return'"'}getCurrentParameterPlaceholder(){return"$"+this.numParameters}getLeftExplainOptionsWrapper(){return"("}getExplainOptionAssignment(){return" "}getExplainOptionsDelimiter(){return", "}getRightExplainOptionsWrapper(){return")"}sanitizeIdentifier(e){let t=this.getLeftIdentifierWrapper(),r=this.getRightIdentifierWrapper(),i="";for(let n of e)if(i+=n,n===t)i+=t;else if(n===r)i+=r;return i}sanitizeStringLiteral(e){return e.replace(oi,"''")}sanitizeJSONPathMemberValue(e){return e.replace(ni,(t)=>t==="'"?"''":"\\\"")}addParameter(e){this.#t.push(e)}appendImmediateValue(e){if(fr(e))this.appendStringLiteral(e);else if(zs(e)||Vi(e)||Za(e))this.append(e.toString());else if(La(e))this.append("null");else if(nf(e))this.appendImmediateValue(e.toISOString());else throw Error(`invalid immediate value ${e}`)}appendStringLiteral(e){this.append("'"),this.append(this.sanitizeStringLiteral(e)),this.append("'")}sortSelectModifiers(e){return e.sort((t,r)=>t.modifier&&r.modifier?Ar[t.modifier]-Ar[r.modifier]:1),C(e)}compileColumnAlterations(e){this.compileList(e)}announcesNewColumnDataType(){return!0}}var si=C({ForKeyShare:"for key share",ForNoKeyUpdate:"for no key update",ForUpdate:"for update",ForShare:"for share",NoWait:"nowait",SkipLocked:"skip locked",Distinct:"distinct"}),Ar=C({ForKeyShare:1,ForNoKeyUpdate:1,ForUpdate:1,ForShare:1,NoWait:2,SkipLocked:2,Distinct:0}),ai=C({InnerJoin:"inner join",LeftJoin:"left join",RightJoin:"right join",FullJoin:"full join",CrossJoin:"cross join",LateralInnerJoin:"inner join lateral",LateralLeftJoin:"left join lateral",LateralCrossJoin:"cross join lateral",OuterApply:"outer apply",CrossApply:"cross apply",Using:"using"});var _m="kysely_migration",ym="kysely_migration_lock";function vm(e){let t=e.filter((i)=>i.pk>0),r=t.length===1?t[0]:void 0;return r?.type.toLowerCase()==="integer"?r.name:void 0}async function Tr(e,t,r){let i=vm(r);if(!i)return;let{rows:n}=await je`
3
3
  PRAGMA index_list(${je.id(t)})
4
- `.execute(e.withoutPlugins());return n.some((a)=>a.origin==="pk")?void 0:i}function af(e,t,r){return{name:e.name,isView:e.type==="view",columns:t.map((i)=>({name:i.name,dataType:i.type,isNullable:i.notnull===0,isAutoIncrementing:i.name===r,hasDefaultValue:i.dflt_value!=null}))}}async function pi(e,t){let{rows:r}=await je`
4
+ `.execute(e.withoutPlugins());return n.some((a)=>a.origin==="pk")?void 0:i}function lf(e,t,r){return{name:e.name,isView:e.type==="view",columns:t.map((i)=>({name:i.name,dataType:i.type,isNullable:i.notnull===0,isAutoIncrementing:i.name===r,hasDefaultValue:i.dflt_value!=null}))}}async function pi(e,t){let{rows:r}=await je`
5
5
  PRAGMA table_info(${je.id(t)})
6
- `.execute(e.withoutPlugins());if(r.length===0)return;let i=await Tr(e,t,r);return af({name:t},r,i)}async function qg(e,t){if(t.length===0)return[];try{return await e.introspection.getTables()}catch{return(await Promise.all(t.map((r)=>pi(e,r)))).filter((r)=>r!==void 0)}}function Lu(e){let t=e;async function r(){return[]}async function i(n={withInternalKyselyTables:!1}){let a=t.selectFrom("sqlite_schema").where("type","=","table").where("name","not like","sqlite_%").select("name");if(!n.withInternalKyselyTables)a=a.where("name","!=",gm).where("name","!=",Am);let j=await a.execute();return Promise.all(j.map(async({name:H})=>{let Y=await e.selectFrom(je`pragma_table_info(${H})`.as("table_info")).select(["cid","name","type","notnull","dflt_value","pk"]).execute(),we=await Tr(e,H,Y);return af({name:H},Y,we)}))}return{getSchemas:r,getTables:i,getMetadata:async(n)=>({tables:await i(n)})}}
7
- export{So,dr,zs,Vi,Fa,rf,La,zg,fr,sn,C,Io,st,jg,fo,po,mo,Rr,Wt,dc,Za,pm,tr,hi,is,mm,fc,Ba,_n,yr,Oe,nr,nf,It,Du,js,Ua,of,Nu,gi,sf,as,Fu,qs,Ho,hm,or,$s,je,ho,gm,Am,_m,af,qg,Lu};
6
+ `.execute(e.withoutPlugins());if(r.length===0)return;let i=await Tr(e,t,r);return lf({name:t},r,i)}async function Hg(e,t){if(t.length===0)return[];try{return await e.introspection.getTables()}catch{return(await Promise.all(t.map((r)=>pi(e,r)))).filter((r)=>r!==void 0)}}function Bu(e){let t=e;async function r(){return[]}async function i(n={withInternalKyselyTables:!1}){let a=t.selectFrom("sqlite_schema").where("type","=","table").where("name","not like","sqlite_%").select("name");if(!n.withInternalKyselyTables)a=a.where("name","!=",_m).where("name","!=",ym);let j=await a.execute();return Promise.all(j.map(async({name:H})=>{let Y=await e.selectFrom(je`pragma_table_info(${H})`.as("table_info")).select(["cid","name","type","notnull","dflt_value","pk"]).execute(),we=await Tr(e,H,Y);return lf({name:H},Y,we)}))}return{getSchemas:r,getTables:i,getMetadata:async(n)=>({tables:await i(n)})}}
7
+ export{So,fr,zs,Vi,La,nf,Za,qg,pr,sn,C,Io,st,$g,fo,po,mo,Rr,Wt,fc,Ba,hm,rr,hi,is,gm,pc,Ua,yn,yr,Oe,or,of,It,Fu,js,za,sf,Lu,gi,af,as,Zu,qs,Ho,Am,sr,$s,je,ho,_m,ym,vm,lf,Hg,Bu};
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- import{cc,uc}from"./chunk-mzsw9var.js";import{gm,Am,_m,af}from"./chunk-a411xhmm.js";function p(e){return`'${e.replaceAll("'","''")}'`}function f(e){return async(t)=>{if(t.length===0)return[];let n=(await e.batch(t.map((r)=>e.prepare(`PRAGMA index_list(${p(r)})`)))).flatMap((r,o)=>{let i=t[o];if(!i)return[];return r.results.map((u)=>({...u,tableName:i}))});if(n.length===0)return[];let l=await e.batch(n.map((r)=>e.prepare(`PRAGMA index_info(${p(r.name)})`)));return n.map((r,o)=>({columns:(l[o]?.results??[]).map((i)=>({fullLength:i.name!==null,name:i.name,position:i.seqno})),name:r.name,partial:r.partial!==0,table:r.tableName,unique:r.unique!==0,valid:!0}))}}var h=class extends uc{get supportsMultipleConnections(){return!0}},m=class{#e;#t;constructor(e){this.#e={...e}}async init(){if(this.#t=new w(this.#e.database),this.#e.onCreateConnection)await this.#e.onCreateConnection(this.#t)}async acquireConnection(){return this.#t}async beginTransaction(){throw Error("D1 does not support interactive transactions. Use the D1 batch() API instead.")}async commitTransaction(){throw Error("D1 does not support interactive transactions. Use the D1 batch() API instead.")}async rollbackTransaction(){throw Error("D1 does not support interactive transactions. Use the D1 batch() API instead.")}async releaseConnection(){}async destroy(){}},w=class{#e;constructor(e){this.#e=e}async executeQuery(e){let t=await this.#e.prepare(e.sql).bind(...e.parameters).all(),n=t.meta.changes!=null?BigInt(t.meta.changes):void 0;return{insertId:t.meta.last_row_id===void 0||t.meta.last_row_id===null?void 0:BigInt(t.meta.last_row_id),rows:t?.results||[],numAffectedRows:n}}async*streamQuery(){throw Error("D1 does not support streaming queries.")}},d=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}async getSchemas(){return[]}async getTables(e={withInternalKyselyTables:!1}){let t=this.#e.selectFrom("sqlite_master").where("type","in",["table","view"]).where("name","not like","sqlite_%").where("name","not like","_cf_%").select(["name","type"]).$castTo();if(!e.withInternalKyselyTables)t=t.where("name","!=",gm).where("name","!=",Am);let n=await t.execute();if(n.length===0)return[];let l=n.map((a)=>this.#t.prepare("SELECT * FROM pragma_table_info(?)").bind(a.name)),r=await this.#t.batch(l),o=n.flatMap((a,s)=>{let c=_m(r[s]?.results??[]);return c?[{index:s,tableName:a.name,column:c}]:[]}),i=o.length?await this.#t.batch(o.map(({tableName:a})=>this.#t.prepare(`PRAGMA index_list(${p(a)})`))):[],u=new Map(o.filter((a,s)=>!i[s]?.results?.some((c)=>c.origin==="pk")).map(({index:a,column:s})=>[a,s]));return n.map((a,s)=>af(a,r[s]?.results??[],u.get(s)))}async getMetadata(e){return{tables:await this.getTables(e)}}},y=class extends cc{},q=class{#e;constructor(e){this.#e={...e}}createDriver(){return new m(this.#e)}createQueryCompiler(){return new y}createAdapter(){return new h}createIntrospector(e){return new d(e,this.#e.database)}};export{q as D1SqliteDialect,f as createD1IndexIntrospector};
2
+ import{uc,dc}from"./chunk-q5x0yywj.js";import{_m,ym,vm,lf}from"./chunk-bd3v8mp1.js";function p(e){return`'${e.replaceAll("'","''")}'`}function f(e){return async(t)=>{if(t.length===0)return[];let n=(await e.batch(t.map((r)=>e.prepare(`PRAGMA index_list(${p(r)})`)))).flatMap((r,o)=>{let i=t[o];if(!i)return[];return r.results.map((u)=>({...u,tableName:i}))});if(n.length===0)return[];let l=await e.batch(n.map((r)=>e.prepare(`PRAGMA index_info(${p(r.name)})`)));return n.map((r,o)=>({columns:(l[o]?.results??[]).map((i)=>({fullLength:i.name!==null,name:i.name,position:i.seqno})),name:r.name,partial:r.partial!==0,table:r.tableName,unique:r.unique!==0,valid:!0}))}}var h=class extends dc{get supportsMultipleConnections(){return!0}},m=class{#e;#t;constructor(e){this.#e={...e}}async init(){if(this.#t=new w(this.#e.database),this.#e.onCreateConnection)await this.#e.onCreateConnection(this.#t)}async acquireConnection(){return this.#t}async beginTransaction(){throw Error("D1 does not support interactive transactions. Use the D1 batch() API instead.")}async commitTransaction(){throw Error("D1 does not support interactive transactions. Use the D1 batch() API instead.")}async rollbackTransaction(){throw Error("D1 does not support interactive transactions. Use the D1 batch() API instead.")}async releaseConnection(){}async destroy(){}},w=class{#e;constructor(e){this.#e=e}async executeQuery(e){let t=await this.#e.prepare(e.sql).bind(...e.parameters).all(),n=t.meta.changes!=null?BigInt(t.meta.changes):void 0;return{insertId:t.meta.last_row_id===void 0||t.meta.last_row_id===null?void 0:BigInt(t.meta.last_row_id),rows:t?.results||[],numAffectedRows:n}}async*streamQuery(){throw Error("D1 does not support streaming queries.")}},d=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}async getSchemas(){return[]}async getTables(e={withInternalKyselyTables:!1}){let t=this.#e.selectFrom("sqlite_master").where("type","in",["table","view"]).where("name","not like","sqlite_%").where("name","not like","_cf_%").select(["name","type"]).$castTo();if(!e.withInternalKyselyTables)t=t.where("name","!=",_m).where("name","!=",ym);let n=await t.execute();if(n.length===0)return[];let l=n.map((a)=>this.#t.prepare("SELECT * FROM pragma_table_info(?)").bind(a.name)),r=await this.#t.batch(l),o=n.flatMap((a,s)=>{let c=vm(r[s]?.results??[]);return c?[{index:s,tableName:a.name,column:c}]:[]}),i=o.length?await this.#t.batch(o.map(({tableName:a})=>this.#t.prepare(`PRAGMA index_list(${p(a)})`))):[],u=new Map(o.filter((a,s)=>!i[s]?.results?.some((c)=>c.origin==="pk")).map(({index:a,column:s})=>[a,s]));return n.map((a,s)=>lf(a,r[s]?.results??[],u.get(s)))}async getMetadata(e){return{tables:await this.getTables(e)}}},y=class extends uc{},q=class{#e;constructor(e){this.#e={...e}}createDriver(){return new m(this.#e)}createQueryCompiler(){return new y}createAdapter(){return new h}createIntrospector(e){return new d(e,this.#e.database)}};export{q as D1SqliteDialect,f as createD1IndexIntrospector};