@prisma/studio-core 0.0.0-dev.202505011736 → 0.0.0-dev.202505012230
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{adapter-BrIP6ZU8.d.cts → adapter-61uOYxS-.d.cts} +1 -1
- package/dist/{adapter-BrIP6ZU8.d.ts → adapter-61uOYxS-.d.ts} +1 -1
- package/dist/chunk-YGVG6UDX.js +1 -0
- package/dist/data/accelerate/index.d.cts +2 -2
- package/dist/data/accelerate/index.d.ts +2 -2
- package/dist/data/bff/index.d.cts +2 -2
- package/dist/data/bff/index.d.ts +2 -2
- package/dist/data/index.d.cts +2 -2
- package/dist/data/index.d.ts +2 -2
- package/dist/data/pglite/index.cjs +1 -1
- package/dist/data/pglite/index.d.cts +2 -2
- package/dist/data/pglite/index.d.ts +2 -2
- package/dist/data/pglite/index.js +1 -1
- package/dist/data/postgres-core/index.cjs +1 -1
- package/dist/data/postgres-core/index.d.cts +2 -2
- package/dist/data/postgres-core/index.d.ts +2 -2
- package/dist/data/postgres-core/index.js +1 -1
- package/dist/{index-CCCmtFfv.d.ts → index-B4GQ3MX6.d.ts} +1 -1
- package/dist/{index-nAcdeOvh.d.cts → index-HYs1YMk7.d.cts} +1 -1
- package/dist/ui/index.cjs +504 -504
- package/dist/ui/index.css +5 -0
- package/dist/ui/index.d.cts +1 -1
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.js +6 -6
- package/package.json +1 -1
- package/dist/chunk-J5BO45GU.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var ei=Object.defineProperty;var pn=Object.getOwnPropertyDescriptor;var cn=Object.getOwnPropertyNames;var hn=Object.prototype.hasOwnProperty;var mn=(t,e)=>{for(var r in e)ei(t,r,{get:e[r],enumerable:!0})},ln=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of cn(e))!hn.call(t,n)&&n!==r&&ei(t,n,{get:()=>e[n],enumerable:!(o=pn(e,n))||o.enumerable});return t};var fn=t=>ln(ei({},"__esModule",{value:!0}),t);var ss={};mn(ss,{createPGLiteAdapter:()=>ns,createPGLiteExecutor:()=>un});module.exports=fn(ss);var to={bool:{group:"boolean"},boolean:{group:"boolean"},bytea:{group:"string"},char:{group:"string"},citext:{group:"string"},date:{group:"datetime"},interval:{group:"string"},name:{group:"string"},varchar:{group:"string"},text:{group:"string"},time:{group:"time"},timestamp:{group:"datetime"},timestamptz:{group:"datetime"},"timestamp without time zone":{group:"datetime"},"timestamp with time zone":{group:"datetime"},timetz:{group:"time"},"time without time zone":{group:"time"},"time with time zone":{group:"datetime"},uuid:{group:"string"}};function j(t){return typeof t>"u"||t===void 0}function C(t){return typeof t=="string"}function Se(t){return typeof t=="number"}function ze(t){return typeof t=="boolean"}function Ye(t){return t===null}function ro(t){return t instanceof Date}function Xe(t){return typeof t=="bigint"}function T(t){return typeof t=="function"}function B(t){return typeof t=="object"&&t!==null}function i(t){return Object.freeze(t)}function kt(t){return P(t)?t:[t]}function P(t){return Array.isArray(t)}function z(t){return t}var f=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 p=i({is(t){return t.kind==="IdentifierNode"},create(t){return i({kind:"IdentifierNode",name:t})}});var re=i({is(t){return t.kind==="CreateIndexNode"},create(t){return i({kind:"CreateIndexNode",name:p.create(t)})},cloneWith(t,e){return i({...t,...e})},cloneWithColumns(t,e){return i({...t,columns:[...t.columns||[],...e]})}});var Vt=i({is(t){return t.kind==="CreateSchemaNode"},create(t,e){return i({kind:"CreateSchemaNode",schema:p.create(t),...e})},cloneWith(t,e){return i({...t,...e})}});var io=["preserve rows","delete rows","drop"],M=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 F=i({is(t){return t.kind==="SchemableIdentifierNode"},create(t){return i({kind:"SchemableIdentifierNode",identifier:p.create(t)})},createWithSchema(t,e){return i({kind:"SchemableIdentifierNode",schema:p.create(t),identifier:p.create(e)})}});var ke=i({is(t){return t.kind==="DropIndexNode"},create(t,e){return i({kind:"DropIndexNode",name:F.create(t),...e})},cloneWith(t,e){return i({...t,...e})}});var Et=i({is(t){return t.kind==="DropSchemaNode"},create(t,e){return i({kind:"DropSchemaNode",schema:p.create(t),...e})},cloneWith(t,e){return i({...t,...e})}});var At=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 R=i({is(t){return t.kind==="AliasNode"},create(t,e){return i({kind:"AliasNode",node:t,alias:e})}});var H=i({is(t){return t.kind==="TableNode"},create(t){return i({kind:"TableNode",table:F.create(t)})},createWithSchema(t,e){return i({kind:"TableNode",table:F.createWithSchema(t,e)})}});function b(t){return B(t)&&T(t.toOperationNode)}function Ut(t){return B(t)&&"expressionType"in t&&b(t)}function oo(t){return B(t)&&"expression"in t&&C(t.alias)&&b(t)}var ce=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 J=i({is(t){return t.kind==="AndNode"},create(t,e){return i({kind:"AndNode",left:t,right:e})}});var ie=i({is(t){return t.kind==="OrNode"},create(t,e){return i({kind:"OrNode",left:t,right:e})}});var Jt=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"?J.create(t.on,r):ie.create(t.on,r)})}});var we=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:Jt.create(r)})},cloneWithOn(t,e){return i({...t,on:t.on?Jt.cloneWithOperation(t.on,"And",e):Jt.create(e)})}});var Ee=i({is(t){return t.kind==="BinaryOperationNode"},create(t,e,r){return i({kind:"BinaryOperationNode",leftOperand:t,operator:e,rightOperand:r})}});var Nn=["=","==","!=","<>",">",">=","<","<=","in","not in","is","is not","like","not like","match","ilike","not ilike","@>","<@","^@","&&","?","?&","?|","!<","!>","<=>","!~","~","~*","!~*","@@","@@@","!!","<->","regexp","is distinct from","is not distinct from"],yn=["+","-","*","/","%","^","&","|","#","<<",">>"],no=["->","->>"],wn=[...Nn,...yn,"&&","||"],xn=["exists","not exists"],gn=["not","-",...xn],so=[...wn,...no,...gn,"between","between symmetric"],Y=i({is(t){return t.kind==="OperatorNode"},create(t){return i({kind:"OperatorNode",operator:t})}});function ti(t){return C(t)&&no.includes(t)}var m=i({is(t){return t.kind==="ColumnNode"},create(t){return i({kind:"ColumnNode",column:p.create(t)})}});var Ze=i({is(t){return t.kind==="SelectAllNode"},create(){return i({kind:"SelectAllNode"})}});var _e=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:Ze.create()})}});var $t=class{#e;get dynamicReference(){return this.#e}get refType(){}constructor(e){this.#e=e}toOperationNode(){return ri(this.#e)}};function Kt(t){return B(t)&&b(t)&&C(t.dynamicReference)}var oe=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 W=i({is(t){return t.kind==="RawNode"},create(t,e){return i({kind:"RawNode",sqlFragments:i(t),parameters:i(e)})},createWithSql(t){return W.create([t],[])},createWithChild(t){return W.create(["",""],[t])},createWithChildren(t){return W.create(new Array(t.length+1).fill(""),t)}});var ao={is(t){return t.kind==="CollateNode"},create(t){return i({kind:"CollateNode",collation:p.create(t)})}};var Gt=class t{#e;constructor(e){this.#e=i(e)}desc(){return new t({node:oe.cloneWith(this.#e.node,{direction:W.createWithSql("desc")})})}asc(){return new t({node:oe.cloneWith(this.#e.node,{direction:W.createWithSql("asc")})})}nullsLast(){return new t({node:oe.cloneWith(this.#e.node,{nulls:"last"})})}nullsFirst(){return new t({node:oe.cloneWith(this.#e.node,{nulls:"first"})})}collate(e){return new t({node:oe.cloneWith(this.#e.node,{collation:ao.create(e)})})}toOperationNode(){return this.#e.node}};var uo=new Set;function Ae(t){uo.has(t)||(uo.add(t),console.log(t))}function oi(t){return t==="asc"||t==="desc"}function Z(t){if(t.length===2)return[ii(t[0],t[1])];if(t.length===1){let[e]=t;return Array.isArray(e)?(Ae("orderBy(array) is deprecated, use multiple orderBy calls instead."),e.map(r=>ii(r))):[ii(e)]}throw new Error(`Invalid number of arguments at order by! expected 1-2, received ${t.length}`)}function ii(t,e){let r=On(t);if(oe.is(r)){if(e)throw new Error("Cannot specify direction twice!");return r}return po(r,e)}function On(t){if(xe(t))return $(t);if(Kt(t))return t.toOperationNode();let[e,r]=t.split(" ");return r?(Ae("`orderBy('column asc')` is deprecated. Use `orderBy('column', 'asc')` instead."),po(X(e),r)):X(t)}function po(t,e){if(typeof e=="string"){if(!oi(e))throw new Error(`Invalid order by direction: ${e}`);return oe.create(t,W.createWithSql(e))}if(Ut(e))return Ae("`orderBy(..., expr)` is deprecated. Use `orderBy(..., 'asc')` or `orderBy(..., (ob) => ...)` instead."),oe.create(t,e.toOperationNode());let r=oe.create(t);return e?e(new Gt({node:r})).toOperationNode():r}var et=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 jt=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 Re=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 ri(t){return C(t)?X(t):t.toOperationNode()}function ge(t){return P(t)?t.map(e=>L(e)):[L(t)]}function L(t){return xe(t)?$(t):ri(t)}function co(t,e){let r=X(t);if(ti(e))return et.create(r,jt.create(Y.create(e)));let o=e.slice(0,-1);if(ti(o))return et.create(r,Re.create(Y.create(o)));throw new Error(`Invalid JSON operator: ${e}`)}function X(t){let e=".";if(!t.includes(e))return _e.create(m.create(t));let r=t.split(e).map(si);if(r.length===3)return bn(r);if(r.length===2)return vn(r);throw new Error(`invalid column reference ${t}`)}function ho(t){let e=" as ";if(t.includes(e)){let[r,o]=t.split(e).map(si);return R.create(X(r),p.create(o))}else return X(t)}function ni(t){return m.create(t)}function tt(t){let e=" ";if(t.includes(e)){let[r,o]=t.split(e).map(si);if(!oi(o))throw new Error(`invalid order direction "${o}" next to "${r}"`);return Z([r,o])[0]}else return ni(t)}function bn(t){let[e,r,o]=t;return _e.create(m.create(o),H.createWithSchema(e,r))}function vn(t){let[e,r]=t;return _e.create(m.create(r),H.create(e))}function si(t){return t.trim()}var Ht=i({is(t){return t.kind==="PrimitiveValueListNode"},create(t){return i({kind:"PrimitiveValueListNode",values:i([...t])})}});var he=i({is(t){return t.kind==="ValueListNode"},create(t){return i({kind:"ValueListNode",values:i(t)})}});var k=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 mo(t){return P(t)?Cn(t):g(t)}function g(t){return xe(t)?$(t):k.create(t)}function Yt(t){return Se(t)||ze(t)||Ye(t)}function Rt(t){if(!Yt(t))throw new Error(`unsafe immediate value ${JSON.stringify(t)}`);return k.createImmediate(t)}function Cn(t){return t.some(xe)?he.create(t.map(e=>g(e))):Ht.create(t)}var me=i({is(t){return t.kind==="ParensNode"},create(t){return i({kind:"ParensNode",node:t})}});function O(t){if(t.length===3)return Xt(t[0],t[1],t[2]);if(t.length===1)return g(t[0]);throw new Error(`invalid arguments: ${JSON.stringify(t)}`)}function Xt(t,e,r){return Wn(e)&&fo(r)?Ee.create(L(t),ai(e),k.createImmediate(r)):Ee.create(L(t),ai(e),mo(r))}function I(t,e,r){return Ee.create(L(t),ai(e),L(r))}function ui(t,e){return rt(Object.entries(t).filter(([,r])=>!j(r)).map(([r,o])=>Xt(r,fo(o)?"is":"=",o)),e)}function rt(t,e,r=!0){let o=e==="and"?J.create:ie.create;if(t.length===0)return Ee.create(k.createImmediate(1),Y.create("="),k.createImmediate(e==="and"?1:0));let n=lo(t[0]);for(let a=1;a<t.length;++a)n=o(n,lo(t[a]));return t.length>1&&r?me.create(n):n}function Wn(t){return t==="is"||t==="is not"}function fo(t){return Ye(t)||ze(t)}function ai(t){if(C(t)&&so.includes(t))return Y.create(t);if(b(t))return t.toOperationNode();throw new Error(`invalid operator ${JSON.stringify(t)}`)}function lo(t){return b(t)?t.toOperationNode():t}var Oe=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 di=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 It=i({is(t){return t.kind==="OverNode"},create(){return i({kind:"OverNode"})},cloneWithOrderByItems(t,e){return i({...t,orderBy:t.orderBy?Oe.cloneWithItems(t.orderBy,e):Oe.create(e)})},cloneWithPartitionByItems(t,e){return i({...t,partitionBy:t.partitionBy?di.cloneWithItems(t.partitionBy,e):di.create(e)})}});var Ve=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 pi=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 ci=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"?J.create(t.having,r):ie.create(t.having,r)})}});var S=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 Zt=i({is(t){return t.kind==="ListNode"},create(t){return i({kind:"ListNode",items:i(t)})}});var le=i({is(t){return t.kind==="UpdateQueryNode"},create(t,e){return i({kind:"UpdateQueryNode",table:t.length===1?t[0]:Zt.create(t),...e&&{with:e}})},createWithoutTable(){return i({kind:"UpdateQueryNode"})},cloneWithFromItems(t,e){return i({...t,from:t.from?Ve.cloneWithFroms(t.from,e):Ve.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 hi=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 Ie=i({is(t){return t.kind==="DeleteQueryNode"},create(t,e){return i({kind:"DeleteQueryNode",from:Ve.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?hi.cloneWithTables(t.using,e):hi.create(e)})}});var Q=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"?J.create(t.where,r):ie.create(t.where,r)})}});var mi=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 No=i({is(t){return t.kind==="ExplainNode"},create(t,e){return i({kind:"ExplainNode",format:t,options:e})}});var be=i({is(t){return t.kind==="WhenNode"},create(t){return i({kind:"WhenNode",condition:t})},cloneWithResult(t,e){return i({...t,result:e})}});var D=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),be.cloneWithResult(t.whens[t.whens.length-1],e)]):void 0})}});var li=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 x.is(t)||S.is(t)||le.is(t)||Ie.is(t)||D.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?Q.cloneWithOperation(t.where,"And",e):Q.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?mi.cloneWithSelections(t.returning,e):mi.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:No.create(e,r?.toOperationNode())})},cloneWithTop(t,e){return i({...t,top:e})},cloneWithOutput(t,e){return i({...t,output:t.output?li.cloneWithSelections(t.output,e):li.create(e)})},cloneWithOrderByItems(t,e){return i({...t,orderBy:t.orderBy?Oe.cloneWithItems(t.orderBy,e):Oe.create(e)})},cloneWithoutOrderBy(t){return i({...t,orderBy:void 0})}});var x=i({is(t){return t.kind==="SelectQueryNode"},create(t){return i({kind:"SelectQueryNode",...t&&{with:t}})},createFrom(t,e){return i({kind:"SelectQueryNode",from:Ve.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?pi.cloneWithItems(t.groupBy,e):pi.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?ci.cloneWithOperation(t.having,"And",e):ci.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 _t=class t{#e;constructor(e){this.#e=i(e)}on(...e){return new t({...this.#e,joinNode:we.cloneWithOn(this.#e.joinNode,O(e))})}onRef(e,r,o){return new t({...this.#e,joinNode:we.cloneWithOn(this.#e.joinNode,I(e,r,o))})}onTrue(){return new t({...this.#e,joinNode:we.cloneWithOn(this.#e.joinNode,W.createWithSql("true"))})}$call(e){return e(this)}toOperationNode(){return this.#e.joinNode}};var yo=i({is(t){return t.kind==="PartitionByItemNode"},create(t){return i({kind:"PartitionByItemNode",partitionBy:t})}});function wo(t){return ge(t).map(yo.create)}var er=class t{#e;constructor(e){this.#e=i(e)}orderBy(...e){return new t({overNode:It.cloneWithOrderByItems(this.#e.overNode,Z(e))})}clearOrderBy(){return new t({overNode:u.cloneWithoutOrderBy(this.#e.overNode)})}partitionBy(e){return new t({overNode:It.cloneWithPartitionByItems(this.#e.overNode,wo(e))})}$call(e){return e(this)}toOperationNode(){return this.#e.overNode}};var it=i({is(t){return t.kind==="SelectionNode"},create(t){return i({kind:"SelectionNode",selection:t})},createSelectAll(){return i({kind:"SelectionNode",selection:Ze.create()})},createSelectAllFromTable(t){return i({kind:"SelectionNode",selection:_e.createSelectAll(t)})}});function A(t){return T(t)?A(t(ne())):P(t)?t.map(e=>xo(e)):[xo(t)]}function xo(t){return C(t)?it.create(ho(t)):Kt(t)?it.create(t.toOperationNode()):it.create(tr(t))}function q(t){return t?Array.isArray(t)?t.map(go):[go(t)]:[it.createSelectAll()]}function go(t){if(C(t))return it.createSelectAllFromTable(N(t));throw new Error(`invalid value selectAll expression: ${JSON.stringify(t)}`)}var Oo=i({is(t){return t.kind==="ValuesNode"},create(t){return i({kind:"ValuesNode",values:i(t)})}});var bo=i({is(t){return t.kind==="DefaultInsertValueNode"},create(){return i({kind:"DefaultInsertValueNode"})}});function rr(t){let e=T(t)?t(ne()):t,r=P(e)?e:i([e]);return Tn(r)}function Tn(t){let e=Sn(t);return[i([...e.keys()].map(m.create)),Oo.create(t.map(r=>kn(r,e)))]}function Sn(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 kn(t,e){let r=Object.keys(t),o=Array.from({length:e.size}),n=!1,a=r.length;for(let c of r){let y=e.get(c);if(j(y)){a--;continue}let h=t[c];(j(h)||xe(h))&&(n=!0),o[y]=h}if(a<e.size||n){let c=bo.create();return he.create(o.map(y=>j(y)?c:g(y)))}return Ht.create(o)}var fi=i({is(t){return t.kind==="ColumnUpdateNode"},create(t,e){return i({kind:"ColumnUpdateNode",column:t,value:e})}});function vo(...t){return t.length===2?[fi.create(L(t[0]),g(t[1]))]:Dt(t[0])}function Dt(t){let e=T(t)?t(ne()):t;return Object.entries(e).filter(([r,o])=>o!==void 0).map(([r,o])=>fi.create(m.create(r),g(o)))}var Co=i({is(t){return t.kind==="OnDuplicateKeyNode"},create(t){return i({kind:"OnDuplicateKeyNode",updates:t})}});var ir=class{insertId;numInsertedOrUpdatedRows;constructor(e,r){this.insertId=e,this.numInsertedOrUpdatedRows=r}};var ee=class extends Error{node;constructor(e){super("no result"),this.node=e}};function fe(t){return Object.prototype.hasOwnProperty.call(t,"prototype")}var V=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?Q.cloneWithOperation(t.indexWhere,"And",e):Q.create(e)})},cloneWithIndexOrWhere(t,e){return i({...t,indexWhere:t.indexWhere?Q.cloneWithOperation(t.indexWhere,"Or",e):Q.create(e)})},cloneWithUpdateWhere(t,e){return i({...t,updateWhere:t.updateWhere?Q.cloneWithOperation(t.updateWhere,"And",e):Q.create(e)})},cloneWithUpdateOrWhere(t,e){return i({...t,updateWhere:t.updateWhere?Q.cloneWithOperation(t.updateWhere,"Or",e):Q.create(e)})},cloneWithoutIndexWhere(t){return i({...t,indexWhere:void 0})},cloneWithoutUpdateWhere(t){return i({...t,updateWhere:void 0})}});var or=class t{#e;constructor(e){this.#e=i(e)}column(e){let r=m.create(e);return new t({...this.#e,onConflictNode:V.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?i([...this.#e.onConflictNode.columns,r]):i([r])})})}columns(e){let r=e.map(m.create);return new t({...this.#e,onConflictNode:V.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:V.cloneWith(this.#e.onConflictNode,{constraint:p.create(e)})})}expression(e){return new t({...this.#e,onConflictNode:V.cloneWith(this.#e.onConflictNode,{indexExpression:e.toOperationNode()})})}where(...e){return new t({...this.#e,onConflictNode:V.cloneWithIndexWhere(this.#e.onConflictNode,O(e))})}whereRef(e,r,o){return new t({...this.#e,onConflictNode:V.cloneWithIndexWhere(this.#e.onConflictNode,I(e,r,o))})}clearWhere(){return new t({...this.#e,onConflictNode:V.cloneWithoutIndexWhere(this.#e.onConflictNode)})}doNothing(){return new Ni({...this.#e,onConflictNode:V.cloneWith(this.#e.onConflictNode,{doNothing:!0})})}doUpdateSet(e){return new yi({...this.#e,onConflictNode:V.cloneWith(this.#e.onConflictNode,{updates:Dt(e)})})}$call(e){return e(this)}},Ni=class{#e;constructor(e){this.#e=i(e)}toOperationNode(){return this.#e.onConflictNode}},yi=class t{#e;constructor(e){this.#e=i(e)}where(...e){return new t({...this.#e,onConflictNode:V.cloneWithUpdateWhere(this.#e.onConflictNode,O(e))})}whereRef(e,r,o){return new t({...this.#e,onConflictNode:V.cloneWithUpdateWhere(this.#e.onConflictNode,I(e,r,o))})}clearWhere(){return new t({...this.#e,onConflictNode:V.cloneWithoutUpdateWhere(this.#e.onConflictNode)})}$call(e){return e(this)}toOperationNode(){return this.#e.onConflictNode}};var Wo=i({is(t){return t.kind==="TopNode"},create(t,e){return i({kind:"TopNode",expression:t,modifiers:e})}});function se(t,e){if(!Se(t)&&!Xe(t))throw new Error(`Invalid top expression: ${t}`);if(!j(e)&&!En(e))throw new Error(`Invalid top modifiers: ${e}`);return Wo.create(t,e)}function En(t){return t==="percent"||t==="with ties"||t==="percent with ties"}var Ue=i({is(t){return t.kind==="OrActionNode"},create(t){return i({kind:"OrActionNode",action:t})}});var qt=class t{#e;constructor(e){this.#e=i(e)}values(e){let[r,o]=rr(e);return new t({...this.#e,queryNode:S.cloneWith(this.#e.queryNode,{columns:r,values:o})})}columns(e){return new t({...this.#e,queryNode:S.cloneWith(this.#e.queryNode,{columns:i(e.map(m.create))})})}expression(e){return new t({...this.#e,queryNode:S.cloneWith(this.#e.queryNode,{values:$(e)})})}defaultValues(){return new t({...this.#e,queryNode:S.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:S.cloneWith(this.#e.queryNode,{orAction:Ue.create("ignore")})})}orIgnore(){return new t({...this.#e,queryNode:S.cloneWith(this.#e.queryNode,{orAction:Ue.create("ignore")})})}orAbort(){return new t({...this.#e,queryNode:S.cloneWith(this.#e.queryNode,{orAction:Ue.create("abort")})})}orFail(){return new t({...this.#e,queryNode:S.cloneWith(this.#e.queryNode,{orAction:Ue.create("fail")})})}orReplace(){return new t({...this.#e,queryNode:S.cloneWith(this.#e.queryNode,{orAction:Ue.create("replace")})})}orRollback(){return new t({...this.#e,queryNode:S.cloneWith(this.#e.queryNode,{orAction:Ue.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:S.cloneWith(this.#e.queryNode,{onConflict:e(new or({onConflictNode:V.create()})).toOperationNode()})})}onDuplicateKeyUpdate(e){return new t({...this.#e,queryNode:S.cloneWith(this.#e.queryNode,{onDuplicateKey:Co.create(Dt(e))})})}returning(e){return new t({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,A(e))})}returningAll(){return new t({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,q())})}output(e){return new t({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,A(e))})}outputAll(e){return new t({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,q(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,this.#e.queryId),{adapter:o}=this.#e.executor,n=e.query;return n.returning&&o.supportsReturning||n.output&&o.supportsOutput?r.rows:[new ir(r.insertId,r.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=ee){let r=await this.executeTakeFirst();if(r===void 0)throw fe(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,this.#e.queryId);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 nr=class{numDeletedRows;constructor(e){this.numDeletedRows=e}};var ot=i({is(t){return t.kind==="LimitNode"},create(t){return i({kind:"LimitNode",limit:t})}});var sr=class t{#e;constructor(e){this.#e=i(e)}where(...e){return new t({...this.#e,queryNode:u.cloneWithWhere(this.#e.queryNode,O(e))})}whereRef(e,r,o){return new t({...this.#e,queryNode:u.cloneWithWhere(this.#e.queryNode,I(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:Ie.cloneWithUsing(this.#e.queryNode,ae(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,De(e,r))})}returning(e){return new t({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,A(e))})}returningAll(e){return new t({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,q(e))})}output(e){return new t({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,A(e))})}outputAll(e){return new t({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,q(e))})}clearReturning(){return new t({...this.#e,queryNode:u.cloneWithoutReturning(this.#e.queryNode)})}clearLimit(){return new t({...this.#e,queryNode:Ie.cloneWithoutLimit(this.#e.queryNode)})}orderBy(...e){return new t({...this.#e,queryNode:u.cloneWithOrderByItems(this.#e.queryNode,Z(e))})}clearOrderBy(){return new t({...this.#e,queryNode:u.cloneWithoutOrderBy(this.#e.queryNode)})}limit(e){return new t({...this.#e,queryNode:Ie.cloneWithLimit(this.#e.queryNode,ot.create(g(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,this.#e.queryId),{adapter:o}=this.#e.executor,n=e.query;return n.returning&&o.supportsReturning||n.output&&o.supportsOutput?r.rows:[new nr(r.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=ee){let r=await this.executeTakeFirst();if(r===void 0)throw fe(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,this.#e.queryId);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 ar=class{numUpdatedRows;numChangedRows;constructor(e,r){this.numUpdatedRows=e,this.numChangedRows=r}};var nt=class t{#e;constructor(e){this.#e=i(e)}where(...e){return new t({...this.#e,queryNode:u.cloneWithWhere(this.#e.queryNode,O(e))})}whereRef(e,r,o){return new t({...this.#e,queryNode:u.cloneWithWhere(this.#e.queryNode,I(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:le.cloneWithFromItems(this.#e.queryNode,ae(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,De(e,r))})}orderBy(...e){return new t({...this.#e,queryNode:u.cloneWithOrderByItems(this.#e.queryNode,Z(e))})}clearOrderBy(){return new t({...this.#e,queryNode:u.cloneWithoutOrderBy(this.#e.queryNode)})}limit(e){return new t({...this.#e,queryNode:le.cloneWithLimit(this.#e.queryNode,ot.create(g(e)))})}set(...e){return new t({...this.#e,queryNode:le.cloneWithUpdates(this.#e.queryNode,vo(...e))})}returning(e){return new t({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,A(e))})}returningAll(e){return new t({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,q(e))})}output(e){return new t({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,A(e))})}outputAll(e){return new t({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,q(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,this.#e.queryId),{adapter:o}=this.#e.executor,n=e.query;return n.returning&&o.supportsReturning||n.output&&o.supportsOutput?r.rows:[new ar(r.numAffectedRows??BigInt(0),r.numChangedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=ee){let r=await this.executeTakeFirst();if(r===void 0)throw fe(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,this.#e.queryId);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 wi=i({is(t){return t.kind==="CommonTableExpressionNameNode"},create(t,e){return i({kind:"CommonTableExpressionNameNode",table:H.create(t),columns:e?i(e.map(m.create)):void 0})}});var st=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 ur=class t{#e;constructor(e){this.#e=i(e)}materialized(){return new t({...this.#e,node:st.cloneWith(this.#e.node,{materialized:!0})})}notMaterialized(){return new t({...this.#e,node:st.cloneWith(this.#e.node,{materialized:!1})})}toOperationNode(){return this.#e.node}};function xi(t,e){let r=e(So()).toOperationNode();return T(t)?t(An(r)).toOperationNode():st.create(To(t),r)}function An(t){return e=>new ur({node:st.create(To(e),t)})}function To(t){if(t.includes("(")){let e=t.split(/[\(\)]/),r=e[0],o=e[1].split(",").map(n=>n.trim());return wi.create(r,o)}else return wi.create(t)}var Bt=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 ko=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"];function Eo(t){let e="";for(let r=0;r<t;++r)e+=Rn();return e}function Rn(){return ko[~~(Math.random()*ko.length)]}function l(){return new gi}var gi=class{#e;get queryId(){return this.#e===void 0&&(this.#e=Eo(8)),this.#e}};var qe=class{nodeStack=[];#e=i({AliasNode:this.transformAlias.bind(this),ColumnNode:this.transformColumn.bind(this),IdentifierNode:this.transformIdentifier.bind(this),SchemableIdentifierNode:this.transformSchemableIdentifier.bind(this),RawNode:this.transformRaw.bind(this),ReferenceNode:this.transformReference.bind(this),SelectQueryNode:this.transformSelectQuery.bind(this),SelectionNode:this.transformSelection.bind(this),TableNode:this.transformTable.bind(this),FromNode:this.transformFrom.bind(this),SelectAllNode:this.transformSelectAll.bind(this),AndNode:this.transformAnd.bind(this),OrNode:this.transformOr.bind(this),ValueNode:this.transformValue.bind(this),ValueListNode:this.transformValueList.bind(this),PrimitiveValueListNode:this.transformPrimitiveValueList.bind(this),ParensNode:this.transformParens.bind(this),JoinNode:this.transformJoin.bind(this),OperatorNode:this.transformOperator.bind(this),WhereNode:this.transformWhere.bind(this),InsertQueryNode:this.transformInsertQuery.bind(this),DeleteQueryNode:this.transformDeleteQuery.bind(this),ReturningNode:this.transformReturning.bind(this),CreateTableNode:this.transformCreateTable.bind(this),AddColumnNode:this.transformAddColumn.bind(this),ColumnDefinitionNode:this.transformColumnDefinition.bind(this),DropTableNode:this.transformDropTable.bind(this),DataTypeNode:this.transformDataType.bind(this),OrderByNode:this.transformOrderBy.bind(this),OrderByItemNode:this.transformOrderByItem.bind(this),GroupByNode:this.transformGroupBy.bind(this),GroupByItemNode:this.transformGroupByItem.bind(this),UpdateQueryNode:this.transformUpdateQuery.bind(this),ColumnUpdateNode:this.transformColumnUpdate.bind(this),LimitNode:this.transformLimit.bind(this),OffsetNode:this.transformOffset.bind(this),OnConflictNode:this.transformOnConflict.bind(this),OnDuplicateKeyNode:this.transformOnDuplicateKey.bind(this),CreateIndexNode:this.transformCreateIndex.bind(this),DropIndexNode:this.transformDropIndex.bind(this),ListNode:this.transformList.bind(this),PrimaryKeyConstraintNode:this.transformPrimaryKeyConstraint.bind(this),UniqueConstraintNode:this.transformUniqueConstraint.bind(this),ReferencesNode:this.transformReferences.bind(this),CheckConstraintNode:this.transformCheckConstraint.bind(this),WithNode:this.transformWith.bind(this),CommonTableExpressionNode:this.transformCommonTableExpression.bind(this),CommonTableExpressionNameNode:this.transformCommonTableExpressionName.bind(this),HavingNode:this.transformHaving.bind(this),CreateSchemaNode:this.transformCreateSchema.bind(this),DropSchemaNode:this.transformDropSchema.bind(this),AlterTableNode:this.transformAlterTable.bind(this),DropColumnNode:this.transformDropColumn.bind(this),RenameColumnNode:this.transformRenameColumn.bind(this),AlterColumnNode:this.transformAlterColumn.bind(this),ModifyColumnNode:this.transformModifyColumn.bind(this),AddConstraintNode:this.transformAddConstraint.bind(this),DropConstraintNode:this.transformDropConstraint.bind(this),RenameConstraintNode:this.transformRenameConstraint.bind(this),ForeignKeyConstraintNode:this.transformForeignKeyConstraint.bind(this),CreateViewNode:this.transformCreateView.bind(this),RefreshMaterializedViewNode:this.transformRefreshMaterializedView.bind(this),DropViewNode:this.transformDropView.bind(this),GeneratedNode:this.transformGenerated.bind(this),DefaultValueNode:this.transformDefaultValue.bind(this),OnNode:this.transformOn.bind(this),ValuesNode:this.transformValues.bind(this),SelectModifierNode:this.transformSelectModifier.bind(this),CreateTypeNode:this.transformCreateType.bind(this),DropTypeNode:this.transformDropType.bind(this),ExplainNode:this.transformExplain.bind(this),DefaultInsertValueNode:this.transformDefaultInsertValue.bind(this),AggregateFunctionNode:this.transformAggregateFunction.bind(this),OverNode:this.transformOver.bind(this),PartitionByNode:this.transformPartitionBy.bind(this),PartitionByItemNode:this.transformPartitionByItem.bind(this),SetOperationNode:this.transformSetOperation.bind(this),BinaryOperationNode:this.transformBinaryOperation.bind(this),UnaryOperationNode:this.transformUnaryOperation.bind(this),UsingNode:this.transformUsing.bind(this),FunctionNode:this.transformFunction.bind(this),CaseNode:this.transformCase.bind(this),WhenNode:this.transformWhen.bind(this),JSONReferenceNode:this.transformJSONReference.bind(this),JSONPathNode:this.transformJSONPath.bind(this),JSONPathLegNode:this.transformJSONPathLeg.bind(this),JSONOperatorChainNode:this.transformJSONOperatorChain.bind(this),TupleNode:this.transformTuple.bind(this),MergeQueryNode:this.transformMergeQuery.bind(this),MatchedNode:this.transformMatched.bind(this),AddIndexNode:this.transformAddIndex.bind(this),CastNode:this.transformCast.bind(this),FetchNode:this.transformFetch.bind(this),TopNode:this.transformTop.bind(this),OutputNode:this.transformOutput.bind(this),OrActionNode:this.transformOrAction.bind(this),CollateNode:this.transformCollate.bind(this)});transformNode(e,r){if(!e)return e;this.nodeStack.push(e);let o=this.transformNodeImpl(e,r);return this.nodeStack.pop(),i(o)}transformNodeImpl(e,r){return this.#e[e.kind](e,r)}transformNodeList(e,r){return e&&i(e.map(o=>this.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 In=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}),Dn={json_agg:!0,to_json:!0},dr=class extends qe{#e;#t=new Set;#r=new Set;constructor(e){super(),this.#e=e}transformNodeImpl(e,r){if(!this.#o(e))return super.transformNodeImpl(e,r);let o=this.#d(e);for(let d of o)this.#r.add(d);let n=this.#a(e);for(let d of n)this.#t.add(d);let a=super.transformNodeImpl(e,r);for(let d of n)this.#t.delete(d);for(let d of o)this.#r.delete(d);return a}transformSchemableIdentifier(e,r){let o=super.transformSchemableIdentifier(e,r);return o.schema||!this.#t.has(e.identifier.name)?o:{...o,schema:p.create(this.#e)}}transformReferences(e,r){let o=super.transformReferences(e,r);return o.table.table.schema?o:{...o,table:H.createWithSchema(this.#e,o.table.table.identifier.name)}}transformAggregateFunction(e,r){return{...super.transformAggregateFunction({...e,aggregated:[]},r),aggregated:this.#i(e,r,"aggregated")}}transformFunction(e,r){return{...super.transformFunction({...e,arguments:[]},r),arguments:this.#i(e,r,"arguments")}}#i(e,r,o){return Dn[e.func]?e[o].map(n=>!H.is(n)||n.table.schema?this.transformNode(n,r):{...n,table:this.transformIdentifier(n.table.identifier,r)}):this.transformNodeList(e[o],r)}#o(e){return e.kind in In}#a(e){let r=new Set;if("name"in e&&e.name&&F.is(e.name)&&this.#s(e.name,r),"from"in e&&e.from)for(let o of e.from.froms)this.#n(o,r);if("into"in e&&e.into&&this.#n(e.into,r),"table"in e&&e.table&&this.#n(e.table,r),"joins"in e&&e.joins)for(let o of e.joins)this.#n(o.table,r);return"using"in e&&e.using&&this.#n(e.using,r),r}#d(e){let r=new Set;return"with"in e&&e.with&&this.#u(e.with,r),r}#n(e,r){if(H.is(e))this.#s(e.table,r);else if(R.is(e)&&H.is(e.node))this.#s(e.node.table,r);else if(Zt.is(e))for(let o of e.items)this.#n(o,r)}#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 te=class{#e;constructor(e){this.#e=new dr(e)}transformQuery(e){return this.#e.transformNode(e.node,e.queryId)}async transformResult(e){return e.result}};var Ao=i({is(t){return t.kind==="MatchedNode"},create(t,e=!1){return i({kind:"MatchedNode",not:t,bySource:e})}});function Oi(t,e,r){return be.create(rt([Ao.create(!t.isMatched,t.bySource),...e&&e.length>0?[e.length===3&&r?I(e[0],e[1],e[2]):O(e)]:[]],"and",!1))}function at(t){return C(t)?W.create([t],[]):b(t)?t.toOperationNode():t}var Lt=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 pr(t){let e=new Lt,r=new Lt;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 qn=i([]),ut=class{#e;constructor(e=qn){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,r){return await this.provideConnection(async o=>{let n=await o.executeQuery(e);return"numUpdatedOrDeletedRows"in n&&Ae("kysely:warning: outdated driver/plugin detected! `QueryResult.numUpdatedOrDeletedRows` has been replaced with `QueryResult.numAffectedRows`."),await this.#t(n,r)})}async*stream(e,r,o){let{connection:n,release:a}=await pr(this);try{for await(let d of n.streamQuery(e,r))yield await this.#t(d,o)}finally{a()}}async#t(e,r){for(let o of this.#e)e=await o.transformResult({result:e,queryId:r});return e}};var bi=class t extends ut{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([])}},Be=new bi;var cr=class{numChangedRows;constructor(e){this.numChangedRows=e}};var hr=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 Le({...this.#e,queryNode:D.cloneWithUsing(this.#e.queryNode,De("Using",e))})}returning(e){return new t({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,A(e))})}returningAll(e){return new t({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,q(e))})}output(e){return new t({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,A(e))})}outputAll(e){return new t({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,q(e))})}},Le=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 mr({...this.#e,queryNode:D.cloneWithWhen(this.#e.queryNode,Oi({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,A(e))})}returningAll(e){return new t({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,q(e))})}output(e){return new t({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,A(e))})}outputAll(e){return new t({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,q(e))})}#r(e,r=!1,o=!1){let n={...this.#e,queryNode:D.cloneWithWhen(this.#e.queryNode,Oi({isMatched:!1,bySource:o},e,r))},a=o?mr:vi;return new a(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,this.#e.queryId),{adapter:o}=this.#e.executor,n=e.query;return n.returning&&o.supportsReturning||n.output&&o.supportsOutput?r.rows:[new cr(r.numAffectedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=ee){let r=await this.executeTakeFirst();if(r===void 0)throw fe(e)?new e(this.toOperationNode()):e(this.toOperationNode());return r}},mr=class{#e;constructor(e){this.#e=i(e)}thenDelete(){return new Le({...this.#e,queryNode:D.cloneWithThen(this.#e.queryNode,at("delete"))})}thenDoNothing(){return new Le({...this.#e,queryNode:D.cloneWithThen(this.#e.queryNode,at("do nothing"))})}thenUpdate(e){return new Le({...this.#e,queryNode:D.cloneWithThen(this.#e.queryNode,at(e(new nt({queryId:this.#e.queryId,executor:Be,queryNode:le.createWithoutTable()}))))})}thenUpdateSet(...e){return this.thenUpdate(r=>r.set(...e))}},vi=class{#e;constructor(e){this.#e=i(e)}thenDoNothing(){return new Le({...this.#e,queryNode:D.cloneWithThen(this.#e.queryNode,at("do nothing"))})}thenInsertValues(e){let[r,o]=rr(e);return new Le({...this.#e,queryNode:D.cloneWithThen(this.#e.queryNode,at(S.cloneWith(S.createWithoutInto(),{columns:r,values:o})))})}};var dt=class t{#e;constructor(e){this.#e=i(e)}selectFrom(e){return Qt({queryId:l(),executor:this.#e.executor,queryNode:x.createFrom(ae(e),this.#e.withNode)})}selectNoFrom(e){return Qt({queryId:l(),executor:this.#e.executor,queryNode:x.cloneWithSelections(x.create(this.#e.withNode),A(e))})}insertInto(e){return new qt({queryId:l(),executor:this.#e.executor,queryNode:S.create(N(e),this.#e.withNode)})}replaceInto(e){return new qt({queryId:l(),executor:this.#e.executor,queryNode:S.create(N(e),this.#e.withNode,!0)})}deleteFrom(e){return new sr({queryId:l(),executor:this.#e.executor,queryNode:Ie.create(ae(e),this.#e.withNode)})}updateTable(e){return new nt({queryId:l(),executor:this.#e.executor,queryNode:le.create(ae(e),this.#e.withNode)})}mergeInto(e){return new hr({queryId:l(),executor:this.#e.executor,queryNode:D.create(Ci(e),this.#e.withNode)})}with(e,r){let o=xi(e,r);return new t({...this.#e,withNode:this.#e.withNode?Bt.cloneWithExpression(this.#e.withNode,o):Bt.create(o)})}withRecursive(e,r){let o=xi(e,r);return new t({...this.#e,withNode:this.#e.withNode?Bt.cloneWithExpression(this.#e.withNode,o):Bt.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 te(e))})}};function So(){return new dt({executor:Be})}function Ro(t,e){return new _t({joinNode:we.create(t,Je(e))})}function Io(){return new er({overNode:It.create()})}function De(t,e){if(e.length===3)return Ln(t,e[0],e[1],e[2]);if(e.length===2)return Bn(t,e[0],e[1]);if(e.length===1)return Qn(t,e[0]);throw new Error("not implemented")}function Bn(t,e,r){return r(Ro(t,e)).toOperationNode()}function Ln(t,e,r,o){return we.createWithOn(t,Je(e),I(r,"=",o))}function Qn(t,e){return we.create(t,Je(e))}var Do=i({is(t){return t.kind==="OffsetNode"},create(t){return i({kind:"OffsetNode",offset:t})}});var qo=i({is(t){return t.kind==="GroupByItemNode"},create(t){return i({kind:"GroupByItemNode",groupBy:t})}});function Bo(t){return t=T(t)?t(ne()):t,ge(t).map(qo.create)}var lr=i({is(t){return t.kind==="SetOperationNode"},create(t,e,r){return i({kind:"SetOperationNode",operator:t,expression:e,all:r})}});function $e(t,e,r){return T(e)&&(e=e(fr())),P(e)||(e=[e]),e.map(o=>lr.create(t,$(o),r))}var w=class t{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new Pt(this,e)}or(...e){return new Wi(ie.create(this.#e,O(e)))}and(...e){return new Ti(J.create(this.#e,O(e)))}$castTo(){return new t(this.#e)}$notNull(){return new t(this.#e)}toOperationNode(){return this.#e}},Pt=class{#e;#t;constructor(e,r){this.#e=e,this.#t=r}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return R.create(this.#e.toOperationNode(),b(this.#t)?this.#t.toOperationNode():p.create(this.#t))}},Wi=class t{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new Pt(this,e)}or(...e){return new t(ie.create(this.#e,O(e)))}$castTo(){return new t(this.#e)}toOperationNode(){return me.create(this.#e)}},Ti=class t{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new Pt(this,e)}and(...e){return new t(J.create(this.#e,O(e)))}$castTo(){return new t(this.#e)}toOperationNode(){return me.create(this.#e)}};var Lo={is(t){return t.kind==="FetchNode"},create(t,e){return{kind:"FetchNode",rowCount:k.create(t),modifier:e}}};function Qo(t,e){if(!Se(t)&&!Xe(t))throw new Error(`Invalid fetch row count: ${t}`);if(!Pn(e))throw new Error(`Invalid fetch modifier: ${e}`);return Lo.create(t,e)}function Pn(t){return t==="only"||t==="with ties"}var Si=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,O(e))})}whereRef(e,r,o){return new t({...this.#e,queryNode:u.cloneWithWhere(this.#e.queryNode,I(e,r,o))})}having(...e){return new t({...this.#e,queryNode:x.cloneWithHaving(this.#e.queryNode,O(e))})}havingRef(e,r,o){return new t({...this.#e,queryNode:x.cloneWithHaving(this.#e.queryNode,I(e,r,o))})}select(e){return new t({...this.#e,queryNode:x.cloneWithSelections(this.#e.queryNode,A(e))})}distinctOn(e){return new t({...this.#e,queryNode:x.cloneWithDistinctOn(this.#e.queryNode,ge(e))})}modifyFront(e){return new t({...this.#e,queryNode:x.cloneWithFrontModifier(this.#e.queryNode,ce.createWithExpression(e.toOperationNode()))})}modifyEnd(e){return new t({...this.#e,queryNode:u.cloneWithEndModifier(this.#e.queryNode,ce.createWithExpression(e.toOperationNode()))})}distinct(){return new t({...this.#e,queryNode:x.cloneWithFrontModifier(this.#e.queryNode,ce.create("Distinct"))})}forUpdate(e){return new t({...this.#e,queryNode:u.cloneWithEndModifier(this.#e.queryNode,ce.create("ForUpdate",e?kt(e).map(N):void 0))})}forShare(e){return new t({...this.#e,queryNode:u.cloneWithEndModifier(this.#e.queryNode,ce.create("ForShare",e?kt(e).map(N):void 0))})}forKeyShare(e){return new t({...this.#e,queryNode:u.cloneWithEndModifier(this.#e.queryNode,ce.create("ForKeyShare",e?kt(e).map(N):void 0))})}forNoKeyUpdate(e){return new t({...this.#e,queryNode:u.cloneWithEndModifier(this.#e.queryNode,ce.create("ForNoKeyUpdate",e?kt(e).map(N):void 0))})}skipLocked(){return new t({...this.#e,queryNode:u.cloneWithEndModifier(this.#e.queryNode,ce.create("SkipLocked"))})}noWait(){return new t({...this.#e,queryNode:u.cloneWithEndModifier(this.#e.queryNode,ce.create("NoWait"))})}selectAll(e){return new t({...this.#e,queryNode:x.cloneWithSelections(this.#e.queryNode,q(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,De(e,r))})}orderBy(...e){return new t({...this.#e,queryNode:u.cloneWithOrderByItems(this.#e.queryNode,Z(e))})}groupBy(e){return new t({...this.#e,queryNode:x.cloneWithGroupByItems(this.#e.queryNode,Bo(e))})}limit(e){return new t({...this.#e,queryNode:x.cloneWithLimit(this.#e.queryNode,ot.create(g(e)))})}offset(e){return new t({...this.#e,queryNode:x.cloneWithOffset(this.#e.queryNode,Do.create(g(e)))})}fetch(e,r="only"){return new t({...this.#e,queryNode:x.cloneWithFetch(this.#e.queryNode,Qo(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:x.cloneWithSetOperations(this.#e.queryNode,$e("union",e,!1))})}unionAll(e){return new t({...this.#e,queryNode:x.cloneWithSetOperations(this.#e.queryNode,$e("union",e,!0))})}intersect(e){return new t({...this.#e,queryNode:x.cloneWithSetOperations(this.#e.queryNode,$e("intersect",e,!1))})}intersectAll(e){return new t({...this.#e,queryNode:x.cloneWithSetOperations(this.#e.queryNode,$e("intersect",e,!0))})}except(e){return new t({...this.#e,queryNode:x.cloneWithSetOperations(this.#e.queryNode,$e("except",e,!1))})}exceptAll(e){return new t({...this.#e,queryNode:x.cloneWithSetOperations(this.#e.queryNode,$e("except",e,!0))})}as(e){return new ki(this,e)}clearSelect(){return new t({...this.#e,queryNode:x.cloneWithoutSelections(this.#e.queryNode)})}clearWhere(){return new t({...this.#e,queryNode:u.cloneWithoutWhere(this.#e.queryNode)})}clearLimit(){return new t({...this.#e,queryNode:x.cloneWithoutLimit(this.#e.queryNode)})}clearOffset(){return new t({...this.#e,queryNode:x.cloneWithoutOffset(this.#e.queryNode)})}clearOrderBy(){return new t({...this.#e,queryNode:u.cloneWithoutOrderBy(this.#e.queryNode)})}clearGroupBy(){return new t({...this.#e,queryNode:x.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,this.#e.queryId)).rows}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=ee){let r=await this.executeTakeFirst();if(r===void 0)throw fe(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,this.#e.queryId);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 Qt(t){return new Si(t)}var ki=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 R.create(this.#e.toOperationNode(),p.create(this.#t))}};var Ne=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]?Oe.cloneWithItems(t[o],e):Oe.create(e)})},cloneWithFilter(t,e){return i({...t,filter:t.filter?Q.cloneWithOperation(t.filter,"And",e):Q.create(e)})},cloneWithOrFilter(t,e){return i({...t,filter:t.filter?Q.cloneWithOperation(t.filter,"Or",e):Q.create(e)})},cloneWithOver(t,e){return i({...t,over:e})}});var Ei=i({is(t){return t.kind==="FunctionNode"},create(t,e){return i({kind:"FunctionNode",func:t,arguments:e})}});var pt=class t{#e;constructor(e){this.#e=i(e)}get expressionType(){}as(e){return new Ai(this,e)}distinct(){return new t({...this.#e,aggregateFunctionNode:Ne.cloneWithDistinct(this.#e.aggregateFunctionNode)})}orderBy(...e){return new t({...this.#e,aggregateFunctionNode:u.cloneWithOrderByItems(this.#e.aggregateFunctionNode,Z(e))})}clearOrderBy(){return new t({...this.#e,aggregateFunctionNode:u.cloneWithoutOrderBy(this.#e.aggregateFunctionNode)})}withinGroupOrderBy(...e){return new t({...this.#e,aggregateFunctionNode:Ne.cloneWithOrderBy(this.#e.aggregateFunctionNode,Z(e),!0)})}filterWhere(...e){return new t({...this.#e,aggregateFunctionNode:Ne.cloneWithFilter(this.#e.aggregateFunctionNode,O(e))})}filterWhereRef(e,r,o){return new t({...this.#e,aggregateFunctionNode:Ne.cloneWithFilter(this.#e.aggregateFunctionNode,I(e,r,o))})}over(e){let r=Io();return new t({...this.#e,aggregateFunctionNode:Ne.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}},Ai=class{#e;#t;constructor(e,r){this.#e=e,this.#t=r}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return R.create(this.#e.toOperationNode(),p.create(this.#t))}};function Nr(){let t=(r,o)=>new w(Ei.create(r,ge(o??[]))),e=(r,o)=>new pt({aggregateFunctionNode:Ne.create(r,o?ge(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 pt({aggregateFunctionNode:Ne.create("count",q(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 pt({aggregateFunctionNode:Ne.create("json_agg",[C(r)?N(r):r.toOperationNode()])})},toJson(r){return new w(Ei.create("to_json",[C(r)?N(r):r.toOperationNode()]))}})}var Po=i({is(t){return t.kind==="UnaryOperationNode"},create(t,e){return i({kind:"UnaryOperationNode",operator:t,operand:e})}});function Mo(t,e){return Po.create(Y.create(t),L(e))}var _=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),be.cloneWithResult(t.when[t.when.length-1],e)]):void 0})},cloneWith(t,e){return i({...t,...e})}});var ct=class{#e;constructor(e){this.#e=i(e)}when(...e){return new yr({...this.#e,node:_.cloneWithWhen(this.#e.node,be.create(O(e)))})}},yr=class{#e;constructor(e){this.#e=i(e)}then(e){return new Ri({...this.#e,node:_.cloneWithThen(this.#e.node,Yt(e)?Rt(e):g(e))})}},Ri=class{#e;constructor(e){this.#e=i(e)}when(...e){return new yr({...this.#e,node:_.cloneWithWhen(this.#e.node,be.create(O(e)))})}else(e){return new Ii({...this.#e,node:_.cloneWith(this.#e.node,{else:Yt(e)?Rt(e):g(e)})})}end(){return new w(_.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new w(_.cloneWith(this.#e.node,{isStatement:!0}))}},Ii=class{#e;constructor(e){this.#e=i(e)}end(){return new w(_.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new w(_.cloneWith(this.#e.node,{isStatement:!0}))}};var Di=i({is(t){return t.kind==="JSONPathLegNode"},create(t,e){return i({kind:"JSONPathLegNode",type:t,value:e})}});var ht=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 et.is(this.#e)?new wr(et.cloneWithTraversal(this.#e,Re.is(this.#e.traversal)?Re.cloneWithLeg(this.#e.traversal,Di.create(e,r)):jt.cloneWithValue(this.#e.traversal,k.createImmediate(r)))):new wr(Re.cloneWithLeg(this.#e,Di.create(e,r)))}},wr=class t extends ht{#e;constructor(e){super(e),this.#e=e}get expressionType(){}as(e){return new qi(this,e)}$castTo(){return new t(this.#e)}$notNull(){return new t(this.#e)}toOperationNode(){return this.#e}},qi=class{#e;#t;constructor(e,r){this.#e=e,this.#t=r}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return R.create(this.#e.toOperationNode(),b(this.#t)?this.#t.toOperationNode():p.create(this.#t))}};var Bi=i({is(t){return t.kind==="TupleNode"},create(t){return i({kind:"TupleNode",values:i(t)})}});var Mn=["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"],Fn=[/^varchar\(\d+\)$/,/^char\(\d+\)$/,/^decimal\(\d+, \d+\)$/,/^numeric\(\d+, \d+\)$/,/^binary\(\d+\)$/,/^datetime\(\d+\)$/,/^time\(\d+\)$/,/^timetz\(\d+\)$/,/^timestamp\(\d+\)$/,/^timestamptz\(\d+\)$/,/^varbinary\(\d+\)$/],Fo=i({is(t){return t.kind==="DataTypeNode"},create(t){return i({kind:"DataTypeNode",dataType:t})}});function zo(t){return!!(Mn.includes(t)||Fn.some(e=>e.test(t)))}function ue(t){if(b(t))return t.toOperationNode();if(zo(t))return Fo.create(t);throw new Error(`invalid column data type ${JSON.stringify(t)}`)}var Vo=i({is(t){return t.kind==="CastNode"},create(t,e){return i({kind:"CastNode",expression:t,dataType:e})}});function fr(t=Be){function e(n,a,d){return new w(Xt(n,a,d))}function r(n,a){return new w(Mo(n,a))}let o=Object.assign(e,{fn:void 0,eb:void 0,selectFrom(n){return Qt({queryId:l(),executor:t,queryNode:x.createFrom(ae(n))})},case(n){return new ct({node:_.create(j(n)?void 0:L(n))})},ref(n,a){return j(a)?new w(X(n)):new ht(co(n,a))},jsonPath(){return new ht(Re.create())},table(n){return new w(N(n))},val(n){return new w(g(n))},refTuple(...n){return new w(Bi.create(n.map(L)))},tuple(...n){return new w(Bi.create(n.map(g)))},lit(n){return new w(Rt(n))},unary:r,not(n){return r("not",n)},exists(n){return r("exists",n)},neg(n){return r("-",n)},between(n,a,d){return new w(Ee.create(L(n),Y.create("between"),J.create(g(a),g(d))))},betweenSymmetric(n,a,d){return new w(Ee.create(L(n),Y.create("between symmetric"),J.create(g(a),g(d))))},and(n){return P(n)?new w(rt(n,"and")):new w(ui(n,"and"))},or(n){return P(n)?new w(rt(n,"or")):new w(ui(n,"or"))},parens(...n){let a=O(n);return me.is(a)?new w(a):new w(me.create(a))},cast(n,a){return new w(Vo.create(L(n),ue(a)))},withSchema(n){return fr(t.withPluginAtFront(new te(n)))}});return o.fn=Nr(),o.eb=o,o}function ne(t){return fr()}function $(t){if(b(t))return t.toOperationNode();if(T(t))return t(ne()).toOperationNode();throw new Error(`invalid expression: ${JSON.stringify(t)}`)}function tr(t){if(b(t))return t.toOperationNode();if(T(t))return t(ne()).toOperationNode();throw new Error(`invalid aliased expression: ${JSON.stringify(t)}`)}function xe(t){return Ut(t)||oo(t)||T(t)}var xr=class{#e;get table(){return this.#e}constructor(e){this.#e=e}as(e){return new Li(this.#e,e)}},Li=class{#e;#t;get table(){return this.#e}get alias(){return this.#t}constructor(e,r){this.#e=e,this.#t=r}toOperationNode(){return R.create(N(this.#e),p.create(this.#t))}};function Uo(t){return B(t)&&b(t)&&C(t.table)&&C(t.alias)}function ae(t){return P(t)?t.map(e=>Je(e)):[Je(t)]}function Je(t){return C(t)?Ci(t):Uo(t)?t.toOperationNode():tr(t)}function Ci(t){let e=" as ";if(t.includes(e)){let[r,o]=t.split(e).map(Jo);return R.create(N(r),p.create(o))}else return N(t)}function N(t){let e=".";if(t.includes(e)){let[r,o]=t.split(e).map(Jo);return H.createWithSchema(r,o)}else return H.create(t)}function Jo(t){return t.trim()}var Qi=i({is(t){return t.kind==="AddColumnNode"},create(t){return i({kind:"AddColumnNode",column:t})}});var v=i({is(t){return t.kind==="ColumnDefinitionNode"},create(t,e){return i({kind:"ColumnDefinitionNode",column:m.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 Pi=i({is(t){return t.kind==="DropColumnNode"},create(t){return i({kind:"DropColumnNode",column:m.create(t)})}});var Mi=i({is(t){return t.kind==="RenameColumnNode"},create(t,e){return i({kind:"RenameColumnNode",column:m.create(t),renameTo:m.create(e)})}});var mt=i({is(t){return t.kind==="CheckConstraintNode"},create(t,e){return i({kind:"CheckConstraintNode",expression:t,name:e?p.create(e):void 0})}});var $o=["no action","restrict","cascade","set null","set default"],lt=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 gr(t){return b(t)?t.toOperationNode():k.createImmediate(t)}var Mt=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 Ko=i({is(t){return t.kind==="DefaultValueNode"},create(t){return i({kind:"DefaultValueNode",defaultValue:t})}});function ft(t){if($o.includes(t))return t;throw new Error(`invalid OnModifyForeignAction ${t}`)}var ve=class t{#e;constructor(e){this.#e=e}autoIncrement(){return new t(v.cloneWith(this.#e,{autoIncrement:!0}))}identity(){return new t(v.cloneWith(this.#e,{identity:!0}))}primaryKey(){return new t(v.cloneWith(this.#e,{primaryKey:!0}))}references(e){let r=X(e);if(!r.table||Ze.is(r.column))throw new Error(`invalid call references('${e}'). The reference must have format table.column or schema.table.column`);return new t(v.cloneWith(this.#e,{references:lt.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(v.cloneWith(this.#e,{references:lt.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(v.cloneWith(this.#e,{references:lt.cloneWithOnUpdate(this.#e.references,ft(e))}))}unique(){return new t(v.cloneWith(this.#e,{unique:!0}))}notNull(){return new t(v.cloneWith(this.#e,{notNull:!0}))}unsigned(){return new t(v.cloneWith(this.#e,{unsigned:!0}))}defaultTo(e){return new t(v.cloneWith(this.#e,{defaultTo:Ko.create(gr(e))}))}check(e){return new t(v.cloneWith(this.#e,{check:mt.create(e.toOperationNode())}))}generatedAlwaysAs(e){return new t(v.cloneWith(this.#e,{generated:Mt.createWithExpression(e.toOperationNode())}))}generatedAlwaysAsIdentity(){return new t(v.cloneWith(this.#e,{generated:Mt.create({identity:!0,always:!0})}))}generatedByDefaultAsIdentity(){return new t(v.cloneWith(this.#e,{generated:Mt.create({identity:!0,byDefault:!0})}))}stored(){if(!this.#e.generated)throw new Error("stored() can only be called after generatedAlwaysAs");return new t(v.cloneWith(this.#e,{generated:Mt.cloneWith(this.#e.generated,{stored:!0})}))}modifyFront(e){return new t(v.cloneWithFrontModifier(this.#e,e.toOperationNode()))}nullsNotDistinct(){return new t(v.cloneWith(this.#e,{nullsNotDistinct:!0}))}ifNotExists(){return new t(v.cloneWith(this.#e,{ifNotExists:!0}))}modifyEnd(e){return new t(v.cloneWithEndModifier(this.#e,e.toOperationNode()))}$call(e){return e(this)}toOperationNode(){return this.#e}};var Fi=i({is(t){return t.kind==="ModifyColumnNode"},create(t){return i({kind:"ModifyColumnNode",column:t})}});var de=i({is(t){return t.kind==="ForeignKeyConstraintNode"},create(t,e,r,o){return i({kind:"ForeignKeyConstraintNode",columns:t,references:lt.create(e,r),name:o?p.create(o):void 0})},cloneWith(t,e){return i({...t,...e})}});var Nt=class t{#e;constructor(e){this.#e=e}onDelete(e){return new t(de.cloneWith(this.#e,{onDelete:ft(e)}))}onUpdate(e){return new t(de.cloneWith(this.#e,{onUpdate:ft(e)}))}deferrable(){return new t(de.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new t(de.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new t(de.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new t(de.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}};var yt=i({is(t){return t.kind==="AddConstraintNode"},create(t){return i({kind:"AddConstraintNode",constraint:t})}});var ye=i({is(t){return t.kind==="UniqueConstraintNode"},create(t,e,r){return i({kind:"UniqueConstraintNode",columns:i(t.map(m.create)),name:e?p.create(e):void 0,nullsNotDistinct:r})},cloneWith(t,e){return i({...t,...e})}});var wt=i({is(t){return t.kind==="DropConstraintNode"},create(t){return i({kind:"DropConstraintNode",constraintName:p.create(t)})},cloneWith(t,e){return i({...t,...e})}});var xt=i({is(t){return t.kind==="AlterColumnNode"},create(t,e,r){return i({kind:"AlterColumnNode",column:m.create(t),[e]:r})}});var Ft=class{#e;constructor(e){this.#e=e}setDataType(e){return new Ke(xt.create(this.#e,"dataType",ue(e)))}setDefault(e){return new Ke(xt.create(this.#e,"setDefault",gr(e)))}dropDefault(){return new Ke(xt.create(this.#e,"dropDefault",!0))}setNotNull(){return new Ke(xt.create(this.#e,"setNotNull",!0))}dropNotNull(){return new Ke(xt.create(this.#e,"dropNotNull",!0))}$call(e){return e(this)}},Ke=class{#e;constructor(e){this.#e=e}toOperationNode(){return this.#e}};var Ce=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(),this.#e.queryId)}};var Or=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(f.cloneWithTableProps(this.#e.node,{addConstraint:yt.create(this.#e.constraintBuilder.toOperationNode())}),this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var zt=class t{#e;constructor(e){this.#e=i(e)}ifExists(){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{dropConstraint:wt.cloneWith(this.#e.node.dropConstraint,{ifExists:!0})})})}cascade(){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{dropConstraint:wt.cloneWith(this.#e.node.dropConstraint,{modifier:"cascade"})})})}restrict(){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{dropConstraint:wt.cloneWith(this.#e.node.dropConstraint,{modifier:"restrict"})})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var We=i({is(t){return t.kind==="PrimaryKeyConstraintNode"},create(t,e){return i({kind:"PrimaryKeyConstraintNode",columns:i(t.map(m.create)),name:e?p.create(e):void 0})},cloneWith(t,e){return i({...t,...e})}});var Qe=i({is(t){return t.kind==="AddIndexNode"},create(t){return i({kind:"AddIndexNode",name:p.create(t)})},cloneWith(t,e){return i({...t,...e})},cloneWithColumns(t,e){return i({...t,columns:[...t.columns||[],...e]})}});var br=class t{#e;constructor(e){this.#e=i(e)}unique(){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addIndex:Qe.cloneWith(this.#e.node.addIndex,{unique:!0})})})}column(e){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addIndex:Qe.cloneWithColumns(this.#e.node.addIndex,[tt(e)])})})}columns(e){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addIndex:Qe.cloneWithColumns(this.#e.node.addIndex,e.map(tt))})})}expression(e){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addIndex:Qe.cloneWithColumns(this.#e.node.addIndex,[e.toOperationNode()])})})}using(e){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addIndex:Qe.cloneWith(this.#e.node.addIndex,{using:W.createWithSql(e)})})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var gt=class t{#e;constructor(e){this.#e=e}nullsNotDistinct(){return new t(ye.cloneWith(this.#e,{nullsNotDistinct:!0}))}deferrable(){return new t(ye.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new t(ye.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new t(ye.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new t(ye.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}};var Ot=class t{#e;constructor(e){this.#e=e}deferrable(){return new t(We.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new t(We.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new t(We.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new t(We.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}};var bt=class{#e;constructor(e){this.#e=e}$call(e){return e(this)}toOperationNode(){return this.#e}};var Go=i({is(t){return t.kind==="RenameConstraintNode"},create(t,e){return i({kind:"RenameConstraintNode",oldName:p.create(t),newName:p.create(e)})}});var vr=class{#e;constructor(e){this.#e=i(e)}renameTo(e){return new Ce({...this.#e,node:f.cloneWithTableProps(this.#e.node,{renameTo:N(e)})})}setSchema(e){return new Ce({...this.#e,node:f.cloneWithTableProps(this.#e.node,{setSchema:p.create(e)})})}alterColumn(e,r){let o=r(new Ft(e));return new Ge({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,o.toOperationNode())})}dropColumn(e){return new Ge({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Pi.create(e))})}renameColumn(e,r){return new Ge({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Mi.create(e,r))})}addColumn(e,r,o=z){let n=o(new ve(v.create(e,ue(r))));return new Ge({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Qi.create(n.toOperationNode()))})}modifyColumn(e,r,o=z){let n=o(new ve(v.create(e,ue(r))));return new Ge({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Fi.create(n.toOperationNode()))})}addUniqueConstraint(e,r,o=z){let n=o(new gt(ye.create(r,e)));return new Ce({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addConstraint:yt.create(n.toOperationNode())})})}addCheckConstraint(e,r,o=z){let n=o(new bt(mt.create(r.toOperationNode(),e)));return new Ce({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addConstraint:yt.create(n.toOperationNode())})})}addForeignKeyConstraint(e,r,o,n,a=z){let d=a(new Nt(de.create(r.map(m.create),N(o),n.map(m.create),e)));return new Or({...this.#e,constraintBuilder:d})}addPrimaryKeyConstraint(e,r,o=z){let n=o(new Ot(We.create(r,e)));return new Ce({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addConstraint:yt.create(n.toOperationNode())})})}dropConstraint(e){return new zt({...this.#e,node:f.cloneWithTableProps(this.#e.node,{dropConstraint:wt.create(e)})})}renameConstraint(e,r){return new zt({...this.#e,node:f.cloneWithTableProps(this.#e.node,{renameConstraint:Go.create(e,r)})})}addIndex(e){return new br({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addIndex:Qe.create(e)})})}dropIndex(e){return new Ce({...this.#e,node:f.cloneWithTableProps(this.#e.node,{dropIndex:ke.create(e)})})}$call(e){return e(this)}},Ge=class t{#e;constructor(e){this.#e=i(e)}alterColumn(e,r){let o=r(new Ft(e));return new t({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,o.toOperationNode())})}dropColumn(e){return new t({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Pi.create(e))})}renameColumn(e,r){return new t({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Mi.create(e,r))})}addColumn(e,r,o=z){let n=o(new ve(v.create(e,ue(r))));return new t({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Qi.create(n.toOperationNode()))})}modifyColumn(e,r,o=z){let n=o(new ve(v.create(e,ue(r))));return new t({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Fi.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(),this.#e.queryId)}};var vt=class extends qe{transformPrimitiveValueList(e){return he.create(e.values.map(k.createImmediate))}transformValue(e){return k.createImmediate(e.value)}};var Cr=class t{#e;constructor(e){this.#e=i(e)}ifNotExists(){return new t({...this.#e,node:re.cloneWith(this.#e.node,{ifNotExists:!0})})}unique(){return new t({...this.#e,node:re.cloneWith(this.#e.node,{unique:!0})})}nullsNotDistinct(){return new t({...this.#e,node:re.cloneWith(this.#e.node,{nullsNotDistinct:!0})})}on(e){return new t({...this.#e,node:re.cloneWith(this.#e.node,{table:N(e)})})}column(e){return new t({...this.#e,node:re.cloneWithColumns(this.#e.node,[tt(e)])})}columns(e){return new t({...this.#e,node:re.cloneWithColumns(this.#e.node,e.map(tt))})}expression(e){return new t({...this.#e,node:re.cloneWithColumns(this.#e.node,[e.toOperationNode()])})}using(e){return new t({...this.#e,node:re.cloneWith(this.#e.node,{using:W.createWithSql(e)})})}where(...e){let r=new vt;return new t({...this.#e,node:u.cloneWithWhere(this.#e.node,r.transformNode(O(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(),this.#e.queryId)}};var Wr=class t{#e;constructor(e){this.#e=i(e)}ifNotExists(){return new t({...this.#e,node:Vt.cloneWith(this.#e.node,{ifNotExists:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};function jo(t){if(io.includes(t))return t;throw new Error(`invalid OnCommitAction ${t}`)}var Tr=class t{#e;constructor(e){this.#e=i(e)}temporary(){return new t({...this.#e,node:M.cloneWith(this.#e.node,{temporary:!0})})}onCommit(e){return new t({...this.#e,node:M.cloneWith(this.#e.node,{onCommit:jo(e)})})}ifNotExists(){return new t({...this.#e,node:M.cloneWith(this.#e.node,{ifNotExists:!0})})}addColumn(e,r,o=z){let n=o(new ve(v.create(e,ue(r))));return new t({...this.#e,node:M.cloneWithColumn(this.#e.node,n.toOperationNode())})}addPrimaryKeyConstraint(e,r,o=z){let n=o(new Ot(We.create(r,e)));return new t({...this.#e,node:M.cloneWithConstraint(this.#e.node,n.toOperationNode())})}addUniqueConstraint(e,r,o=z){let n=o(new gt(ye.create(r,e)));return new t({...this.#e,node:M.cloneWithConstraint(this.#e.node,n.toOperationNode())})}addCheckConstraint(e,r,o=z){let n=o(new bt(mt.create(r.toOperationNode(),e)));return new t({...this.#e,node:M.cloneWithConstraint(this.#e.node,n.toOperationNode())})}addForeignKeyConstraint(e,r,o,n,a=z){let d=a(new Nt(de.create(r.map(m.create),N(o),n.map(m.create),e)));return new t({...this.#e,node:M.cloneWithConstraint(this.#e.node,d.toOperationNode())})}modifyFront(e){return new t({...this.#e,node:M.cloneWithFrontModifier(this.#e.node,e.toOperationNode())})}modifyEnd(e){return new t({...this.#e,node:M.cloneWithEndModifier(this.#e.node,e.toOperationNode())})}as(e){return new t({...this.#e,node:M.cloneWith(this.#e.node,{selectQuery:$(e)})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var Sr=class t{#e;constructor(e){this.#e=i(e)}on(e){return new t({...this.#e,node:ke.cloneWith(this.#e.node,{table:N(e)})})}ifExists(){return new t({...this.#e,node:ke.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:ke.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var kr=class t{#e;constructor(e){this.#e=i(e)}ifExists(){return new t({...this.#e,node:Et.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:Et.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var Er=class t{#e;constructor(e){this.#e=i(e)}ifExists(){return new t({...this.#e,node:At.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:At.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var pe=i({is(t){return t.kind==="CreateViewNode"},create(t){return i({kind:"CreateViewNode",name:F.create(t)})},cloneWith(t,e){return i({...t,...e})}});var Ar=class{#e=new vt;transformQuery(e){return this.#e.transformNode(e.node,e.queryId)}transformResult(e){return Promise.resolve(e.result)}};var Rr=class t{#e;constructor(e){this.#e=i(e)}temporary(){return new t({...this.#e,node:pe.cloneWith(this.#e.node,{temporary:!0})})}materialized(){return new t({...this.#e,node:pe.cloneWith(this.#e.node,{materialized:!0})})}ifNotExists(){return new t({...this.#e,node:pe.cloneWith(this.#e.node,{ifNotExists:!0})})}orReplace(){return new t({...this.#e,node:pe.cloneWith(this.#e.node,{orReplace:!0})})}columns(e){return new t({...this.#e,node:pe.cloneWith(this.#e.node,{columns:e.map(ni)})})}as(e){let r=e.withPlugin(new Ar).toOperationNode();return new t({...this.#e,node:pe.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(),this.#e.queryId)}};var Ct=i({is(t){return t.kind==="DropViewNode"},create(t){return i({kind:"DropViewNode",name:F.create(t)})},cloneWith(t,e){return i({...t,...e})}});var Ir=class t{#e;constructor(e){this.#e=i(e)}materialized(){return new t({...this.#e,node:Ct.cloneWith(this.#e.node,{materialized:!0})})}ifExists(){return new t({...this.#e,node:Ct.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:Ct.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var Dr=i({is(t){return t.kind==="CreateTypeNode"},create(t){return i({kind:"CreateTypeNode",name:t})},cloneWithEnum(t,e){return i({...t,enum:he.create(e.map(k.createImmediate))})}});var qr=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:Dr.cloneWithEnum(this.#e.node,e)})}$call(e){return e(this)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var Br=i({is(t){return t.kind==="DropTypeNode"},create(t){return i({kind:"DropTypeNode",name:t})},cloneWith(t,e){return i({...t,...e})}});var Lr=class t{#e;constructor(e){this.#e=i(e)}ifExists(){return new t({...this.#e,node:Br.cloneWith(this.#e.node,{ifExists:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};function zi(t){let e=".";if(t.includes(e)){let r=t.split(e).map(zn);if(r.length===2)return F.createWithSchema(r[0],r[1]);throw new Error(`invalid schemable identifier ${t}`)}else return F.create(t)}function zn(t){return t.trim()}var Wt=i({is(t){return t.kind==="RefreshMaterializedViewNode"},create(t){return i({kind:"RefreshMaterializedViewNode",name:F.create(t)})},cloneWith(t,e){return i({...t,...e})}});var Qr=class t{#e;constructor(e){this.#e=i(e)}concurrently(){return new t({...this.#e,node:Wt.cloneWith(this.#e.node,{concurrently:!0,withNoData:!1})})}withData(){return new t({...this.#e,node:Wt.cloneWith(this.#e.node,{withNoData:!1})})}withNoData(){return new t({...this.#e,node:Wt.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(),this.#e.queryId)}};var Pr=class t{#e;constructor(e){this.#e=e}createTable(e){return new Tr({queryId:l(),executor:this.#e,node:M.create(N(e))})}dropTable(e){return new Er({queryId:l(),executor:this.#e,node:At.create(N(e))})}createIndex(e){return new Cr({queryId:l(),executor:this.#e,node:re.create(e)})}dropIndex(e){return new Sr({queryId:l(),executor:this.#e,node:ke.create(e)})}createSchema(e){return new Wr({queryId:l(),executor:this.#e,node:Vt.create(e)})}dropSchema(e){return new kr({queryId:l(),executor:this.#e,node:Et.create(e)})}alterTable(e){return new vr({queryId:l(),executor:this.#e,node:f.create(N(e))})}createView(e){return new Rr({queryId:l(),executor:this.#e,node:pe.create(e)})}refreshMaterializedView(e){return new Qr({queryId:l(),executor:this.#e,node:Wt.create(e)})}dropView(e){return new Ir({queryId:l(),executor:this.#e,node:Ct.create(e)})}createType(e){return new qr({queryId:l(),executor:this.#e,node:Dr.create(zi(e))})}dropType(e){return new Lr({queryId:l(),executor:this.#e,node:Br.create(zi(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 te(e)))}};var Mr=class{ref(e){return new $t(e)}table(e){return new xr(e)}};var Fr=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 zr=class t extends ut{#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 Vr(){return typeof performance<"u"&&T(performance.now)?performance.now():Date.now()}var Ur=class{#e;#t;#r;#i;#o;#a=new WeakSet;constructor(e,r){this.#i=!1,this.#e=e,this.#t=r}async init(){if(this.#o)throw new Error("driver has already been destroyed");this.#r||(this.#r=this.#e.init().then(()=>{this.#i=!0}).catch(e=>(this.#r=void 0,Promise.reject(e)))),await this.#r}async acquireConnection(){if(this.#o)throw new Error("driver has already been destroyed");this.#i||await this.init();let e=await this.#e.acquireConnection();return this.#a.has(e)||(this.#d()&&this.#n(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.#o||(this.#o=this.#e.destroy().catch(e=>(this.#o=void 0,Promise.reject(e)))),await this.#o)}#d(){return this.#t.isLevelEnabled("query")||this.#t.isLevelEnabled("error")}#n(e){let r=e.executeQuery,o=e.streamQuery,n=this;e.executeQuery=async a=>{let d,c=Vr();try{return await r.call(e,a)}catch(y){throw d=y,await n.#s(y,a,c),y}finally{d||await n.#u(a,c)}},e.streamQuery=async function*(a,d){let c,y=Vr();try{for await(let h of o.call(e,a,d))yield h}catch(h){throw c=h,await n.#s(h,a,y),h}finally{c||await n.#u(a,y,!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 Vr()-e}};var Vn=()=>{},Tt=class{#e;#t;constructor(e){this.#e=e}async provideConnection(e){for(;this.#t;)await this.#t.catch(Vn);return this.#t=this.#r(e).finally(()=>{this.#t=void 0}),this.#t}async#r(e){return await e(this.#e)}};var Un=["read only","read write"],Jn=["read uncommitted","read committed","repeatable read","serializable","snapshot"];function Vi(t){if(t.accessMode&&!Un.includes(t.accessMode))throw new Error(`invalid transaction access mode ${t.accessMode}`);if(t.isolationLevel&&!Jn.includes(t.isolationLevel))throw new Error(`invalid transaction isolation level ${t.isolationLevel}`)}var VC=i(["query","error"]),Jr=class{#e;#t;constructor(e){T(e)?(this.#t=e,this.#e=i({query:!0,error:!0})):(this.#t=$n,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 $n(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 Ho(t){return B(t)&&T(t.compile)}Symbol.asyncDispose??=Symbol("Symbol.asyncDispose");var St=class t extends dt{#e;constructor(e){let r,o;if(Kn(e))r={executor:e.executor},o={...e};else{let n=e.dialect,a=n.createDriver(),d=n.createQueryCompiler(),c=n.createAdapter(),y=new Jr(e.log??[]),h=new Ur(a,y),G=new Fr(h),E=new zr(d,c,G,e.plugins??[]);r={executor:E},o={config:e,executor:E,dialect:n,driver:h}}super(r),this.#e=i(o)}get schema(){return new Pr(this.#e.executor)}get dynamic(){return new Mr}get introspection(){return this.#e.dialect.createIntrospector(this.withoutPlugins())}case(e){return new ct({node:_.create(j(e)?void 0:$(e))})}get fn(){return Nr()}transaction(){return new Ji({...this.#e})}startTransaction(){return new $i({...this.#e})}connection(){return new Ui({...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 te(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=l()){let o=Ho(e)?e.compile():e;return this.getExecutor().executeQuery(o,r)}async[Symbol.asyncDispose](){await this.destroy()}},$r=class t extends St{#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 te(e))})}withTables(){return new t({...this.#e})}};function Kn(t){return B(t)&&B(t.config)&&B(t.driver)&&B(t.executor)&&B(t.dialect)}var Ui=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 Tt(r)),n=new St({...this.#e,executor:o});return await e(n)})}},Ji=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,a={isolationLevel:r,accessMode:o};return Vi(a),this.#e.executor.provideConnection(async d=>{let c=this.#e.executor.withConnectionProvider(new Tt(d)),y=new $r({...n,executor:c});try{await this.#e.driver.beginTransaction(d,a);let h=await e(y);return await this.#e.driver.commitTransaction(d),h}catch(h){throw await this.#e.driver.rollbackTransaction(d),h}})}},$i=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};Vi(n);let a=await pr(this.#e.executor);return await this.#e.driver.beginTransaction(a.connection,n),new Ki({...o,connection:a,executor:this.#e.executor.withConnectionProvider(new Tt(a.connection))})}},Ki=class t extends $r{#e;#t;#r;constructor(e){let r={isCommitted:!1,isRolledBack:!1};e={...e,executor:new Gi(e.executor,r)};let{connection:o,...n}=e;super(n),this.#e=i(e),this.#r=r;let a=l();this.#t=d=>e.executor.compileQuery(d,a)}get isCommitted(){return this.#r.isCommitted}get isRolledBack(){return this.#r.isRolledBack}commit(){return He(this.#r),new je(async()=>{await this.#e.driver.commitTransaction(this.#e.connection.connection),this.#r.isCommitted=!0,this.#e.connection.release()})}rollback(){return He(this.#r),new je(async()=>{await this.#e.driver.rollbackTransaction(this.#e.connection.connection),this.#r.isRolledBack=!0,this.#e.connection.release()})}savepoint(e){return He(this.#r),new je(async()=>(await this.#e.driver.savepoint?.(this.#e.connection.connection,e,this.#t),new t({...this.#e})))}rollbackToSavepoint(e){return He(this.#r),new je(async()=>(await this.#e.driver.rollbackToSavepoint?.(this.#e.connection.connection,e,this.#t),new t({...this.#e})))}releaseSavepoint(e){return He(this.#r),new je(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 te(e))})}withTables(){return new t({...this.#e})}},je=class{#e;constructor(e){this.#e=e}async execute(){return await this.#e()}};function He(t){if(t.isCommitted)throw new Error("Transaction is already committed");if(t.isRolledBack)throw new Error("Transaction is already rolled back")}var Gi=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,r){return He(this.#t),this.#e.executeQuery(e,r)}stream(e,r,o){return He(this.#t),this.#e.stream(e,r,o)}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 ji=class t{#e;constructor(e){this.#e=i(e)}get expressionType(){}get isRawBuilder(){return!0}as(e){return new Hi(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.#i(this.#t(e))}async execute(e){let r=this.#t(e);return r.executeQuery(this.#i(r),this.#e.queryId)}#t(e){let r=e!==void 0?e.getExecutor():Be;return this.#e.plugins!==void 0?r.withPlugins(this.#e.plugins):r}#r(e){return e.transformQuery(this.#e.rawNode,this.#e.queryId)}#i(e){return e.compileQuery(this.#r(e),this.#e.queryId)}};function Te(t){return new ji(t)}var Hi=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 R.create(this.#e.toOperationNode(),b(this.#t)?this.#t.toOperationNode():p.create(this.#t))}};var K=Object.assign((t,...e)=>Te({queryId:l(),rawNode:W.create(t,e?.map(Yo)??[])}),{ref(t){return Te({queryId:l(),rawNode:W.createWithChild(X(t))})},val(t){return Te({queryId:l(),rawNode:W.createWithChild(g(t))})},value(t){return this.val(t)},table(t){return Te({queryId:l(),rawNode:W.createWithChild(N(t))})},id(...t){let e=new Array(t.length+1).fill(".");return e[0]="",e[e.length-1]="",Te({queryId:l(),rawNode:W.create(e,t.map(p.create))})},lit(t){return Te({queryId:l(),rawNode:W.createWithChild(k.createImmediate(t))})},literal(t){return this.lit(t)},raw(t){return Te({queryId:l(),rawNode:W.createWithSql(t)})},join(t,e=K`, `){let r=new Array(Math.max(2*t.length-1,0)),o=e.toOperationNode();for(let n=0;n<t.length;++n)r[2*n]=Yo(t[n]),n!==t.length-1&&(r[2*n+1]=o);return Te({queryId:l(),rawNode:W.createWithChildren(r)})}});function Yo(t){return b(t)?t.toOperationNode():g(t)}var Kr=class{nodeStack=[];get parentNode(){return this.nodeStack[this.nodeStack.length-2]}#e=i({AliasNode:this.visitAlias.bind(this),ColumnNode:this.visitColumn.bind(this),IdentifierNode:this.visitIdentifier.bind(this),SchemableIdentifierNode:this.visitSchemableIdentifier.bind(this),RawNode:this.visitRaw.bind(this),ReferenceNode:this.visitReference.bind(this),SelectQueryNode:this.visitSelectQuery.bind(this),SelectionNode:this.visitSelection.bind(this),TableNode:this.visitTable.bind(this),FromNode:this.visitFrom.bind(this),SelectAllNode:this.visitSelectAll.bind(this),AndNode:this.visitAnd.bind(this),OrNode:this.visitOr.bind(this),ValueNode:this.visitValue.bind(this),ValueListNode:this.visitValueList.bind(this),PrimitiveValueListNode:this.visitPrimitiveValueList.bind(this),ParensNode:this.visitParens.bind(this),JoinNode:this.visitJoin.bind(this),OperatorNode:this.visitOperator.bind(this),WhereNode:this.visitWhere.bind(this),InsertQueryNode:this.visitInsertQuery.bind(this),DeleteQueryNode:this.visitDeleteQuery.bind(this),ReturningNode:this.visitReturning.bind(this),CreateTableNode:this.visitCreateTable.bind(this),AddColumnNode:this.visitAddColumn.bind(this),ColumnDefinitionNode:this.visitColumnDefinition.bind(this),DropTableNode:this.visitDropTable.bind(this),DataTypeNode:this.visitDataType.bind(this),OrderByNode:this.visitOrderBy.bind(this),OrderByItemNode:this.visitOrderByItem.bind(this),GroupByNode:this.visitGroupBy.bind(this),GroupByItemNode:this.visitGroupByItem.bind(this),UpdateQueryNode:this.visitUpdateQuery.bind(this),ColumnUpdateNode:this.visitColumnUpdate.bind(this),LimitNode:this.visitLimit.bind(this),OffsetNode:this.visitOffset.bind(this),OnConflictNode:this.visitOnConflict.bind(this),OnDuplicateKeyNode:this.visitOnDuplicateKey.bind(this),CreateIndexNode:this.visitCreateIndex.bind(this),DropIndexNode:this.visitDropIndex.bind(this),ListNode:this.visitList.bind(this),PrimaryKeyConstraintNode:this.visitPrimaryKeyConstraint.bind(this),UniqueConstraintNode:this.visitUniqueConstraint.bind(this),ReferencesNode:this.visitReferences.bind(this),CheckConstraintNode:this.visitCheckConstraint.bind(this),WithNode:this.visitWith.bind(this),CommonTableExpressionNode:this.visitCommonTableExpression.bind(this),CommonTableExpressionNameNode:this.visitCommonTableExpressionName.bind(this),HavingNode:this.visitHaving.bind(this),CreateSchemaNode:this.visitCreateSchema.bind(this),DropSchemaNode:this.visitDropSchema.bind(this),AlterTableNode:this.visitAlterTable.bind(this),DropColumnNode:this.visitDropColumn.bind(this),RenameColumnNode:this.visitRenameColumn.bind(this),AlterColumnNode:this.visitAlterColumn.bind(this),ModifyColumnNode:this.visitModifyColumn.bind(this),AddConstraintNode:this.visitAddConstraint.bind(this),DropConstraintNode:this.visitDropConstraint.bind(this),RenameConstraintNode:this.visitRenameConstraint.bind(this),ForeignKeyConstraintNode:this.visitForeignKeyConstraint.bind(this),CreateViewNode:this.visitCreateView.bind(this),RefreshMaterializedViewNode:this.visitRefreshMaterializedView.bind(this),DropViewNode:this.visitDropView.bind(this),GeneratedNode:this.visitGenerated.bind(this),DefaultValueNode:this.visitDefaultValue.bind(this),OnNode:this.visitOn.bind(this),ValuesNode:this.visitValues.bind(this),SelectModifierNode:this.visitSelectModifier.bind(this),CreateTypeNode:this.visitCreateType.bind(this),DropTypeNode:this.visitDropType.bind(this),ExplainNode:this.visitExplain.bind(this),DefaultInsertValueNode:this.visitDefaultInsertValue.bind(this),AggregateFunctionNode:this.visitAggregateFunction.bind(this),OverNode:this.visitOver.bind(this),PartitionByNode:this.visitPartitionBy.bind(this),PartitionByItemNode:this.visitPartitionByItem.bind(this),SetOperationNode:this.visitSetOperation.bind(this),BinaryOperationNode:this.visitBinaryOperation.bind(this),UnaryOperationNode:this.visitUnaryOperation.bind(this),UsingNode:this.visitUsing.bind(this),FunctionNode:this.visitFunction.bind(this),CaseNode:this.visitCase.bind(this),WhenNode:this.visitWhen.bind(this),JSONReferenceNode:this.visitJSONReference.bind(this),JSONPathNode:this.visitJSONPath.bind(this),JSONPathLegNode:this.visitJSONPathLeg.bind(this),JSONOperatorChainNode:this.visitJSONOperatorChain.bind(this),TupleNode:this.visitTuple.bind(this),MergeQueryNode:this.visitMergeQuery.bind(this),MatchedNode:this.visitMatched.bind(this),AddIndexNode:this.visitAddIndex.bind(this),CastNode:this.visitCast.bind(this),FetchNode:this.visitFetch.bind(this),TopNode:this.visitTop.bind(this),OutputNode:this.visitOutput.bind(this),OrActionNode:this.visitOrAction.bind(this),CollateNode:this.visitCollate.bind(this)});visitNode=e=>{this.nodeStack.push(e),this.#e[e.kind](e),this.nodeStack.pop()}};var Gn=/'/g,Gr=class extends Kr{#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&&!me.is(this.parentNode)&&!S.is(this.parentNode)&&!M.is(this.parentNode)&&!pe.is(this.parentNode)&&!lr.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]),n<o&&this.append(r)}visitWhere(e){this.append("where "),this.visitNode(e.where)}visitHaving(e){this.append("having "),this.visitNode(e.having)}visitInsertQuery(e){let r=this.nodeStack.find(u.is),o=r!==e;!o&&e.explain&&(this.visitNode(e.explain),this.append(" ")),o&&!D.is(r)&&this.append("("),e.with&&(this.visitNode(e.with),this.append(" ")),this.append(e.replace?"replace":"insert"),e.ignore&&(Ae("`InsertQueryNode.ignore` is deprecated. Use `InsertQueryNode.orAction` instead."),this.append(" ignore")),e.orAction&&(this.append(" "),this.visitNode(e.orAction)),e.top&&(this.append(" "),this.visitNode(e.top)),e.into&&(this.append(" into "),this.visitNode(e.into)),e.columns&&(this.append(" ("),this.compileList(e.columns),this.append(")")),e.output&&(this.append(" "),this.visitNode(e.output)),e.values&&(this.append(" "),this.visitNode(e.values)),e.defaultValues&&(this.append(" "),this.append("default values")),e.onConflict&&(this.append(" "),this.visitNode(e.onConflict)),e.onDuplicateKey&&(this.append(" "),this.visitNode(e.onDuplicateKey)),e.returning&&(this.append(" "),this.visitNode(e.returning)),o&&!D.is(r)&&this.append(")"),e.endModifiers?.length&&(this.append(" "),this.compileList(e.endModifiers," "))}visitValues(e){this.append("values "),this.compileList(e.values)}visitDeleteQuery(e){let r=this.nodeStack.find(u.is)!==e;!r&&e.explain&&(this.visitNode(e.explain),this.append(" ")),r&&this.append("("),e.with&&(this.visitNode(e.with),this.append(" ")),this.append("delete "),e.top&&(this.visitNode(e.top),this.append(" ")),this.visitNode(e.from),e.output&&(this.append(" "),this.visitNode(e.output)),e.using&&(this.append(" "),this.visitNode(e.using)),e.joins&&(this.append(" "),this.compileList(e.joins," ")),e.where&&(this.append(" "),this.visitNode(e.where)),e.orderBy&&(this.append(" "),this.visitNode(e.orderBy)),e.limit&&(this.append(" "),this.visitNode(e.limit)),e.returning&&(this.append(" "),this.visitNode(e.returning)),r&&this.append(")"),e.endModifiers?.length&&(this.append(" "),this.compileList(e.endModifiers," "))}visitReturning(e){this.append("returning "),this.compileList(e.selections)}visitAlias(e){this.visitNode(e.node),this.append(" as "),this.visitNode(e.alias)}visitReference(e){e.table&&(this.visitNode(e.table),this.append(".")),this.visitNode(e.column)}visitSelectAll(e){this.append("*")}visitIdentifier(e){this.append(this.getLeftIdentifierWrapper()),this.compileUnwrappedIdentifier(e),this.append(this.getRightIdentifierWrapper())}compileUnwrappedIdentifier(e){if(!C(e.name))throw new Error("a non-string identifier was passed to compileUnwrappedIdentifier.");this.append(this.sanitizeIdentifier(e.name))}visitAnd(e){this.visitNode(e.left),this.append(" and "),this.visitNode(e.right)}visitOr(e){this.visitNode(e.left),this.append(" or "),this.visitNode(e.right)}visitValue(e){e.immediate?this.appendImmediateValue(e.value):this.appendValue(e.value)}visitValueList(e){this.append("("),this.compileList(e.values),this.append(")")}visitTuple(e){this.append("("),this.compileList(e.values),this.append(")")}visitPrimitiveValueList(e){this.append("(");let{values:r}=e;for(let o=0;o<r.length;++o)this.appendValue(r[o]),o!==r.length-1&&this.append(", ");this.append(")")}visitParens(e){this.append("("),this.visitNode(e.node),this.append(")")}visitJoin(e){this.append(Hn[e.joinType]),this.append(" "),this.visitNode(e.table),e.on&&(this.append(" "),this.visitNode(e.on))}visitOn(e){this.append("on "),this.visitNode(e.on)}visitRaw(e){let{sqlFragments:r,parameters:o}=e;for(let n=0;n<r.length;++n)this.append(r[n]),o.length>n&&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.nodeStack.find(u.is),o=r!==e;if(!o&&e.explain&&(this.visitNode(e.explain),this.append(" ")),o&&!D.is(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)),o&&!D.is(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 "),ze(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(jn[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 Y.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<o;r++)r===o-1?this.visitNode(e.operator):this.append("->"),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 a of e)n+=a,a===r?n+=r:a===o&&(n+=o);return n}sanitizeStringLiteral(e){return e.replace(Gn,"''")}addParameter(e){this.#t.push(e)}appendImmediateValue(e){if(C(e))this.appendStringLiteral(e);else if(Se(e)||ze(e))this.append(e.toString());else if(Ye(e))this.append("null");else if(ro(e))this.appendImmediateValue(e.toISOString());else if(Xe(e))this.appendImmediateValue(e.toString());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?Xo[r.modifier]-Xo[o.modifier]:1),i(e)}compileColumnAlterations(e){this.compileList(e)}announcesNewColumnDataType(){return!0}},jn=i({ForKeyShare:"for key share",ForNoKeyUpdate:"for no key update",ForUpdate:"for update",ForShare:"for share",NoWait:"nowait",SkipLocked:"skip locked",Distinct:"distinct"}),Xo=i({ForKeyShare:1,ForNoKeyUpdate:1,ForUpdate:1,ForShare:1,NoWait:2,SkipLocked:2,Distinct:0}),Hn=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 jr=class{async init(){}async acquireConnection(){return new Yi}async beginTransaction(){}async commitTransaction(){}async rollbackTransaction(){}async releaseConnection(){}async destroy(){}async releaseSavepoint(){}async rollbackToSavepoint(){}async savepoint(){}},Yi=class{async executeQuery(){return{rows:[]}}async*streamQuery(){}};var Hr=class{get supportsCreateIfNotExists(){return!0}get supportsTransactionalDdl(){return!1}get supportsReturning(){return!1}get supportsOutput(){return!1}};var Yn=/"/g,Yr=class extends Gr{sanitizeIdentifier(e){return e.replace(Yn,'""')}};var Xn=BigInt("3853314791062309107"),Xr=class extends Hr{get supportsTransactionalDdl(){return!0}get supportsReturning(){return!0}async acquireMigrationLock(e,r){await K`select pg_advisory_xact_lock(${K.lit(Xn)})`.execute(e)}async releaseMigrationLock(e,r){}};function Zo(t){return new St({dialect:{createAdapter:()=>new t.Adapter,createDriver:()=>new jr,createIntrospector:()=>null,createQueryCompiler:()=>new t.QueryCompiler},plugins:[...t.noParameters?[new Xi]:[]]})}var Xi=class{#e=new Zi;transformQuery(e){return this.#e.transformNode(e.node)}transformResult(e){return Promise.resolve(e.result)}},Zi=class extends qe{transformPrimitiveValueList(e){return he.create(e.values.map(k.createImmediate))}transformValue(e){return{...super.transformValue(e),immediate:!0}}};function Pe(t){let e=t.compile();return{parameters:e.parameters,sql:e.sql}}function _i(t,e){let r=_n(t,e);return o=>o.where(n=>n.or(r.map(a=>n.and(a.map(([d,c])=>n(d,c===null?"is":"=",c))))))}function Zn(t,e){return Object.entries(Object.values(e).reduce((r,o)=>{let{isInPrimaryKey:n,name:a}=o;return n&&(r[a]=t[a]),r},{}))}function _n(t,e){return t.map(r=>Zn(r,e))}function Me(t){return Zo({...t,Adapter:Xr,QueryCompiler:Yr})}function _o(t,e){let{table:r,rows:o}=t,{name:n,schema:a,columns:d}=r,c=Me(e),y=Object.values(d).map(({name:h})=>`${n}.${h}`);return Pe(c.withSchema(a).insertInto(n).values(o).returning(y).returning(h=>h.cast("ctid","text").as("ctid")))}function en(t,e){let{pageIndex:r,pageSize:o,sortOrder:n,table:{name:a,schema:d,columns:c}}=t,y=Me(e),h=Object.values(c).map(({name:E})=>`${a}.${E}`),G=y.withSchema(d).selectFrom(a).select(E=>E.cast(E.fn.coalesce(E.fn.countAll(),K.lit(0)),"text").as("value"));return Pe(y.with("count",()=>G).withSchema(d).selectFrom([a,"count"]).select(K.ref("count.value").$castTo().as("oid")).select(E=>E.cast("ctid","text").as("ctid")).select(h).$call(E=>n.reduce((U,Fe)=>U.orderBy(Fe.column,Fe.direction),E)).limit(o).offset(K.lit(BigInt(r)*BigInt(o))))}function tn(t,e){let{changes:r,row:o,table:{columns:n,name:a,schema:d}}=t,c=Me(e),y=Object.values(n).map(({name:h})=>`${a}.${h}`);return Pe(c.withSchema(d).updateTable(a).set(r).$call(_i([o],n)).returning(y).returning(h=>[h.cast("ctid","text").as("ctid"),h.cast(h.fn("floor",[h(h.fn("extract",[K`epoch from now()`]),"*",1e6)]),"text").as("__ps_updated_at__")]))}function rn(t,e){let{rows:r,table:{columns:o,name:n,schema:a}}=t,d=Me(e);return Pe(d.withSchema(a).deleteFrom(n).$call(_i(r,o)))}function on(t){return K`(select coalesce(json_agg(agg), '[]') from ${t} as agg)`}var es="r",ts="v",rs=[es,ts];function nn(t){return Pe(Me(t).selectFrom("pg_catalog.pg_class as cls").innerJoin("pg_catalog.pg_namespace as ns","cls.relnamespace","ns.oid").$call(is).where("cls.relkind","in",rs).select(e=>["ns.nspname as schema","cls.relname as name",on(e.selectFrom("pg_catalog.pg_attribute as att").innerJoin("pg_catalog.pg_type as typ","typ.oid","att.atttypid").innerJoin("pg_catalog.pg_namespace as tns","tns.oid","typ.typnamespace").leftJoin("pg_catalog.pg_constraint as con",r=>r.on("con.contype","=","p").onRef("con.conrelid","=","cls.oid").on(o=>o("att.attnum","=",o.fn.any("con.conkey")))).whereRef("att.attrelid","=","cls.oid").where("att.attnum",">=",0).where("att.attisdropped","!=",!0).where("att.attgenerated","=","").select(["att.attname as name","typ.typname as datatype","tns.nspname as datatype_schema"]).select(r=>[r("con.conkey","is not",null).$castTo().as("pk"),r("att.attgenerated","!=","").$castTo().as("computed"),r("att.attnotnull","!=",!0).$castTo().as("nullable"),r.fn.coalesce(r.selectFrom("pg_catalog.pg_enum as enm").whereRef("enm.enumtypid","=","typ.oid").select(o=>o.fn.jsonAgg(o.ref("enm.enumlabel")).as("o")),K`'[]'`).as("options")])).as("columns")]))}function sn(){let t=Me();return Pe(t.selectNoFrom(t.fn("current_setting",[K.lit("timezone")]).as("timezone")))}function is(t){return t.where("ns.nspname","!~","^pg_").where("ns.nspname","!=","information_schema")}function an(t){let{executor:e,...r}=t;return{defaultSchema:"public",async introspect(o){try{let n=nn(r),a=sn(),[[d,c],[y,h]]=await Promise.all([e.execute(n,o),e.execute(a,o)]),G=d||y;if(G)return[G];let[E]=h;return E?[null,os(c,E.timezone)]:[new Error("Timezone not found")]}catch(n){return[n]}},async query(o,n){try{let a=en(o,r),[d,c]=await e.execute(a,n);return d?[d]:[null,{filteredRowCount:c[0]?.oid||"0",rows:c}]}catch(a){return[a]}},async insert(o,n){try{let a=_o(o,r),[d,c]=await e.execute(a,n);return d?[d]:[null,{rows:c}]}catch(a){return[a]}},async update(o,n){try{let a=tn(o,r),[d,c]=await e.execute(a,n);if(d)return[d];let[y]=c;return y?[null,{row:y}]:[new Error("Update failed")]}catch(a){return[a]}},async delete(o,n){try{let a=rn(o,r),[d]=await e.execute(a,n);return d?[d]:[null,o]}catch(a){return[a]}}}}function os(t,e){return t.reduce((r,o)=>{let{schemas:n}=r,{columns:a,name:d,schema:c}=o,y=a.reduce((h,G)=>{let{datatype:E,datatype_schema:U,name:Fe,options:eo,nullable:dn}=G,Zr=E.startsWith("_"),_r=Zr?E.slice(1):E;return{...h,[Fe]:{datatype:{...to[_r]||{group:eo.length>0?"enum":"raw"},isArray:Zr,isNative:U==="pg_catalog",name:Zr?`${_r}[]`:_r,options:eo,schema:U},isComputed:G.computed,isInPrimaryKey:G.pk,name:Fe,nullable:dn,schema:c,table:d}}},{});return(n[c]||={tables:{}}).tables[d]={columns:y,name:d,schema:c},r},{schemas:{public:{tables:{}}},timezone:e})}function un(t,e){let{addDelay:r=0}=e??{};return{execute:async(o,n)=>{let{abortSignal:a}=n||{},d,c=new Promise((U,Fe)=>d=Fe);function y(){let U=new Error("This operation was aborted");U.name="AbortError",d(U)}a?.addEventListener("abort",y);let h=typeof r=="function"?r(o):r,G=()=>t.query(o.sql,o.parameters,{rowMode:"object"}),E=h>0?()=>new Promise(U=>setTimeout(U,h)).then(()=>G()):G;try{return[null,(await Promise.race([E(),c])).rows]}catch(U){return[U]}finally{a?.removeEventListener("abort",y)}}}}function ns(t,e){return an({executor:un(t,e)})}0&&(module.exports={createPGLiteAdapter,createPGLiteExecutor});
|
|
1
|
+
"use strict";var ei=Object.defineProperty;var pn=Object.getOwnPropertyDescriptor;var cn=Object.getOwnPropertyNames;var hn=Object.prototype.hasOwnProperty;var mn=(t,e)=>{for(var r in e)ei(t,r,{get:e[r],enumerable:!0})},ln=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of cn(e))!hn.call(t,n)&&n!==r&&ei(t,n,{get:()=>e[n],enumerable:!(o=pn(e,n))||o.enumerable});return t};var fn=t=>ln(ei({},"__esModule",{value:!0}),t);var ss={};mn(ss,{createPGLiteAdapter:()=>ns,createPGLiteExecutor:()=>un});module.exports=fn(ss);var to={bool:{group:"boolean"},boolean:{group:"boolean"},bytea:{group:"string"},char:{group:"string"},citext:{group:"string"},date:{group:"datetime"},interval:{group:"string"},name:{group:"string"},varchar:{group:"string"},text:{group:"string"},time:{group:"time"},timestamp:{group:"datetime"},timestamptz:{group:"datetime"},"timestamp without time zone":{group:"datetime"},"timestamp with time zone":{group:"datetime"},timetz:{group:"time"},"time without time zone":{group:"time"},"time with time zone":{group:"datetime"},uuid:{group:"string"},int2:{group:"numeric"},int4:{group:"numeric"},int8:{group:"numeric"},smallint:{group:"numeric"},integer:{group:"numeric"},bigint:{group:"numeric"},decimal:{group:"numeric"},numeric:{group:"numeric"},real:{group:"numeric"},float4:{group:"numeric"},float8:{group:"numeric"},"double precision":{group:"numeric"}};function j(t){return typeof t>"u"||t===void 0}function C(t){return typeof t=="string"}function Se(t){return typeof t=="number"}function ze(t){return typeof t=="boolean"}function Ye(t){return t===null}function ro(t){return t instanceof Date}function Xe(t){return typeof t=="bigint"}function T(t){return typeof t=="function"}function B(t){return typeof t=="object"&&t!==null}function i(t){return Object.freeze(t)}function kt(t){return P(t)?t:[t]}function P(t){return Array.isArray(t)}function z(t){return t}var f=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 p=i({is(t){return t.kind==="IdentifierNode"},create(t){return i({kind:"IdentifierNode",name:t})}});var re=i({is(t){return t.kind==="CreateIndexNode"},create(t){return i({kind:"CreateIndexNode",name:p.create(t)})},cloneWith(t,e){return i({...t,...e})},cloneWithColumns(t,e){return i({...t,columns:[...t.columns||[],...e]})}});var Vt=i({is(t){return t.kind==="CreateSchemaNode"},create(t,e){return i({kind:"CreateSchemaNode",schema:p.create(t),...e})},cloneWith(t,e){return i({...t,...e})}});var io=["preserve rows","delete rows","drop"],M=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 F=i({is(t){return t.kind==="SchemableIdentifierNode"},create(t){return i({kind:"SchemableIdentifierNode",identifier:p.create(t)})},createWithSchema(t,e){return i({kind:"SchemableIdentifierNode",schema:p.create(t),identifier:p.create(e)})}});var ke=i({is(t){return t.kind==="DropIndexNode"},create(t,e){return i({kind:"DropIndexNode",name:F.create(t),...e})},cloneWith(t,e){return i({...t,...e})}});var Et=i({is(t){return t.kind==="DropSchemaNode"},create(t,e){return i({kind:"DropSchemaNode",schema:p.create(t),...e})},cloneWith(t,e){return i({...t,...e})}});var At=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 R=i({is(t){return t.kind==="AliasNode"},create(t,e){return i({kind:"AliasNode",node:t,alias:e})}});var H=i({is(t){return t.kind==="TableNode"},create(t){return i({kind:"TableNode",table:F.create(t)})},createWithSchema(t,e){return i({kind:"TableNode",table:F.createWithSchema(t,e)})}});function b(t){return B(t)&&T(t.toOperationNode)}function Ut(t){return B(t)&&"expressionType"in t&&b(t)}function oo(t){return B(t)&&"expression"in t&&C(t.alias)&&b(t)}var ce=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 J=i({is(t){return t.kind==="AndNode"},create(t,e){return i({kind:"AndNode",left:t,right:e})}});var ie=i({is(t){return t.kind==="OrNode"},create(t,e){return i({kind:"OrNode",left:t,right:e})}});var Jt=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"?J.create(t.on,r):ie.create(t.on,r)})}});var we=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:Jt.create(r)})},cloneWithOn(t,e){return i({...t,on:t.on?Jt.cloneWithOperation(t.on,"And",e):Jt.create(e)})}});var Ee=i({is(t){return t.kind==="BinaryOperationNode"},create(t,e,r){return i({kind:"BinaryOperationNode",leftOperand:t,operator:e,rightOperand:r})}});var Nn=["=","==","!=","<>",">",">=","<","<=","in","not in","is","is not","like","not like","match","ilike","not ilike","@>","<@","^@","&&","?","?&","?|","!<","!>","<=>","!~","~","~*","!~*","@@","@@@","!!","<->","regexp","is distinct from","is not distinct from"],yn=["+","-","*","/","%","^","&","|","#","<<",">>"],no=["->","->>"],wn=[...Nn,...yn,"&&","||"],xn=["exists","not exists"],gn=["not","-",...xn],so=[...wn,...no,...gn,"between","between symmetric"],Y=i({is(t){return t.kind==="OperatorNode"},create(t){return i({kind:"OperatorNode",operator:t})}});function ti(t){return C(t)&&no.includes(t)}var m=i({is(t){return t.kind==="ColumnNode"},create(t){return i({kind:"ColumnNode",column:p.create(t)})}});var Ze=i({is(t){return t.kind==="SelectAllNode"},create(){return i({kind:"SelectAllNode"})}});var _e=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:Ze.create()})}});var $t=class{#e;get dynamicReference(){return this.#e}get refType(){}constructor(e){this.#e=e}toOperationNode(){return ri(this.#e)}};function Kt(t){return B(t)&&b(t)&&C(t.dynamicReference)}var oe=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 W=i({is(t){return t.kind==="RawNode"},create(t,e){return i({kind:"RawNode",sqlFragments:i(t),parameters:i(e)})},createWithSql(t){return W.create([t],[])},createWithChild(t){return W.create(["",""],[t])},createWithChildren(t){return W.create(new Array(t.length+1).fill(""),t)}});var ao={is(t){return t.kind==="CollateNode"},create(t){return i({kind:"CollateNode",collation:p.create(t)})}};var Gt=class t{#e;constructor(e){this.#e=i(e)}desc(){return new t({node:oe.cloneWith(this.#e.node,{direction:W.createWithSql("desc")})})}asc(){return new t({node:oe.cloneWith(this.#e.node,{direction:W.createWithSql("asc")})})}nullsLast(){return new t({node:oe.cloneWith(this.#e.node,{nulls:"last"})})}nullsFirst(){return new t({node:oe.cloneWith(this.#e.node,{nulls:"first"})})}collate(e){return new t({node:oe.cloneWith(this.#e.node,{collation:ao.create(e)})})}toOperationNode(){return this.#e.node}};var uo=new Set;function Ae(t){uo.has(t)||(uo.add(t),console.log(t))}function oi(t){return t==="asc"||t==="desc"}function Z(t){if(t.length===2)return[ii(t[0],t[1])];if(t.length===1){let[e]=t;return Array.isArray(e)?(Ae("orderBy(array) is deprecated, use multiple orderBy calls instead."),e.map(r=>ii(r))):[ii(e)]}throw new Error(`Invalid number of arguments at order by! expected 1-2, received ${t.length}`)}function ii(t,e){let r=On(t);if(oe.is(r)){if(e)throw new Error("Cannot specify direction twice!");return r}return po(r,e)}function On(t){if(xe(t))return $(t);if(Kt(t))return t.toOperationNode();let[e,r]=t.split(" ");return r?(Ae("`orderBy('column asc')` is deprecated. Use `orderBy('column', 'asc')` instead."),po(X(e),r)):X(t)}function po(t,e){if(typeof e=="string"){if(!oi(e))throw new Error(`Invalid order by direction: ${e}`);return oe.create(t,W.createWithSql(e))}if(Ut(e))return Ae("`orderBy(..., expr)` is deprecated. Use `orderBy(..., 'asc')` or `orderBy(..., (ob) => ...)` instead."),oe.create(t,e.toOperationNode());let r=oe.create(t);return e?e(new Gt({node:r})).toOperationNode():r}var et=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 jt=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 Re=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 ri(t){return C(t)?X(t):t.toOperationNode()}function ge(t){return P(t)?t.map(e=>L(e)):[L(t)]}function L(t){return xe(t)?$(t):ri(t)}function co(t,e){let r=X(t);if(ti(e))return et.create(r,jt.create(Y.create(e)));let o=e.slice(0,-1);if(ti(o))return et.create(r,Re.create(Y.create(o)));throw new Error(`Invalid JSON operator: ${e}`)}function X(t){let e=".";if(!t.includes(e))return _e.create(m.create(t));let r=t.split(e).map(si);if(r.length===3)return bn(r);if(r.length===2)return vn(r);throw new Error(`invalid column reference ${t}`)}function ho(t){let e=" as ";if(t.includes(e)){let[r,o]=t.split(e).map(si);return R.create(X(r),p.create(o))}else return X(t)}function ni(t){return m.create(t)}function tt(t){let e=" ";if(t.includes(e)){let[r,o]=t.split(e).map(si);if(!oi(o))throw new Error(`invalid order direction "${o}" next to "${r}"`);return Z([r,o])[0]}else return ni(t)}function bn(t){let[e,r,o]=t;return _e.create(m.create(o),H.createWithSchema(e,r))}function vn(t){let[e,r]=t;return _e.create(m.create(r),H.create(e))}function si(t){return t.trim()}var Ht=i({is(t){return t.kind==="PrimitiveValueListNode"},create(t){return i({kind:"PrimitiveValueListNode",values:i([...t])})}});var he=i({is(t){return t.kind==="ValueListNode"},create(t){return i({kind:"ValueListNode",values:i(t)})}});var k=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 mo(t){return P(t)?Cn(t):g(t)}function g(t){return xe(t)?$(t):k.create(t)}function Yt(t){return Se(t)||ze(t)||Ye(t)}function Rt(t){if(!Yt(t))throw new Error(`unsafe immediate value ${JSON.stringify(t)}`);return k.createImmediate(t)}function Cn(t){return t.some(xe)?he.create(t.map(e=>g(e))):Ht.create(t)}var me=i({is(t){return t.kind==="ParensNode"},create(t){return i({kind:"ParensNode",node:t})}});function O(t){if(t.length===3)return Xt(t[0],t[1],t[2]);if(t.length===1)return g(t[0]);throw new Error(`invalid arguments: ${JSON.stringify(t)}`)}function Xt(t,e,r){return Wn(e)&&fo(r)?Ee.create(L(t),ai(e),k.createImmediate(r)):Ee.create(L(t),ai(e),mo(r))}function I(t,e,r){return Ee.create(L(t),ai(e),L(r))}function ui(t,e){return rt(Object.entries(t).filter(([,r])=>!j(r)).map(([r,o])=>Xt(r,fo(o)?"is":"=",o)),e)}function rt(t,e,r=!0){let o=e==="and"?J.create:ie.create;if(t.length===0)return Ee.create(k.createImmediate(1),Y.create("="),k.createImmediate(e==="and"?1:0));let n=lo(t[0]);for(let a=1;a<t.length;++a)n=o(n,lo(t[a]));return t.length>1&&r?me.create(n):n}function Wn(t){return t==="is"||t==="is not"}function fo(t){return Ye(t)||ze(t)}function ai(t){if(C(t)&&so.includes(t))return Y.create(t);if(b(t))return t.toOperationNode();throw new Error(`invalid operator ${JSON.stringify(t)}`)}function lo(t){return b(t)?t.toOperationNode():t}var Oe=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 di=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 It=i({is(t){return t.kind==="OverNode"},create(){return i({kind:"OverNode"})},cloneWithOrderByItems(t,e){return i({...t,orderBy:t.orderBy?Oe.cloneWithItems(t.orderBy,e):Oe.create(e)})},cloneWithPartitionByItems(t,e){return i({...t,partitionBy:t.partitionBy?di.cloneWithItems(t.partitionBy,e):di.create(e)})}});var Ve=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 pi=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 ci=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"?J.create(t.having,r):ie.create(t.having,r)})}});var S=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 Zt=i({is(t){return t.kind==="ListNode"},create(t){return i({kind:"ListNode",items:i(t)})}});var le=i({is(t){return t.kind==="UpdateQueryNode"},create(t,e){return i({kind:"UpdateQueryNode",table:t.length===1?t[0]:Zt.create(t),...e&&{with:e}})},createWithoutTable(){return i({kind:"UpdateQueryNode"})},cloneWithFromItems(t,e){return i({...t,from:t.from?Ve.cloneWithFroms(t.from,e):Ve.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 hi=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 Ie=i({is(t){return t.kind==="DeleteQueryNode"},create(t,e){return i({kind:"DeleteQueryNode",from:Ve.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?hi.cloneWithTables(t.using,e):hi.create(e)})}});var Q=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"?J.create(t.where,r):ie.create(t.where,r)})}});var mi=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 No=i({is(t){return t.kind==="ExplainNode"},create(t,e){return i({kind:"ExplainNode",format:t,options:e})}});var be=i({is(t){return t.kind==="WhenNode"},create(t){return i({kind:"WhenNode",condition:t})},cloneWithResult(t,e){return i({...t,result:e})}});var D=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),be.cloneWithResult(t.whens[t.whens.length-1],e)]):void 0})}});var li=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 x.is(t)||S.is(t)||le.is(t)||Ie.is(t)||D.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?Q.cloneWithOperation(t.where,"And",e):Q.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?mi.cloneWithSelections(t.returning,e):mi.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:No.create(e,r?.toOperationNode())})},cloneWithTop(t,e){return i({...t,top:e})},cloneWithOutput(t,e){return i({...t,output:t.output?li.cloneWithSelections(t.output,e):li.create(e)})},cloneWithOrderByItems(t,e){return i({...t,orderBy:t.orderBy?Oe.cloneWithItems(t.orderBy,e):Oe.create(e)})},cloneWithoutOrderBy(t){return i({...t,orderBy:void 0})}});var x=i({is(t){return t.kind==="SelectQueryNode"},create(t){return i({kind:"SelectQueryNode",...t&&{with:t}})},createFrom(t,e){return i({kind:"SelectQueryNode",from:Ve.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?pi.cloneWithItems(t.groupBy,e):pi.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?ci.cloneWithOperation(t.having,"And",e):ci.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 _t=class t{#e;constructor(e){this.#e=i(e)}on(...e){return new t({...this.#e,joinNode:we.cloneWithOn(this.#e.joinNode,O(e))})}onRef(e,r,o){return new t({...this.#e,joinNode:we.cloneWithOn(this.#e.joinNode,I(e,r,o))})}onTrue(){return new t({...this.#e,joinNode:we.cloneWithOn(this.#e.joinNode,W.createWithSql("true"))})}$call(e){return e(this)}toOperationNode(){return this.#e.joinNode}};var yo=i({is(t){return t.kind==="PartitionByItemNode"},create(t){return i({kind:"PartitionByItemNode",partitionBy:t})}});function wo(t){return ge(t).map(yo.create)}var er=class t{#e;constructor(e){this.#e=i(e)}orderBy(...e){return new t({overNode:It.cloneWithOrderByItems(this.#e.overNode,Z(e))})}clearOrderBy(){return new t({overNode:u.cloneWithoutOrderBy(this.#e.overNode)})}partitionBy(e){return new t({overNode:It.cloneWithPartitionByItems(this.#e.overNode,wo(e))})}$call(e){return e(this)}toOperationNode(){return this.#e.overNode}};var it=i({is(t){return t.kind==="SelectionNode"},create(t){return i({kind:"SelectionNode",selection:t})},createSelectAll(){return i({kind:"SelectionNode",selection:Ze.create()})},createSelectAllFromTable(t){return i({kind:"SelectionNode",selection:_e.createSelectAll(t)})}});function A(t){return T(t)?A(t(ne())):P(t)?t.map(e=>xo(e)):[xo(t)]}function xo(t){return C(t)?it.create(ho(t)):Kt(t)?it.create(t.toOperationNode()):it.create(tr(t))}function q(t){return t?Array.isArray(t)?t.map(go):[go(t)]:[it.createSelectAll()]}function go(t){if(C(t))return it.createSelectAllFromTable(N(t));throw new Error(`invalid value selectAll expression: ${JSON.stringify(t)}`)}var Oo=i({is(t){return t.kind==="ValuesNode"},create(t){return i({kind:"ValuesNode",values:i(t)})}});var bo=i({is(t){return t.kind==="DefaultInsertValueNode"},create(){return i({kind:"DefaultInsertValueNode"})}});function rr(t){let e=T(t)?t(ne()):t,r=P(e)?e:i([e]);return Tn(r)}function Tn(t){let e=Sn(t);return[i([...e.keys()].map(m.create)),Oo.create(t.map(r=>kn(r,e)))]}function Sn(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 kn(t,e){let r=Object.keys(t),o=Array.from({length:e.size}),n=!1,a=r.length;for(let c of r){let y=e.get(c);if(j(y)){a--;continue}let h=t[c];(j(h)||xe(h))&&(n=!0),o[y]=h}if(a<e.size||n){let c=bo.create();return he.create(o.map(y=>j(y)?c:g(y)))}return Ht.create(o)}var fi=i({is(t){return t.kind==="ColumnUpdateNode"},create(t,e){return i({kind:"ColumnUpdateNode",column:t,value:e})}});function vo(...t){return t.length===2?[fi.create(L(t[0]),g(t[1]))]:Dt(t[0])}function Dt(t){let e=T(t)?t(ne()):t;return Object.entries(e).filter(([r,o])=>o!==void 0).map(([r,o])=>fi.create(m.create(r),g(o)))}var Co=i({is(t){return t.kind==="OnDuplicateKeyNode"},create(t){return i({kind:"OnDuplicateKeyNode",updates:t})}});var ir=class{insertId;numInsertedOrUpdatedRows;constructor(e,r){this.insertId=e,this.numInsertedOrUpdatedRows=r}};var ee=class extends Error{node;constructor(e){super("no result"),this.node=e}};function fe(t){return Object.prototype.hasOwnProperty.call(t,"prototype")}var V=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?Q.cloneWithOperation(t.indexWhere,"And",e):Q.create(e)})},cloneWithIndexOrWhere(t,e){return i({...t,indexWhere:t.indexWhere?Q.cloneWithOperation(t.indexWhere,"Or",e):Q.create(e)})},cloneWithUpdateWhere(t,e){return i({...t,updateWhere:t.updateWhere?Q.cloneWithOperation(t.updateWhere,"And",e):Q.create(e)})},cloneWithUpdateOrWhere(t,e){return i({...t,updateWhere:t.updateWhere?Q.cloneWithOperation(t.updateWhere,"Or",e):Q.create(e)})},cloneWithoutIndexWhere(t){return i({...t,indexWhere:void 0})},cloneWithoutUpdateWhere(t){return i({...t,updateWhere:void 0})}});var or=class t{#e;constructor(e){this.#e=i(e)}column(e){let r=m.create(e);return new t({...this.#e,onConflictNode:V.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?i([...this.#e.onConflictNode.columns,r]):i([r])})})}columns(e){let r=e.map(m.create);return new t({...this.#e,onConflictNode:V.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:V.cloneWith(this.#e.onConflictNode,{constraint:p.create(e)})})}expression(e){return new t({...this.#e,onConflictNode:V.cloneWith(this.#e.onConflictNode,{indexExpression:e.toOperationNode()})})}where(...e){return new t({...this.#e,onConflictNode:V.cloneWithIndexWhere(this.#e.onConflictNode,O(e))})}whereRef(e,r,o){return new t({...this.#e,onConflictNode:V.cloneWithIndexWhere(this.#e.onConflictNode,I(e,r,o))})}clearWhere(){return new t({...this.#e,onConflictNode:V.cloneWithoutIndexWhere(this.#e.onConflictNode)})}doNothing(){return new Ni({...this.#e,onConflictNode:V.cloneWith(this.#e.onConflictNode,{doNothing:!0})})}doUpdateSet(e){return new yi({...this.#e,onConflictNode:V.cloneWith(this.#e.onConflictNode,{updates:Dt(e)})})}$call(e){return e(this)}},Ni=class{#e;constructor(e){this.#e=i(e)}toOperationNode(){return this.#e.onConflictNode}},yi=class t{#e;constructor(e){this.#e=i(e)}where(...e){return new t({...this.#e,onConflictNode:V.cloneWithUpdateWhere(this.#e.onConflictNode,O(e))})}whereRef(e,r,o){return new t({...this.#e,onConflictNode:V.cloneWithUpdateWhere(this.#e.onConflictNode,I(e,r,o))})}clearWhere(){return new t({...this.#e,onConflictNode:V.cloneWithoutUpdateWhere(this.#e.onConflictNode)})}$call(e){return e(this)}toOperationNode(){return this.#e.onConflictNode}};var Wo=i({is(t){return t.kind==="TopNode"},create(t,e){return i({kind:"TopNode",expression:t,modifiers:e})}});function se(t,e){if(!Se(t)&&!Xe(t))throw new Error(`Invalid top expression: ${t}`);if(!j(e)&&!En(e))throw new Error(`Invalid top modifiers: ${e}`);return Wo.create(t,e)}function En(t){return t==="percent"||t==="with ties"||t==="percent with ties"}var Ue=i({is(t){return t.kind==="OrActionNode"},create(t){return i({kind:"OrActionNode",action:t})}});var qt=class t{#e;constructor(e){this.#e=i(e)}values(e){let[r,o]=rr(e);return new t({...this.#e,queryNode:S.cloneWith(this.#e.queryNode,{columns:r,values:o})})}columns(e){return new t({...this.#e,queryNode:S.cloneWith(this.#e.queryNode,{columns:i(e.map(m.create))})})}expression(e){return new t({...this.#e,queryNode:S.cloneWith(this.#e.queryNode,{values:$(e)})})}defaultValues(){return new t({...this.#e,queryNode:S.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:S.cloneWith(this.#e.queryNode,{orAction:Ue.create("ignore")})})}orIgnore(){return new t({...this.#e,queryNode:S.cloneWith(this.#e.queryNode,{orAction:Ue.create("ignore")})})}orAbort(){return new t({...this.#e,queryNode:S.cloneWith(this.#e.queryNode,{orAction:Ue.create("abort")})})}orFail(){return new t({...this.#e,queryNode:S.cloneWith(this.#e.queryNode,{orAction:Ue.create("fail")})})}orReplace(){return new t({...this.#e,queryNode:S.cloneWith(this.#e.queryNode,{orAction:Ue.create("replace")})})}orRollback(){return new t({...this.#e,queryNode:S.cloneWith(this.#e.queryNode,{orAction:Ue.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:S.cloneWith(this.#e.queryNode,{onConflict:e(new or({onConflictNode:V.create()})).toOperationNode()})})}onDuplicateKeyUpdate(e){return new t({...this.#e,queryNode:S.cloneWith(this.#e.queryNode,{onDuplicateKey:Co.create(Dt(e))})})}returning(e){return new t({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,A(e))})}returningAll(){return new t({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,q())})}output(e){return new t({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,A(e))})}outputAll(e){return new t({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,q(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,this.#e.queryId),{adapter:o}=this.#e.executor,n=e.query;return n.returning&&o.supportsReturning||n.output&&o.supportsOutput?r.rows:[new ir(r.insertId,r.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=ee){let r=await this.executeTakeFirst();if(r===void 0)throw fe(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,this.#e.queryId);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 nr=class{numDeletedRows;constructor(e){this.numDeletedRows=e}};var ot=i({is(t){return t.kind==="LimitNode"},create(t){return i({kind:"LimitNode",limit:t})}});var sr=class t{#e;constructor(e){this.#e=i(e)}where(...e){return new t({...this.#e,queryNode:u.cloneWithWhere(this.#e.queryNode,O(e))})}whereRef(e,r,o){return new t({...this.#e,queryNode:u.cloneWithWhere(this.#e.queryNode,I(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:Ie.cloneWithUsing(this.#e.queryNode,ae(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,De(e,r))})}returning(e){return new t({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,A(e))})}returningAll(e){return new t({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,q(e))})}output(e){return new t({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,A(e))})}outputAll(e){return new t({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,q(e))})}clearReturning(){return new t({...this.#e,queryNode:u.cloneWithoutReturning(this.#e.queryNode)})}clearLimit(){return new t({...this.#e,queryNode:Ie.cloneWithoutLimit(this.#e.queryNode)})}orderBy(...e){return new t({...this.#e,queryNode:u.cloneWithOrderByItems(this.#e.queryNode,Z(e))})}clearOrderBy(){return new t({...this.#e,queryNode:u.cloneWithoutOrderBy(this.#e.queryNode)})}limit(e){return new t({...this.#e,queryNode:Ie.cloneWithLimit(this.#e.queryNode,ot.create(g(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,this.#e.queryId),{adapter:o}=this.#e.executor,n=e.query;return n.returning&&o.supportsReturning||n.output&&o.supportsOutput?r.rows:[new nr(r.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=ee){let r=await this.executeTakeFirst();if(r===void 0)throw fe(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,this.#e.queryId);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 ar=class{numUpdatedRows;numChangedRows;constructor(e,r){this.numUpdatedRows=e,this.numChangedRows=r}};var nt=class t{#e;constructor(e){this.#e=i(e)}where(...e){return new t({...this.#e,queryNode:u.cloneWithWhere(this.#e.queryNode,O(e))})}whereRef(e,r,o){return new t({...this.#e,queryNode:u.cloneWithWhere(this.#e.queryNode,I(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:le.cloneWithFromItems(this.#e.queryNode,ae(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,De(e,r))})}orderBy(...e){return new t({...this.#e,queryNode:u.cloneWithOrderByItems(this.#e.queryNode,Z(e))})}clearOrderBy(){return new t({...this.#e,queryNode:u.cloneWithoutOrderBy(this.#e.queryNode)})}limit(e){return new t({...this.#e,queryNode:le.cloneWithLimit(this.#e.queryNode,ot.create(g(e)))})}set(...e){return new t({...this.#e,queryNode:le.cloneWithUpdates(this.#e.queryNode,vo(...e))})}returning(e){return new t({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,A(e))})}returningAll(e){return new t({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,q(e))})}output(e){return new t({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,A(e))})}outputAll(e){return new t({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,q(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,this.#e.queryId),{adapter:o}=this.#e.executor,n=e.query;return n.returning&&o.supportsReturning||n.output&&o.supportsOutput?r.rows:[new ar(r.numAffectedRows??BigInt(0),r.numChangedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=ee){let r=await this.executeTakeFirst();if(r===void 0)throw fe(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,this.#e.queryId);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 wi=i({is(t){return t.kind==="CommonTableExpressionNameNode"},create(t,e){return i({kind:"CommonTableExpressionNameNode",table:H.create(t),columns:e?i(e.map(m.create)):void 0})}});var st=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 ur=class t{#e;constructor(e){this.#e=i(e)}materialized(){return new t({...this.#e,node:st.cloneWith(this.#e.node,{materialized:!0})})}notMaterialized(){return new t({...this.#e,node:st.cloneWith(this.#e.node,{materialized:!1})})}toOperationNode(){return this.#e.node}};function xi(t,e){let r=e(So()).toOperationNode();return T(t)?t(An(r)).toOperationNode():st.create(To(t),r)}function An(t){return e=>new ur({node:st.create(To(e),t)})}function To(t){if(t.includes("(")){let e=t.split(/[\(\)]/),r=e[0],o=e[1].split(",").map(n=>n.trim());return wi.create(r,o)}else return wi.create(t)}var Bt=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 ko=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"];function Eo(t){let e="";for(let r=0;r<t;++r)e+=Rn();return e}function Rn(){return ko[~~(Math.random()*ko.length)]}function l(){return new gi}var gi=class{#e;get queryId(){return this.#e===void 0&&(this.#e=Eo(8)),this.#e}};var qe=class{nodeStack=[];#e=i({AliasNode:this.transformAlias.bind(this),ColumnNode:this.transformColumn.bind(this),IdentifierNode:this.transformIdentifier.bind(this),SchemableIdentifierNode:this.transformSchemableIdentifier.bind(this),RawNode:this.transformRaw.bind(this),ReferenceNode:this.transformReference.bind(this),SelectQueryNode:this.transformSelectQuery.bind(this),SelectionNode:this.transformSelection.bind(this),TableNode:this.transformTable.bind(this),FromNode:this.transformFrom.bind(this),SelectAllNode:this.transformSelectAll.bind(this),AndNode:this.transformAnd.bind(this),OrNode:this.transformOr.bind(this),ValueNode:this.transformValue.bind(this),ValueListNode:this.transformValueList.bind(this),PrimitiveValueListNode:this.transformPrimitiveValueList.bind(this),ParensNode:this.transformParens.bind(this),JoinNode:this.transformJoin.bind(this),OperatorNode:this.transformOperator.bind(this),WhereNode:this.transformWhere.bind(this),InsertQueryNode:this.transformInsertQuery.bind(this),DeleteQueryNode:this.transformDeleteQuery.bind(this),ReturningNode:this.transformReturning.bind(this),CreateTableNode:this.transformCreateTable.bind(this),AddColumnNode:this.transformAddColumn.bind(this),ColumnDefinitionNode:this.transformColumnDefinition.bind(this),DropTableNode:this.transformDropTable.bind(this),DataTypeNode:this.transformDataType.bind(this),OrderByNode:this.transformOrderBy.bind(this),OrderByItemNode:this.transformOrderByItem.bind(this),GroupByNode:this.transformGroupBy.bind(this),GroupByItemNode:this.transformGroupByItem.bind(this),UpdateQueryNode:this.transformUpdateQuery.bind(this),ColumnUpdateNode:this.transformColumnUpdate.bind(this),LimitNode:this.transformLimit.bind(this),OffsetNode:this.transformOffset.bind(this),OnConflictNode:this.transformOnConflict.bind(this),OnDuplicateKeyNode:this.transformOnDuplicateKey.bind(this),CreateIndexNode:this.transformCreateIndex.bind(this),DropIndexNode:this.transformDropIndex.bind(this),ListNode:this.transformList.bind(this),PrimaryKeyConstraintNode:this.transformPrimaryKeyConstraint.bind(this),UniqueConstraintNode:this.transformUniqueConstraint.bind(this),ReferencesNode:this.transformReferences.bind(this),CheckConstraintNode:this.transformCheckConstraint.bind(this),WithNode:this.transformWith.bind(this),CommonTableExpressionNode:this.transformCommonTableExpression.bind(this),CommonTableExpressionNameNode:this.transformCommonTableExpressionName.bind(this),HavingNode:this.transformHaving.bind(this),CreateSchemaNode:this.transformCreateSchema.bind(this),DropSchemaNode:this.transformDropSchema.bind(this),AlterTableNode:this.transformAlterTable.bind(this),DropColumnNode:this.transformDropColumn.bind(this),RenameColumnNode:this.transformRenameColumn.bind(this),AlterColumnNode:this.transformAlterColumn.bind(this),ModifyColumnNode:this.transformModifyColumn.bind(this),AddConstraintNode:this.transformAddConstraint.bind(this),DropConstraintNode:this.transformDropConstraint.bind(this),RenameConstraintNode:this.transformRenameConstraint.bind(this),ForeignKeyConstraintNode:this.transformForeignKeyConstraint.bind(this),CreateViewNode:this.transformCreateView.bind(this),RefreshMaterializedViewNode:this.transformRefreshMaterializedView.bind(this),DropViewNode:this.transformDropView.bind(this),GeneratedNode:this.transformGenerated.bind(this),DefaultValueNode:this.transformDefaultValue.bind(this),OnNode:this.transformOn.bind(this),ValuesNode:this.transformValues.bind(this),SelectModifierNode:this.transformSelectModifier.bind(this),CreateTypeNode:this.transformCreateType.bind(this),DropTypeNode:this.transformDropType.bind(this),ExplainNode:this.transformExplain.bind(this),DefaultInsertValueNode:this.transformDefaultInsertValue.bind(this),AggregateFunctionNode:this.transformAggregateFunction.bind(this),OverNode:this.transformOver.bind(this),PartitionByNode:this.transformPartitionBy.bind(this),PartitionByItemNode:this.transformPartitionByItem.bind(this),SetOperationNode:this.transformSetOperation.bind(this),BinaryOperationNode:this.transformBinaryOperation.bind(this),UnaryOperationNode:this.transformUnaryOperation.bind(this),UsingNode:this.transformUsing.bind(this),FunctionNode:this.transformFunction.bind(this),CaseNode:this.transformCase.bind(this),WhenNode:this.transformWhen.bind(this),JSONReferenceNode:this.transformJSONReference.bind(this),JSONPathNode:this.transformJSONPath.bind(this),JSONPathLegNode:this.transformJSONPathLeg.bind(this),JSONOperatorChainNode:this.transformJSONOperatorChain.bind(this),TupleNode:this.transformTuple.bind(this),MergeQueryNode:this.transformMergeQuery.bind(this),MatchedNode:this.transformMatched.bind(this),AddIndexNode:this.transformAddIndex.bind(this),CastNode:this.transformCast.bind(this),FetchNode:this.transformFetch.bind(this),TopNode:this.transformTop.bind(this),OutputNode:this.transformOutput.bind(this),OrActionNode:this.transformOrAction.bind(this),CollateNode:this.transformCollate.bind(this)});transformNode(e,r){if(!e)return e;this.nodeStack.push(e);let o=this.transformNodeImpl(e,r);return this.nodeStack.pop(),i(o)}transformNodeImpl(e,r){return this.#e[e.kind](e,r)}transformNodeList(e,r){return e&&i(e.map(o=>this.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 In=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}),Dn={json_agg:!0,to_json:!0},dr=class extends qe{#e;#t=new Set;#r=new Set;constructor(e){super(),this.#e=e}transformNodeImpl(e,r){if(!this.#o(e))return super.transformNodeImpl(e,r);let o=this.#d(e);for(let d of o)this.#r.add(d);let n=this.#a(e);for(let d of n)this.#t.add(d);let a=super.transformNodeImpl(e,r);for(let d of n)this.#t.delete(d);for(let d of o)this.#r.delete(d);return a}transformSchemableIdentifier(e,r){let o=super.transformSchemableIdentifier(e,r);return o.schema||!this.#t.has(e.identifier.name)?o:{...o,schema:p.create(this.#e)}}transformReferences(e,r){let o=super.transformReferences(e,r);return o.table.table.schema?o:{...o,table:H.createWithSchema(this.#e,o.table.table.identifier.name)}}transformAggregateFunction(e,r){return{...super.transformAggregateFunction({...e,aggregated:[]},r),aggregated:this.#i(e,r,"aggregated")}}transformFunction(e,r){return{...super.transformFunction({...e,arguments:[]},r),arguments:this.#i(e,r,"arguments")}}#i(e,r,o){return Dn[e.func]?e[o].map(n=>!H.is(n)||n.table.schema?this.transformNode(n,r):{...n,table:this.transformIdentifier(n.table.identifier,r)}):this.transformNodeList(e[o],r)}#o(e){return e.kind in In}#a(e){let r=new Set;if("name"in e&&e.name&&F.is(e.name)&&this.#s(e.name,r),"from"in e&&e.from)for(let o of e.from.froms)this.#n(o,r);if("into"in e&&e.into&&this.#n(e.into,r),"table"in e&&e.table&&this.#n(e.table,r),"joins"in e&&e.joins)for(let o of e.joins)this.#n(o.table,r);return"using"in e&&e.using&&this.#n(e.using,r),r}#d(e){let r=new Set;return"with"in e&&e.with&&this.#u(e.with,r),r}#n(e,r){if(H.is(e))this.#s(e.table,r);else if(R.is(e)&&H.is(e.node))this.#s(e.node.table,r);else if(Zt.is(e))for(let o of e.items)this.#n(o,r)}#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 te=class{#e;constructor(e){this.#e=new dr(e)}transformQuery(e){return this.#e.transformNode(e.node,e.queryId)}async transformResult(e){return e.result}};var Ao=i({is(t){return t.kind==="MatchedNode"},create(t,e=!1){return i({kind:"MatchedNode",not:t,bySource:e})}});function Oi(t,e,r){return be.create(rt([Ao.create(!t.isMatched,t.bySource),...e&&e.length>0?[e.length===3&&r?I(e[0],e[1],e[2]):O(e)]:[]],"and",!1))}function at(t){return C(t)?W.create([t],[]):b(t)?t.toOperationNode():t}var Lt=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 pr(t){let e=new Lt,r=new Lt;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 qn=i([]),ut=class{#e;constructor(e=qn){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,r){return await this.provideConnection(async o=>{let n=await o.executeQuery(e);return"numUpdatedOrDeletedRows"in n&&Ae("kysely:warning: outdated driver/plugin detected! `QueryResult.numUpdatedOrDeletedRows` has been replaced with `QueryResult.numAffectedRows`."),await this.#t(n,r)})}async*stream(e,r,o){let{connection:n,release:a}=await pr(this);try{for await(let d of n.streamQuery(e,r))yield await this.#t(d,o)}finally{a()}}async#t(e,r){for(let o of this.#e)e=await o.transformResult({result:e,queryId:r});return e}};var bi=class t extends ut{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([])}},Be=new bi;var cr=class{numChangedRows;constructor(e){this.numChangedRows=e}};var hr=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 Le({...this.#e,queryNode:D.cloneWithUsing(this.#e.queryNode,De("Using",e))})}returning(e){return new t({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,A(e))})}returningAll(e){return new t({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,q(e))})}output(e){return new t({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,A(e))})}outputAll(e){return new t({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,q(e))})}},Le=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 mr({...this.#e,queryNode:D.cloneWithWhen(this.#e.queryNode,Oi({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,A(e))})}returningAll(e){return new t({...this.#e,queryNode:u.cloneWithReturning(this.#e.queryNode,q(e))})}output(e){return new t({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,A(e))})}outputAll(e){return new t({...this.#e,queryNode:u.cloneWithOutput(this.#e.queryNode,q(e))})}#r(e,r=!1,o=!1){let n={...this.#e,queryNode:D.cloneWithWhen(this.#e.queryNode,Oi({isMatched:!1,bySource:o},e,r))},a=o?mr:vi;return new a(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,this.#e.queryId),{adapter:o}=this.#e.executor,n=e.query;return n.returning&&o.supportsReturning||n.output&&o.supportsOutput?r.rows:[new cr(r.numAffectedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=ee){let r=await this.executeTakeFirst();if(r===void 0)throw fe(e)?new e(this.toOperationNode()):e(this.toOperationNode());return r}},mr=class{#e;constructor(e){this.#e=i(e)}thenDelete(){return new Le({...this.#e,queryNode:D.cloneWithThen(this.#e.queryNode,at("delete"))})}thenDoNothing(){return new Le({...this.#e,queryNode:D.cloneWithThen(this.#e.queryNode,at("do nothing"))})}thenUpdate(e){return new Le({...this.#e,queryNode:D.cloneWithThen(this.#e.queryNode,at(e(new nt({queryId:this.#e.queryId,executor:Be,queryNode:le.createWithoutTable()}))))})}thenUpdateSet(...e){return this.thenUpdate(r=>r.set(...e))}},vi=class{#e;constructor(e){this.#e=i(e)}thenDoNothing(){return new Le({...this.#e,queryNode:D.cloneWithThen(this.#e.queryNode,at("do nothing"))})}thenInsertValues(e){let[r,o]=rr(e);return new Le({...this.#e,queryNode:D.cloneWithThen(this.#e.queryNode,at(S.cloneWith(S.createWithoutInto(),{columns:r,values:o})))})}};var dt=class t{#e;constructor(e){this.#e=i(e)}selectFrom(e){return Qt({queryId:l(),executor:this.#e.executor,queryNode:x.createFrom(ae(e),this.#e.withNode)})}selectNoFrom(e){return Qt({queryId:l(),executor:this.#e.executor,queryNode:x.cloneWithSelections(x.create(this.#e.withNode),A(e))})}insertInto(e){return new qt({queryId:l(),executor:this.#e.executor,queryNode:S.create(N(e),this.#e.withNode)})}replaceInto(e){return new qt({queryId:l(),executor:this.#e.executor,queryNode:S.create(N(e),this.#e.withNode,!0)})}deleteFrom(e){return new sr({queryId:l(),executor:this.#e.executor,queryNode:Ie.create(ae(e),this.#e.withNode)})}updateTable(e){return new nt({queryId:l(),executor:this.#e.executor,queryNode:le.create(ae(e),this.#e.withNode)})}mergeInto(e){return new hr({queryId:l(),executor:this.#e.executor,queryNode:D.create(Ci(e),this.#e.withNode)})}with(e,r){let o=xi(e,r);return new t({...this.#e,withNode:this.#e.withNode?Bt.cloneWithExpression(this.#e.withNode,o):Bt.create(o)})}withRecursive(e,r){let o=xi(e,r);return new t({...this.#e,withNode:this.#e.withNode?Bt.cloneWithExpression(this.#e.withNode,o):Bt.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 te(e))})}};function So(){return new dt({executor:Be})}function Ro(t,e){return new _t({joinNode:we.create(t,Je(e))})}function Io(){return new er({overNode:It.create()})}function De(t,e){if(e.length===3)return Ln(t,e[0],e[1],e[2]);if(e.length===2)return Bn(t,e[0],e[1]);if(e.length===1)return Qn(t,e[0]);throw new Error("not implemented")}function Bn(t,e,r){return r(Ro(t,e)).toOperationNode()}function Ln(t,e,r,o){return we.createWithOn(t,Je(e),I(r,"=",o))}function Qn(t,e){return we.create(t,Je(e))}var Do=i({is(t){return t.kind==="OffsetNode"},create(t){return i({kind:"OffsetNode",offset:t})}});var qo=i({is(t){return t.kind==="GroupByItemNode"},create(t){return i({kind:"GroupByItemNode",groupBy:t})}});function Bo(t){return t=T(t)?t(ne()):t,ge(t).map(qo.create)}var lr=i({is(t){return t.kind==="SetOperationNode"},create(t,e,r){return i({kind:"SetOperationNode",operator:t,expression:e,all:r})}});function $e(t,e,r){return T(e)&&(e=e(fr())),P(e)||(e=[e]),e.map(o=>lr.create(t,$(o),r))}var w=class t{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new Pt(this,e)}or(...e){return new Wi(ie.create(this.#e,O(e)))}and(...e){return new Ti(J.create(this.#e,O(e)))}$castTo(){return new t(this.#e)}$notNull(){return new t(this.#e)}toOperationNode(){return this.#e}},Pt=class{#e;#t;constructor(e,r){this.#e=e,this.#t=r}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return R.create(this.#e.toOperationNode(),b(this.#t)?this.#t.toOperationNode():p.create(this.#t))}},Wi=class t{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new Pt(this,e)}or(...e){return new t(ie.create(this.#e,O(e)))}$castTo(){return new t(this.#e)}toOperationNode(){return me.create(this.#e)}},Ti=class t{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new Pt(this,e)}and(...e){return new t(J.create(this.#e,O(e)))}$castTo(){return new t(this.#e)}toOperationNode(){return me.create(this.#e)}};var Lo={is(t){return t.kind==="FetchNode"},create(t,e){return{kind:"FetchNode",rowCount:k.create(t),modifier:e}}};function Qo(t,e){if(!Se(t)&&!Xe(t))throw new Error(`Invalid fetch row count: ${t}`);if(!Pn(e))throw new Error(`Invalid fetch modifier: ${e}`);return Lo.create(t,e)}function Pn(t){return t==="only"||t==="with ties"}var Si=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,O(e))})}whereRef(e,r,o){return new t({...this.#e,queryNode:u.cloneWithWhere(this.#e.queryNode,I(e,r,o))})}having(...e){return new t({...this.#e,queryNode:x.cloneWithHaving(this.#e.queryNode,O(e))})}havingRef(e,r,o){return new t({...this.#e,queryNode:x.cloneWithHaving(this.#e.queryNode,I(e,r,o))})}select(e){return new t({...this.#e,queryNode:x.cloneWithSelections(this.#e.queryNode,A(e))})}distinctOn(e){return new t({...this.#e,queryNode:x.cloneWithDistinctOn(this.#e.queryNode,ge(e))})}modifyFront(e){return new t({...this.#e,queryNode:x.cloneWithFrontModifier(this.#e.queryNode,ce.createWithExpression(e.toOperationNode()))})}modifyEnd(e){return new t({...this.#e,queryNode:u.cloneWithEndModifier(this.#e.queryNode,ce.createWithExpression(e.toOperationNode()))})}distinct(){return new t({...this.#e,queryNode:x.cloneWithFrontModifier(this.#e.queryNode,ce.create("Distinct"))})}forUpdate(e){return new t({...this.#e,queryNode:u.cloneWithEndModifier(this.#e.queryNode,ce.create("ForUpdate",e?kt(e).map(N):void 0))})}forShare(e){return new t({...this.#e,queryNode:u.cloneWithEndModifier(this.#e.queryNode,ce.create("ForShare",e?kt(e).map(N):void 0))})}forKeyShare(e){return new t({...this.#e,queryNode:u.cloneWithEndModifier(this.#e.queryNode,ce.create("ForKeyShare",e?kt(e).map(N):void 0))})}forNoKeyUpdate(e){return new t({...this.#e,queryNode:u.cloneWithEndModifier(this.#e.queryNode,ce.create("ForNoKeyUpdate",e?kt(e).map(N):void 0))})}skipLocked(){return new t({...this.#e,queryNode:u.cloneWithEndModifier(this.#e.queryNode,ce.create("SkipLocked"))})}noWait(){return new t({...this.#e,queryNode:u.cloneWithEndModifier(this.#e.queryNode,ce.create("NoWait"))})}selectAll(e){return new t({...this.#e,queryNode:x.cloneWithSelections(this.#e.queryNode,q(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,De(e,r))})}orderBy(...e){return new t({...this.#e,queryNode:u.cloneWithOrderByItems(this.#e.queryNode,Z(e))})}groupBy(e){return new t({...this.#e,queryNode:x.cloneWithGroupByItems(this.#e.queryNode,Bo(e))})}limit(e){return new t({...this.#e,queryNode:x.cloneWithLimit(this.#e.queryNode,ot.create(g(e)))})}offset(e){return new t({...this.#e,queryNode:x.cloneWithOffset(this.#e.queryNode,Do.create(g(e)))})}fetch(e,r="only"){return new t({...this.#e,queryNode:x.cloneWithFetch(this.#e.queryNode,Qo(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:x.cloneWithSetOperations(this.#e.queryNode,$e("union",e,!1))})}unionAll(e){return new t({...this.#e,queryNode:x.cloneWithSetOperations(this.#e.queryNode,$e("union",e,!0))})}intersect(e){return new t({...this.#e,queryNode:x.cloneWithSetOperations(this.#e.queryNode,$e("intersect",e,!1))})}intersectAll(e){return new t({...this.#e,queryNode:x.cloneWithSetOperations(this.#e.queryNode,$e("intersect",e,!0))})}except(e){return new t({...this.#e,queryNode:x.cloneWithSetOperations(this.#e.queryNode,$e("except",e,!1))})}exceptAll(e){return new t({...this.#e,queryNode:x.cloneWithSetOperations(this.#e.queryNode,$e("except",e,!0))})}as(e){return new ki(this,e)}clearSelect(){return new t({...this.#e,queryNode:x.cloneWithoutSelections(this.#e.queryNode)})}clearWhere(){return new t({...this.#e,queryNode:u.cloneWithoutWhere(this.#e.queryNode)})}clearLimit(){return new t({...this.#e,queryNode:x.cloneWithoutLimit(this.#e.queryNode)})}clearOffset(){return new t({...this.#e,queryNode:x.cloneWithoutOffset(this.#e.queryNode)})}clearOrderBy(){return new t({...this.#e,queryNode:u.cloneWithoutOrderBy(this.#e.queryNode)})}clearGroupBy(){return new t({...this.#e,queryNode:x.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,this.#e.queryId)).rows}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=ee){let r=await this.executeTakeFirst();if(r===void 0)throw fe(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,this.#e.queryId);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 Qt(t){return new Si(t)}var ki=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 R.create(this.#e.toOperationNode(),p.create(this.#t))}};var Ne=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]?Oe.cloneWithItems(t[o],e):Oe.create(e)})},cloneWithFilter(t,e){return i({...t,filter:t.filter?Q.cloneWithOperation(t.filter,"And",e):Q.create(e)})},cloneWithOrFilter(t,e){return i({...t,filter:t.filter?Q.cloneWithOperation(t.filter,"Or",e):Q.create(e)})},cloneWithOver(t,e){return i({...t,over:e})}});var Ei=i({is(t){return t.kind==="FunctionNode"},create(t,e){return i({kind:"FunctionNode",func:t,arguments:e})}});var pt=class t{#e;constructor(e){this.#e=i(e)}get expressionType(){}as(e){return new Ai(this,e)}distinct(){return new t({...this.#e,aggregateFunctionNode:Ne.cloneWithDistinct(this.#e.aggregateFunctionNode)})}orderBy(...e){return new t({...this.#e,aggregateFunctionNode:u.cloneWithOrderByItems(this.#e.aggregateFunctionNode,Z(e))})}clearOrderBy(){return new t({...this.#e,aggregateFunctionNode:u.cloneWithoutOrderBy(this.#e.aggregateFunctionNode)})}withinGroupOrderBy(...e){return new t({...this.#e,aggregateFunctionNode:Ne.cloneWithOrderBy(this.#e.aggregateFunctionNode,Z(e),!0)})}filterWhere(...e){return new t({...this.#e,aggregateFunctionNode:Ne.cloneWithFilter(this.#e.aggregateFunctionNode,O(e))})}filterWhereRef(e,r,o){return new t({...this.#e,aggregateFunctionNode:Ne.cloneWithFilter(this.#e.aggregateFunctionNode,I(e,r,o))})}over(e){let r=Io();return new t({...this.#e,aggregateFunctionNode:Ne.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}},Ai=class{#e;#t;constructor(e,r){this.#e=e,this.#t=r}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return R.create(this.#e.toOperationNode(),p.create(this.#t))}};function Nr(){let t=(r,o)=>new w(Ei.create(r,ge(o??[]))),e=(r,o)=>new pt({aggregateFunctionNode:Ne.create(r,o?ge(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 pt({aggregateFunctionNode:Ne.create("count",q(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 pt({aggregateFunctionNode:Ne.create("json_agg",[C(r)?N(r):r.toOperationNode()])})},toJson(r){return new w(Ei.create("to_json",[C(r)?N(r):r.toOperationNode()]))}})}var Po=i({is(t){return t.kind==="UnaryOperationNode"},create(t,e){return i({kind:"UnaryOperationNode",operator:t,operand:e})}});function Mo(t,e){return Po.create(Y.create(t),L(e))}var _=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),be.cloneWithResult(t.when[t.when.length-1],e)]):void 0})},cloneWith(t,e){return i({...t,...e})}});var ct=class{#e;constructor(e){this.#e=i(e)}when(...e){return new yr({...this.#e,node:_.cloneWithWhen(this.#e.node,be.create(O(e)))})}},yr=class{#e;constructor(e){this.#e=i(e)}then(e){return new Ri({...this.#e,node:_.cloneWithThen(this.#e.node,Yt(e)?Rt(e):g(e))})}},Ri=class{#e;constructor(e){this.#e=i(e)}when(...e){return new yr({...this.#e,node:_.cloneWithWhen(this.#e.node,be.create(O(e)))})}else(e){return new Ii({...this.#e,node:_.cloneWith(this.#e.node,{else:Yt(e)?Rt(e):g(e)})})}end(){return new w(_.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new w(_.cloneWith(this.#e.node,{isStatement:!0}))}},Ii=class{#e;constructor(e){this.#e=i(e)}end(){return new w(_.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new w(_.cloneWith(this.#e.node,{isStatement:!0}))}};var Di=i({is(t){return t.kind==="JSONPathLegNode"},create(t,e){return i({kind:"JSONPathLegNode",type:t,value:e})}});var ht=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 et.is(this.#e)?new wr(et.cloneWithTraversal(this.#e,Re.is(this.#e.traversal)?Re.cloneWithLeg(this.#e.traversal,Di.create(e,r)):jt.cloneWithValue(this.#e.traversal,k.createImmediate(r)))):new wr(Re.cloneWithLeg(this.#e,Di.create(e,r)))}},wr=class t extends ht{#e;constructor(e){super(e),this.#e=e}get expressionType(){}as(e){return new qi(this,e)}$castTo(){return new t(this.#e)}$notNull(){return new t(this.#e)}toOperationNode(){return this.#e}},qi=class{#e;#t;constructor(e,r){this.#e=e,this.#t=r}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return R.create(this.#e.toOperationNode(),b(this.#t)?this.#t.toOperationNode():p.create(this.#t))}};var Bi=i({is(t){return t.kind==="TupleNode"},create(t){return i({kind:"TupleNode",values:i(t)})}});var Mn=["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"],Fn=[/^varchar\(\d+\)$/,/^char\(\d+\)$/,/^decimal\(\d+, \d+\)$/,/^numeric\(\d+, \d+\)$/,/^binary\(\d+\)$/,/^datetime\(\d+\)$/,/^time\(\d+\)$/,/^timetz\(\d+\)$/,/^timestamp\(\d+\)$/,/^timestamptz\(\d+\)$/,/^varbinary\(\d+\)$/],Fo=i({is(t){return t.kind==="DataTypeNode"},create(t){return i({kind:"DataTypeNode",dataType:t})}});function zo(t){return!!(Mn.includes(t)||Fn.some(e=>e.test(t)))}function ue(t){if(b(t))return t.toOperationNode();if(zo(t))return Fo.create(t);throw new Error(`invalid column data type ${JSON.stringify(t)}`)}var Vo=i({is(t){return t.kind==="CastNode"},create(t,e){return i({kind:"CastNode",expression:t,dataType:e})}});function fr(t=Be){function e(n,a,d){return new w(Xt(n,a,d))}function r(n,a){return new w(Mo(n,a))}let o=Object.assign(e,{fn:void 0,eb:void 0,selectFrom(n){return Qt({queryId:l(),executor:t,queryNode:x.createFrom(ae(n))})},case(n){return new ct({node:_.create(j(n)?void 0:L(n))})},ref(n,a){return j(a)?new w(X(n)):new ht(co(n,a))},jsonPath(){return new ht(Re.create())},table(n){return new w(N(n))},val(n){return new w(g(n))},refTuple(...n){return new w(Bi.create(n.map(L)))},tuple(...n){return new w(Bi.create(n.map(g)))},lit(n){return new w(Rt(n))},unary:r,not(n){return r("not",n)},exists(n){return r("exists",n)},neg(n){return r("-",n)},between(n,a,d){return new w(Ee.create(L(n),Y.create("between"),J.create(g(a),g(d))))},betweenSymmetric(n,a,d){return new w(Ee.create(L(n),Y.create("between symmetric"),J.create(g(a),g(d))))},and(n){return P(n)?new w(rt(n,"and")):new w(ui(n,"and"))},or(n){return P(n)?new w(rt(n,"or")):new w(ui(n,"or"))},parens(...n){let a=O(n);return me.is(a)?new w(a):new w(me.create(a))},cast(n,a){return new w(Vo.create(L(n),ue(a)))},withSchema(n){return fr(t.withPluginAtFront(new te(n)))}});return o.fn=Nr(),o.eb=o,o}function ne(t){return fr()}function $(t){if(b(t))return t.toOperationNode();if(T(t))return t(ne()).toOperationNode();throw new Error(`invalid expression: ${JSON.stringify(t)}`)}function tr(t){if(b(t))return t.toOperationNode();if(T(t))return t(ne()).toOperationNode();throw new Error(`invalid aliased expression: ${JSON.stringify(t)}`)}function xe(t){return Ut(t)||oo(t)||T(t)}var xr=class{#e;get table(){return this.#e}constructor(e){this.#e=e}as(e){return new Li(this.#e,e)}},Li=class{#e;#t;get table(){return this.#e}get alias(){return this.#t}constructor(e,r){this.#e=e,this.#t=r}toOperationNode(){return R.create(N(this.#e),p.create(this.#t))}};function Uo(t){return B(t)&&b(t)&&C(t.table)&&C(t.alias)}function ae(t){return P(t)?t.map(e=>Je(e)):[Je(t)]}function Je(t){return C(t)?Ci(t):Uo(t)?t.toOperationNode():tr(t)}function Ci(t){let e=" as ";if(t.includes(e)){let[r,o]=t.split(e).map(Jo);return R.create(N(r),p.create(o))}else return N(t)}function N(t){let e=".";if(t.includes(e)){let[r,o]=t.split(e).map(Jo);return H.createWithSchema(r,o)}else return H.create(t)}function Jo(t){return t.trim()}var Qi=i({is(t){return t.kind==="AddColumnNode"},create(t){return i({kind:"AddColumnNode",column:t})}});var v=i({is(t){return t.kind==="ColumnDefinitionNode"},create(t,e){return i({kind:"ColumnDefinitionNode",column:m.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 Pi=i({is(t){return t.kind==="DropColumnNode"},create(t){return i({kind:"DropColumnNode",column:m.create(t)})}});var Mi=i({is(t){return t.kind==="RenameColumnNode"},create(t,e){return i({kind:"RenameColumnNode",column:m.create(t),renameTo:m.create(e)})}});var mt=i({is(t){return t.kind==="CheckConstraintNode"},create(t,e){return i({kind:"CheckConstraintNode",expression:t,name:e?p.create(e):void 0})}});var $o=["no action","restrict","cascade","set null","set default"],lt=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 gr(t){return b(t)?t.toOperationNode():k.createImmediate(t)}var Mt=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 Ko=i({is(t){return t.kind==="DefaultValueNode"},create(t){return i({kind:"DefaultValueNode",defaultValue:t})}});function ft(t){if($o.includes(t))return t;throw new Error(`invalid OnModifyForeignAction ${t}`)}var ve=class t{#e;constructor(e){this.#e=e}autoIncrement(){return new t(v.cloneWith(this.#e,{autoIncrement:!0}))}identity(){return new t(v.cloneWith(this.#e,{identity:!0}))}primaryKey(){return new t(v.cloneWith(this.#e,{primaryKey:!0}))}references(e){let r=X(e);if(!r.table||Ze.is(r.column))throw new Error(`invalid call references('${e}'). The reference must have format table.column or schema.table.column`);return new t(v.cloneWith(this.#e,{references:lt.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(v.cloneWith(this.#e,{references:lt.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(v.cloneWith(this.#e,{references:lt.cloneWithOnUpdate(this.#e.references,ft(e))}))}unique(){return new t(v.cloneWith(this.#e,{unique:!0}))}notNull(){return new t(v.cloneWith(this.#e,{notNull:!0}))}unsigned(){return new t(v.cloneWith(this.#e,{unsigned:!0}))}defaultTo(e){return new t(v.cloneWith(this.#e,{defaultTo:Ko.create(gr(e))}))}check(e){return new t(v.cloneWith(this.#e,{check:mt.create(e.toOperationNode())}))}generatedAlwaysAs(e){return new t(v.cloneWith(this.#e,{generated:Mt.createWithExpression(e.toOperationNode())}))}generatedAlwaysAsIdentity(){return new t(v.cloneWith(this.#e,{generated:Mt.create({identity:!0,always:!0})}))}generatedByDefaultAsIdentity(){return new t(v.cloneWith(this.#e,{generated:Mt.create({identity:!0,byDefault:!0})}))}stored(){if(!this.#e.generated)throw new Error("stored() can only be called after generatedAlwaysAs");return new t(v.cloneWith(this.#e,{generated:Mt.cloneWith(this.#e.generated,{stored:!0})}))}modifyFront(e){return new t(v.cloneWithFrontModifier(this.#e,e.toOperationNode()))}nullsNotDistinct(){return new t(v.cloneWith(this.#e,{nullsNotDistinct:!0}))}ifNotExists(){return new t(v.cloneWith(this.#e,{ifNotExists:!0}))}modifyEnd(e){return new t(v.cloneWithEndModifier(this.#e,e.toOperationNode()))}$call(e){return e(this)}toOperationNode(){return this.#e}};var Fi=i({is(t){return t.kind==="ModifyColumnNode"},create(t){return i({kind:"ModifyColumnNode",column:t})}});var de=i({is(t){return t.kind==="ForeignKeyConstraintNode"},create(t,e,r,o){return i({kind:"ForeignKeyConstraintNode",columns:t,references:lt.create(e,r),name:o?p.create(o):void 0})},cloneWith(t,e){return i({...t,...e})}});var Nt=class t{#e;constructor(e){this.#e=e}onDelete(e){return new t(de.cloneWith(this.#e,{onDelete:ft(e)}))}onUpdate(e){return new t(de.cloneWith(this.#e,{onUpdate:ft(e)}))}deferrable(){return new t(de.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new t(de.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new t(de.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new t(de.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}};var yt=i({is(t){return t.kind==="AddConstraintNode"},create(t){return i({kind:"AddConstraintNode",constraint:t})}});var ye=i({is(t){return t.kind==="UniqueConstraintNode"},create(t,e,r){return i({kind:"UniqueConstraintNode",columns:i(t.map(m.create)),name:e?p.create(e):void 0,nullsNotDistinct:r})},cloneWith(t,e){return i({...t,...e})}});var wt=i({is(t){return t.kind==="DropConstraintNode"},create(t){return i({kind:"DropConstraintNode",constraintName:p.create(t)})},cloneWith(t,e){return i({...t,...e})}});var xt=i({is(t){return t.kind==="AlterColumnNode"},create(t,e,r){return i({kind:"AlterColumnNode",column:m.create(t),[e]:r})}});var Ft=class{#e;constructor(e){this.#e=e}setDataType(e){return new Ke(xt.create(this.#e,"dataType",ue(e)))}setDefault(e){return new Ke(xt.create(this.#e,"setDefault",gr(e)))}dropDefault(){return new Ke(xt.create(this.#e,"dropDefault",!0))}setNotNull(){return new Ke(xt.create(this.#e,"setNotNull",!0))}dropNotNull(){return new Ke(xt.create(this.#e,"dropNotNull",!0))}$call(e){return e(this)}},Ke=class{#e;constructor(e){this.#e=e}toOperationNode(){return this.#e}};var Ce=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(),this.#e.queryId)}};var Or=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(f.cloneWithTableProps(this.#e.node,{addConstraint:yt.create(this.#e.constraintBuilder.toOperationNode())}),this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var zt=class t{#e;constructor(e){this.#e=i(e)}ifExists(){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{dropConstraint:wt.cloneWith(this.#e.node.dropConstraint,{ifExists:!0})})})}cascade(){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{dropConstraint:wt.cloneWith(this.#e.node.dropConstraint,{modifier:"cascade"})})})}restrict(){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{dropConstraint:wt.cloneWith(this.#e.node.dropConstraint,{modifier:"restrict"})})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var We=i({is(t){return t.kind==="PrimaryKeyConstraintNode"},create(t,e){return i({kind:"PrimaryKeyConstraintNode",columns:i(t.map(m.create)),name:e?p.create(e):void 0})},cloneWith(t,e){return i({...t,...e})}});var Qe=i({is(t){return t.kind==="AddIndexNode"},create(t){return i({kind:"AddIndexNode",name:p.create(t)})},cloneWith(t,e){return i({...t,...e})},cloneWithColumns(t,e){return i({...t,columns:[...t.columns||[],...e]})}});var br=class t{#e;constructor(e){this.#e=i(e)}unique(){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addIndex:Qe.cloneWith(this.#e.node.addIndex,{unique:!0})})})}column(e){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addIndex:Qe.cloneWithColumns(this.#e.node.addIndex,[tt(e)])})})}columns(e){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addIndex:Qe.cloneWithColumns(this.#e.node.addIndex,e.map(tt))})})}expression(e){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addIndex:Qe.cloneWithColumns(this.#e.node.addIndex,[e.toOperationNode()])})})}using(e){return new t({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addIndex:Qe.cloneWith(this.#e.node.addIndex,{using:W.createWithSql(e)})})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var gt=class t{#e;constructor(e){this.#e=e}nullsNotDistinct(){return new t(ye.cloneWith(this.#e,{nullsNotDistinct:!0}))}deferrable(){return new t(ye.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new t(ye.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new t(ye.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new t(ye.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}};var Ot=class t{#e;constructor(e){this.#e=e}deferrable(){return new t(We.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new t(We.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new t(We.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new t(We.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}};var bt=class{#e;constructor(e){this.#e=e}$call(e){return e(this)}toOperationNode(){return this.#e}};var Go=i({is(t){return t.kind==="RenameConstraintNode"},create(t,e){return i({kind:"RenameConstraintNode",oldName:p.create(t),newName:p.create(e)})}});var vr=class{#e;constructor(e){this.#e=i(e)}renameTo(e){return new Ce({...this.#e,node:f.cloneWithTableProps(this.#e.node,{renameTo:N(e)})})}setSchema(e){return new Ce({...this.#e,node:f.cloneWithTableProps(this.#e.node,{setSchema:p.create(e)})})}alterColumn(e,r){let o=r(new Ft(e));return new Ge({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,o.toOperationNode())})}dropColumn(e){return new Ge({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Pi.create(e))})}renameColumn(e,r){return new Ge({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Mi.create(e,r))})}addColumn(e,r,o=z){let n=o(new ve(v.create(e,ue(r))));return new Ge({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Qi.create(n.toOperationNode()))})}modifyColumn(e,r,o=z){let n=o(new ve(v.create(e,ue(r))));return new Ge({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Fi.create(n.toOperationNode()))})}addUniqueConstraint(e,r,o=z){let n=o(new gt(ye.create(r,e)));return new Ce({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addConstraint:yt.create(n.toOperationNode())})})}addCheckConstraint(e,r,o=z){let n=o(new bt(mt.create(r.toOperationNode(),e)));return new Ce({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addConstraint:yt.create(n.toOperationNode())})})}addForeignKeyConstraint(e,r,o,n,a=z){let d=a(new Nt(de.create(r.map(m.create),N(o),n.map(m.create),e)));return new Or({...this.#e,constraintBuilder:d})}addPrimaryKeyConstraint(e,r,o=z){let n=o(new Ot(We.create(r,e)));return new Ce({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addConstraint:yt.create(n.toOperationNode())})})}dropConstraint(e){return new zt({...this.#e,node:f.cloneWithTableProps(this.#e.node,{dropConstraint:wt.create(e)})})}renameConstraint(e,r){return new zt({...this.#e,node:f.cloneWithTableProps(this.#e.node,{renameConstraint:Go.create(e,r)})})}addIndex(e){return new br({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addIndex:Qe.create(e)})})}dropIndex(e){return new Ce({...this.#e,node:f.cloneWithTableProps(this.#e.node,{dropIndex:ke.create(e)})})}$call(e){return e(this)}},Ge=class t{#e;constructor(e){this.#e=i(e)}alterColumn(e,r){let o=r(new Ft(e));return new t({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,o.toOperationNode())})}dropColumn(e){return new t({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Pi.create(e))})}renameColumn(e,r){return new t({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Mi.create(e,r))})}addColumn(e,r,o=z){let n=o(new ve(v.create(e,ue(r))));return new t({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Qi.create(n.toOperationNode()))})}modifyColumn(e,r,o=z){let n=o(new ve(v.create(e,ue(r))));return new t({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Fi.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(),this.#e.queryId)}};var vt=class extends qe{transformPrimitiveValueList(e){return he.create(e.values.map(k.createImmediate))}transformValue(e){return k.createImmediate(e.value)}};var Cr=class t{#e;constructor(e){this.#e=i(e)}ifNotExists(){return new t({...this.#e,node:re.cloneWith(this.#e.node,{ifNotExists:!0})})}unique(){return new t({...this.#e,node:re.cloneWith(this.#e.node,{unique:!0})})}nullsNotDistinct(){return new t({...this.#e,node:re.cloneWith(this.#e.node,{nullsNotDistinct:!0})})}on(e){return new t({...this.#e,node:re.cloneWith(this.#e.node,{table:N(e)})})}column(e){return new t({...this.#e,node:re.cloneWithColumns(this.#e.node,[tt(e)])})}columns(e){return new t({...this.#e,node:re.cloneWithColumns(this.#e.node,e.map(tt))})}expression(e){return new t({...this.#e,node:re.cloneWithColumns(this.#e.node,[e.toOperationNode()])})}using(e){return new t({...this.#e,node:re.cloneWith(this.#e.node,{using:W.createWithSql(e)})})}where(...e){let r=new vt;return new t({...this.#e,node:u.cloneWithWhere(this.#e.node,r.transformNode(O(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(),this.#e.queryId)}};var Wr=class t{#e;constructor(e){this.#e=i(e)}ifNotExists(){return new t({...this.#e,node:Vt.cloneWith(this.#e.node,{ifNotExists:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};function jo(t){if(io.includes(t))return t;throw new Error(`invalid OnCommitAction ${t}`)}var Tr=class t{#e;constructor(e){this.#e=i(e)}temporary(){return new t({...this.#e,node:M.cloneWith(this.#e.node,{temporary:!0})})}onCommit(e){return new t({...this.#e,node:M.cloneWith(this.#e.node,{onCommit:jo(e)})})}ifNotExists(){return new t({...this.#e,node:M.cloneWith(this.#e.node,{ifNotExists:!0})})}addColumn(e,r,o=z){let n=o(new ve(v.create(e,ue(r))));return new t({...this.#e,node:M.cloneWithColumn(this.#e.node,n.toOperationNode())})}addPrimaryKeyConstraint(e,r,o=z){let n=o(new Ot(We.create(r,e)));return new t({...this.#e,node:M.cloneWithConstraint(this.#e.node,n.toOperationNode())})}addUniqueConstraint(e,r,o=z){let n=o(new gt(ye.create(r,e)));return new t({...this.#e,node:M.cloneWithConstraint(this.#e.node,n.toOperationNode())})}addCheckConstraint(e,r,o=z){let n=o(new bt(mt.create(r.toOperationNode(),e)));return new t({...this.#e,node:M.cloneWithConstraint(this.#e.node,n.toOperationNode())})}addForeignKeyConstraint(e,r,o,n,a=z){let d=a(new Nt(de.create(r.map(m.create),N(o),n.map(m.create),e)));return new t({...this.#e,node:M.cloneWithConstraint(this.#e.node,d.toOperationNode())})}modifyFront(e){return new t({...this.#e,node:M.cloneWithFrontModifier(this.#e.node,e.toOperationNode())})}modifyEnd(e){return new t({...this.#e,node:M.cloneWithEndModifier(this.#e.node,e.toOperationNode())})}as(e){return new t({...this.#e,node:M.cloneWith(this.#e.node,{selectQuery:$(e)})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var Sr=class t{#e;constructor(e){this.#e=i(e)}on(e){return new t({...this.#e,node:ke.cloneWith(this.#e.node,{table:N(e)})})}ifExists(){return new t({...this.#e,node:ke.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:ke.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var kr=class t{#e;constructor(e){this.#e=i(e)}ifExists(){return new t({...this.#e,node:Et.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:Et.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var Er=class t{#e;constructor(e){this.#e=i(e)}ifExists(){return new t({...this.#e,node:At.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:At.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var pe=i({is(t){return t.kind==="CreateViewNode"},create(t){return i({kind:"CreateViewNode",name:F.create(t)})},cloneWith(t,e){return i({...t,...e})}});var Ar=class{#e=new vt;transformQuery(e){return this.#e.transformNode(e.node,e.queryId)}transformResult(e){return Promise.resolve(e.result)}};var Rr=class t{#e;constructor(e){this.#e=i(e)}temporary(){return new t({...this.#e,node:pe.cloneWith(this.#e.node,{temporary:!0})})}materialized(){return new t({...this.#e,node:pe.cloneWith(this.#e.node,{materialized:!0})})}ifNotExists(){return new t({...this.#e,node:pe.cloneWith(this.#e.node,{ifNotExists:!0})})}orReplace(){return new t({...this.#e,node:pe.cloneWith(this.#e.node,{orReplace:!0})})}columns(e){return new t({...this.#e,node:pe.cloneWith(this.#e.node,{columns:e.map(ni)})})}as(e){let r=e.withPlugin(new Ar).toOperationNode();return new t({...this.#e,node:pe.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(),this.#e.queryId)}};var Ct=i({is(t){return t.kind==="DropViewNode"},create(t){return i({kind:"DropViewNode",name:F.create(t)})},cloneWith(t,e){return i({...t,...e})}});var Ir=class t{#e;constructor(e){this.#e=i(e)}materialized(){return new t({...this.#e,node:Ct.cloneWith(this.#e.node,{materialized:!0})})}ifExists(){return new t({...this.#e,node:Ct.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:Ct.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var Dr=i({is(t){return t.kind==="CreateTypeNode"},create(t){return i({kind:"CreateTypeNode",name:t})},cloneWithEnum(t,e){return i({...t,enum:he.create(e.map(k.createImmediate))})}});var qr=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:Dr.cloneWithEnum(this.#e.node,e)})}$call(e){return e(this)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var Br=i({is(t){return t.kind==="DropTypeNode"},create(t){return i({kind:"DropTypeNode",name:t})},cloneWith(t,e){return i({...t,...e})}});var Lr=class t{#e;constructor(e){this.#e=i(e)}ifExists(){return new t({...this.#e,node:Br.cloneWith(this.#e.node,{ifExists:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};function zi(t){let e=".";if(t.includes(e)){let r=t.split(e).map(zn);if(r.length===2)return F.createWithSchema(r[0],r[1]);throw new Error(`invalid schemable identifier ${t}`)}else return F.create(t)}function zn(t){return t.trim()}var Wt=i({is(t){return t.kind==="RefreshMaterializedViewNode"},create(t){return i({kind:"RefreshMaterializedViewNode",name:F.create(t)})},cloneWith(t,e){return i({...t,...e})}});var Qr=class t{#e;constructor(e){this.#e=i(e)}concurrently(){return new t({...this.#e,node:Wt.cloneWith(this.#e.node,{concurrently:!0,withNoData:!1})})}withData(){return new t({...this.#e,node:Wt.cloneWith(this.#e.node,{withNoData:!1})})}withNoData(){return new t({...this.#e,node:Wt.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(),this.#e.queryId)}};var Pr=class t{#e;constructor(e){this.#e=e}createTable(e){return new Tr({queryId:l(),executor:this.#e,node:M.create(N(e))})}dropTable(e){return new Er({queryId:l(),executor:this.#e,node:At.create(N(e))})}createIndex(e){return new Cr({queryId:l(),executor:this.#e,node:re.create(e)})}dropIndex(e){return new Sr({queryId:l(),executor:this.#e,node:ke.create(e)})}createSchema(e){return new Wr({queryId:l(),executor:this.#e,node:Vt.create(e)})}dropSchema(e){return new kr({queryId:l(),executor:this.#e,node:Et.create(e)})}alterTable(e){return new vr({queryId:l(),executor:this.#e,node:f.create(N(e))})}createView(e){return new Rr({queryId:l(),executor:this.#e,node:pe.create(e)})}refreshMaterializedView(e){return new Qr({queryId:l(),executor:this.#e,node:Wt.create(e)})}dropView(e){return new Ir({queryId:l(),executor:this.#e,node:Ct.create(e)})}createType(e){return new qr({queryId:l(),executor:this.#e,node:Dr.create(zi(e))})}dropType(e){return new Lr({queryId:l(),executor:this.#e,node:Br.create(zi(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 te(e)))}};var Mr=class{ref(e){return new $t(e)}table(e){return new xr(e)}};var Fr=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 zr=class t extends ut{#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 Vr(){return typeof performance<"u"&&T(performance.now)?performance.now():Date.now()}var Ur=class{#e;#t;#r;#i;#o;#a=new WeakSet;constructor(e,r){this.#i=!1,this.#e=e,this.#t=r}async init(){if(this.#o)throw new Error("driver has already been destroyed");this.#r||(this.#r=this.#e.init().then(()=>{this.#i=!0}).catch(e=>(this.#r=void 0,Promise.reject(e)))),await this.#r}async acquireConnection(){if(this.#o)throw new Error("driver has already been destroyed");this.#i||await this.init();let e=await this.#e.acquireConnection();return this.#a.has(e)||(this.#d()&&this.#n(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.#o||(this.#o=this.#e.destroy().catch(e=>(this.#o=void 0,Promise.reject(e)))),await this.#o)}#d(){return this.#t.isLevelEnabled("query")||this.#t.isLevelEnabled("error")}#n(e){let r=e.executeQuery,o=e.streamQuery,n=this;e.executeQuery=async a=>{let d,c=Vr();try{return await r.call(e,a)}catch(y){throw d=y,await n.#s(y,a,c),y}finally{d||await n.#u(a,c)}},e.streamQuery=async function*(a,d){let c,y=Vr();try{for await(let h of o.call(e,a,d))yield h}catch(h){throw c=h,await n.#s(h,a,y),h}finally{c||await n.#u(a,y,!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 Vr()-e}};var Vn=()=>{},Tt=class{#e;#t;constructor(e){this.#e=e}async provideConnection(e){for(;this.#t;)await this.#t.catch(Vn);return this.#t=this.#r(e).finally(()=>{this.#t=void 0}),this.#t}async#r(e){return await e(this.#e)}};var Un=["read only","read write"],Jn=["read uncommitted","read committed","repeatable read","serializable","snapshot"];function Vi(t){if(t.accessMode&&!Un.includes(t.accessMode))throw new Error(`invalid transaction access mode ${t.accessMode}`);if(t.isolationLevel&&!Jn.includes(t.isolationLevel))throw new Error(`invalid transaction isolation level ${t.isolationLevel}`)}var VC=i(["query","error"]),Jr=class{#e;#t;constructor(e){T(e)?(this.#t=e,this.#e=i({query:!0,error:!0})):(this.#t=$n,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 $n(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 Ho(t){return B(t)&&T(t.compile)}Symbol.asyncDispose??=Symbol("Symbol.asyncDispose");var St=class t extends dt{#e;constructor(e){let r,o;if(Kn(e))r={executor:e.executor},o={...e};else{let n=e.dialect,a=n.createDriver(),d=n.createQueryCompiler(),c=n.createAdapter(),y=new Jr(e.log??[]),h=new Ur(a,y),G=new Fr(h),E=new zr(d,c,G,e.plugins??[]);r={executor:E},o={config:e,executor:E,dialect:n,driver:h}}super(r),this.#e=i(o)}get schema(){return new Pr(this.#e.executor)}get dynamic(){return new Mr}get introspection(){return this.#e.dialect.createIntrospector(this.withoutPlugins())}case(e){return new ct({node:_.create(j(e)?void 0:$(e))})}get fn(){return Nr()}transaction(){return new Ji({...this.#e})}startTransaction(){return new $i({...this.#e})}connection(){return new Ui({...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 te(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=l()){let o=Ho(e)?e.compile():e;return this.getExecutor().executeQuery(o,r)}async[Symbol.asyncDispose](){await this.destroy()}},$r=class t extends St{#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 te(e))})}withTables(){return new t({...this.#e})}};function Kn(t){return B(t)&&B(t.config)&&B(t.driver)&&B(t.executor)&&B(t.dialect)}var Ui=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 Tt(r)),n=new St({...this.#e,executor:o});return await e(n)})}},Ji=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,a={isolationLevel:r,accessMode:o};return Vi(a),this.#e.executor.provideConnection(async d=>{let c=this.#e.executor.withConnectionProvider(new Tt(d)),y=new $r({...n,executor:c});try{await this.#e.driver.beginTransaction(d,a);let h=await e(y);return await this.#e.driver.commitTransaction(d),h}catch(h){throw await this.#e.driver.rollbackTransaction(d),h}})}},$i=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};Vi(n);let a=await pr(this.#e.executor);return await this.#e.driver.beginTransaction(a.connection,n),new Ki({...o,connection:a,executor:this.#e.executor.withConnectionProvider(new Tt(a.connection))})}},Ki=class t extends $r{#e;#t;#r;constructor(e){let r={isCommitted:!1,isRolledBack:!1};e={...e,executor:new Gi(e.executor,r)};let{connection:o,...n}=e;super(n),this.#e=i(e),this.#r=r;let a=l();this.#t=d=>e.executor.compileQuery(d,a)}get isCommitted(){return this.#r.isCommitted}get isRolledBack(){return this.#r.isRolledBack}commit(){return He(this.#r),new je(async()=>{await this.#e.driver.commitTransaction(this.#e.connection.connection),this.#r.isCommitted=!0,this.#e.connection.release()})}rollback(){return He(this.#r),new je(async()=>{await this.#e.driver.rollbackTransaction(this.#e.connection.connection),this.#r.isRolledBack=!0,this.#e.connection.release()})}savepoint(e){return He(this.#r),new je(async()=>(await this.#e.driver.savepoint?.(this.#e.connection.connection,e,this.#t),new t({...this.#e})))}rollbackToSavepoint(e){return He(this.#r),new je(async()=>(await this.#e.driver.rollbackToSavepoint?.(this.#e.connection.connection,e,this.#t),new t({...this.#e})))}releaseSavepoint(e){return He(this.#r),new je(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 te(e))})}withTables(){return new t({...this.#e})}},je=class{#e;constructor(e){this.#e=e}async execute(){return await this.#e()}};function He(t){if(t.isCommitted)throw new Error("Transaction is already committed");if(t.isRolledBack)throw new Error("Transaction is already rolled back")}var Gi=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,r){return He(this.#t),this.#e.executeQuery(e,r)}stream(e,r,o){return He(this.#t),this.#e.stream(e,r,o)}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 ji=class t{#e;constructor(e){this.#e=i(e)}get expressionType(){}get isRawBuilder(){return!0}as(e){return new Hi(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.#i(this.#t(e))}async execute(e){let r=this.#t(e);return r.executeQuery(this.#i(r),this.#e.queryId)}#t(e){let r=e!==void 0?e.getExecutor():Be;return this.#e.plugins!==void 0?r.withPlugins(this.#e.plugins):r}#r(e){return e.transformQuery(this.#e.rawNode,this.#e.queryId)}#i(e){return e.compileQuery(this.#r(e),this.#e.queryId)}};function Te(t){return new ji(t)}var Hi=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 R.create(this.#e.toOperationNode(),b(this.#t)?this.#t.toOperationNode():p.create(this.#t))}};var K=Object.assign((t,...e)=>Te({queryId:l(),rawNode:W.create(t,e?.map(Yo)??[])}),{ref(t){return Te({queryId:l(),rawNode:W.createWithChild(X(t))})},val(t){return Te({queryId:l(),rawNode:W.createWithChild(g(t))})},value(t){return this.val(t)},table(t){return Te({queryId:l(),rawNode:W.createWithChild(N(t))})},id(...t){let e=new Array(t.length+1).fill(".");return e[0]="",e[e.length-1]="",Te({queryId:l(),rawNode:W.create(e,t.map(p.create))})},lit(t){return Te({queryId:l(),rawNode:W.createWithChild(k.createImmediate(t))})},literal(t){return this.lit(t)},raw(t){return Te({queryId:l(),rawNode:W.createWithSql(t)})},join(t,e=K`, `){let r=new Array(Math.max(2*t.length-1,0)),o=e.toOperationNode();for(let n=0;n<t.length;++n)r[2*n]=Yo(t[n]),n!==t.length-1&&(r[2*n+1]=o);return Te({queryId:l(),rawNode:W.createWithChildren(r)})}});function Yo(t){return b(t)?t.toOperationNode():g(t)}var Kr=class{nodeStack=[];get parentNode(){return this.nodeStack[this.nodeStack.length-2]}#e=i({AliasNode:this.visitAlias.bind(this),ColumnNode:this.visitColumn.bind(this),IdentifierNode:this.visitIdentifier.bind(this),SchemableIdentifierNode:this.visitSchemableIdentifier.bind(this),RawNode:this.visitRaw.bind(this),ReferenceNode:this.visitReference.bind(this),SelectQueryNode:this.visitSelectQuery.bind(this),SelectionNode:this.visitSelection.bind(this),TableNode:this.visitTable.bind(this),FromNode:this.visitFrom.bind(this),SelectAllNode:this.visitSelectAll.bind(this),AndNode:this.visitAnd.bind(this),OrNode:this.visitOr.bind(this),ValueNode:this.visitValue.bind(this),ValueListNode:this.visitValueList.bind(this),PrimitiveValueListNode:this.visitPrimitiveValueList.bind(this),ParensNode:this.visitParens.bind(this),JoinNode:this.visitJoin.bind(this),OperatorNode:this.visitOperator.bind(this),WhereNode:this.visitWhere.bind(this),InsertQueryNode:this.visitInsertQuery.bind(this),DeleteQueryNode:this.visitDeleteQuery.bind(this),ReturningNode:this.visitReturning.bind(this),CreateTableNode:this.visitCreateTable.bind(this),AddColumnNode:this.visitAddColumn.bind(this),ColumnDefinitionNode:this.visitColumnDefinition.bind(this),DropTableNode:this.visitDropTable.bind(this),DataTypeNode:this.visitDataType.bind(this),OrderByNode:this.visitOrderBy.bind(this),OrderByItemNode:this.visitOrderByItem.bind(this),GroupByNode:this.visitGroupBy.bind(this),GroupByItemNode:this.visitGroupByItem.bind(this),UpdateQueryNode:this.visitUpdateQuery.bind(this),ColumnUpdateNode:this.visitColumnUpdate.bind(this),LimitNode:this.visitLimit.bind(this),OffsetNode:this.visitOffset.bind(this),OnConflictNode:this.visitOnConflict.bind(this),OnDuplicateKeyNode:this.visitOnDuplicateKey.bind(this),CreateIndexNode:this.visitCreateIndex.bind(this),DropIndexNode:this.visitDropIndex.bind(this),ListNode:this.visitList.bind(this),PrimaryKeyConstraintNode:this.visitPrimaryKeyConstraint.bind(this),UniqueConstraintNode:this.visitUniqueConstraint.bind(this),ReferencesNode:this.visitReferences.bind(this),CheckConstraintNode:this.visitCheckConstraint.bind(this),WithNode:this.visitWith.bind(this),CommonTableExpressionNode:this.visitCommonTableExpression.bind(this),CommonTableExpressionNameNode:this.visitCommonTableExpressionName.bind(this),HavingNode:this.visitHaving.bind(this),CreateSchemaNode:this.visitCreateSchema.bind(this),DropSchemaNode:this.visitDropSchema.bind(this),AlterTableNode:this.visitAlterTable.bind(this),DropColumnNode:this.visitDropColumn.bind(this),RenameColumnNode:this.visitRenameColumn.bind(this),AlterColumnNode:this.visitAlterColumn.bind(this),ModifyColumnNode:this.visitModifyColumn.bind(this),AddConstraintNode:this.visitAddConstraint.bind(this),DropConstraintNode:this.visitDropConstraint.bind(this),RenameConstraintNode:this.visitRenameConstraint.bind(this),ForeignKeyConstraintNode:this.visitForeignKeyConstraint.bind(this),CreateViewNode:this.visitCreateView.bind(this),RefreshMaterializedViewNode:this.visitRefreshMaterializedView.bind(this),DropViewNode:this.visitDropView.bind(this),GeneratedNode:this.visitGenerated.bind(this),DefaultValueNode:this.visitDefaultValue.bind(this),OnNode:this.visitOn.bind(this),ValuesNode:this.visitValues.bind(this),SelectModifierNode:this.visitSelectModifier.bind(this),CreateTypeNode:this.visitCreateType.bind(this),DropTypeNode:this.visitDropType.bind(this),ExplainNode:this.visitExplain.bind(this),DefaultInsertValueNode:this.visitDefaultInsertValue.bind(this),AggregateFunctionNode:this.visitAggregateFunction.bind(this),OverNode:this.visitOver.bind(this),PartitionByNode:this.visitPartitionBy.bind(this),PartitionByItemNode:this.visitPartitionByItem.bind(this),SetOperationNode:this.visitSetOperation.bind(this),BinaryOperationNode:this.visitBinaryOperation.bind(this),UnaryOperationNode:this.visitUnaryOperation.bind(this),UsingNode:this.visitUsing.bind(this),FunctionNode:this.visitFunction.bind(this),CaseNode:this.visitCase.bind(this),WhenNode:this.visitWhen.bind(this),JSONReferenceNode:this.visitJSONReference.bind(this),JSONPathNode:this.visitJSONPath.bind(this),JSONPathLegNode:this.visitJSONPathLeg.bind(this),JSONOperatorChainNode:this.visitJSONOperatorChain.bind(this),TupleNode:this.visitTuple.bind(this),MergeQueryNode:this.visitMergeQuery.bind(this),MatchedNode:this.visitMatched.bind(this),AddIndexNode:this.visitAddIndex.bind(this),CastNode:this.visitCast.bind(this),FetchNode:this.visitFetch.bind(this),TopNode:this.visitTop.bind(this),OutputNode:this.visitOutput.bind(this),OrActionNode:this.visitOrAction.bind(this),CollateNode:this.visitCollate.bind(this)});visitNode=e=>{this.nodeStack.push(e),this.#e[e.kind](e),this.nodeStack.pop()}};var Gn=/'/g,Gr=class extends Kr{#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&&!me.is(this.parentNode)&&!S.is(this.parentNode)&&!M.is(this.parentNode)&&!pe.is(this.parentNode)&&!lr.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]),n<o&&this.append(r)}visitWhere(e){this.append("where "),this.visitNode(e.where)}visitHaving(e){this.append("having "),this.visitNode(e.having)}visitInsertQuery(e){let r=this.nodeStack.find(u.is),o=r!==e;!o&&e.explain&&(this.visitNode(e.explain),this.append(" ")),o&&!D.is(r)&&this.append("("),e.with&&(this.visitNode(e.with),this.append(" ")),this.append(e.replace?"replace":"insert"),e.ignore&&(Ae("`InsertQueryNode.ignore` is deprecated. Use `InsertQueryNode.orAction` instead."),this.append(" ignore")),e.orAction&&(this.append(" "),this.visitNode(e.orAction)),e.top&&(this.append(" "),this.visitNode(e.top)),e.into&&(this.append(" into "),this.visitNode(e.into)),e.columns&&(this.append(" ("),this.compileList(e.columns),this.append(")")),e.output&&(this.append(" "),this.visitNode(e.output)),e.values&&(this.append(" "),this.visitNode(e.values)),e.defaultValues&&(this.append(" "),this.append("default values")),e.onConflict&&(this.append(" "),this.visitNode(e.onConflict)),e.onDuplicateKey&&(this.append(" "),this.visitNode(e.onDuplicateKey)),e.returning&&(this.append(" "),this.visitNode(e.returning)),o&&!D.is(r)&&this.append(")"),e.endModifiers?.length&&(this.append(" "),this.compileList(e.endModifiers," "))}visitValues(e){this.append("values "),this.compileList(e.values)}visitDeleteQuery(e){let r=this.nodeStack.find(u.is)!==e;!r&&e.explain&&(this.visitNode(e.explain),this.append(" ")),r&&this.append("("),e.with&&(this.visitNode(e.with),this.append(" ")),this.append("delete "),e.top&&(this.visitNode(e.top),this.append(" ")),this.visitNode(e.from),e.output&&(this.append(" "),this.visitNode(e.output)),e.using&&(this.append(" "),this.visitNode(e.using)),e.joins&&(this.append(" "),this.compileList(e.joins," ")),e.where&&(this.append(" "),this.visitNode(e.where)),e.orderBy&&(this.append(" "),this.visitNode(e.orderBy)),e.limit&&(this.append(" "),this.visitNode(e.limit)),e.returning&&(this.append(" "),this.visitNode(e.returning)),r&&this.append(")"),e.endModifiers?.length&&(this.append(" "),this.compileList(e.endModifiers," "))}visitReturning(e){this.append("returning "),this.compileList(e.selections)}visitAlias(e){this.visitNode(e.node),this.append(" as "),this.visitNode(e.alias)}visitReference(e){e.table&&(this.visitNode(e.table),this.append(".")),this.visitNode(e.column)}visitSelectAll(e){this.append("*")}visitIdentifier(e){this.append(this.getLeftIdentifierWrapper()),this.compileUnwrappedIdentifier(e),this.append(this.getRightIdentifierWrapper())}compileUnwrappedIdentifier(e){if(!C(e.name))throw new Error("a non-string identifier was passed to compileUnwrappedIdentifier.");this.append(this.sanitizeIdentifier(e.name))}visitAnd(e){this.visitNode(e.left),this.append(" and "),this.visitNode(e.right)}visitOr(e){this.visitNode(e.left),this.append(" or "),this.visitNode(e.right)}visitValue(e){e.immediate?this.appendImmediateValue(e.value):this.appendValue(e.value)}visitValueList(e){this.append("("),this.compileList(e.values),this.append(")")}visitTuple(e){this.append("("),this.compileList(e.values),this.append(")")}visitPrimitiveValueList(e){this.append("(");let{values:r}=e;for(let o=0;o<r.length;++o)this.appendValue(r[o]),o!==r.length-1&&this.append(", ");this.append(")")}visitParens(e){this.append("("),this.visitNode(e.node),this.append(")")}visitJoin(e){this.append(Hn[e.joinType]),this.append(" "),this.visitNode(e.table),e.on&&(this.append(" "),this.visitNode(e.on))}visitOn(e){this.append("on "),this.visitNode(e.on)}visitRaw(e){let{sqlFragments:r,parameters:o}=e;for(let n=0;n<r.length;++n)this.append(r[n]),o.length>n&&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.nodeStack.find(u.is),o=r!==e;if(!o&&e.explain&&(this.visitNode(e.explain),this.append(" ")),o&&!D.is(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)),o&&!D.is(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 "),ze(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(jn[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 Y.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<o;r++)r===o-1?this.visitNode(e.operator):this.append("->"),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 a of e)n+=a,a===r?n+=r:a===o&&(n+=o);return n}sanitizeStringLiteral(e){return e.replace(Gn,"''")}addParameter(e){this.#t.push(e)}appendImmediateValue(e){if(C(e))this.appendStringLiteral(e);else if(Se(e)||ze(e))this.append(e.toString());else if(Ye(e))this.append("null");else if(ro(e))this.appendImmediateValue(e.toISOString());else if(Xe(e))this.appendImmediateValue(e.toString());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?Xo[r.modifier]-Xo[o.modifier]:1),i(e)}compileColumnAlterations(e){this.compileList(e)}announcesNewColumnDataType(){return!0}},jn=i({ForKeyShare:"for key share",ForNoKeyUpdate:"for no key update",ForUpdate:"for update",ForShare:"for share",NoWait:"nowait",SkipLocked:"skip locked",Distinct:"distinct"}),Xo=i({ForKeyShare:1,ForNoKeyUpdate:1,ForUpdate:1,ForShare:1,NoWait:2,SkipLocked:2,Distinct:0}),Hn=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 jr=class{async init(){}async acquireConnection(){return new Yi}async beginTransaction(){}async commitTransaction(){}async rollbackTransaction(){}async releaseConnection(){}async destroy(){}async releaseSavepoint(){}async rollbackToSavepoint(){}async savepoint(){}},Yi=class{async executeQuery(){return{rows:[]}}async*streamQuery(){}};var Hr=class{get supportsCreateIfNotExists(){return!0}get supportsTransactionalDdl(){return!1}get supportsReturning(){return!1}get supportsOutput(){return!1}};var Yn=/"/g,Yr=class extends Gr{sanitizeIdentifier(e){return e.replace(Yn,'""')}};var Xn=BigInt("3853314791062309107"),Xr=class extends Hr{get supportsTransactionalDdl(){return!0}get supportsReturning(){return!0}async acquireMigrationLock(e,r){await K`select pg_advisory_xact_lock(${K.lit(Xn)})`.execute(e)}async releaseMigrationLock(e,r){}};function Zo(t){return new St({dialect:{createAdapter:()=>new t.Adapter,createDriver:()=>new jr,createIntrospector:()=>null,createQueryCompiler:()=>new t.QueryCompiler},plugins:[...t.noParameters?[new Xi]:[]]})}var Xi=class{#e=new Zi;transformQuery(e){return this.#e.transformNode(e.node)}transformResult(e){return Promise.resolve(e.result)}},Zi=class extends qe{transformPrimitiveValueList(e){return he.create(e.values.map(k.createImmediate))}transformValue(e){return{...super.transformValue(e),immediate:!0}}};function Pe(t){let e=t.compile();return{parameters:e.parameters,sql:e.sql}}function _i(t,e){let r=_n(t,e);return o=>o.where(n=>n.or(r.map(a=>n.and(a.map(([d,c])=>n(d,c===null?"is":"=",c))))))}function Zn(t,e){return Object.entries(Object.values(e).reduce((r,o)=>{let{isInPrimaryKey:n,name:a}=o;return n&&(r[a]=t[a]),r},{}))}function _n(t,e){return t.map(r=>Zn(r,e))}function Me(t){return Zo({...t,Adapter:Xr,QueryCompiler:Yr})}function _o(t,e){let{table:r,rows:o}=t,{name:n,schema:a,columns:d}=r,c=Me(e),y=Object.values(d).map(({name:h})=>`${n}.${h}`);return Pe(c.withSchema(a).insertInto(n).values(o).returning(y).returning(h=>h.cast("ctid","text").as("ctid")))}function en(t,e){let{pageIndex:r,pageSize:o,sortOrder:n,table:{name:a,schema:d,columns:c}}=t,y=Me(e),h=Object.values(c).map(({name:E})=>`${a}.${E}`),G=y.withSchema(d).selectFrom(a).select(E=>E.cast(E.fn.coalesce(E.fn.countAll(),K.lit(0)),"text").as("value"));return Pe(y.with("count",()=>G).withSchema(d).selectFrom([a,"count"]).select(K.ref("count.value").$castTo().as("oid")).select(E=>E.cast("ctid","text").as("ctid")).select(h).$call(E=>n.reduce((U,Fe)=>U.orderBy(Fe.column,Fe.direction),E)).limit(o).offset(K.lit(BigInt(r)*BigInt(o))))}function tn(t,e){let{changes:r,row:o,table:{columns:n,name:a,schema:d}}=t,c=Me(e),y=Object.values(n).map(({name:h})=>`${a}.${h}`);return Pe(c.withSchema(d).updateTable(a).set(r).$call(_i([o],n)).returning(y).returning(h=>[h.cast("ctid","text").as("ctid"),h.cast(h.fn("floor",[h(h.fn("extract",[K`epoch from now()`]),"*",1e6)]),"text").as("__ps_updated_at__")]))}function rn(t,e){let{rows:r,table:{columns:o,name:n,schema:a}}=t,d=Me(e);return Pe(d.withSchema(a).deleteFrom(n).$call(_i(r,o)))}function on(t){return K`(select coalesce(json_agg(agg), '[]') from ${t} as agg)`}var es="r",ts="v",rs=[es,ts];function nn(t){return Pe(Me(t).selectFrom("pg_catalog.pg_class as cls").innerJoin("pg_catalog.pg_namespace as ns","cls.relnamespace","ns.oid").$call(is).where("cls.relkind","in",rs).select(e=>["ns.nspname as schema","cls.relname as name",on(e.selectFrom("pg_catalog.pg_attribute as att").innerJoin("pg_catalog.pg_type as typ","typ.oid","att.atttypid").innerJoin("pg_catalog.pg_namespace as tns","tns.oid","typ.typnamespace").leftJoin("pg_catalog.pg_constraint as con",r=>r.on("con.contype","=","p").onRef("con.conrelid","=","cls.oid").on(o=>o("att.attnum","=",o.fn.any("con.conkey")))).whereRef("att.attrelid","=","cls.oid").where("att.attnum",">=",0).where("att.attisdropped","!=",!0).where("att.attgenerated","=","").select(["att.attname as name","typ.typname as datatype","tns.nspname as datatype_schema"]).select(r=>[r("con.conkey","is not",null).$castTo().as("pk"),r("att.attgenerated","!=","").$castTo().as("computed"),r("att.attnotnull","!=",!0).$castTo().as("nullable"),r.fn.coalesce(r.selectFrom("pg_catalog.pg_enum as enm").whereRef("enm.enumtypid","=","typ.oid").select(o=>o.fn.jsonAgg(o.ref("enm.enumlabel")).as("o")),K`'[]'`).as("options")])).as("columns")]))}function sn(){let t=Me();return Pe(t.selectNoFrom(t.fn("current_setting",[K.lit("timezone")]).as("timezone")))}function is(t){return t.where("ns.nspname","!~","^pg_").where("ns.nspname","!=","information_schema")}function an(t){let{executor:e,...r}=t;return{defaultSchema:"public",async introspect(o){try{let n=nn(r),a=sn(),[[d,c],[y,h]]=await Promise.all([e.execute(n,o),e.execute(a,o)]),G=d||y;if(G)return[G];let[E]=h;return E?[null,os(c,E.timezone)]:[new Error("Timezone not found")]}catch(n){return[n]}},async query(o,n){try{let a=en(o,r),[d,c]=await e.execute(a,n);return d?[d]:[null,{filteredRowCount:c[0]?.oid||"0",rows:c}]}catch(a){return[a]}},async insert(o,n){try{let a=_o(o,r),[d,c]=await e.execute(a,n);return d?[d]:[null,{rows:c}]}catch(a){return[a]}},async update(o,n){try{let a=tn(o,r),[d,c]=await e.execute(a,n);if(d)return[d];let[y]=c;return y?[null,{row:y}]:[new Error("Update failed")]}catch(a){return[a]}},async delete(o,n){try{let a=rn(o,r),[d]=await e.execute(a,n);return d?[d]:[null,o]}catch(a){return[a]}}}}function os(t,e){return t.reduce((r,o)=>{let{schemas:n}=r,{columns:a,name:d,schema:c}=o,y=a.reduce((h,G)=>{let{datatype:E,datatype_schema:U,name:Fe,options:eo,nullable:dn}=G,Zr=E.startsWith("_"),_r=Zr?E.slice(1):E;return{...h,[Fe]:{datatype:{...to[_r]||{group:eo.length>0?"enum":"raw"},isArray:Zr,isNative:U==="pg_catalog",name:Zr?`${_r}[]`:_r,options:eo,schema:U},isComputed:G.computed,isInPrimaryKey:G.pk,name:Fe,nullable:dn,schema:c,table:d}}},{});return(n[c]||={tables:{}}).tables[d]={columns:y,name:d,schema:c},r},{schemas:{public:{tables:{}}},timezone:e})}function un(t,e){let{addDelay:r=0}=e??{};return{execute:async(o,n)=>{let{abortSignal:a}=n||{},d,c=new Promise((U,Fe)=>d=Fe);function y(){let U=new Error("This operation was aborted");U.name="AbortError",d(U)}a?.addEventListener("abort",y);let h=typeof r=="function"?r(o):r,G=()=>t.query(o.sql,o.parameters,{rowMode:"object"}),E=h>0?()=>new Promise(U=>setTimeout(U,h)).then(()=>G()):G;try{return[null,(await Promise.race([E(),c])).rows]}catch(U){return[U]}finally{a?.removeEventListener("abort",y)}}}}function ns(t,e){return an({executor:un(t,e)})}0&&(module.exports={createPGLiteAdapter,createPGLiteExecutor});
|