@prisma/studio-core 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/{CPIOZS5X-NALOZFPD.js → CPIOZS5X-V4BHP4CI.js} +1 -1
  2. package/dist/{OKF6E45R-6KC3BLVB.js → OKF6E45R-XYOIK2NY.js} +1 -1
  3. package/dist/{adapter-Co8KY8Hi.d.cts → adapter-CKFCHq71.d.cts} +40 -5
  4. package/dist/{adapter-Co8KY8Hi.d.ts → adapter-CKFCHq71.d.ts} +40 -5
  5. package/dist/chunk-2ZJZX5I7.js +0 -0
  6. package/dist/chunk-BMVJYUJW.js +1 -0
  7. package/dist/chunk-P72NBTYE.js +1 -0
  8. package/dist/chunk-XS52QRY2.js +1 -0
  9. package/dist/data/accelerate/index.d.cts +2 -2
  10. package/dist/data/accelerate/index.d.ts +2 -2
  11. package/dist/data/accelerate/index.js +1 -1
  12. package/dist/data/bff/index.d.cts +2 -2
  13. package/dist/data/bff/index.d.ts +2 -2
  14. package/dist/data/bff/index.js +1 -1
  15. package/dist/data/index.cjs +1 -1
  16. package/dist/data/index.d.cts +2 -2
  17. package/dist/data/index.d.ts +2 -2
  18. package/dist/data/index.js +1 -1
  19. package/dist/data/pglite/index.cjs +1 -1
  20. package/dist/data/pglite/index.d.cts +22 -5
  21. package/dist/data/pglite/index.d.ts +22 -5
  22. package/dist/data/pglite/index.js +1 -1
  23. package/dist/data/postgres-core/index.cjs +1 -1
  24. package/dist/data/postgres-core/index.d.cts +35 -10
  25. package/dist/data/postgres-core/index.d.ts +35 -10
  26. package/dist/data/postgres-core/index.js +1 -1
  27. package/dist/{index-M4EjPWNJ.d.ts → index-BDPv5Gnt.d.ts} +19 -6
  28. package/dist/{index-CnVNNyod.d.cts → index-BNAA6jKD.d.cts} +19 -6
  29. package/dist/ui/index.cjs +62 -54
  30. package/dist/ui/index.css +154 -41
  31. package/dist/ui/index.d.cts +1 -1
  32. package/dist/ui/index.d.ts +1 -1
  33. package/dist/ui/index.js +14 -6
  34. package/package.json +5 -2
  35. package/dist/chunk-2FW6TKD6.js +0 -1
  36. package/dist/chunk-RGBMDID6.js +0 -1
  37. package/dist/chunk-ZCFLMQMM.js +0 -1
