@prisma/studio-core 0.0.0-dev.202504300949 → 0.0.0-dev.202504301002
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/data/pglite/index.cjs +1 -1
- package/dist/data/pglite/index.d.cts +15 -4
- package/dist/data/pglite/index.d.ts +15 -4
- package/dist/data/pglite/index.js +1 -1
- package/dist/ui/index.cjs +21 -21
- package/dist/ui/index.js +2 -2
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var Gr=Object.defineProperty;var Uo=Object.getOwnPropertyDescriptor;var Jo=Object.getOwnPropertyNames;var $o=Object.prototype.hasOwnProperty;var Ko=(t,e)=>{for(var i in e)Gr(t,i,{get:e[i],enumerable:!0})},jo=(t,e,i,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Jo(e))!$o.call(t,s)&&s!==i&&Gr(t,s,{get:()=>e[s],enumerable:!(o=Uo(e,s))||o.enumerable});return t};var Go=t=>jo(Gr({},"__esModule",{value:!0}),t);var Qn={};Ko(Qn,{createPGLiteAdapter:()=>Bn,createPGLiteExecutor:()=>Mo});module.exports=Go(Qn);var Bi={bool:{group:"boolean"},boolean:{group:"boolean"},bytea:{group:"string"},char:{group:"string"},citext:{group:"string"},date:{group:"datetime"},interval:{group:"string"},name:{group:"string"},varchar:{group:"string"},text:{group:"string"},time:{group:"time"},timestamp:{group:"datetime"},timestamptz:{group:"datetime"},"timestamp without time zone":{group:"datetime"},"timestamp with time zone":{group:"datetime"},timetz:{group:"time"},"time without time zone":{group:"time"},"time with time zone":{group:"datetime"},uuid:{group:"string"}};function K(t){return typeof t>"u"||t===void 0}function W(t){return typeof t=="string"}function ve(t){return typeof t=="number"}function Pe(t){return typeof t=="boolean"}function Ge(t){return t===null}function Qi(t){return t instanceof Date}function He(t){return typeof t=="bigint"}function C(t){return typeof t=="function"}function M(t){return typeof t=="object"&&t!==null}function r(t){return Object.freeze(t)}function gt(t){return L(t)?t:[t]}function L(t){return Array.isArray(t)}function ae(t){return t}var f=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 c=r({is(t){return t.kind==="IdentifierNode"},create(t){return r({kind:"IdentifierNode",name:t})}});var ee=r({is(t){return t.kind==="CreateIndexNode"},create(t){return r({kind:"CreateIndexNode",name:c.create(t)})},cloneWith(t,e){return r({...t,...e})},cloneWithColumns(t,e){return r({...t,columns:[...t.columns||[],...e]})}});var _t=r({is(t){return t.kind==="CreateSchemaNode"},create(t,e){return r({kind:"CreateSchemaNode",schema:c.create(t),...e})},cloneWith(t,e){return r({...t,...e})}});var Li=["preserve rows","delete rows","drop"],P=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 U=r({is(t){return t.kind==="SchemableIdentifierNode"},create(t){return r({kind:"SchemableIdentifierNode",identifier:c.create(t)})},createWithSchema(t,e){return r({kind:"SchemableIdentifierNode",schema:c.create(t),identifier:c.create(e)})}});var Ce=r({is(t){return t.kind==="DropIndexNode"},create(t,e){return r({kind:"DropIndexNode",name:U.create(t),...e})},cloneWith(t,e){return r({...t,...e})}});var Ot=r({is(t){return t.kind==="DropSchemaNode"},create(t,e){return r({kind:"DropSchemaNode",schema:c.create(t),...e})},cloneWith(t,e){return r({...t,...e})}});var bt=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 F=r({is(t){return t.kind==="AliasNode"},create(t,e){return r({kind:"AliasNode",node:t,alias:e})}});var X=r({is(t){return t.kind==="TableNode"},create(t){return r({kind:"TableNode",table:U.create(t)})},createWithSchema(t,e){return r({kind:"TableNode",table:U.createWithSchema(t,e)})}});function v(t){return M(t)&&C(t.toOperationNode)}function Pi(t){return M(t)&&"expressionType"in t&&v(t)}function Fi(t){return M(t)&&"expression"in t&&W(t.alias)&&v(t)}var ue=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 J=r({is(t){return t.kind==="AndNode"},create(t,e){return r({kind:"AndNode",left:t,right:e})}});var te=r({is(t){return t.kind==="OrNode"},create(t,e){return r({kind:"OrNode",left:t,right:e})}});var er=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"?J.create(t.on,i):te.create(t.on,i)})}});var We=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:er.create(i)})},cloneWithOn(t,e){return r({...t,on:t.on?er.cloneWithOperation(t.on,"And",e):er.create(e)})}});var Te=r({is(t){return t.kind==="BinaryOperationNode"},create(t,e,i){return r({kind:"BinaryOperationNode",leftOperand:t,operator:e,rightOperand:i})}});var Ho=["=","==","!=","<>",">",">=","<","<=","in","not in","is","is not","like","not like","match","ilike","not ilike","@>","<@","^@","&&","?","?&","?|","!<","!>","<=>","!~","~","~*","!~*","@@","@@@","!!","<->","regexp","is distinct from","is not distinct from"],Yo=["+","-","*","/","%","^","&","|","#","<<",">>"],zi=["->","->>"],Xo=[...Ho,...Yo,"&&","||"],Zo=["exists","not exists"],_o=["not","-",...Zo],Mi=[...Xo,...zi,..._o,"between","between symmetric"],j=r({is(t){return t.kind==="OperatorNode"},create(t){return r({kind:"OperatorNode",operator:t})}});function Hr(t){return W(t)&&zi.includes(t)}var l=r({is(t){return t.kind==="ColumnNode"},create(t){return r({kind:"ColumnNode",column:c.create(t)})}});var Ye=r({is(t){return t.kind==="SelectAllNode"},create(){return r({kind:"SelectAllNode"})}});var Xe=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:Ye.create()})}});var tr=class{#e;get dynamicReference(){return this.#e}get refType(){}constructor(e){this.#e=e}toOperationNode(){return Yr(this.#e)}};function rr(t){return M(t)&&v(t)&&W(t.dynamicReference)}var ir=r({is(t){return t.kind==="OrderByItemNode"},create(t,e){return r({kind:"OrderByItemNode",orderBy:t,direction:e})}});var T=r({is(t){return t.kind==="RawNode"},create(t,e){return r({kind:"RawNode",sqlFragments:r(t),parameters:r(e)})},createWithSql(t){return T.create([t],[])},createWithChild(t){return T.create(["",""],[t])},createWithChildren(t){return T.create(new Array(t.length+1).fill(""),t)}});function Zr(t){return t==="asc"||t==="desc"}function qe(t){if(t.length===2)return[Xr(t[0],t[1])];if(t.length===1){let[e]=t;return Array.isArray(e)?e.map(i=>Xr(i)):[Xr(e)]}throw new Error(`Invalid number of arguments at order by! expected 1-2, received ${t.length}`)}function Xr(t,e){let i=en(t);if(ir.is(i)){if(e)throw new Error("Cannot specify direction twice!");return i}return ir.create(i,Vi(e))}function en(t){if(Ne(t))return $(t);if(rr(t))return t.toOperationNode();let[e,i]=t.split(" ");if(i){if(!Zr(i))throw new Error(`Invalid order by direction: ${i}`);return ir.create(G(e),Vi(i))}return G(t)}function Vi(t){if(t)return t==="asc"||t==="desc"?T.createWithSql(t):t.toOperationNode()}var Ze=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 or=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 Ie=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 Yr(t){return W(t)?G(t):t.toOperationNode()}function ye(t){return L(t)?t.map(e=>D(e)):[D(t)]}function D(t){return Ne(t)?$(t):Yr(t)}function Ui(t,e){let i=G(t);if(Hr(e))return Ze.create(i,or.create(j.create(e)));let o=e.slice(0,-1);if(Hr(o))return Ze.create(i,Ie.create(j.create(o)));throw new Error(`Invalid JSON operator: ${e}`)}function G(t){let e=".";if(!t.includes(e))return Xe.create(l.create(t));let i=t.split(e).map(ei);if(i.length===3)return tn(i);if(i.length===2)return rn(i);throw new Error(`invalid column reference ${t}`)}function Ji(t){let e=" as ";if(t.includes(e)){let[i,o]=t.split(e).map(ei);return F.create(G(i),c.create(o))}else return G(t)}function _r(t){return l.create(t)}function _e(t){let e=" ";if(t.includes(e)){let[i,o]=t.split(e).map(ei);if(!Zr(o))throw new Error(`invalid order direction "${o}" next to "${i}"`);return qe([i,o])[0]}else return _r(t)}function tn(t){let[e,i,o]=t;return Xe.create(l.create(o),X.createWithSchema(e,i))}function rn(t){let[e,i]=t;return Xe.create(l.create(i),X.create(e))}function ei(t){return t.trim()}var nr=r({is(t){return t.kind==="PrimitiveValueListNode"},create(t){return r({kind:"PrimitiveValueListNode",values:r([...t])})}});var Se=r({is(t){return t.kind==="ValueListNode"},create(t){return r({kind:"ValueListNode",values:r(t)})}});var I=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 $i(t){return L(t)?on(t):x(t)}function x(t){return Ne(t)?$(t):I.create(t)}function sr(t){return ve(t)||Pe(t)||Ge(t)}function vt(t){if(!sr(t))throw new Error(`unsafe immediate value ${JSON.stringify(t)}`);return I.createImmediate(t)}function on(t){return t.some(Ne)?Se.create(t.map(e=>x(e))):nr.create(t)}var de=r({is(t){return t.kind==="ParensNode"},create(t){return r({kind:"ParensNode",node:t})}});function g(t){if(t.length===3)return ar(t[0],t[1],t[2]);if(t.length===1)return x(t[0]);throw new Error(`invalid arguments: ${JSON.stringify(t)}`)}function ar(t,e,i){return nn(e)&&ji(i)?Te.create(D(t),ti(e),I.createImmediate(i)):Te.create(D(t),ti(e),$i(i))}function k(t,e,i){return Te.create(D(t),ti(e),D(i))}function ri(t,e){return et(Object.entries(t).filter(([,i])=>!K(i)).map(([i,o])=>ar(i,ji(o)?"is":"=",o)),e)}function et(t,e,i=!0){let o=e==="and"?J.create:te.create;if(t.length===0)return Te.create(I.createImmediate(1),j.create("="),I.createImmediate(e==="and"?1:0));let s=Ki(t[0]);for(let a=1;a<t.length;++a)s=o(s,Ki(t[a]));return t.length>1&&i?de.create(s):s}function nn(t){return t==="is"||t==="is not"}function ji(t){return Ge(t)||Pe(t)}function ti(t){if(W(t)&&Mi.includes(t))return j.create(t);if(v(t))return t.toOperationNode();throw new Error(`invalid operator ${JSON.stringify(t)}`)}function Ki(t){return v(t)?t.toOperationNode():t}var we=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 ii=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 Ct=r({is(t){return t.kind==="OverNode"},create(){return r({kind:"OverNode"})},cloneWithOrderByItems(t,e){return r({...t,orderBy:t.orderBy?we.cloneWithItems(t.orderBy,e):we.create(e)})},cloneWithPartitionByItems(t,e){return r({...t,partitionBy:t.partitionBy?ii.cloneWithItems(t.partitionBy,e):ii.create(e)})}});var Fe=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 oi=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 ni=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"?J.create(t.having,i):te.create(t.having,i)})}});var m=r({is(t){return t.kind==="SelectQueryNode"},create(t){return r({kind:"SelectQueryNode",...t&&{with:t}})},createFrom(t,e){return r({kind:"SelectQueryNode",from:Fe.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?we.cloneWithItems(t.orderBy,e):we.create(e)})},cloneWithGroupByItems(t,e){return r({...t,groupBy:t.groupBy?oi.cloneWithItems(t.groupBy,e):oi.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?ni.cloneWithOperation(t.having,"And",e):ni.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 u(t,e){Object.defineProperties(t.prototype,{then:{enumerable:!1,value:()=>{throw new Error(e)}}})}var Wt=class t{#e;constructor(e){this.#e=r(e)}on(...e){return new t({...this.#e,joinNode:We.cloneWithOn(this.#e.joinNode,g(e))})}onRef(e,i,o){return new t({...this.#e,joinNode:We.cloneWithOn(this.#e.joinNode,k(e,i,o))})}onTrue(){return new t({...this.#e,joinNode:We.cloneWithOn(this.#e.joinNode,T.createWithSql("true"))})}$call(e){return e(this)}toOperationNode(){return this.#e.joinNode}};u(Wt,"don't await JoinBuilder instances. They are never executed directly and are always just a part of a query.");var Gi=r({is(t){return t.kind==="PartitionByItemNode"},create(t){return r({kind:"PartitionByItemNode",partitionBy:t})}});function Hi(t){return ye(t).map(Gi.create)}var Tt=class t{#e;constructor(e){this.#e=r(e)}orderBy(e,i){return new t({overNode:Ct.cloneWithOrderByItems(this.#e.overNode,qe([e,i]))})}partitionBy(e){return new t({overNode:Ct.cloneWithPartitionByItems(this.#e.overNode,Hi(e))})}$call(e){return e(this)}toOperationNode(){return this.#e.overNode}};u(Tt,"don't await OverBuilder instances. They are never executed directly and are always just a part of a query.");var tt=r({is(t){return t.kind==="SelectionNode"},create(t){return r({kind:"SelectionNode",selection:t})},createSelectAll(){return r({kind:"SelectionNode",selection:Ye.create()})},createSelectAllFromTable(t){return r({kind:"SelectionNode",selection:Xe.createSelectAll(t)})}});function B(t){return C(t)?B(t(re())):L(t)?t.map(e=>Yi(e)):[Yi(t)]}function Yi(t){return W(t)?tt.create(Ji(t)):rr(t)?tt.create(t.toOperationNode()):tt.create(ur(t))}function z(t){return t?Array.isArray(t)?t.map(Xi):[Xi(t)]:[tt.createSelectAll()]}function Xi(t){if(W(t))return tt.createSelectAllFromTable(y(t));throw new Error(`invalid value selectAll expression: ${JSON.stringify(t)}`)}var Zi=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 dr(t){let e=C(t)?t(re()):t,i=L(e)?e:r([e]);return sn(i)}function sn(t){let e=an(t);return[r([...e.keys()].map(l.create)),Zi.create(t.map(i=>un(i,e)))]}function an(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 un(t,e){let i=Object.keys(t),o=Array.from({length:e.size}),s=!1;for(let p of i){let h=e.get(p);if(K(h))continue;let b=t[p];(K(b)||Ne(b))&&(s=!0),o[h]=b}if(i.length<e.size||s){let p=_i.create();return Se.create(o.map(h=>K(h)?p:x(h)))}return nr.create(o)}var A=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 pe=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?Fe.cloneWithFroms(t.from,e):Fe.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 si=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 ce=r({is(t){return t.kind==="DeleteQueryNode"},create(t,e){return r({kind:"DeleteQueryNode",from:Fe.create(t),...e&&{with:e}})},cloneWithOrderByItems(t,e){return r({...t,orderBy:t.orderBy?we.cloneWithItems(t.orderBy,e):we.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?si.cloneWithTables(t.using,e):si.create(e)})}});var Q=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"?J.create(t.where,i):te.create(t.where,i)})}});var ai=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 eo=r({is(t){return t.kind==="ExplainNode"},create(t,e){return r({kind:"ExplainNode",format:t,options:e})}});var xe=r({is(t){return t.kind==="WhenNode"},create(t){return r({kind:"WhenNode",condition:t})},cloneWithResult(t,e){return r({...t,result:e})}});var E=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),xe.cloneWithResult(t.whens[t.whens.length-1],e)]):void 0})}});var ui=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 m.is(t)||A.is(t)||pe.is(t)||ce.is(t)||E.is(t)},cloneWithWhere(t,e){return r({...t,where:t.where?Q.cloneWithOperation(t.where,"And",e):Q.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?ai.cloneWithSelections(t.returning,e):ai.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:eo.create(e,i?.toOperationNode())})},cloneWithTop(t,e){return r({...t,top:e})},cloneWithOutput(t,e){return r({...t,output:t.output?ui.cloneWithSelections(t.output,e):ui.create(e)})}});var di=r({is(t){return t.kind==="ColumnUpdateNode"},create(t,e){return r({kind:"ColumnUpdateNode",column:t,value:e})}});function to(...t){return t.length===2?[di.create(D(t[0]),x(t[1]))]:qt(t[0])}function qt(t){let e=C(t)?t(re()):t;return Object.entries(e).filter(([i,o])=>o!==void 0).map(([i,o])=>di.create(l.create(i),x(o)))}var ro=r({is(t){return t.kind==="OnDuplicateKeyNode"},create(t){return r({kind:"OnDuplicateKeyNode",updates:t})}});var pr=class{insertId;numInsertedOrUpdatedRows;constructor(e,i){this.insertId=e,this.numInsertedOrUpdatedRows=i}};var Z=class extends Error{node;constructor(e){super("no result"),this.node=e}};function he(t){return Object.prototype.hasOwnProperty.call(t,"prototype")}var V=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?Q.cloneWithOperation(t.indexWhere,"And",e):Q.create(e)})},cloneWithIndexOrWhere(t,e){return r({...t,indexWhere:t.indexWhere?Q.cloneWithOperation(t.indexWhere,"Or",e):Q.create(e)})},cloneWithUpdateWhere(t,e){return r({...t,updateWhere:t.updateWhere?Q.cloneWithOperation(t.updateWhere,"And",e):Q.create(e)})},cloneWithUpdateOrWhere(t,e){return r({...t,updateWhere:t.updateWhere?Q.cloneWithOperation(t.updateWhere,"Or",e):Q.create(e)})},cloneWithoutIndexWhere(t){return r({...t,indexWhere:void 0})},cloneWithoutUpdateWhere(t){return r({...t,updateWhere:void 0})}});var It=class t{#e;constructor(e){this.#e=r(e)}column(e){let i=l.create(e);return new t({...this.#e,onConflictNode:V.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?r([...this.#e.onConflictNode.columns,i]):r([i])})})}columns(e){let i=e.map(l.create);return new t({...this.#e,onConflictNode:V.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:V.cloneWith(this.#e.onConflictNode,{constraint:c.create(e)})})}expression(e){return new t({...this.#e,onConflictNode:V.cloneWith(this.#e.onConflictNode,{indexExpression:e.toOperationNode()})})}where(...e){return new t({...this.#e,onConflictNode:V.cloneWithIndexWhere(this.#e.onConflictNode,g(e))})}whereRef(e,i,o){return new t({...this.#e,onConflictNode:V.cloneWithIndexWhere(this.#e.onConflictNode,k(e,i,o))})}clearWhere(){return new t({...this.#e,onConflictNode:V.cloneWithoutIndexWhere(this.#e.onConflictNode)})}doNothing(){return new cr({...this.#e,onConflictNode:V.cloneWith(this.#e.onConflictNode,{doNothing:!0})})}doUpdateSet(e){return new hr({...this.#e,onConflictNode:V.cloneWith(this.#e.onConflictNode,{updates:qt(e)})})}$call(e){return e(this)}};u(It,"don't await OnConflictBuilder instances.");var cr=class{#e;constructor(e){this.#e=r(e)}toOperationNode(){return this.#e.onConflictNode}};u(cr,"don't await OnConflictDoNothingBuilder instances.");var hr=class t{#e;constructor(e){this.#e=r(e)}where(...e){return new t({...this.#e,onConflictNode:V.cloneWithUpdateWhere(this.#e.onConflictNode,g(e))})}whereRef(e,i,o){return new t({...this.#e,onConflictNode:V.cloneWithUpdateWhere(this.#e.onConflictNode,k(e,i,o))})}clearWhere(){return new t({...this.#e,onConflictNode:V.cloneWithoutUpdateWhere(this.#e.onConflictNode)})}$call(e){return e(this)}toOperationNode(){return this.#e.onConflictNode}};u(hr,"don't await OnConflictUpdateBuilder instances.");var io=r({is(t){return t.kind==="TopNode"},create(t,e){return r({kind:"TopNode",expression:t,modifiers:e})}});function ie(t,e){if(!ve(t)&&!He(t))throw new Error(`Invalid top expression: ${t}`);if(!K(e)&&!dn(e))throw new Error(`Invalid top modifiers: ${e}`);return io.create(t,e)}function dn(t){return t==="percent"||t==="with ties"||t==="percent with ties"}var rt=class t{#e;constructor(e){this.#e=r(e)}values(e){let[i,o]=dr(e);return new t({...this.#e,queryNode:A.cloneWith(this.#e.queryNode,{columns:i,values:o})})}columns(e){return new t({...this.#e,queryNode:A.cloneWith(this.#e.queryNode,{columns:r(e.map(l.create))})})}expression(e){return new t({...this.#e,queryNode:A.cloneWith(this.#e.queryNode,{values:$(e)})})}defaultValues(){return new t({...this.#e,queryNode:A.cloneWith(this.#e.queryNode,{defaultValues:!0})})}ignore(){return new t({...this.#e,queryNode:A.cloneWith(this.#e.queryNode,{ignore:!0})})}top(e,i){return new t({...this.#e,queryNode:d.cloneWithTop(this.#e.queryNode,ie(e,i))})}onConflict(e){return new t({...this.#e,queryNode:A.cloneWith(this.#e.queryNode,{onConflict:e(new It({onConflictNode:V.create()})).toOperationNode()})})}onDuplicateKeyUpdate(e){return new t({...this.#e,queryNode:A.cloneWith(this.#e.queryNode,{onDuplicateKey:ro.create(qt(e))})})}returning(e){return new t({...this.#e,queryNode:d.cloneWithReturning(this.#e.queryNode,B(e))})}returningAll(){return new t({...this.#e,queryNode:d.cloneWithReturning(this.#e.queryNode,z())})}output(e){return new t({...this.#e,queryNode:d.cloneWithOutput(this.#e.queryNode,B(e))})}outputAll(e){return new t({...this.#e,queryNode:d.cloneWithOutput(this.#e.queryNode,z(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:o}=this.#e.executor,s=e.query;return s.returning&&o.supportsReturning||s.output&&o.supportsOutput?i.rows:[new pr(i.insertId,i.numAffectedRows??i.numUpdatedOrDeletedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=Z){let i=await this.executeTakeFirst();if(i===void 0)throw he(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:d.cloneWithExplain(this.#e.queryNode,e,i)}).execute()}};u(rt,"don't await InsertQueryBuilder instances directly. To execute the query you need to call `execute` or `executeTakeFirst`.");var mr=class{numDeletedRows;constructor(e){this.numDeletedRows=e}};var it=r({is(t){return t.kind==="LimitNode"},create(t){return r({kind:"LimitNode",limit:t})}});var St=class t{#e;constructor(e){this.#e=r(e)}where(...e){return new t({...this.#e,queryNode:d.cloneWithWhere(this.#e.queryNode,g(e))})}whereRef(e,i,o){return new t({...this.#e,queryNode:d.cloneWithWhere(this.#e.queryNode,k(e,i,o))})}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,ie(e,i))})}using(e){return new t({...this.#e,queryNode:ce.cloneWithUsing(this.#e.queryNode,me(e))})}innerJoin(...e){return new t({...this.#e,queryNode:d.cloneWithJoin(this.#e.queryNode,S("InnerJoin",e))})}leftJoin(...e){return new t({...this.#e,queryNode:d.cloneWithJoin(this.#e.queryNode,S("LeftJoin",e))})}rightJoin(...e){return new t({...this.#e,queryNode:d.cloneWithJoin(this.#e.queryNode,S("RightJoin",e))})}fullJoin(...e){return new t({...this.#e,queryNode:d.cloneWithJoin(this.#e.queryNode,S("FullJoin",e))})}returning(e){return new t({...this.#e,queryNode:d.cloneWithReturning(this.#e.queryNode,B(e))})}returningAll(e){return new t({...this.#e,queryNode:d.cloneWithReturning(this.#e.queryNode,z(e))})}output(e){return new t({...this.#e,queryNode:d.cloneWithOutput(this.#e.queryNode,B(e))})}outputAll(e){return new t({...this.#e,queryNode:d.cloneWithOutput(this.#e.queryNode,z(e))})}clearReturning(){return new t({...this.#e,queryNode:d.cloneWithoutReturning(this.#e.queryNode)})}clearLimit(){return new t({...this.#e,queryNode:ce.cloneWithoutLimit(this.#e.queryNode)})}clearOrderBy(){return new t({...this.#e,queryNode:ce.cloneWithoutOrderBy(this.#e.queryNode)})}orderBy(e,i){return new t({...this.#e,queryNode:ce.cloneWithOrderByItems(this.#e.queryNode,qe([e,i]))})}limit(e){return new t({...this.#e,queryNode:ce.cloneWithLimit(this.#e.queryNode,it.create(x(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 mr(i.numAffectedRows??i.numUpdatedOrDeletedRows??BigInt(0))]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=Z){let i=await this.executeTakeFirst();if(i===void 0)throw he(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:d.cloneWithExplain(this.#e.queryNode,e,i)}).execute()}};u(St,"don't await DeleteQueryBuilder instances directly. To execute the query you need to call `execute` or `executeTakeFirst`.");var lr=class{numUpdatedRows;numChangedRows;constructor(e,i){this.numUpdatedRows=e,this.numChangedRows=i}};var ze=class t{#e;constructor(e){this.#e=r(e)}where(...e){return new t({...this.#e,queryNode:d.cloneWithWhere(this.#e.queryNode,g(e))})}whereRef(e,i,o){return new t({...this.#e,queryNode:d.cloneWithWhere(this.#e.queryNode,k(e,i,o))})}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,ie(e,i))})}from(e){return new t({...this.#e,queryNode:pe.cloneWithFromItems(this.#e.queryNode,me(e))})}innerJoin(...e){return new t({...this.#e,queryNode:d.cloneWithJoin(this.#e.queryNode,S("InnerJoin",e))})}leftJoin(...e){return new t({...this.#e,queryNode:d.cloneWithJoin(this.#e.queryNode,S("LeftJoin",e))})}rightJoin(...e){return new t({...this.#e,queryNode:d.cloneWithJoin(this.#e.queryNode,S("RightJoin",e))})}fullJoin(...e){return new t({...this.#e,queryNode:d.cloneWithJoin(this.#e.queryNode,S("FullJoin",e))})}limit(e){return new t({...this.#e,queryNode:pe.cloneWithLimit(this.#e.queryNode,it.create(x(e)))})}set(...e){return new t({...this.#e,queryNode:pe.cloneWithUpdates(this.#e.queryNode,to(...e))})}returning(e){return new t({...this.#e,queryNode:d.cloneWithReturning(this.#e.queryNode,B(e))})}returningAll(e){return new t({...this.#e,queryNode:d.cloneWithReturning(this.#e.queryNode,z(e))})}output(e){return new t({...this.#e,queryNode:d.cloneWithOutput(this.#e.queryNode,B(e))})}outputAll(e){return new t({...this.#e,queryNode:d.cloneWithOutput(this.#e.queryNode,z(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:o}=this.#e.executor,s=e.query;return s.returning&&o.supportsReturning||s.output&&o.supportsOutput?i.rows:[new lr(i.numAffectedRows??i.numUpdatedOrDeletedRows??BigInt(0),i.numChangedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=Z){let i=await this.executeTakeFirst();if(i===void 0)throw he(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:d.cloneWithExplain(this.#e.queryNode,e,i)}).execute()}};u(ze,"don't await UpdateQueryBuilder instances directly. To execute the query you need to call `execute` or `executeTakeFirst`.");var pi=r({is(t){return t.kind==="CommonTableExpressionNameNode"},create(t,e){return r({kind:"CommonTableExpressionNameNode",table:X.create(t),columns:e?r(e.map(l.create)):void 0})}});var ot=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 kt=class t{#e;constructor(e){this.#e=r(e)}materialized(){return new t({...this.#e,node:ot.cloneWith(this.#e.node,{materialized:!0})})}notMaterialized(){return new t({...this.#e,node:ot.cloneWith(this.#e.node,{materialized:!1})})}toOperationNode(){return this.#e.node}};u(kt,"don't await CTEBuilder instances. They are never executed directly and are always just a part of a query.");function ci(t,e){let i=e(no()).toOperationNode();return C(t)?t(pn(i)).toOperationNode():ot.create(oo(t),i)}function pn(t){return e=>new kt({node:ot.create(oo(e),t)})}function oo(t){if(t.includes("(")){let e=t.split(/[\(\)]/),i=e[0],o=e[1].split(",").map(s=>s.trim());return pi.create(i,o)}else return pi.create(t)}var At=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 so=["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 ao(t){let e="";for(let i=0;i<t;++i)e+=cn();return e}function cn(){return so[~~(Math.random()*so.length)]}function N(){return new hi}var hi=class{#e;get queryId(){return this.#e===void 0&&(this.#e=ao(8)),this.#e}};var ke=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 hn=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}),fr=class extends ke{#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 a of i)this.#r.add(a);let o=this.#o(e);for(let a of o)this.#t.add(a);let s=super.transformNodeImpl(e);for(let a of o)this.#t.delete(a);for(let a of i)this.#r.delete(a);return s}transformSchemableIdentifier(e){let i=super.transformSchemableIdentifier(e);return i.schema||!this.#t.has(e.identifier.name)?i:{...i,schema:c.create(this.#e)}}transformReferences(e){let i=super.transformReferences(e);return i.table.table.schema?i:{...i,table:X.createWithSchema(this.#e,i.table.table.identifier.name)}}#i(e){return e.kind in hn}#o(e){let i=new Set;if("name"in e&&e.name&&U.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=X.is(e)?e:F.is(e)&&X.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 oe=class{#e;constructor(e){this.#e=new fr(e)}transformQuery(e){return this.#e.transformNode(e.node)}async transformResult(e){return e.result}};var uo=r({is(t){return t.kind==="MatchedNode"},create(t,e=!1){return r({kind:"MatchedNode",not:t,bySource:e})}});function mi(t,e,i){return xe.create(et([uo.create(!t.isMatched,t.bySource),...e&&e.length>0?[e.length===3&&i?k(e[0],e[1],e[2]):g(e)]:[]],"and",!1))}function nt(t){return W(t)?T.create([t],[]):v(t)?t.toOperationNode():t}var Et=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 po=new Set;function co(t){po.has(t)||(po.add(t),console.log(t))}var mn=r([]),st=class{#e;constructor(e=mn){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),a=await this.#t(s,i);return ln(s,a),a})}async*stream(e,i,o){let s=new Et,a=new Et;this.provideConnection(async h=>(s.resolve(h),await a.promise)).catch(h=>s.reject(h));let p=await s.promise;try{for await(let h of p.streamQuery(e,i))yield await this.#t(h,o)}finally{a.resolve()}}async#t(e,i){for(let o of this.#e)e=await o.transformResult({result:e,queryId:i});return e}};function ln(t,e){let{numAffectedRows:i}=t;i===void 0&&t.numUpdatedOrDeletedRows===void 0||i!==void 0&&e.numAffectedRows!==void 0||co("kysely:warning: outdated driver/plugin detected! QueryResult.numUpdatedOrDeletedRows is deprecated and will be removed in a future release.")}var li=class t extends st{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([])}},Ae=new li;var Nr=class{numChangedRows;constructor(e){this.numChangedRows=e}};var Rt=class t{#e;constructor(e){this.#e=r(e)}top(e,i){return new t({...this.#e,queryNode:d.cloneWithTop(this.#e.queryNode,ie(e,i))})}using(...e){return new ge({...this.#e,queryNode:E.cloneWithUsing(this.#e.queryNode,S("Using",e))})}output(e){return new t({...this.#e,queryNode:d.cloneWithOutput(this.#e.queryNode,B(e))})}outputAll(e){return new t({...this.#e,queryNode:d.cloneWithOutput(this.#e.queryNode,z(e))})}};u(Rt,"don't await MergeQueryBuilder instances directly. To execute the query you need to call `execute` when available.");var ge=class t{#e;constructor(e){this.#e=r(e)}top(e,i){return new t({...this.#e,queryNode:d.cloneWithTop(this.#e.queryNode,ie(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 Dt({...this.#e,queryNode:E.cloneWithWhen(this.#e.queryNode,mi({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:d.cloneWithOutput(this.#e.queryNode,B(e))})}outputAll(e){return new t({...this.#e,queryNode:d.cloneWithOutput(this.#e.queryNode,z(e))})}#r(e,i=!1,o=!1){let s={...this.#e,queryNode:E.cloneWithWhen(this.#e.queryNode,mi({isMatched:!1,bySource:o},e,i))},a=o?Dt:yr;return new a(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 Nr(i.numAffectedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=Z){let i=await this.executeTakeFirst();if(i===void 0)throw he(e)?new e(this.toOperationNode()):e(this.toOperationNode());return i}};u(ge,"don't await WheneableMergeQueryBuilder instances directly. To execute the query you need to call `execute`.");var Dt=class{#e;constructor(e){this.#e=r(e)}thenDelete(){return new ge({...this.#e,queryNode:E.cloneWithThen(this.#e.queryNode,nt("delete"))})}thenDoNothing(){return new ge({...this.#e,queryNode:E.cloneWithThen(this.#e.queryNode,nt("do nothing"))})}thenUpdate(e){return new ge({...this.#e,queryNode:E.cloneWithThen(this.#e.queryNode,nt(e(new ze({queryId:this.#e.queryId,executor:Ae,queryNode:pe.createWithoutTable()}))))})}thenUpdateSet(...e){return this.thenUpdate(i=>i.set(...e))}};u(Dt,"don't await MatchedThenableMergeQueryBuilder instances directly. To execute the query you need to call `execute` when available.");var yr=class{#e;constructor(e){this.#e=r(e)}thenDoNothing(){return new ge({...this.#e,queryNode:E.cloneWithThen(this.#e.queryNode,nt("do nothing"))})}thenInsertValues(e){let[i,o]=dr(e);return new ge({...this.#e,queryNode:E.cloneWithThen(this.#e.queryNode,nt(A.cloneWith(A.createWithoutInto(),{columns:i,values:o})))})}};u(yr,"don't await NotMatchedThenableMergeQueryBuilder instances directly. To execute the query you need to call `execute` when available.");var at=class t{#e;constructor(e){this.#e=r(e)}selectFrom(e){return Bt({queryId:N(),executor:this.#e.executor,queryNode:m.createFrom(me(e),this.#e.withNode)})}selectNoFrom(e){return Bt({queryId:N(),executor:this.#e.executor,queryNode:m.cloneWithSelections(m.create(this.#e.withNode),B(e))})}insertInto(e){return new rt({queryId:N(),executor:this.#e.executor,queryNode:A.create(y(e),this.#e.withNode)})}replaceInto(e){return new rt({queryId:N(),executor:this.#e.executor,queryNode:A.create(y(e),this.#e.withNode,!0)})}deleteFrom(e){return new St({queryId:N(),executor:this.#e.executor,queryNode:ce.create(me(e),this.#e.withNode)})}updateTable(e){return new ze({queryId:N(),executor:this.#e.executor,queryNode:pe.create(Ee(e),this.#e.withNode)})}mergeInto(e){return new Rt({queryId:N(),executor:this.#e.executor,queryNode:E.create(fi(e),this.#e.withNode)})}with(e,i){let o=ci(e,i);return new t({...this.#e,withNode:this.#e.withNode?At.cloneWithExpression(this.#e.withNode,o):At.create(o)})}withRecursive(e,i){let o=ci(e,i);return new t({...this.#e,withNode:this.#e.withNode?At.cloneWithExpression(this.#e.withNode,o):At.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 oe(e))})}};function no(){return new at({executor:Ae})}function ho(t,e){return new Wt({joinNode:We.create(t,Ee(e))})}function mo(){return new Tt({overNode:Ct.create()})}function S(t,e){if(e.length===3)return Nn(t,e[0],e[1],e[2]);if(e.length===2)return fn(t,e[0],e[1]);throw new Error("not implemented")}function fn(t,e,i){return i(ho(t,e)).toOperationNode()}function Nn(t,e,i,o){return We.createWithOn(t,Ee(e),k(i,"=",o))}var lo=r({is(t){return t.kind==="OffsetNode"},create(t){return r({kind:"OffsetNode",offset:t})}});var fo=r({is(t){return t.kind==="GroupByItemNode"},create(t){return r({kind:"GroupByItemNode",groupBy:t})}});function No(t){return t=C(t)?t(re()):t,ye(t).map(fo.create)}var wr=r({is(t){return t.kind==="SetOperationNode"},create(t,e,i){return r({kind:"SetOperationNode",operator:t,expression:e,all:i})}});function Me(t,e,i){return C(e)&&(e=e(xr())),L(e)||(e=[e]),e.map(o=>wr.create(t,$(o),i))}var w=class t{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new Qt(this,e)}or(...e){return new Ni(te.create(this.#e,g(e)))}and(...e){return new yi(J.create(this.#e,g(e)))}$castTo(){return new t(this.#e)}$notNull(){return new t(this.#e)}toOperationNode(){return this.#e}},Qt=class{#e;#t;constructor(e,i){this.#e=e,this.#t=i}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return F.create(this.#e.toOperationNode(),v(this.#t)?this.#t.toOperationNode():c.create(this.#t))}},Ni=class t{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new Qt(this,e)}or(...e){return new t(te.create(this.#e,g(e)))}$castTo(){return new t(this.#e)}toOperationNode(){return de.create(this.#e)}},yi=class t{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new Qt(this,e)}and(...e){return new t(J.create(this.#e,g(e)))}$castTo(){return new t(this.#e)}toOperationNode(){return de.create(this.#e)}};var yo={is(t){return t.kind==="FetchNode"},create(t,e){return{kind:"FetchNode",rowCount:I.create(t),modifier:e}}};function wo(t,e){if(!ve(t)&&!He(t))throw new Error(`Invalid fetch row count: ${t}`);if(!yn(e))throw new Error(`Invalid fetch modifier: ${e}`);return yo.create(t,e)}function yn(t){return t==="only"||t==="with ties"}var gr=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,g(e))})}whereRef(e,i,o){return new t({...this.#e,queryNode:d.cloneWithWhere(this.#e.queryNode,k(e,i,o))})}having(...e){return new t({...this.#e,queryNode:m.cloneWithHaving(this.#e.queryNode,g(e))})}havingRef(e,i,o){return new t({...this.#e,queryNode:m.cloneWithHaving(this.#e.queryNode,k(e,i,o))})}select(e){return new t({...this.#e,queryNode:m.cloneWithSelections(this.#e.queryNode,B(e))})}distinctOn(e){return new t({...this.#e,queryNode:m.cloneWithDistinctOn(this.#e.queryNode,ye(e))})}modifyFront(e){return new t({...this.#e,queryNode:m.cloneWithFrontModifier(this.#e.queryNode,ue.createWithExpression(e.toOperationNode()))})}modifyEnd(e){return new t({...this.#e,queryNode:m.cloneWithEndModifier(this.#e.queryNode,ue.createWithExpression(e.toOperationNode()))})}distinct(){return new t({...this.#e,queryNode:m.cloneWithFrontModifier(this.#e.queryNode,ue.create("Distinct"))})}forUpdate(e){return new t({...this.#e,queryNode:m.cloneWithEndModifier(this.#e.queryNode,ue.create("ForUpdate",e?gt(e).map(y):void 0))})}forShare(e){return new t({...this.#e,queryNode:m.cloneWithEndModifier(this.#e.queryNode,ue.create("ForShare",e?gt(e).map(y):void 0))})}forKeyShare(e){return new t({...this.#e,queryNode:m.cloneWithEndModifier(this.#e.queryNode,ue.create("ForKeyShare",e?gt(e).map(y):void 0))})}forNoKeyUpdate(e){return new t({...this.#e,queryNode:m.cloneWithEndModifier(this.#e.queryNode,ue.create("ForNoKeyUpdate",e?gt(e).map(y):void 0))})}skipLocked(){return new t({...this.#e,queryNode:m.cloneWithEndModifier(this.#e.queryNode,ue.create("SkipLocked"))})}noWait(){return new t({...this.#e,queryNode:m.cloneWithEndModifier(this.#e.queryNode,ue.create("NoWait"))})}selectAll(e){return new t({...this.#e,queryNode:m.cloneWithSelections(this.#e.queryNode,z(e))})}innerJoin(...e){return new t({...this.#e,queryNode:d.cloneWithJoin(this.#e.queryNode,S("InnerJoin",e))})}leftJoin(...e){return new t({...this.#e,queryNode:d.cloneWithJoin(this.#e.queryNode,S("LeftJoin",e))})}rightJoin(...e){return new t({...this.#e,queryNode:d.cloneWithJoin(this.#e.queryNode,S("RightJoin",e))})}fullJoin(...e){return new t({...this.#e,queryNode:d.cloneWithJoin(this.#e.queryNode,S("FullJoin",e))})}innerJoinLateral(...e){return new t({...this.#e,queryNode:d.cloneWithJoin(this.#e.queryNode,S("LateralInnerJoin",e))})}leftJoinLateral(...e){return new t({...this.#e,queryNode:d.cloneWithJoin(this.#e.queryNode,S("LateralLeftJoin",e))})}orderBy(...e){return new t({...this.#e,queryNode:m.cloneWithOrderByItems(this.#e.queryNode,qe(e))})}groupBy(e){return new t({...this.#e,queryNode:m.cloneWithGroupByItems(this.#e.queryNode,No(e))})}limit(e){return new t({...this.#e,queryNode:m.cloneWithLimit(this.#e.queryNode,it.create(x(e)))})}offset(e){return new t({...this.#e,queryNode:m.cloneWithOffset(this.#e.queryNode,lo.create(x(e)))})}fetch(e,i="only"){return new t({...this.#e,queryNode:m.cloneWithFetch(this.#e.queryNode,wo(e,i))})}top(e,i){return new t({...this.#e,queryNode:d.cloneWithTop(this.#e.queryNode,ie(e,i))})}union(e){return new t({...this.#e,queryNode:m.cloneWithSetOperations(this.#e.queryNode,Me("union",e,!1))})}unionAll(e){return new t({...this.#e,queryNode:m.cloneWithSetOperations(this.#e.queryNode,Me("union",e,!0))})}intersect(e){return new t({...this.#e,queryNode:m.cloneWithSetOperations(this.#e.queryNode,Me("intersect",e,!1))})}intersectAll(e){return new t({...this.#e,queryNode:m.cloneWithSetOperations(this.#e.queryNode,Me("intersect",e,!0))})}except(e){return new t({...this.#e,queryNode:m.cloneWithSetOperations(this.#e.queryNode,Me("except",e,!1))})}exceptAll(e){return new t({...this.#e,queryNode:m.cloneWithSetOperations(this.#e.queryNode,Me("except",e,!0))})}as(e){return new Or(this,e)}clearSelect(){return new t({...this.#e,queryNode:m.cloneWithoutSelections(this.#e.queryNode)})}clearWhere(){return new t({...this.#e,queryNode:d.cloneWithoutWhere(this.#e.queryNode)})}clearLimit(){return new t({...this.#e,queryNode:m.cloneWithoutLimit(this.#e.queryNode)})}clearOffset(){return new t({...this.#e,queryNode:m.cloneWithoutOffset(this.#e.queryNode)})}clearOrderBy(){return new t({...this.#e,queryNode:m.cloneWithoutOrderBy(this.#e.queryNode)})}clearGroupBy(){return new t({...this.#e,queryNode:m.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 w(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=Z){let i=await this.executeTakeFirst();if(i===void 0)throw he(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:d.cloneWithExplain(this.#e.queryNode,e,i)}).execute()}};u(gr,"don't await SelectQueryBuilder instances directly. To execute the query you need to call `execute` or `executeTakeFirst`.");function Bt(t){return new gr(t)}var Or=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 F.create(this.#e.toOperationNode(),c.create(this.#t))}};u(Or,"don't await AliasedSelectQueryBuilder instances directly. AliasedSelectQueryBuilder should never be executed directly since it's always a part of another query.");var Oe=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?Q.cloneWithOperation(t.filter,"And",e):Q.create(e)})},cloneWithOrFilter(t,e){return r({...t,filter:t.filter?Q.cloneWithOperation(t.filter,"Or",e):Q.create(e)})},cloneWithOver(t,e){return r({...t,over:e})}});var wi=r({is(t){return t.kind==="FunctionNode"},create(t,e){return r({kind:"FunctionNode",func:t,arguments:e})}});var Ve=class t{#e;constructor(e){this.#e=r(e)}get expressionType(){}as(e){return new xi(this,e)}distinct(){return new t({...this.#e,aggregateFunctionNode:Oe.cloneWithDistinct(this.#e.aggregateFunctionNode)})}filterWhere(...e){return new t({...this.#e,aggregateFunctionNode:Oe.cloneWithFilter(this.#e.aggregateFunctionNode,g(e))})}filterWhereRef(e,i,o){return new t({...this.#e,aggregateFunctionNode:Oe.cloneWithFilter(this.#e.aggregateFunctionNode,k(e,i,o))})}over(e){let i=mo();return new t({...this.#e,aggregateFunctionNode:Oe.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(Ve,"don't await AggregateFunctionBuilder instances. They are never executed directly and are always just a part of a query.");var xi=class{#e;#t;constructor(e,i){this.#e=e,this.#t=i}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return F.create(this.#e.toOperationNode(),c.create(this.#t))}};function br(){let t=(i,o)=>new w(wi.create(i,ye(o??[]))),e=(i,o)=>new Ve({aggregateFunctionNode:Oe.create(i,o?ye(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 Ve({aggregateFunctionNode:Oe.create("count",z(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 Ve({aggregateFunctionNode:Oe.create("json_agg",[W(i)?y(i):i.toOperationNode()])})},toJson(i){return new w(wi.create("to_json",[W(i)?y(i):i.toOperationNode()]))}})}var xo=r({is(t){return t.kind==="UnaryOperationNode"},create(t,e){return r({kind:"UnaryOperationNode",operator:t,operand:e})}});function go(t,e){return xo.create(j.create(t),D(e))}var H=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),xe.cloneWithResult(t.when[t.when.length-1],e)]):void 0})},cloneWith(t,e){return r({...t,...e})}});var ut=class{#e;constructor(e){this.#e=r(e)}when(...e){return new vr({...this.#e,node:H.cloneWithWhen(this.#e.node,xe.create(g(e)))})}},vr=class{#e;constructor(e){this.#e=r(e)}then(e){return new gi({...this.#e,node:H.cloneWithThen(this.#e.node,sr(e)?vt(e):x(e))})}},gi=class{#e;constructor(e){this.#e=r(e)}when(...e){return new vr({...this.#e,node:H.cloneWithWhen(this.#e.node,xe.create(g(e)))})}else(e){return new Oi({...this.#e,node:H.cloneWith(this.#e.node,{else:sr(e)?vt(e):x(e)})})}end(){return new w(H.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new w(H.cloneWith(this.#e.node,{isStatement:!0}))}},Oi=class{#e;constructor(e){this.#e=r(e)}end(){return new w(H.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new w(H.cloneWith(this.#e.node,{isStatement:!0}))}};var bi=r({is(t){return t.kind==="JSONPathLegNode"},create(t,e){return r({kind:"JSONPathLegNode",type:t,value:e})}});var Re=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 Ze.is(this.#e)?new Cr(Ze.cloneWithTraversal(this.#e,Ie.is(this.#e.traversal)?Ie.cloneWithLeg(this.#e.traversal,bi.create(e,i)):or.cloneWithValue(this.#e.traversal,I.createImmediate(i)))):new Cr(Ie.cloneWithLeg(this.#e,bi.create(e,i)))}},Cr=class extends Re{#e;constructor(e){super(e),this.#e=e}get expressionType(){}as(e){return new vi(this,e)}$castTo(){return new Re(this.#e)}$notNull(){return new Re(this.#e)}toOperationNode(){return this.#e}},vi=class{#e;#t;constructor(e,i){this.#e=e,this.#t=i}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return F.create(this.#e.toOperationNode(),v(this.#t)?this.#t.toOperationNode():c.create(this.#t))}};var Ci=r({is(t){return t.kind==="TupleNode"},create(t){return r({kind:"TupleNode",values:r(t)})}});var wn=["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"],xn=[/^varchar\(\d+\)$/,/^char\(\d+\)$/,/^decimal\(\d+, \d+\)$/,/^numeric\(\d+, \d+\)$/,/^binary\(\d+\)$/,/^datetime\(\d+\)$/,/^time\(\d+\)$/,/^timetz\(\d+\)$/,/^timestamp\(\d+\)$/,/^timestamptz\(\d+\)$/,/^varbinary\(\d+\)$/],Oo=r({is(t){return t.kind==="DataTypeNode"},create(t){return r({kind:"DataTypeNode",dataType:t})}});function bo(t){return!!(wn.includes(t)||xn.some(e=>e.test(t)))}function ne(t){if(v(t))return t.toOperationNode();if(bo(t))return Oo.create(t);throw new Error(`invalid column data type ${JSON.stringify(t)}`)}var vo=r({is(t){return t.kind==="CastNode"},create(t,e){return r({kind:"CastNode",expression:t,dataType:e})}});function xr(t=Ae){function e(s,a,p){return new w(ar(s,a,p))}function i(s,a){return new w(go(s,a))}let o=Object.assign(e,{fn:void 0,eb:void 0,selectFrom(s){return Bt({queryId:N(),executor:t,queryNode:m.createFrom(me(s))})},case(s){return new ut({node:H.create(K(s)?void 0:D(s))})},ref(s,a){return K(a)?new w(G(s)):new Re(Ui(s,a))},jsonPath(){return new Re(Ie.create())},table(s){return new w(y(s))},val(s){return new w(x(s))},refTuple(...s){return new w(Ci.create(s.map(D)))},tuple(...s){return new w(Ci.create(s.map(x)))},lit(s){return new w(vt(s))},unary:i,not(s){return i("not",s)},exists(s){return i("exists",s)},neg(s){return i("-",s)},between(s,a,p){return new w(Te.create(D(s),j.create("between"),J.create(x(a),x(p))))},betweenSymmetric(s,a,p){return new w(Te.create(D(s),j.create("between symmetric"),J.create(x(a),x(p))))},and(s){return L(s)?new w(et(s,"and")):new w(ri(s,"and"))},or(s){return L(s)?new w(et(s,"or")):new w(ri(s,"or"))},parens(...s){let a=g(s);return de.is(a)?new w(a):new w(de.create(a))},cast(s,a){return new w(vo.create(D(s),ne(a)))},withSchema(s){return xr(t.withPluginAtFront(new oe(s)))}});return o.fn=br(),o.eb=o,o}function re(t){return xr()}function $(t){if(v(t))return t.toOperationNode();if(C(t))return t(re()).toOperationNode();throw new Error(`invalid expression: ${JSON.stringify(t)}`)}function ur(t){if(v(t))return t.toOperationNode();if(C(t))return t(re()).toOperationNode();throw new Error(`invalid aliased expression: ${JSON.stringify(t)}`)}function Ne(t){return Pi(t)||Fi(t)||C(t)}function me(t){return L(t)?t.map(e=>Ee(e)):[Ee(t)]}function Ee(t){return W(t)?fi(t):ur(t)}function fi(t){let e=" as ";if(t.includes(e)){let[i,o]=t.split(e).map(Co);return F.create(y(i),c.create(o))}else return y(t)}function y(t){let e=".";if(t.includes(e)){let[i,o]=t.split(e).map(Co);return X.createWithSchema(i,o)}else return X.create(t)}function Co(t){return t.trim()}var Wi=r({is(t){return t.kind==="AddColumnNode"},create(t){return r({kind:"AddColumnNode",column:t})}});var O=r({is(t){return t.kind==="ColumnDefinitionNode"},create(t,e){return r({kind:"ColumnDefinitionNode",column:l.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 Ti=r({is(t){return t.kind==="DropColumnNode"},create(t){return r({kind:"DropColumnNode",column:l.create(t)})}});var qi=r({is(t){return t.kind==="RenameColumnNode"},create(t,e){return r({kind:"RenameColumnNode",column:l.create(t),renameTo:l.create(e)})}});var dt=r({is(t){return t.kind==="CheckConstraintNode"},create(t,e){return r({kind:"CheckConstraintNode",expression:t,name:e?c.create(e):void 0})}});var Wo=["no action","restrict","cascade","set null","set default"],pt=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 Wr(t){return v(t)?t.toOperationNode():I.createImmediate(t)}var Lt=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 To=r({is(t){return t.kind==="DefaultValueNode"},create(t){return r({kind:"DefaultValueNode",defaultValue:t})}});function ct(t){if(Wo.includes(t))return t;throw new Error(`invalid OnModifyForeignAction ${t}`)}var le=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=G(e);if(!i.table||Ye.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:pt.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:pt.cloneWithOnDelete(this.#e.references,ct(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:pt.cloneWithOnUpdate(this.#e.references,ct(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:To.create(Wr(e))}))}check(e){return new t(O.cloneWith(this.#e,{check:dt.create(e.toOperationNode())}))}generatedAlwaysAs(e){return new t(O.cloneWith(this.#e,{generated:Lt.createWithExpression(e.toOperationNode())}))}generatedAlwaysAsIdentity(){return new t(O.cloneWith(this.#e,{generated:Lt.create({identity:!0,always:!0})}))}generatedByDefaultAsIdentity(){return new t(O.cloneWith(this.#e,{generated:Lt.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:Lt.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(le,"don't await ColumnDefinitionBuilder instances directly.");var Ii=r({is(t){return t.kind==="ModifyColumnNode"},create(t){return r({kind:"ModifyColumnNode",column:t})}});var Ue=r({is(t){return t.kind==="ForeignKeyConstraintNode"},create(t,e,i,o){return r({kind:"ForeignKeyConstraintNode",columns:t,references:pt.create(e,i),name:o?c.create(o):void 0})},cloneWith(t,e){return r({...t,...e})}});var Je=class t{#e;constructor(e){this.#e=e}onDelete(e){return new t(Ue.cloneWith(this.#e,{onDelete:ct(e)}))}onUpdate(e){return new t(Ue.cloneWith(this.#e,{onUpdate:ct(e)}))}$call(e){return e(this)}toOperationNode(){return this.#e}};u(Je,"don't await ForeignKeyConstraintBuilder instances directly.");var ht=r({is(t){return t.kind==="AddConstraintNode"},create(t){return r({kind:"AddConstraintNode",constraint:t})}});var mt=r({is(t){return t.kind==="UniqueConstraintNode"},create(t,e,i){return r({kind:"UniqueConstraintNode",columns:r(t.map(l.create)),name:e?c.create(e):void 0,nullsNotDistinct:i})},cloneWith(t,e){return r({...t,...e})}});var lt=r({is(t){return t.kind==="DropConstraintNode"},create(t){return r({kind:"DropConstraintNode",constraintName:c.create(t)})},cloneWith(t,e){return r({...t,...e})}});var ft=r({is(t){return t.kind==="AlterColumnNode"},create(t,e,i){return r({kind:"AlterColumnNode",column:l.create(t),[e]:i})}});var Nt=class{#e;constructor(e){this.#e=e}setDataType(e){return new De(ft.create(this.#e,"dataType",ne(e)))}setDefault(e){return new De(ft.create(this.#e,"setDefault",Wr(e)))}dropDefault(){return new De(ft.create(this.#e,"dropDefault",!0))}setNotNull(){return new De(ft.create(this.#e,"setNotNull",!0))}dropNotNull(){return new De(ft.create(this.#e,"dropNotNull",!0))}$call(e){return e(this)}};u(Nt,"don't await AlterColumnBuilder instances");var De=class{#e;constructor(e){this.#e=e}toOperationNode(){return this.#e}};u(De,"don't await AlteredColumnBuilder instances");var fe=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(fe,"don't await AlterTableExecutor instances directly. To execute the query you need to call `execute`");var Pt=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(f.cloneWithTableProps(this.#e.node,{addConstraint:ht.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(Pt,"don't await AlterTableAddForeignKeyConstraintBuilder instances directly. To execute the query you need to call `execute`");var Ft=class t{#e;constructor(e){this.#e=r(e)}ifExists(){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{dropConstraint:lt.cloneWith(this.#e.node.dropConstraint,{ifExists:!0})})})}cascade(){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{dropConstraint:lt.cloneWith(this.#e.node.dropConstraint,{modifier:"cascade"})})})}restrict(){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{dropConstraint:lt.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(Ft,"don't await AlterTableDropConstraintBuilder instances directly. To execute the query you need to call `execute`");var Tr=r({is(t){return t.kind==="PrimaryKeyConstraintNode"},create(t,e){return r({kind:"PrimaryKeyConstraintNode",columns:r(t.map(l.create)),name:e?c.create(e):void 0})}});var Be=r({is(t){return t.kind==="AddIndexNode"},create(t){return r({kind:"AddIndexNode",name:c.create(t)})},cloneWith(t,e){return r({...t,...e})},cloneWithColumns(t,e){return r({...t,columns:[...t.columns||[],...e]})}});var zt=class t{#e;constructor(e){this.#e=r(e)}unique(){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addIndex:Be.cloneWith(this.#e.node.addIndex,{unique:!0})})})}column(e){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addIndex:Be.cloneWithColumns(this.#e.node.addIndex,[_e(e)])})})}columns(e){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addIndex:Be.cloneWithColumns(this.#e.node.addIndex,e.map(_e))})})}expression(e){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addIndex:Be.cloneWithColumns(this.#e.node.addIndex,[e.toOperationNode()])})})}using(e){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addIndex:Be.cloneWith(this.#e.node.addIndex,{using:T.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(zt,"don't await AlterTableAddIndexBuilder instances directly. To execute the query you need to call `execute`");var $e=class t{#e;constructor(e){this.#e=e}toOperationNode(){return this.#e}nullsNotDistinct(){return new t(mt.cloneWith(this.#e,{nullsNotDistinct:!0}))}};u($e,"don't await UniqueConstraintNodeBuilder instances directly.");var Mt=class{#e;constructor(e){this.#e=r(e)}renameTo(e){return new fe({...this.#e,node:f.cloneWithTableProps(this.#e.node,{renameTo:y(e)})})}setSchema(e){return new fe({...this.#e,node:f.cloneWithTableProps(this.#e.node,{setSchema:c.create(e)})})}alterColumn(e,i){let o=i(new Nt(e));return new Qe({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,o.toOperationNode())})}dropColumn(e){return new Qe({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Ti.create(e))})}renameColumn(e,i){return new Qe({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,qi.create(e,i))})}addColumn(e,i,o=ae){let s=o(new le(O.create(e,ne(i))));return new Qe({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Wi.create(s.toOperationNode()))})}modifyColumn(e,i,o=ae){let s=o(new le(O.create(e,ne(i))));return new Qe({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Ii.create(s.toOperationNode()))})}addUniqueConstraint(e,i,o=ae){let s=o(new $e(mt.create(i,e)));return new fe({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addConstraint:ht.create(s.toOperationNode())})})}addCheckConstraint(e,i){return new fe({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addConstraint:ht.create(dt.create(i.toOperationNode(),e))})})}addForeignKeyConstraint(e,i,o,s){return new Pt({...this.#e,constraintBuilder:new Je(Ue.create(i.map(l.create),y(o),s.map(l.create),e))})}addPrimaryKeyConstraint(e,i){return new fe({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addConstraint:ht.create(Tr.create(i,e))})})}dropConstraint(e){return new Ft({...this.#e,node:f.cloneWithTableProps(this.#e.node,{dropConstraint:lt.create(e)})})}addIndex(e){return new zt({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addIndex:Be.create(e)})})}dropIndex(e){return new fe({...this.#e,node:f.cloneWithTableProps(this.#e.node,{dropIndex:Ce.create(e)})})}$call(e){return e(this)}};u(Mt,"don't await AlterTableBuilder instances");var Qe=class t{#e;constructor(e){this.#e=r(e)}alterColumn(e,i){let o=i(new Nt(e));return new t({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,o.toOperationNode())})}dropColumn(e){return new t({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Ti.create(e))})}renameColumn(e,i){return new t({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,qi.create(e,i))})}addColumn(e,i,o=ae){let s=o(new le(O.create(e,ne(i))));return new t({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Wi.create(s.toOperationNode()))})}modifyColumn(e,i,o=ae){let s=o(new le(O.create(e,ne(i))));return new t({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Ii.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)}};u(Qe,"don't await AlterTableColumnAlteringBuilder instances directly. To execute the query you need to call `execute`");var yt=class extends ke{transformValue(e){return{...super.transformValue(e),immediate:!0}}};var Vt=class t{#e;constructor(e){this.#e=r(e)}ifNotExists(){return new t({...this.#e,node:ee.cloneWith(this.#e.node,{ifNotExists:!0})})}unique(){return new t({...this.#e,node:ee.cloneWith(this.#e.node,{unique:!0})})}nullsNotDistinct(){return new t({...this.#e,node:ee.cloneWith(this.#e.node,{nullsNotDistinct:!0})})}on(e){return new t({...this.#e,node:ee.cloneWith(this.#e.node,{table:y(e)})})}column(e){return new t({...this.#e,node:ee.cloneWithColumns(this.#e.node,[_e(e)])})}columns(e){return new t({...this.#e,node:ee.cloneWithColumns(this.#e.node,e.map(_e))})}expression(e){return new t({...this.#e,node:ee.cloneWithColumns(this.#e.node,[e.toOperationNode()])})}using(e){return new t({...this.#e,node:ee.cloneWith(this.#e.node,{using:T.createWithSql(e)})})}where(...e){let i=new yt;return new t({...this.#e,node:d.cloneWithWhere(this.#e.node,i.transformNode(g(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(Vt,"don't await CreateIndexBuilder instances directly. To execute the query you need to call `execute`");var Ut=class t{#e;constructor(e){this.#e=r(e)}ifNotExists(){return new t({...this.#e,node:_t.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(Ut,"don't await CreateSchemaBuilder instances directly. To execute the query you need to call `execute`");function qo(t){if(Li.includes(t))return t;throw new Error(`invalid OnCommitAction ${t}`)}var Jt=class t{#e;constructor(e){this.#e=r(e)}temporary(){return new t({...this.#e,node:P.cloneWith(this.#e.node,{temporary:!0})})}onCommit(e){return new t({...this.#e,node:P.cloneWith(this.#e.node,{onCommit:qo(e)})})}ifNotExists(){return new t({...this.#e,node:P.cloneWith(this.#e.node,{ifNotExists:!0})})}addColumn(e,i,o=ae){let s=o(new le(O.create(e,ne(i))));return new t({...this.#e,node:P.cloneWithColumn(this.#e.node,s.toOperationNode())})}addPrimaryKeyConstraint(e,i){return new t({...this.#e,node:P.cloneWithConstraint(this.#e.node,Tr.create(i,e))})}addUniqueConstraint(e,i,o=ae){let s=o(new $e(mt.create(i,e)));return new t({...this.#e,node:P.cloneWithConstraint(this.#e.node,s.toOperationNode())})}addCheckConstraint(e,i){return new t({...this.#e,node:P.cloneWithConstraint(this.#e.node,dt.create(i.toOperationNode(),e))})}addForeignKeyConstraint(e,i,o,s,a=ae){let p=a(new Je(Ue.create(i.map(l.create),y(o),s.map(l.create),e)));return new t({...this.#e,node:P.cloneWithConstraint(this.#e.node,p.toOperationNode())})}modifyFront(e){return new t({...this.#e,node:P.cloneWithFrontModifier(this.#e.node,e.toOperationNode())})}modifyEnd(e){return new t({...this.#e,node:P.cloneWithEndModifier(this.#e.node,e.toOperationNode())})}as(e){return new t({...this.#e,node:P.cloneWith(this.#e.node,{selectQuery:$(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(Jt,"don't await CreateTableBuilder instances directly. To execute the query you need to call `execute`");var $t=class t{#e;constructor(e){this.#e=r(e)}on(e){return new t({...this.#e,node:Ce.cloneWith(this.#e.node,{table:y(e)})})}ifExists(){return new t({...this.#e,node:Ce.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:Ce.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($t,"don't await DropIndexBuilder instances directly. To execute the query you need to call `execute`");var Kt=class t{#e;constructor(e){this.#e=r(e)}ifExists(){return new t({...this.#e,node:Ot.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:Ot.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(Kt,"don't await DropSchemaBuilder instances directly. To execute the query you need to call `execute`");var jt=class t{#e;constructor(e){this.#e=r(e)}ifExists(){return new t({...this.#e,node:bt.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:bt.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 DropTableBuilder instances directly. To execute the query you need to call `execute`");var se=r({is(t){return t.kind==="CreateViewNode"},create(t){return r({kind:"CreateViewNode",name:U.create(t)})},cloneWith(t,e){return r({...t,...e})}});var qr=class{#e=new yt;transformQuery(e){return this.#e.transformNode(e.node)}transformResult(e){return Promise.resolve(e.result)}};var Gt=class t{#e;constructor(e){this.#e=r(e)}temporary(){return new t({...this.#e,node:se.cloneWith(this.#e.node,{temporary:!0})})}materialized(){return new t({...this.#e,node:se.cloneWith(this.#e.node,{materialized:!0})})}ifNotExists(){return new t({...this.#e,node:se.cloneWith(this.#e.node,{ifNotExists:!0})})}orReplace(){return new t({...this.#e,node:se.cloneWith(this.#e.node,{orReplace:!0})})}columns(e){return new t({...this.#e,node:se.cloneWith(this.#e.node,{columns:e.map(_r)})})}as(e){let i=e.withPlugin(new qr).toOperationNode();return new t({...this.#e,node:se.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(Gt,"don't await CreateViewBuilder instances directly. To execute the query you need to call `execute`");var wt=r({is(t){return t.kind==="DropViewNode"},create(t){return r({kind:"DropViewNode",name:U.create(t)})},cloneWith(t,e){return r({...t,...e})}});var Ht=class t{#e;constructor(e){this.#e=r(e)}materialized(){return new t({...this.#e,node:wt.cloneWith(this.#e.node,{materialized:!0})})}ifExists(){return new t({...this.#e,node:wt.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:wt.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(Ht,"don't await DropViewBuilder instances directly. To execute the query you need to call `execute`");var Ir=r({is(t){return t.kind==="CreateTypeNode"},create(t){return r({kind:"CreateTypeNode",name:t})},cloneWithEnum(t,e){return r({...t,enum:Se.create(e.map(i=>I.createImmediate(i)))})}});var Yt=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:Ir.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(Yt,"don't await CreateTypeBuilder instances directly. To execute the query you need to call `execute`");var Sr=r({is(t){return t.kind==="DropTypeNode"},create(t){return r({kind:"DropTypeNode",name:t})},cloneWith(t,e){return r({...t,...e})}});var Xt=class t{#e;constructor(e){this.#e=r(e)}ifExists(){return new t({...this.#e,node:Sr.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(Xt,"don't await DropTypeBuilder instances directly. To execute the query you need to call `execute`");function Si(t){let e=".";if(t.includes(e)){let i=t.split(e).map(gn);if(i.length===2)return U.createWithSchema(i[0],i[1]);throw new Error(`invalid schemable identifier ${t}`)}else return U.create(t)}function gn(t){return t.trim()}var kr=class t{#e;constructor(e){this.#e=e}createTable(e){return new Jt({queryId:N(),executor:this.#e,node:P.create(y(e))})}dropTable(e){return new jt({queryId:N(),executor:this.#e,node:bt.create(y(e))})}createIndex(e){return new Vt({queryId:N(),executor:this.#e,node:ee.create(e)})}dropIndex(e){return new $t({queryId:N(),executor:this.#e,node:Ce.create(e)})}createSchema(e){return new Ut({queryId:N(),executor:this.#e,node:_t.create(e)})}dropSchema(e){return new Kt({queryId:N(),executor:this.#e,node:Ot.create(e)})}alterTable(e){return new Mt({queryId:N(),executor:this.#e,node:f.create(y(e))})}createView(e){return new Gt({queryId:N(),executor:this.#e,node:se.create(e)})}dropView(e){return new Ht({queryId:N(),executor:this.#e,node:wt.create(e)})}createType(e){return new Yt({queryId:N(),executor:this.#e,node:Ir.create(Si(e))})}dropType(e){return new Xt({queryId:N(),executor:this.#e,node:Sr.create(Si(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 oe(e)))}};var Ar=class{ref(e){return new tr(e)}};var Er=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 Rr=class t extends st{#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 ki(){return typeof performance<"u"&&C(performance.now)?performance.now():Date.now()}var Dr=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,a=ki();try{return await i.call(e,o)}catch(p){throw s=p,await this.#u(p,o,a),p}finally{s||await this.#p(o,a)}}}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 ki()-e}};var On=()=>{},Zt=class{#e;#t;constructor(e){this.#e=e}async provideConnection(e){for(;this.#t;)await this.#t.catch(On);return this.#t=this.#r(e).finally(()=>{this.#t=void 0}),this.#t}async#r(e){return await e(this.#e)}};var Io=["read uncommitted","read committed","repeatable read","serializable","snapshot"];var Qv=r(["query","error"]),Br=class{#e;#t;constructor(e){C(e)?(this.#t=e,this.#e=r({query:!0,error:!0})):(this.#t=bn,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 bn(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 So(t){return M(t)&&C(t.compile)}var xt=class t extends at{#e;constructor(e){let i,o;if(vn(e))i={executor:e.executor},o={...e};else{let s=e.dialect,a=s.createDriver(),p=s.createQueryCompiler(),h=s.createAdapter(),b=new Br(e.log??[]),q=new Dr(a,b),R=new Er(q),_=new Rr(p,h,R,e.plugins??[]);i={executor:_},o={config:e,executor:_,dialect:s,driver:q}}super(i),this.#e=r(o)}get schema(){return new kr(this.#e.executor)}get dynamic(){return new Ar}get introspection(){return this.#e.dialect.createIntrospector(this.withoutPlugins())}case(e){return new ut({node:H.create(K(e)?void 0:$(e))})}get fn(){return br()}transaction(){return new Lr({...this.#e})}connection(){return new Qr({...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 oe(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=N()){let o=So(e)?e.compile():e;return this.getExecutor().executeQuery(o,i)}},Ai=class t extends xt{#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 oe(e))})}withTables(){return new t({...this.#e})}};function vn(t){return M(t)&&M(t.config)&&M(t.driver)&&M(t.executor)&&M(t.dialect)}var Qr=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 Zt(i)),s=new xt({...this.#e,executor:o});return await e(s)})}};u(Qr,"don't await ConnectionBuilder instances directly. To execute the query you need to call the `execute` method");var Lr=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 Cn(s),this.#e.executor.provideConnection(async a=>{let p=this.#e.executor.withConnectionProvider(new Zt(a)),h=new Ai({...o,executor:p});try{await this.#e.driver.beginTransaction(a,s);let b=await e(h);return await this.#e.driver.commitTransaction(a),b}catch(b){throw await this.#e.driver.rollbackTransaction(a),b}})}};u(Lr,"don't await TransactionBuilder instances directly. To execute the transaction you need to call the `execute` method");function Cn(t){if(t.isolationLevel&&!Io.includes(t.isolationLevel))throw new Error(`invalid transaction isolation level ${t.isolationLevel}`)}var Pr=class t{#e;constructor(e){this.#e=r(e)}get expressionType(){}get isRawBuilder(){return!0}as(e){return new Fr(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():Ae;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 be(t){return new Pr(t)}u(Pr,"don't await RawBuilder instances directly. To execute the query you need to call `execute`");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 rawBuilder(){return this.#e}toOperationNode(){return F.create(this.#e.toOperationNode(),v(this.#t)?this.#t.toOperationNode():c.create(this.#t))}};u(Fr,"don't await AliasedRawBuilder instances directly. AliasedRawBuilder should never be executed directly since it's always a part of another query.");var Y=Object.assign((t,...e)=>be({queryId:N(),rawNode:T.create(t,e?.map(ko)??[])}),{ref(t){return be({queryId:N(),rawNode:T.createWithChild(G(t))})},val(t){return be({queryId:N(),rawNode:T.createWithChild(x(t))})},value(t){return this.val(t)},table(t){return be({queryId:N(),rawNode:T.createWithChild(y(t))})},id(...t){let e=new Array(t.length+1).fill(".");return e[0]="",e[e.length-1]="",be({queryId:N(),rawNode:T.create(e,t.map(c.create))})},lit(t){return be({queryId:N(),rawNode:T.createWithChild(I.createImmediate(t))})},literal(t){return this.lit(t)},raw(t){return be({queryId:N(),rawNode:T.createWithSql(t)})},join(t,e=Y`, `){let i=new Array(2*t.length-1),o=e.toOperationNode();for(let s=0;s<t.length;++s)i[2*s]=ko(t[s]),s!==t.length-1&&(i[2*s+1]=o);return be({queryId:N(),rawNode:T.createWithChildren(i)})}});function ko(t){return v(t)?t.toOperationNode():x(t)}var zr=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 Mr=class extends zr{#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&&!de.is(this.parentNode)&&!A.is(this.parentNode)&&!P.is(this.parentNode)&&!se.is(this.parentNode)&&!wr.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(d.is),o=i!==e;!o&&e.explain&&(this.visitNode(e.explain),this.append(" ")),o&&!E.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&&!E.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(!W(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(Tn[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(d.is),o=i!==e;!o&&e.explain&&(this.visitNode(e.explain),this.append(" ")),o&&!E.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&&!E.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 "),Pe(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(Wn[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 a of e)s+=a,a===i?s+=i:a===o&&(s+=o);return s}addParameter(e){this.#t.push(e)}appendImmediateValue(e){if(W(e))this.append(`'${e}'`);else if(ve(e)||Pe(e))this.append(e.toString());else if(Ge(e))this.append("null");else if(Qi(e))this.appendImmediateValue(e.toISOString());else if(He(e))this.appendImmediateValue(e.toString());else throw new Error(`invalid immediate value ${e}`)}sortSelectModifiers(e){return e.sort((i,o)=>i.modifier&&o.modifier?Ao[i.modifier]-Ao[o.modifier]:1),r(e)}compileColumnAlterations(e){this.compileList(e)}announcesNewColumnDataType(){return!0}},Wn=r({ForKeyShare:"for key share",ForNoKeyUpdate:"for no key update",ForUpdate:"for update",ForShare:"for share",NoWait:"nowait",SkipLocked:"skip locked",Distinct:"distinct"}),Ao=r({ForKeyShare:1,ForNoKeyUpdate:1,ForUpdate:1,ForShare:1,NoWait:2,SkipLocked:2,Distinct:0}),Tn=r({InnerJoin:"inner join",LeftJoin:"left join",RightJoin:"right join",FullJoin:"full join",LateralInnerJoin:"inner join lateral",LateralLeftJoin:"left join lateral",Using:"using"});var Vr=class{async init(){}async acquireConnection(){return new Ei}async beginTransaction(){}async commitTransaction(){}async rollbackTransaction(){}async releaseConnection(){}async destroy(){}},Ei=class{async executeQuery(){return{rows:[]}}async*streamQuery(){}};var Ur=class{get supportsCreateIfNotExists(){return!0}get supportsTransactionalDdl(){return!1}get supportsReturning(){return!1}get supportsOutput(){return!1}};var qn=/"/g,Jr=class extends Mr{sanitizeIdentifier(e){return e.replace(qn,'""')}};var In=BigInt("3853314791062309107"),$r=class extends Ur{get supportsTransactionalDdl(){return!0}get supportsReturning(){return!0}async acquireMigrationLock(e,i){await Y`select pg_advisory_xact_lock(${Y.lit(In)})`.execute(e)}async releaseMigrationLock(e,i){}};function Eo(t){return new xt({dialect:{createAdapter:()=>new t.Adapter,createDriver:()=>new Vr,createIntrospector:()=>null,createQueryCompiler:()=>new t.QueryCompiler},plugins:[...t.noParameters?[new Ri]:[]]})}var Ri=class{#e=new Di;transformQuery(e){return this.#e.transformNode(e.node)}transformResult(e){return Promise.resolve(e.result)}},Di=class extends ke{transformPrimitiveValueList(e){return Se.create(e.values.map(I.createImmediate))}transformValue(e){return{...super.transformValue(e),immediate:!0}}};function Ke(t){let e=t.compile();return{parameters:e.parameters,sql:e.sql}}function Ro(t,e){let i=Sn(t,e);return o=>o.where(s=>s.and(i.map(([a,p])=>s(a,p===null?"is":"=",p))))}function Sn(t,e){return Object.entries(Object.values(e).reduce((i,o)=>{let{isInPrimaryKey:s,name:a}=o;return s&&(i[a]=t[a]),i},{}))}function je(t){return Eo({...t,Adapter:$r,QueryCompiler:Jr})}function Do(t,e){let{table:i,rows:o}=t,{name:s,schema:a,columns:p}=i,h=je(e),b=Object.values(p).map(({name:q})=>`${s}.${q}`);return Ke(h.withSchema(a).insertInto(s).values(o).returning(b).returning(q=>[q.cast("ctid","text").as("ctid")]))}function Bo(t,e){let{pageIndex:i,pageSize:o,sortOrder:s,table:{name:a,schema:p,columns:h}}=t,b=je(e),q=Object.values(h).map(({name:R})=>`${a}.${R}`);return Ke(b.with("count",R=>R.withSchema(p).selectFrom(a).select(_=>_.cast(b.fn.coalesce(b.fn.countAll(),Y.lit(0)),"text").as("oid"))).withSchema(p).selectFrom([a,"count"]).select(R=>[R.cast("ctid","text").as("ctid"),R.ref("count.oid").as("oid")]).select(q).$call(R=>s.reduce((_,Le)=>_.orderBy(Le.column,Le.direction),R)).limit(o).offset(Y.lit(BigInt(i)*BigInt(o))))}function Qo(t,e){let{changes:i,row:o,table:{columns:s,name:a,schema:p}}=t,h=je(e),b=Object.values(s).map(({name:q})=>`${a}.${q}`);return Ke(h.withSchema(p).updateTable(a).set(i).$call(Ro(o,s)).returning(b).returning(q=>[q.cast("ctid","text").as("ctid"),q.cast(q.fn("floor",[q(q.fn("extract",[Y`epoch from now()`]),"*",1e6)]),"text").as("__ps_updated_at__")]))}function Lo(t){return Y`(select coalesce(json_agg(agg), '[]') from ${t} as agg)`}var kn="r",An="v",En=[kn,An];function Po(t){return Ke(je(t).selectFrom("pg_catalog.pg_class as cls").innerJoin("pg_catalog.pg_namespace as ns","cls.relnamespace","ns.oid").$call(Rn).where("cls.relkind","in",En).select(e=>["ns.nspname as schema","cls.relname as name",Lo(e.selectFrom("pg_catalog.pg_attribute as att").innerJoin("pg_catalog.pg_type as typ","typ.oid","att.atttypid").leftJoin("pg_catalog.pg_constraint as con",i=>i.on("con.contype","=","p").onRef("con.conrelid","=","cls.oid").on(o=>Y`${o.ref("att.attnum")} = ANY(${o.ref("con.conkey")})`)).whereRef("att.attrelid","=","cls.oid").where("att.attnum",">=",0).where("att.attisdropped","!=",!0).where("att.attgenerated","=","").select(i=>["att.attname as name","typ.typname as datatype",i("con.conkey","is not",null).$castTo().as("pk"),i("att.attgenerated","!=","").$castTo().as("computed")])).as("columns")]))}function Fo(){let t=je();return Ke(t.selectNoFrom(t.fn("current_setting",[Y.lit("timezone")]).as("timezone")))}function Rn(t){return t.where("ns.nspname","!~","^pg_").where("ns.nspname","!=","information_schema")}function zo(t){let{executor:e,...i}=t;return{defaultSchema:"public",async introspect(o){try{let s=Po(i),a=Fo(),[[p,h],[b,q]]=await Promise.all([e.execute(s,o),e.execute(a,o)]),R=p||b;if(R)return[R];let[_]=q;return _?[null,Dn(h,_.timezone)]:[new Error("Timezone not found")]}catch(s){return[s]}},async query(o,s){try{let a=Bo(o,i),[p,h]=await e.execute(a,s);return p?[p]:[null,{filteredRowCount:h[0]?.oid||"0",rows:h}]}catch(a){return[a]}},async insert(o,s){try{let a=Do(o,i),[p,h]=await e.execute(a,s);return p?[p]:[null,{rows:h}]}catch(a){return[a]}},async update(o,s){try{let a=Qo(o,i),[p,h]=await e.execute(a,s);if(p)return[p];let[b]=h;return b?[null,{row:b}]:[new Error("Update failed")]}catch(a){return[a]}}}}function Dn(t,e){return t.reduce((i,o)=>{let{schemas:s}=i,{columns:a,name:p,schema:h}=o,b=a.reduce((q,{datatype:R,computed:_,name:Le,pk:Vo})=>{let Kr=R.startsWith("_"),jr=Kr?R.slice(1):R;return{...q,[Le]:{name:Le,schema:h,table:Le,isInPrimaryKey:Vo,datatype:{...Bi[jr]||{group:"raw"},isArray:Kr,name:Kr?`${jr}[]`:jr},computed:_}}},{});return(s[h]||={tables:{}}).tables[p]={columns:b,name:p,schema:h},i},{schemas:{public:{tables:{}}},timezone:e})}function Mo(t){return{execute:async(e,i)=>{let{abortSignal:o}=i||{},s,a=new Promise((h,b)=>s=b);function p(){let h=new Error("This operation was aborted");h.name="AbortError",s(h)}o?.addEventListener("abort",p);try{return[null,(await Promise.race([t.query(e.sql,e.parameters,{rowMode:"object"}),a])).rows]}catch(h){return[h]}finally{o?.removeEventListener("abort",p)}}}}function Bn(t){return zo({executor:Mo(t)})}0&&(module.exports={createPGLiteAdapter,createPGLiteExecutor});
|
|
1
|
+
"use strict";var Hr=Object.defineProperty;var Uo=Object.getOwnPropertyDescriptor;var Jo=Object.getOwnPropertyNames;var $o=Object.prototype.hasOwnProperty;var Ko=(t,e)=>{for(var i in e)Hr(t,i,{get:e[i],enumerable:!0})},Go=(t,e,i,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Jo(e))!$o.call(t,s)&&s!==i&&Hr(t,s,{get:()=>e[s],enumerable:!(o=Uo(e,s))||o.enumerable});return t};var jo=t=>Go(Hr({},"__esModule",{value:!0}),t);var Qn={};Ko(Qn,{createPGLiteAdapter:()=>Bn,createPGLiteExecutor:()=>Vo});module.exports=jo(Qn);var Qi={bool:{group:"boolean"},boolean:{group:"boolean"},bytea:{group:"string"},char:{group:"string"},citext:{group:"string"},date:{group:"datetime"},interval:{group:"string"},name:{group:"string"},varchar:{group:"string"},text:{group:"string"},time:{group:"time"},timestamp:{group:"datetime"},timestamptz:{group:"datetime"},"timestamp without time zone":{group:"datetime"},"timestamp with time zone":{group:"datetime"},timetz:{group:"time"},"time without time zone":{group:"time"},"time with time zone":{group:"datetime"},uuid:{group:"string"}};function j(t){return typeof t>"u"||t===void 0}function T(t){return typeof t=="string"}function Ce(t){return typeof t=="number"}function Pe(t){return typeof t=="boolean"}function je(t){return t===null}function Li(t){return t instanceof Date}function He(t){return typeof t=="bigint"}function C(t){return typeof t=="function"}function V(t){return typeof t=="object"&&t!==null}function r(t){return Object.freeze(t)}function gt(t){return P(t)?t:[t]}function P(t){return Array.isArray(t)}function ue(t){return t}var f=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 c=r({is(t){return t.kind==="IdentifierNode"},create(t){return r({kind:"IdentifierNode",name:t})}});var te=r({is(t){return t.kind==="CreateIndexNode"},create(t){return r({kind:"CreateIndexNode",name:c.create(t)})},cloneWith(t,e){return r({...t,...e})},cloneWithColumns(t,e){return r({...t,columns:[...t.columns||[],...e]})}});var _t=r({is(t){return t.kind==="CreateSchemaNode"},create(t,e){return r({kind:"CreateSchemaNode",schema:c.create(t),...e})},cloneWith(t,e){return r({...t,...e})}});var Pi=["preserve rows","delete rows","drop"],F=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 J=r({is(t){return t.kind==="SchemableIdentifierNode"},create(t){return r({kind:"SchemableIdentifierNode",identifier:c.create(t)})},createWithSchema(t,e){return r({kind:"SchemableIdentifierNode",schema:c.create(t),identifier:c.create(e)})}});var We=r({is(t){return t.kind==="DropIndexNode"},create(t,e){return r({kind:"DropIndexNode",name:J.create(t),...e})},cloneWith(t,e){return r({...t,...e})}});var Ot=r({is(t){return t.kind==="DropSchemaNode"},create(t,e){return r({kind:"DropSchemaNode",schema:c.create(t),...e})},cloneWith(t,e){return r({...t,...e})}});var bt=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 z=r({is(t){return t.kind==="AliasNode"},create(t,e){return r({kind:"AliasNode",node:t,alias:e})}});var _=r({is(t){return t.kind==="TableNode"},create(t){return r({kind:"TableNode",table:J.create(t)})},createWithSchema(t,e){return r({kind:"TableNode",table:J.createWithSchema(t,e)})}});function v(t){return V(t)&&C(t.toOperationNode)}function Fi(t){return V(t)&&"expressionType"in t&&v(t)}function zi(t){return V(t)&&"expression"in t&&T(t.alias)&&v(t)}var de=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 $=r({is(t){return t.kind==="AndNode"},create(t,e){return r({kind:"AndNode",left:t,right:e})}});var re=r({is(t){return t.kind==="OrNode"},create(t,e){return r({kind:"OrNode",left:t,right:e})}});var er=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"?$.create(t.on,i):re.create(t.on,i)})}});var Te=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:er.create(i)})},cloneWithOn(t,e){return r({...t,on:t.on?er.cloneWithOperation(t.on,"And",e):er.create(e)})}});var qe=r({is(t){return t.kind==="BinaryOperationNode"},create(t,e,i){return r({kind:"BinaryOperationNode",leftOperand:t,operator:e,rightOperand:i})}});var Ho=["=","==","!=","<>",">",">=","<","<=","in","not in","is","is not","like","not like","match","ilike","not ilike","@>","<@","^@","&&","?","?&","?|","!<","!>","<=>","!~","~","~*","!~*","@@","@@@","!!","<->","regexp","is distinct from","is not distinct from"],Yo=["+","-","*","/","%","^","&","|","#","<<",">>"],Mi=["->","->>"],Xo=[...Ho,...Yo,"&&","||"],Zo=["exists","not exists"],_o=["not","-",...Zo],Vi=[...Xo,...Mi,..._o,"between","between symmetric"],H=r({is(t){return t.kind==="OperatorNode"},create(t){return r({kind:"OperatorNode",operator:t})}});function Yr(t){return T(t)&&Mi.includes(t)}var l=r({is(t){return t.kind==="ColumnNode"},create(t){return r({kind:"ColumnNode",column:c.create(t)})}});var Ye=r({is(t){return t.kind==="SelectAllNode"},create(){return r({kind:"SelectAllNode"})}});var Xe=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:Ye.create()})}});var tr=class{#e;get dynamicReference(){return this.#e}get refType(){}constructor(e){this.#e=e}toOperationNode(){return Xr(this.#e)}};function rr(t){return V(t)&&v(t)&&T(t.dynamicReference)}var ir=r({is(t){return t.kind==="OrderByItemNode"},create(t,e){return r({kind:"OrderByItemNode",orderBy:t,direction:e})}});var q=r({is(t){return t.kind==="RawNode"},create(t,e){return r({kind:"RawNode",sqlFragments:r(t),parameters:r(e)})},createWithSql(t){return q.create([t],[])},createWithChild(t){return q.create(["",""],[t])},createWithChildren(t){return q.create(new Array(t.length+1).fill(""),t)}});function _r(t){return t==="asc"||t==="desc"}function Ie(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=en(t);if(ir.is(i)){if(e)throw new Error("Cannot specify direction twice!");return i}return ir.create(i,Ui(e))}function en(t){if(ye(t))return K(t);if(rr(t))return t.toOperationNode();let[e,i]=t.split(" ");if(i){if(!_r(i))throw new Error(`Invalid order by direction: ${i}`);return ir.create(Y(e),Ui(i))}return Y(t)}function Ui(t){if(t)return t==="asc"||t==="desc"?q.createWithSql(t):t.toOperationNode()}var Ze=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 or=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 Se=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 Xr(t){return T(t)?Y(t):t.toOperationNode()}function we(t){return P(t)?t.map(e=>D(e)):[D(t)]}function D(t){return ye(t)?K(t):Xr(t)}function Ji(t,e){let i=Y(t);if(Yr(e))return Ze.create(i,or.create(H.create(e)));let o=e.slice(0,-1);if(Yr(o))return Ze.create(i,Se.create(H.create(o)));throw new Error(`Invalid JSON operator: ${e}`)}function Y(t){let e=".";if(!t.includes(e))return Xe.create(l.create(t));let i=t.split(e).map(ti);if(i.length===3)return tn(i);if(i.length===2)return rn(i);throw new Error(`invalid column reference ${t}`)}function $i(t){let e=" as ";if(t.includes(e)){let[i,o]=t.split(e).map(ti);return z.create(Y(i),c.create(o))}else return Y(t)}function ei(t){return l.create(t)}function _e(t){let e=" ";if(t.includes(e)){let[i,o]=t.split(e).map(ti);if(!_r(o))throw new Error(`invalid order direction "${o}" next to "${i}"`);return Ie([i,o])[0]}else return ei(t)}function tn(t){let[e,i,o]=t;return Xe.create(l.create(o),_.createWithSchema(e,i))}function rn(t){let[e,i]=t;return Xe.create(l.create(i),_.create(e))}function ti(t){return t.trim()}var nr=r({is(t){return t.kind==="PrimitiveValueListNode"},create(t){return r({kind:"PrimitiveValueListNode",values:r([...t])})}});var ke=r({is(t){return t.kind==="ValueListNode"},create(t){return r({kind:"ValueListNode",values:r(t)})}});var S=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 Ki(t){return P(t)?on(t):x(t)}function x(t){return ye(t)?K(t):S.create(t)}function sr(t){return Ce(t)||Pe(t)||je(t)}function vt(t){if(!sr(t))throw new Error(`unsafe immediate value ${JSON.stringify(t)}`);return S.createImmediate(t)}function on(t){return t.some(ye)?ke.create(t.map(e=>x(e))):nr.create(t)}var pe=r({is(t){return t.kind==="ParensNode"},create(t){return r({kind:"ParensNode",node:t})}});function g(t){if(t.length===3)return ar(t[0],t[1],t[2]);if(t.length===1)return x(t[0]);throw new Error(`invalid arguments: ${JSON.stringify(t)}`)}function ar(t,e,i){return nn(e)&&ji(i)?qe.create(D(t),ri(e),S.createImmediate(i)):qe.create(D(t),ri(e),Ki(i))}function A(t,e,i){return qe.create(D(t),ri(e),D(i))}function ii(t,e){return et(Object.entries(t).filter(([,i])=>!j(i)).map(([i,o])=>ar(i,ji(o)?"is":"=",o)),e)}function et(t,e,i=!0){let o=e==="and"?$.create:re.create;if(t.length===0)return qe.create(S.createImmediate(1),H.create("="),S.createImmediate(e==="and"?1:0));let s=Gi(t[0]);for(let a=1;a<t.length;++a)s=o(s,Gi(t[a]));return t.length>1&&i?pe.create(s):s}function nn(t){return t==="is"||t==="is not"}function ji(t){return je(t)||Pe(t)}function ri(t){if(T(t)&&Vi.includes(t))return H.create(t);if(v(t))return t.toOperationNode();throw new Error(`invalid operator ${JSON.stringify(t)}`)}function Gi(t){return v(t)?t.toOperationNode():t}var xe=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 oi=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 Ct=r({is(t){return t.kind==="OverNode"},create(){return r({kind:"OverNode"})},cloneWithOrderByItems(t,e){return r({...t,orderBy:t.orderBy?xe.cloneWithItems(t.orderBy,e):xe.create(e)})},cloneWithPartitionByItems(t,e){return r({...t,partitionBy:t.partitionBy?oi.cloneWithItems(t.partitionBy,e):oi.create(e)})}});var Fe=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 ni=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 si=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"?$.create(t.having,i):re.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:Fe.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?xe.cloneWithItems(t.orderBy,e):xe.create(e)})},cloneWithGroupByItems(t,e){return r({...t,groupBy:t.groupBy?ni.cloneWithItems(t.groupBy,e):ni.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?si.cloneWithOperation(t.having,"And",e):si.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 u(t,e){Object.defineProperties(t.prototype,{then:{enumerable:!1,value:()=>{throw new Error(e)}}})}var Wt=class t{#e;constructor(e){this.#e=r(e)}on(...e){return new t({...this.#e,joinNode:Te.cloneWithOn(this.#e.joinNode,g(e))})}onRef(e,i,o){return new t({...this.#e,joinNode:Te.cloneWithOn(this.#e.joinNode,A(e,i,o))})}onTrue(){return new t({...this.#e,joinNode:Te.cloneWithOn(this.#e.joinNode,q.createWithSql("true"))})}$call(e){return e(this)}toOperationNode(){return this.#e.joinNode}};u(Wt,"don't await JoinBuilder instances. They are never executed directly and are always just a part of a query.");var Hi=r({is(t){return t.kind==="PartitionByItemNode"},create(t){return r({kind:"PartitionByItemNode",partitionBy:t})}});function Yi(t){return we(t).map(Hi.create)}var Tt=class t{#e;constructor(e){this.#e=r(e)}orderBy(e,i){return new t({overNode:Ct.cloneWithOrderByItems(this.#e.overNode,Ie([e,i]))})}partitionBy(e){return new t({overNode:Ct.cloneWithPartitionByItems(this.#e.overNode,Yi(e))})}$call(e){return e(this)}toOperationNode(){return this.#e.overNode}};u(Tt,"don't await OverBuilder instances. They are never executed directly and are always just a part of a query.");var tt=r({is(t){return t.kind==="SelectionNode"},create(t){return r({kind:"SelectionNode",selection:t})},createSelectAll(){return r({kind:"SelectionNode",selection:Ye.create()})},createSelectAllFromTable(t){return r({kind:"SelectionNode",selection:Xe.createSelectAll(t)})}});function B(t){return C(t)?B(t(ie())):P(t)?t.map(e=>Xi(e)):[Xi(t)]}function Xi(t){return T(t)?tt.create($i(t)):rr(t)?tt.create(t.toOperationNode()):tt.create(ur(t))}function M(t){return t?Array.isArray(t)?t.map(Zi):[Zi(t)]:[tt.createSelectAll()]}function Zi(t){if(T(t))return tt.createSelectAllFromTable(y(t));throw new Error(`invalid value selectAll expression: ${JSON.stringify(t)}`)}var _i=r({is(t){return t.kind==="ValuesNode"},create(t){return r({kind:"ValuesNode",values:r(t)})}});var eo=r({is(t){return t.kind==="DefaultInsertValueNode"},create(){return r({kind:"DefaultInsertValueNode"})}});function dr(t){let e=C(t)?t(ie()):t,i=P(e)?e:r([e]);return sn(i)}function sn(t){let e=an(t);return[r([...e.keys()].map(l.create)),_i.create(t.map(i=>un(i,e)))]}function an(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 un(t,e){let i=Object.keys(t),o=Array.from({length:e.size}),s=!1;for(let p of i){let m=e.get(p);if(j(m))continue;let O=t[p];(j(O)||ye(O))&&(s=!0),o[m]=O}if(i.length<e.size||s){let p=eo.create();return ke.create(o.map(m=>j(m)?p:x(m)))}return nr.create(o)}var E=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 ce=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?Fe.cloneWithFroms(t.from,e):Fe.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 ai=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 he=r({is(t){return t.kind==="DeleteQueryNode"},create(t,e){return r({kind:"DeleteQueryNode",from:Fe.create(t),...e&&{with:e}})},cloneWithOrderByItems(t,e){return r({...t,orderBy:t.orderBy?xe.cloneWithItems(t.orderBy,e):xe.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?ai.cloneWithTables(t.using,e):ai.create(e)})}});var Q=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"?$.create(t.where,i):re.create(t.where,i)})}});var ui=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 to=r({is(t){return t.kind==="ExplainNode"},create(t,e){return r({kind:"ExplainNode",format:t,options:e})}});var ge=r({is(t){return t.kind==="WhenNode"},create(t){return r({kind:"WhenNode",condition:t})},cloneWithResult(t,e){return r({...t,result:e})}});var R=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),ge.cloneWithResult(t.whens[t.whens.length-1],e)]):void 0})}});var di=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 h.is(t)||E.is(t)||ce.is(t)||he.is(t)||R.is(t)},cloneWithWhere(t,e){return r({...t,where:t.where?Q.cloneWithOperation(t.where,"And",e):Q.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?ui.cloneWithSelections(t.returning,e):ui.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:to.create(e,i?.toOperationNode())})},cloneWithTop(t,e){return r({...t,top:e})},cloneWithOutput(t,e){return r({...t,output:t.output?di.cloneWithSelections(t.output,e):di.create(e)})}});var pi=r({is(t){return t.kind==="ColumnUpdateNode"},create(t,e){return r({kind:"ColumnUpdateNode",column:t,value:e})}});function ro(...t){return t.length===2?[pi.create(D(t[0]),x(t[1]))]:qt(t[0])}function qt(t){let e=C(t)?t(ie()):t;return Object.entries(e).filter(([i,o])=>o!==void 0).map(([i,o])=>pi.create(l.create(i),x(o)))}var io=r({is(t){return t.kind==="OnDuplicateKeyNode"},create(t){return r({kind:"OnDuplicateKeyNode",updates:t})}});var pr=class{insertId;numInsertedOrUpdatedRows;constructor(e,i){this.insertId=e,this.numInsertedOrUpdatedRows=i}};var ee=class extends Error{node;constructor(e){super("no result"),this.node=e}};function me(t){return Object.prototype.hasOwnProperty.call(t,"prototype")}var U=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?Q.cloneWithOperation(t.indexWhere,"And",e):Q.create(e)})},cloneWithIndexOrWhere(t,e){return r({...t,indexWhere:t.indexWhere?Q.cloneWithOperation(t.indexWhere,"Or",e):Q.create(e)})},cloneWithUpdateWhere(t,e){return r({...t,updateWhere:t.updateWhere?Q.cloneWithOperation(t.updateWhere,"And",e):Q.create(e)})},cloneWithUpdateOrWhere(t,e){return r({...t,updateWhere:t.updateWhere?Q.cloneWithOperation(t.updateWhere,"Or",e):Q.create(e)})},cloneWithoutIndexWhere(t){return r({...t,indexWhere:void 0})},cloneWithoutUpdateWhere(t){return r({...t,updateWhere:void 0})}});var It=class t{#e;constructor(e){this.#e=r(e)}column(e){let i=l.create(e);return new t({...this.#e,onConflictNode:U.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?r([...this.#e.onConflictNode.columns,i]):r([i])})})}columns(e){let i=e.map(l.create);return new t({...this.#e,onConflictNode:U.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:U.cloneWith(this.#e.onConflictNode,{constraint:c.create(e)})})}expression(e){return new t({...this.#e,onConflictNode:U.cloneWith(this.#e.onConflictNode,{indexExpression:e.toOperationNode()})})}where(...e){return new t({...this.#e,onConflictNode:U.cloneWithIndexWhere(this.#e.onConflictNode,g(e))})}whereRef(e,i,o){return new t({...this.#e,onConflictNode:U.cloneWithIndexWhere(this.#e.onConflictNode,A(e,i,o))})}clearWhere(){return new t({...this.#e,onConflictNode:U.cloneWithoutIndexWhere(this.#e.onConflictNode)})}doNothing(){return new cr({...this.#e,onConflictNode:U.cloneWith(this.#e.onConflictNode,{doNothing:!0})})}doUpdateSet(e){return new hr({...this.#e,onConflictNode:U.cloneWith(this.#e.onConflictNode,{updates:qt(e)})})}$call(e){return e(this)}};u(It,"don't await OnConflictBuilder instances.");var cr=class{#e;constructor(e){this.#e=r(e)}toOperationNode(){return this.#e.onConflictNode}};u(cr,"don't await OnConflictDoNothingBuilder instances.");var hr=class t{#e;constructor(e){this.#e=r(e)}where(...e){return new t({...this.#e,onConflictNode:U.cloneWithUpdateWhere(this.#e.onConflictNode,g(e))})}whereRef(e,i,o){return new t({...this.#e,onConflictNode:U.cloneWithUpdateWhere(this.#e.onConflictNode,A(e,i,o))})}clearWhere(){return new t({...this.#e,onConflictNode:U.cloneWithoutUpdateWhere(this.#e.onConflictNode)})}$call(e){return e(this)}toOperationNode(){return this.#e.onConflictNode}};u(hr,"don't await OnConflictUpdateBuilder instances.");var oo=r({is(t){return t.kind==="TopNode"},create(t,e){return r({kind:"TopNode",expression:t,modifiers:e})}});function oe(t,e){if(!Ce(t)&&!He(t))throw new Error(`Invalid top expression: ${t}`);if(!j(e)&&!dn(e))throw new Error(`Invalid top modifiers: ${e}`);return oo.create(t,e)}function dn(t){return t==="percent"||t==="with ties"||t==="percent with ties"}var rt=class t{#e;constructor(e){this.#e=r(e)}values(e){let[i,o]=dr(e);return new t({...this.#e,queryNode:E.cloneWith(this.#e.queryNode,{columns:i,values:o})})}columns(e){return new t({...this.#e,queryNode:E.cloneWith(this.#e.queryNode,{columns:r(e.map(l.create))})})}expression(e){return new t({...this.#e,queryNode:E.cloneWith(this.#e.queryNode,{values:K(e)})})}defaultValues(){return new t({...this.#e,queryNode:E.cloneWith(this.#e.queryNode,{defaultValues:!0})})}ignore(){return new t({...this.#e,queryNode:E.cloneWith(this.#e.queryNode,{ignore:!0})})}top(e,i){return new t({...this.#e,queryNode:d.cloneWithTop(this.#e.queryNode,oe(e,i))})}onConflict(e){return new t({...this.#e,queryNode:E.cloneWith(this.#e.queryNode,{onConflict:e(new It({onConflictNode:U.create()})).toOperationNode()})})}onDuplicateKeyUpdate(e){return new t({...this.#e,queryNode:E.cloneWith(this.#e.queryNode,{onDuplicateKey:io.create(qt(e))})})}returning(e){return new t({...this.#e,queryNode:d.cloneWithReturning(this.#e.queryNode,B(e))})}returningAll(){return new t({...this.#e,queryNode:d.cloneWithReturning(this.#e.queryNode,M())})}output(e){return new t({...this.#e,queryNode:d.cloneWithOutput(this.#e.queryNode,B(e))})}outputAll(e){return new t({...this.#e,queryNode:d.cloneWithOutput(this.#e.queryNode,M(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:o}=this.#e.executor,s=e.query;return s.returning&&o.supportsReturning||s.output&&o.supportsOutput?i.rows:[new pr(i.insertId,i.numAffectedRows??i.numUpdatedOrDeletedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=ee){let i=await this.executeTakeFirst();if(i===void 0)throw me(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:d.cloneWithExplain(this.#e.queryNode,e,i)}).execute()}};u(rt,"don't await InsertQueryBuilder instances directly. To execute the query you need to call `execute` or `executeTakeFirst`.");var mr=class{numDeletedRows;constructor(e){this.numDeletedRows=e}};var it=r({is(t){return t.kind==="LimitNode"},create(t){return r({kind:"LimitNode",limit:t})}});var St=class t{#e;constructor(e){this.#e=r(e)}where(...e){return new t({...this.#e,queryNode:d.cloneWithWhere(this.#e.queryNode,g(e))})}whereRef(e,i,o){return new t({...this.#e,queryNode:d.cloneWithWhere(this.#e.queryNode,A(e,i,o))})}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,oe(e,i))})}using(e){return new t({...this.#e,queryNode:he.cloneWithUsing(this.#e.queryNode,le(e))})}innerJoin(...e){return new t({...this.#e,queryNode:d.cloneWithJoin(this.#e.queryNode,k("InnerJoin",e))})}leftJoin(...e){return new t({...this.#e,queryNode:d.cloneWithJoin(this.#e.queryNode,k("LeftJoin",e))})}rightJoin(...e){return new t({...this.#e,queryNode:d.cloneWithJoin(this.#e.queryNode,k("RightJoin",e))})}fullJoin(...e){return new t({...this.#e,queryNode:d.cloneWithJoin(this.#e.queryNode,k("FullJoin",e))})}returning(e){return new t({...this.#e,queryNode:d.cloneWithReturning(this.#e.queryNode,B(e))})}returningAll(e){return new t({...this.#e,queryNode:d.cloneWithReturning(this.#e.queryNode,M(e))})}output(e){return new t({...this.#e,queryNode:d.cloneWithOutput(this.#e.queryNode,B(e))})}outputAll(e){return new t({...this.#e,queryNode:d.cloneWithOutput(this.#e.queryNode,M(e))})}clearReturning(){return new t({...this.#e,queryNode:d.cloneWithoutReturning(this.#e.queryNode)})}clearLimit(){return new t({...this.#e,queryNode:he.cloneWithoutLimit(this.#e.queryNode)})}clearOrderBy(){return new t({...this.#e,queryNode:he.cloneWithoutOrderBy(this.#e.queryNode)})}orderBy(e,i){return new t({...this.#e,queryNode:he.cloneWithOrderByItems(this.#e.queryNode,Ie([e,i]))})}limit(e){return new t({...this.#e,queryNode:he.cloneWithLimit(this.#e.queryNode,it.create(x(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 mr(i.numAffectedRows??i.numUpdatedOrDeletedRows??BigInt(0))]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=ee){let i=await this.executeTakeFirst();if(i===void 0)throw me(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:d.cloneWithExplain(this.#e.queryNode,e,i)}).execute()}};u(St,"don't await DeleteQueryBuilder instances directly. To execute the query you need to call `execute` or `executeTakeFirst`.");var lr=class{numUpdatedRows;numChangedRows;constructor(e,i){this.numUpdatedRows=e,this.numChangedRows=i}};var ze=class t{#e;constructor(e){this.#e=r(e)}where(...e){return new t({...this.#e,queryNode:d.cloneWithWhere(this.#e.queryNode,g(e))})}whereRef(e,i,o){return new t({...this.#e,queryNode:d.cloneWithWhere(this.#e.queryNode,A(e,i,o))})}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,oe(e,i))})}from(e){return new t({...this.#e,queryNode:ce.cloneWithFromItems(this.#e.queryNode,le(e))})}innerJoin(...e){return new t({...this.#e,queryNode:d.cloneWithJoin(this.#e.queryNode,k("InnerJoin",e))})}leftJoin(...e){return new t({...this.#e,queryNode:d.cloneWithJoin(this.#e.queryNode,k("LeftJoin",e))})}rightJoin(...e){return new t({...this.#e,queryNode:d.cloneWithJoin(this.#e.queryNode,k("RightJoin",e))})}fullJoin(...e){return new t({...this.#e,queryNode:d.cloneWithJoin(this.#e.queryNode,k("FullJoin",e))})}limit(e){return new t({...this.#e,queryNode:ce.cloneWithLimit(this.#e.queryNode,it.create(x(e)))})}set(...e){return new t({...this.#e,queryNode:ce.cloneWithUpdates(this.#e.queryNode,ro(...e))})}returning(e){return new t({...this.#e,queryNode:d.cloneWithReturning(this.#e.queryNode,B(e))})}returningAll(e){return new t({...this.#e,queryNode:d.cloneWithReturning(this.#e.queryNode,M(e))})}output(e){return new t({...this.#e,queryNode:d.cloneWithOutput(this.#e.queryNode,B(e))})}outputAll(e){return new t({...this.#e,queryNode:d.cloneWithOutput(this.#e.queryNode,M(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:o}=this.#e.executor,s=e.query;return s.returning&&o.supportsReturning||s.output&&o.supportsOutput?i.rows:[new lr(i.numAffectedRows??i.numUpdatedOrDeletedRows??BigInt(0),i.numChangedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=ee){let i=await this.executeTakeFirst();if(i===void 0)throw me(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:d.cloneWithExplain(this.#e.queryNode,e,i)}).execute()}};u(ze,"don't await UpdateQueryBuilder instances directly. To execute the query you need to call `execute` or `executeTakeFirst`.");var ci=r({is(t){return t.kind==="CommonTableExpressionNameNode"},create(t,e){return r({kind:"CommonTableExpressionNameNode",table:_.create(t),columns:e?r(e.map(l.create)):void 0})}});var ot=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 kt=class t{#e;constructor(e){this.#e=r(e)}materialized(){return new t({...this.#e,node:ot.cloneWith(this.#e.node,{materialized:!0})})}notMaterialized(){return new t({...this.#e,node:ot.cloneWith(this.#e.node,{materialized:!1})})}toOperationNode(){return this.#e.node}};u(kt,"don't await CTEBuilder instances. They are never executed directly and are always just a part of a query.");function hi(t,e){let i=e(so()).toOperationNode();return C(t)?t(pn(i)).toOperationNode():ot.create(no(t),i)}function pn(t){return e=>new kt({node:ot.create(no(e),t)})}function no(t){if(t.includes("(")){let e=t.split(/[\(\)]/),i=e[0],o=e[1].split(",").map(s=>s.trim());return ci.create(i,o)}else return ci.create(t)}var At=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 ao=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"];function uo(t){let e="";for(let i=0;i<t;++i)e+=cn();return e}function cn(){return ao[~~(Math.random()*ao.length)]}function N(){return new mi}var mi=class{#e;get queryId(){return this.#e===void 0&&(this.#e=uo(8)),this.#e}};var Ae=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 hn=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}),fr=class extends Ae{#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 a of i)this.#r.add(a);let o=this.#o(e);for(let a of o)this.#t.add(a);let s=super.transformNodeImpl(e);for(let a of o)this.#t.delete(a);for(let a of i)this.#r.delete(a);return s}transformSchemableIdentifier(e){let i=super.transformSchemableIdentifier(e);return i.schema||!this.#t.has(e.identifier.name)?i:{...i,schema:c.create(this.#e)}}transformReferences(e){let i=super.transformReferences(e);return i.table.table.schema?i:{...i,table:_.createWithSchema(this.#e,i.table.table.identifier.name)}}#i(e){return e.kind in hn}#o(e){let i=new Set;if("name"in e&&e.name&&J.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=_.is(e)?e:z.is(e)&&_.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 ne=class{#e;constructor(e){this.#e=new fr(e)}transformQuery(e){return this.#e.transformNode(e.node)}async transformResult(e){return e.result}};var po=r({is(t){return t.kind==="MatchedNode"},create(t,e=!1){return r({kind:"MatchedNode",not:t,bySource:e})}});function li(t,e,i){return ge.create(et([po.create(!t.isMatched,t.bySource),...e&&e.length>0?[e.length===3&&i?A(e[0],e[1],e[2]):g(e)]:[]],"and",!1))}function nt(t){return T(t)?q.create([t],[]):v(t)?t.toOperationNode():t}var Et=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 co=new Set;function ho(t){co.has(t)||(co.add(t),console.log(t))}var mn=r([]),st=class{#e;constructor(e=mn){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),a=await this.#t(s,i);return ln(s,a),a})}async*stream(e,i,o){let s=new Et,a=new Et;this.provideConnection(async m=>(s.resolve(m),await a.promise)).catch(m=>s.reject(m));let p=await s.promise;try{for await(let m of p.streamQuery(e,i))yield await this.#t(m,o)}finally{a.resolve()}}async#t(e,i){for(let o of this.#e)e=await o.transformResult({result:e,queryId:i});return e}};function ln(t,e){let{numAffectedRows:i}=t;i===void 0&&t.numUpdatedOrDeletedRows===void 0||i!==void 0&&e.numAffectedRows!==void 0||ho("kysely:warning: outdated driver/plugin detected! QueryResult.numUpdatedOrDeletedRows is deprecated and will be removed in a future release.")}var fi=class t extends st{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([])}},Ee=new fi;var Nr=class{numChangedRows;constructor(e){this.numChangedRows=e}};var Rt=class t{#e;constructor(e){this.#e=r(e)}top(e,i){return new t({...this.#e,queryNode:d.cloneWithTop(this.#e.queryNode,oe(e,i))})}using(...e){return new Oe({...this.#e,queryNode:R.cloneWithUsing(this.#e.queryNode,k("Using",e))})}output(e){return new t({...this.#e,queryNode:d.cloneWithOutput(this.#e.queryNode,B(e))})}outputAll(e){return new t({...this.#e,queryNode:d.cloneWithOutput(this.#e.queryNode,M(e))})}};u(Rt,"don't await MergeQueryBuilder instances directly. To execute the query you need to call `execute` when available.");var Oe=class t{#e;constructor(e){this.#e=r(e)}top(e,i){return new t({...this.#e,queryNode:d.cloneWithTop(this.#e.queryNode,oe(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 Dt({...this.#e,queryNode:R.cloneWithWhen(this.#e.queryNode,li({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:d.cloneWithOutput(this.#e.queryNode,B(e))})}outputAll(e){return new t({...this.#e,queryNode:d.cloneWithOutput(this.#e.queryNode,M(e))})}#r(e,i=!1,o=!1){let s={...this.#e,queryNode:R.cloneWithWhen(this.#e.queryNode,li({isMatched:!1,bySource:o},e,i))},a=o?Dt:yr;return new a(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 Nr(i.numAffectedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=ee){let i=await this.executeTakeFirst();if(i===void 0)throw me(e)?new e(this.toOperationNode()):e(this.toOperationNode());return i}};u(Oe,"don't await WheneableMergeQueryBuilder instances directly. To execute the query you need to call `execute`.");var Dt=class{#e;constructor(e){this.#e=r(e)}thenDelete(){return new Oe({...this.#e,queryNode:R.cloneWithThen(this.#e.queryNode,nt("delete"))})}thenDoNothing(){return new Oe({...this.#e,queryNode:R.cloneWithThen(this.#e.queryNode,nt("do nothing"))})}thenUpdate(e){return new Oe({...this.#e,queryNode:R.cloneWithThen(this.#e.queryNode,nt(e(new ze({queryId:this.#e.queryId,executor:Ee,queryNode:ce.createWithoutTable()}))))})}thenUpdateSet(...e){return this.thenUpdate(i=>i.set(...e))}};u(Dt,"don't await MatchedThenableMergeQueryBuilder instances directly. To execute the query you need to call `execute` when available.");var yr=class{#e;constructor(e){this.#e=r(e)}thenDoNothing(){return new Oe({...this.#e,queryNode:R.cloneWithThen(this.#e.queryNode,nt("do nothing"))})}thenInsertValues(e){let[i,o]=dr(e);return new Oe({...this.#e,queryNode:R.cloneWithThen(this.#e.queryNode,nt(E.cloneWith(E.createWithoutInto(),{columns:i,values:o})))})}};u(yr,"don't await NotMatchedThenableMergeQueryBuilder instances directly. To execute the query you need to call `execute` when available.");var at=class t{#e;constructor(e){this.#e=r(e)}selectFrom(e){return Bt({queryId:N(),executor:this.#e.executor,queryNode:h.createFrom(le(e),this.#e.withNode)})}selectNoFrom(e){return Bt({queryId:N(),executor:this.#e.executor,queryNode:h.cloneWithSelections(h.create(this.#e.withNode),B(e))})}insertInto(e){return new rt({queryId:N(),executor:this.#e.executor,queryNode:E.create(y(e),this.#e.withNode)})}replaceInto(e){return new rt({queryId:N(),executor:this.#e.executor,queryNode:E.create(y(e),this.#e.withNode,!0)})}deleteFrom(e){return new St({queryId:N(),executor:this.#e.executor,queryNode:he.create(le(e),this.#e.withNode)})}updateTable(e){return new ze({queryId:N(),executor:this.#e.executor,queryNode:ce.create(Re(e),this.#e.withNode)})}mergeInto(e){return new Rt({queryId:N(),executor:this.#e.executor,queryNode:R.create(Ni(e),this.#e.withNode)})}with(e,i){let o=hi(e,i);return new t({...this.#e,withNode:this.#e.withNode?At.cloneWithExpression(this.#e.withNode,o):At.create(o)})}withRecursive(e,i){let o=hi(e,i);return new t({...this.#e,withNode:this.#e.withNode?At.cloneWithExpression(this.#e.withNode,o):At.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 ne(e))})}};function so(){return new at({executor:Ee})}function mo(t,e){return new Wt({joinNode:Te.create(t,Re(e))})}function lo(){return new Tt({overNode:Ct.create()})}function k(t,e){if(e.length===3)return Nn(t,e[0],e[1],e[2]);if(e.length===2)return fn(t,e[0],e[1]);throw new Error("not implemented")}function fn(t,e,i){return i(mo(t,e)).toOperationNode()}function Nn(t,e,i,o){return Te.createWithOn(t,Re(e),A(i,"=",o))}var fo=r({is(t){return t.kind==="OffsetNode"},create(t){return r({kind:"OffsetNode",offset:t})}});var No=r({is(t){return t.kind==="GroupByItemNode"},create(t){return r({kind:"GroupByItemNode",groupBy:t})}});function yo(t){return t=C(t)?t(ie()):t,we(t).map(No.create)}var wr=r({is(t){return t.kind==="SetOperationNode"},create(t,e,i){return r({kind:"SetOperationNode",operator:t,expression:e,all:i})}});function Me(t,e,i){return C(e)&&(e=e(xr())),P(e)||(e=[e]),e.map(o=>wr.create(t,K(o),i))}var w=class t{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new Qt(this,e)}or(...e){return new yi(re.create(this.#e,g(e)))}and(...e){return new wi($.create(this.#e,g(e)))}$castTo(){return new t(this.#e)}$notNull(){return new t(this.#e)}toOperationNode(){return this.#e}},Qt=class{#e;#t;constructor(e,i){this.#e=e,this.#t=i}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return z.create(this.#e.toOperationNode(),v(this.#t)?this.#t.toOperationNode():c.create(this.#t))}},yi=class t{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new Qt(this,e)}or(...e){return new t(re.create(this.#e,g(e)))}$castTo(){return new t(this.#e)}toOperationNode(){return pe.create(this.#e)}},wi=class t{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new Qt(this,e)}and(...e){return new t($.create(this.#e,g(e)))}$castTo(){return new t(this.#e)}toOperationNode(){return pe.create(this.#e)}};var wo={is(t){return t.kind==="FetchNode"},create(t,e){return{kind:"FetchNode",rowCount:S.create(t),modifier:e}}};function xo(t,e){if(!Ce(t)&&!He(t))throw new Error(`Invalid fetch row count: ${t}`);if(!yn(e))throw new Error(`Invalid fetch modifier: ${e}`);return wo.create(t,e)}function yn(t){return t==="only"||t==="with ties"}var gr=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,g(e))})}whereRef(e,i,o){return new t({...this.#e,queryNode:d.cloneWithWhere(this.#e.queryNode,A(e,i,o))})}having(...e){return new t({...this.#e,queryNode:h.cloneWithHaving(this.#e.queryNode,g(e))})}havingRef(e,i,o){return new t({...this.#e,queryNode:h.cloneWithHaving(this.#e.queryNode,A(e,i,o))})}select(e){return new t({...this.#e,queryNode:h.cloneWithSelections(this.#e.queryNode,B(e))})}distinctOn(e){return new t({...this.#e,queryNode:h.cloneWithDistinctOn(this.#e.queryNode,we(e))})}modifyFront(e){return new t({...this.#e,queryNode:h.cloneWithFrontModifier(this.#e.queryNode,de.createWithExpression(e.toOperationNode()))})}modifyEnd(e){return new t({...this.#e,queryNode:h.cloneWithEndModifier(this.#e.queryNode,de.createWithExpression(e.toOperationNode()))})}distinct(){return new t({...this.#e,queryNode:h.cloneWithFrontModifier(this.#e.queryNode,de.create("Distinct"))})}forUpdate(e){return new t({...this.#e,queryNode:h.cloneWithEndModifier(this.#e.queryNode,de.create("ForUpdate",e?gt(e).map(y):void 0))})}forShare(e){return new t({...this.#e,queryNode:h.cloneWithEndModifier(this.#e.queryNode,de.create("ForShare",e?gt(e).map(y):void 0))})}forKeyShare(e){return new t({...this.#e,queryNode:h.cloneWithEndModifier(this.#e.queryNode,de.create("ForKeyShare",e?gt(e).map(y):void 0))})}forNoKeyUpdate(e){return new t({...this.#e,queryNode:h.cloneWithEndModifier(this.#e.queryNode,de.create("ForNoKeyUpdate",e?gt(e).map(y):void 0))})}skipLocked(){return new t({...this.#e,queryNode:h.cloneWithEndModifier(this.#e.queryNode,de.create("SkipLocked"))})}noWait(){return new t({...this.#e,queryNode:h.cloneWithEndModifier(this.#e.queryNode,de.create("NoWait"))})}selectAll(e){return new t({...this.#e,queryNode:h.cloneWithSelections(this.#e.queryNode,M(e))})}innerJoin(...e){return new t({...this.#e,queryNode:d.cloneWithJoin(this.#e.queryNode,k("InnerJoin",e))})}leftJoin(...e){return new t({...this.#e,queryNode:d.cloneWithJoin(this.#e.queryNode,k("LeftJoin",e))})}rightJoin(...e){return new t({...this.#e,queryNode:d.cloneWithJoin(this.#e.queryNode,k("RightJoin",e))})}fullJoin(...e){return new t({...this.#e,queryNode:d.cloneWithJoin(this.#e.queryNode,k("FullJoin",e))})}innerJoinLateral(...e){return new t({...this.#e,queryNode:d.cloneWithJoin(this.#e.queryNode,k("LateralInnerJoin",e))})}leftJoinLateral(...e){return new t({...this.#e,queryNode:d.cloneWithJoin(this.#e.queryNode,k("LateralLeftJoin",e))})}orderBy(...e){return new t({...this.#e,queryNode:h.cloneWithOrderByItems(this.#e.queryNode,Ie(e))})}groupBy(e){return new t({...this.#e,queryNode:h.cloneWithGroupByItems(this.#e.queryNode,yo(e))})}limit(e){return new t({...this.#e,queryNode:h.cloneWithLimit(this.#e.queryNode,it.create(x(e)))})}offset(e){return new t({...this.#e,queryNode:h.cloneWithOffset(this.#e.queryNode,fo.create(x(e)))})}fetch(e,i="only"){return new t({...this.#e,queryNode:h.cloneWithFetch(this.#e.queryNode,xo(e,i))})}top(e,i){return new t({...this.#e,queryNode:d.cloneWithTop(this.#e.queryNode,oe(e,i))})}union(e){return new t({...this.#e,queryNode:h.cloneWithSetOperations(this.#e.queryNode,Me("union",e,!1))})}unionAll(e){return new t({...this.#e,queryNode:h.cloneWithSetOperations(this.#e.queryNode,Me("union",e,!0))})}intersect(e){return new t({...this.#e,queryNode:h.cloneWithSetOperations(this.#e.queryNode,Me("intersect",e,!1))})}intersectAll(e){return new t({...this.#e,queryNode:h.cloneWithSetOperations(this.#e.queryNode,Me("intersect",e,!0))})}except(e){return new t({...this.#e,queryNode:h.cloneWithSetOperations(this.#e.queryNode,Me("except",e,!1))})}exceptAll(e){return new t({...this.#e,queryNode:h.cloneWithSetOperations(this.#e.queryNode,Me("except",e,!0))})}as(e){return new Or(this,e)}clearSelect(){return new t({...this.#e,queryNode:h.cloneWithoutSelections(this.#e.queryNode)})}clearWhere(){return new t({...this.#e,queryNode:d.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 w(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=ee){let i=await this.executeTakeFirst();if(i===void 0)throw me(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:d.cloneWithExplain(this.#e.queryNode,e,i)}).execute()}};u(gr,"don't await SelectQueryBuilder instances directly. To execute the query you need to call `execute` or `executeTakeFirst`.");function Bt(t){return new gr(t)}var Or=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 z.create(this.#e.toOperationNode(),c.create(this.#t))}};u(Or,"don't await AliasedSelectQueryBuilder instances directly. AliasedSelectQueryBuilder should never be executed directly since it's always a part of another query.");var be=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?Q.cloneWithOperation(t.filter,"And",e):Q.create(e)})},cloneWithOrFilter(t,e){return r({...t,filter:t.filter?Q.cloneWithOperation(t.filter,"Or",e):Q.create(e)})},cloneWithOver(t,e){return r({...t,over:e})}});var xi=r({is(t){return t.kind==="FunctionNode"},create(t,e){return r({kind:"FunctionNode",func:t,arguments:e})}});var Ve=class t{#e;constructor(e){this.#e=r(e)}get expressionType(){}as(e){return new gi(this,e)}distinct(){return new t({...this.#e,aggregateFunctionNode:be.cloneWithDistinct(this.#e.aggregateFunctionNode)})}filterWhere(...e){return new t({...this.#e,aggregateFunctionNode:be.cloneWithFilter(this.#e.aggregateFunctionNode,g(e))})}filterWhereRef(e,i,o){return new t({...this.#e,aggregateFunctionNode:be.cloneWithFilter(this.#e.aggregateFunctionNode,A(e,i,o))})}over(e){let i=lo();return new t({...this.#e,aggregateFunctionNode:be.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(Ve,"don't await AggregateFunctionBuilder instances. They are never executed directly and are always just a part of a query.");var gi=class{#e;#t;constructor(e,i){this.#e=e,this.#t=i}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return z.create(this.#e.toOperationNode(),c.create(this.#t))}};function br(){let t=(i,o)=>new w(xi.create(i,we(o??[]))),e=(i,o)=>new Ve({aggregateFunctionNode:be.create(i,o?we(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 Ve({aggregateFunctionNode:be.create("count",M(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 Ve({aggregateFunctionNode:be.create("json_agg",[T(i)?y(i):i.toOperationNode()])})},toJson(i){return new w(xi.create("to_json",[T(i)?y(i):i.toOperationNode()]))}})}var go=r({is(t){return t.kind==="UnaryOperationNode"},create(t,e){return r({kind:"UnaryOperationNode",operator:t,operand:e})}});function Oo(t,e){return go.create(H.create(t),D(e))}var X=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),ge.cloneWithResult(t.when[t.when.length-1],e)]):void 0})},cloneWith(t,e){return r({...t,...e})}});var ut=class{#e;constructor(e){this.#e=r(e)}when(...e){return new vr({...this.#e,node:X.cloneWithWhen(this.#e.node,ge.create(g(e)))})}},vr=class{#e;constructor(e){this.#e=r(e)}then(e){return new Oi({...this.#e,node:X.cloneWithThen(this.#e.node,sr(e)?vt(e):x(e))})}},Oi=class{#e;constructor(e){this.#e=r(e)}when(...e){return new vr({...this.#e,node:X.cloneWithWhen(this.#e.node,ge.create(g(e)))})}else(e){return new bi({...this.#e,node:X.cloneWith(this.#e.node,{else:sr(e)?vt(e):x(e)})})}end(){return new w(X.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new w(X.cloneWith(this.#e.node,{isStatement:!0}))}},bi=class{#e;constructor(e){this.#e=r(e)}end(){return new w(X.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new w(X.cloneWith(this.#e.node,{isStatement:!0}))}};var vi=r({is(t){return t.kind==="JSONPathLegNode"},create(t,e){return r({kind:"JSONPathLegNode",type:t,value:e})}});var De=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 Ze.is(this.#e)?new Cr(Ze.cloneWithTraversal(this.#e,Se.is(this.#e.traversal)?Se.cloneWithLeg(this.#e.traversal,vi.create(e,i)):or.cloneWithValue(this.#e.traversal,S.createImmediate(i)))):new Cr(Se.cloneWithLeg(this.#e,vi.create(e,i)))}},Cr=class extends De{#e;constructor(e){super(e),this.#e=e}get expressionType(){}as(e){return new Ci(this,e)}$castTo(){return new De(this.#e)}$notNull(){return new De(this.#e)}toOperationNode(){return this.#e}},Ci=class{#e;#t;constructor(e,i){this.#e=e,this.#t=i}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return z.create(this.#e.toOperationNode(),v(this.#t)?this.#t.toOperationNode():c.create(this.#t))}};var Wi=r({is(t){return t.kind==="TupleNode"},create(t){return r({kind:"TupleNode",values:r(t)})}});var wn=["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"],xn=[/^varchar\(\d+\)$/,/^char\(\d+\)$/,/^decimal\(\d+, \d+\)$/,/^numeric\(\d+, \d+\)$/,/^binary\(\d+\)$/,/^datetime\(\d+\)$/,/^time\(\d+\)$/,/^timetz\(\d+\)$/,/^timestamp\(\d+\)$/,/^timestamptz\(\d+\)$/,/^varbinary\(\d+\)$/],bo=r({is(t){return t.kind==="DataTypeNode"},create(t){return r({kind:"DataTypeNode",dataType:t})}});function vo(t){return!!(wn.includes(t)||xn.some(e=>e.test(t)))}function se(t){if(v(t))return t.toOperationNode();if(vo(t))return bo.create(t);throw new Error(`invalid column data type ${JSON.stringify(t)}`)}var Co=r({is(t){return t.kind==="CastNode"},create(t,e){return r({kind:"CastNode",expression:t,dataType:e})}});function xr(t=Ee){function e(s,a,p){return new w(ar(s,a,p))}function i(s,a){return new w(Oo(s,a))}let o=Object.assign(e,{fn:void 0,eb:void 0,selectFrom(s){return Bt({queryId:N(),executor:t,queryNode:h.createFrom(le(s))})},case(s){return new ut({node:X.create(j(s)?void 0:D(s))})},ref(s,a){return j(a)?new w(Y(s)):new De(Ji(s,a))},jsonPath(){return new De(Se.create())},table(s){return new w(y(s))},val(s){return new w(x(s))},refTuple(...s){return new w(Wi.create(s.map(D)))},tuple(...s){return new w(Wi.create(s.map(x)))},lit(s){return new w(vt(s))},unary:i,not(s){return i("not",s)},exists(s){return i("exists",s)},neg(s){return i("-",s)},between(s,a,p){return new w(qe.create(D(s),H.create("between"),$.create(x(a),x(p))))},betweenSymmetric(s,a,p){return new w(qe.create(D(s),H.create("between symmetric"),$.create(x(a),x(p))))},and(s){return P(s)?new w(et(s,"and")):new w(ii(s,"and"))},or(s){return P(s)?new w(et(s,"or")):new w(ii(s,"or"))},parens(...s){let a=g(s);return pe.is(a)?new w(a):new w(pe.create(a))},cast(s,a){return new w(Co.create(D(s),se(a)))},withSchema(s){return xr(t.withPluginAtFront(new ne(s)))}});return o.fn=br(),o.eb=o,o}function ie(t){return xr()}function K(t){if(v(t))return t.toOperationNode();if(C(t))return t(ie()).toOperationNode();throw new Error(`invalid expression: ${JSON.stringify(t)}`)}function ur(t){if(v(t))return t.toOperationNode();if(C(t))return t(ie()).toOperationNode();throw new Error(`invalid aliased expression: ${JSON.stringify(t)}`)}function ye(t){return Fi(t)||zi(t)||C(t)}function le(t){return P(t)?t.map(e=>Re(e)):[Re(t)]}function Re(t){return T(t)?Ni(t):ur(t)}function Ni(t){let e=" as ";if(t.includes(e)){let[i,o]=t.split(e).map(Wo);return z.create(y(i),c.create(o))}else return y(t)}function y(t){let e=".";if(t.includes(e)){let[i,o]=t.split(e).map(Wo);return _.createWithSchema(i,o)}else return _.create(t)}function Wo(t){return t.trim()}var Ti=r({is(t){return t.kind==="AddColumnNode"},create(t){return r({kind:"AddColumnNode",column:t})}});var b=r({is(t){return t.kind==="ColumnDefinitionNode"},create(t,e){return r({kind:"ColumnDefinitionNode",column:l.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 qi=r({is(t){return t.kind==="DropColumnNode"},create(t){return r({kind:"DropColumnNode",column:l.create(t)})}});var Ii=r({is(t){return t.kind==="RenameColumnNode"},create(t,e){return r({kind:"RenameColumnNode",column:l.create(t),renameTo:l.create(e)})}});var dt=r({is(t){return t.kind==="CheckConstraintNode"},create(t,e){return r({kind:"CheckConstraintNode",expression:t,name:e?c.create(e):void 0})}});var To=["no action","restrict","cascade","set null","set default"],pt=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 Wr(t){return v(t)?t.toOperationNode():S.createImmediate(t)}var Lt=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 qo=r({is(t){return t.kind==="DefaultValueNode"},create(t){return r({kind:"DefaultValueNode",defaultValue:t})}});function ct(t){if(To.includes(t))return t;throw new Error(`invalid OnModifyForeignAction ${t}`)}var fe=class t{#e;constructor(e){this.#e=e}autoIncrement(){return new t(b.cloneWith(this.#e,{autoIncrement:!0}))}identity(){return new t(b.cloneWith(this.#e,{identity:!0}))}primaryKey(){return new t(b.cloneWith(this.#e,{primaryKey:!0}))}references(e){let i=Y(e);if(!i.table||Ye.is(i.column))throw new Error(`invalid call references('${e}'). The reference must have format table.column or schema.table.column`);return new t(b.cloneWith(this.#e,{references:pt.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(b.cloneWith(this.#e,{references:pt.cloneWithOnDelete(this.#e.references,ct(e))}))}onUpdate(e){if(!this.#e.references)throw new Error("on update constraint can only be added for foreign keys");return new t(b.cloneWith(this.#e,{references:pt.cloneWithOnUpdate(this.#e.references,ct(e))}))}unique(){return new t(b.cloneWith(this.#e,{unique:!0}))}notNull(){return new t(b.cloneWith(this.#e,{notNull:!0}))}unsigned(){return new t(b.cloneWith(this.#e,{unsigned:!0}))}defaultTo(e){return new t(b.cloneWith(this.#e,{defaultTo:qo.create(Wr(e))}))}check(e){return new t(b.cloneWith(this.#e,{check:dt.create(e.toOperationNode())}))}generatedAlwaysAs(e){return new t(b.cloneWith(this.#e,{generated:Lt.createWithExpression(e.toOperationNode())}))}generatedAlwaysAsIdentity(){return new t(b.cloneWith(this.#e,{generated:Lt.create({identity:!0,always:!0})}))}generatedByDefaultAsIdentity(){return new t(b.cloneWith(this.#e,{generated:Lt.create({identity:!0,byDefault:!0})}))}stored(){if(!this.#e.generated)throw new Error("stored() can only be called after generatedAlwaysAs");return new t(b.cloneWith(this.#e,{generated:Lt.cloneWith(this.#e.generated,{stored:!0})}))}modifyFront(e){return new t(b.cloneWithFrontModifier(this.#e,e.toOperationNode()))}nullsNotDistinct(){return new t(b.cloneWith(this.#e,{nullsNotDistinct:!0}))}ifNotExists(){return new t(b.cloneWith(this.#e,{ifNotExists:!0}))}modifyEnd(e){return new t(b.cloneWithEndModifier(this.#e,e.toOperationNode()))}$call(e){return e(this)}toOperationNode(){return this.#e}};u(fe,"don't await ColumnDefinitionBuilder instances directly.");var Si=r({is(t){return t.kind==="ModifyColumnNode"},create(t){return r({kind:"ModifyColumnNode",column:t})}});var Ue=r({is(t){return t.kind==="ForeignKeyConstraintNode"},create(t,e,i,o){return r({kind:"ForeignKeyConstraintNode",columns:t,references:pt.create(e,i),name:o?c.create(o):void 0})},cloneWith(t,e){return r({...t,...e})}});var Je=class t{#e;constructor(e){this.#e=e}onDelete(e){return new t(Ue.cloneWith(this.#e,{onDelete:ct(e)}))}onUpdate(e){return new t(Ue.cloneWith(this.#e,{onUpdate:ct(e)}))}$call(e){return e(this)}toOperationNode(){return this.#e}};u(Je,"don't await ForeignKeyConstraintBuilder instances directly.");var ht=r({is(t){return t.kind==="AddConstraintNode"},create(t){return r({kind:"AddConstraintNode",constraint:t})}});var mt=r({is(t){return t.kind==="UniqueConstraintNode"},create(t,e,i){return r({kind:"UniqueConstraintNode",columns:r(t.map(l.create)),name:e?c.create(e):void 0,nullsNotDistinct:i})},cloneWith(t,e){return r({...t,...e})}});var lt=r({is(t){return t.kind==="DropConstraintNode"},create(t){return r({kind:"DropConstraintNode",constraintName:c.create(t)})},cloneWith(t,e){return r({...t,...e})}});var ft=r({is(t){return t.kind==="AlterColumnNode"},create(t,e,i){return r({kind:"AlterColumnNode",column:l.create(t),[e]:i})}});var Nt=class{#e;constructor(e){this.#e=e}setDataType(e){return new Be(ft.create(this.#e,"dataType",se(e)))}setDefault(e){return new Be(ft.create(this.#e,"setDefault",Wr(e)))}dropDefault(){return new Be(ft.create(this.#e,"dropDefault",!0))}setNotNull(){return new Be(ft.create(this.#e,"setNotNull",!0))}dropNotNull(){return new Be(ft.create(this.#e,"dropNotNull",!0))}$call(e){return e(this)}};u(Nt,"don't await AlterColumnBuilder instances");var Be=class{#e;constructor(e){this.#e=e}toOperationNode(){return this.#e}};u(Be,"don't await AlteredColumnBuilder instances");var Ne=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(Ne,"don't await AlterTableExecutor instances directly. To execute the query you need to call `execute`");var Pt=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(f.cloneWithTableProps(this.#e.node,{addConstraint:ht.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(Pt,"don't await AlterTableAddForeignKeyConstraintBuilder instances directly. To execute the query you need to call `execute`");var Ft=class t{#e;constructor(e){this.#e=r(e)}ifExists(){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{dropConstraint:lt.cloneWith(this.#e.node.dropConstraint,{ifExists:!0})})})}cascade(){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{dropConstraint:lt.cloneWith(this.#e.node.dropConstraint,{modifier:"cascade"})})})}restrict(){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{dropConstraint:lt.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(Ft,"don't await AlterTableDropConstraintBuilder instances directly. To execute the query you need to call `execute`");var Tr=r({is(t){return t.kind==="PrimaryKeyConstraintNode"},create(t,e){return r({kind:"PrimaryKeyConstraintNode",columns:r(t.map(l.create)),name:e?c.create(e):void 0})}});var Qe=r({is(t){return t.kind==="AddIndexNode"},create(t){return r({kind:"AddIndexNode",name:c.create(t)})},cloneWith(t,e){return r({...t,...e})},cloneWithColumns(t,e){return r({...t,columns:[...t.columns||[],...e]})}});var zt=class t{#e;constructor(e){this.#e=r(e)}unique(){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addIndex:Qe.cloneWith(this.#e.node.addIndex,{unique:!0})})})}column(e){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addIndex:Qe.cloneWithColumns(this.#e.node.addIndex,[_e(e)])})})}columns(e){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addIndex:Qe.cloneWithColumns(this.#e.node.addIndex,e.map(_e))})})}expression(e){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addIndex:Qe.cloneWithColumns(this.#e.node.addIndex,[e.toOperationNode()])})})}using(e){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addIndex:Qe.cloneWith(this.#e.node.addIndex,{using:q.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(zt,"don't await AlterTableAddIndexBuilder instances directly. To execute the query you need to call `execute`");var $e=class t{#e;constructor(e){this.#e=e}toOperationNode(){return this.#e}nullsNotDistinct(){return new t(mt.cloneWith(this.#e,{nullsNotDistinct:!0}))}};u($e,"don't await UniqueConstraintNodeBuilder instances directly.");var Mt=class{#e;constructor(e){this.#e=r(e)}renameTo(e){return new Ne({...this.#e,node:f.cloneWithTableProps(this.#e.node,{renameTo:y(e)})})}setSchema(e){return new Ne({...this.#e,node:f.cloneWithTableProps(this.#e.node,{setSchema:c.create(e)})})}alterColumn(e,i){let o=i(new Nt(e));return new Le({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,o.toOperationNode())})}dropColumn(e){return new Le({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,qi.create(e))})}renameColumn(e,i){return new Le({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Ii.create(e,i))})}addColumn(e,i,o=ue){let s=o(new fe(b.create(e,se(i))));return new Le({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Ti.create(s.toOperationNode()))})}modifyColumn(e,i,o=ue){let s=o(new fe(b.create(e,se(i))));return new Le({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Si.create(s.toOperationNode()))})}addUniqueConstraint(e,i,o=ue){let s=o(new $e(mt.create(i,e)));return new Ne({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addConstraint:ht.create(s.toOperationNode())})})}addCheckConstraint(e,i){return new Ne({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addConstraint:ht.create(dt.create(i.toOperationNode(),e))})})}addForeignKeyConstraint(e,i,o,s){return new Pt({...this.#e,constraintBuilder:new Je(Ue.create(i.map(l.create),y(o),s.map(l.create),e))})}addPrimaryKeyConstraint(e,i){return new Ne({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addConstraint:ht.create(Tr.create(i,e))})})}dropConstraint(e){return new Ft({...this.#e,node:f.cloneWithTableProps(this.#e.node,{dropConstraint:lt.create(e)})})}addIndex(e){return new zt({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addIndex:Qe.create(e)})})}dropIndex(e){return new Ne({...this.#e,node:f.cloneWithTableProps(this.#e.node,{dropIndex:We.create(e)})})}$call(e){return e(this)}};u(Mt,"don't await AlterTableBuilder instances");var Le=class t{#e;constructor(e){this.#e=r(e)}alterColumn(e,i){let o=i(new Nt(e));return new t({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,o.toOperationNode())})}dropColumn(e){return new t({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,qi.create(e))})}renameColumn(e,i){return new t({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Ii.create(e,i))})}addColumn(e,i,o=ue){let s=o(new fe(b.create(e,se(i))));return new t({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Ti.create(s.toOperationNode()))})}modifyColumn(e,i,o=ue){let s=o(new fe(b.create(e,se(i))));return new t({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Si.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)}};u(Le,"don't await AlterTableColumnAlteringBuilder instances directly. To execute the query you need to call `execute`");var yt=class extends Ae{transformValue(e){return{...super.transformValue(e),immediate:!0}}};var Vt=class t{#e;constructor(e){this.#e=r(e)}ifNotExists(){return new t({...this.#e,node:te.cloneWith(this.#e.node,{ifNotExists:!0})})}unique(){return new t({...this.#e,node:te.cloneWith(this.#e.node,{unique:!0})})}nullsNotDistinct(){return new t({...this.#e,node:te.cloneWith(this.#e.node,{nullsNotDistinct:!0})})}on(e){return new t({...this.#e,node:te.cloneWith(this.#e.node,{table:y(e)})})}column(e){return new t({...this.#e,node:te.cloneWithColumns(this.#e.node,[_e(e)])})}columns(e){return new t({...this.#e,node:te.cloneWithColumns(this.#e.node,e.map(_e))})}expression(e){return new t({...this.#e,node:te.cloneWithColumns(this.#e.node,[e.toOperationNode()])})}using(e){return new t({...this.#e,node:te.cloneWith(this.#e.node,{using:q.createWithSql(e)})})}where(...e){let i=new yt;return new t({...this.#e,node:d.cloneWithWhere(this.#e.node,i.transformNode(g(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(Vt,"don't await CreateIndexBuilder instances directly. To execute the query you need to call `execute`");var Ut=class t{#e;constructor(e){this.#e=r(e)}ifNotExists(){return new t({...this.#e,node:_t.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(Ut,"don't await CreateSchemaBuilder instances directly. To execute the query you need to call `execute`");function Io(t){if(Pi.includes(t))return t;throw new Error(`invalid OnCommitAction ${t}`)}var Jt=class t{#e;constructor(e){this.#e=r(e)}temporary(){return new t({...this.#e,node:F.cloneWith(this.#e.node,{temporary:!0})})}onCommit(e){return new t({...this.#e,node:F.cloneWith(this.#e.node,{onCommit:Io(e)})})}ifNotExists(){return new t({...this.#e,node:F.cloneWith(this.#e.node,{ifNotExists:!0})})}addColumn(e,i,o=ue){let s=o(new fe(b.create(e,se(i))));return new t({...this.#e,node:F.cloneWithColumn(this.#e.node,s.toOperationNode())})}addPrimaryKeyConstraint(e,i){return new t({...this.#e,node:F.cloneWithConstraint(this.#e.node,Tr.create(i,e))})}addUniqueConstraint(e,i,o=ue){let s=o(new $e(mt.create(i,e)));return new t({...this.#e,node:F.cloneWithConstraint(this.#e.node,s.toOperationNode())})}addCheckConstraint(e,i){return new t({...this.#e,node:F.cloneWithConstraint(this.#e.node,dt.create(i.toOperationNode(),e))})}addForeignKeyConstraint(e,i,o,s,a=ue){let p=a(new Je(Ue.create(i.map(l.create),y(o),s.map(l.create),e)));return new t({...this.#e,node:F.cloneWithConstraint(this.#e.node,p.toOperationNode())})}modifyFront(e){return new t({...this.#e,node:F.cloneWithFrontModifier(this.#e.node,e.toOperationNode())})}modifyEnd(e){return new t({...this.#e,node:F.cloneWithEndModifier(this.#e.node,e.toOperationNode())})}as(e){return new t({...this.#e,node:F.cloneWith(this.#e.node,{selectQuery:K(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(Jt,"don't await CreateTableBuilder instances directly. To execute the query you need to call `execute`");var $t=class t{#e;constructor(e){this.#e=r(e)}on(e){return new t({...this.#e,node:We.cloneWith(this.#e.node,{table:y(e)})})}ifExists(){return new t({...this.#e,node:We.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:We.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($t,"don't await DropIndexBuilder instances directly. To execute the query you need to call `execute`");var Kt=class t{#e;constructor(e){this.#e=r(e)}ifExists(){return new t({...this.#e,node:Ot.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:Ot.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(Kt,"don't await DropSchemaBuilder instances directly. To execute the query you need to call `execute`");var Gt=class t{#e;constructor(e){this.#e=r(e)}ifExists(){return new t({...this.#e,node:bt.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:bt.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(Gt,"don't await DropTableBuilder instances directly. To execute the query you need to call `execute`");var ae=r({is(t){return t.kind==="CreateViewNode"},create(t){return r({kind:"CreateViewNode",name:J.create(t)})},cloneWith(t,e){return r({...t,...e})}});var qr=class{#e=new yt;transformQuery(e){return this.#e.transformNode(e.node)}transformResult(e){return Promise.resolve(e.result)}};var jt=class t{#e;constructor(e){this.#e=r(e)}temporary(){return new t({...this.#e,node:ae.cloneWith(this.#e.node,{temporary:!0})})}materialized(){return new t({...this.#e,node:ae.cloneWith(this.#e.node,{materialized:!0})})}ifNotExists(){return new t({...this.#e,node:ae.cloneWith(this.#e.node,{ifNotExists:!0})})}orReplace(){return new t({...this.#e,node:ae.cloneWith(this.#e.node,{orReplace:!0})})}columns(e){return new t({...this.#e,node:ae.cloneWith(this.#e.node,{columns:e.map(ei)})})}as(e){let i=e.withPlugin(new qr).toOperationNode();return new t({...this.#e,node:ae.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(jt,"don't await CreateViewBuilder instances directly. To execute the query you need to call `execute`");var wt=r({is(t){return t.kind==="DropViewNode"},create(t){return r({kind:"DropViewNode",name:J.create(t)})},cloneWith(t,e){return r({...t,...e})}});var Ht=class t{#e;constructor(e){this.#e=r(e)}materialized(){return new t({...this.#e,node:wt.cloneWith(this.#e.node,{materialized:!0})})}ifExists(){return new t({...this.#e,node:wt.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:wt.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(Ht,"don't await DropViewBuilder instances directly. To execute the query you need to call `execute`");var Ir=r({is(t){return t.kind==="CreateTypeNode"},create(t){return r({kind:"CreateTypeNode",name:t})},cloneWithEnum(t,e){return r({...t,enum:ke.create(e.map(i=>S.createImmediate(i)))})}});var Yt=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:Ir.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(Yt,"don't await CreateTypeBuilder instances directly. To execute the query you need to call `execute`");var Sr=r({is(t){return t.kind==="DropTypeNode"},create(t){return r({kind:"DropTypeNode",name:t})},cloneWith(t,e){return r({...t,...e})}});var Xt=class t{#e;constructor(e){this.#e=r(e)}ifExists(){return new t({...this.#e,node:Sr.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(Xt,"don't await DropTypeBuilder instances directly. To execute the query you need to call `execute`");function ki(t){let e=".";if(t.includes(e)){let i=t.split(e).map(gn);if(i.length===2)return J.createWithSchema(i[0],i[1]);throw new Error(`invalid schemable identifier ${t}`)}else return J.create(t)}function gn(t){return t.trim()}var kr=class t{#e;constructor(e){this.#e=e}createTable(e){return new Jt({queryId:N(),executor:this.#e,node:F.create(y(e))})}dropTable(e){return new Gt({queryId:N(),executor:this.#e,node:bt.create(y(e))})}createIndex(e){return new Vt({queryId:N(),executor:this.#e,node:te.create(e)})}dropIndex(e){return new $t({queryId:N(),executor:this.#e,node:We.create(e)})}createSchema(e){return new Ut({queryId:N(),executor:this.#e,node:_t.create(e)})}dropSchema(e){return new Kt({queryId:N(),executor:this.#e,node:Ot.create(e)})}alterTable(e){return new Mt({queryId:N(),executor:this.#e,node:f.create(y(e))})}createView(e){return new jt({queryId:N(),executor:this.#e,node:ae.create(e)})}dropView(e){return new Ht({queryId:N(),executor:this.#e,node:wt.create(e)})}createType(e){return new Yt({queryId:N(),executor:this.#e,node:Ir.create(ki(e))})}dropType(e){return new Xt({queryId:N(),executor:this.#e,node:Sr.create(ki(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 ne(e)))}};var Ar=class{ref(e){return new tr(e)}};var Er=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 Rr=class t extends st{#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 Ai(){return typeof performance<"u"&&C(performance.now)?performance.now():Date.now()}var Dr=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,a=Ai();try{return await i.call(e,o)}catch(p){throw s=p,await this.#u(p,o,a),p}finally{s||await this.#p(o,a)}}}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 Ai()-e}};var On=()=>{},Zt=class{#e;#t;constructor(e){this.#e=e}async provideConnection(e){for(;this.#t;)await this.#t.catch(On);return this.#t=this.#r(e).finally(()=>{this.#t=void 0}),this.#t}async#r(e){return await e(this.#e)}};var So=["read uncommitted","read committed","repeatable read","serializable","snapshot"];var Qv=r(["query","error"]),Br=class{#e;#t;constructor(e){C(e)?(this.#t=e,this.#e=r({query:!0,error:!0})):(this.#t=bn,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 bn(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 ko(t){return V(t)&&C(t.compile)}var xt=class t extends at{#e;constructor(e){let i,o;if(vn(e))i={executor:e.executor},o={...e};else{let s=e.dialect,a=s.createDriver(),p=s.createQueryCompiler(),m=s.createAdapter(),O=new Br(e.log??[]),W=new Dr(a,O),I=new Er(W),G=new Rr(p,m,I,e.plugins??[]);i={executor:G},o={config:e,executor:G,dialect:s,driver:W}}super(i),this.#e=r(o)}get schema(){return new kr(this.#e.executor)}get dynamic(){return new Ar}get introspection(){return this.#e.dialect.createIntrospector(this.withoutPlugins())}case(e){return new ut({node:X.create(j(e)?void 0:K(e))})}get fn(){return br()}transaction(){return new Lr({...this.#e})}connection(){return new Qr({...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 ne(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=N()){let o=ko(e)?e.compile():e;return this.getExecutor().executeQuery(o,i)}},Ei=class t extends xt{#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 ne(e))})}withTables(){return new t({...this.#e})}};function vn(t){return V(t)&&V(t.config)&&V(t.driver)&&V(t.executor)&&V(t.dialect)}var Qr=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 Zt(i)),s=new xt({...this.#e,executor:o});return await e(s)})}};u(Qr,"don't await ConnectionBuilder instances directly. To execute the query you need to call the `execute` method");var Lr=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 Cn(s),this.#e.executor.provideConnection(async a=>{let p=this.#e.executor.withConnectionProvider(new Zt(a)),m=new Ei({...o,executor:p});try{await this.#e.driver.beginTransaction(a,s);let O=await e(m);return await this.#e.driver.commitTransaction(a),O}catch(O){throw await this.#e.driver.rollbackTransaction(a),O}})}};u(Lr,"don't await TransactionBuilder instances directly. To execute the transaction you need to call the `execute` method");function Cn(t){if(t.isolationLevel&&!So.includes(t.isolationLevel))throw new Error(`invalid transaction isolation level ${t.isolationLevel}`)}var Pr=class t{#e;constructor(e){this.#e=r(e)}get expressionType(){}get isRawBuilder(){return!0}as(e){return new Fr(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():Ee;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 ve(t){return new Pr(t)}u(Pr,"don't await RawBuilder instances directly. To execute the query you need to call `execute`");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 rawBuilder(){return this.#e}toOperationNode(){return z.create(this.#e.toOperationNode(),v(this.#t)?this.#t.toOperationNode():c.create(this.#t))}};u(Fr,"don't await AliasedRawBuilder instances directly. AliasedRawBuilder should never be executed directly since it's always a part of another query.");var Z=Object.assign((t,...e)=>ve({queryId:N(),rawNode:q.create(t,e?.map(Ao)??[])}),{ref(t){return ve({queryId:N(),rawNode:q.createWithChild(Y(t))})},val(t){return ve({queryId:N(),rawNode:q.createWithChild(x(t))})},value(t){return this.val(t)},table(t){return ve({queryId:N(),rawNode:q.createWithChild(y(t))})},id(...t){let e=new Array(t.length+1).fill(".");return e[0]="",e[e.length-1]="",ve({queryId:N(),rawNode:q.create(e,t.map(c.create))})},lit(t){return ve({queryId:N(),rawNode:q.createWithChild(S.createImmediate(t))})},literal(t){return this.lit(t)},raw(t){return ve({queryId:N(),rawNode:q.createWithSql(t)})},join(t,e=Z`, `){let i=new Array(2*t.length-1),o=e.toOperationNode();for(let s=0;s<t.length;++s)i[2*s]=Ao(t[s]),s!==t.length-1&&(i[2*s+1]=o);return ve({queryId:N(),rawNode:q.createWithChildren(i)})}});function Ao(t){return v(t)?t.toOperationNode():x(t)}var zr=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 Mr=class extends zr{#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&&!pe.is(this.parentNode)&&!E.is(this.parentNode)&&!F.is(this.parentNode)&&!ae.is(this.parentNode)&&!wr.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(d.is),o=i!==e;!o&&e.explain&&(this.visitNode(e.explain),this.append(" ")),o&&!R.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&&!R.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(!T(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(Tn[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(d.is),o=i!==e;!o&&e.explain&&(this.visitNode(e.explain),this.append(" ")),o&&!R.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&&!R.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 "),Pe(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(Wn[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 H.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 a of e)s+=a,a===i?s+=i:a===o&&(s+=o);return s}addParameter(e){this.#t.push(e)}appendImmediateValue(e){if(T(e))this.append(`'${e}'`);else if(Ce(e)||Pe(e))this.append(e.toString());else if(je(e))this.append("null");else if(Li(e))this.appendImmediateValue(e.toISOString());else if(He(e))this.appendImmediateValue(e.toString());else throw new Error(`invalid immediate value ${e}`)}sortSelectModifiers(e){return e.sort((i,o)=>i.modifier&&o.modifier?Eo[i.modifier]-Eo[o.modifier]:1),r(e)}compileColumnAlterations(e){this.compileList(e)}announcesNewColumnDataType(){return!0}},Wn=r({ForKeyShare:"for key share",ForNoKeyUpdate:"for no key update",ForUpdate:"for update",ForShare:"for share",NoWait:"nowait",SkipLocked:"skip locked",Distinct:"distinct"}),Eo=r({ForKeyShare:1,ForNoKeyUpdate:1,ForUpdate:1,ForShare:1,NoWait:2,SkipLocked:2,Distinct:0}),Tn=r({InnerJoin:"inner join",LeftJoin:"left join",RightJoin:"right join",FullJoin:"full join",LateralInnerJoin:"inner join lateral",LateralLeftJoin:"left join lateral",Using:"using"});var Vr=class{async init(){}async acquireConnection(){return new Ri}async beginTransaction(){}async commitTransaction(){}async rollbackTransaction(){}async releaseConnection(){}async destroy(){}},Ri=class{async executeQuery(){return{rows:[]}}async*streamQuery(){}};var Ur=class{get supportsCreateIfNotExists(){return!0}get supportsTransactionalDdl(){return!1}get supportsReturning(){return!1}get supportsOutput(){return!1}};var qn=/"/g,Jr=class extends Mr{sanitizeIdentifier(e){return e.replace(qn,'""')}};var In=BigInt("3853314791062309107"),$r=class extends Ur{get supportsTransactionalDdl(){return!0}get supportsReturning(){return!0}async acquireMigrationLock(e,i){await Z`select pg_advisory_xact_lock(${Z.lit(In)})`.execute(e)}async releaseMigrationLock(e,i){}};function Ro(t){return new xt({dialect:{createAdapter:()=>new t.Adapter,createDriver:()=>new Vr,createIntrospector:()=>null,createQueryCompiler:()=>new t.QueryCompiler},plugins:[...t.noParameters?[new Di]:[]]})}var Di=class{#e=new Bi;transformQuery(e){return this.#e.transformNode(e.node)}transformResult(e){return Promise.resolve(e.result)}},Bi=class extends Ae{transformPrimitiveValueList(e){return ke.create(e.values.map(S.createImmediate))}transformValue(e){return{...super.transformValue(e),immediate:!0}}};function Ke(t){let e=t.compile();return{parameters:e.parameters,sql:e.sql}}function Do(t,e){let i=Sn(t,e);return o=>o.where(s=>s.and(i.map(([a,p])=>s(a,p===null?"is":"=",p))))}function Sn(t,e){return Object.entries(Object.values(e).reduce((i,o)=>{let{isInPrimaryKey:s,name:a}=o;return s&&(i[a]=t[a]),i},{}))}function Ge(t){return Ro({...t,Adapter:$r,QueryCompiler:Jr})}function Bo(t,e){let{table:i,rows:o}=t,{name:s,schema:a,columns:p}=i,m=Ge(e),O=Object.values(p).map(({name:W})=>`${s}.${W}`);return Ke(m.withSchema(a).insertInto(s).values(o).returning(O).returning(W=>[W.cast("ctid","text").as("ctid")]))}function Qo(t,e){let{pageIndex:i,pageSize:o,sortOrder:s,table:{name:a,schema:p,columns:m}}=t,O=Ge(e),W=Object.values(m).map(({name:I})=>`${a}.${I}`);return Ke(O.with("count",I=>I.withSchema(p).selectFrom(a).select(G=>G.cast(O.fn.coalesce(O.fn.countAll(),Z.lit(0)),"text").as("oid"))).withSchema(p).selectFrom([a,"count"]).select(I=>[I.cast("ctid","text").as("ctid"),I.ref("count.oid").as("oid")]).select(W).$call(I=>s.reduce((G,L)=>G.orderBy(L.column,L.direction),I)).limit(o).offset(Z.lit(BigInt(i)*BigInt(o))))}function Lo(t,e){let{changes:i,row:o,table:{columns:s,name:a,schema:p}}=t,m=Ge(e),O=Object.values(s).map(({name:W})=>`${a}.${W}`);return Ke(m.withSchema(p).updateTable(a).set(i).$call(Do(o,s)).returning(O).returning(W=>[W.cast("ctid","text").as("ctid"),W.cast(W.fn("floor",[W(W.fn("extract",[Z`epoch from now()`]),"*",1e6)]),"text").as("__ps_updated_at__")]))}function Po(t){return Z`(select coalesce(json_agg(agg), '[]') from ${t} as agg)`}var kn="r",An="v",En=[kn,An];function Fo(t){return Ke(Ge(t).selectFrom("pg_catalog.pg_class as cls").innerJoin("pg_catalog.pg_namespace as ns","cls.relnamespace","ns.oid").$call(Rn).where("cls.relkind","in",En).select(e=>["ns.nspname as schema","cls.relname as name",Po(e.selectFrom("pg_catalog.pg_attribute as att").innerJoin("pg_catalog.pg_type as typ","typ.oid","att.atttypid").leftJoin("pg_catalog.pg_constraint as con",i=>i.on("con.contype","=","p").onRef("con.conrelid","=","cls.oid").on(o=>Z`${o.ref("att.attnum")} = ANY(${o.ref("con.conkey")})`)).whereRef("att.attrelid","=","cls.oid").where("att.attnum",">=",0).where("att.attisdropped","!=",!0).where("att.attgenerated","=","").select(i=>["att.attname as name","typ.typname as datatype",i("con.conkey","is not",null).$castTo().as("pk"),i("att.attgenerated","!=","").$castTo().as("computed")])).as("columns")]))}function zo(){let t=Ge();return Ke(t.selectNoFrom(t.fn("current_setting",[Z.lit("timezone")]).as("timezone")))}function Rn(t){return t.where("ns.nspname","!~","^pg_").where("ns.nspname","!=","information_schema")}function Mo(t){let{executor:e,...i}=t;return{defaultSchema:"public",async introspect(o){try{let s=Fo(i),a=zo(),[[p,m],[O,W]]=await Promise.all([e.execute(s,o),e.execute(a,o)]),I=p||O;if(I)return[I];let[G]=W;return G?[null,Dn(m,G.timezone)]:[new Error("Timezone not found")]}catch(s){return[s]}},async query(o,s){try{let a=Qo(o,i),[p,m]=await e.execute(a,s);return p?[p]:[null,{filteredRowCount:m[0]?.oid||"0",rows:m}]}catch(a){return[a]}},async insert(o,s){try{let a=Bo(o,i),[p,m]=await e.execute(a,s);return p?[p]:[null,{rows:m}]}catch(a){return[a]}},async update(o,s){try{let a=Lo(o,i),[p,m]=await e.execute(a,s);if(p)return[p];let[O]=m;return O?[null,{row:O}]:[new Error("Update failed")]}catch(a){return[a]}}}}function Dn(t,e){return t.reduce((i,o)=>{let{schemas:s}=i,{columns:a,name:p,schema:m}=o,O=a.reduce((W,{datatype:I,computed:G,name:L,pk:Kr})=>{let Gr=I.startsWith("_"),jr=Gr?I.slice(1):I;return{...W,[L]:{name:L,schema:m,table:L,isInPrimaryKey:Kr,datatype:{...Qi[jr]||{group:"raw"},isArray:Gr,name:Gr?`${jr}[]`:jr},computed:G}}},{});return(s[m]||={tables:{}}).tables[p]={columns:O,name:p,schema:m},i},{schemas:{public:{tables:{}}},timezone:e})}function Vo(t,e){let{addDelay:i=0}=e??{};return{execute:async(o,s)=>{let{abortSignal:a}=s||{},p,m=new Promise((L,Kr)=>p=Kr);function O(){let L=new Error("This operation was aborted");L.name="AbortError",p(L)}a?.addEventListener("abort",O);let W=typeof i=="function"?i(o):i,I=()=>t.query(o.sql,o.parameters,{rowMode:"object"}),G=W>0?()=>new Promise(L=>setTimeout(L,W)).then(()=>I()):I;try{return[null,(await Promise.race([G(),m])).rows]}catch(L){return[L]}finally{a?.removeEventListener("abort",O)}}}}function Bn(t,e){return Mo({executor:Vo(t,e)})}0&&(module.exports={createPGLiteAdapter,createPGLiteExecutor});
|