import * as ___react___ from 'react'; import * as ___react_dom___ from 'react-dom'; function require(mod) { if (mod === 'react') return ___react___; if (mod === 'react-dom') return ___react_dom___; throw new Error(`Unknown module ${mod}`); } import{b as Io,d as Lo}from"./chunk-6QJ7HVIC.js";var qo=Io((Ti,ki)=>{"use strict";(function(t,e){typeof Ti=="object"&&typeof ki<"u"?ki.exports=e():typeof define=="function"&&define.amd?define(e):(t=typeof globalThis<"u"?globalThis:t||self).dayjs=e()})(Ti,(function(){"use strict";var t=1e3,e=6e4,r=36e5,o="millisecond",n="second",s="minute",a="hour",c="day",g="week",w="month",te="quarter",M="year",re="date",f="Invalid Date",Y=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,ut=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,Ke={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(N){var h=["th","st","nd","rd"],d=N%100;return"["+N+(h[(d-20)%10]||h[d]||h[0])+"]"}},ye=function(N,h,d){var m=String(N);return!m||m.length>=h?N:""+Array(h+1-m.length).join(d)+N},xr={s:ye,z:function(N){var h=-N.utcOffset(),d=Math.abs(h),m=Math.floor(d/60),p=d%60;return(h<=0?"+":"-")+ye(m,2,"0")+":"+ye(p,2,"0")},m:function N(h,d){if(h.date()1)return N(x[0])}else{var I=h.name;De[I]=h,p=I}return!m&&p&&(Qe=p),p||!m&&Qe},z=function(N,h){if(er(N))return N.clone();var d=typeof h=="object"?h:{};return d.date=N,d.args=arguments,new wr(d)},E=xr;E.l=Ge,E.i=er,E.w=function(N,h){return z(N,{locale:h.$L,utc:h.$u,x:h.$x,$offset:h.$offset})};var wr=(function(){function N(d){this.$L=Ge(d.locale,null,!0),this.parse(d),this.$x=this.$x||d.x||{},this[gt]=!0}var h=N.prototype;return h.parse=function(d){this.$d=(function(m){var p=m.date,y=m.utc;if(p===null)return new Date(NaN);if(E.u(p))return new Date;if(p instanceof Date)return new Date(p);if(typeof p=="string"&&!/Z$/i.test(p)){var x=p.match(Y);if(x){var I=x[2]-1||0,Q=(x[7]||"0").substring(0,3);return y?new Date(Date.UTC(x[1],I,x[3]||1,x[4]||0,x[5]||0,x[6]||0,Q)):new Date(x[1],I,x[3]||1,x[4]||0,x[5]||0,x[6]||0,Q)}}return new Date(p)})(d),this.init()},h.init=function(){var d=this.$d;this.$y=d.getFullYear(),this.$M=d.getMonth(),this.$D=d.getDate(),this.$W=d.getDay(),this.$H=d.getHours(),this.$m=d.getMinutes(),this.$s=d.getSeconds(),this.$ms=d.getMilliseconds()},h.$utils=function(){return E},h.isValid=function(){return this.$d.toString()!==f},h.isSame=function(d,m){var p=z(d);return this.startOf(m)<=p&&p<=this.endOf(m)},h.isAfter=function(d,m){return z(d){"use strict";(function(t,e){typeof Ei=="object"&&typeof Ai<"u"?Ai.exports=e():typeof define=="function"&&define.amd?define(e):(t=typeof globalThis<"u"?globalThis:t||self).dayjs_plugin_utc=e()})(Ei,(function(){"use strict";var t="minute",e=/[+-]\d\d(?::?\d\d)?/g,r=/([+-]|\d\d)/g;return function(o,n,s){var a=n.prototype;s.utc=function(f){var Y={date:f,utc:!0,args:arguments};return new n(Y)},a.utc=function(f){var Y=s(this.toDate(),{locale:this.$L,utc:!0});return f?Y.add(this.utcOffset(),t):Y},a.local=function(){return s(this.toDate(),{locale:this.$L,utc:!1})};var c=a.parse;a.parse=function(f){f.utc&&(this.$u=!0),this.$utils().u(f.$offset)||(this.$offset=f.$offset),c.call(this,f)};var g=a.init;a.init=function(){if(this.$u){var f=this.$d;this.$y=f.getUTCFullYear(),this.$M=f.getUTCMonth(),this.$D=f.getUTCDate(),this.$W=f.getUTCDay(),this.$H=f.getUTCHours(),this.$m=f.getUTCMinutes(),this.$s=f.getUTCSeconds(),this.$ms=f.getUTCMilliseconds()}else g.call(this)};var w=a.utcOffset;a.utcOffset=function(f,Y){var ut=this.$utils().u;if(ut(f))return this.$u?0:ut(this.$offset)?w.call(this):this.$offset;if(typeof f=="string"&&(f=(function(Qe){Qe===void 0&&(Qe="");var De=Qe.match(e);if(!De)return null;var gt=(""+De[0]).match(r)||["-",0,0],er=gt[0],Ge=60*+gt[1]+ +gt[2];return Ge===0?0:er==="+"?Ge:-Ge})(f),f===null))return this;var Ke=Math.abs(f)<=16?60*f:f;if(Ke===0)return this.utc(Y);var ye=this.clone();if(Y)return ye.$offset=Ke,ye.$u=!1,ye;var xr=this.$u?this.toDate().getTimezoneOffset():-1*this.utcOffset();return(ye=this.local().add(Ke+xr,t)).$offset=Ke,ye.$x.$localOffset=xr,ye};var te=a.format;a.format=function(f){var Y=f||(this.$u?"YYYY-MM-DDTHH:mm:ss[Z]":"");return te.call(this,Y)},a.valueOf=function(){var f=this.$utils().u(this.$offset)?0:this.$offset+(this.$x.$localOffset||this.$d.getTimezoneOffset());return this.$d.valueOf()-6e4*f},a.isUTC=function(){return!!this.$u},a.toISOString=function(){return this.toDate().toISOString()},a.toString=function(){return this.toDate().toUTCString()};var M=a.toDate;a.toDate=function(f){return f==="s"&&this.$offset?s(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate():M.call(this)};var re=a.diff;a.diff=function(f,Y,ut){if(f&&this.$u===f.$u)return re.call(this,f,Y,ut);var Ke=this.local(),ye=s(f).local();return re.call(Ke,ye,Y,ut)}}}))});var Di=Lo(qo(),1),Mo=Lo(Bo(),1);Di.default.extend(Mo.default);var Yn={};function Po(t){return Yn[t]??=(0,Di.default)(0).utc().format(t)}var Qo="",$o=0,Fo=!1,Us="[]",Ri="{}",Js=Ri;function pe(t){return typeof t>"u"||t===void 0}function L(t){return typeof t=="string"}function Ye(t){return typeof t=="number"}function ht(t){return typeof t=="boolean"}function vt(t){return t===null}function zo(t){return t instanceof Date}function bt(t){return typeof t=="bigint"}function q(t){return typeof t=="function"}function K(t){return typeof t=="object"&&t!==null}function i(t){return Object.freeze(t)}function ir(t){return Z(t)?t:[t]}function Z(t){return Array.isArray(t)}function ie(t){return t}var v=i({is(t){return t.kind==="AlterTableNode"},create(t){return i({kind:"AlterTableNode",table:t})},cloneWithTableProps(t,e){return i({...t,...e})},cloneWithColumnAlteration(t,e){return i({...t,columnAlterations:t.columnAlterations?[...t.columnAlterations,e]:[e]})}});var l=i({is(t){return t.kind==="IdentifierNode"},create(t){return i({kind:"IdentifierNode",name:t})}});var ve=i({is(t){return t.kind==="CreateIndexNode"},create(t){return i({kind:"CreateIndexNode",name:l.create(t)})},cloneWith(t,e){return i({...t,...e})},cloneWithColumns(t,e){return i({...t,columns:[...t.columns||[],...e]})}});var Or=i({is(t){return t.kind==="CreateSchemaNode"},create(t,e){return i({kind:"CreateSchemaNode",schema:l.create(t),...e})},cloneWith(t,e){return i({...t,...e})}});var Vo=["preserve rows","delete rows","drop"],_=i({is(t){return t.kind==="CreateTableNode"},create(t){return i({kind:"CreateTableNode",table:t,columns:i([])})},cloneWithColumn(t,e){return i({...t,columns:i([...t.columns,e])})},cloneWithConstraint(t,e){return i({...t,constraints:t.constraints?i([...t.constraints,e]):i([e])})},cloneWithFrontModifier(t,e){return i({...t,frontModifiers:t.frontModifiers?i([...t.frontModifiers,e]):i([e])})},cloneWithEndModifier(t,e){return i({...t,endModifiers:t.endModifiers?i([...t.endModifiers,e]):i([e])})},cloneWith(t,e){return i({...t,...e})}});var ee=i({is(t){return t.kind==="SchemableIdentifierNode"},create(t){return i({kind:"SchemableIdentifierNode",identifier:l.create(t)})},createWithSchema(t,e){return i({kind:"SchemableIdentifierNode",schema:l.create(t),identifier:l.create(e)})}});var Xe=i({is(t){return t.kind==="DropIndexNode"},create(t,e){return i({kind:"DropIndexNode",name:ee.create(t),...e})},cloneWith(t,e){return i({...t,...e})}});var or=i({is(t){return t.kind==="DropSchemaNode"},create(t,e){return i({kind:"DropSchemaNode",schema:l.create(t),...e})},cloneWith(t,e){return i({...t,...e})}});var nr=i({is(t){return t.kind==="DropTableNode"},create(t,e){return i({kind:"DropTableNode",table:t,...e})},cloneWith(t,e){return i({...t,...e})}});var U=i({is(t){return t.kind==="AliasNode"},create(t,e){return i({kind:"AliasNode",node:t,alias:e})}});var ae=i({is(t){return t.kind==="TableNode"},create(t){return i({kind:"TableNode",table:ee.create(t)})},createWithSchema(t,e){return i({kind:"TableNode",table:ee.createWithSchema(t,e)})}});function D(t){return K(t)&&q(t.toOperationNode)}function vr(t){return K(t)&&"expressionType"in t&&D(t)}function Uo(t){return K(t)&&"expression"in t&&L(t.alias)&&D(t)}var Re=i({is(t){return t.kind==="SelectModifierNode"},create(t,e){return i({kind:"SelectModifierNode",modifier:t,of:e})},createWithExpression(t){return i({kind:"SelectModifierNode",rawModifier:t})}});var ue=i({is(t){return t.kind==="AndNode"},create(t,e){return i({kind:"AndNode",left:t,right:e})}});var be=i({is(t){return t.kind==="OrNode"},create(t,e){return i({kind:"OrNode",left:t,right:e})}});var br=i({is(t){return t.kind==="OnNode"},create(t){return i({kind:"OnNode",on:t})},cloneWithOperation(t,e,r){return i({...t,on:e==="And"?ue.create(t.on,r):be.create(t.on,r)})}});var Ce=i({is(t){return t.kind==="JoinNode"},create(t,e){return i({kind:"JoinNode",joinType:t,table:e,on:void 0})},createWithOn(t,e,r){return i({kind:"JoinNode",joinType:t,table:e,on:br.create(r)})},cloneWithOn(t,e){return i({...t,on:t.on?br.cloneWithOperation(t.on,"And",e):br.create(e)})}});var Ze=i({is(t){return t.kind==="BinaryOperationNode"},create(t,e,r){return i({kind:"BinaryOperationNode",leftOperand:t,operator:e,rightOperand:r})}});var Xn=["=","==","!=","<>",">",">=","<","<=","in","not in","is","is not","like","not like","match","ilike","not ilike","@>","<@","^@","&&","?","?&","?|","!<","!>","<=>","!~","~","~*","!~*","@@","@@@","!!","<->","regexp","is distinct from","is not distinct from"],Zn=["+","-","*","/","%","^","&","|","#","<<",">>"],Jo=["->","->>"],_n=[...Xn,...Zn,"&&","||"],es=["exists","not exists"],ts=["not","-",...es],jo=[..._n,...Jo,...ts,"between","between symmetric"],he=i({is(t){return t.kind==="OperatorNode"},create(t){return i({kind:"OperatorNode",operator:t})}});function Ii(t){return L(t)&&Jo.includes(t)}var O=i({is(t){return t.kind==="ColumnNode"},create(t){return i({kind:"ColumnNode",column:l.create(t)})}});var Ct=i({is(t){return t.kind==="SelectAllNode"},create(){return i({kind:"SelectAllNode"})}});var Wt=i({is(t){return t.kind==="ReferenceNode"},create(t,e){return i({kind:"ReferenceNode",table:e,column:t})},createSelectAll(t){return i({kind:"ReferenceNode",table:t,column:Ct.create()})}});var Cr=class{#e;get dynamicReference(){return this.#e}get refType(){}constructor(e){this.#e=e}toOperationNode(){return Li(this.#e)}};function Wr(t){return K(t)&&D(t)&&L(t.dynamicReference)}var We=i({is(t){return t.kind==="OrderByItemNode"},create(t,e){return i({kind:"OrderByItemNode",orderBy:t,direction:e})},cloneWith(t,e){return i({...t,...e})}});var T=i({is(t){return t.kind==="RawNode"},create(t,e){return i({kind:"RawNode",sqlFragments:i(t),parameters:i(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)}});var Ko=i({is(t){return t.kind==="CollateNode"},create(t){return i({kind:"CollateNode",collation:l.create(t)})}});var Sr=class t{#e;constructor(e){this.#e=i(e)}desc(){return new t({node:We.cloneWith(this.#e.node,{direction:T.createWithSql("desc")})})}asc(){return new t({node:We.cloneWith(this.#e.node,{direction:T.createWithSql("asc")})})}nullsLast(){return new t({node:We.cloneWith(this.#e.node,{nulls:"last"})})}nullsFirst(){return new t({node:We.cloneWith(this.#e.node,{nulls:"first"})})}collate(e){return new t({node:We.cloneWith(this.#e.node,{collation:Ko.create(e)})})}toOperationNode(){return this.#e.node}};var Go=new Set;function Ie(t){Go.has(t)||(Go.add(t),console.log(t))}function Bi(t){return t==="asc"||t==="desc"}function me(t){if(t.length===2)return[qi(t[0],t[1])];if(t.length===1){let[e]=t;return Array.isArray(e)?(Ie("orderBy(array) is deprecated, use multiple orderBy calls instead."),e.map(r=>qi(r))):[qi(e)]}throw new Error(`Invalid number of arguments at order by! expected 1-2, received ${t.length}`)}function qi(t,e){let r=rs(t);if(We.is(r)){if(e)throw new Error("Cannot specify direction twice!");return r}return Ho(r,e)}function rs(t){if($e(t))return de(t);if(Wr(t))return t.toOperationNode();let[e,r]=t.split(" ");return r?(Ie("`orderBy('column asc')` is deprecated. Use `orderBy('column', 'asc')` instead."),Ho(ce(e),r)):ce(t)}function Ho(t,e){if(typeof e=="string"){if(!Bi(e))throw new Error(`Invalid order by direction: ${e}`);return We.create(t,T.createWithSql(e))}if(vr(e))return Ie("`orderBy(..., expr)` is deprecated. Use `orderBy(..., 'asc')` or `orderBy(..., (ob) => ...)` instead."),We.create(t,e.toOperationNode());let r=We.create(t);return e?e(new Sr({node:r})).toOperationNode():r}var St=i({is(t){return t.kind==="JSONReferenceNode"},create(t,e){return i({kind:"JSONReferenceNode",reference:t,traversal:e})},cloneWithTraversal(t,e){return i({...t,traversal:e})}});var Tr=i({is(t){return t.kind==="JSONOperatorChainNode"},create(t){return i({kind:"JSONOperatorChainNode",operator:t,values:i([])})},cloneWithValue(t,e){return i({...t,values:i([...t.values,e])})}});var _e=i({is(t){return t.kind==="JSONPathNode"},create(t){return i({kind:"JSONPathNode",inOperator:t,pathLegs:i([])})},cloneWithLeg(t,e){return i({...t,pathLegs:i([...t.pathLegs,e])})}});function Li(t){return L(t)?ce(t):t.toOperationNode()}function Fe(t){return Z(t)?t.map(e=>G(e)):[G(t)]}function G(t){return $e(t)?de(t):Li(t)}function Yo(t,e){let r=ce(t);if(Ii(e))return St.create(r,Tr.create(he.create(e)));let o=e.slice(0,-1);if(Ii(o))return St.create(r,_e.create(he.create(o)));throw new Error(`Invalid JSON operator: ${e}`)}function ce(t){if(!t.includes("."))return Wt.create(O.create(t));let r=t.split(".").map(Pi);if(r.length===3)return is(r);if(r.length===2)return os(r);throw new Error(`invalid column reference ${t}`)}function Xo(t){let e=" as ";if(t.includes(e)){let[r,o]=t.split(e).map(Pi);return U.create(ce(r),l.create(o))}else return ce(t)}function Mi(t){return O.create(t)}function Tt(t){if(t.includes(" ")){let[r,o]=t.split(" ").map(Pi);if(!Bi(o))throw new Error(`invalid order direction "${o}" next to "${r}"`);return me([r,o])[0]}else return Mi(t)}function is(t){let[e,r,o]=t;return Wt.create(O.create(o),ae.createWithSchema(e,r))}function os(t){let[e,r]=t;return Wt.create(O.create(r),ae.create(e))}function Pi(t){return t.trim()}var kr=i({is(t){return t.kind==="PrimitiveValueListNode"},create(t){return i({kind:"PrimitiveValueListNode",values:i([...t])})}});var Le=i({is(t){return t.kind==="ValueListNode"},create(t){return i({kind:"ValueListNode",values:i(t)})}});var P=i({is(t){return t.kind==="ValueNode"},create(t){return i({kind:"ValueNode",value:t})},createImmediate(t){return i({kind:"ValueNode",value:t,immediate:!0})}});function Zo(t){return Z(t)?ns(t):k(t)}function k(t){return $e(t)?de(t):P.create(t)}function Er(t){return Ye(t)||ht(t)||vt(t)}function sr(t){if(!Er(t))throw new Error(`unsafe immediate value ${JSON.stringify(t)}`);return P.createImmediate(t)}function ns(t){return t.some($e)?Le.create(t.map(e=>k(e))):kr.create(t)}var le=i({is(t){return t.kind==="ParensNode"},create(t){return i({kind:"ParensNode",node:t})}});function A(t){if(t.length===3)return Ar(t[0],t[1],t[2]);if(t.length===1)return k(t[0]);throw new Error(`invalid arguments: ${JSON.stringify(t)}`)}function Ar(t,e,r){return ss(e)&&en(r)?Ze.create(G(t),Qi(e),P.createImmediate(r)):Ze.create(G(t),Qi(e),Zo(r))}function J(t,e,r){return Ze.create(G(t),Qi(e),G(r))}function $i(t,e){return kt(Object.entries(t).filter(([,r])=>!pe(r)).map(([r,o])=>Ar(r,en(o)?"is":"=",o)),e)}function kt(t,e,r=!0){let o=e==="and"?ue.create:be.create;if(t.length===0)return Ze.create(P.createImmediate(1),he.create("="),P.createImmediate(e==="and"?1:0));let n=_o(t[0]);for(let s=1;s1&&r?le.create(n):n}function ss(t){return t==="is"||t==="is not"}function en(t){return vt(t)||ht(t)}function Qi(t){if(L(t)&&jo.includes(t))return he.create(t);if(D(t))return t.toOperationNode();throw new Error(`invalid operator ${JSON.stringify(t)}`)}function _o(t){return D(t)?t.toOperationNode():t}var ze=i({is(t){return t.kind==="OrderByNode"},create(t){return i({kind:"OrderByNode",items:i([...t])})},cloneWithItems(t,e){return i({...t,items:i([...t.items,...e])})}});var Fi=i({is(t){return t.kind==="PartitionByNode"},create(t){return i({kind:"PartitionByNode",items:i(t)})},cloneWithItems(t,e){return i({...t,items:i([...t.items,...e])})}});var ar=i({is(t){return t.kind==="OverNode"},create(){return i({kind:"OverNode"})},cloneWithOrderByItems(t,e){return i({...t,orderBy:t.orderBy?ze.cloneWithItems(t.orderBy,e):ze.create(e)})},cloneWithPartitionByItems(t,e){return i({...t,partitionBy:t.partitionBy?Fi.cloneWithItems(t.partitionBy,e):Fi.create(e)})}});var ct=i({is(t){return t.kind==="FromNode"},create(t){return i({kind:"FromNode",froms:i(t)})},cloneWithFroms(t,e){return i({...t,froms:i([...t.froms,...e])})}});var zi=i({is(t){return t.kind==="GroupByNode"},create(t){return i({kind:"GroupByNode",items:i(t)})},cloneWithItems(t,e){return i({...t,items:i([...t.items,...e])})}});var Vi=i({is(t){return t.kind==="HavingNode"},create(t){return i({kind:"HavingNode",having:t})},cloneWithOperation(t,e,r){return i({...t,having:e==="And"?ue.create(t.having,r):be.create(t.having,r)})}});var B=i({is(t){return t.kind==="InsertQueryNode"},create(t,e,r){return i({kind:"InsertQueryNode",into:t,...e&&{with:e},replace:r})},createWithoutInto(){return i({kind:"InsertQueryNode"})},cloneWith(t,e){return i({...t,...e})}});var Dr=i({is(t){return t.kind==="ListNode"},create(t){return i({kind:"ListNode",items:i(t)})}});var qe=i({is(t){return t.kind==="UpdateQueryNode"},create(t,e){return i({kind:"UpdateQueryNode",table:t.length===1?t[0]:Dr.create(t),...e&&{with:e}})},createWithoutTable(){return i({kind:"UpdateQueryNode"})},cloneWithFromItems(t,e){return i({...t,from:t.from?ct.cloneWithFroms(t.from,e):ct.create(e)})},cloneWithUpdates(t,e){return i({...t,updates:t.updates?i([...t.updates,...e]):e})},cloneWithLimit(t,e){return i({...t,limit:e})}});var ur=i({is(t){return t.kind==="UsingNode"},create(t){return i({kind:"UsingNode",tables:i(t)})},cloneWithTables(t,e){return i({...t,tables:i([...t.tables,...e])})}});var et=i({is(t){return t.kind==="DeleteQueryNode"},create(t,e){return i({kind:"DeleteQueryNode",from:ct.create(t),...e&&{with:e}})},cloneWithOrderByItems:(t,e)=>u.cloneWithOrderByItems(t,e),cloneWithoutOrderBy:t=>u.cloneWithoutOrderBy(t),cloneWithLimit(t,e){return i({...t,limit:e})},cloneWithoutLimit(t){return i({...t,limit:void 0})},cloneWithUsing(t,e){return i({...t,using:t.using!==void 0?ur.cloneWithTables(t.using,e):ur.create(e)})}});var H=i({is(t){return t.kind==="WhereNode"},create(t){return i({kind:"WhereNode",where:t})},cloneWithOperation(t,e,r){return i({...t,where:e==="And"?ue.create(t.where,r):be.create(t.where,r)})}});var Ui=i({is(t){return t.kind==="ReturningNode"},create(t){return i({kind:"ReturningNode",selections:i(t)})},cloneWithSelections(t,e){return i({...t,selections:t.selections?i([...t.selections,...e]):i(e)})}});var tn=i({is(t){return t.kind==="ExplainNode"},create(t,e){return i({kind:"ExplainNode",format:t,options:e})}});var we=i({is(t){return t.kind==="WhenNode"},create(t){return i({kind:"WhenNode",condition:t})},cloneWithResult(t,e){return i({...t,result:e})}});var fe=i({is(t){return t.kind==="MergeQueryNode"},create(t,e){return i({kind:"MergeQueryNode",into:t,...e&&{with:e}})},cloneWithUsing(t,e){return i({...t,using:e})},cloneWithWhen(t,e){return i({...t,whens:t.whens?i([...t.whens,e]):i([e])})},cloneWithThen(t,e){return i({...t,whens:t.whens?i([...t.whens.slice(0,-1),we.cloneWithResult(t.whens[t.whens.length-1],e)]):void 0})}});var Ji=i({is(t){return t.kind==="OutputNode"},create(t){return i({kind:"OutputNode",selections:i(t)})},cloneWithSelections(t,e){return i({...t,selections:t.selections?i([...t.selections,...e]):i(e)})}});var u=i({is(t){return S.is(t)||B.is(t)||qe.is(t)||et.is(t)||fe.is(t)},cloneWithEndModifier(t,e){return i({...t,endModifiers:t.endModifiers?i([...t.endModifiers,e]):i([e])})},cloneWithWhere(t,e){return i({...t,where:t.where?H.cloneWithOperation(t.where,"And",e):H.create(e)})},cloneWithJoin(t,e){return i({...t,joins:t.joins?i([...t.joins,e]):i([e])})},cloneWithReturning(t,e){return i({...t,returning:t.returning?Ui.cloneWithSelections(t.returning,e):Ui.create(e)})},cloneWithoutReturning(t){return i({...t,returning:void 0})},cloneWithoutWhere(t){return i({...t,where:void 0})},cloneWithExplain(t,e,r){return i({...t,explain:tn.create(e,r?.toOperationNode())})},cloneWithTop(t,e){return i({...t,top:e})},cloneWithOutput(t,e){return i({...t,output:t.output?Ji.cloneWithSelections(t.output,e):Ji.create(e)})},cloneWithOrderByItems(t,e){return i({...t,orderBy:t.orderBy?ze.cloneWithItems(t.orderBy,e):ze.create(e)})},cloneWithoutOrderBy(t){return i({...t,orderBy:void 0})}});var S=i({is(t){return t.kind==="SelectQueryNode"},create(t){return i({kind:"SelectQueryNode",...t&&{with:t}})},createFrom(t,e){return i({kind:"SelectQueryNode",from:ct.create(t),...e&&{with:e}})},cloneWithSelections(t,e){return i({...t,selections:t.selections?i([...t.selections,...e]):i(e)})},cloneWithDistinctOn(t,e){return i({...t,distinctOn:t.distinctOn?i([...t.distinctOn,...e]):i(e)})},cloneWithFrontModifier(t,e){return i({...t,frontModifiers:t.frontModifiers?i([...t.frontModifiers,e]):i([e])})},cloneWithOrderByItems:(t,e)=>u.cloneWithOrderByItems(t,e),cloneWithGroupByItems(t,e){return i({...t,groupBy:t.groupBy?zi.cloneWithItems(t.groupBy,e):zi.create(e)})},cloneWithLimit(t,e){return i({...t,limit:e})},cloneWithOffset(t,e){return i({...t,offset:e})},cloneWithFetch(t,e){return i({...t,fetch:e})},cloneWithHaving(t,e){return i({...t,having:t.having?Vi.cloneWithOperation(t.having,"And",e):Vi.create(e)})},cloneWithSetOperations(t,e){return i({...t,setOperations:t.setOperations?i([...t.setOperations,...e]):i([...e])})},cloneWithoutSelections(t){return i({...t,selections:[]})},cloneWithoutLimit(t){return i({...t,limit:void 0})},cloneWithoutOffset(t){return i({...t,offset:void 0})},cloneWithoutOrderBy:t=>u.cloneWithoutOrderBy(t),cloneWithoutGroupBy(t){return i({...t,groupBy:void 0})}});var Rr=class t{#e;constructor(e){this.#e=i(e)}on(...e){return new t({...this.#e,joinNode:Ce.cloneWithOn(this.#e.joinNode,A(e))})}onRef(e,r,o){return new t({...this.#e,joinNode:Ce.cloneWithOn(this.#e.joinNode,J(e,r,o))})}onTrue(){return new t({...this.#e,joinNode:Ce.cloneWithOn(this.#e.joinNode,T.createWithSql("true"))})}$call(e){return e(this)}toOperationNode(){return this.#e.joinNode}};var rn=i({is(t){return t.kind==="PartitionByItemNode"},create(t){return i({kind:"PartitionByItemNode",partitionBy:t})}});function on(t){return Fe(t).map(rn.create)}var Ir=class t{#e;constructor(e){this.#e=i(e)}orderBy(...e){return new t({overNode:ar.cloneWithOrderByItems(this.#e.overNode,me(e))})}clearOrderBy(){return new t({overNode:u.cloneWithoutOrderBy(this.#e.overNode)})}partitionBy(e){return new t({overNode:ar.cloneWithPartitionByItems(this.#e.overNode,on(e))})}$call(e){return e(this)}toOperationNode(){return this.#e.overNode}};var Et=i({is(t){return t.kind==="SelectionNode"},create(t){return i({kind:"SelectionNode",selection:t})},createSelectAll(){return i({kind:"SelectionNode",selection:Ct.create()})},createSelectAllFromTable(t){return i({kind:"SelectionNode",selection:Wt.createSelectAll(t)})}});function $(t){return q(t)?$(t(oe())):Z(t)?t.map(e=>nn(e)):[nn(t)]}function nn(t){return L(t)?Et.create(Xo(t)):Wr(t)?Et.create(t.toOperationNode()):Et.create(Lr(t))}function j(t){return t?Array.isArray(t)?t.map(sn):[sn(t)]:[Et.createSelectAll()]}function sn(t){if(L(t))return Et.createSelectAllFromTable(b(t));throw new Error(`invalid value selectAll expression: ${JSON.stringify(t)}`)}var an=i({is(t){return t.kind==="ValuesNode"},create(t){return i({kind:"ValuesNode",values:i(t)})}});var un=i({is(t){return t.kind==="DefaultInsertValueNode"},create(){return i({kind:"DefaultInsertValueNode"})}});function qr(t){let e=q(t)?t(oe()):t,r=Z(e)?e:i([e]);return as(r)}function as(t){let e=us(t);return[i([...e.keys()].map(O.create)),an.create(t.map(r=>ds(r,e)))]}function us(t){let e=new Map;for(let r of t){let o=Object.keys(r);for(let n of o)!e.has(n)&&r[n]!==void 0&&e.set(n,e.size)}return e}function ds(t,e){let r=Object.keys(t),o=Array.from({length:e.size}),n=!1,s=r.length;for(let c of r){let g=e.get(c);if(pe(g)){s--;continue}let w=t[c];(pe(w)||$e(w))&&(n=!0),o[g]=w}if(spe(g)?c:k(g)))}return kr.create(o)}var ji=i({is(t){return t.kind==="ColumnUpdateNode"},create(t,e){return i({kind:"ColumnUpdateNode",column:t,value:e})}});function dn(...t){return t.length===2?[ji.create(G(t[0]),k(t[1]))]:dr(t[0])}function dr(t){let e=q(t)?t(oe()):t;return Object.entries(e).filter(([r,o])=>o!==void 0).map(([r,o])=>ji.create(O.create(r),k(o)))}var pn=i({is(t){return t.kind==="OnDuplicateKeyNode"},create(t){return i({kind:"OnDuplicateKeyNode",updates:t})}});var Br=class{insertId;numInsertedOrUpdatedRows;constructor(e,r){this.insertId=e,this.numInsertedOrUpdatedRows=r}};var ge=class extends Error{node;constructor(e){super("no result"),this.node=e}};function Be(t){return Object.prototype.hasOwnProperty.call(t,"prototype")}var ne=i({is(t){return t.kind==="OnConflictNode"},create(){return i({kind:"OnConflictNode"})},cloneWith(t,e){return i({...t,...e})},cloneWithIndexWhere(t,e){return i({...t,indexWhere:t.indexWhere?H.cloneWithOperation(t.indexWhere,"And",e):H.create(e)})},cloneWithIndexOrWhere(t,e){return i({...t,indexWhere:t.indexWhere?H.cloneWithOperation(t.indexWhere,"Or",e):H.create(e)})},cloneWithUpdateWhere(t,e){return i({...t,updateWhere:t.updateWhere?H.cloneWithOperation(t.updateWhere,"And",e):H.create(e)})},cloneWithUpdateOrWhere(t,e){return i({...t,updateWhere:t.updateWhere?H.cloneWithOperation(t.updateWhere,"Or",e):H.create(e)})},cloneWithoutIndexWhere(t){return i({...t,indexWhere:void 0})},cloneWithoutUpdateWhere(t){return i({...t,updateWhere:void 0})}});var Mr=class t{#e;constructor(e){this.#e=i(e)}column(e){let r=O.create(e);return new t({...this.#e,onConflictNode:ne.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?i([...this.#e.onConflictNode.columns,r]):i([r])})})}columns(e){let r=e.map(O.create);return new t({...this.#e,onConflictNode:ne.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?i([...this.#e.onConflictNode.columns,...r]):i(r)})})}constraint(e){return new t({...this.#e,onConflictNode:ne.cloneWith(this.#e.onConflictNode,{constraint:l.create(e)})})}expression(e){return new t({...this.#e,onConflictNode:ne.cloneWith(this.#e.onConflictNode,{indexExpression:e.toOperationNode()})})}where(...e){return new t({...this.#e,onConflictNode:ne.cloneWithIndexWhere(this.#e.onConflictNode,A(e))})}whereRef(e,r,o){return new t({...this.#e,onConflictNode:ne.cloneWithIndexWhere(this.#e.onConflictNode,J(e,r,o))})}clearWhere(){return new t({...this.#e,onConflictNode:ne.cloneWithoutIndexWhere(this.#e.onConflictNode)})}doNothing(){return new Ki({...this.#e,onConflictNode:ne.cloneWith(this.#e.onConflictNode,{doNothing:!0})})}doUpdateSet(e){return new Gi({...this.#e,onConflictNode:ne.cloneWith(this.#e.onConflictNode,{updates:dr(e)})})}$call(e){return e(this)}},Ki=class{#e;constructor(e){this.#e=i(e)}toOperationNode(){return this.#e.onConflictNode}},Gi=class t{#e;constructor(e){this.#e=i(e)}where(...e){return new t({...this.#e,onConflictNode:ne.cloneWithUpdateWhere(this.#e.onConflictNode,A(e))})}whereRef(e,r,o){return new t({...this.#e,onConflictNode:ne.cloneWithUpdateWhere(this.#e.onConflictNode,J(e,r,o))})}clearWhere(){return new t({...this.#e,onConflictNode:ne.cloneWithoutUpdateWhere(this.#e.onConflictNode)})}$call(e){return e(this)}toOperationNode(){return this.#e.onConflictNode}};var hn=i({is(t){return t.kind==="TopNode"},create(t,e){return i({kind:"TopNode",expression:t,modifiers:e})}});function Se(t,e){if(!Ye(t)&&!bt(t))throw new Error(`Invalid top expression: ${t}`);if(!pe(e)&&!ps(e))throw new Error(`Invalid top modifiers: ${e}`);return hn.create(t,e)}function ps(t){return t==="percent"||t==="with ties"||t==="percent with ties"}var mt=i({is(t){return t.kind==="OrActionNode"},create(t){return i({kind:"OrActionNode",action:t})}});var pr=class t{#e;constructor(e){this.#e=i(e)}values(e){let[r,o]=qr(e);return new t({...this.#e,queryNode:B.cloneWith(this.#e.queryNode,{columns:r,values:o})})}columns(e){return new t({...this.#e,queryNode:B.cloneWith(this.#e.queryNode,{columns:i(e.map(O.create))})})}expression(e){return new t({...this.#e,queryNode:B.cloneWith(this.#e.queryNode,{values:de(e)})})}defaultValues(){return new t({...this.#e,queryNode:B.cloneWith(this.#e.queryNode,{defaultValues:!0})})}modifyEnd(e){return new t({...this.#e,queryNode:u.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}ignore(){return new t({...this.#e,queryNode:B.cloneWith(this.#e.queryNode,{orAction:mt.create("ignore")})})}orIgnore(){return new t({...this.#e,queryNode:B.cloneWith(this.#e.queryNode,{orAction:mt.create("ignore")})})}orAbort(){return new t({...this.#e,queryNode:B.cloneWith(this.#e.queryNode,{orAction:mt.create("abort")})})}orFail(){return new t({...this.#e,queryNode:B.cloneWith(this.#e.queryNode,{orAction:mt.create("fail")})})}orReplace(){return new t({...this.#e,queryNode:B.cloneWith(this.#e.queryNode,{orAction:mt.create("replace")})})}orRollback(){return new t({...this.#e,queryNode:B.cloneWith(this.#e.queryNode,{orAction:mt.create("rollback")})})}top(e,r){return new t({...this.#e,queryNode:u.cloneWithTop(this.#e.queryNode,Se(e,r))})}onConflict(e){return new t({...this.#e,queryNode:B.cloneWith(this.#e.queryNode,{onConflict:e(new Mr({onConflictNode:ne.create()})).toOperationNode()})})}onDuplicateKeyUpdate(e){return new t({...this.#e,queryNode:B.cloneWith(this.#e.queryNode,{onDuplicateKey:pn.create(dr(e))})})}returning(e){return new t({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,$(e))})}returningAll(){return new t({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,j())})}output(e){return new t({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,$(e))})}outputAll(e){return new t({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,j(e))})}clearReturning(){return new t({...this.#e,queryNode:u.cloneWithoutReturning(this.#e.queryNode)})}$call(e){return e(this)}$if(e,r){return e?r(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(),r=await this.#e.executor.executeQuery(e),{adapter:o}=this.#e.executor,n=e.query;return n.returning&&o.supportsReturning||n.output&&o.supportsOutput?r.rows:[new Br(r.insertId,r.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=ge){let r=await this.executeTakeFirst();if(r===void 0)throw Be(e)?new e(this.toOperationNode()):e(this.toOperationNode());return r}async*stream(e=100){let r=this.compile(),o=this.#e.executor.stream(r,e);for await(let n of o)yield*n.rows}async explain(e,r){return await new t({...this.#e,queryNode:u.cloneWithExplain(this.#e.queryNode,e,r)}).execute()}};var Pr=class{numDeletedRows;constructor(e){this.numDeletedRows=e}};var At=i({is(t){return t.kind==="LimitNode"},create(t){return i({kind:"LimitNode",limit:t})}});var Qr=class t{#e;constructor(e){this.#e=i(e)}where(...e){return new t({...this.#e,queryNode:u.cloneWithWhere(this.#e.queryNode,A(e))})}whereRef(e,r,o){return new t({...this.#e,queryNode:u.cloneWithWhere(this.#e.queryNode,J(e,r,o))})}clearWhere(){return new t({...this.#e,queryNode:u.cloneWithoutWhere(this.#e.queryNode)})}top(e,r){return new t({...this.#e,queryNode:u.cloneWithTop(this.#e.queryNode,Se(e,r))})}using(e){return new t({...this.#e,queryNode:et.cloneWithUsing(this.#e.queryNode,Te(e))})}innerJoin(...e){return this.#t("InnerJoin",e)}leftJoin(...e){return this.#t("LeftJoin",e)}rightJoin(...e){return this.#t("RightJoin",e)}fullJoin(...e){return this.#t("FullJoin",e)}#t(e,r){return new t({...this.#e,queryNode:u.cloneWithJoin(this.#e.queryNode,tt(e,r))})}returning(e){return new t({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,$(e))})}returningAll(e){return new t({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,j(e))})}output(e){return new t({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,$(e))})}outputAll(e){return new t({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,j(e))})}clearReturning(){return new t({...this.#e,queryNode:u.cloneWithoutReturning(this.#e.queryNode)})}clearLimit(){return new t({...this.#e,queryNode:et.cloneWithoutLimit(this.#e.queryNode)})}orderBy(...e){return new t({...this.#e,queryNode:u.cloneWithOrderByItems(this.#e.queryNode,me(e))})}clearOrderBy(){return new t({...this.#e,queryNode:u.cloneWithoutOrderBy(this.#e.queryNode)})}limit(e){return new t({...this.#e,queryNode:et.cloneWithLimit(this.#e.queryNode,At.create(k(e)))})}modifyEnd(e){return new t({...this.#e,queryNode:u.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}$call(e){return e(this)}$if(e,r){return e?r(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(),r=await this.#e.executor.executeQuery(e),{adapter:o}=this.#e.executor,n=e.query;return n.returning&&o.supportsReturning||n.output&&o.supportsOutput?r.rows:[new Pr(r.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=ge){let r=await this.executeTakeFirst();if(r===void 0)throw Be(e)?new e(this.toOperationNode()):e(this.toOperationNode());return r}async*stream(e=100){let r=this.compile(),o=this.#e.executor.stream(r,e);for await(let n of o)yield*n.rows}async explain(e,r){return await new t({...this.#e,queryNode:u.cloneWithExplain(this.#e.queryNode,e,r)}).execute()}};var $r=class{numUpdatedRows;numChangedRows;constructor(e,r){this.numUpdatedRows=e,this.numChangedRows=r}};var Dt=class t{#e;constructor(e){this.#e=i(e)}where(...e){return new t({...this.#e,queryNode:u.cloneWithWhere(this.#e.queryNode,A(e))})}whereRef(e,r,o){return new t({...this.#e,queryNode:u.cloneWithWhere(this.#e.queryNode,J(e,r,o))})}clearWhere(){return new t({...this.#e,queryNode:u.cloneWithoutWhere(this.#e.queryNode)})}top(e,r){return new t({...this.#e,queryNode:u.cloneWithTop(this.#e.queryNode,Se(e,r))})}from(e){return new t({...this.#e,queryNode:qe.cloneWithFromItems(this.#e.queryNode,Te(e))})}innerJoin(...e){return this.#t("InnerJoin",e)}leftJoin(...e){return this.#t("LeftJoin",e)}rightJoin(...e){return this.#t("RightJoin",e)}fullJoin(...e){return this.#t("FullJoin",e)}#t(e,r){return new t({...this.#e,queryNode:u.cloneWithJoin(this.#e.queryNode,tt(e,r))})}orderBy(...e){return new t({...this.#e,queryNode:u.cloneWithOrderByItems(this.#e.queryNode,me(e))})}clearOrderBy(){return new t({...this.#e,queryNode:u.cloneWithoutOrderBy(this.#e.queryNode)})}limit(e){return new t({...this.#e,queryNode:qe.cloneWithLimit(this.#e.queryNode,At.create(k(e)))})}set(...e){return new t({...this.#e,queryNode:qe.cloneWithUpdates(this.#e.queryNode,dn(...e))})}returning(e){return new t({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,$(e))})}returningAll(e){return new t({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,j(e))})}output(e){return new t({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,$(e))})}outputAll(e){return new t({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,j(e))})}modifyEnd(e){return new t({...this.#e,queryNode:u.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}clearReturning(){return new t({...this.#e,queryNode:u.cloneWithoutReturning(this.#e.queryNode)})}$call(e){return e(this)}$if(e,r){return e?r(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(),r=await this.#e.executor.executeQuery(e),{adapter:o}=this.#e.executor,n=e.query;return n.returning&&o.supportsReturning||n.output&&o.supportsOutput?r.rows:[new $r(r.numAffectedRows??BigInt(0),r.numChangedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=ge){let r=await this.executeTakeFirst();if(r===void 0)throw Be(e)?new e(this.toOperationNode()):e(this.toOperationNode());return r}async*stream(e=100){let r=this.compile(),o=this.#e.executor.stream(r,e);for await(let n of o)yield*n.rows}async explain(e,r){return await new t({...this.#e,queryNode:u.cloneWithExplain(this.#e.queryNode,e,r)}).execute()}};var Hi=i({is(t){return t.kind==="CommonTableExpressionNameNode"},create(t,e){return i({kind:"CommonTableExpressionNameNode",table:ae.create(t),columns:e?i(e.map(O.create)):void 0})}});var Rt=i({is(t){return t.kind==="CommonTableExpressionNode"},create(t,e){return i({kind:"CommonTableExpressionNode",name:t,expression:e})},cloneWith(t,e){return i({...t,...e})}});var Fr=class t{#e;constructor(e){this.#e=i(e)}materialized(){return new t({...this.#e,node:Rt.cloneWith(this.#e.node,{materialized:!0})})}notMaterialized(){return new t({...this.#e,node:Rt.cloneWith(this.#e.node,{materialized:!1})})}toOperationNode(){return this.#e.node}};function Yi(t,e){let r=e(mn()).toOperationNode();return q(t)?t(hs(r)).toOperationNode():Rt.create(cn(t),r)}function hs(t){return e=>new Fr({node:Rt.create(cn(e),t)})}function cn(t){if(t.includes("(")){let e=t.split(/[\(\)]/),r=e[0],o=e[1].split(",").map(n=>n.trim());return Hi.create(r,o)}else return Hi.create(t)}var hr=i({is(t){return t.kind==="WithNode"},create(t,e){return i({kind:"WithNode",expressions:i([t]),...e})},cloneWithExpression(t,e){return i({...t,expressions:i([...t.expressions,e])})}});var ln=["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 fn(t){let e="";for(let r=0;rthis.transformNode(o,r)))}transformSelectQuery(e,r){return{kind:"SelectQueryNode",from:this.transformNode(e.from,r),selections:this.transformNodeList(e.selections,r),distinctOn:this.transformNodeList(e.distinctOn,r),joins:this.transformNodeList(e.joins,r),groupBy:this.transformNode(e.groupBy,r),orderBy:this.transformNode(e.orderBy,r),where:this.transformNode(e.where,r),frontModifiers:this.transformNodeList(e.frontModifiers,r),endModifiers:this.transformNodeList(e.endModifiers,r),limit:this.transformNode(e.limit,r),offset:this.transformNode(e.offset,r),with:this.transformNode(e.with,r),having:this.transformNode(e.having,r),explain:this.transformNode(e.explain,r),setOperations:this.transformNodeList(e.setOperations,r),fetch:this.transformNode(e.fetch,r),top:this.transformNode(e.top,r)}}transformSelection(e,r){return{kind:"SelectionNode",selection:this.transformNode(e.selection,r)}}transformColumn(e,r){return{kind:"ColumnNode",column:this.transformNode(e.column,r)}}transformAlias(e,r){return{kind:"AliasNode",node:this.transformNode(e.node,r),alias:this.transformNode(e.alias,r)}}transformTable(e,r){return{kind:"TableNode",table:this.transformNode(e.table,r)}}transformFrom(e,r){return{kind:"FromNode",froms:this.transformNodeList(e.froms,r)}}transformReference(e,r){return{kind:"ReferenceNode",column:this.transformNode(e.column,r),table:this.transformNode(e.table,r)}}transformAnd(e,r){return{kind:"AndNode",left:this.transformNode(e.left,r),right:this.transformNode(e.right,r)}}transformOr(e,r){return{kind:"OrNode",left:this.transformNode(e.left,r),right:this.transformNode(e.right,r)}}transformValueList(e,r){return{kind:"ValueListNode",values:this.transformNodeList(e.values,r)}}transformParens(e,r){return{kind:"ParensNode",node:this.transformNode(e.node,r)}}transformJoin(e,r){return{kind:"JoinNode",joinType:e.joinType,table:this.transformNode(e.table,r),on:this.transformNode(e.on,r)}}transformRaw(e,r){return{kind:"RawNode",sqlFragments:i([...e.sqlFragments]),parameters:this.transformNodeList(e.parameters,r)}}transformWhere(e,r){return{kind:"WhereNode",where:this.transformNode(e.where,r)}}transformInsertQuery(e,r){return{kind:"InsertQueryNode",into:this.transformNode(e.into,r),columns:this.transformNodeList(e.columns,r),values:this.transformNode(e.values,r),returning:this.transformNode(e.returning,r),onConflict:this.transformNode(e.onConflict,r),onDuplicateKey:this.transformNode(e.onDuplicateKey,r),endModifiers:this.transformNodeList(e.endModifiers,r),with:this.transformNode(e.with,r),ignore:e.ignore,orAction:this.transformNode(e.orAction,r),replace:e.replace,explain:this.transformNode(e.explain,r),defaultValues:e.defaultValues,top:this.transformNode(e.top,r),output:this.transformNode(e.output,r)}}transformValues(e,r){return{kind:"ValuesNode",values:this.transformNodeList(e.values,r)}}transformDeleteQuery(e,r){return{kind:"DeleteQueryNode",from:this.transformNode(e.from,r),using:this.transformNode(e.using,r),joins:this.transformNodeList(e.joins,r),where:this.transformNode(e.where,r),returning:this.transformNode(e.returning,r),endModifiers:this.transformNodeList(e.endModifiers,r),with:this.transformNode(e.with,r),orderBy:this.transformNode(e.orderBy,r),limit:this.transformNode(e.limit,r),explain:this.transformNode(e.explain,r),top:this.transformNode(e.top,r),output:this.transformNode(e.output,r)}}transformReturning(e,r){return{kind:"ReturningNode",selections:this.transformNodeList(e.selections,r)}}transformCreateTable(e,r){return{kind:"CreateTableNode",table:this.transformNode(e.table,r),columns:this.transformNodeList(e.columns,r),constraints:this.transformNodeList(e.constraints,r),temporary:e.temporary,ifNotExists:e.ifNotExists,onCommit:e.onCommit,frontModifiers:this.transformNodeList(e.frontModifiers,r),endModifiers:this.transformNodeList(e.endModifiers,r),selectQuery:this.transformNode(e.selectQuery,r)}}transformColumnDefinition(e,r){return{kind:"ColumnDefinitionNode",column:this.transformNode(e.column,r),dataType:this.transformNode(e.dataType,r),references:this.transformNode(e.references,r),primaryKey:e.primaryKey,autoIncrement:e.autoIncrement,unique:e.unique,notNull:e.notNull,unsigned:e.unsigned,defaultTo:this.transformNode(e.defaultTo,r),check:this.transformNode(e.check,r),generated:this.transformNode(e.generated,r),frontModifiers:this.transformNodeList(e.frontModifiers,r),endModifiers:this.transformNodeList(e.endModifiers,r),nullsNotDistinct:e.nullsNotDistinct,identity:e.identity,ifNotExists:e.ifNotExists}}transformAddColumn(e,r){return{kind:"AddColumnNode",column:this.transformNode(e.column,r)}}transformDropTable(e,r){return{kind:"DropTableNode",table:this.transformNode(e.table,r),ifExists:e.ifExists,cascade:e.cascade}}transformOrderBy(e,r){return{kind:"OrderByNode",items:this.transformNodeList(e.items,r)}}transformOrderByItem(e,r){return{kind:"OrderByItemNode",orderBy:this.transformNode(e.orderBy,r),direction:this.transformNode(e.direction,r),collation:this.transformNode(e.collation,r),nulls:e.nulls}}transformGroupBy(e,r){return{kind:"GroupByNode",items:this.transformNodeList(e.items,r)}}transformGroupByItem(e,r){return{kind:"GroupByItemNode",groupBy:this.transformNode(e.groupBy,r)}}transformUpdateQuery(e,r){return{kind:"UpdateQueryNode",table:this.transformNode(e.table,r),from:this.transformNode(e.from,r),joins:this.transformNodeList(e.joins,r),where:this.transformNode(e.where,r),updates:this.transformNodeList(e.updates,r),returning:this.transformNode(e.returning,r),endModifiers:this.transformNodeList(e.endModifiers,r),with:this.transformNode(e.with,r),explain:this.transformNode(e.explain,r),limit:this.transformNode(e.limit,r),top:this.transformNode(e.top,r),output:this.transformNode(e.output,r),orderBy:this.transformNode(e.orderBy,r)}}transformColumnUpdate(e,r){return{kind:"ColumnUpdateNode",column:this.transformNode(e.column,r),value:this.transformNode(e.value,r)}}transformLimit(e,r){return{kind:"LimitNode",limit:this.transformNode(e.limit,r)}}transformOffset(e,r){return{kind:"OffsetNode",offset:this.transformNode(e.offset,r)}}transformOnConflict(e,r){return{kind:"OnConflictNode",columns:this.transformNodeList(e.columns,r),constraint:this.transformNode(e.constraint,r),indexExpression:this.transformNode(e.indexExpression,r),indexWhere:this.transformNode(e.indexWhere,r),updates:this.transformNodeList(e.updates,r),updateWhere:this.transformNode(e.updateWhere,r),doNothing:e.doNothing}}transformOnDuplicateKey(e,r){return{kind:"OnDuplicateKeyNode",updates:this.transformNodeList(e.updates,r)}}transformCreateIndex(e,r){return{kind:"CreateIndexNode",name:this.transformNode(e.name,r),table:this.transformNode(e.table,r),columns:this.transformNodeList(e.columns,r),unique:e.unique,using:this.transformNode(e.using,r),ifNotExists:e.ifNotExists,where:this.transformNode(e.where,r),nullsNotDistinct:e.nullsNotDistinct}}transformList(e,r){return{kind:"ListNode",items:this.transformNodeList(e.items,r)}}transformDropIndex(e,r){return{kind:"DropIndexNode",name:this.transformNode(e.name,r),table:this.transformNode(e.table,r),ifExists:e.ifExists,cascade:e.cascade}}transformPrimaryKeyConstraint(e,r){return{kind:"PrimaryKeyConstraintNode",columns:this.transformNodeList(e.columns,r),name:this.transformNode(e.name,r),deferrable:e.deferrable,initiallyDeferred:e.initiallyDeferred}}transformUniqueConstraint(e,r){return{kind:"UniqueConstraintNode",columns:this.transformNodeList(e.columns,r),name:this.transformNode(e.name,r),nullsNotDistinct:e.nullsNotDistinct,deferrable:e.deferrable,initiallyDeferred:e.initiallyDeferred}}transformForeignKeyConstraint(e,r){return{kind:"ForeignKeyConstraintNode",columns:this.transformNodeList(e.columns,r),references:this.transformNode(e.references,r),name:this.transformNode(e.name,r),onDelete:e.onDelete,onUpdate:e.onUpdate,deferrable:e.deferrable,initiallyDeferred:e.initiallyDeferred}}transformSetOperation(e,r){return{kind:"SetOperationNode",operator:e.operator,expression:this.transformNode(e.expression,r),all:e.all}}transformReferences(e,r){return{kind:"ReferencesNode",table:this.transformNode(e.table,r),columns:this.transformNodeList(e.columns,r),onDelete:e.onDelete,onUpdate:e.onUpdate}}transformCheckConstraint(e,r){return{kind:"CheckConstraintNode",expression:this.transformNode(e.expression,r),name:this.transformNode(e.name,r)}}transformWith(e,r){return{kind:"WithNode",expressions:this.transformNodeList(e.expressions,r),recursive:e.recursive}}transformCommonTableExpression(e,r){return{kind:"CommonTableExpressionNode",name:this.transformNode(e.name,r),materialized:e.materialized,expression:this.transformNode(e.expression,r)}}transformCommonTableExpressionName(e,r){return{kind:"CommonTableExpressionNameNode",table:this.transformNode(e.table,r),columns:this.transformNodeList(e.columns,r)}}transformHaving(e,r){return{kind:"HavingNode",having:this.transformNode(e.having,r)}}transformCreateSchema(e,r){return{kind:"CreateSchemaNode",schema:this.transformNode(e.schema,r),ifNotExists:e.ifNotExists}}transformDropSchema(e,r){return{kind:"DropSchemaNode",schema:this.transformNode(e.schema,r),ifExists:e.ifExists,cascade:e.cascade}}transformAlterTable(e,r){return{kind:"AlterTableNode",table:this.transformNode(e.table,r),renameTo:this.transformNode(e.renameTo,r),setSchema:this.transformNode(e.setSchema,r),columnAlterations:this.transformNodeList(e.columnAlterations,r),addConstraint:this.transformNode(e.addConstraint,r),dropConstraint:this.transformNode(e.dropConstraint,r),renameConstraint:this.transformNode(e.renameConstraint,r),addIndex:this.transformNode(e.addIndex,r),dropIndex:this.transformNode(e.dropIndex,r)}}transformDropColumn(e,r){return{kind:"DropColumnNode",column:this.transformNode(e.column,r)}}transformRenameColumn(e,r){return{kind:"RenameColumnNode",column:this.transformNode(e.column,r),renameTo:this.transformNode(e.renameTo,r)}}transformAlterColumn(e,r){return{kind:"AlterColumnNode",column:this.transformNode(e.column,r),dataType:this.transformNode(e.dataType,r),dataTypeExpression:this.transformNode(e.dataTypeExpression,r),setDefault:this.transformNode(e.setDefault,r),dropDefault:e.dropDefault,setNotNull:e.setNotNull,dropNotNull:e.dropNotNull}}transformModifyColumn(e,r){return{kind:"ModifyColumnNode",column:this.transformNode(e.column,r)}}transformAddConstraint(e,r){return{kind:"AddConstraintNode",constraint:this.transformNode(e.constraint,r)}}transformDropConstraint(e,r){return{kind:"DropConstraintNode",constraintName:this.transformNode(e.constraintName,r),ifExists:e.ifExists,modifier:e.modifier}}transformRenameConstraint(e,r){return{kind:"RenameConstraintNode",oldName:this.transformNode(e.oldName,r),newName:this.transformNode(e.newName,r)}}transformCreateView(e,r){return{kind:"CreateViewNode",name:this.transformNode(e.name,r),temporary:e.temporary,orReplace:e.orReplace,ifNotExists:e.ifNotExists,materialized:e.materialized,columns:this.transformNodeList(e.columns,r),as:this.transformNode(e.as,r)}}transformRefreshMaterializedView(e,r){return{kind:"RefreshMaterializedViewNode",name:this.transformNode(e.name,r),concurrently:e.concurrently,withNoData:e.withNoData}}transformDropView(e,r){return{kind:"DropViewNode",name:this.transformNode(e.name,r),ifExists:e.ifExists,materialized:e.materialized,cascade:e.cascade}}transformGenerated(e,r){return{kind:"GeneratedNode",byDefault:e.byDefault,always:e.always,identity:e.identity,stored:e.stored,expression:this.transformNode(e.expression,r)}}transformDefaultValue(e,r){return{kind:"DefaultValueNode",defaultValue:this.transformNode(e.defaultValue,r)}}transformOn(e,r){return{kind:"OnNode",on:this.transformNode(e.on,r)}}transformSelectModifier(e,r){return{kind:"SelectModifierNode",modifier:e.modifier,rawModifier:this.transformNode(e.rawModifier,r),of:this.transformNodeList(e.of,r)}}transformCreateType(e,r){return{kind:"CreateTypeNode",name:this.transformNode(e.name,r),enum:this.transformNode(e.enum,r)}}transformDropType(e,r){return{kind:"DropTypeNode",name:this.transformNode(e.name,r),ifExists:e.ifExists}}transformExplain(e,r){return{kind:"ExplainNode",format:e.format,options:this.transformNode(e.options,r)}}transformSchemableIdentifier(e,r){return{kind:"SchemableIdentifierNode",schema:this.transformNode(e.schema,r),identifier:this.transformNode(e.identifier,r)}}transformAggregateFunction(e,r){return{kind:"AggregateFunctionNode",func:e.func,aggregated:this.transformNodeList(e.aggregated,r),distinct:e.distinct,orderBy:this.transformNode(e.orderBy,r),withinGroup:this.transformNode(e.withinGroup,r),filter:this.transformNode(e.filter,r),over:this.transformNode(e.over,r)}}transformOver(e,r){return{kind:"OverNode",orderBy:this.transformNode(e.orderBy,r),partitionBy:this.transformNode(e.partitionBy,r)}}transformPartitionBy(e,r){return{kind:"PartitionByNode",items:this.transformNodeList(e.items,r)}}transformPartitionByItem(e,r){return{kind:"PartitionByItemNode",partitionBy:this.transformNode(e.partitionBy,r)}}transformBinaryOperation(e,r){return{kind:"BinaryOperationNode",leftOperand:this.transformNode(e.leftOperand,r),operator:this.transformNode(e.operator,r),rightOperand:this.transformNode(e.rightOperand,r)}}transformUnaryOperation(e,r){return{kind:"UnaryOperationNode",operator:this.transformNode(e.operator,r),operand:this.transformNode(e.operand,r)}}transformUsing(e,r){return{kind:"UsingNode",tables:this.transformNodeList(e.tables,r)}}transformFunction(e,r){return{kind:"FunctionNode",func:e.func,arguments:this.transformNodeList(e.arguments,r)}}transformCase(e,r){return{kind:"CaseNode",value:this.transformNode(e.value,r),when:this.transformNodeList(e.when,r),else:this.transformNode(e.else,r),isStatement:e.isStatement}}transformWhen(e,r){return{kind:"WhenNode",condition:this.transformNode(e.condition,r),result:this.transformNode(e.result,r)}}transformJSONReference(e,r){return{kind:"JSONReferenceNode",reference:this.transformNode(e.reference,r),traversal:this.transformNode(e.traversal,r)}}transformJSONPath(e,r){return{kind:"JSONPathNode",inOperator:this.transformNode(e.inOperator,r),pathLegs:this.transformNodeList(e.pathLegs,r)}}transformJSONPathLeg(e,r){return{kind:"JSONPathLegNode",type:e.type,value:e.value}}transformJSONOperatorChain(e,r){return{kind:"JSONOperatorChainNode",operator:this.transformNode(e.operator,r),values:this.transformNodeList(e.values,r)}}transformTuple(e,r){return{kind:"TupleNode",values:this.transformNodeList(e.values,r)}}transformMergeQuery(e,r){return{kind:"MergeQueryNode",into:this.transformNode(e.into,r),using:this.transformNode(e.using,r),whens:this.transformNodeList(e.whens,r),with:this.transformNode(e.with,r),top:this.transformNode(e.top,r),endModifiers:this.transformNodeList(e.endModifiers,r),output:this.transformNode(e.output,r),returning:this.transformNode(e.returning,r)}}transformMatched(e,r){return{kind:"MatchedNode",not:e.not,bySource:e.bySource}}transformAddIndex(e,r){return{kind:"AddIndexNode",name:this.transformNode(e.name,r),columns:this.transformNodeList(e.columns,r),unique:e.unique,using:this.transformNode(e.using,r),ifNotExists:e.ifNotExists}}transformCast(e,r){return{kind:"CastNode",expression:this.transformNode(e.expression,r),dataType:this.transformNode(e.dataType,r)}}transformFetch(e,r){return{kind:"FetchNode",rowCount:this.transformNode(e.rowCount,r),modifier:e.modifier}}transformTop(e,r){return{kind:"TopNode",expression:e.expression,modifiers:e.modifiers}}transformOutput(e,r){return{kind:"OutputNode",selections:this.transformNodeList(e.selections,r)}}transformDataType(e,r){return e}transformSelectAll(e,r){return e}transformIdentifier(e,r){return e}transformValue(e,r){return e}transformPrimitiveValueList(e,r){return e}transformOperator(e,r){return e}transformDefaultInsertValue(e,r){return e}transformOrAction(e,r){return e}transformCollate(e,r){return e}};var ms=i({AlterTableNode:!0,CreateIndexNode:!0,CreateSchemaNode:!0,CreateTableNode:!0,CreateTypeNode:!0,CreateViewNode:!0,RefreshMaterializedViewNode:!0,DeleteQueryNode:!0,DropIndexNode:!0,DropSchemaNode:!0,DropTableNode:!0,DropTypeNode:!0,DropViewNode:!0,InsertQueryNode:!0,RawNode:!0,SelectQueryNode:!0,UpdateQueryNode:!0,MergeQueryNode:!0}),ls={json_agg:!0,to_json:!0},zr=class extends rt{#e;#t=new Set;#r=new Set;constructor(e){super(),this.#e=e}transformNodeImpl(e,r){if(!this.#n(e))return super.transformNodeImpl(e,r);let o=this.#d(e);for(let a of o)this.#r.add(a);let n=this.#a(e);for(let a of n)this.#t.add(a);let s=super.transformNodeImpl(e,r);for(let a of n)this.#t.delete(a);for(let a of o)this.#r.delete(a);return s}transformSchemableIdentifier(e,r){let o=super.transformSchemableIdentifier(e,r);return o.schema||!this.#t.has(e.identifier.name)?o:{...o,schema:l.create(this.#e)}}transformReferences(e,r){let o=super.transformReferences(e,r);return o.table.table.schema?o:{...o,table:ae.createWithSchema(this.#e,o.table.table.identifier.name)}}transformAggregateFunction(e,r){return{...super.transformAggregateFunction({...e,aggregated:[]},r),aggregated:this.#o(e,r,"aggregated")}}transformFunction(e,r){return{...super.transformFunction({...e,arguments:[]},r),arguments:this.#o(e,r,"arguments")}}transformSelectModifier(e,r){return{...super.transformSelectModifier({...e,of:void 0},r),of:e.of?.map(o=>ae.is(o)&&!o.table.schema?{...o,table:this.transformIdentifier(o.table.identifier,r)}:this.transformNode(o,r))}}#o(e,r,o){return ls[e.func]?e[o].map(n=>!ae.is(n)||n.table.schema?this.transformNode(n,r):{...n,table:this.transformIdentifier(n.table.identifier,r)}):this.transformNodeList(e[o],r)}#n(e){return e.kind in ms}#a(e){let r=new Set;if("name"in e&&e.name&&ee.is(e.name)&&this.#s(e.name,r),"from"in e&&e.from)for(let o of e.from.froms)this.#i(o,r);if("into"in e&&e.into&&this.#i(e.into,r),"table"in e&&e.table&&this.#i(e.table,r),"joins"in e&&e.joins)for(let o of e.joins)this.#i(o.table,r);return"using"in e&&e.using&&(Ce.is(e.using)?this.#i(e.using.table,r):this.#i(e.using,r)),r}#d(e){let r=new Set;return"with"in e&&e.with&&this.#u(e.with,r),r}#i(e,r){if(ae.is(e))return this.#s(e.table,r);if(U.is(e)&&ae.is(e.node))return this.#s(e.node.table,r);if(Dr.is(e)){for(let o of e.items)this.#i(o,r);return}if(ur.is(e)){for(let o of e.tables)this.#i(o,r);return}}#s(e,r){let o=e.identifier.name;!this.#t.has(o)&&!this.#r.has(o)&&r.add(o)}#u(e,r){for(let o of e.expressions){let n=o.name.table.table.identifier.name;this.#r.has(n)||r.add(n)}}};var Oe=class{#e;constructor(e){this.#e=new zr(e)}transformQuery(e){return this.#e.transformNode(e.node,e.queryId)}async transformResult(e){return e.result}};var Nn=i({is(t){return t.kind==="MatchedNode"},create(t,e=!1){return i({kind:"MatchedNode",not:t,bySource:e})}});function Zi(t,e,r){return we.create(kt([Nn.create(!t.isMatched,t.bySource),...e&&e.length>0?[e.length===3&&r?J(e[0],e[1],e[2]):A(e)]:[]],"and",!1))}function It(t){return L(t)?T.create([t],[]):D(t)?t.toOperationNode():t}var cr=class{#e;#t;#r;constructor(){this.#e=new Promise((e,r)=>{this.#r=r,this.#t=e})}get promise(){return this.#e}resolve=e=>{this.#t&&this.#t(e)};reject=e=>{this.#r&&this.#r(e)}};async function Vr(t){let e=new cr,r=new cr;return t.provideConnection(async o=>(e.resolve(o),await r.promise)).catch(o=>e.reject(o)),i({connection:await e.promise,release:r.resolve})}var fs=i([]),Lt=class{#e;constructor(e=fs){this.#e=e}get plugins(){return this.#e}transformQuery(e,r){for(let o of this.#e){let n=o.transformQuery({node:e,queryId:r});if(n.kind===e.kind)e=n;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 ${n.kind}`].join(" "))}return e}async executeQuery(e){return await this.provideConnection(async r=>{let o=await r.executeQuery(e);return"numUpdatedOrDeletedRows"in o&&Ie("kysely:warning: outdated driver/plugin detected! `QueryResult.numUpdatedOrDeletedRows` has been replaced with `QueryResult.numAffectedRows`."),await this.#t(o,e.queryId)})}async*stream(e,r){let{connection:o,release:n}=await Vr(this);try{for await(let s of o.streamQuery(e,r))yield await this.#t(s,e.queryId)}finally{n()}}async#t(e,r){for(let o of this.#e)e=await o.transformResult({result:e,queryId:r});return e}};var _i=class t extends Lt{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([])}},it=new _i;var Ur=class{numChangedRows;constructor(e){this.numChangedRows=e}};var Jr=class t{#e;constructor(e){this.#e=i(e)}modifyEnd(e){return new t({...this.#e,queryNode:u.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}top(e,r){return new t({...this.#e,queryNode:u.cloneWithTop(this.#e.queryNode,Se(e,r))})}using(...e){return new ot({...this.#e,queryNode:fe.cloneWithUsing(this.#e.queryNode,tt("Using",e))})}returning(e){return new t({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,$(e))})}returningAll(e){return new t({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,j(e))})}output(e){return new t({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,$(e))})}outputAll(e){return new t({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,j(e))})}},ot=class t{#e;constructor(e){this.#e=i(e)}modifyEnd(e){return new t({...this.#e,queryNode:u.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}top(e,r){return new t({...this.#e,queryNode:u.cloneWithTop(this.#e.queryNode,Se(e,r))})}whenMatched(){return this.#t([])}whenMatchedAnd(...e){return this.#t(e)}whenMatchedAndRef(e,r,o){return this.#t([e,r,o],!0)}#t(e,r){return new jr({...this.#e,queryNode:fe.cloneWithWhen(this.#e.queryNode,Zi({isMatched:!0},e,r))})}whenNotMatched(){return this.#r([])}whenNotMatchedAnd(...e){return this.#r(e)}whenNotMatchedAndRef(e,r,o){return this.#r([e,r,o],!0)}whenNotMatchedBySource(){return this.#r([],!1,!0)}whenNotMatchedBySourceAnd(...e){return this.#r(e,!1,!0)}whenNotMatchedBySourceAndRef(e,r,o){return this.#r([e,r,o],!0,!0)}returning(e){return new t({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,$(e))})}returningAll(e){return new t({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,j(e))})}output(e){return new t({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,$(e))})}outputAll(e){return new t({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,j(e))})}#r(e,r=!1,o=!1){let n={...this.#e,queryNode:fe.cloneWithWhen(this.#e.queryNode,Zi({isMatched:!1,bySource:o},e,r))},s=o?jr:eo;return new s(n)}$call(e){return e(this)}$if(e,r){return e?r(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(),r=await this.#e.executor.executeQuery(e),{adapter:o}=this.#e.executor,n=e.query;return n.returning&&o.supportsReturning||n.output&&o.supportsOutput?r.rows:[new Ur(r.numAffectedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=ge){let r=await this.executeTakeFirst();if(r===void 0)throw Be(e)?new e(this.toOperationNode()):e(this.toOperationNode());return r}},jr=class{#e;constructor(e){this.#e=i(e)}thenDelete(){return new ot({...this.#e,queryNode:fe.cloneWithThen(this.#e.queryNode,It("delete"))})}thenDoNothing(){return new ot({...this.#e,queryNode:fe.cloneWithThen(this.#e.queryNode,It("do nothing"))})}thenUpdate(e){return new ot({...this.#e,queryNode:fe.cloneWithThen(this.#e.queryNode,It(e(new Dt({queryId:this.#e.queryId,executor:it,queryNode:qe.createWithoutTable()}))))})}thenUpdateSet(...e){return this.thenUpdate(r=>r.set(...e))}},eo=class{#e;constructor(e){this.#e=i(e)}thenDoNothing(){return new ot({...this.#e,queryNode:fe.cloneWithThen(this.#e.queryNode,It("do nothing"))})}thenInsertValues(e){let[r,o]=qr(e);return new ot({...this.#e,queryNode:fe.cloneWithThen(this.#e.queryNode,It(B.cloneWith(B.createWithoutInto(),{columns:r,values:o})))})}};var qt=class t{#e;constructor(e){this.#e=i(e)}selectFrom(e){return mr({queryId:C(),executor:this.#e.executor,queryNode:S.createFrom(Te(e),this.#e.withNode)})}selectNoFrom(e){return mr({queryId:C(),executor:this.#e.executor,queryNode:S.cloneWithSelections(S.create(this.#e.withNode),$(e))})}insertInto(e){return new pr({queryId:C(),executor:this.#e.executor,queryNode:B.create(b(e),this.#e.withNode)})}replaceInto(e){return new pr({queryId:C(),executor:this.#e.executor,queryNode:B.create(b(e),this.#e.withNode,!0)})}deleteFrom(e){return new Qr({queryId:C(),executor:this.#e.executor,queryNode:et.create(Te(e),this.#e.withNode)})}updateTable(e){return new Dt({queryId:C(),executor:this.#e.executor,queryNode:qe.create(Te(e),this.#e.withNode)})}mergeInto(e){return new Jr({queryId:C(),executor:this.#e.executor,queryNode:fe.create(to(e),this.#e.withNode)})}with(e,r){let o=Yi(e,r);return new t({...this.#e,withNode:this.#e.withNode?hr.cloneWithExpression(this.#e.withNode,o):hr.create(o)})}withRecursive(e,r){let o=Yi(e,r);return new t({...this.#e,withNode:this.#e.withNode?hr.cloneWithExpression(this.#e.withNode,o):hr.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 mn(){return new qt({executor:it})}function yn(t,e){return new Rr({joinNode:Ce.create(t,lt(e))})}function xn(){return new Ir({overNode:ar.create()})}function tt(t,e){if(e.length===3)return ys(t,e[0],e[1],e[2]);if(e.length===2)return Ns(t,e[0],e[1]);if(e.length===1)return xs(t,e[0]);throw new Error("not implemented")}function Ns(t,e,r){return r(yn(t,e)).toOperationNode()}function ys(t,e,r,o){return Ce.createWithOn(t,lt(e),J(r,"=",o))}function xs(t,e){return Ce.create(t,lt(e))}var wn=i({is(t){return t.kind==="OffsetNode"},create(t){return i({kind:"OffsetNode",offset:t})}});var gn=i({is(t){return t.kind==="GroupByItemNode"},create(t){return i({kind:"GroupByItemNode",groupBy:t})}});function On(t){return t=q(t)?t(oe()):t,Fe(t).map(gn.create)}var Kr=i({is(t){return t.kind==="SetOperationNode"},create(t,e,r){return i({kind:"SetOperationNode",operator:t,expression:e,all:r})}});function ft(t,e,r){return q(e)&&(e=e(Gr())),Z(e)||(e=[e]),e.map(o=>Kr.create(t,de(o),r))}var W=class t{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new lr(this,e)}or(...e){return new ro(be.create(this.#e,A(e)))}and(...e){return new io(ue.create(this.#e,A(e)))}$castTo(){return new t(this.#e)}$notNull(){return new t(this.#e)}toOperationNode(){return this.#e}},lr=class{#e;#t;constructor(e,r){this.#e=e,this.#t=r}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return U.create(this.#e.toOperationNode(),D(this.#t)?this.#t.toOperationNode():l.create(this.#t))}},ro=class t{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new lr(this,e)}or(...e){return new t(be.create(this.#e,A(e)))}$castTo(){return new t(this.#e)}toOperationNode(){return le.create(this.#e)}},io=class t{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new lr(this,e)}and(...e){return new t(ue.create(this.#e,A(e)))}$castTo(){return new t(this.#e)}toOperationNode(){return le.create(this.#e)}};var vn=i({is(t){return t.kind==="FetchNode"},create(t,e){return{kind:"FetchNode",rowCount:P.create(t),modifier:e}}});function bn(t,e){if(!Ye(t)&&!bt(t))throw new Error(`Invalid fetch row count: ${t}`);if(!ws(e))throw new Error(`Invalid fetch modifier: ${e}`);return vn.create(t,e)}function ws(t){return t==="only"||t==="with ties"}var oo=class t{#e;constructor(e){this.#e=i(e)}get expressionType(){}get isSelectQueryBuilder(){return!0}where(...e){return new t({...this.#e,queryNode:u.cloneWithWhere(this.#e.queryNode,A(e))})}whereRef(e,r,o){return new t({...this.#e,queryNode:u.cloneWithWhere(this.#e.queryNode,J(e,r,o))})}having(...e){return new t({...this.#e,queryNode:S.cloneWithHaving(this.#e.queryNode,A(e))})}havingRef(e,r,o){return new t({...this.#e,queryNode:S.cloneWithHaving(this.#e.queryNode,J(e,r,o))})}select(e){return new t({...this.#e,queryNode:S.cloneWithSelections(this.#e.queryNode,$(e))})}distinctOn(e){return new t({...this.#e,queryNode:S.cloneWithDistinctOn(this.#e.queryNode,Fe(e))})}modifyFront(e){return new t({...this.#e,queryNode:S.cloneWithFrontModifier(this.#e.queryNode,Re.createWithExpression(e.toOperationNode()))})}modifyEnd(e){return new t({...this.#e,queryNode:u.cloneWithEndModifier(this.#e.queryNode,Re.createWithExpression(e.toOperationNode()))})}distinct(){return new t({...this.#e,queryNode:S.cloneWithFrontModifier(this.#e.queryNode,Re.create("Distinct"))})}forUpdate(e){return new t({...this.#e,queryNode:u.cloneWithEndModifier(this.#e.queryNode,Re.create("ForUpdate",e?ir(e).map(b):void 0))})}forShare(e){return new t({...this.#e,queryNode:u.cloneWithEndModifier(this.#e.queryNode,Re.create("ForShare",e?ir(e).map(b):void 0))})}forKeyShare(e){return new t({...this.#e,queryNode:u.cloneWithEndModifier(this.#e.queryNode,Re.create("ForKeyShare",e?ir(e).map(b):void 0))})}forNoKeyUpdate(e){return new t({...this.#e,queryNode:u.cloneWithEndModifier(this.#e.queryNode,Re.create("ForNoKeyUpdate",e?ir(e).map(b):void 0))})}skipLocked(){return new t({...this.#e,queryNode:u.cloneWithEndModifier(this.#e.queryNode,Re.create("SkipLocked"))})}noWait(){return new t({...this.#e,queryNode:u.cloneWithEndModifier(this.#e.queryNode,Re.create("NoWait"))})}selectAll(e){return new t({...this.#e,queryNode:S.cloneWithSelections(this.#e.queryNode,j(e))})}innerJoin(...e){return this.#t("InnerJoin",e)}leftJoin(...e){return this.#t("LeftJoin",e)}rightJoin(...e){return this.#t("RightJoin",e)}fullJoin(...e){return this.#t("FullJoin",e)}crossJoin(...e){return this.#t("CrossJoin",e)}innerJoinLateral(...e){return this.#t("LateralInnerJoin",e)}leftJoinLateral(...e){return this.#t("LateralLeftJoin",e)}crossJoinLateral(...e){return this.#t("LateralCrossJoin",e)}crossApply(...e){return this.#t("CrossApply",e)}outerApply(...e){return this.#t("OuterApply",e)}#t(e,r){return new t({...this.#e,queryNode:u.cloneWithJoin(this.#e.queryNode,tt(e,r))})}orderBy(...e){return new t({...this.#e,queryNode:u.cloneWithOrderByItems(this.#e.queryNode,me(e))})}groupBy(e){return new t({...this.#e,queryNode:S.cloneWithGroupByItems(this.#e.queryNode,On(e))})}limit(e){return new t({...this.#e,queryNode:S.cloneWithLimit(this.#e.queryNode,At.create(k(e)))})}offset(e){return new t({...this.#e,queryNode:S.cloneWithOffset(this.#e.queryNode,wn.create(k(e)))})}fetch(e,r="only"){return new t({...this.#e,queryNode:S.cloneWithFetch(this.#e.queryNode,bn(e,r))})}top(e,r){return new t({...this.#e,queryNode:u.cloneWithTop(this.#e.queryNode,Se(e,r))})}union(e){return new t({...this.#e,queryNode:S.cloneWithSetOperations(this.#e.queryNode,ft("union",e,!1))})}unionAll(e){return new t({...this.#e,queryNode:S.cloneWithSetOperations(this.#e.queryNode,ft("union",e,!0))})}intersect(e){return new t({...this.#e,queryNode:S.cloneWithSetOperations(this.#e.queryNode,ft("intersect",e,!1))})}intersectAll(e){return new t({...this.#e,queryNode:S.cloneWithSetOperations(this.#e.queryNode,ft("intersect",e,!0))})}except(e){return new t({...this.#e,queryNode:S.cloneWithSetOperations(this.#e.queryNode,ft("except",e,!1))})}exceptAll(e){return new t({...this.#e,queryNode:S.cloneWithSetOperations(this.#e.queryNode,ft("except",e,!0))})}as(e){return new no(this,e)}clearSelect(){return new t({...this.#e,queryNode:S.cloneWithoutSelections(this.#e.queryNode)})}clearWhere(){return new t({...this.#e,queryNode:u.cloneWithoutWhere(this.#e.queryNode)})}clearLimit(){return new t({...this.#e,queryNode:S.cloneWithoutLimit(this.#e.queryNode)})}clearOffset(){return new t({...this.#e,queryNode:S.cloneWithoutOffset(this.#e.queryNode)})}clearOrderBy(){return new t({...this.#e,queryNode:u.cloneWithoutOrderBy(this.#e.queryNode)})}clearGroupBy(){return new t({...this.#e,queryNode:S.cloneWithoutGroupBy(this.#e.queryNode)})}$call(e){return e(this)}$if(e,r){return e?r(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())}$asScalar(){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)).rows}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=ge){let r=await this.executeTakeFirst();if(r===void 0)throw Be(e)?new e(this.toOperationNode()):e(this.toOperationNode());return r}async*stream(e=100){let r=this.compile(),o=this.#e.executor.stream(r,e);for await(let n of o)yield*n.rows}async explain(e,r){return await new t({...this.#e,queryNode:u.cloneWithExplain(this.#e.queryNode,e,r)}).execute()}};function mr(t){return new oo(t)}var no=class{#e;#t;constructor(e,r){this.#e=e,this.#t=r}get expression(){return this.#e}get alias(){return this.#t}get isAliasedSelectQueryBuilder(){return!0}toOperationNode(){return U.create(this.#e.toOperationNode(),l.create(this.#t))}};var Me=i({is(t){return t.kind==="AggregateFunctionNode"},create(t,e=[]){return i({kind:"AggregateFunctionNode",func:t,aggregated:e})},cloneWithDistinct(t){return i({...t,distinct:!0})},cloneWithOrderBy(t,e,r=!1){let o=r?"withinGroup":"orderBy";return i({...t,[o]:t[o]?ze.cloneWithItems(t[o],e):ze.create(e)})},cloneWithFilter(t,e){return i({...t,filter:t.filter?H.cloneWithOperation(t.filter,"And",e):H.create(e)})},cloneWithOrFilter(t,e){return i({...t,filter:t.filter?H.cloneWithOperation(t.filter,"Or",e):H.create(e)})},cloneWithOver(t,e){return i({...t,over:e})}});var so=i({is(t){return t.kind==="FunctionNode"},create(t,e){return i({kind:"FunctionNode",func:t,arguments:e})}});var Bt=class t{#e;constructor(e){this.#e=i(e)}get expressionType(){}as(e){return new ao(this,e)}distinct(){return new t({...this.#e,aggregateFunctionNode:Me.cloneWithDistinct(this.#e.aggregateFunctionNode)})}orderBy(...e){return new t({...this.#e,aggregateFunctionNode:u.cloneWithOrderByItems(this.#e.aggregateFunctionNode,me(e))})}clearOrderBy(){return new t({...this.#e,aggregateFunctionNode:u.cloneWithoutOrderBy(this.#e.aggregateFunctionNode)})}withinGroupOrderBy(...e){return new t({...this.#e,aggregateFunctionNode:Me.cloneWithOrderBy(this.#e.aggregateFunctionNode,me(e),!0)})}filterWhere(...e){return new t({...this.#e,aggregateFunctionNode:Me.cloneWithFilter(this.#e.aggregateFunctionNode,A(e))})}filterWhereRef(e,r,o){return new t({...this.#e,aggregateFunctionNode:Me.cloneWithFilter(this.#e.aggregateFunctionNode,J(e,r,o))})}over(e){let r=xn();return new t({...this.#e,aggregateFunctionNode:Me.cloneWithOver(this.#e.aggregateFunctionNode,(e?e(r):r).toOperationNode())})}$call(e){return e(this)}$castTo(){return new t(this.#e)}$notNull(){return new t(this.#e)}toOperationNode(){return this.#e.aggregateFunctionNode}},ao=class{#e;#t;constructor(e,r){this.#e=e,this.#t=r}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return U.create(this.#e.toOperationNode(),l.create(this.#t))}};function Hr(){let t=(r,o)=>new W(so.create(r,Fe(o??[]))),e=(r,o)=>new Bt({aggregateFunctionNode:Me.create(r,o?Fe(o):void 0)});return Object.assign(t,{agg:e,avg(r){return e("avg",[r])},coalesce(...r){return t("coalesce",r)},count(r){return e("count",[r])},countAll(r){return new Bt({aggregateFunctionNode:Me.create("count",j(r))})},max(r){return e("max",[r])},min(r){return e("min",[r])},sum(r){return e("sum",[r])},any(r){return t("any",[r])},jsonAgg(r){return new Bt({aggregateFunctionNode:Me.create("json_agg",[L(r)?b(r):r.toOperationNode()])})},toJson(r){return new W(so.create("to_json",[L(r)?b(r):r.toOperationNode()]))}})}var Cn=i({is(t){return t.kind==="UnaryOperationNode"},create(t,e){return i({kind:"UnaryOperationNode",operator:t,operand:e})}});function Wn(t,e){return Cn.create(he.create(t),G(e))}var Ne=i({is(t){return t.kind==="CaseNode"},create(t){return i({kind:"CaseNode",value:t})},cloneWithWhen(t,e){return i({...t,when:i(t.when?[...t.when,e]:[e])})},cloneWithThen(t,e){return i({...t,when:t.when?i([...t.when.slice(0,-1),we.cloneWithResult(t.when[t.when.length-1],e)]):void 0})},cloneWith(t,e){return i({...t,...e})}});var Mt=class{#e;constructor(e){this.#e=i(e)}when(...e){return new Yr({...this.#e,node:Ne.cloneWithWhen(this.#e.node,we.create(A(e)))})}},Yr=class{#e;constructor(e){this.#e=i(e)}then(e){return new uo({...this.#e,node:Ne.cloneWithThen(this.#e.node,Er(e)?sr(e):k(e))})}},uo=class{#e;constructor(e){this.#e=i(e)}when(...e){return new Yr({...this.#e,node:Ne.cloneWithWhen(this.#e.node,we.create(A(e)))})}else(e){return new po({...this.#e,node:Ne.cloneWith(this.#e.node,{else:Er(e)?sr(e):k(e)})})}end(){return new W(Ne.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new W(Ne.cloneWith(this.#e.node,{isStatement:!0}))}},po=class{#e;constructor(e){this.#e=i(e)}end(){return new W(Ne.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new W(Ne.cloneWith(this.#e.node,{isStatement:!0}))}};var ho=i({is(t){return t.kind==="JSONPathLegNode"},create(t,e){return i({kind:"JSONPathLegNode",type:t,value:e})}});var Pt=class{#e;constructor(e){this.#e=e}at(e){return this.#t("ArrayLocation",e)}key(e){return this.#t("Member",e)}#t(e,r){return St.is(this.#e)?new Xr(St.cloneWithTraversal(this.#e,_e.is(this.#e.traversal)?_e.cloneWithLeg(this.#e.traversal,ho.create(e,r)):Tr.cloneWithValue(this.#e.traversal,P.createImmediate(r)))):new Xr(_e.cloneWithLeg(this.#e,ho.create(e,r)))}},Xr=class t extends Pt{#e;constructor(e){super(e),this.#e=e}get expressionType(){}as(e){return new co(this,e)}$castTo(){return new t(this.#e)}$notNull(){return new t(this.#e)}toOperationNode(){return this.#e}},co=class{#e;#t;constructor(e,r){this.#e=e,this.#t=r}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return U.create(this.#e.toOperationNode(),D(this.#t)?this.#t.toOperationNode():l.create(this.#t))}};var mo=i({is(t){return t.kind==="TupleNode"},create(t){return i({kind:"TupleNode",values:i(t)})}});var gs=["varchar","char","text","integer","int2","int4","int8","smallint","bigint","boolean","real","double precision","float4","float8","decimal","numeric","binary","bytea","date","datetime","time","timetz","timestamp","timestamptz","serial","bigserial","uuid","json","jsonb","blob","varbinary","int4range","int4multirange","int8range","int8multirange","numrange","nummultirange","tsrange","tsmultirange","tstzrange","tstzmultirange","daterange","datemultirange"],Os=[/^varchar\(\d+\)$/,/^char\(\d+\)$/,/^decimal\(\d+, \d+\)$/,/^numeric\(\d+, \d+\)$/,/^binary\(\d+\)$/,/^datetime\(\d+\)$/,/^time\(\d+\)$/,/^timetz\(\d+\)$/,/^timestamp\(\d+\)$/,/^timestamptz\(\d+\)$/,/^varbinary\(\d+\)$/],Sn=i({is(t){return t.kind==="DataTypeNode"},create(t){return i({kind:"DataTypeNode",dataType:t})}});function Tn(t){return!!(gs.includes(t)||Os.some(e=>e.test(t)))}function ke(t){if(D(t))return t.toOperationNode();if(Tn(t))return Sn.create(t);throw new Error(`invalid column data type ${JSON.stringify(t)}`)}var kn=i({is(t){return t.kind==="CastNode"},create(t,e){return i({kind:"CastNode",expression:t,dataType:e})}});function Gr(t=it){function e(n,s,a){return new W(Ar(n,s,a))}function r(n,s){return new W(Wn(n,s))}let o=Object.assign(e,{fn:void 0,eb:void 0,selectFrom(n){return mr({queryId:C(),executor:t,queryNode:S.createFrom(Te(n))})},case(n){return new Mt({node:Ne.create(pe(n)?void 0:G(n))})},ref(n,s){return pe(s)?new W(ce(n)):new Pt(Yo(n,s))},jsonPath(){return new Pt(_e.create())},table(n){return new W(b(n))},val(n){return new W(k(n))},refTuple(...n){return new W(mo.create(n.map(G)))},tuple(...n){return new W(mo.create(n.map(k)))},lit(n){return new W(sr(n))},unary:r,not(n){return r("not",n)},exists(n){return r("exists",n)},neg(n){return r("-",n)},between(n,s,a){return new W(Ze.create(G(n),he.create("between"),ue.create(k(s),k(a))))},betweenSymmetric(n,s,a){return new W(Ze.create(G(n),he.create("between symmetric"),ue.create(k(s),k(a))))},and(n){return Z(n)?new W(kt(n,"and")):new W($i(n,"and"))},or(n){return Z(n)?new W(kt(n,"or")):new W($i(n,"or"))},parens(...n){let s=A(n);return le.is(s)?new W(s):new W(le.create(s))},cast(n,s){return new W(kn.create(G(n),ke(s)))},withSchema(n){return Gr(t.withPluginAtFront(new Oe(n)))}});return o.fn=Hr(),o.eb=o,o}function oe(t){return Gr()}function de(t){if(D(t))return t.toOperationNode();if(q(t))return t(oe()).toOperationNode();throw new Error(`invalid expression: ${JSON.stringify(t)}`)}function Lr(t){if(D(t))return t.toOperationNode();if(q(t))return t(oe()).toOperationNode();throw new Error(`invalid aliased expression: ${JSON.stringify(t)}`)}function $e(t){return vr(t)||Uo(t)||q(t)}var Zr=class{#e;get table(){return this.#e}constructor(e){this.#e=e}as(e){return new lo(this.#e,e)}},lo=class{#e;#t;get table(){return this.#e}get alias(){return this.#t}constructor(e,r){this.#e=e,this.#t=r}toOperationNode(){return U.create(b(this.#e),l.create(this.#t))}};function En(t){return K(t)&&D(t)&&L(t.table)&&L(t.alias)}function Te(t){return Z(t)?t.map(e=>lt(e)):[lt(t)]}function lt(t){return L(t)?to(t):En(t)?t.toOperationNode():Lr(t)}function to(t){let e=" as ";if(t.includes(e)){let[r,o]=t.split(e).map(An);return U.create(b(r),l.create(o))}else return b(t)}function b(t){if(t.includes(".")){let[r,o]=t.split(".").map(An);return ae.createWithSchema(r,o)}else return ae.create(t)}function An(t){return t.trim()}var fo=i({is(t){return t.kind==="AddColumnNode"},create(t){return i({kind:"AddColumnNode",column:t})}});var R=i({is(t){return t.kind==="ColumnDefinitionNode"},create(t,e){return i({kind:"ColumnDefinitionNode",column:O.create(t),dataType:e})},cloneWithFrontModifier(t,e){return i({...t,frontModifiers:t.frontModifiers?i([...t.frontModifiers,e]):[e]})},cloneWithEndModifier(t,e){return i({...t,endModifiers:t.endModifiers?i([...t.endModifiers,e]):[e]})},cloneWith(t,e){return i({...t,...e})}});var No=i({is(t){return t.kind==="DropColumnNode"},create(t){return i({kind:"DropColumnNode",column:O.create(t)})}});var yo=i({is(t){return t.kind==="RenameColumnNode"},create(t,e){return i({kind:"RenameColumnNode",column:O.create(t),renameTo:O.create(e)})}});var Qt=i({is(t){return t.kind==="CheckConstraintNode"},create(t,e){return i({kind:"CheckConstraintNode",expression:t,name:e?l.create(e):void 0})}});var Dn=["no action","restrict","cascade","set null","set default"],$t=i({is(t){return t.kind==="ReferencesNode"},create(t,e){return i({kind:"ReferencesNode",table:t,columns:i([...e])})},cloneWithOnDelete(t,e){return i({...t,onDelete:e})},cloneWithOnUpdate(t,e){return i({...t,onUpdate:e})}});function _r(t){return D(t)?t.toOperationNode():P.createImmediate(t)}var fr=i({is(t){return t.kind==="GeneratedNode"},create(t){return i({kind:"GeneratedNode",...t})},createWithExpression(t){return i({kind:"GeneratedNode",always:!0,expression:t})},cloneWith(t,e){return i({...t,...e})}});var Rn=i({is(t){return t.kind==="DefaultValueNode"},create(t){return i({kind:"DefaultValueNode",defaultValue:t})}});function Ft(t){if(Dn.includes(t))return t;throw new Error(`invalid OnModifyForeignAction ${t}`)}var Ve=class t{#e;constructor(e){this.#e=e}autoIncrement(){return new t(R.cloneWith(this.#e,{autoIncrement:!0}))}identity(){return new t(R.cloneWith(this.#e,{identity:!0}))}primaryKey(){return new t(R.cloneWith(this.#e,{primaryKey:!0}))}references(e){let r=ce(e);if(!r.table||Ct.is(r.column))throw new Error(`invalid call references('${e}'). The reference must have format table.column or schema.table.column`);return new t(R.cloneWith(this.#e,{references:$t.create(r.table,[r.column])}))}onDelete(e){if(!this.#e.references)throw new Error("on delete constraint can only be added for foreign keys");return new t(R.cloneWith(this.#e,{references:$t.cloneWithOnDelete(this.#e.references,Ft(e))}))}onUpdate(e){if(!this.#e.references)throw new Error("on update constraint can only be added for foreign keys");return new t(R.cloneWith(this.#e,{references:$t.cloneWithOnUpdate(this.#e.references,Ft(e))}))}unique(){return new t(R.cloneWith(this.#e,{unique:!0}))}notNull(){return new t(R.cloneWith(this.#e,{notNull:!0}))}unsigned(){return new t(R.cloneWith(this.#e,{unsigned:!0}))}defaultTo(e){return new t(R.cloneWith(this.#e,{defaultTo:Rn.create(_r(e))}))}check(e){return new t(R.cloneWith(this.#e,{check:Qt.create(e.toOperationNode())}))}generatedAlwaysAs(e){return new t(R.cloneWith(this.#e,{generated:fr.createWithExpression(e.toOperationNode())}))}generatedAlwaysAsIdentity(){return new t(R.cloneWith(this.#e,{generated:fr.create({identity:!0,always:!0})}))}generatedByDefaultAsIdentity(){return new t(R.cloneWith(this.#e,{generated:fr.create({identity:!0,byDefault:!0})}))}stored(){if(!this.#e.generated)throw new Error("stored() can only be called after generatedAlwaysAs");return new t(R.cloneWith(this.#e,{generated:fr.cloneWith(this.#e.generated,{stored:!0})}))}modifyFront(e){return new t(R.cloneWithFrontModifier(this.#e,e.toOperationNode()))}nullsNotDistinct(){return new t(R.cloneWith(this.#e,{nullsNotDistinct:!0}))}ifNotExists(){return new t(R.cloneWith(this.#e,{ifNotExists:!0}))}modifyEnd(e){return new t(R.cloneWithEndModifier(this.#e,e.toOperationNode()))}$call(e){return e(this)}toOperationNode(){return this.#e}};var xo=i({is(t){return t.kind==="ModifyColumnNode"},create(t){return i({kind:"ModifyColumnNode",column:t})}});var Ee=i({is(t){return t.kind==="ForeignKeyConstraintNode"},create(t,e,r,o){return i({kind:"ForeignKeyConstraintNode",columns:t,references:$t.create(e,r),name:o?l.create(o):void 0})},cloneWith(t,e){return i({...t,...e})}});var zt=class t{#e;constructor(e){this.#e=e}onDelete(e){return new t(Ee.cloneWith(this.#e,{onDelete:Ft(e)}))}onUpdate(e){return new t(Ee.cloneWith(this.#e,{onUpdate:Ft(e)}))}deferrable(){return new t(Ee.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new t(Ee.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new t(Ee.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new t(Ee.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}};var Vt=i({is(t){return t.kind==="AddConstraintNode"},create(t){return i({kind:"AddConstraintNode",constraint:t})}});var Pe=i({is(t){return t.kind==="UniqueConstraintNode"},create(t,e,r){return i({kind:"UniqueConstraintNode",columns:i(t.map(O.create)),name:e?l.create(e):void 0,nullsNotDistinct:r})},cloneWith(t,e){return i({...t,...e})}});var Ut=i({is(t){return t.kind==="DropConstraintNode"},create(t){return i({kind:"DropConstraintNode",constraintName:l.create(t)})},cloneWith(t,e){return i({...t,...e})}});var Jt=i({is(t){return t.kind==="AlterColumnNode"},create(t,e,r){return i({kind:"AlterColumnNode",column:O.create(t),[e]:r})}});var Nr=class{#e;constructor(e){this.#e=e}setDataType(e){return new Nt(Jt.create(this.#e,"dataType",ke(e)))}setDefault(e){return new Nt(Jt.create(this.#e,"setDefault",_r(e)))}dropDefault(){return new Nt(Jt.create(this.#e,"dropDefault",!0))}setNotNull(){return new Nt(Jt.create(this.#e,"setNotNull",!0))}dropNotNull(){return new Nt(Jt.create(this.#e,"dropNotNull",!0))}$call(e){return e(this)}},Nt=class{#e;constructor(e){this.#e=e}toOperationNode(){return this.#e}};var Ue=class{#e;constructor(e){this.#e=i(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())}};var ei=class t{#e;constructor(e){this.#e=i(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)})}deferrable(){return new t({...this.#e,constraintBuilder:this.#e.constraintBuilder.deferrable()})}notDeferrable(){return new t({...this.#e,constraintBuilder:this.#e.constraintBuilder.notDeferrable()})}initiallyDeferred(){return new t({...this.#e,constraintBuilder:this.#e.constraintBuilder.initiallyDeferred()})}initiallyImmediate(){return new t({...this.#e,constraintBuilder:this.#e.constraintBuilder.initiallyImmediate()})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(v.cloneWithTableProps(this.#e.node,{addConstraint:Vt.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())}};var yr=class t{#e;constructor(e){this.#e=i(e)}ifExists(){return new t({...this.#e,node:v.cloneWithTableProps(this.#e.node,{dropConstraint:Ut.cloneWith(this.#e.node.dropConstraint,{ifExists:!0})})})}cascade(){return new t({...this.#e,node:v.cloneWithTableProps(this.#e.node,{dropConstraint:Ut.cloneWith(this.#e.node.dropConstraint,{modifier:"cascade"})})})}restrict(){return new t({...this.#e,node:v.cloneWithTableProps(this.#e.node,{dropConstraint:Ut.cloneWith(this.#e.node.dropConstraint,{modifier:"restrict"})})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}};var Je=i({is(t){return t.kind==="PrimaryKeyConstraintNode"},create(t,e){return i({kind:"PrimaryKeyConstraintNode",columns:i(t.map(O.create)),name:e?l.create(e):void 0})},cloneWith(t,e){return i({...t,...e})}});var nt=i({is(t){return t.kind==="AddIndexNode"},create(t){return i({kind:"AddIndexNode",name:l.create(t)})},cloneWith(t,e){return i({...t,...e})},cloneWithColumns(t,e){return i({...t,columns:[...t.columns||[],...e]})}});var ti=class t{#e;constructor(e){this.#e=i(e)}unique(){return new t({...this.#e,node:v.cloneWithTableProps(this.#e.node,{addIndex:nt.cloneWith(this.#e.node.addIndex,{unique:!0})})})}column(e){return new t({...this.#e,node:v.cloneWithTableProps(this.#e.node,{addIndex:nt.cloneWithColumns(this.#e.node.addIndex,[Tt(e)])})})}columns(e){return new t({...this.#e,node:v.cloneWithTableProps(this.#e.node,{addIndex:nt.cloneWithColumns(this.#e.node.addIndex,e.map(Tt))})})}expression(e){return new t({...this.#e,node:v.cloneWithTableProps(this.#e.node,{addIndex:nt.cloneWithColumns(this.#e.node.addIndex,[e.toOperationNode()])})})}using(e){return new t({...this.#e,node:v.cloneWithTableProps(this.#e.node,{addIndex:nt.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())}};var jt=class t{#e;constructor(e){this.#e=e}nullsNotDistinct(){return new t(Pe.cloneWith(this.#e,{nullsNotDistinct:!0}))}deferrable(){return new t(Pe.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new t(Pe.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new t(Pe.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new t(Pe.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}};var Kt=class t{#e;constructor(e){this.#e=e}deferrable(){return new t(Je.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new t(Je.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new t(Je.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new t(Je.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}};var Gt=class{#e;constructor(e){this.#e=e}$call(e){return e(this)}toOperationNode(){return this.#e}};var In=i({is(t){return t.kind==="RenameConstraintNode"},create(t,e){return i({kind:"RenameConstraintNode",oldName:l.create(t),newName:l.create(e)})}});var ri=class{#e;constructor(e){this.#e=i(e)}renameTo(e){return new Ue({...this.#e,node:v.cloneWithTableProps(this.#e.node,{renameTo:b(e)})})}setSchema(e){return new Ue({...this.#e,node:v.cloneWithTableProps(this.#e.node,{setSchema:l.create(e)})})}alterColumn(e,r){let o=r(new Nr(e));return new yt({...this.#e,node:v.cloneWithColumnAlteration(this.#e.node,o.toOperationNode())})}dropColumn(e){return new yt({...this.#e,node:v.cloneWithColumnAlteration(this.#e.node,No.create(e))})}renameColumn(e,r){return new yt({...this.#e,node:v.cloneWithColumnAlteration(this.#e.node,yo.create(e,r))})}addColumn(e,r,o=ie){let n=o(new Ve(R.create(e,ke(r))));return new yt({...this.#e,node:v.cloneWithColumnAlteration(this.#e.node,fo.create(n.toOperationNode()))})}modifyColumn(e,r,o=ie){let n=o(new Ve(R.create(e,ke(r))));return new yt({...this.#e,node:v.cloneWithColumnAlteration(this.#e.node,xo.create(n.toOperationNode()))})}addUniqueConstraint(e,r,o=ie){let n=o(new jt(Pe.create(r,e)));return new Ue({...this.#e,node:v.cloneWithTableProps(this.#e.node,{addConstraint:Vt.create(n.toOperationNode())})})}addCheckConstraint(e,r,o=ie){let n=o(new Gt(Qt.create(r.toOperationNode(),e)));return new Ue({...this.#e,node:v.cloneWithTableProps(this.#e.node,{addConstraint:Vt.create(n.toOperationNode())})})}addForeignKeyConstraint(e,r,o,n,s=ie){let a=s(new zt(Ee.create(r.map(O.create),b(o),n.map(O.create),e)));return new ei({...this.#e,constraintBuilder:a})}addPrimaryKeyConstraint(e,r,o=ie){let n=o(new Kt(Je.create(r,e)));return new Ue({...this.#e,node:v.cloneWithTableProps(this.#e.node,{addConstraint:Vt.create(n.toOperationNode())})})}dropConstraint(e){return new yr({...this.#e,node:v.cloneWithTableProps(this.#e.node,{dropConstraint:Ut.create(e)})})}renameConstraint(e,r){return new yr({...this.#e,node:v.cloneWithTableProps(this.#e.node,{renameConstraint:In.create(e,r)})})}addIndex(e){return new ti({...this.#e,node:v.cloneWithTableProps(this.#e.node,{addIndex:nt.create(e)})})}dropIndex(e){return new Ue({...this.#e,node:v.cloneWithTableProps(this.#e.node,{dropIndex:Xe.create(e)})})}$call(e){return e(this)}},yt=class t{#e;constructor(e){this.#e=i(e)}alterColumn(e,r){let o=r(new Nr(e));return new t({...this.#e,node:v.cloneWithColumnAlteration(this.#e.node,o.toOperationNode())})}dropColumn(e){return new t({...this.#e,node:v.cloneWithColumnAlteration(this.#e.node,No.create(e))})}renameColumn(e,r){return new t({...this.#e,node:v.cloneWithColumnAlteration(this.#e.node,yo.create(e,r))})}addColumn(e,r,o=ie){let n=o(new Ve(R.create(e,ke(r))));return new t({...this.#e,node:v.cloneWithColumnAlteration(this.#e.node,fo.create(n.toOperationNode()))})}modifyColumn(e,r,o=ie){let n=o(new Ve(R.create(e,ke(r))));return new t({...this.#e,node:v.cloneWithColumnAlteration(this.#e.node,xo.create(n.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())}};var Ht=class extends rt{transformPrimitiveValueList(e){return Le.create(e.values.map(P.createImmediate))}transformValue(e){return P.createImmediate(e.value)}};var ii=class t{#e;constructor(e){this.#e=i(e)}ifNotExists(){return new t({...this.#e,node:ve.cloneWith(this.#e.node,{ifNotExists:!0})})}unique(){return new t({...this.#e,node:ve.cloneWith(this.#e.node,{unique:!0})})}nullsNotDistinct(){return new t({...this.#e,node:ve.cloneWith(this.#e.node,{nullsNotDistinct:!0})})}on(e){return new t({...this.#e,node:ve.cloneWith(this.#e.node,{table:b(e)})})}column(e){return new t({...this.#e,node:ve.cloneWithColumns(this.#e.node,[Tt(e)])})}columns(e){return new t({...this.#e,node:ve.cloneWithColumns(this.#e.node,e.map(Tt))})}expression(e){return new t({...this.#e,node:ve.cloneWithColumns(this.#e.node,[e.toOperationNode()])})}using(e){return new t({...this.#e,node:ve.cloneWith(this.#e.node,{using:T.createWithSql(e)})})}where(...e){let r=new Ht;return new t({...this.#e,node:u.cloneWithWhere(this.#e.node,r.transformNode(A(e),this.#e.queryId))})}$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())}};var oi=class t{#e;constructor(e){this.#e=i(e)}ifNotExists(){return new t({...this.#e,node:Or.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())}};function Ln(t){if(Vo.includes(t))return t;throw new Error(`invalid OnCommitAction ${t}`)}var ni=class t{#e;constructor(e){this.#e=i(e)}temporary(){return new t({...this.#e,node:_.cloneWith(this.#e.node,{temporary:!0})})}onCommit(e){return new t({...this.#e,node:_.cloneWith(this.#e.node,{onCommit:Ln(e)})})}ifNotExists(){return new t({...this.#e,node:_.cloneWith(this.#e.node,{ifNotExists:!0})})}addColumn(e,r,o=ie){let n=o(new Ve(R.create(e,ke(r))));return new t({...this.#e,node:_.cloneWithColumn(this.#e.node,n.toOperationNode())})}addPrimaryKeyConstraint(e,r,o=ie){let n=o(new Kt(Je.create(r,e)));return new t({...this.#e,node:_.cloneWithConstraint(this.#e.node,n.toOperationNode())})}addUniqueConstraint(e,r,o=ie){let n=o(new jt(Pe.create(r,e)));return new t({...this.#e,node:_.cloneWithConstraint(this.#e.node,n.toOperationNode())})}addCheckConstraint(e,r,o=ie){let n=o(new Gt(Qt.create(r.toOperationNode(),e)));return new t({...this.#e,node:_.cloneWithConstraint(this.#e.node,n.toOperationNode())})}addForeignKeyConstraint(e,r,o,n,s=ie){let a=s(new zt(Ee.create(r.map(O.create),b(o),n.map(O.create),e)));return new t({...this.#e,node:_.cloneWithConstraint(this.#e.node,a.toOperationNode())})}modifyFront(e){return new t({...this.#e,node:_.cloneWithFrontModifier(this.#e.node,e.toOperationNode())})}modifyEnd(e){return new t({...this.#e,node:_.cloneWithEndModifier(this.#e.node,e.toOperationNode())})}as(e){return new t({...this.#e,node:_.cloneWith(this.#e.node,{selectQuery:de(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())}};var si=class t{#e;constructor(e){this.#e=i(e)}on(e){return new t({...this.#e,node:Xe.cloneWith(this.#e.node,{table:b(e)})})}ifExists(){return new t({...this.#e,node:Xe.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:Xe.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())}};var ai=class t{#e;constructor(e){this.#e=i(e)}ifExists(){return new t({...this.#e,node:or.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:or.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())}};var ui=class t{#e;constructor(e){this.#e=i(e)}ifExists(){return new t({...this.#e,node:nr.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:nr.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())}};var Ae=i({is(t){return t.kind==="CreateViewNode"},create(t){return i({kind:"CreateViewNode",name:ee.create(t)})},cloneWith(t,e){return i({...t,...e})}});var di=class{#e=new Ht;transformQuery(e){return this.#e.transformNode(e.node,e.queryId)}transformResult(e){return Promise.resolve(e.result)}};var pi=class t{#e;constructor(e){this.#e=i(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(Mi)})})}as(e){let r=e.withPlugin(new di).toOperationNode();return new t({...this.#e,node:Ae.cloneWith(this.#e.node,{as:r})})}$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())}};var Yt=i({is(t){return t.kind==="DropViewNode"},create(t){return i({kind:"DropViewNode",name:ee.create(t)})},cloneWith(t,e){return i({...t,...e})}});var hi=class t{#e;constructor(e){this.#e=i(e)}materialized(){return new t({...this.#e,node:Yt.cloneWith(this.#e.node,{materialized:!0})})}ifExists(){return new t({...this.#e,node:Yt.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:Yt.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}};var ci=i({is(t){return t.kind==="CreateTypeNode"},create(t){return i({kind:"CreateTypeNode",name:t})},cloneWithEnum(t,e){return i({...t,enum:Le.create(e.map(P.createImmediate))})}});var mi=class t{#e;constructor(e){this.#e=i(e)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}asEnum(e){return new t({...this.#e,node:ci.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())}};var li=i({is(t){return t.kind==="DropTypeNode"},create(t){return i({kind:"DropTypeNode",name:t})},cloneWith(t,e){return i({...t,...e})}});var fi=class t{#e;constructor(e){this.#e=i(e)}ifExists(){return new t({...this.#e,node:li.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())}};function wo(t){if(t.includes(".")){let r=t.split(".").map(vs);if(r.length===2)return ee.createWithSchema(r[0],r[1]);throw new Error(`invalid schemable identifier ${t}`)}else return ee.create(t)}function vs(t){return t.trim()}var Xt=i({is(t){return t.kind==="RefreshMaterializedViewNode"},create(t){return i({kind:"RefreshMaterializedViewNode",name:ee.create(t)})},cloneWith(t,e){return i({...t,...e})}});var Ni=class t{#e;constructor(e){this.#e=i(e)}concurrently(){return new t({...this.#e,node:Xt.cloneWith(this.#e.node,{concurrently:!0,withNoData:!1})})}withData(){return new t({...this.#e,node:Xt.cloneWith(this.#e.node,{withNoData:!1})})}withNoData(){return new t({...this.#e,node:Xt.cloneWith(this.#e.node,{withNoData:!0,concurrently:!1})})}$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())}};var yi=class t{#e;constructor(e){this.#e=e}createTable(e){return new ni({queryId:C(),executor:this.#e,node:_.create(b(e))})}dropTable(e){return new ui({queryId:C(),executor:this.#e,node:nr.create(b(e))})}createIndex(e){return new ii({queryId:C(),executor:this.#e,node:ve.create(e)})}dropIndex(e){return new si({queryId:C(),executor:this.#e,node:Xe.create(e)})}createSchema(e){return new oi({queryId:C(),executor:this.#e,node:Or.create(e)})}dropSchema(e){return new ai({queryId:C(),executor:this.#e,node:or.create(e)})}alterTable(e){return new ri({queryId:C(),executor:this.#e,node:v.create(b(e))})}createView(e){return new pi({queryId:C(),executor:this.#e,node:Ae.create(e)})}refreshMaterializedView(e){return new Ni({queryId:C(),executor:this.#e,node:Xt.create(e)})}dropView(e){return new hi({queryId:C(),executor:this.#e,node:Yt.create(e)})}createType(e){return new mi({queryId:C(),executor:this.#e,node:ci.create(wo(e))})}dropType(e){return new fi({queryId:C(),executor:this.#e,node:li.create(wo(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 xi=class{ref(e){return new Cr(e)}table(e){return new Zr(e)}};var wi=class{#e;constructor(e){this.#e=e}async provideConnection(e){let r=await this.#e.acquireConnection();try{return await e(r)}finally{await this.#e.releaseConnection(r)}}};var gi=class t extends Lt{#e;#t;#r;constructor(e,r,o,n=[]){super(n),this.#e=e,this.#t=r,this.#r=o}get adapter(){return this.#t}compileQuery(e,r){return this.#e.compileQuery(e,r)}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 Oi(){return typeof performance<"u"&&q(performance.now)?performance.now():Date.now()}var vi=class{#e;#t;#r;#o;#n;#a=new WeakSet;constructor(e,r){this.#o=!1,this.#e=e,this.#t=r}async init(){if(this.#n)throw new Error("driver has already been destroyed");this.#r||(this.#r=this.#e.init().then(()=>{this.#o=!0}).catch(e=>(this.#r=void 0,Promise.reject(e)))),await this.#r}async acquireConnection(){if(this.#n)throw new Error("driver has already been destroyed");this.#o||await this.init();let e=await this.#e.acquireConnection();return this.#a.has(e)||(this.#d()&&this.#i(e),this.#a.add(e)),e}async releaseConnection(e){await this.#e.releaseConnection(e)}beginTransaction(e,r){return this.#e.beginTransaction(e,r)}commitTransaction(e){return this.#e.commitTransaction(e)}rollbackTransaction(e){return this.#e.rollbackTransaction(e)}savepoint(e,r,o){if(this.#e.savepoint)return this.#e.savepoint(e,r,o);throw new Error("The `savepoint` method is not supported by this driver")}rollbackToSavepoint(e,r,o){if(this.#e.rollbackToSavepoint)return this.#e.rollbackToSavepoint(e,r,o);throw new Error("The `rollbackToSavepoint` method is not supported by this driver")}releaseSavepoint(e,r,o){if(this.#e.releaseSavepoint)return this.#e.releaseSavepoint(e,r,o);throw new Error("The `releaseSavepoint` method is not supported by this driver")}async destroy(){this.#r&&(await this.#r,this.#n||(this.#n=this.#e.destroy().catch(e=>(this.#n=void 0,Promise.reject(e)))),await this.#n)}#d(){return this.#t.isLevelEnabled("query")||this.#t.isLevelEnabled("error")}#i(e){let r=e.executeQuery,o=e.streamQuery,n=this;e.executeQuery=async s=>{let a,c=Oi();try{return await r.call(e,s)}catch(g){throw a=g,await n.#s(g,s,c),g}finally{a||await n.#u(s,c)}},e.streamQuery=async function*(s,a){let c,g=Oi();try{for await(let w of o.call(e,s,a))yield w}catch(w){throw c=w,await n.#s(w,s,g),w}finally{c||await n.#u(s,g,!0)}}}async#s(e,r,o){await this.#t.error(()=>({level:"error",error:e,query:r,queryDurationMillis:this.#p(o)}))}async#u(e,r,o=!1){await this.#t.query(()=>({level:"query",isStream:o,query:e,queryDurationMillis:this.#p(r)}))}#p(e){return Oi()-e}};var bs=()=>{},Zt=class{#e;#t;constructor(e){this.#e=e}async provideConnection(e){for(;this.#t;)await this.#t.catch(bs);return this.#t=this.#r(e).finally(()=>{this.#t=void 0}),this.#t}async#r(e){return await e(this.#e)}};var Cs=["read only","read write"],Ws=["read uncommitted","read committed","repeatable read","serializable","snapshot"];function go(t){if(t.accessMode&&!Cs.includes(t.accessMode))throw new Error(`invalid transaction access mode ${t.accessMode}`);if(t.isolationLevel&&!Ws.includes(t.isolationLevel))throw new Error(`invalid transaction isolation level ${t.isolationLevel}`)}var Ss=["query","error"],_O=i(Ss),bi=class{#e;#t;constructor(e){q(e)?(this.#t=e,this.#e=i({query:!0,error:!0})):(this.#t=Ts,this.#e=i({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 Ts(t){if(t.level==="query"){let e=`kysely:query:${t.isStream?"stream:":""}`;console.log(`${e} ${t.query.sql}`),console.log(`${e} duration: ${t.queryDurationMillis.toFixed(1)}ms`)}else 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 qn(t){return K(t)&&q(t.compile)}Symbol.asyncDispose??=Symbol("Symbol.asyncDispose");var _t=class t extends qt{#e;constructor(e){let r,o;if(ks(e))r={executor:e.executor},o={...e};else{let n=e.dialect,s=n.createDriver(),a=n.createQueryCompiler(),c=n.createAdapter(),g=new bi(e.log??[]),w=new vi(s,g),te=new wi(w),M=new gi(a,c,te,e.plugins??[]);r={executor:M},o={config:e,executor:M,dialect:n,driver:w}}super(r),this.#e=i(o)}get schema(){return new yi(this.#e.executor)}get dynamic(){return new xi}get introspection(){return this.#e.dialect.createIntrospector(this.withoutPlugins())}case(e){return new Mt({node:Ne.create(pe(e)?void 0:de(e))})}get fn(){return Hr()}transaction(){return new vo({...this.#e})}startTransaction(){return new bo({...this.#e})}connection(){return new Oo({...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,r){r!==void 0&&Ie("Passing `queryId` in `db.executeQuery` is deprecated and will result in a compile-time error in the future.");let o=qn(e)?e.compile():e;return this.getExecutor().executeQuery(o)}async[Symbol.asyncDispose](){await this.destroy()}},Ci=class t extends _t{#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 ks(t){return K(t)&&K(t.config)&&K(t.driver)&&K(t.executor)&&K(t.dialect)}var Oo=class{#e;constructor(e){this.#e=i(e)}async execute(e){return this.#e.executor.provideConnection(async r=>{let o=this.#e.executor.withConnectionProvider(new Zt(r)),n=new _t({...this.#e,executor:o});return await e(n)})}},vo=class t{#e;constructor(e){this.#e=i(e)}setAccessMode(e){return new t({...this.#e,accessMode:e})}setIsolationLevel(e){return new t({...this.#e,isolationLevel:e})}async execute(e){let{isolationLevel:r,accessMode:o,...n}=this.#e,s={isolationLevel:r,accessMode:o};return go(s),this.#e.executor.provideConnection(async a=>{let c=this.#e.executor.withConnectionProvider(new Zt(a)),g=new Ci({...n,executor:c}),w=!1;try{await this.#e.driver.beginTransaction(a,s),w=!0;let te=await e(g);return await this.#e.driver.commitTransaction(a),te}catch(te){throw w&&await this.#e.driver.rollbackTransaction(a),te}})}},bo=class t{#e;constructor(e){this.#e=i(e)}setAccessMode(e){return new t({...this.#e,accessMode:e})}setIsolationLevel(e){return new t({...this.#e,isolationLevel:e})}async execute(){let{isolationLevel:e,accessMode:r,...o}=this.#e,n={isolationLevel:e,accessMode:r};go(n);let s=await Vr(this.#e.executor);return await this.#e.driver.beginTransaction(s.connection,n),new Co({...o,connection:s,executor:this.#e.executor.withConnectionProvider(new Zt(s.connection))})}},Co=class t extends Ci{#e;#t;#r;constructor(e){let r={isCommitted:!1,isRolledBack:!1};e={...e,executor:new Wo(e.executor,r)};let{connection:o,...n}=e;super(n),this.#e=i(e),this.#r=r;let s=C();this.#t=a=>e.executor.compileQuery(a,s)}get isCommitted(){return this.#r.isCommitted}get isRolledBack(){return this.#r.isRolledBack}commit(){return wt(this.#r),new xt(async()=>{await this.#e.driver.commitTransaction(this.#e.connection.connection),this.#r.isCommitted=!0,this.#e.connection.release()})}rollback(){return wt(this.#r),new xt(async()=>{await this.#e.driver.rollbackTransaction(this.#e.connection.connection),this.#r.isRolledBack=!0,this.#e.connection.release()})}savepoint(e){return wt(this.#r),new xt(async()=>(await this.#e.driver.savepoint?.(this.#e.connection.connection,e,this.#t),new t({...this.#e})))}rollbackToSavepoint(e){return wt(this.#r),new xt(async()=>(await this.#e.driver.rollbackToSavepoint?.(this.#e.connection.connection,e,this.#t),new t({...this.#e})))}releaseSavepoint(e){return wt(this.#r),new xt(async()=>(await this.#e.driver.releaseSavepoint?.(this.#e.connection.connection,e,this.#t),new t({...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})}},xt=class{#e;constructor(e){this.#e=e}async execute(){return await this.#e()}};function wt(t){if(t.isCommitted)throw new Error("Transaction is already committed");if(t.isRolledBack)throw new Error("Transaction is already rolled back")}var Wo=class t{#e;#t;constructor(e,r){e instanceof t?this.#e=e.#e:this.#e=e,this.#t=r}get adapter(){return this.#e.adapter}get plugins(){return this.#e.plugins}transformQuery(e,r){return this.#e.transformQuery(e,r)}compileQuery(e,r){return this.#e.compileQuery(e,r)}provideConnection(e){return this.#e.provideConnection(e)}executeQuery(e){return wt(this.#t),this.#e.executeQuery(e)}stream(e,r){return wt(this.#t),this.#e.stream(e,r)}withConnectionProvider(e){return new t(this.#e.withConnectionProvider(e),this.#t)}withPlugin(e){return new t(this.#e.withPlugin(e),this.#t)}withPlugins(e){return new t(this.#e.withPlugins(e),this.#t)}withPluginAtFront(e){return new t(this.#e.withPluginAtFront(e),this.#t)}withoutPlugins(){return new t(this.#e.withoutPlugins(),this.#t)}};var So=class t{#e;constructor(e){this.#e=i(e)}get expressionType(){}get isRawBuilder(){return!0}as(e){return new To(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?i([...this.#e.plugins,e]):i([e])})}toOperationNode(){return this.#r(this.#t())}compile(e){return this.#o(this.#t(e))}async execute(e){let r=this.#t(e);return r.executeQuery(this.#o(r))}#t(e){let r=e!==void 0?e.getExecutor():it;return this.#e.plugins!==void 0?r.withPlugins(this.#e.plugins):r}#r(e){return e.transformQuery(this.#e.rawNode,this.#e.queryId)}#o(e){return e.compileQuery(this.#r(e),this.#e.queryId)}};function je(t){return new So(t)}var To=class{#e;#t;constructor(e,r){this.#e=e,this.#t=r}get expression(){return this.#e}get alias(){return this.#t}get rawBuilder(){return this.#e}toOperationNode(){return U.create(this.#e.toOperationNode(),D(this.#t)?this.#t.toOperationNode():l.create(this.#t))}};var F=Object.assign((t,...e)=>je({queryId:C(),rawNode:T.create(t,e?.map(Bn)??[])}),{ref(t){return je({queryId:C(),rawNode:T.createWithChild(ce(t))})},val(t){return je({queryId:C(),rawNode:T.createWithChild(k(t))})},value(t){return this.val(t)},table(t){return je({queryId:C(),rawNode:T.createWithChild(b(t))})},id(...t){let e=new Array(t.length+1).fill(".");return e[0]="",e[e.length-1]="",je({queryId:C(),rawNode:T.create(e,t.map(l.create))})},lit(t){return je({queryId:C(),rawNode:T.createWithChild(P.createImmediate(t))})},literal(t){return this.lit(t)},raw(t){return je({queryId:C(),rawNode:T.createWithSql(t)})},join(t,e=F`, `){let r=new Array(Math.max(2*t.length-1,0)),o=e.toOperationNode();for(let n=0;n{this.nodeStack.push(e),this.#e[e.kind](e),this.nodeStack.pop()}};var Es=/'/g,st=class extends Wi{#e="";#t=[];get numParameters(){return this.#t.length}compileQuery(e,r){return this.#e="",this.#t=[],this.nodeStack.splice(0,this.nodeStack.length),this.visitNode(e),i({query:e,queryId:r,sql:this.getSql(),parameters:[...this.#t]})}getSql(){return this.#e}visitSelectQuery(e){let r=this.parentNode!==void 0&&!le.is(this.parentNode)&&!B.is(this.parentNode)&&!_.is(this.parentNode)&&!Ae.is(this.parentNode)&&!Kr.is(this.parentNode);this.parentNode===void 0&&e.explain&&(this.visitNode(e.explain),this.append(" ")),r&&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])," ")),r&&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,r=", "){let o=e.length-1;for(let n=0;n<=o;n++)this.visitNode(e[n]),nn&&this.visitNode(o[n])}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.collation&&(this.append(" "),this.visitNode(e.collation)),e.direction&&(this.append(" "),this.visitNode(e.direction)),e.nulls&&(this.append(" nulls "),this.append(e.nulls))}visitGroupBy(e){this.append("group by "),this.compileList(e.items)}visitGroupByItem(e){this.visitNode(e.groupBy)}visitUpdateQuery(e){let r=this.parentNode!==void 0&&!le.is(this.parentNode)&&!T.is(this.parentNode)&&!we.is(this.parentNode);if(this.parentNode===void 0&&e.explain&&(this.visitNode(e.explain),this.append(" ")),r&&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){if(!e.from)throw new Error("Joins in an update query are only supported as a part of a PostgreSQL 'update set from join' query. If you want to create a MySQL 'update join set' query, see https://kysely.dev/docs/examples/update/my-sql-joins");this.append(" "),this.compileList(e.joins," ")}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)),r&&this.append(")"),e.endModifiers?.length&&(this.append(" "),this.compileList(e.endModifiers," "))}visitColumnUpdate(e){this.visitNode(e.column),this.append(" = "),this.visitNode(e.value)}visitLimit(e){this.append("limit "),this.visitNode(e.limit)}visitOffset(e){this.append("offset "),this.visitNode(e.offset)}visitOnConflict(e){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(")"),this.buildDeferrable(e)}buildDeferrable(e){e.deferrable!==void 0&&(e.deferrable?this.append(" deferrable"):this.append(" not deferrable")),e.initiallyDeferred!==void 0&&(e.initiallyDeferred?this.append(" initially deferred"):this.append(" initially immediate"))}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(")"),this.buildDeferrable(e)}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)),this.buildDeferrable(e)}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 "),ht(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.renameConstraint&&this.visitNode(e.renameConstraint),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")}visitRenameConstraint(e){this.append("rename constraint "),this.visitNode(e.oldName),this.append(" to "),this.visitNode(e.newName)}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))}visitRefreshMaterializedView(e){this.append("refresh materialized view "),e.concurrently&&this.append("concurrently "),this.visitNode(e.name),e.withNoData?this.append(" with no data"):this.append(" with data")}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(As[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),e.orderBy&&(this.append(" "),this.visitNode(e.orderBy)),this.append(")"),e.withinGroup&&(this.append(" within group ("),this.visitNode(e.withinGroup),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 he.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 r of e.pathLegs)this.visitNode(r);this.append("'")}visitJSONPathLeg(e){let r=e.type==="ArrayLocation";this.append(r?"[":"."),this.append(String(e.value)),r&&this.append("]")}visitJSONOperatorChain(e){for(let r=0,o=e.values.length;r"),this.visitNode(e.values[r])}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.returning&&(this.append(" "),this.visitNode(e.returning)),e.output&&(this.append(" "),this.visitNode(e.output)),e.endModifiers?.length&&(this.append(" "),this.compileList(e.endModifiers," "))}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}`)}visitOrAction(e){this.append(e.action)}visitCollate(e){this.append("collate "),this.visitNode(e.collation)}append(e){this.#e+=e}appendValue(e){this.addParameter(e),this.append(this.getCurrentParameterPlaceholder())}getLeftIdentifierWrapper(){return'"'}getRightIdentifierWrapper(){return'"'}getCurrentParameterPlaceholder(){return"$"+this.numParameters}getLeftExplainOptionsWrapper(){return"("}getExplainOptionAssignment(){return" "}getExplainOptionsDelimiter(){return", "}getRightExplainOptionsWrapper(){return")"}sanitizeIdentifier(e){let r=this.getLeftIdentifierWrapper(),o=this.getRightIdentifierWrapper(),n="";for(let s of e)n+=s,s===r?n+=r:s===o&&(n+=o);return n}sanitizeStringLiteral(e){return e.replace(Es,"''")}addParameter(e){this.#t.push(e)}appendImmediateValue(e){if(L(e))this.appendStringLiteral(e);else if(Ye(e)||ht(e)||bt(e))this.append(e.toString());else if(vt(e))this.append("null");else if(zo(e))this.appendImmediateValue(e.toISOString());else throw new Error(`invalid immediate value ${e}`)}appendStringLiteral(e){this.append("'"),this.append(this.sanitizeStringLiteral(e)),this.append("'")}sortSelectModifiers(e){return e.sort((r,o)=>r.modifier&&o.modifier?Mn[r.modifier]-Mn[o.modifier]:1),i(e)}compileColumnAlterations(e){this.compileList(e)}announcesNewColumnDataType(){return!0}},As=i({ForKeyShare:"for key share",ForNoKeyUpdate:"for no key update",ForUpdate:"for update",ForShare:"for share",NoWait:"nowait",SkipLocked:"skip locked",Distinct:"distinct"}),Mn=i({ForKeyShare:1,ForNoKeyUpdate:1,ForUpdate:1,ForShare:1,NoWait:2,SkipLocked:2,Distinct:0}),Ds=i({InnerJoin:"inner join",LeftJoin:"left join",RightJoin:"right join",FullJoin:"full join",CrossJoin:"cross join",LateralInnerJoin:"inner join lateral",LateralLeftJoin:"left join lateral",LateralCrossJoin:"cross join lateral",OuterApply:"outer apply",CrossApply:"cross apply",Using:"using"});var Si=class{async init(){}async acquireConnection(){return new ko}async beginTransaction(){}async commitTransaction(){}async rollbackTransaction(){}async releaseConnection(){}async destroy(){}async releaseSavepoint(){}async rollbackToSavepoint(){}async savepoint(){}},ko=class{async executeQuery(){return{rows:[]}}async*streamQuery(){}};var at=class{get supportsCreateIfNotExists(){return!0}get supportsTransactionalDdl(){return!1}get supportsReturning(){return!1}get supportsOutput(){return!1}};var Rs=/"/g,Pn=class extends st{visitOrAction(e){this.append("or "),this.append(e.action)}getCurrentParameterPlaceholder(){return"?"}getLeftExplainOptionsWrapper(){return""}getRightExplainOptionsWrapper(){return""}getLeftIdentifierWrapper(){return'"'}getRightIdentifierWrapper(){return'"'}getAutoIncrement(){return"autoincrement"}sanitizeIdentifier(e){return e.replace(Rs,'""')}visitDefaultInsertValue(e){this.append("null")}};var Qn=class extends at{get supportsTransactionalDdl(){return!1}get supportsReturning(){return!0}async acquireMigrationLock(e,r){}async releaseMigrationLock(e,r){}};var Is=/"/g,$n=class extends st{sanitizeIdentifier(e){return e.replace(Is,'""')}};var Ls=BigInt("3853314791062309107"),Fn=class extends at{get supportsTransactionalDdl(){return!0}get supportsReturning(){return!0}async acquireMigrationLock(e,r){await F`select pg_advisory_xact_lock(${F.lit(Ls)})`.execute(e)}async releaseMigrationLock(e,r){}};var qs=/`/g,zn=class extends st{getCurrentParameterPlaceholder(){return"?"}getLeftExplainOptionsWrapper(){return""}getExplainOptionAssignment(){return"="}getExplainOptionsDelimiter(){return" "}getRightExplainOptionsWrapper(){return""}getLeftIdentifierWrapper(){return"`"}getRightIdentifierWrapper(){return"`"}sanitizeIdentifier(e){return e.replace(qs,"``")}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.using&&(this.append(" using "),this.visitNode(e.using)),e.table&&(this.append(" on "),this.visitNode(e.table)),e.columns&&(this.append(" ("),this.compileList(e.columns),this.append(")")),e.where&&(this.append(" "),this.visitNode(e.where))}};var Vn="ea586330-2c93-47c8-908d-981d9d270f9d",Bs=3600,Un=class extends at{get supportsTransactionalDdl(){return!1}get supportsReturning(){return!1}async acquireMigrationLock(e,r){await F`select get_lock(${F.lit(Vn)}, ${F.lit(Bs)})`.execute(e)}async releaseMigrationLock(e,r){await F`select release_lock(${F.lit(Vn)})`.execute(e)}};function Jn(t){return t.trim().replace(/^where\b/i,"").trim().replace(/;+$/u,"").trim()}function dT(t){return t.trim().replace(/;+$/u,"").includes(";")}function lT(t){return new _t({dialect:{createAdapter:()=>new t.Adapter,createDriver:()=>new Si,createIntrospector:()=>null,createQueryCompiler:()=>new t.QueryCompiler},plugins:[...t.noParameters?[new Eo]:[]]})}var Eo=class{#e=new Ao;transformQuery(e){return this.#e.transformNode(e.node)}transformResult(e){return Promise.resolve(e.result)}},Ao=class extends rt{transformPrimitiveValueList(e){return Le.create(e.values.map(P.createImmediate))}transformValue(e){return{...super.transformValue(e),immediate:!0}}};function fT(t){return typeof t=="string"?{parameters:[],sql:t}:t}function NT(t,e){let r=t.compile();return{parameters:r.parameters,sql:r.sql,transformations:e?.transformations}}function yT(t,e){let r=Ms(t,e);return o=>o.where(n=>n.or(r.map(s=>n.and(s.map(([a,c])=>n(a,c===null?"is":Array.isArray(c)?"in":"=",c))))))}function xT(t,e){let r={};for(let o of Object.values(e)){let{name:n,pkPosition:s}=o;s!=null&&(r[n]=t[n]??null)}return r}function Ms(t,e){let r=[],o=[],n=oe();for(let c of t){let g=[];for(let w of Object.values(e)){let{name:te,pkPosition:M}=w;if(M==null)continue;let re=M-1;c===t.at(0)&&(r[re]=n.ref(te)),g[re]=Do(c[te]??null,w)}o.push(r.length===1?g.at(0):jn(g))}let s=r.length===1?r.at(0):jn(r),a=o.length===1?o.at(0):o;return[[[s,a]]]}function jn(t){return F`(${F.join(t,F`, `)})`}function wT(t){let{values:e}=t;return()=>Array.isArray(e)?e.map(r=>Kn({...t,values:r})):Kn({...t,values:e})}function Kn(t){let{columns:e,context:r,supportsDefaultKeyword:o,values:n}=t,s=Object.entries(n),a=r==="update"?[]:Object.values(e).filter(c=>c.isRequired);return r==="insert"&&s.length===0&&a.length===0?{[Object.keys(e).at(0)]:o?F`default`:null}:s.reduce((c,[g,w])=>({...c,[g]:Do(w,e[g],o)}),a.reduce((c,g)=>{let{datatype:w,fkColumn:te,name:M}=g,{format:re,group:f,isArray:Y}=w;return te?c:Y||f==="json"?{...c,[M]:Ri}:f==="boolean"?{...c,[M]:Fo}:f==="string"?{...c,[M]:Qo}:f==="numeric"?{...c,[M]:$o}:(f==="datetime"||f==="time")&&re?{...c,[M]:Po(re)}:c},{}))}function Do(t,e,r=!0){let{datatype:o,defaultValue:n,nullable:s}=e,a=oe();return t===null||t===""&&s?a.lit(null):(t===""||t===void 0)&&n!=null?r?F`default`:a.lit(null):o.isNative?a.val(t):a.cast(a.val(t),F.id(o.schema,o.name))}function Ps(t,e){if(t.length===0)return n=>n.lit(!0);let r=[],o=[];for(let n=0;n{let s=r.map(a=>n.and(a.map(c=>c(n))));return n.or(s)}}var Qs=new Set(["ilike","like","not ilike","not like"]);function $s(t,e){if(t.kind==="ColumnFilter")return r=>{let{column:o,operator:n,value:s}=t,a=e[o];if(Qs.has(n)){let g=typeof s=="string"?s:String(s??"");return r(r.cast(o,"text"),n,g)}return r(a.datatype.group==="raw"?r.cast(o,"text"):o,n,Do(s,a))};if(t.kind==="SqlFilter"){let r=Jn(t.sql);return o=>r.length>0?F`(${F.raw(r)})`:o.lit(!0)}return Ps(t.filters,e)}function Fs(t){let e={blockCommentDepth:0,dollarQuoteDelimiter:"",mode:"normal"},r=[],o=0,n=0;for(;n=a.from&&r<=a.to)return a;let n=o[0],s=Hn(r,n);for(let a of o.slice(1)){let c=Hn(r,a);ce.to?t-e.to:0}function zs(t,e){if(t[e]!=="$")return null;let r=e+1;for(;r