@@ -1 +0,0 @@
1
- function M(r){return typeof r>"u"||r===void 0}function C(r){return typeof r=="string"}function Pe(r){return typeof r=="number"}function Vr(r){return typeof r=="boolean"}function Ur(r){return r===null}function Jn(r){return r instanceof Date}function Jr(r){return typeof r=="bigint"}function O(r){return typeof r=="function"}function D(r){return typeof r=="object"&&r!==null}function t(r){return Object.freeze(r)}function dr(r){return A(r)?r:[r]}function A(r){return Array.isArray(r)}function re(r){return r}var l=t({is(r){return r.kind==="AlterTableNode"},create(r){return t({kind:"AlterTableNode",table:r})},cloneWithTableProps(r,e){return t({...r,...e})},cloneWithColumnAlteration(r,e){return t({...r,columnAlterations:r.columnAlterations?[...r.columnAlterations,e]:[e]})}});var c=t({is(r){return r.kind==="IdentifierNode"},create(r){return t({kind:"IdentifierNode",name:r})}});var G=t({is(r){return r.kind==="CreateIndexNode"},create(r){return t({kind:"CreateIndexNode",name:c.create(r)})},cloneWith(r,e){return t({...r,...e})},cloneWithColumns(r,e){return t({...r,columns:[...r.columns||[],...e]})}});var $r=t({is(r){return r.kind==="CreateSchemaNode"},create(r,e){return t({kind:"CreateSchemaNode",schema:c.create(r),...e})},cloneWith(r,e){return t({...r,...e})}});var xo=["preserve rows","delete rows","drop"],v=t({is(r){return r.kind==="CreateTableNode"},create(r){return t({kind:"CreateTableNode",table:r,columns:t([])})},cloneWithColumn(r,e){return t({...r,columns:t([...r.columns,e])})},cloneWithConstraint(r,e){return t({...r,constraints:r.constraints?t([...r.constraints,e]):t([e])})},cloneWithFrontModifier(r,e){return t({...r,frontModifiers:r.frontModifiers?t([...r.frontModifiers,e]):t([e])})},cloneWithEndModifier(r,e){return t({...r,endModifiers:r.endModifiers?t([...r.endModifiers,e]):t([e])})},cloneWith(r,e){return t({...r,...e})}});var P=t({is(r){return r.kind==="SchemableIdentifierNode"},create(r){return t({kind:"SchemableIdentifierNode",identifier:c.create(r)})},createWithSchema(r,e){return t({kind:"SchemableIdentifierNode",schema:c.create(r),identifier:c.create(e)})}});var ye=t({is(r){return r.kind==="DropIndexNode"},create(r,e){return t({kind:"DropIndexNode",name:P.create(r),...e})},cloneWith(r,e){return t({...r,...e})}});var cr=t({is(r){return r.kind==="DropSchemaNode"},create(r,e){return t({kind:"DropSchemaNode",schema:c.create(r),...e})},cloneWith(r,e){return t({...r,...e})}});var mr=t({is(r){return r.kind==="DropTableNode"},create(r,e){return t({kind:"DropTableNode",table:r,...e})},cloneWith(r,e){return t({...r,...e})}});var L=t({is(r){return r.kind==="AliasNode"},create(r,e){return t({kind:"AliasNode",node:r,alias:e})}});var $=t({is(r){return r.kind==="TableNode"},create(r){return t({kind:"TableNode",table:P.create(r)})},createWithSchema(r,e){return t({kind:"TableNode",table:P.createWithSchema(r,e)})}});function g(r){return D(r)&&O(r.toOperationNode)}function Oo(r){return D(r)&&"expressionType"in r&&g(r)}function Wo(r){return D(r)&&"expression"in r&&C(r.alias)&&g(r)}var te=t({is(r){return r.kind==="SelectModifierNode"},create(r,e){return t({kind:"SelectModifierNode",modifier:r,of:e})},createWithExpression(r){return t({kind:"SelectModifierNode",rawModifier:r})}});var F=t({is(r){return r.kind==="AndNode"},create(r,e){return t({kind:"AndNode",left:r,right:e})}});var j=t({is(r){return r.kind==="OrNode"},create(r,e){return t({kind:"OrNode",left:r,right:e})}});var Kr=t({is(r){return r.kind==="OnNode"},create(r){return t({kind:"OnNode",on:r})},cloneWithOperation(r,e,o){return t({...r,on:e==="And"?F.create(r.on,o):j.create(r.on,o)})}});var we=t({is(r){return r.kind==="JoinNode"},create(r,e){return t({kind:"JoinNode",joinType:r,table:e,on:void 0})},createWithOn(r,e,o){return t({kind:"JoinNode",joinType:r,table:e,on:Kr.create(o)})},cloneWithOn(r,e){return t({...r,on:r.on?Kr.cloneWithOperation(r.on,"And",e):Kr.create(e)})}});var xe=t({is(r){return r.kind==="BinaryOperationNode"},create(r,e,o){return t({kind:"BinaryOperationNode",leftOperand:r,operator:e,rightOperand:o})}});var pn=["=","==","!=","<>",">",">=","<","<=","in","not in","is","is not","like","not like","match","ilike","not ilike","@>","<@","^@","&&","?","?&","?|","!<","!>","<=>","!~","~","~*","!~*","@@","@@@","!!","<->","regexp","is distinct from","is not distinct from"],fn=["+","-","*","/","%","^","&","|","#","<<",">>"],go=["->","->>"],Nn=[...pn,...fn,"&&","||"],yn=["exists","not exists"],wn=["not","-",...yn],Co=[...Nn,...go,...wn,"between","between symmetric"],H=t({is(r){return r.kind==="OperatorNode"},create(r){return t({kind:"OperatorNode",operator:r})}});function At(r){return C(r)&&go.includes(r)}var h=t({is(r){return r.kind==="ColumnNode"},create(r){return t({kind:"ColumnNode",column:c.create(r)})}});var Le=t({is(r){return r.kind==="SelectAllNode"},create(){return t({kind:"SelectAllNode"})}});var Fe=t({is(r){return r.kind==="ReferenceNode"},create(r,e){return t({kind:"ReferenceNode",table:e,column:r})},createSelectAll(r){return t({kind:"ReferenceNode",table:r,column:Le.create()})}});var Gr=class{#e;get dynamicReference(){return this.#e}get refType(){}constructor(e){this.#e=e}toOperationNode(){return Et(this.#e)}};function jr(r){return D(r)&&g(r)&&C(r.dynamicReference)}var Hr=t({is(r){return r.kind==="OrderByItemNode"},create(r,e){return t({kind:"OrderByItemNode",orderBy:r,direction:e})}});var V=t({is(r){return r.kind==="RawNode"},create(r,e){return t({kind:"RawNode",sqlFragments:t(r),parameters:t(e)})},createWithSql(r){return V.create([r],[])},createWithChild(r){return V.create(["",""],[r])},createWithChildren(r){return V.create(new Array(r.length+1).fill(""),r)}});function Bt(r){return r==="asc"||r==="desc"}function Oe(r){if(r.length===2)return[Rt(r[0],r[1])];if(r.length===1){let[e]=r;return Array.isArray(e)?e.map(o=>Rt(o)):[Rt(e)]}throw new Error(`Invalid number of arguments at order by! expected 1-2, received ${r.length}`)}function Rt(r,e){let o=xn(r);if(Hr.is(o)){if(e)throw new Error("Cannot specify direction twice!");return o}return Hr.create(o,qo(e))}function xn(r){if(ce(r))return z(r);if(jr(r))return r.toOperationNode();let[e,o]=r.split(" ");if(o){if(!Bt(o))throw new Error(`Invalid order by direction: ${o}`);return Hr.create(Y(e),qo(o))}return Y(r)}function qo(r){if(r)return r==="asc"||r==="desc"?V.createWithSql(r):r.toOperationNode()}var ze=t({is(r){return r.kind==="JSONReferenceNode"},create(r,e){return t({kind:"JSONReferenceNode",reference:r,traversal:e})},cloneWithTraversal(r,e){return t({...r,traversal:e})}});var Yr=t({is(r){return r.kind==="JSONOperatorChainNode"},create(r){return t({kind:"JSONOperatorChainNode",operator:r,values:t([])})},cloneWithValue(r,e){return t({...r,values:t([...r.values,e])})}});var We=t({is(r){return r.kind==="JSONPathNode"},create(r){return t({kind:"JSONPathNode",inOperator:r,pathLegs:t([])})},cloneWithLeg(r,e){return t({...r,pathLegs:t([...r.pathLegs,e])})}});function Et(r){return C(r)?Y(r):r.toOperationNode()}function me(r){return A(r)?r.map(e=>b(e)):[b(r)]}function b(r){return ce(r)?z(r):Et(r)}function To(r,e){let o=Y(r);if(At(e))return ze.create(o,Yr.create(H.create(e)));let i=e.slice(0,-1);if(At(i))return ze.create(o,We.create(H.create(i)));throw new Error(`Invalid JSON operator: ${e}`)}function Y(r){let e=".";if(!r.includes(e))return Fe.create(h.create(r));let o=r.split(e).map(Qt);if(o.length===3)return On(o);if(o.length===2)return Wn(o);throw new Error(`invalid column reference ${r}`)}function bo(r){let e=" as ";if(r.includes(e)){let[o,i]=r.split(e).map(Qt);return L.create(Y(o),c.create(i))}else return Y(r)}function Dt(r){return h.create(r)}function Me(r){let e=" ";if(r.includes(e)){let[o,i]=r.split(e).map(Qt);if(!Bt(i))throw new Error(`invalid order direction "${i}" next to "${o}"`);return Oe([o,i])[0]}else return Dt(r)}function On(r){let[e,o,i]=r;return Fe.create(h.create(i),$.createWithSchema(e,o))}function Wn(r){let[e,o]=r;return Fe.create(h.create(o),$.create(e))}function Qt(r){return r.trim()}var Xr=t({is(r){return r.kind==="PrimitiveValueListNode"},create(r){return t({kind:"PrimitiveValueListNode",values:t([...r])})}});var ge=t({is(r){return r.kind==="ValueListNode"},create(r){return t({kind:"ValueListNode",values:t(r)})}});var k=t({is(r){return r.kind==="ValueNode"},create(r){return t({kind:"ValueNode",value:r})},createImmediate(r){return t({kind:"ValueNode",value:r,immediate:!0})}});function ko(r){return A(r)?gn(r):w(r)}function w(r){return ce(r)?z(r):k.create(r)}function Zr(r){return Pe(r)||Vr(r)||Ur(r)}function hr(r){if(!Zr(r))throw new Error(`unsafe immediate value ${JSON.stringify(r)}`);return k.createImmediate(r)}function gn(r){return r.some(ce)?ge.create(r.map(e=>w(e))):Xr.create(r)}var Ce=t({is(r){return r.kind==="ParensNode"},create(r){return t({kind:"ParensNode",node:r})}});function N(r){if(r.length===3)return _r(r[0],r[1],r[2]);if(r.length===1)return w(r[0]);throw new Error(`invalid arguments: ${JSON.stringify(r)}`)}function _r(r,e,o){return Cn(e)&&So(o)?xe.create(b(r),vt(e),k.createImmediate(o)):xe.create(b(r),vt(e),ko(o))}function T(r,e,o){return xe.create(b(r),vt(e),b(o))}function Pt(r,e){return Ve(Object.entries(r).filter(([,o])=>!M(o)).map(([o,i])=>_r(o,So(i)?"is":"=",i)),e)}function Ve(r,e,o=!0){let i=e==="and"?F.create:j.create;if(r.length===0)return xe.create(k.createImmediate(1),H.create("="),k.createImmediate(e==="and"?1:0));let s=Io(r[0]);for(let d=1;d<r.length;++d)s=i(s,Io(r[d]));return r.length>1&&o?Ce.create(s):s}function Cn(r){return r==="is"||r==="is not"}function So(r){return Ur(r)||Vr(r)}function vt(r){if(C(r)&&Co.includes(r))return H.create(r);if(g(r))return r.toOperationNode();throw new Error(`invalid operator ${JSON.stringify(r)}`)}function Io(r){return g(r)?r.toOperationNode():r}var he=t({is(r){return r.kind==="OrderByNode"},create(r){return t({kind:"OrderByNode",items:t([...r])})},cloneWithItems(r,e){return t({...r,items:t([...r.items,...e])})}});var Lt=t({is(r){return r.kind==="PartitionByNode"},create(r){return t({kind:"PartitionByNode",items:t(r)})},cloneWithItems(r,e){return t({...r,items:t([...r.items,...e])})}});var lr=t({is(r){return r.kind==="OverNode"},create(){return t({kind:"OverNode"})},cloneWithOrderByItems(r,e){return t({...r,orderBy:r.orderBy?he.cloneWithItems(r.orderBy,e):he.create(e)})},cloneWithPartitionByItems(r,e){return t({...r,partitionBy:r.partitionBy?Lt.cloneWithItems(r.partitionBy,e):Lt.create(e)})}});var Ae=t({is(r){return r.kind==="FromNode"},create(r){return t({kind:"FromNode",froms:t(r)})},cloneWithFroms(r,e){return t({...r,froms:t([...r.froms,...e])})}});var Ft=t({is(r){return r.kind==="GroupByNode"},create(r){return t({kind:"GroupByNode",items:t(r)})},cloneWithItems(r,e){return t({...r,items:t([...r.items,...e])})}});var zt=t({is(r){return r.kind==="HavingNode"},create(r){return t({kind:"HavingNode",having:r})},cloneWithOperation(r,e,o){return t({...r,having:e==="And"?F.create(r.having,o):j.create(r.having,o)})}});var m=t({is(r){return r.kind==="SelectQueryNode"},create(r){return t({kind:"SelectQueryNode",...r&&{with:r}})},createFrom(r,e){return t({kind:"SelectQueryNode",from:Ae.create(r),...e&&{with:e}})},cloneWithSelections(r,e){return t({...r,selections:r.selections?t([...r.selections,...e]):t(e)})},cloneWithDistinctOn(r,e){return t({...r,distinctOn:r.distinctOn?t([...r.distinctOn,...e]):t(e)})},cloneWithFrontModifier(r,e){return t({...r,frontModifiers:r.frontModifiers?t([...r.frontModifiers,e]):t([e])})},cloneWithEndModifier(r,e){return t({...r,endModifiers:r.endModifiers?t([...r.endModifiers,e]):t([e])})},cloneWithOrderByItems(r,e){return t({...r,orderBy:r.orderBy?he.cloneWithItems(r.orderBy,e):he.create(e)})},cloneWithGroupByItems(r,e){return t({...r,groupBy:r.groupBy?Ft.cloneWithItems(r.groupBy,e):Ft.create(e)})},cloneWithLimit(r,e){return t({...r,limit:e})},cloneWithOffset(r,e){return t({...r,offset:e})},cloneWithFetch(r,e){return t({...r,fetch:e})},cloneWithHaving(r,e){return t({...r,having:r.having?zt.cloneWithOperation(r.having,"And",e):zt.create(e)})},cloneWithSetOperations(r,e){return t({...r,setOperations:r.setOperations?t([...r.setOperations,...e]):t([...e])})},cloneWithoutSelections(r){return t({...r,selections:[]})},cloneWithoutLimit(r){return t({...r,limit:void 0})},cloneWithoutOffset(r){return t({...r,offset:void 0})},cloneWithoutOrderBy(r){return t({...r,orderBy:void 0})},cloneWithoutGroupBy(r){return t({...r,groupBy:void 0})}});function a(r,e){Object.defineProperties(r.prototype,{then:{enumerable:!1,value:()=>{throw new Error(e)}}})}var pr=class r{#e;constructor(e){this.#e=t(e)}on(...e){return new r({...this.#e,joinNode:we.cloneWithOn(this.#e.joinNode,N(e))})}onRef(e,o,i){return new r({...this.#e,joinNode:we.cloneWithOn(this.#e.joinNode,T(e,o,i))})}onTrue(){return new r({...this.#e,joinNode:we.cloneWithOn(this.#e.joinNode,V.createWithSql("true"))})}$call(e){return e(this)}toOperationNode(){return this.#e.joinNode}};a(pr,"don't await JoinBuilder instances. They are never executed directly and are always just a part of a query.");var Ao=t({is(r){return r.kind==="PartitionByItemNode"},create(r){return t({kind:"PartitionByItemNode",partitionBy:r})}});function Eo(r){return me(r).map(Ao.create)}var fr=class r{#e;constructor(e){this.#e=t(e)}orderBy(e,o){return new r({overNode:lr.cloneWithOrderByItems(this.#e.overNode,Oe([e,o]))})}partitionBy(e){return new r({overNode:lr.cloneWithPartitionByItems(this.#e.overNode,Eo(e))})}$call(e){return e(this)}toOperationNode(){return this.#e.overNode}};a(fr,"don't await OverBuilder instances. They are never executed directly and are always just a part of a query.");var Ue=t({is(r){return r.kind==="SelectionNode"},create(r){return t({kind:"SelectionNode",selection:r})},createSelectAll(){return t({kind:"SelectionNode",selection:Le.create()})},createSelectAllFromTable(r){return t({kind:"SelectionNode",selection:Fe.createSelectAll(r)})}});function I(r){return O(r)?I(r(X())):A(r)?r.map(e=>Ro(e)):[Ro(r)]}function Ro(r){return C(r)?Ue.create(bo(r)):jr(r)?Ue.create(r.toOperationNode()):Ue.create(et(r))}function E(r){return r?Array.isArray(r)?r.map(Bo):[Bo(r)]:[Ue.createSelectAll()]}function Bo(r){if(C(r))return Ue.createSelectAllFromTable(p(r));throw new Error(`invalid value selectAll expression: ${JSON.stringify(r)}`)}var Do=t({is(r){return r.kind==="ValuesNode"},create(r){return t({kind:"ValuesNode",values:t(r)})}});var Qo=t({is(r){return r.kind==="DefaultInsertValueNode"},create(){return t({kind:"DefaultInsertValueNode"})}});function rt(r){let e=O(r)?r(X()):r,o=A(e)?e:t([e]);return qn(o)}function qn(r){let e=Tn(r);return[t([...e.keys()].map(h.create)),Do.create(r.map(o=>bn(o,e)))]}function Tn(r){let e=new Map;for(let o of r){let i=Object.keys(o);for(let s of i)!e.has(s)&&o[s]!==void 0&&e.set(s,e.size)}return e}function bn(r,e){let o=Object.keys(r),i=Array.from({length:e.size}),s=!1;for(let x of o){let B=e.get(x);if(M(B))continue;let de=r[x];(M(de)||ce(de))&&(s=!0),i[B]=de}if(o.length<e.size||s){let x=Qo.create();return ge.create(i.map(B=>M(B)?x:w(B)))}return Xr.create(i)}var R=t({is(r){return r.kind==="InsertQueryNode"},create(r,e,o){return t({kind:"InsertQueryNode",into:r,...e&&{with:e},replace:o})},createWithoutInto(){return t({kind:"InsertQueryNode"})},cloneWith(r,e){return t({...r,...e})}});var oe=t({is(r){return r.kind==="UpdateQueryNode"},create(r,e){return t({kind:"UpdateQueryNode",table:r,...e&&{with:e}})},createWithoutTable(){return t({kind:"UpdateQueryNode"})},cloneWithFromItems(r,e){return t({...r,from:r.from?Ae.cloneWithFroms(r.from,e):Ae.create(e)})},cloneWithUpdates(r,e){return t({...r,updates:r.updates?t([...r.updates,...e]):e})},cloneWithLimit(r,e){return t({...r,limit:e})}});var Mt=t({is(r){return r.kind==="UsingNode"},create(r){return t({kind:"UsingNode",tables:t(r)})},cloneWithTables(r,e){return t({...r,tables:t([...r.tables,...e])})}});var ne=t({is(r){return r.kind==="DeleteQueryNode"},create(r,e){return t({kind:"DeleteQueryNode",from:Ae.create(r),...e&&{with:e}})},cloneWithOrderByItems(r,e){return t({...r,orderBy:r.orderBy?he.cloneWithItems(r.orderBy,e):he.create(e)})},cloneWithoutOrderBy(r){return t({...r,orderBy:void 0})},cloneWithLimit(r,e){return t({...r,limit:e})},cloneWithoutLimit(r){return t({...r,limit:void 0})},cloneWithUsing(r,e){return t({...r,using:r.using!==void 0?Mt.cloneWithTables(r.using,e):Mt.create(e)})}});var S=t({is(r){return r.kind==="WhereNode"},create(r){return t({kind:"WhereNode",where:r})},cloneWithOperation(r,e,o){return t({...r,where:e==="And"?F.create(r.where,o):j.create(r.where,o)})}});var Vt=t({is(r){return r.kind==="ReturningNode"},create(r){return t({kind:"ReturningNode",selections:t(r)})},cloneWithSelections(r,e){return t({...r,selections:r.selections?t([...r.selections,...e]):t(e)})}});var vo=t({is(r){return r.kind==="ExplainNode"},create(r,e){return t({kind:"ExplainNode",format:r,options:e})}});var le=t({is(r){return r.kind==="WhenNode"},create(r){return t({kind:"WhenNode",condition:r})},cloneWithResult(r,e){return t({...r,result:e})}});var U=t({is(r){return r.kind==="MergeQueryNode"},create(r,e){return t({kind:"MergeQueryNode",into:r,...e&&{with:e}})},cloneWithUsing(r,e){return t({...r,using:e})},cloneWithWhen(r,e){return t({...r,whens:r.whens?t([...r.whens,e]):t([e])})},cloneWithThen(r,e){return t({...r,whens:r.whens?t([...r.whens.slice(0,-1),le.cloneWithResult(r.whens[r.whens.length-1],e)]):void 0})}});var Ut=t({is(r){return r.kind==="OutputNode"},create(r){return t({kind:"OutputNode",selections:t(r)})},cloneWithSelections(r,e){return t({...r,selections:r.selections?t([...r.selections,...e]):t(e)})}});var u=t({is(r){return m.is(r)||R.is(r)||oe.is(r)||ne.is(r)||U.is(r)},cloneWithWhere(r,e){return t({...r,where:r.where?S.cloneWithOperation(r.where,"And",e):S.create(e)})},cloneWithJoin(r,e){return t({...r,joins:r.joins?t([...r.joins,e]):t([e])})},cloneWithReturning(r,e){return t({...r,returning:r.returning?Vt.cloneWithSelections(r.returning,e):Vt.create(e)})},cloneWithoutReturning(r){return t({...r,returning:void 0})},cloneWithoutWhere(r){return t({...r,where:void 0})},cloneWithExplain(r,e,o){return t({...r,explain:vo.create(e,o?.toOperationNode())})},cloneWithTop(r,e){return t({...r,top:e})},cloneWithOutput(r,e){return t({...r,output:r.output?Ut.cloneWithSelections(r.output,e):Ut.create(e)})}});var Jt=t({is(r){return r.kind==="ColumnUpdateNode"},create(r,e){return t({kind:"ColumnUpdateNode",column:r,value:e})}});function Po(...r){return r.length===2?[Jt.create(b(r[0]),w(r[1]))]:Nr(r[0])}function Nr(r){let e=O(r)?r(X()):r;return Object.entries(e).filter(([o,i])=>i!==void 0).map(([o,i])=>Jt.create(h.create(o),w(i)))}var Lo=t({is(r){return r.kind==="OnDuplicateKeyNode"},create(r){return t({kind:"OnDuplicateKeyNode",updates:r})}});var tt=class{insertId;numInsertedOrUpdatedRows;constructor(e,o){this.insertId=e,this.numInsertedOrUpdatedRows=o}};var K=class extends Error{node;constructor(e){super("no result"),this.node=e}};function ie(r){return Object.prototype.hasOwnProperty.call(r,"prototype")}var Q=t({is(r){return r.kind==="OnConflictNode"},create(){return t({kind:"OnConflictNode"})},cloneWith(r,e){return t({...r,...e})},cloneWithIndexWhere(r,e){return t({...r,indexWhere:r.indexWhere?S.cloneWithOperation(r.indexWhere,"And",e):S.create(e)})},cloneWithIndexOrWhere(r,e){return t({...r,indexWhere:r.indexWhere?S.cloneWithOperation(r.indexWhere,"Or",e):S.create(e)})},cloneWithUpdateWhere(r,e){return t({...r,updateWhere:r.updateWhere?S.cloneWithOperation(r.updateWhere,"And",e):S.create(e)})},cloneWithUpdateOrWhere(r,e){return t({...r,updateWhere:r.updateWhere?S.cloneWithOperation(r.updateWhere,"Or",e):S.create(e)})},cloneWithoutIndexWhere(r){return t({...r,indexWhere:void 0})},cloneWithoutUpdateWhere(r){return t({...r,updateWhere:void 0})}});var yr=class r{#e;constructor(e){this.#e=t(e)}column(e){let o=h.create(e);return new r({...this.#e,onConflictNode:Q.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?t([...this.#e.onConflictNode.columns,o]):t([o])})})}columns(e){let o=e.map(h.create);return new r({...this.#e,onConflictNode:Q.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?t([...this.#e.onConflictNode.columns,...o]):t(o)})})}constraint(e){return new r({...this.#e,onConflictNode:Q.cloneWith(this.#e.onConflictNode,{constraint:c.create(e)})})}expression(e){return new r({...this.#e,onConflictNode:Q.cloneWith(this.#e.onConflictNode,{indexExpression:e.toOperationNode()})})}where(...e){return new r({...this.#e,onConflictNode:Q.cloneWithIndexWhere(this.#e.onConflictNode,N(e))})}whereRef(e,o,i){return new r({...this.#e,onConflictNode:Q.cloneWithIndexWhere(this.#e.onConflictNode,T(e,o,i))})}clearWhere(){return new r({...this.#e,onConflictNode:Q.cloneWithoutIndexWhere(this.#e.onConflictNode)})}doNothing(){return new ot({...this.#e,onConflictNode:Q.cloneWith(this.#e.onConflictNode,{doNothing:!0})})}doUpdateSet(e){return new nt({...this.#e,onConflictNode:Q.cloneWith(this.#e.onConflictNode,{updates:Nr(e)})})}$call(e){return e(this)}};a(yr,"don't await OnConflictBuilder instances.");var ot=class{#e;constructor(e){this.#e=t(e)}toOperationNode(){return this.#e.onConflictNode}};a(ot,"don't await OnConflictDoNothingBuilder instances.");var nt=class r{#e;constructor(e){this.#e=t(e)}where(...e){return new r({...this.#e,onConflictNode:Q.cloneWithUpdateWhere(this.#e.onConflictNode,N(e))})}whereRef(e,o,i){return new r({...this.#e,onConflictNode:Q.cloneWithUpdateWhere(this.#e.onConflictNode,T(e,o,i))})}clearWhere(){return new r({...this.#e,onConflictNode:Q.cloneWithoutUpdateWhere(this.#e.onConflictNode)})}$call(e){return e(this)}toOperationNode(){return this.#e.onConflictNode}};a(nt,"don't await OnConflictUpdateBuilder instances.");var Fo=t({is(r){return r.kind==="TopNode"},create(r,e){return t({kind:"TopNode",expression:r,modifiers:e})}});function Z(r,e){if(!Pe(r)&&!Jr(r))throw new Error(`Invalid top expression: ${r}`);if(!M(e)&&!kn(e))throw new Error(`Invalid top modifiers: ${e}`);return Fo.create(r,e)}function kn(r){return r==="percent"||r==="with ties"||r==="percent with ties"}var Je=class r{#e;constructor(e){this.#e=t(e)}values(e){let[o,i]=rt(e);return new r({...this.#e,queryNode:R.cloneWith(this.#e.queryNode,{columns:o,values:i})})}columns(e){return new r({...this.#e,queryNode:R.cloneWith(this.#e.queryNode,{columns:t(e.map(h.create))})})}expression(e){return new r({...this.#e,queryNode:R.cloneWith(this.#e.queryNode,{values:z(e)})})}defaultValues(){return new r({...this.#e,queryNode:R.cloneWith(this.#e.queryNode,{defaultValues:!0})})}ignore(){return new r({...this.#e,queryNode:R.cloneWith(this.#e.queryNode,{ignore:!0})})}top(e,o){return new r({...this.#e,queryNode:u.cloneWithTop(this.#e.queryNode,Z(e,o))})}onConflict(e){return new r({...this.#e,queryNode:R.cloneWith(this.#e.queryNode,{onConflict:e(new yr({onConflictNode:Q.create()})).toOperationNode()})})}onDuplicateKeyUpdate(e){return new r({...this.#e,queryNode:R.cloneWith(this.#e.queryNode,{onDuplicateKey:Lo.create(Nr(e))})})}returning(e){return new r({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,I(e))})}returningAll(){return new r({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,E())})}output(e){return new r({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,I(e))})}outputAll(e){return new r({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,E(e))})}clearReturning(){return new r({...this.#e,queryNode:u.cloneWithoutReturning(this.#e.queryNode)})}$call(e){return e(this)}$if(e,o){return e?o(this):new r({...this.#e})}$castTo(){return new r(this.#e)}$narrowType(){return new r(this.#e)}$assertType(){return new r(this.#e)}withPlugin(e){return new r({...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(),o=await this.#e.executor.executeQuery(e,this.#e.queryId),{adapter:i}=this.#e.executor,s=e.query;return s.returning&&i.supportsReturning||s.output&&i.supportsOutput?o.rows:[new tt(o.insertId,o.numAffectedRows??o.numUpdatedOrDeletedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=K){let o=await this.executeTakeFirst();if(o===void 0)throw ie(e)?new e(this.toOperationNode()):e(this.toOperationNode());return o}async*stream(e=100){let o=this.compile(),i=this.#e.executor.stream(o,e,this.#e.queryId);for await(let s of i)yield*s.rows}async explain(e,o){return await new r({...this.#e,queryNode:u.cloneWithExplain(this.#e.queryNode,e,o)}).execute()}};a(Je,"don't await InsertQueryBuilder instances directly. To execute the query you need to call `execute` or `executeTakeFirst`.");var it=class{numDeletedRows;constructor(e){this.numDeletedRows=e}};var $e=t({is(r){return r.kind==="LimitNode"},create(r){return t({kind:"LimitNode",limit:r})}});var wr=class r{#e;constructor(e){this.#e=t(e)}where(...e){return new r({...this.#e,queryNode:u.cloneWithWhere(this.#e.queryNode,N(e))})}whereRef(e,o,i){return new r({...this.#e,queryNode:u.cloneWithWhere(this.#e.queryNode,T(e,o,i))})}clearWhere(){return new r({...this.#e,queryNode:u.cloneWithoutWhere(this.#e.queryNode)})}top(e,o){return new r({...this.#e,queryNode:u.cloneWithTop(this.#e.queryNode,Z(e,o))})}using(e){return new r({...this.#e,queryNode:ne.cloneWithUsing(this.#e.queryNode,se(e))})}innerJoin(...e){return new r({...this.#e,queryNode:u.cloneWithJoin(this.#e.queryNode,q("InnerJoin",e))})}leftJoin(...e){return new r({...this.#e,queryNode:u.cloneWithJoin(this.#e.queryNode,q("LeftJoin",e))})}rightJoin(...e){return new r({...this.#e,queryNode:u.cloneWithJoin(this.#e.queryNode,q("RightJoin",e))})}fullJoin(...e){return new r({...this.#e,queryNode:u.cloneWithJoin(this.#e.queryNode,q("FullJoin",e))})}returning(e){return new r({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,I(e))})}returningAll(e){return new r({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,E(e))})}output(e){return new r({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,I(e))})}outputAll(e){return new r({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,E(e))})}clearReturning(){return new r({...this.#e,queryNode:u.cloneWithoutReturning(this.#e.queryNode)})}clearLimit(){return new r({...this.#e,queryNode:ne.cloneWithoutLimit(this.#e.queryNode)})}clearOrderBy(){return new r({...this.#e,queryNode:ne.cloneWithoutOrderBy(this.#e.queryNode)})}orderBy(e,o){return new r({...this.#e,queryNode:ne.cloneWithOrderByItems(this.#e.queryNode,Oe([e,o]))})}limit(e){return new r({...this.#e,queryNode:ne.cloneWithLimit(this.#e.queryNode,$e.create(w(e)))})}$call(e){return e(this)}$if(e,o){return e?o(this):new r({...this.#e})}$castTo(){return new r(this.#e)}$narrowType(){return new r(this.#e)}$assertType(){return new r(this.#e)}withPlugin(e){return new r({...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(),o=await this.#e.executor.executeQuery(e,this.#e.queryId),{adapter:i}=this.#e.executor,s=e.query;return s.returning&&i.supportsReturning||s.output&&i.supportsOutput?o.rows:[new it(o.numAffectedRows??o.numUpdatedOrDeletedRows??BigInt(0))]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=K){let o=await this.executeTakeFirst();if(o===void 0)throw ie(e)?new e(this.toOperationNode()):e(this.toOperationNode());return o}async*stream(e=100){let o=this.compile(),i=this.#e.executor.stream(o,e,this.#e.queryId);for await(let s of i)yield*s.rows}async explain(e,o){return await new r({...this.#e,queryNode:u.cloneWithExplain(this.#e.queryNode,e,o)}).execute()}};a(wr,"don't await DeleteQueryBuilder instances directly. To execute the query you need to call `execute` or `executeTakeFirst`.");var st=class{numUpdatedRows;numChangedRows;constructor(e,o){this.numUpdatedRows=e,this.numChangedRows=o}};var Ee=class r{#e;constructor(e){this.#e=t(e)}where(...e){return new r({...this.#e,queryNode:u.cloneWithWhere(this.#e.queryNode,N(e))})}whereRef(e,o,i){return new r({...this.#e,queryNode:u.cloneWithWhere(this.#e.queryNode,T(e,o,i))})}clearWhere(){return new r({...this.#e,queryNode:u.cloneWithoutWhere(this.#e.queryNode)})}top(e,o){return new r({...this.#e,queryNode:u.cloneWithTop(this.#e.queryNode,Z(e,o))})}from(e){return new r({...this.#e,queryNode:oe.cloneWithFromItems(this.#e.queryNode,se(e))})}innerJoin(...e){return new r({...this.#e,queryNode:u.cloneWithJoin(this.#e.queryNode,q("InnerJoin",e))})}leftJoin(...e){return new r({...this.#e,queryNode:u.cloneWithJoin(this.#e.queryNode,q("LeftJoin",e))})}rightJoin(...e){return new r({...this.#e,queryNode:u.cloneWithJoin(this.#e.queryNode,q("RightJoin",e))})}fullJoin(...e){return new r({...this.#e,queryNode:u.cloneWithJoin(this.#e.queryNode,q("FullJoin",e))})}limit(e){return new r({...this.#e,queryNode:oe.cloneWithLimit(this.#e.queryNode,$e.create(w(e)))})}set(...e){return new r({...this.#e,queryNode:oe.cloneWithUpdates(this.#e.queryNode,Po(...e))})}returning(e){return new r({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,I(e))})}returningAll(e){return new r({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,E(e))})}output(e){return new r({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,I(e))})}outputAll(e){return new r({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,E(e))})}clearReturning(){return new r({...this.#e,queryNode:u.cloneWithoutReturning(this.#e.queryNode)})}$call(e){return e(this)}$if(e,o){return e?o(this):new r({...this.#e})}$castTo(){return new r(this.#e)}$narrowType(){return new r(this.#e)}$assertType(){return new r(this.#e)}withPlugin(e){return new r({...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(),o=await this.#e.executor.executeQuery(e,this.#e.queryId),{adapter:i}=this.#e.executor,s=e.query;return s.returning&&i.supportsReturning||s.output&&i.supportsOutput?o.rows:[new st(o.numAffectedRows??o.numUpdatedOrDeletedRows??BigInt(0),o.numChangedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=K){let o=await this.executeTakeFirst();if(o===void 0)throw ie(e)?new e(this.toOperationNode()):e(this.toOperationNode());return o}async*stream(e=100){let o=this.compile(),i=this.#e.executor.stream(o,e,this.#e.queryId);for await(let s of i)yield*s.rows}async explain(e,o){return await new r({...this.#e,queryNode:u.cloneWithExplain(this.#e.queryNode,e,o)}).execute()}};a(Ee,"don't await UpdateQueryBuilder instances directly. To execute the query you need to call `execute` or `executeTakeFirst`.");var $t=t({is(r){return r.kind==="CommonTableExpressionNameNode"},create(r,e){return t({kind:"CommonTableExpressionNameNode",table:$.create(r),columns:e?t(e.map(h.create)):void 0})}});var Ke=t({is(r){return r.kind==="CommonTableExpressionNode"},create(r,e){return t({kind:"CommonTableExpressionNode",name:r,expression:e})},cloneWith(r,e){return t({...r,...e})}});var xr=class r{#e;constructor(e){this.#e=t(e)}materialized(){return new r({...this.#e,node:Ke.cloneWith(this.#e.node,{materialized:!0})})}notMaterialized(){return new r({...this.#e,node:Ke.cloneWith(this.#e.node,{materialized:!1})})}toOperationNode(){return this.#e.node}};a(xr,"don't await CTEBuilder instances. They are never executed directly and are always just a part of a query.");function Kt(r,e){let o=e(Mo()).toOperationNode();return O(r)?r(In(o)).toOperationNode():Ke.create(zo(r),o)}function In(r){return e=>new xr({node:Ke.create(zo(e),r)})}function zo(r){if(r.includes("(")){let e=r.split(/[\(\)]/),o=e[0],i=e[1].split(",").map(s=>s.trim());return $t.create(o,i)}else return $t.create(r)}var Or=t({is(r){return r.kind==="WithNode"},create(r,e){return t({kind:"WithNode",expressions:t([r]),...e})},cloneWithExpression(r,e){return t({...r,expressions:t([...r.expressions,e])})}});var Vo=["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 Uo(r){let e="";for(let o=0;o<r;++o)e+=Sn();return e}function Sn(){return Vo[~~(Math.random()*Vo.length)]}function W(){return new Gt}var Gt=class{#e;get queryId(){return this.#e===void 0&&(this.#e=Uo(8)),this.#e}};var qe=class{nodeStack=[];#e=t({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),ForeignKeyConstraintNode:this.transformForeignKeyConstraint.bind(this),CreateViewNode:this.transformCreateView.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)});transformNode(e){if(!e)return e;this.nodeStack.push(e);let o=this.transformNodeImpl(e);return this.nodeStack.pop(),t(o)}transformNodeImpl(e){return this.#e[e.kind](e)}transformNodeList(e){return e&&t(e.map(o=>this.transformNode(o)))}transformSelectQuery(e){return{kind:"SelectQueryNode",from:this.transformNode(e.from),selections:this.transformNodeList(e.selections),distinctOn:this.transformNodeList(e.distinctOn),joins:this.transformNodeList(e.joins),groupBy:this.transformNode(e.groupBy),orderBy:this.transformNode(e.orderBy),where:this.transformNode(e.where),frontModifiers:this.transformNodeList(e.frontModifiers),endModifiers:this.transformNodeList(e.endModifiers),limit:this.transformNode(e.limit),offset:this.transformNode(e.offset),with:this.transformNode(e.with),having:this.transformNode(e.having),explain:this.transformNode(e.explain),setOperations:this.transformNodeList(e.setOperations),fetch:this.transformNode(e.fetch),top:this.transformNode(e.top)}}transformSelection(e){return{kind:"SelectionNode",selection:this.transformNode(e.selection)}}transformColumn(e){return{kind:"ColumnNode",column:this.transformNode(e.column)}}transformAlias(e){return{kind:"AliasNode",node:this.transformNode(e.node),alias:this.transformNode(e.alias)}}transformTable(e){return{kind:"TableNode",table:this.transformNode(e.table)}}transformFrom(e){return{kind:"FromNode",froms:this.transformNodeList(e.froms)}}transformReference(e){return{kind:"ReferenceNode",column:this.transformNode(e.column),table:this.transformNode(e.table)}}transformAnd(e){return{kind:"AndNode",left:this.transformNode(e.left),right:this.transformNode(e.right)}}transformOr(e){return{kind:"OrNode",left:this.transformNode(e.left),right:this.transformNode(e.right)}}transformValueList(e){return{kind:"ValueListNode",values:this.transformNodeList(e.values)}}transformParens(e){return{kind:"ParensNode",node:this.transformNode(e.node)}}transformJoin(e){return{kind:"JoinNode",joinType:e.joinType,table:this.transformNode(e.table),on:this.transformNode(e.on)}}transformRaw(e){return{kind:"RawNode",sqlFragments:t([...e.sqlFragments]),parameters:this.transformNodeList(e.parameters)}}transformWhere(e){return{kind:"WhereNode",where:this.transformNode(e.where)}}transformInsertQuery(e){return{kind:"InsertQueryNode",into:this.transformNode(e.into),columns:this.transformNodeList(e.columns),values:this.transformNode(e.values),returning:this.transformNode(e.returning),onConflict:this.transformNode(e.onConflict),onDuplicateKey:this.transformNode(e.onDuplicateKey),with:this.transformNode(e.with),ignore:e.ignore,replace:e.replace,explain:this.transformNode(e.explain),defaultValues:e.defaultValues,top:this.transformNode(e.top),output:this.transformNode(e.output)}}transformValues(e){return{kind:"ValuesNode",values:this.transformNodeList(e.values)}}transformDeleteQuery(e){return{kind:"DeleteQueryNode",from:this.transformNode(e.from),using:this.transformNode(e.using),joins:this.transformNodeList(e.joins),where:this.transformNode(e.where),returning:this.transformNode(e.returning),with:this.transformNode(e.with),orderBy:this.transformNode(e.orderBy),limit:this.transformNode(e.limit),explain:this.transformNode(e.explain),top:this.transformNode(e.top),output:this.transformNode(e.output)}}transformReturning(e){return{kind:"ReturningNode",selections:this.transformNodeList(e.selections)}}transformCreateTable(e){return{kind:"CreateTableNode",table:this.transformNode(e.table),columns:this.transformNodeList(e.columns),constraints:this.transformNodeList(e.constraints),temporary:e.temporary,ifNotExists:e.ifNotExists,onCommit:e.onCommit,frontModifiers:this.transformNodeList(e.frontModifiers),endModifiers:this.transformNodeList(e.endModifiers),selectQuery:this.transformNode(e.selectQuery)}}transformColumnDefinition(e){return{kind:"ColumnDefinitionNode",column:this.transformNode(e.column),dataType:this.transformNode(e.dataType),references:this.transformNode(e.references),primaryKey:e.primaryKey,autoIncrement:e.autoIncrement,unique:e.unique,notNull:e.notNull,unsigned:e.unsigned,defaultTo:this.transformNode(e.defaultTo),check:this.transformNode(e.check),generated:this.transformNode(e.generated),frontModifiers:this.transformNodeList(e.frontModifiers),endModifiers:this.transformNodeList(e.endModifiers),nullsNotDistinct:e.nullsNotDistinct,identity:e.identity,ifNotExists:e.ifNotExists}}transformAddColumn(e){return{kind:"AddColumnNode",column:this.transformNode(e.column)}}transformDropTable(e){return{kind:"DropTableNode",table:this.transformNode(e.table),ifExists:e.ifExists,cascade:e.cascade}}transformOrderBy(e){return{kind:"OrderByNode",items:this.transformNodeList(e.items)}}transformOrderByItem(e){return{kind:"OrderByItemNode",orderBy:this.transformNode(e.orderBy),direction:this.transformNode(e.direction)}}transformGroupBy(e){return{kind:"GroupByNode",items:this.transformNodeList(e.items)}}transformGroupByItem(e){return{kind:"GroupByItemNode",groupBy:this.transformNode(e.groupBy)}}transformUpdateQuery(e){return{kind:"UpdateQueryNode",table:this.transformNode(e.table),from:this.transformNode(e.from),joins:this.transformNodeList(e.joins),where:this.transformNode(e.where),updates:this.transformNodeList(e.updates),returning:this.transformNode(e.returning),with:this.transformNode(e.with),explain:this.transformNode(e.explain),limit:this.transformNode(e.limit),top:this.transformNode(e.top),output:this.transformNode(e.output)}}transformColumnUpdate(e){return{kind:"ColumnUpdateNode",column:this.transformNode(e.column),value:this.transformNode(e.value)}}transformLimit(e){return{kind:"LimitNode",limit:this.transformNode(e.limit)}}transformOffset(e){return{kind:"OffsetNode",offset:this.transformNode(e.offset)}}transformOnConflict(e){return{kind:"OnConflictNode",columns:this.transformNodeList(e.columns),constraint:this.transformNode(e.constraint),indexExpression:this.transformNode(e.indexExpression),indexWhere:this.transformNode(e.indexWhere),updates:this.transformNodeList(e.updates),updateWhere:this.transformNode(e.updateWhere),doNothing:e.doNothing}}transformOnDuplicateKey(e){return{kind:"OnDuplicateKeyNode",updates:this.transformNodeList(e.updates)}}transformCreateIndex(e){return{kind:"CreateIndexNode",name:this.transformNode(e.name),table:this.transformNode(e.table),columns:this.transformNodeList(e.columns),unique:e.unique,using:this.transformNode(e.using),ifNotExists:e.ifNotExists,where:this.transformNode(e.where),nullsNotDistinct:e.nullsNotDistinct}}transformList(e){return{kind:"ListNode",items:this.transformNodeList(e.items)}}transformDropIndex(e){return{kind:"DropIndexNode",name:this.transformNode(e.name),table:this.transformNode(e.table),ifExists:e.ifExists,cascade:e.cascade}}transformPrimaryKeyConstraint(e){return{kind:"PrimaryKeyConstraintNode",columns:this.transformNodeList(e.columns),name:this.transformNode(e.name)}}transformUniqueConstraint(e){return{kind:"UniqueConstraintNode",columns:this.transformNodeList(e.columns),name:this.transformNode(e.name),nullsNotDistinct:e.nullsNotDistinct}}transformForeignKeyConstraint(e){return{kind:"ForeignKeyConstraintNode",columns:this.transformNodeList(e.columns),references:this.transformNode(e.references),name:this.transformNode(e.name),onDelete:e.onDelete,onUpdate:e.onUpdate}}transformSetOperation(e){return{kind:"SetOperationNode",operator:e.operator,expression:this.transformNode(e.expression),all:e.all}}transformReferences(e){return{kind:"ReferencesNode",table:this.transformNode(e.table),columns:this.transformNodeList(e.columns),onDelete:e.onDelete,onUpdate:e.onUpdate}}transformCheckConstraint(e){return{kind:"CheckConstraintNode",expression:this.transformNode(e.expression),name:this.transformNode(e.name)}}transformWith(e){return{kind:"WithNode",expressions:this.transformNodeList(e.expressions),recursive:e.recursive}}transformCommonTableExpression(e){return{kind:"CommonTableExpressionNode",name:this.transformNode(e.name),materialized:e.materialized,expression:this.transformNode(e.expression)}}transformCommonTableExpressionName(e){return{kind:"CommonTableExpressionNameNode",table:this.transformNode(e.table),columns:this.transformNodeList(e.columns)}}transformHaving(e){return{kind:"HavingNode",having:this.transformNode(e.having)}}transformCreateSchema(e){return{kind:"CreateSchemaNode",schema:this.transformNode(e.schema),ifNotExists:e.ifNotExists}}transformDropSchema(e){return{kind:"DropSchemaNode",schema:this.transformNode(e.schema),ifExists:e.ifExists,cascade:e.cascade}}transformAlterTable(e){return{kind:"AlterTableNode",table:this.transformNode(e.table),renameTo:this.transformNode(e.renameTo),setSchema:this.transformNode(e.setSchema),columnAlterations:this.transformNodeList(e.columnAlterations),addConstraint:this.transformNode(e.addConstraint),dropConstraint:this.transformNode(e.dropConstraint),addIndex:this.transformNode(e.addIndex),dropIndex:this.transformNode(e.dropIndex)}}transformDropColumn(e){return{kind:"DropColumnNode",column:this.transformNode(e.column)}}transformRenameColumn(e){return{kind:"RenameColumnNode",column:this.transformNode(e.column),renameTo:this.transformNode(e.renameTo)}}transformAlterColumn(e){return{kind:"AlterColumnNode",column:this.transformNode(e.column),dataType:this.transformNode(e.dataType),dataTypeExpression:this.transformNode(e.dataTypeExpression),setDefault:this.transformNode(e.setDefault),dropDefault:e.dropDefault,setNotNull:e.setNotNull,dropNotNull:e.dropNotNull}}transformModifyColumn(e){return{kind:"ModifyColumnNode",column:this.transformNode(e.column)}}transformAddConstraint(e){return{kind:"AddConstraintNode",constraint:this.transformNode(e.constraint)}}transformDropConstraint(e){return{kind:"DropConstraintNode",constraintName:this.transformNode(e.constraintName),ifExists:e.ifExists,modifier:e.modifier}}transformCreateView(e){return{kind:"CreateViewNode",name:this.transformNode(e.name),temporary:e.temporary,orReplace:e.orReplace,ifNotExists:e.ifNotExists,materialized:e.materialized,columns:this.transformNodeList(e.columns),as:this.transformNode(e.as)}}transformDropView(e){return{kind:"DropViewNode",name:this.transformNode(e.name),ifExists:e.ifExists,materialized:e.materialized,cascade:e.cascade}}transformGenerated(e){return{kind:"GeneratedNode",byDefault:e.byDefault,always:e.always,identity:e.identity,stored:e.stored,expression:this.transformNode(e.expression)}}transformDefaultValue(e){return{kind:"DefaultValueNode",defaultValue:this.transformNode(e.defaultValue)}}transformOn(e){return{kind:"OnNode",on:this.transformNode(e.on)}}transformSelectModifier(e){return{kind:"SelectModifierNode",modifier:e.modifier,rawModifier:this.transformNode(e.rawModifier),of:this.transformNodeList(e.of)}}transformCreateType(e){return{kind:"CreateTypeNode",name:this.transformNode(e.name),enum:this.transformNode(e.enum)}}transformDropType(e){return{kind:"DropTypeNode",name:this.transformNode(e.name),ifExists:e.ifExists}}transformExplain(e){return{kind:"ExplainNode",format:e.format,options:this.transformNode(e.options)}}transformSchemableIdentifier(e){return{kind:"SchemableIdentifierNode",schema:this.transformNode(e.schema),identifier:this.transformNode(e.identifier)}}transformAggregateFunction(e){return{kind:"AggregateFunctionNode",aggregated:this.transformNodeList(e.aggregated),distinct:e.distinct,filter:this.transformNode(e.filter),func:e.func,over:this.transformNode(e.over)}}transformOver(e){return{kind:"OverNode",orderBy:this.transformNode(e.orderBy),partitionBy:this.transformNode(e.partitionBy)}}transformPartitionBy(e){return{kind:"PartitionByNode",items:this.transformNodeList(e.items)}}transformPartitionByItem(e){return{kind:"PartitionByItemNode",partitionBy:this.transformNode(e.partitionBy)}}transformBinaryOperation(e){return{kind:"BinaryOperationNode",leftOperand:this.transformNode(e.leftOperand),operator:this.transformNode(e.operator),rightOperand:this.transformNode(e.rightOperand)}}transformUnaryOperation(e){return{kind:"UnaryOperationNode",operator:this.transformNode(e.operator),operand:this.transformNode(e.operand)}}transformUsing(e){return{kind:"UsingNode",tables:this.transformNodeList(e.tables)}}transformFunction(e){return{kind:"FunctionNode",func:e.func,arguments:this.transformNodeList(e.arguments)}}transformCase(e){return{kind:"CaseNode",value:this.transformNode(e.value),when:this.transformNodeList(e.when),else:this.transformNode(e.else),isStatement:e.isStatement}}transformWhen(e){return{kind:"WhenNode",condition:this.transformNode(e.condition),result:this.transformNode(e.result)}}transformJSONReference(e){return{kind:"JSONReferenceNode",reference:this.transformNode(e.reference),traversal:this.transformNode(e.traversal)}}transformJSONPath(e){return{kind:"JSONPathNode",inOperator:this.transformNode(e.inOperator),pathLegs:this.transformNodeList(e.pathLegs)}}transformJSONPathLeg(e){return{kind:"JSONPathLegNode",type:e.type,value:e.value}}transformJSONOperatorChain(e){return{kind:"JSONOperatorChainNode",operator:this.transformNode(e.operator),values:this.transformNodeList(e.values)}}transformTuple(e){return{kind:"TupleNode",values:this.transformNodeList(e.values)}}transformMergeQuery(e){return{kind:"MergeQueryNode",into:this.transformNode(e.into),using:this.transformNode(e.using),whens:this.transformNodeList(e.whens),with:this.transformNode(e.with),top:this.transformNode(e.top),output:this.transformNode(e.output)}}transformMatched(e){return{kind:"MatchedNode",not:e.not,bySource:e.bySource}}transformAddIndex(e){return{kind:"AddIndexNode",name:this.transformNode(e.name),columns:this.transformNodeList(e.columns),unique:e.unique,using:this.transformNode(e.using),ifNotExists:e.ifNotExists}}transformCast(e){return{kind:"CastNode",expression:this.transformNode(e.expression),dataType:this.transformNode(e.dataType)}}transformFetch(e){return{kind:"FetchNode",rowCount:this.transformNode(e.rowCount),modifier:e.modifier}}transformTop(e){return{kind:"TopNode",expression:e.expression,modifiers:e.modifiers}}transformOutput(e){return{kind:"OutputNode",selections:this.transformNodeList(e.selections)}}transformDataType(e){return e}transformSelectAll(e){return e}transformIdentifier(e){return e}transformValue(e){return e}transformPrimitiveValueList(e){return e}transformOperator(e){return e}transformDefaultInsertValue(e){return e}};var An=t({AlterTableNode:!0,CreateIndexNode:!0,CreateSchemaNode:!0,CreateTableNode:!0,CreateTypeNode:!0,CreateViewNode:!0,DeleteQueryNode:!0,DropIndexNode:!0,DropSchemaNode:!0,DropTableNode:!0,DropTypeNode:!0,DropViewNode:!0,InsertQueryNode:!0,RawNode:!0,SelectQueryNode:!0,UpdateQueryNode:!0,MergeQueryNode:!0}),at=class extends qe{#e;#r=new Set;#t=new Set;constructor(e){super(),this.#e=e}transformNodeImpl(e){if(!this.#i(e))return super.transformNodeImpl(e);let o=this.#s(e);for(let d of o)this.#t.add(d);let i=this.#o(e);for(let d of i)this.#r.add(d);let s=super.transformNodeImpl(e);for(let d of i)this.#r.delete(d);for(let d of o)this.#t.delete(d);return s}transformSchemableIdentifier(e){let o=super.transformSchemableIdentifier(e);return o.schema||!this.#r.has(e.identifier.name)?o:{...o,schema:c.create(this.#e)}}transformReferences(e){let o=super.transformReferences(e);return o.table.table.schema?o:{...o,table:$.createWithSchema(this.#e,o.table.table.identifier.name)}}#i(e){return e.kind in An}#o(e){let o=new Set;if("name"in e&&e.name&&P.is(e.name)&&this.#a(e.name,o),"from"in e&&e.from)for(let i of e.from.froms)this.#n(i,o);if("into"in e&&e.into&&this.#n(e.into,o),"table"in e&&e.table&&this.#n(e.table,o),"joins"in e&&e.joins)for(let i of e.joins)this.#n(i.table,o);return"using"in e&&e.using&&this.#n(e.using,o),o}#s(e){let o=new Set;return"with"in e&&e.with&&this.#u(e.with,o),o}#n(e,o){let i=$.is(e)?e:L.is(e)&&$.is(e.node)?e.node:null;i&&this.#a(i.table,o)}#a(e,o){let i=e.identifier.name;!this.#r.has(i)&&!this.#t.has(i)&&o.add(i)}#u(e,o){for(let i of e.expressions){let s=i.name.table.table.identifier.name;this.#t.has(s)||o.add(s)}}};var _=class{#e;constructor(e){this.#e=new at(e)}transformQuery(e){return this.#e.transformNode(e.node)}async transformResult(e){return e.result}};var Jo=t({is(r){return r.kind==="MatchedNode"},create(r,e=!1){return t({kind:"MatchedNode",not:r,bySource:e})}});function jt(r,e,o){return le.create(Ve([Jo.create(!r.isMatched,r.bySource),...e&&e.length>0?[e.length===3&&o?T(e[0],e[1],e[2]):N(e)]:[]],"and",!1))}function Ge(r){return C(r)?V.create([r],[]):g(r)?r.toOperationNode():r}var Wr=class{#e;#r;#t;constructor(){this.#e=new Promise((e,o)=>{this.#t=o,this.#r=e})}get promise(){return this.#e}resolve=e=>{this.#r&&this.#r(e)};reject=e=>{this.#t&&this.#t(e)}};var $o=new Set;function Ko(r){$o.has(r)||($o.add(r),console.log(r))}var En=t([]),je=class{#e;constructor(e=En){this.#e=e}get plugins(){return this.#e}transformQuery(e,o){for(let i of this.#e){let s=i.transformQuery({node:e,queryId:o});if(s.kind===e.kind)e=s;else throw new 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 ${s.kind}`].join(" "))}return e}async executeQuery(e,o){return await this.provideConnection(async i=>{let s=await i.executeQuery(e),d=await this.#r(s,o);return Rn(s,d),d})}async*stream(e,o,i){let s=new Wr,d=new Wr;this.provideConnection(async B=>(s.resolve(B),await d.promise)).catch(B=>s.reject(B));let x=await s.promise;try{for await(let B of x.streamQuery(e,o))yield await this.#r(B,i)}finally{d.resolve()}}async#r(e,o){for(let i of this.#e)e=await i.transformResult({result:e,queryId:o});return e}};function Rn(r,e){let{numAffectedRows:o}=r;o===void 0&&r.numUpdatedOrDeletedRows===void 0||o!==void 0&&e.numAffectedRows!==void 0||Ko("kysely:warning: outdated driver/plugin detected! QueryResult.numUpdatedOrDeletedRows is deprecated and will be removed in a future release.")}var Ht=class r extends je{get adapter(){throw new Error("this query cannot be compiled to SQL")}compileQuery(){throw new Error("this query cannot be compiled to SQL")}provideConnection(){throw new Error("this query cannot be executed")}withConnectionProvider(){throw new Error("this query cannot have a connection provider")}withPlugin(e){return new r([...this.plugins,e])}withPlugins(e){return new r([...this.plugins,...e])}withPluginAtFront(e){return new r([e,...this.plugins])}withoutPlugins(){return new r([])}},He=new Ht;var ut=class{numChangedRows;constructor(e){this.numChangedRows=e}};var gr=class r{#e;constructor(e){this.#e=t(e)}top(e,o){return new r({...this.#e,queryNode:u.cloneWithTop(this.#e.queryNode,Z(e,o))})}using(...e){return new pe({...this.#e,queryNode:U.cloneWithUsing(this.#e.queryNode,q("Using",e))})}output(e){return new r({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,I(e))})}outputAll(e){return new r({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,E(e))})}};a(gr,"don't await MergeQueryBuilder instances directly. To execute the query you need to call `execute` when available.");var pe=class r{#e;constructor(e){this.#e=t(e)}top(e,o){return new r({...this.#e,queryNode:u.cloneWithTop(this.#e.queryNode,Z(e,o))})}whenMatched(){return this.#r([])}whenMatchedAnd(...e){return this.#r(e)}whenMatchedAndRef(e,o,i){return this.#r([e,o,i],!0)}#r(e,o){return new Cr({...this.#e,queryNode:U.cloneWithWhen(this.#e.queryNode,jt({isMatched:!0},e,o))})}whenNotMatched(){return this.#t([])}whenNotMatchedAnd(...e){return this.#t(e)}whenNotMatchedAndRef(e,o,i){return this.#t([e,o,i],!0)}whenNotMatchedBySource(){return this.#t([],!1,!0)}whenNotMatchedBySourceAnd(...e){return this.#t(e,!1,!0)}whenNotMatchedBySourceAndRef(e,o,i){return this.#t([e,o,i],!0,!0)}output(e){return new r({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,I(e))})}outputAll(e){return new r({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,E(e))})}#t(e,o=!1,i=!1){let s={...this.#e,queryNode:U.cloneWithWhen(this.#e.queryNode,jt({isMatched:!1,bySource:i},e,o))},d=i?Cr:dt;return new d(s)}$call(e){return e(this)}$if(e,o){return e?o(this):new r({...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(),o=await this.#e.executor.executeQuery(e,this.#e.queryId);return e.query.output&&this.#e.executor.adapter.supportsOutput?o.rows:[new ut(o.numAffectedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=K){let o=await this.executeTakeFirst();if(o===void 0)throw ie(e)?new e(this.toOperationNode()):e(this.toOperationNode());return o}};a(pe,"don't await WheneableMergeQueryBuilder instances directly. To execute the query you need to call `execute`.");var Cr=class{#e;constructor(e){this.#e=t(e)}thenDelete(){return new pe({...this.#e,queryNode:U.cloneWithThen(this.#e.queryNode,Ge("delete"))})}thenDoNothing(){return new pe({...this.#e,queryNode:U.cloneWithThen(this.#e.queryNode,Ge("do nothing"))})}thenUpdate(e){return new pe({...this.#e,queryNode:U.cloneWithThen(this.#e.queryNode,Ge(e(new Ee({queryId:this.#e.queryId,executor:He,queryNode:oe.createWithoutTable()}))))})}thenUpdateSet(...e){return this.thenUpdate(o=>o.set(...e))}};a(Cr,"don't await MatchedThenableMergeQueryBuilder instances directly. To execute the query you need to call `execute` when available.");var dt=class{#e;constructor(e){this.#e=t(e)}thenDoNothing(){return new pe({...this.#e,queryNode:U.cloneWithThen(this.#e.queryNode,Ge("do nothing"))})}thenInsertValues(e){let[o,i]=rt(e);return new pe({...this.#e,queryNode:U.cloneWithThen(this.#e.queryNode,Ge(R.cloneWith(R.createWithoutInto(),{columns:o,values:i})))})}};a(dt,"don't await NotMatchedThenableMergeQueryBuilder instances directly. To execute the query you need to call `execute` when available.");var Ye=class r{#e;constructor(e){this.#e=t(e)}selectFrom(e){return qr({queryId:W(),executor:this.#e.executor,queryNode:m.createFrom(se(e),this.#e.withNode)})}selectNoFrom(e){return qr({queryId:W(),executor:this.#e.executor,queryNode:m.cloneWithSelections(m.create(this.#e.withNode),I(e))})}insertInto(e){return new Je({queryId:W(),executor:this.#e.executor,queryNode:R.create(p(e),this.#e.withNode)})}replaceInto(e){return new Je({queryId:W(),executor:this.#e.executor,queryNode:R.create(p(e),this.#e.withNode,!0)})}deleteFrom(e){return new wr({queryId:W(),executor:this.#e.executor,queryNode:ne.create(se(e),this.#e.withNode)})}updateTable(e){return new Ee({queryId:W(),executor:this.#e.executor,queryNode:oe.create(Te(e),this.#e.withNode)})}mergeInto(e){return new gr({queryId:W(),executor:this.#e.executor,queryNode:U.create(Yt(e),this.#e.withNode)})}with(e,o){let i=Kt(e,o);return new r({...this.#e,withNode:this.#e.withNode?Or.cloneWithExpression(this.#e.withNode,i):Or.create(i)})}withRecursive(e,o){let i=Kt(e,o);return new r({...this.#e,withNode:this.#e.withNode?Or.cloneWithExpression(this.#e.withNode,i):Or.create(i,{recursive:!0})})}withPlugin(e){return new r({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new r({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new r({...this.#e,executor:this.#e.executor.withPluginAtFront(new _(e))})}};function Mo(){return new Ye({executor:He})}function Go(r,e){return new pr({joinNode:we.create(r,Te(e))})}function jo(){return new fr({overNode:lr.create()})}function q(r,e){if(e.length===3)return Dn(r,e[0],e[1],e[2]);if(e.length===2)return Bn(r,e[0],e[1]);throw new Error("not implemented")}function Bn(r,e,o){return o(Go(r,e)).toOperationNode()}function Dn(r,e,o,i){return we.createWithOn(r,Te(e),T(o,"=",i))}var Ho=t({is(r){return r.kind==="OffsetNode"},create(r){return t({kind:"OffsetNode",offset:r})}});var Yo=t({is(r){return r.kind==="GroupByItemNode"},create(r){return t({kind:"GroupByItemNode",groupBy:r})}});function Xo(r){return r=O(r)?r(X()):r,me(r).map(Yo.create)}var Zo=t({is(r){return r.kind==="SetOperationNode"},create(r,e,o){return t({kind:"SetOperationNode",operator:r,expression:e,all:o})}});function Re(r,e,o){return O(e)&&(e=e(ct())),A(e)||(e=[e]),e.map(i=>Zo.create(r,z(i),o))}var f=class r{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new Tr(this,e)}or(...e){return new Xt(j.create(this.#e,N(e)))}and(...e){return new Zt(F.create(this.#e,N(e)))}$castTo(){return new r(this.#e)}$notNull(){return new r(this.#e)}toOperationNode(){return this.#e}},Tr=class{#e;#r;constructor(e,o){this.#e=e,this.#r=o}get expression(){return this.#e}get alias(){return this.#r}toOperationNode(){return L.create(this.#e.toOperationNode(),g(this.#r)?this.#r.toOperationNode():c.create(this.#r))}},Xt=class r{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new Tr(this,e)}or(...e){return new r(j.create(this.#e,N(e)))}$castTo(){return new r(this.#e)}toOperationNode(){return Ce.create(this.#e)}},Zt=class r{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new Tr(this,e)}and(...e){return new r(F.create(this.#e,N(e)))}$castTo(){return new r(this.#e)}toOperationNode(){return Ce.create(this.#e)}};var _o={is(r){return r.kind==="FetchNode"},create(r,e){return{kind:"FetchNode",rowCount:k.create(r),modifier:e}}};function en(r,e){if(!Pe(r)&&!Jr(r))throw new Error(`Invalid fetch row count: ${r}`);if(!Qn(e))throw new Error(`Invalid fetch modifier: ${e}`);return _o.create(r,e)}function Qn(r){return r==="only"||r==="with ties"}var mt=class r{#e;constructor(e){this.#e=t(e)}get expressionType(){}get isSelectQueryBuilder(){return!0}where(...e){return new r({...this.#e,queryNode:u.cloneWithWhere(this.#e.queryNode,N(e))})}whereRef(e,o,i){return new r({...this.#e,queryNode:u.cloneWithWhere(this.#e.queryNode,T(e,o,i))})}having(...e){return new r({...this.#e,queryNode:m.cloneWithHaving(this.#e.queryNode,N(e))})}havingRef(e,o,i){return new r({...this.#e,queryNode:m.cloneWithHaving(this.#e.queryNode,T(e,o,i))})}select(e){return new r({...this.#e,queryNode:m.cloneWithSelections(this.#e.queryNode,I(e))})}distinctOn(e){return new r({...this.#e,queryNode:m.cloneWithDistinctOn(this.#e.queryNode,me(e))})}modifyFront(e){return new r({...this.#e,queryNode:m.cloneWithFrontModifier(this.#e.queryNode,te.createWithExpression(e.toOperationNode()))})}modifyEnd(e){return new r({...this.#e,queryNode:m.cloneWithEndModifier(this.#e.queryNode,te.createWithExpression(e.toOperationNode()))})}distinct(){return new r({...this.#e,queryNode:m.cloneWithFrontModifier(this.#e.queryNode,te.create("Distinct"))})}forUpdate(e){return new r({...this.#e,queryNode:m.cloneWithEndModifier(this.#e.queryNode,te.create("ForUpdate",e?dr(e).map(p):void 0))})}forShare(e){return new r({...this.#e,queryNode:m.cloneWithEndModifier(this.#e.queryNode,te.create("ForShare",e?dr(e).map(p):void 0))})}forKeyShare(e){return new r({...this.#e,queryNode:m.cloneWithEndModifier(this.#e.queryNode,te.create("ForKeyShare",e?dr(e).map(p):void 0))})}forNoKeyUpdate(e){return new r({...this.#e,queryNode:m.cloneWithEndModifier(this.#e.queryNode,te.create("ForNoKeyUpdate",e?dr(e).map(p):void 0))})}skipLocked(){return new r({...this.#e,queryNode:m.cloneWithEndModifier(this.#e.queryNode,te.create("SkipLocked"))})}noWait(){return new r({...this.#e,queryNode:m.cloneWithEndModifier(this.#e.queryNode,te.create("NoWait"))})}selectAll(e){return new r({...this.#e,queryNode:m.cloneWithSelections(this.#e.queryNode,E(e))})}innerJoin(...e){return new r({...this.#e,queryNode:u.cloneWithJoin(this.#e.queryNode,q("InnerJoin",e))})}leftJoin(...e){return new r({...this.#e,queryNode:u.cloneWithJoin(this.#e.queryNode,q("LeftJoin",e))})}rightJoin(...e){return new r({...this.#e,queryNode:u.cloneWithJoin(this.#e.queryNode,q("RightJoin",e))})}fullJoin(...e){return new r({...this.#e,queryNode:u.cloneWithJoin(this.#e.queryNode,q("FullJoin",e))})}innerJoinLateral(...e){return new r({...this.#e,queryNode:u.cloneWithJoin(this.#e.queryNode,q("LateralInnerJoin",e))})}leftJoinLateral(...e){return new r({...this.#e,queryNode:u.cloneWithJoin(this.#e.queryNode,q("LateralLeftJoin",e))})}orderBy(...e){return new r({...this.#e,queryNode:m.cloneWithOrderByItems(this.#e.queryNode,Oe(e))})}groupBy(e){return new r({...this.#e,queryNode:m.cloneWithGroupByItems(this.#e.queryNode,Xo(e))})}limit(e){return new r({...this.#e,queryNode:m.cloneWithLimit(this.#e.queryNode,$e.create(w(e)))})}offset(e){return new r({...this.#e,queryNode:m.cloneWithOffset(this.#e.queryNode,Ho.create(w(e)))})}fetch(e,o="only"){return new r({...this.#e,queryNode:m.cloneWithFetch(this.#e.queryNode,en(e,o))})}top(e,o){return new r({...this.#e,queryNode:u.cloneWithTop(this.#e.queryNode,Z(e,o))})}union(e){return new r({...this.#e,queryNode:m.cloneWithSetOperations(this.#e.queryNode,Re("union",e,!1))})}unionAll(e){return new r({...this.#e,queryNode:m.cloneWithSetOperations(this.#e.queryNode,Re("union",e,!0))})}intersect(e){return new r({...this.#e,queryNode:m.cloneWithSetOperations(this.#e.queryNode,Re("intersect",e,!1))})}intersectAll(e){return new r({...this.#e,queryNode:m.cloneWithSetOperations(this.#e.queryNode,Re("intersect",e,!0))})}except(e){return new r({...this.#e,queryNode:m.cloneWithSetOperations(this.#e.queryNode,Re("except",e,!1))})}exceptAll(e){return new r({...this.#e,queryNode:m.cloneWithSetOperations(this.#e.queryNode,Re("except",e,!0))})}as(e){return new ht(this,e)}clearSelect(){return new r({...this.#e,queryNode:m.cloneWithoutSelections(this.#e.queryNode)})}clearWhere(){return new r({...this.#e,queryNode:u.cloneWithoutWhere(this.#e.queryNode)})}clearLimit(){return new r({...this.#e,queryNode:m.cloneWithoutLimit(this.#e.queryNode)})}clearOffset(){return new r({...this.#e,queryNode:m.cloneWithoutOffset(this.#e.queryNode)})}clearOrderBy(){return new r({...this.#e,queryNode:m.cloneWithoutOrderBy(this.#e.queryNode)})}clearGroupBy(){return new r({...this.#e,queryNode:m.cloneWithoutGroupBy(this.#e.queryNode)})}$call(e){return e(this)}$if(e,o){return e?o(this):new r({...this.#e})}$castTo(){return new r(this.#e)}$narrowType(){return new r(this.#e)}$assertType(){return new r(this.#e)}$asTuple(){return new f(this.toOperationNode())}withPlugin(e){return new r({...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,this.#e.queryId)).rows}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=K){let o=await this.executeTakeFirst();if(o===void 0)throw ie(e)?new e(this.toOperationNode()):e(this.toOperationNode());return o}async*stream(e=100){let o=this.compile(),i=this.#e.executor.stream(o,e,this.#e.queryId);for await(let s of i)yield*s.rows}async explain(e,o){return await new r({...this.#e,queryNode:u.cloneWithExplain(this.#e.queryNode,e,o)}).execute()}};a(mt,"don't await SelectQueryBuilder instances directly. To execute the query you need to call `execute` or `executeTakeFirst`.");function qr(r){return new mt(r)}var ht=class{#e;#r;constructor(e,o){this.#e=e,this.#r=o}get expression(){return this.#e}get alias(){return this.#r}get isAliasedSelectQueryBuilder(){return!0}toOperationNode(){return L.create(this.#e.toOperationNode(),c.create(this.#r))}};a(ht,"don't await AliasedSelectQueryBuilder instances directly. AliasedSelectQueryBuilder should never be executed directly since it's always a part of another query.");var fe=t({is(r){return r.kind==="AggregateFunctionNode"},create(r,e=[]){return t({kind:"AggregateFunctionNode",func:r,aggregated:e})},cloneWithDistinct(r){return t({...r,distinct:!0})},cloneWithFilter(r,e){return t({...r,filter:r.filter?S.cloneWithOperation(r.filter,"And",e):S.create(e)})},cloneWithOrFilter(r,e){return t({...r,filter:r.filter?S.cloneWithOperation(r.filter,"Or",e):S.create(e)})},cloneWithOver(r,e){return t({...r,over:e})}});var _t=t({is(r){return r.kind==="FunctionNode"},create(r,e){return t({kind:"FunctionNode",func:r,arguments:e})}});var Be=class r{#e;constructor(e){this.#e=t(e)}get expressionType(){}as(e){return new eo(this,e)}distinct(){return new r({...this.#e,aggregateFunctionNode:fe.cloneWithDistinct(this.#e.aggregateFunctionNode)})}filterWhere(...e){return new r({...this.#e,aggregateFunctionNode:fe.cloneWithFilter(this.#e.aggregateFunctionNode,N(e))})}filterWhereRef(e,o,i){return new r({...this.#e,aggregateFunctionNode:fe.cloneWithFilter(this.#e.aggregateFunctionNode,T(e,o,i))})}over(e){let o=jo();return new r({...this.#e,aggregateFunctionNode:fe.cloneWithOver(this.#e.aggregateFunctionNode,(e?e(o):o).toOperationNode())})}$call(e){return e(this)}$castTo(){return new r(this.#e)}$notNull(){return new r(this.#e)}toOperationNode(){return this.#e.aggregateFunctionNode}};a(Be,"don't await AggregateFunctionBuilder instances. They are never executed directly and are always just a part of a query.");var eo=class{#e;#r;constructor(e,o){this.#e=e,this.#r=o}get expression(){return this.#e}get alias(){return this.#r}toOperationNode(){return L.create(this.#e.toOperationNode(),c.create(this.#r))}};function lt(){let r=(o,i)=>new f(_t.create(o,me(i??[]))),e=(o,i)=>new Be({aggregateFunctionNode:fe.create(o,i?me(i):void 0)});return Object.assign(r,{agg:e,avg(o){return e("avg",[o])},coalesce(...o){return r("coalesce",o)},count(o){return e("count",[o])},countAll(o){return new Be({aggregateFunctionNode:fe.create("count",E(o))})},max(o){return e("max",[o])},min(o){return e("min",[o])},sum(o){return e("sum",[o])},any(o){return r("any",[o])},jsonAgg(o){return new Be({aggregateFunctionNode:fe.create("json_agg",[C(o)?p(o):o.toOperationNode()])})},toJson(o){return new f(_t.create("to_json",[C(o)?p(o):o.toOperationNode()]))}})}var rn=t({is(r){return r.kind==="UnaryOperationNode"},create(r,e){return t({kind:"UnaryOperationNode",operator:r,operand:e})}});function tn(r,e){return rn.create(H.create(r),b(e))}var J=t({is(r){return r.kind==="CaseNode"},create(r){return t({kind:"CaseNode",value:r})},cloneWithWhen(r,e){return t({...r,when:t(r.when?[...r.when,e]:[e])})},cloneWithThen(r,e){return t({...r,when:r.when?t([...r.when.slice(0,-1),le.cloneWithResult(r.when[r.when.length-1],e)]):void 0})},cloneWith(r,e){return t({...r,...e})}});var Xe=class{#e;constructor(e){this.#e=t(e)}when(...e){return new pt({...this.#e,node:J.cloneWithWhen(this.#e.node,le.create(N(e)))})}},pt=class{#e;constructor(e){this.#e=t(e)}then(e){return new ro({...this.#e,node:J.cloneWithThen(this.#e.node,Zr(e)?hr(e):w(e))})}},ro=class{#e;constructor(e){this.#e=t(e)}when(...e){return new pt({...this.#e,node:J.cloneWithWhen(this.#e.node,le.create(N(e)))})}else(e){return new to({...this.#e,node:J.cloneWith(this.#e.node,{else:Zr(e)?hr(e):w(e)})})}end(){return new f(J.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new f(J.cloneWith(this.#e.node,{isStatement:!0}))}},to=class{#e;constructor(e){this.#e=t(e)}end(){return new f(J.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new f(J.cloneWith(this.#e.node,{isStatement:!0}))}};var oo=t({is(r){return r.kind==="JSONPathLegNode"},create(r,e){return t({kind:"JSONPathLegNode",type:r,value:e})}});var be=class{#e;constructor(e){this.#e=e}at(e){return this.#r("ArrayLocation",e)}key(e){return this.#r("Member",e)}#r(e,o){return ze.is(this.#e)?new ft(ze.cloneWithTraversal(this.#e,We.is(this.#e.traversal)?We.cloneWithLeg(this.#e.traversal,oo.create(e,o)):Yr.cloneWithValue(this.#e.traversal,k.createImmediate(o)))):new ft(We.cloneWithLeg(this.#e,oo.create(e,o)))}},ft=class extends be{#e;constructor(e){super(e),this.#e=e}get expressionType(){}as(e){return new no(this,e)}$castTo(){return new be(this.#e)}$notNull(){return new be(this.#e)}toOperationNode(){return this.#e}},no=class{#e;#r;constructor(e,o){this.#e=e,this.#r=o}get expression(){return this.#e}get alias(){return this.#r}toOperationNode(){return L.create(this.#e.toOperationNode(),g(this.#r)?this.#r.toOperationNode():c.create(this.#r))}};var io=t({is(r){return r.kind==="TupleNode"},create(r){return t({kind:"TupleNode",values:t(r)})}});var vn=["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"],Pn=[/^varchar\(\d+\)$/,/^char\(\d+\)$/,/^decimal\(\d+, \d+\)$/,/^numeric\(\d+, \d+\)$/,/^binary\(\d+\)$/,/^datetime\(\d+\)$/,/^time\(\d+\)$/,/^timetz\(\d+\)$/,/^timestamp\(\d+\)$/,/^timestamptz\(\d+\)$/,/^varbinary\(\d+\)$/],on=t({is(r){return r.kind==="DataTypeNode"},create(r){return t({kind:"DataTypeNode",dataType:r})}});function nn(r){return!!(vn.includes(r)||Pn.some(e=>e.test(r)))}function ee(r){if(g(r))return r.toOperationNode();if(nn(r))return on.create(r);throw new Error(`invalid column data type ${JSON.stringify(r)}`)}var sn=t({is(r){return r.kind==="CastNode"},create(r,e){return t({kind:"CastNode",expression:r,dataType:e})}});function ct(r=He){function e(s,d,x){return new f(_r(s,d,x))}function o(s,d){return new f(tn(s,d))}let i=Object.assign(e,{fn:void 0,eb:void 0,selectFrom(s){return qr({queryId:W(),executor:r,queryNode:m.createFrom(se(s))})},case(s){return new Xe({node:J.create(M(s)?void 0:b(s))})},ref(s,d){return M(d)?new f(Y(s)):new be(To(s,d))},jsonPath(){return new be(We.create())},table(s){return new f(p(s))},val(s){return new f(w(s))},refTuple(...s){return new f(io.create(s.map(b)))},tuple(...s){return new f(io.create(s.map(w)))},lit(s){return new f(hr(s))},unary:o,not(s){return o("not",s)},exists(s){return o("exists",s)},neg(s){return o("-",s)},between(s,d,x){return new f(xe.create(b(s),H.create("between"),F.create(w(d),w(x))))},betweenSymmetric(s,d,x){return new f(xe.create(b(s),H.create("between symmetric"),F.create(w(d),w(x))))},and(s){return A(s)?new f(Ve(s,"and")):new f(Pt(s,"and"))},or(s){return A(s)?new f(Ve(s,"or")):new f(Pt(s,"or"))},parens(...s){let d=N(s);return Ce.is(d)?new f(d):new f(Ce.create(d))},cast(s,d){return new f(sn.create(b(s),ee(d)))},withSchema(s){return ct(r.withPluginAtFront(new _(s)))}});return i.fn=lt(),i.eb=i,i}function X(r){return ct()}function z(r){if(g(r))return r.toOperationNode();if(O(r))return r(X()).toOperationNode();throw new Error(`invalid expression: ${JSON.stringify(r)}`)}function et(r){if(g(r))return r.toOperationNode();if(O(r))return r(X()).toOperationNode();throw new Error(`invalid aliased expression: ${JSON.stringify(r)}`)}function ce(r){return Oo(r)||Wo(r)||O(r)}function se(r){return A(r)?r.map(e=>Te(e)):[Te(r)]}function Te(r){return C(r)?Yt(r):et(r)}function Yt(r){let e=" as ";if(r.includes(e)){let[o,i]=r.split(e).map(an);return L.create(p(o),c.create(i))}else return p(r)}function p(r){let e=".";if(r.includes(e)){let[o,i]=r.split(e).map(an);return $.createWithSchema(o,i)}else return $.create(r)}function an(r){return r.trim()}var so=t({is(r){return r.kind==="AddColumnNode"},create(r){return t({kind:"AddColumnNode",column:r})}});var y=t({is(r){return r.kind==="ColumnDefinitionNode"},create(r,e){return t({kind:"ColumnDefinitionNode",column:h.create(r),dataType:e})},cloneWithFrontModifier(r,e){return t({...r,frontModifiers:r.frontModifiers?t([...r.frontModifiers,e]):[e]})},cloneWithEndModifier(r,e){return t({...r,endModifiers:r.endModifiers?t([...r.endModifiers,e]):[e]})},cloneWith(r,e){return t({...r,...e})}});var ao=t({is(r){return r.kind==="DropColumnNode"},create(r){return t({kind:"DropColumnNode",column:h.create(r)})}});var uo=t({is(r){return r.kind==="RenameColumnNode"},create(r,e){return t({kind:"RenameColumnNode",column:h.create(r),renameTo:h.create(e)})}});var Ze=t({is(r){return r.kind==="CheckConstraintNode"},create(r,e){return t({kind:"CheckConstraintNode",expression:r,name:e?c.create(e):void 0})}});var un=["no action","restrict","cascade","set null","set default"],_e=t({is(r){return r.kind==="ReferencesNode"},create(r,e){return t({kind:"ReferencesNode",table:r,columns:t([...e])})},cloneWithOnDelete(r,e){return t({...r,onDelete:e})},cloneWithOnUpdate(r,e){return t({...r,onUpdate:e})}});function Nt(r){return g(r)?r.toOperationNode():k.createImmediate(r)}var br=t({is(r){return r.kind==="GeneratedNode"},create(r){return t({kind:"GeneratedNode",...r})},createWithExpression(r){return t({kind:"GeneratedNode",always:!0,expression:r})},cloneWith(r,e){return t({...r,...e})}});var dn=t({is(r){return r.kind==="DefaultValueNode"},create(r){return t({kind:"DefaultValueNode",defaultValue:r})}});function er(r){if(un.includes(r))return r;throw new Error(`invalid OnModifyForeignAction ${r}`)}var ae=class r{#e;constructor(e){this.#e=e}autoIncrement(){return new r(y.cloneWith(this.#e,{autoIncrement:!0}))}identity(){return new r(y.cloneWith(this.#e,{identity:!0}))}primaryKey(){return new r(y.cloneWith(this.#e,{primaryKey:!0}))}references(e){let o=Y(e);if(!o.table||Le.is(o.column))throw new Error(`invalid call references('${e}'). The reference must have format table.column or schema.table.column`);return new r(y.cloneWith(this.#e,{references:_e.create(o.table,[o.column])}))}onDelete(e){if(!this.#e.references)throw new Error("on delete constraint can only be added for foreign keys");return new r(y.cloneWith(this.#e,{references:_e.cloneWithOnDelete(this.#e.references,er(e))}))}onUpdate(e){if(!this.#e.references)throw new Error("on update constraint can only be added for foreign keys");return new r(y.cloneWith(this.#e,{references:_e.cloneWithOnUpdate(this.#e.references,er(e))}))}unique(){return new r(y.cloneWith(this.#e,{unique:!0}))}notNull(){return new r(y.cloneWith(this.#e,{notNull:!0}))}unsigned(){return new r(y.cloneWith(this.#e,{unsigned:!0}))}defaultTo(e){return new r(y.cloneWith(this.#e,{defaultTo:dn.create(Nt(e))}))}check(e){return new r(y.cloneWith(this.#e,{check:Ze.create(e.toOperationNode())}))}generatedAlwaysAs(e){return new r(y.cloneWith(this.#e,{generated:br.createWithExpression(e.toOperationNode())}))}generatedAlwaysAsIdentity(){return new r(y.cloneWith(this.#e,{generated:br.create({identity:!0,always:!0})}))}generatedByDefaultAsIdentity(){return new r(y.cloneWith(this.#e,{generated:br.create({identity:!0,byDefault:!0})}))}stored(){if(!this.#e.generated)throw new Error("stored() can only be called after generatedAlwaysAs");return new r(y.cloneWith(this.#e,{generated:br.cloneWith(this.#e.generated,{stored:!0})}))}modifyFront(e){return new r(y.cloneWithFrontModifier(this.#e,e.toOperationNode()))}nullsNotDistinct(){return new r(y.cloneWith(this.#e,{nullsNotDistinct:!0}))}ifNotExists(){return new r(y.cloneWith(this.#e,{ifNotExists:!0}))}modifyEnd(e){return new r(y.cloneWithEndModifier(this.#e,e.toOperationNode()))}$call(e){return e(this)}toOperationNode(){return this.#e}};a(ae,"don't await ColumnDefinitionBuilder instances directly.");var co=t({is(r){return r.kind==="ModifyColumnNode"},create(r){return t({kind:"ModifyColumnNode",column:r})}});var De=t({is(r){return r.kind==="ForeignKeyConstraintNode"},create(r,e,o,i){return t({kind:"ForeignKeyConstraintNode",columns:r,references:_e.create(e,o),name:i?c.create(i):void 0})},cloneWith(r,e){return t({...r,...e})}});var Qe=class r{#e;constructor(e){this.#e=e}onDelete(e){return new r(De.cloneWith(this.#e,{onDelete:er(e)}))}onUpdate(e){return new r(De.cloneWith(this.#e,{onUpdate:er(e)}))}$call(e){return e(this)}toOperationNode(){return this.#e}};a(Qe,"don't await ForeignKeyConstraintBuilder instances directly.");var rr=t({is(r){return r.kind==="AddConstraintNode"},create(r){return t({kind:"AddConstraintNode",constraint:r})}});var tr=t({is(r){return r.kind==="UniqueConstraintNode"},create(r,e,o){return t({kind:"UniqueConstraintNode",columns:t(r.map(h.create)),name:e?c.create(e):void 0,nullsNotDistinct:o})},cloneWith(r,e){return t({...r,...e})}});var or=t({is(r){return r.kind==="DropConstraintNode"},create(r){return t({kind:"DropConstraintNode",constraintName:c.create(r)})},cloneWith(r,e){return t({...r,...e})}});var nr=t({is(r){return r.kind==="AlterColumnNode"},create(r,e,o){return t({kind:"AlterColumnNode",column:h.create(r),[e]:o})}});var ir=class{#e;constructor(e){this.#e=e}setDataType(e){return new ke(nr.create(this.#e,"dataType",ee(e)))}setDefault(e){return new ke(nr.create(this.#e,"setDefault",Nt(e)))}dropDefault(){return new ke(nr.create(this.#e,"dropDefault",!0))}setNotNull(){return new ke(nr.create(this.#e,"setNotNull",!0))}dropNotNull(){return new ke(nr.create(this.#e,"dropNotNull",!0))}$call(e){return e(this)}};a(ir,"don't await AlterColumnBuilder instances");var ke=class{#e;constructor(e){this.#e=e}toOperationNode(){return this.#e}};a(ke,"don't await AlteredColumnBuilder instances");var ue=class{#e;constructor(e){this.#e=t(e)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};a(ue,"don't await AlterTableExecutor instances directly. To execute the query you need to call `execute`");var kr=class r{#e;constructor(e){this.#e=t(e)}onDelete(e){return new r({...this.#e,constraintBuilder:this.#e.constraintBuilder.onDelete(e)})}onUpdate(e){return new r({...this.#e,constraintBuilder:this.#e.constraintBuilder.onUpdate(e)})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(l.cloneWithTableProps(this.#e.node,{addConstraint:rr.create(this.#e.constraintBuilder.toOperationNode())}),this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};a(kr,"don't await AlterTableAddForeignKeyConstraintBuilder instances directly. To execute the query you need to call `execute`");var Ir=class r{#e;constructor(e){this.#e=t(e)}ifExists(){return new r({...this.#e,node:l.cloneWithTableProps(this.#e.node,{dropConstraint:or.cloneWith(this.#e.node.dropConstraint,{ifExists:!0})})})}cascade(){return new r({...this.#e,node:l.cloneWithTableProps(this.#e.node,{dropConstraint:or.cloneWith(this.#e.node.dropConstraint,{modifier:"cascade"})})})}restrict(){return new r({...this.#e,node:l.cloneWithTableProps(this.#e.node,{dropConstraint:or.cloneWith(this.#e.node.dropConstraint,{modifier:"restrict"})})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};a(Ir,"don't await AlterTableDropConstraintBuilder instances directly. To execute the query you need to call `execute`");var yt=t({is(r){return r.kind==="PrimaryKeyConstraintNode"},create(r,e){return t({kind:"PrimaryKeyConstraintNode",columns:t(r.map(h.create)),name:e?c.create(e):void 0})}});var Ie=t({is(r){return r.kind==="AddIndexNode"},create(r){return t({kind:"AddIndexNode",name:c.create(r)})},cloneWith(r,e){return t({...r,...e})},cloneWithColumns(r,e){return t({...r,columns:[...r.columns||[],...e]})}});var Sr=class r{#e;constructor(e){this.#e=t(e)}unique(){return new r({...this.#e,node:l.cloneWithTableProps(this.#e.node,{addIndex:Ie.cloneWith(this.#e.node.addIndex,{unique:!0})})})}column(e){return new r({...this.#e,node:l.cloneWithTableProps(this.#e.node,{addIndex:Ie.cloneWithColumns(this.#e.node.addIndex,[Me(e)])})})}columns(e){return new r({...this.#e,node:l.cloneWithTableProps(this.#e.node,{addIndex:Ie.cloneWithColumns(this.#e.node.addIndex,e.map(Me))})})}expression(e){return new r({...this.#e,node:l.cloneWithTableProps(this.#e.node,{addIndex:Ie.cloneWithColumns(this.#e.node.addIndex,[e.toOperationNode()])})})}using(e){return new r({...this.#e,node:l.cloneWithTableProps(this.#e.node,{addIndex:Ie.cloneWith(this.#e.node.addIndex,{using:V.createWithSql(e)})})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};a(Sr,"don't await AlterTableAddIndexBuilder instances directly. To execute the query you need to call `execute`");var ve=class r{#e;constructor(e){this.#e=e}toOperationNode(){return this.#e}nullsNotDistinct(){return new r(tr.cloneWith(this.#e,{nullsNotDistinct:!0}))}};a(ve,"don't await UniqueConstraintNodeBuilder instances directly.");var Ar=class{#e;constructor(e){this.#e=t(e)}renameTo(e){return new ue({...this.#e,node:l.cloneWithTableProps(this.#e.node,{renameTo:p(e)})})}setSchema(e){return new ue({...this.#e,node:l.cloneWithTableProps(this.#e.node,{setSchema:c.create(e)})})}alterColumn(e,o){let i=o(new ir(e));return new Se({...this.#e,node:l.cloneWithColumnAlteration(this.#e.node,i.toOperationNode())})}dropColumn(e){return new Se({...this.#e,node:l.cloneWithColumnAlteration(this.#e.node,ao.create(e))})}renameColumn(e,o){return new Se({...this.#e,node:l.cloneWithColumnAlteration(this.#e.node,uo.create(e,o))})}addColumn(e,o,i=re){let s=i(new ae(y.create(e,ee(o))));return new Se({...this.#e,node:l.cloneWithColumnAlteration(this.#e.node,so.create(s.toOperationNode()))})}modifyColumn(e,o,i=re){let s=i(new ae(y.create(e,ee(o))));return new Se({...this.#e,node:l.cloneWithColumnAlteration(this.#e.node,co.create(s.toOperationNode()))})}addUniqueConstraint(e,o,i=re){let s=i(new ve(tr.create(o,e)));return new ue({...this.#e,node:l.cloneWithTableProps(this.#e.node,{addConstraint:rr.create(s.toOperationNode())})})}addCheckConstraint(e,o){return new ue({...this.#e,node:l.cloneWithTableProps(this.#e.node,{addConstraint:rr.create(Ze.create(o.toOperationNode(),e))})})}addForeignKeyConstraint(e,o,i,s){return new kr({...this.#e,constraintBuilder:new Qe(De.create(o.map(h.create),p(i),s.map(h.create),e))})}addPrimaryKeyConstraint(e,o){return new ue({...this.#e,node:l.cloneWithTableProps(this.#e.node,{addConstraint:rr.create(yt.create(o,e))})})}dropConstraint(e){return new Ir({...this.#e,node:l.cloneWithTableProps(this.#e.node,{dropConstraint:or.create(e)})})}addIndex(e){return new Sr({...this.#e,node:l.cloneWithTableProps(this.#e.node,{addIndex:Ie.create(e)})})}dropIndex(e){return new ue({...this.#e,node:l.cloneWithTableProps(this.#e.node,{dropIndex:ye.create(e)})})}$call(e){return e(this)}};a(Ar,"don't await AlterTableBuilder instances");var Se=class r{#e;constructor(e){this.#e=t(e)}alterColumn(e,o){let i=o(new ir(e));return new r({...this.#e,node:l.cloneWithColumnAlteration(this.#e.node,i.toOperationNode())})}dropColumn(e){return new r({...this.#e,node:l.cloneWithColumnAlteration(this.#e.node,ao.create(e))})}renameColumn(e,o){return new r({...this.#e,node:l.cloneWithColumnAlteration(this.#e.node,uo.create(e,o))})}addColumn(e,o,i=re){let s=i(new ae(y.create(e,ee(o))));return new r({...this.#e,node:l.cloneWithColumnAlteration(this.#e.node,so.create(s.toOperationNode()))})}modifyColumn(e,o,i=re){let s=i(new ae(y.create(e,ee(o))));return new r({...this.#e,node:l.cloneWithColumnAlteration(this.#e.node,co.create(s.toOperationNode()))})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};a(Se,"don't await AlterTableColumnAlteringBuilder instances directly. To execute the query you need to call `execute`");var sr=class extends qe{transformValue(e){return{...super.transformValue(e),immediate:!0}}};var Er=class r{#e;constructor(e){this.#e=t(e)}ifNotExists(){return new r({...this.#e,node:G.cloneWith(this.#e.node,{ifNotExists:!0})})}unique(){return new r({...this.#e,node:G.cloneWith(this.#e.node,{unique:!0})})}nullsNotDistinct(){return new r({...this.#e,node:G.cloneWith(this.#e.node,{nullsNotDistinct:!0})})}on(e){return new r({...this.#e,node:G.cloneWith(this.#e.node,{table:p(e)})})}column(e){return new r({...this.#e,node:G.cloneWithColumns(this.#e.node,[Me(e)])})}columns(e){return new r({...this.#e,node:G.cloneWithColumns(this.#e.node,e.map(Me))})}expression(e){return new r({...this.#e,node:G.cloneWithColumns(this.#e.node,[e.toOperationNode()])})}using(e){return new r({...this.#e,node:G.cloneWith(this.#e.node,{using:V.createWithSql(e)})})}where(...e){let o=new sr;return new r({...this.#e,node:u.cloneWithWhere(this.#e.node,o.transformNode(N(e)))})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};a(Er,"don't await CreateIndexBuilder instances directly. To execute the query you need to call `execute`");var Rr=class r{#e;constructor(e){this.#e=t(e)}ifNotExists(){return new r({...this.#e,node:$r.cloneWith(this.#e.node,{ifNotExists:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};a(Rr,"don't await CreateSchemaBuilder instances directly. To execute the query you need to call `execute`");function cn(r){if(xo.includes(r))return r;throw new Error(`invalid OnCommitAction ${r}`)}var Br=class r{#e;constructor(e){this.#e=t(e)}temporary(){return new r({...this.#e,node:v.cloneWith(this.#e.node,{temporary:!0})})}onCommit(e){return new r({...this.#e,node:v.cloneWith(this.#e.node,{onCommit:cn(e)})})}ifNotExists(){return new r({...this.#e,node:v.cloneWith(this.#e.node,{ifNotExists:!0})})}addColumn(e,o,i=re){let s=i(new ae(y.create(e,ee(o))));return new r({...this.#e,node:v.cloneWithColumn(this.#e.node,s.toOperationNode())})}addPrimaryKeyConstraint(e,o){return new r({...this.#e,node:v.cloneWithConstraint(this.#e.node,yt.create(o,e))})}addUniqueConstraint(e,o,i=re){let s=i(new ve(tr.create(o,e)));return new r({...this.#e,node:v.cloneWithConstraint(this.#e.node,s.toOperationNode())})}addCheckConstraint(e,o){return new r({...this.#e,node:v.cloneWithConstraint(this.#e.node,Ze.create(o.toOperationNode(),e))})}addForeignKeyConstraint(e,o,i,s,d=re){let x=d(new Qe(De.create(o.map(h.create),p(i),s.map(h.create),e)));return new r({...this.#e,node:v.cloneWithConstraint(this.#e.node,x.toOperationNode())})}modifyFront(e){return new r({...this.#e,node:v.cloneWithFrontModifier(this.#e.node,e.toOperationNode())})}modifyEnd(e){return new r({...this.#e,node:v.cloneWithEndModifier(this.#e.node,e.toOperationNode())})}as(e){return new r({...this.#e,node:v.cloneWith(this.#e.node,{selectQuery:z(e)})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};a(Br,"don't await CreateTableBuilder instances directly. To execute the query you need to call `execute`");var Dr=class r{#e;constructor(e){this.#e=t(e)}on(e){return new r({...this.#e,node:ye.cloneWith(this.#e.node,{table:p(e)})})}ifExists(){return new r({...this.#e,node:ye.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new r({...this.#e,node:ye.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};a(Dr,"don't await DropIndexBuilder instances directly. To execute the query you need to call `execute`");var Qr=class r{#e;constructor(e){this.#e=t(e)}ifExists(){return new r({...this.#e,node:cr.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new r({...this.#e,node:cr.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};a(Qr,"don't await DropSchemaBuilder instances directly. To execute the query you need to call `execute`");var vr=class r{#e;constructor(e){this.#e=t(e)}ifExists(){return new r({...this.#e,node:mr.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new r({...this.#e,node:mr.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};a(vr,"don't await DropTableBuilder instances directly. To execute the query you need to call `execute`");var Ne=t({is(r){return r.kind==="CreateViewNode"},create(r){return t({kind:"CreateViewNode",name:P.create(r)})},cloneWith(r,e){return t({...r,...e})}});var wt=class{#e=new sr;transformQuery(e){return this.#e.transformNode(e.node)}transformResult(e){return Promise.resolve(e.result)}};var Pr=class r{#e;constructor(e){this.#e=t(e)}temporary(){return new r({...this.#e,node:Ne.cloneWith(this.#e.node,{temporary:!0})})}materialized(){return new r({...this.#e,node:Ne.cloneWith(this.#e.node,{materialized:!0})})}ifNotExists(){return new r({...this.#e,node:Ne.cloneWith(this.#e.node,{ifNotExists:!0})})}orReplace(){return new r({...this.#e,node:Ne.cloneWith(this.#e.node,{orReplace:!0})})}columns(e){return new r({...this.#e,node:Ne.cloneWith(this.#e.node,{columns:e.map(Dt)})})}as(e){let o=e.withPlugin(new wt).toOperationNode();return new r({...this.#e,node:Ne.cloneWith(this.#e.node,{as:o})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};a(Pr,"don't await CreateViewBuilder instances directly. To execute the query you need to call `execute`");var ar=t({is(r){return r.kind==="DropViewNode"},create(r){return t({kind:"DropViewNode",name:P.create(r)})},cloneWith(r,e){return t({...r,...e})}});var Lr=class r{#e;constructor(e){this.#e=t(e)}materialized(){return new r({...this.#e,node:ar.cloneWith(this.#e.node,{materialized:!0})})}ifExists(){return new r({...this.#e,node:ar.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new r({...this.#e,node:ar.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};a(Lr,"don't await DropViewBuilder instances directly. To execute the query you need to call `execute`");var xt=t({is(r){return r.kind==="CreateTypeNode"},create(r){return t({kind:"CreateTypeNode",name:r})},cloneWithEnum(r,e){return t({...r,enum:ge.create(e.map(o=>k.createImmediate(o)))})}});var Fr=class r{#e;constructor(e){this.#e=t(e)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}asEnum(e){return new r({...this.#e,node:xt.cloneWithEnum(this.#e.node,e)})}$call(e){return e(this)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};a(Fr,"don't await CreateTypeBuilder instances directly. To execute the query you need to call `execute`");var Ot=t({is(r){return r.kind==="DropTypeNode"},create(r){return t({kind:"DropTypeNode",name:r})},cloneWith(r,e){return t({...r,...e})}});var zr=class r{#e;constructor(e){this.#e=t(e)}ifExists(){return new r({...this.#e,node:Ot.cloneWith(this.#e.node,{ifExists:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};a(zr,"don't await DropTypeBuilder instances directly. To execute the query you need to call `execute`");function mo(r){let e=".";if(r.includes(e)){let o=r.split(e).map(Ln);if(o.length===2)return P.createWithSchema(o[0],o[1]);throw new Error(`invalid schemable identifier ${r}`)}else return P.create(r)}function Ln(r){return r.trim()}var Wt=class r{#e;constructor(e){this.#e=e}createTable(e){return new Br({queryId:W(),executor:this.#e,node:v.create(p(e))})}dropTable(e){return new vr({queryId:W(),executor:this.#e,node:mr.create(p(e))})}createIndex(e){return new Er({queryId:W(),executor:this.#e,node:G.create(e)})}dropIndex(e){return new Dr({queryId:W(),executor:this.#e,node:ye.create(e)})}createSchema(e){return new Rr({queryId:W(),executor:this.#e,node:$r.create(e)})}dropSchema(e){return new Qr({queryId:W(),executor:this.#e,node:cr.create(e)})}alterTable(e){return new Ar({queryId:W(),executor:this.#e,node:l.create(p(e))})}createView(e){return new Pr({queryId:W(),executor:this.#e,node:Ne.create(e)})}dropView(e){return new Lr({queryId:W(),executor:this.#e,node:ar.create(e)})}createType(e){return new Fr({queryId:W(),executor:this.#e,node:xt.create(mo(e))})}dropType(e){return new zr({queryId:W(),executor:this.#e,node:Ot.create(mo(e))})}withPlugin(e){return new r(this.#e.withPlugin(e))}withoutPlugins(){return new r(this.#e.withoutPlugins())}withSchema(e){return new r(this.#e.withPluginAtFront(new _(e)))}};var gt=class{ref(e){return new Gr(e)}};var Ct=class{#e;constructor(e){this.#e=e}async provideConnection(e){let o=await this.#e.acquireConnection();try{return await e(o)}finally{await this.#e.releaseConnection(o)}}};var qt=class r extends je{#e;#r;#t;constructor(e,o,i,s=[]){super(s),this.#e=e,this.#r=o,this.#t=i}get adapter(){return this.#r}compileQuery(e){return this.#e.compileQuery(e)}provideConnection(e){return this.#t.provideConnection(e)}withPlugins(e){return new r(this.#e,this.#r,this.#t,[...this.plugins,...e])}withPlugin(e){return new r(this.#e,this.#r,this.#t,[...this.plugins,e])}withPluginAtFront(e){return new r(this.#e,this.#r,this.#t,[e,...this.plugins])}withConnectionProvider(e){return new r(this.#e,this.#r,e,[...this.plugins])}withoutPlugins(){return new r(this.#e,this.#r,this.#t,[])}};function ho(){return typeof performance<"u"&&O(performance.now)?performance.now():Date.now()}var Tt=class{#e;#r;#t;#i;#o;#s=new WeakSet;constructor(e,o){this.#i=!1,this.#e=e,this.#r=o}async init(){if(this.#o)throw new Error("driver has already been destroyed");this.#t||(this.#t=this.#e.init().then(()=>{this.#i=!0}).catch(e=>(this.#t=void 0,Promise.reject(e)))),await this.#t}async acquireConnection(){if(this.#o)throw new Error("driver has already been destroyed");this.#i||await this.init();let e=await this.#e.acquireConnection();return this.#s.has(e)||(this.#n()&&this.#a(e),this.#s.add(e)),e}async releaseConnection(e){await this.#e.releaseConnection(e)}beginTransaction(e,o){return this.#e.beginTransaction(e,o)}commitTransaction(e){return this.#e.commitTransaction(e)}rollbackTransaction(e){return this.#e.rollbackTransaction(e)}async destroy(){this.#t&&(await this.#t,this.#o||(this.#o=this.#e.destroy().catch(e=>(this.#o=void 0,Promise.reject(e)))),await this.#o)}#n(){return this.#r.isLevelEnabled("query")||this.#r.isLevelEnabled("error")}#a(e){let o=e.executeQuery;e.executeQuery=async i=>{let s,d=ho();try{return await o.call(e,i)}catch(x){throw s=x,await this.#u(x,i,d),x}finally{s||await this.#c(i,d)}}}async#u(e,o,i){await this.#r.error(()=>({level:"error",error:e,query:o,queryDurationMillis:this.#d(i)}))}async#c(e,o){await this.#r.query(()=>({level:"query",query:e,queryDurationMillis:this.#d(o)}))}#d(e){return ho()-e}};var Fn=()=>{},Mr=class{#e;#r;constructor(e){this.#e=e}async provideConnection(e){for(;this.#r;)await this.#r.catch(Fn);return this.#r=this.#t(e).finally(()=>{this.#r=void 0}),this.#r}async#t(e){return await e(this.#e)}};var mn=["read uncommitted","read committed","repeatable read","serializable","snapshot"];var Mg=t(["query","error"]),bt=class{#e;#r;constructor(e){O(e)?(this.#r=e,this.#e=t({query:!0,error:!0})):(this.#r=zn,this.#e=t({query:e.includes("query"),error:e.includes("error")}))}isLevelEnabled(e){return this.#e[e]}async query(e){this.#e.query&&await this.#r(e())}async error(e){this.#e.error&&await this.#r(e())}};function zn(r){r.level==="query"?(console.log(`kysely:query: ${r.query.sql}`),console.log(`kysely:query: duration: ${r.queryDurationMillis.toFixed(1)}ms`)):r.level==="error"&&(r.error instanceof Error?console.error(`kysely:error: ${r.error.stack??r.error.message}`):console.error(`kysely:error: ${JSON.stringify({error:r.error,query:r.query.sql,queryDurationMillis:r.queryDurationMillis})}`))}function hn(r){return D(r)&&O(r.compile)}var ur=class r extends Ye{#e;constructor(e){let o,i;if(Mn(e))o={executor:e.executor},i={...e};else{let s=e.dialect,d=s.createDriver(),x=s.createQueryCompiler(),B=s.createAdapter(),de=new bt(e.log??[]),yo=new Tt(d,de),ln=new Ct(yo),wo=new qt(x,B,ln,e.plugins??[]);o={executor:wo},i={config:e,executor:wo,dialect:s,driver:yo}}super(o),this.#e=t(i)}get schema(){return new Wt(this.#e.executor)}get dynamic(){return new gt}get introspection(){return this.#e.dialect.createIntrospector(this.withoutPlugins())}case(e){return new Xe({node:J.create(M(e)?void 0:z(e))})}get fn(){return lt()}transaction(){return new It({...this.#e})}connection(){return new kt({...this.#e})}withPlugin(e){return new r({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new r({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new r({...this.#e,executor:this.#e.executor.withPluginAtFront(new _(e))})}withTables(){return new r({...this.#e})}async destroy(){await this.#e.driver.destroy()}get isTransaction(){return!1}getExecutor(){return this.#e.executor}executeQuery(e,o=W()){let i=hn(e)?e.compile():e;return this.getExecutor().executeQuery(i,o)}},lo=class r extends ur{#e;constructor(e){super(e),this.#e=e}get isTransaction(){return!0}transaction(){throw new Error("calling the transaction method for a Transaction is not supported")}connection(){throw new Error("calling the connection method for a Transaction is not supported")}async destroy(){throw new Error("calling the destroy method for a Transaction is not supported")}withPlugin(e){return new r({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new r({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new r({...this.#e,executor:this.#e.executor.withPluginAtFront(new _(e))})}withTables(){return new r({...this.#e})}};function Mn(r){return D(r)&&D(r.config)&&D(r.driver)&&D(r.executor)&&D(r.dialect)}var kt=class{#e;constructor(e){this.#e=t(e)}async execute(e){return this.#e.executor.provideConnection(async o=>{let i=this.#e.executor.withConnectionProvider(new Mr(o)),s=new ur({...this.#e,executor:i});return await e(s)})}};a(kt,"don't await ConnectionBuilder instances directly. To execute the query you need to call the `execute` method");var It=class r{#e;constructor(e){this.#e=t(e)}setIsolationLevel(e){return new r({...this.#e,isolationLevel:e})}async execute(e){let{isolationLevel:o,...i}=this.#e,s={isolationLevel:o};return Vn(s),this.#e.executor.provideConnection(async d=>{let x=this.#e.executor.withConnectionProvider(new Mr(d)),B=new lo({...i,executor:x});try{await this.#e.driver.beginTransaction(d,s);let de=await e(B);return await this.#e.driver.commitTransaction(d),de}catch(de){throw await this.#e.driver.rollbackTransaction(d),de}})}};a(It,"don't await TransactionBuilder instances directly. To execute the transaction you need to call the `execute` method");function Vn(r){if(r.isolationLevel&&!mn.includes(r.isolationLevel))throw new Error(`invalid transaction isolation level ${r.isolationLevel}`)}var St=class{async init(){}async acquireConnection(){return new po}async beginTransaction(){}async commitTransaction(){}async rollbackTransaction(){}async releaseConnection(){}async destroy(){}},po=class{async executeQuery(){return{rows:[]}}async*streamQuery(){}};function NC(r){return new ur({dialect:{createAdapter:()=>new r.Adapter,createDriver:()=>new St,createIntrospector:()=>null,createQueryCompiler:()=>new r.QueryCompiler},plugins:[...r.noParameters?[new fo]:[]]})}var fo=class{#e=new No;transformQuery(e){return this.#e.transformNode(e.node)}transformResult(e){return Promise.resolve(e.result)}},No=class extends qe{transformPrimitiveValueList(e){return ge.create(e.values.map(k.createImmediate))}transformValue(e){return{...super.transformValue(e),immediate:!0}}};function yC(r){let e=r.compile();return{parameters:e.parameters,sql:e.sql}}function wC(r,e){let o=Un(r,e);return i=>i.where(s=>s.and(o.map(([d,x])=>s(d,x===null?"is":"=",x))))}function Un(r,e){return Object.entries(Object.values(e).reduce((o,i)=>{let{isInPrimaryKey:s,name:d}=i;return s&&(o[d]=r[d]),o},{}))}export{C as a,Pe as b,Vr as c,Ur as d,Jn as e,Jr as f,t as g,c as h,v as i,L as j,g as k,H as l,V as m,Y as n,k as o,w as p,Ce as q,a as r,R as s,U as t,u,W as v,He as w,Zo as x,p as y,Ne as z,NC as A,yC as B,wC as C,Un as D};
@@ -1 +0,0 @@
1
- import{A as Z,B as N,C as ii,a as Q,b as q,c as _,d as M,e as z,f as U,g as l,h as x,i as V,j as F,k as w,l as W,m as c,n as j,o as K,p as B,q as J,r as k,s as $,t as b,u as C,v as m,w as G,x as Y,y as H,z as X}from"./chunk-RGBMDID6.js";var ti={bytea:{group:"string"},char:{group:"string"},citext:{group:"string"},date:{group:"datetime"},interval:{group:"string"},name:{group:"string"},varchar:{group:"string"},text:{group:"string"},time:{group:"time"},timestamp:{group:"datetime"},timestamptz:{group:"datetime"},"timestamp without time zone":{group:"datetime"},"timestamp with time zone":{group:"datetime"},timetz:{group:"time"},"time without time zone":{group:"time"},"time with time zone":{group:"datetime"},uuid:{group:"string"}};var T=class e{#i;constructor(i){this.#i=l(i)}get expressionType(){}get isRawBuilder(){return!0}as(i){return new I(this,i)}$castTo(){return new e({...this.#i})}$notNull(){return new e(this.#i)}withPlugin(i){return new e({...this.#i,plugins:this.#i.plugins!==void 0?l([...this.#i.plugins,i]):l([i])})}toOperationNode(){return this.#e(this.#t())}compile(i){return this.#s(this.#t(i))}async execute(i){let t=this.#t(i);return t.executeQuery(this.#s(t),this.#i.queryId)}#t(i){let t=i!==void 0?i.getExecutor():G;return this.#i.plugins!==void 0?t.withPlugins(this.#i.plugins):t}#e(i){return i.transformQuery(this.#i.rawNode,this.#i.queryId)}#s(i){return i.compileQuery(this.#e(i),this.#i.queryId)}};function f(e){return new T(e)}k(T,"don't await RawBuilder instances directly. To execute the query you need to call `execute`");var I=class{#i;#t;constructor(i,t){this.#i=i,this.#t=t}get expression(){return this.#i}get alias(){return this.#t}get rawBuilder(){return this.#i}toOperationNode(){return F.create(this.#i.toOperationNode(),w(this.#t)?this.#t.toOperationNode():x.create(this.#t))}};k(I,"don't await AliasedRawBuilder instances directly. AliasedRawBuilder should never be executed directly since it's always a part of another query.");var d=Object.assign((e,...i)=>f({queryId:m(),rawNode:c.create(e,i?.map(ei)??[])}),{ref(e){return f({queryId:m(),rawNode:c.createWithChild(j(e))})},val(e){return f({queryId:m(),rawNode:c.createWithChild(B(e))})},value(e){return this.val(e)},table(e){return f({queryId:m(),rawNode:c.createWithChild(H(e))})},id(...e){let i=new Array(e.length+1).fill(".");return i[0]="",i[i.length-1]="",f({queryId:m(),rawNode:c.create(i,e.map(x.create))})},lit(e){return f({queryId:m(),rawNode:c.createWithChild(K.createImmediate(e))})},literal(e){return this.lit(e)},raw(e){return f({queryId:m(),rawNode:c.createWithSql(e)})},join(e,i=d`, `){let t=new Array(2*e.length-1),s=i.toOperationNode();for(let r=0;r<e.length;++r)t[2*r]=ei(e[r]),r!==e.length-1&&(t[2*r+1]=s);return f({queryId:m(),rawNode:c.createWithChildren(t)})}});function ei(e){return w(e)?e.toOperationNode():B(e)}var O=class{nodeStack=[];get parentNode(){return this.nodeStack[this.nodeStack.length-2]}#i=l({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),ForeignKeyConstraintNode:this.visitForeignKeyConstraint.bind(this),CreateViewNode:this.visitCreateView.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)});visitNode=i=>{this.nodeStack.push(i),this.#i[i.kind](i),this.nodeStack.pop()}};var S=class extends O{#i="";#t=[];get numParameters(){return this.#t.length}compileQuery(i){return this.#i="",this.#t=[],this.nodeStack.splice(0,this.nodeStack.length),this.visitNode(i),l({query:i,sql:this.getSql(),parameters:[...this.#t]})}getSql(){return this.#i}visitSelectQuery(i){let t=this.parentNode!==void 0&&!J.is(this.parentNode)&&!$.is(this.parentNode)&&!V.is(this.parentNode)&&!X.is(this.parentNode)&&!Y.is(this.parentNode);this.parentNode===void 0&&i.explain&&(this.visitNode(i.explain),this.append(" ")),t&&this.append("("),i.with&&(this.visitNode(i.with),this.append(" ")),this.append("select"),i.distinctOn&&(this.append(" "),this.compileDistinctOn(i.distinctOn)),i.frontModifiers?.length&&(this.append(" "),this.compileList(i.frontModifiers," ")),i.top&&(this.append(" "),this.visitNode(i.top)),i.selections&&(this.append(" "),this.compileList(i.selections)),i.from&&(this.append(" "),this.visitNode(i.from)),i.joins&&(this.append(" "),this.compileList(i.joins," ")),i.where&&(this.append(" "),this.visitNode(i.where)),i.groupBy&&(this.append(" "),this.visitNode(i.groupBy)),i.having&&(this.append(" "),this.visitNode(i.having)),i.setOperations&&(this.append(" "),this.compileList(i.setOperations," ")),i.orderBy&&(this.append(" "),this.visitNode(i.orderBy)),i.limit&&(this.append(" "),this.visitNode(i.limit)),i.offset&&(this.append(" "),this.visitNode(i.offset)),i.fetch&&(this.append(" "),this.visitNode(i.fetch)),i.endModifiers?.length&&(this.append(" "),this.compileList(this.sortSelectModifiers([...i.endModifiers])," ")),t&&this.append(")")}visitFrom(i){this.append("from "),this.compileList(i.froms)}visitSelection(i){this.visitNode(i.selection)}visitColumn(i){this.visitNode(i.column)}compileDistinctOn(i){this.append("distinct on ("),this.compileList(i),this.append(")")}compileList(i,t=", "){let s=i.length-1;for(let r=0;r<=s;r++)this.visitNode(i[r]),r<s&&this.append(t)}visitWhere(i){this.append("where "),this.visitNode(i.where)}visitHaving(i){this.append("having "),this.visitNode(i.having)}visitInsertQuery(i){let t=this.nodeStack.find(C.is),s=t!==i;!s&&i.explain&&(this.visitNode(i.explain),this.append(" ")),s&&!b.is(t)&&this.append("("),i.with&&(this.visitNode(i.with),this.append(" ")),this.append(i.replace?"replace":"insert"),i.ignore&&this.append(" ignore"),i.top&&(this.append(" "),this.visitNode(i.top)),i.into&&(this.append(" into "),this.visitNode(i.into)),i.columns&&(this.append(" ("),this.compileList(i.columns),this.append(")")),i.output&&(this.append(" "),this.visitNode(i.output)),i.values&&(this.append(" "),this.visitNode(i.values)),i.defaultValues&&(this.append(" "),this.append("default values")),i.onConflict&&(this.append(" "),this.visitNode(i.onConflict)),i.onDuplicateKey&&(this.append(" "),this.visitNode(i.onDuplicateKey)),i.returning&&(this.append(" "),this.visitNode(i.returning)),s&&!b.is(t)&&this.append(")")}visitValues(i){this.append("values "),this.compileList(i.values)}visitDeleteQuery(i){let t=this.nodeStack.find(C.is)!==i;!t&&i.explain&&(this.visitNode(i.explain),this.append(" ")),t&&this.append("("),i.with&&(this.visitNode(i.with),this.append(" ")),this.append("delete "),i.top&&(this.visitNode(i.top),this.append(" ")),this.visitNode(i.from),i.output&&(this.append(" "),this.visitNode(i.output)),i.using&&(this.append(" "),this.visitNode(i.using)),i.joins&&(this.append(" "),this.compileList(i.joins," ")),i.where&&(this.append(" "),this.visitNode(i.where)),i.orderBy&&(this.append(" "),this.visitNode(i.orderBy)),i.limit&&(this.append(" "),this.visitNode(i.limit)),i.returning&&(this.append(" "),this.visitNode(i.returning)),t&&this.append(")")}visitReturning(i){this.append("returning "),this.compileList(i.selections)}visitAlias(i){this.visitNode(i.node),this.append(" as "),this.visitNode(i.alias)}visitReference(i){i.table&&(this.visitNode(i.table),this.append(".")),this.visitNode(i.column)}visitSelectAll(i){this.append("*")}visitIdentifier(i){this.append(this.getLeftIdentifierWrapper()),this.compileUnwrappedIdentifier(i),this.append(this.getRightIdentifierWrapper())}compileUnwrappedIdentifier(i){if(!Q(i.name))throw new Error("a non-string identifier was passed to compileUnwrappedIdentifier.");this.append(this.sanitizeIdentifier(i.name))}visitAnd(i){this.visitNode(i.left),this.append(" and "),this.visitNode(i.right)}visitOr(i){this.visitNode(i.left),this.append(" or "),this.visitNode(i.right)}visitValue(i){i.immediate?this.appendImmediateValue(i.value):this.appendValue(i.value)}visitValueList(i){this.append("("),this.compileList(i.values),this.append(")")}visitTuple(i){this.append("("),this.compileList(i.values),this.append(")")}visitPrimitiveValueList(i){this.append("(");let{values:t}=i;for(let s=0;s<t.length;++s)this.appendValue(t[s]),s!==t.length-1&&this.append(", ");this.append(")")}visitParens(i){this.append("("),this.visitNode(i.node),this.append(")")}visitJoin(i){this.append(mi[i.joinType]),this.append(" "),this.visitNode(i.table),i.on&&(this.append(" "),this.visitNode(i.on))}visitOn(i){this.append("on "),this.visitNode(i.on)}visitRaw(i){let{sqlFragments:t,parameters:s}=i;for(let r=0;r<t.length;++r)this.append(t[r]),s.length>r&&this.visitNode(s[r])}visitOperator(i){this.append(i.operator)}visitTable(i){this.visitNode(i.table)}visitSchemableIdentifier(i){i.schema&&(this.visitNode(i.schema),this.append(".")),this.visitNode(i.identifier)}visitCreateTable(i){this.append("create "),i.frontModifiers&&i.frontModifiers.length>0&&(this.compileList(i.frontModifiers," "),this.append(" ")),i.temporary&&this.append("temporary "),this.append("table "),i.ifNotExists&&this.append("if not exists "),this.visitNode(i.table),i.selectQuery?(this.append(" as "),this.visitNode(i.selectQuery)):(this.append(" ("),this.compileList([...i.columns,...i.constraints??[]]),this.append(")"),i.onCommit&&(this.append(" on commit "),this.append(i.onCommit)),i.endModifiers&&i.endModifiers.length>0&&(this.append(" "),this.compileList(i.endModifiers," ")))}visitColumnDefinition(i){i.ifNotExists&&this.append("if not exists "),this.visitNode(i.column),this.append(" "),this.visitNode(i.dataType),i.unsigned&&this.append(" unsigned"),i.frontModifiers&&i.frontModifiers.length>0&&(this.append(" "),this.compileList(i.frontModifiers," ")),i.generated&&(this.append(" "),this.visitNode(i.generated)),i.identity&&this.append(" identity"),i.defaultTo&&(this.append(" "),this.visitNode(i.defaultTo)),i.notNull&&this.append(" not null"),i.unique&&this.append(" unique"),i.nullsNotDistinct&&this.append(" nulls not distinct"),i.primaryKey&&this.append(" primary key"),i.autoIncrement&&(this.append(" "),this.append(this.getAutoIncrement())),i.references&&(this.append(" "),this.visitNode(i.references)),i.check&&(this.append(" "),this.visitNode(i.check)),i.endModifiers&&i.endModifiers.length>0&&(this.append(" "),this.compileList(i.endModifiers," "))}getAutoIncrement(){return"auto_increment"}visitReferences(i){this.append("references "),this.visitNode(i.table),this.append(" ("),this.compileList(i.columns),this.append(")"),i.onDelete&&(this.append(" on delete "),this.append(i.onDelete)),i.onUpdate&&(this.append(" on update "),this.append(i.onUpdate))}visitDropTable(i){this.append("drop table "),i.ifExists&&this.append("if exists "),this.visitNode(i.table),i.cascade&&this.append(" cascade")}visitDataType(i){this.append(i.dataType)}visitOrderBy(i){this.append("order by "),this.compileList(i.items)}visitOrderByItem(i){this.visitNode(i.orderBy),i.direction&&(this.append(" "),this.visitNode(i.direction))}visitGroupBy(i){this.append("group by "),this.compileList(i.items)}visitGroupByItem(i){this.visitNode(i.groupBy)}visitUpdateQuery(i){let t=this.nodeStack.find(C.is),s=t!==i;!s&&i.explain&&(this.visitNode(i.explain),this.append(" ")),s&&!b.is(t)&&this.append("("),i.with&&(this.visitNode(i.with),this.append(" ")),this.append("update "),i.top&&(this.visitNode(i.top),this.append(" ")),i.table&&(this.visitNode(i.table),this.append(" ")),this.append("set "),i.updates&&this.compileList(i.updates),i.output&&(this.append(" "),this.visitNode(i.output)),i.from&&(this.append(" "),this.visitNode(i.from)),i.joins&&(this.append(" "),this.compileList(i.joins," ")),i.where&&(this.append(" "),this.visitNode(i.where)),i.limit&&(this.append(" "),this.visitNode(i.limit)),i.returning&&(this.append(" "),this.visitNode(i.returning)),s&&!b.is(t)&&this.append(")")}visitColumnUpdate(i){this.visitNode(i.column),this.append(" = "),this.visitNode(i.value)}visitLimit(i){this.append("limit "),this.visitNode(i.limit)}visitOffset(i){this.append("offset "),this.visitNode(i.offset)}visitOnConflict(i){this.append("on conflict"),i.columns?(this.append(" ("),this.compileList(i.columns),this.append(")")):i.constraint?(this.append(" on constraint "),this.visitNode(i.constraint)):i.indexExpression&&(this.append(" ("),this.visitNode(i.indexExpression),this.append(")")),i.indexWhere&&(this.append(" "),this.visitNode(i.indexWhere)),i.doNothing===!0?this.append(" do nothing"):i.updates&&(this.append(" do update set "),this.compileList(i.updates),i.updateWhere&&(this.append(" "),this.visitNode(i.updateWhere)))}visitOnDuplicateKey(i){this.append("on duplicate key update "),this.compileList(i.updates)}visitCreateIndex(i){this.append("create "),i.unique&&this.append("unique "),this.append("index "),i.ifNotExists&&this.append("if not exists "),this.visitNode(i.name),i.table&&(this.append(" on "),this.visitNode(i.table)),i.using&&(this.append(" using "),this.visitNode(i.using)),i.columns&&(this.append(" ("),this.compileList(i.columns),this.append(")")),i.nullsNotDistinct&&this.append(" nulls not distinct"),i.where&&(this.append(" "),this.visitNode(i.where))}visitDropIndex(i){this.append("drop index "),i.ifExists&&this.append("if exists "),this.visitNode(i.name),i.table&&(this.append(" on "),this.visitNode(i.table)),i.cascade&&this.append(" cascade")}visitCreateSchema(i){this.append("create schema "),i.ifNotExists&&this.append("if not exists "),this.visitNode(i.schema)}visitDropSchema(i){this.append("drop schema "),i.ifExists&&this.append("if exists "),this.visitNode(i.schema),i.cascade&&this.append(" cascade")}visitPrimaryKeyConstraint(i){i.name&&(this.append("constraint "),this.visitNode(i.name),this.append(" ")),this.append("primary key ("),this.compileList(i.columns),this.append(")")}visitUniqueConstraint(i){i.name&&(this.append("constraint "),this.visitNode(i.name),this.append(" ")),this.append("unique"),i.nullsNotDistinct&&this.append(" nulls not distinct"),this.append(" ("),this.compileList(i.columns),this.append(")")}visitCheckConstraint(i){i.name&&(this.append("constraint "),this.visitNode(i.name),this.append(" ")),this.append("check ("),this.visitNode(i.expression),this.append(")")}visitForeignKeyConstraint(i){i.name&&(this.append("constraint "),this.visitNode(i.name),this.append(" ")),this.append("foreign key ("),this.compileList(i.columns),this.append(") "),this.visitNode(i.references),i.onDelete&&(this.append(" on delete "),this.append(i.onDelete)),i.onUpdate&&(this.append(" on update "),this.append(i.onUpdate))}visitList(i){this.compileList(i.items)}visitWith(i){this.append("with "),i.recursive&&this.append("recursive "),this.compileList(i.expressions)}visitCommonTableExpression(i){this.visitNode(i.name),this.append(" as "),_(i.materialized)&&(i.materialized||this.append("not "),this.append("materialized ")),this.visitNode(i.expression)}visitCommonTableExpressionName(i){this.visitNode(i.table),i.columns&&(this.append("("),this.compileList(i.columns),this.append(")"))}visitAlterTable(i){this.append("alter table "),this.visitNode(i.table),this.append(" "),i.renameTo&&(this.append("rename to "),this.visitNode(i.renameTo)),i.setSchema&&(this.append("set schema "),this.visitNode(i.setSchema)),i.addConstraint&&this.visitNode(i.addConstraint),i.dropConstraint&&this.visitNode(i.dropConstraint),i.columnAlterations&&this.compileColumnAlterations(i.columnAlterations),i.addIndex&&this.visitNode(i.addIndex),i.dropIndex&&this.visitNode(i.dropIndex)}visitAddColumn(i){this.append("add column "),this.visitNode(i.column)}visitRenameColumn(i){this.append("rename column "),this.visitNode(i.column),this.append(" to "),this.visitNode(i.renameTo)}visitDropColumn(i){this.append("drop column "),this.visitNode(i.column)}visitAlterColumn(i){this.append("alter column "),this.visitNode(i.column),this.append(" "),i.dataType&&(this.announcesNewColumnDataType()&&this.append("type "),this.visitNode(i.dataType),i.dataTypeExpression&&(this.append("using "),this.visitNode(i.dataTypeExpression))),i.setDefault&&(this.append("set default "),this.visitNode(i.setDefault)),i.dropDefault&&this.append("drop default"),i.setNotNull&&this.append("set not null"),i.dropNotNull&&this.append("drop not null")}visitModifyColumn(i){this.append("modify column "),this.visitNode(i.column)}visitAddConstraint(i){this.append("add "),this.visitNode(i.constraint)}visitDropConstraint(i){this.append("drop constraint "),i.ifExists&&this.append("if exists "),this.visitNode(i.constraintName),i.modifier==="cascade"?this.append(" cascade"):i.modifier==="restrict"&&this.append(" restrict")}visitSetOperation(i){this.append(i.operator),this.append(" "),i.all&&this.append("all "),this.visitNode(i.expression)}visitCreateView(i){this.append("create "),i.orReplace&&this.append("or replace "),i.materialized&&this.append("materialized "),i.temporary&&this.append("temporary "),this.append("view "),i.ifNotExists&&this.append("if not exists "),this.visitNode(i.name),this.append(" "),i.columns&&(this.append("("),this.compileList(i.columns),this.append(") ")),i.as&&(this.append("as "),this.visitNode(i.as))}visitDropView(i){this.append("drop "),i.materialized&&this.append("materialized "),this.append("view "),i.ifExists&&this.append("if exists "),this.visitNode(i.name),i.cascade&&this.append(" cascade")}visitGenerated(i){this.append("generated "),i.always&&this.append("always "),i.byDefault&&this.append("by default "),this.append("as "),i.identity&&this.append("identity"),i.expression&&(this.append("("),this.visitNode(i.expression),this.append(")")),i.stored&&this.append(" stored")}visitDefaultValue(i){this.append("default "),this.visitNode(i.defaultValue)}visitSelectModifier(i){i.rawModifier?this.visitNode(i.rawModifier):this.append(ci[i.modifier]),i.of&&(this.append(" of "),this.compileList(i.of,", "))}visitCreateType(i){this.append("create type "),this.visitNode(i.name),i.enum&&(this.append(" as enum "),this.visitNode(i.enum))}visitDropType(i){this.append("drop type "),i.ifExists&&this.append("if exists "),this.visitNode(i.name)}visitExplain(i){this.append("explain"),(i.options||i.format)&&(this.append(" "),this.append(this.getLeftExplainOptionsWrapper()),i.options&&(this.visitNode(i.options),i.format&&this.append(this.getExplainOptionsDelimiter())),i.format&&(this.append("format"),this.append(this.getExplainOptionAssignment()),this.append(i.format)),this.append(this.getRightExplainOptionsWrapper()))}visitDefaultInsertValue(i){this.append("default")}visitAggregateFunction(i){this.append(i.func),this.append("("),i.distinct&&this.append("distinct "),this.compileList(i.aggregated),this.append(")"),i.filter&&(this.append(" filter("),this.visitNode(i.filter),this.append(")")),i.over&&(this.append(" "),this.visitNode(i.over))}visitOver(i){this.append("over("),i.partitionBy&&(this.visitNode(i.partitionBy),i.orderBy&&this.append(" ")),i.orderBy&&this.visitNode(i.orderBy),this.append(")")}visitPartitionBy(i){this.append("partition by "),this.compileList(i.items)}visitPartitionByItem(i){this.visitNode(i.partitionBy)}visitBinaryOperation(i){this.visitNode(i.leftOperand),this.append(" "),this.visitNode(i.operator),this.append(" "),this.visitNode(i.rightOperand)}visitUnaryOperation(i){this.visitNode(i.operator),this.isMinusOperator(i.operator)||this.append(" "),this.visitNode(i.operand)}isMinusOperator(i){return W.is(i)&&i.operator==="-"}visitUsing(i){this.append("using "),this.compileList(i.tables)}visitFunction(i){this.append(i.func),this.append("("),this.compileList(i.arguments),this.append(")")}visitCase(i){this.append("case"),i.value&&(this.append(" "),this.visitNode(i.value)),i.when&&(this.append(" "),this.compileList(i.when," ")),i.else&&(this.append(" else "),this.visitNode(i.else)),this.append(" end"),i.isStatement&&this.append(" case")}visitWhen(i){this.append("when "),this.visitNode(i.condition),i.result&&(this.append(" then "),this.visitNode(i.result))}visitJSONReference(i){this.visitNode(i.reference),this.visitNode(i.traversal)}visitJSONPath(i){i.inOperator&&this.visitNode(i.inOperator),this.append("'$");for(let t of i.pathLegs)this.visitNode(t);this.append("'")}visitJSONPathLeg(i){let t=i.type==="ArrayLocation";this.append(t?"[":"."),this.append(String(i.value)),t&&this.append("]")}visitJSONOperatorChain(i){for(let t=0,s=i.values.length;t<s;t++)t===s-1?this.visitNode(i.operator):this.append("->"),this.visitNode(i.values[t])}visitMergeQuery(i){i.with&&(this.visitNode(i.with),this.append(" ")),this.append("merge "),i.top&&(this.visitNode(i.top),this.append(" ")),this.append("into "),this.visitNode(i.into),i.using&&(this.append(" "),this.visitNode(i.using)),i.whens&&(this.append(" "),this.compileList(i.whens," ")),i.output&&(this.append(" "),this.visitNode(i.output))}visitMatched(i){i.not&&this.append("not "),this.append("matched"),i.bySource&&this.append(" by source")}visitAddIndex(i){this.append("add "),i.unique&&this.append("unique "),this.append("index "),this.visitNode(i.name),i.columns&&(this.append(" ("),this.compileList(i.columns),this.append(")")),i.using&&(this.append(" using "),this.visitNode(i.using))}visitCast(i){this.append("cast("),this.visitNode(i.expression),this.append(" as "),this.visitNode(i.dataType),this.append(")")}visitFetch(i){this.append("fetch next "),this.visitNode(i.rowCount),this.append(` rows ${i.modifier}`)}visitOutput(i){this.append("output "),this.compileList(i.selections)}visitTop(i){this.append(`top(${i.expression})`),i.modifiers&&this.append(` ${i.modifiers}`)}append(i){this.#i+=i}appendValue(i){this.addParameter(i),this.append(this.getCurrentParameterPlaceholder())}getLeftIdentifierWrapper(){return'"'}getRightIdentifierWrapper(){return'"'}getCurrentParameterPlaceholder(){return"$"+this.numParameters}getLeftExplainOptionsWrapper(){return"("}getExplainOptionAssignment(){return" "}getExplainOptionsDelimiter(){return", "}getRightExplainOptionsWrapper(){return")"}sanitizeIdentifier(i){let t=this.getLeftIdentifierWrapper(),s=this.getRightIdentifierWrapper(),r="";for(let a of i)r+=a,a===t?r+=t:a===s&&(r+=s);return r}addParameter(i){this.#t.push(i)}appendImmediateValue(i){if(Q(i))this.append(`'${i}'`);else if(q(i)||_(i))this.append(i.toString());else if(M(i))this.append("null");else if(z(i))this.appendImmediateValue(i.toISOString());else if(U(i))this.appendImmediateValue(i.toString());else throw new Error(`invalid immediate value ${i}`)}sortSelectModifiers(i){return i.sort((t,s)=>t.modifier&&s.modifier?si[t.modifier]-si[s.modifier]:1),l(i)}compileColumnAlterations(i){this.compileList(i)}announcesNewColumnDataType(){return!0}},ci=l({ForKeyShare:"for key share",ForNoKeyUpdate:"for no key update",ForUpdate:"for update",ForShare:"for share",NoWait:"nowait",SkipLocked:"skip locked",Distinct:"distinct"}),si=l({ForKeyShare:1,ForNoKeyUpdate:1,ForUpdate:1,ForShare:1,NoWait:2,SkipLocked:2,Distinct:0}),mi=l({InnerJoin:"inner join",LeftJoin:"left join",RightJoin:"right join",FullJoin:"full join",LateralInnerJoin:"inner join lateral",LateralLeftJoin:"left join lateral",Using:"using"});var D=class{get supportsCreateIfNotExists(){return!0}get supportsTransactionalDdl(){return!1}get supportsReturning(){return!1}get supportsOutput(){return!1}};var fi=/"/g,L=class extends S{sanitizeIdentifier(i){return i.replace(fi,'""')}};var vi=BigInt("3853314791062309107"),A=class extends D{get supportsTransactionalDdl(){return!0}get supportsReturning(){return!0}async acquireMigrationLock(i,t){await d`select pg_advisory_xact_lock(${d.lit(vi)})`.execute(i)}async releaseMigrationLock(i,t){}};function g(e){return Z({...e,Adapter:A,QueryCompiler:L})}function ri(e,i){let{table:t,row:s}=e,{name:r,schema:a}=t,n=g(i);return N(n.withSchema(a).insertInto(r).values(s).returningAll().returning(p=>[p.cast("ctid","text").as("ctid")]))}function ai(e,i){let{pageIndex:t,pageSize:s,sortOrder:r,table:{name:a,schema:n}}=e,p=g(i);return N(p.with("count",o=>o.withSchema(n).selectFrom(a).select(v=>v.cast(p.fn.coalesce(p.fn.countAll(),d.lit(0)),"text").as("oid"))).withSchema(n).selectFrom([a,"count"]).select(o=>[o.cast("ctid","text").as("ctid"),o.ref("count.oid").as("oid")]).selectAll(a).$call(o=>r.reduce((v,u)=>v.orderBy(u.column,u.direction),o)).limit(s).offset(d.lit(BigInt(t)*BigInt(s))))}function yt(){return[{created_at:new Date("2025-01-26T21:56:12.345Z"),ctid:"(0,1)",deleted_at:null,id:1,name:"John Doe",oid:"2",role:"admin"},{created_at:new Date("2025-01-26T20:56:12.345Z"),ctid:"(0,2)",deleted_at:null,id:2,name:"Jane Doe",oid:"2",role:"poweruser"}]}function ni(e,i){let{changes:t,row:s,table:{columns:r,name:a,schema:n}}=e,p=g(i);return N(p.withSchema(n).updateTable(a).set(t).$call(ii(s,r)).returningAll(a).returning(o=>[o.cast("ctid","text").as("ctid"),o.cast(o.fn("floor",[o(o.fn("extract",[d`epoch from now()`]),"*",1e6)]),"text").as("__ps_updated_at__")]))}function pi(e){return d`(select coalesce(json_agg(agg), '[]') from ${e} as agg)`}var Ni="r",gi="v",yi=[Ni,gi];function oi(e){return N(g(e).selectFrom("pg_catalog.pg_class as cls").innerJoin("pg_catalog.pg_namespace as ns","cls.relnamespace","ns.oid").$call(bi).where("cls.relkind","in",yi).select(i=>["ns.nspname as schema","cls.relname as name",pi(i.selectFrom("pg_catalog.pg_attribute as att").innerJoin("pg_catalog.pg_type as typ","typ.oid","att.atttypid").leftJoin("pg_catalog.pg_constraint as con",t=>t.on("con.contype","=","p").onRef("con.conrelid","=","cls.oid").on(s=>d`${s.ref("att.attnum")} = ANY(${s.ref("con.conkey")})`)).whereRef("att.attrelid","=","cls.oid").where("att.attnum",">=",0).where("att.attisdropped","!=",!0).select(t=>["att.attname as name","typ.typname as datatype",t("con.conkey","is not",null).$castTo().as("pk")])).as("columns")]))}function hi(){return[{schema:"public",name:"users",columns:[{name:"id",datatype:"bigint",pk:!0},{name:"name",datatype:"varchar",pk:!1},{name:"role",datatype:"varchar",pk:!1},{name:"created_at",datatype:"timestamptz",pk:!1},{name:"deleted_at",datatype:"timestamptz",pk:!1}]}]}function di(){let e=g();return N(e.selectNoFrom(e.fn("current_setting",[d.lit("timezone")]).as("timezone")))}function li(){return[{timezone:"UTC"}]}function bi(e){return e.where("ns.nspname","!~","^pg_").where("ns.nspname","!=","information_schema")}function _t(e){let{executor:i,...t}=e;return{defaultSchema:"public",async introspect(s){try{let r=oi(t),a=di(),[[n,p],[o,v]]=await Promise.all([i.execute(r,s),i.execute(a,s)]),u=n||o;if(u)return[u];let[y]=v;return y?[null,ui(p,y.timezone)]:[new Error("Timezone not found")]}catch(r){return[r]}},async query(s,r){try{let a=ai(s,t),[n,p]=await i.execute(a,r);return n?[n]:[null,{filteredRowCount:p[0]?.oid||"0",rows:p}]}catch(a){return[a]}},async insert(s,r){try{let a=ri(s,t),[n,p]=await i.execute(a,r);return n?[n]:[null,{row:p[0]}]}catch(a){return[a]}},async update(s,r){try{let a=ni(s,t),[n,p]=await i.execute(a,r);if(n)return[n];let[o]=p;return o?[null,{row:o}]:[new Error("Update failed")]}catch(a){return[a]}}}}function ui(e,i){return e.reduce((t,s)=>{let{schemas:r}=t,{columns:a,name:n,schema:p}=s,o=a.reduce((v,{datatype:u,name:y,pk:P})=>{let E=u.startsWith("_"),R=E?u.slice(1):u;return{...v,[y]:{name:y,schema:p,table:y,isInPrimaryKey:P,datatype:{...ti[R]||{group:"raw"},isArray:E,name:E?`${R}[]`:R}}}},{});return(r[p]||={tables:{}}).tables[n]={columns:o,name:n,schema:p},t},{schemas:{public:{tables:{}}},timezone:i})}function Bt(){let e=hi(),[{timezone:i}]=li();return ui(e,i)}export{ri as a,ai as b,yt as c,ni as d,oi as e,hi as f,di as g,li as h,_t as i,Bt as j};