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