@shumai-one/shumai-transcode 0.1.7 → 0.1.8
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/bin/chunk-06yecqzt.js +2 -0
- package/bin/chunk-0e41hmxh.js +2 -0
- package/bin/chunk-5t78zdc8.js +3 -0
- package/bin/chunk-7sx9g2gs.js +12 -0
- package/bin/chunk-8d9pzbnd.js +2 -0
- package/bin/chunk-8m5z0v3d.js +11511 -0
- package/bin/chunk-9zem8ffs.js +3 -0
- package/bin/chunk-cq2r8hc4.js +3 -0
- package/bin/chunk-deg4vcxz.js +2 -0
- package/bin/chunk-jsvz5f2k.js +3 -0
- package/bin/chunk-mary8ss4.js +2 -0
- package/bin/chunk-nr15akde.js +6 -0
- package/bin/chunk-xg9xscqz.js +1 -0
- package/bin/shumai-transcode-app.js +186 -11707
- package/package.json +7 -7
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var j=Object.create;var{getPrototypeOf:k,defineProperty:f,getOwnPropertyNames:l}=Object;var m=Object.prototype.hasOwnProperty;function n(a){return this[a]}var o,p,s=(a,b,c)=>{var g=a!=null&&typeof a==="object";if(g){var h=b?o??=new WeakMap:p??=new WeakMap,i=h.get(a);if(i)return i}c=a!=null?j(k(a)):{};let d=b||!a||!a.__esModule?f(c,"default",{value:a,enumerable:!0}):c;for(let e of l(a))if(!m.call(d,e))f(d,e,{get:n.bind(a,e),enumerable:!0});if(g)h.set(a,d);return d};var t=(a,b)=>()=>(b||a((b={exports:{}}).exports,b),b.exports);var q=(a)=>a;function r(a,b){this[a]=q.bind(null,b)}var u=(a,b)=>{for(var c in b)f(a,c,{get:b[c],enumerable:!0,configurable:!0,set:r.bind(b,c)})};var v=import.meta.require;
|
|
3
|
+
export{s as Wa,t as Xa,u as Ya,v as Za};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{Ta as a}from"./chunk-jsvz5f2k.js";var l=/"/g,n=/[\\'"]/g;class r extends a{visitOrAction(t){this.append("or "),this.append(t.action)}getCurrentParameterPlaceholder(){return"?"}getLeftExplainOptionsWrapper(){return""}getRightExplainOptionsWrapper(){return""}getLeftIdentifierWrapper(){return'"'}getRightIdentifierWrapper(){return'"'}getAutoIncrement(){return"autoincrement"}sanitizeIdentifier(t){return t.replace(l,'""')}sanitizeJSONPathMemberValue(t){return t.replace(n,(e)=>e==="\\"?"\\\\":e==="'"?"''":"\\\"")}visitDefaultInsertValue(t){this.append("null")}}class s{get supportsCreateIfNotExists(){return!0}get supportsTransactionalDdl(){return!1}get supportsReturning(){return!1}get supportsOutput(){return!1}}class p extends s{get supportsTransactionalDdl(){return!1}get supportsReturning(){return!0}async acquireMigrationLock(t,e){}async releaseMigrationLock(t,e){}}
|
|
3
|
+
export{s as fa,r as ga,p as ha};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{da as J,ea as H}from"./chunk-5t78zdc8.js";import{Ta as P,Ua as V,Va as W}from"./chunk-jsvz5f2k.js";import"./chunk-9zem8ffs.js";var X=class{get supportsCreateIfNotExists(){return!0}get supportsTransactionalDdl(){return!1}get supportsReturning(){return!0}async acquireMigrationLock(){}async releaseMigrationLock(){}get supportsOutput(){return!0}},Y=class{#h;#j=new $;#w;#z;constructor(h){this.#h={...h}}async init(){if(this.#w=this.#h.database,this.#z=new Z(this.#w),this.#h.onCreateConnection)await this.#h.onCreateConnection(this.#z)}async acquireConnection(){return await this.#j.lock(),this.#z}async beginTransaction(h){await h.executeQuery(H.raw("begin"))}async commitTransaction(h){await h.executeQuery(H.raw("commit"))}async rollbackTransaction(h){await h.executeQuery(H.raw("rollback"))}async releaseConnection(){this.#j.unlock()}async destroy(){this.#w?.close()}},Z=class{#h;constructor(h){this.#h=h}executeQuery(h){let{sql:w,parameters:z}=h,j=this.#h.prepare(w);return Promise.resolve({rows:j.all(z)})}async*streamQuery(){throw Error("Streaming query is not supported by SQLite driver.")}},$=class{#h;#j;async lock(){while(this.#h!==void 0)await this.#h;this.#h=new Promise((h)=>{this.#j=h})}unlock(){let h=this.#j;this.#h=void 0,this.#j=void 0,h?.()}},k=class{#h;constructor(h){this.#h=h}async getSchemas(){return[]}async getTables(h={withInternalKyselyTables:!1}){let w=this.#h.selectFrom("sqlite_schema").where("type","=","table").where("name","not like","sqlite_%").select("name").$castTo();if(!h.withInternalKyselyTables)w=w.where("name","!=",V).where("name","!=",W);let z=await w.execute();return Promise.all(z.map(({name:j})=>this.#j(j)))}async getMetadata(h){return{tables:await this.getTables(h)}}async#j(h){let w=this.#h,z=(await w.selectFrom("sqlite_master").where("name","=",h).select("sql").$castTo().execute())[0]?.sql?.split(/[\(\),]/)?.find((j)=>j.toLowerCase().includes("autoincrement"))?.split(/\s+/)?.[0]?.replace(/["`]/g,"");return{name:h,columns:(await w.selectFrom(J`pragma_table_info(${h})`.as("table_info")).select(["name","type","notnull","dflt_value"]).execute()).map((j)=>({name:j.name,dataType:j.type,isNullable:!j.notnull,isAutoIncrementing:j.name===z,hasDefaultValue:j.dflt_value!=null})),isView:!0}}},K=class extends P{getCurrentParameterPlaceholder(){return"?"}getLeftIdentifierWrapper(){return'"'}getRightIdentifierWrapper(){return'"'}getAutoIncrement(){return"autoincrement"}},G=class{#h;constructor(h){this.#h={...h}}createDriver(){return new Y(this.#h)}createQueryCompiler(){return new K}createAdapter(){return new X}createIntrospector(h){return new k(h)}};export{G as BunSqliteDialect};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
function ct(t){return typeof t>"u"||t===void 0}function V(t){return typeof t==="string"}function F(t){return typeof t==="number"}function J(t){return typeof t==="boolean"}function Y(t){return t===null}function Z(t){return t instanceof Date}function $(t){return typeof t==="bigint"}function pt(t){return typeof Buffer<"u"&&Buffer.isBuffer(t)}function St(t){return typeof t==="function"}function X(t){return typeof t==="object"&&t!==null}function G(t){return t[t.length-1]}function N(t){return Object.freeze(t)}function Wt(t){if(r(t))return t;else return[t]}function r(t){return Array.isArray(t)}function Vt(t){return t}var Bt=["preserve rows","delete rows","drop"],L=N({is(t){return t.kind==="CreateTableNode"},create(t){return N({kind:"CreateTableNode",table:t,columns:N([])})},cloneWithColumn(t,i){return N({...t,columns:N([...t.columns,i])})},cloneWithConstraint(t,i){return N({...t,constraints:t.constraints?N([...t.constraints,i]):N([i])})},cloneWithFrontModifier(t,i){return N({...t,frontModifiers:t.frontModifiers?N([...t.frontModifiers,i]):N([i])})},cloneWithEndModifier(t,i){return N({...t,endModifiers:t.endModifiers?N([...t.endModifiers,i]):N([i])})},cloneWith(t,i){return N({...t,...i})}});var x=N({is(t){return t.kind==="InsertQueryNode"},create(t,i,h){return N({kind:"InsertQueryNode",into:t,...i&&{with:i},replace:h})},createWithoutInto(){return N({kind:"InsertQueryNode"})},cloneWith(t,i){return N({...t,...i})}});class U{nodeStack=[];get parentNode(){return this.nodeStack[this.nodeStack.length-2]}#t=N({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=(t)=>{this.nodeStack.push(t),this.#t[t.kind](t),this.nodeStack.pop()}}var q=["=","==","!=","<>",">",">=","<","<=","in","not in","is","is not","like","not like","match","ilike","not ilike","@>","<@","^@","&&","?","?&","?|","!<","!>","<=>","!~","~","~*","!~*","@@","@@@","!!","<->","regexp","is distinct from","is not distinct from"],n=["+","-","*","/","%","^","&","|","#","<<",">>"],_=["->","->>"],o=[...q,...n,"&&","||"],d=["exists","not exists"],e=["not","-",...d],Ht=[...o,..._,...e,"between","between symmetric"],m=N({is(t){return t.kind==="OperatorNode"},create(t){return N({kind:"OperatorNode",operator:t})}});function Kt(t){return V(t)&&_.includes(t)}var R=N({is(t){return t.kind==="ParensNode"},create(t){return N({kind:"ParensNode",node:t})}});var c=N({is(t){return t.kind==="RawNode"},create(t,i){return N({kind:"RawNode",sqlFragments:N(t),parameters:N(i)})},createWithSql(t){return c.create([t],[])},createWithChild(t){return c.create(["",""],[t])},createWithChildren(t){return c.create(Array(t.length+1).fill(""),t)}});var S=N({is(t){return t.kind==="IdentifierNode"},create(t){return N({kind:"IdentifierNode",name:t})}});var p=N({is(t){return t.kind==="SchemableIdentifierNode"},create(t){return N({kind:"SchemableIdentifierNode",identifier:S.create(t)})},createWithSchema(t,i){return N({kind:"SchemableIdentifierNode",schema:S.create(t),identifier:S.create(i)})}});var E=N({is(t){return t.kind==="CreateViewNode"},create(t){return N({kind:"CreateViewNode",name:p.create(t)})},cloneWith(t,i){return N({...t,...i})}});var M=N({is(t){return t.kind==="SetOperationNode"},create(t,i,h){return N({kind:"SetOperationNode",operator:t,expression:i,all:h})}});var Q=N({is(t){return t.kind==="WhenNode"},create(t){return N({kind:"WhenNode",condition:t})},cloneWithResult(t,i){return N({...t,result:i})}});var A=new Set;function b(t){if(A.has(t))return;A.add(t),console.log(t)}var tt=/'/g,it=/['"]/g;class ht extends U{#t="";#i=[];get numParameters(){return this.#i.length}compileQuery(t,i){return this.#t="",this.#i=[],this.nodeStack.splice(0,this.nodeStack.length),this.visitNode(t),N({query:t,queryId:i,sql:this.getSql(),parameters:[...this.#i]})}getSql(){return this.#t}visitSelectQuery(t){let i=this.parentNode!==void 0&&!R.is(this.parentNode)&&!x.is(this.parentNode)&&!L.is(this.parentNode)&&!E.is(this.parentNode)&&!M.is(this.parentNode);if(this.parentNode===void 0&&t.explain)this.visitNode(t.explain),this.append(" ");if(i)this.append("(");if(t.with)this.visitNode(t.with),this.append(" ");if(this.append("select"),t.distinctOn)this.append(" "),this.compileDistinctOn(t.distinctOn);if(t.frontModifiers?.length)this.append(" "),this.compileList(t.frontModifiers," ");if(t.top)this.append(" "),this.visitNode(t.top);if(t.selections)this.append(" "),this.compileList(t.selections);if(t.from)this.append(" "),this.visitNode(t.from);if(t.joins)this.append(" "),this.compileList(t.joins," ");if(t.where)this.append(" "),this.visitNode(t.where);if(t.groupBy)this.append(" "),this.visitNode(t.groupBy);if(t.having)this.append(" "),this.visitNode(t.having);if(t.setOperations)this.append(" "),this.compileList(t.setOperations," ");if(t.orderBy)this.append(" "),this.visitNode(t.orderBy);if(t.limit)this.append(" "),this.visitNode(t.limit);if(t.offset)this.append(" "),this.visitNode(t.offset);if(t.fetch)this.append(" "),this.visitNode(t.fetch);if(t.endModifiers?.length)this.append(" "),this.compileList(this.sortSelectModifiers([...t.endModifiers])," ");if(i)this.append(")")}visitFrom(t){this.append("from "),this.compileList(t.froms)}visitSelection(t){this.visitNode(t.selection)}visitColumn(t){this.visitNode(t.column)}compileDistinctOn(t){this.append("distinct on ("),this.compileList(t),this.append(")")}compileList(t,i=", "){let h=t.length-1;for(let f=0;f<=h;f++)if(this.visitNode(t[f]),f<h)this.append(i)}visitWhere(t){this.append("where "),this.visitNode(t.where)}visitHaving(t){this.append("having "),this.visitNode(t.having)}visitInsertQuery(t){let i=this.parentNode!==void 0&&!R.is(this.parentNode)&&!c.is(this.parentNode)&&!Q.is(this.parentNode);if(this.parentNode===void 0&&t.explain)this.visitNode(t.explain),this.append(" ");if(i)this.append("(");if(t.with)this.visitNode(t.with),this.append(" ");if(this.append(t.replace?"replace":"insert"),t.ignore)b("`InsertQueryNode.ignore` is deprecated. Use `InsertQueryNode.orAction` instead."),this.append(" ignore");if(t.orAction)this.append(" "),this.visitNode(t.orAction);if(t.top)this.append(" "),this.visitNode(t.top);if(t.into)this.append(" into "),this.visitNode(t.into);if(t.columns)this.append(" ("),this.compileList(t.columns),this.append(")");if(t.output)this.append(" "),this.visitNode(t.output);if(t.values)this.append(" "),this.visitNode(t.values);if(t.defaultValues)this.append(" "),this.append("default values");if(t.onConflict)this.append(" "),this.visitNode(t.onConflict);if(t.onDuplicateKey)this.append(" "),this.visitNode(t.onDuplicateKey);if(t.returning)this.append(" "),this.visitNode(t.returning);if(i)this.append(")");if(t.endModifiers?.length)this.append(" "),this.compileList(t.endModifiers," ")}visitValues(t){this.append("values "),this.compileList(t.values)}visitDeleteQuery(t){let i=this.parentNode!==void 0&&!R.is(this.parentNode)&&!c.is(this.parentNode);if(this.parentNode===void 0&&t.explain)this.visitNode(t.explain),this.append(" ");if(i)this.append("(");if(t.with)this.visitNode(t.with),this.append(" ");if(this.append("delete "),t.top)this.visitNode(t.top),this.append(" ");if(this.visitNode(t.from),t.output)this.append(" "),this.visitNode(t.output);if(t.using)this.append(" "),this.visitNode(t.using);if(t.joins)this.append(" "),this.compileList(t.joins," ");if(t.where)this.append(" "),this.visitNode(t.where);if(t.orderBy)this.append(" "),this.visitNode(t.orderBy);if(t.limit)this.append(" "),this.visitNode(t.limit);if(t.returning)this.append(" "),this.visitNode(t.returning);if(i)this.append(")");if(t.endModifiers?.length)this.append(" "),this.compileList(t.endModifiers," ")}visitReturning(t){this.append("returning "),this.compileList(t.selections)}visitAlias(t){this.visitNode(t.node),this.append(" as "),this.visitNode(t.alias)}visitReference(t){if(t.table)this.visitNode(t.table),this.append(".");this.visitNode(t.column)}visitSelectAll(t){this.append("*")}visitIdentifier(t){this.append(this.getLeftIdentifierWrapper()),this.compileUnwrappedIdentifier(t),this.append(this.getRightIdentifierWrapper())}compileUnwrappedIdentifier(t){if(!V(t.name))throw Error("a non-string identifier was passed to compileUnwrappedIdentifier.");this.append(this.sanitizeIdentifier(t.name))}visitAnd(t){this.visitNode(t.left),this.append(" and "),this.visitNode(t.right)}visitOr(t){this.visitNode(t.left),this.append(" or "),this.visitNode(t.right)}visitValue(t){if(t.immediate)this.appendImmediateValue(t.value);else this.appendValue(t.value)}visitValueList(t){this.append("("),this.compileList(t.values),this.append(")")}visitTuple(t){this.append("("),this.compileList(t.values),this.append(")")}visitPrimitiveValueList(t){this.append("(");let{values:i}=t;for(let h=0;h<i.length;++h)if(this.appendValue(i[h]),h!==i.length-1)this.append(", ");this.append(")")}visitParens(t){this.append("("),this.visitNode(t.node),this.append(")")}visitJoin(t){if(this.append(st[t.joinType]),this.append(" "),this.visitNode(t.table),t.on)this.append(" "),this.visitNode(t.on)}visitOn(t){this.append("on "),this.visitNode(t.on)}visitRaw(t){let{sqlFragments:i,parameters:h}=t;for(let f=0;f<i.length;++f)if(this.append(i[f]),h.length>f)this.visitNode(h[f])}visitOperator(t){this.append(t.operator)}visitTable(t){this.visitNode(t.table)}visitSchemableIdentifier(t){if(t.schema)this.visitNode(t.schema),this.append(".");this.visitNode(t.identifier)}visitCreateTable(t){if(this.append("create "),t.frontModifiers?.length)this.compileList(t.frontModifiers," "),this.append(" ");if(t.temporary)this.append("temporary ");if(this.append("table "),t.ifNotExists)this.append("if not exists ");if(this.visitNode(t.table),!t.selectQuery)this.append(" ("),this.compileList([...t.columns,...t.constraints??[]]),this.append(")");if(t.onCommit)this.append(" on commit "),this.append(t.onCommit);if(t.endModifiers?.length)this.append(" "),this.compileList(t.endModifiers," ");if(t.selectQuery)this.append(" as "),this.visitNode(t.selectQuery)}visitColumnDefinition(t){if(t.ifNotExists)this.append("if not exists ");if(this.visitNode(t.column),this.append(" "),this.visitNode(t.dataType),t.unsigned)this.append(" unsigned");if(t.frontModifiers&&t.frontModifiers.length>0)this.append(" "),this.compileList(t.frontModifiers," ");if(t.generated)this.append(" "),this.visitNode(t.generated);if(t.identity)this.append(" identity");if(t.defaultTo)this.append(" "),this.visitNode(t.defaultTo);if(t.notNull)this.append(" not null");if(t.unique)this.append(" unique");if(t.nullsNotDistinct)this.append(" nulls not distinct");if(t.primaryKey)this.append(" primary key");if(t.autoIncrement)this.append(" "),this.append(this.getAutoIncrement());if(t.references)this.append(" "),this.visitNode(t.references);if(t.check)this.append(" "),this.visitNode(t.check);if(t.endModifiers&&t.endModifiers.length>0)this.append(" "),this.compileList(t.endModifiers," ")}getAutoIncrement(){return"auto_increment"}visitReferences(t){if(this.append("references "),this.visitNode(t.table),this.append(" ("),this.compileList(t.columns),this.append(")"),t.onDelete)this.append(" on delete "),this.append(t.onDelete);if(t.onUpdate)this.append(" on update "),this.append(t.onUpdate)}visitDropTable(t){if(this.append("drop table "),t.ifExists)this.append("if exists ");if(this.visitNode(t.table),t.cascade)this.append(" cascade")}visitDataType(t){this.append(t.dataType)}visitOrderBy(t){this.append("order by "),this.compileList(t.items)}visitOrderByItem(t){if(this.visitNode(t.orderBy),t.collation)this.append(" "),this.visitNode(t.collation);if(t.direction)this.append(" "),this.visitNode(t.direction);if(t.nulls)this.append(" nulls "),this.append(t.nulls)}visitGroupBy(t){this.append("group by "),this.compileList(t.items)}visitGroupByItem(t){this.visitNode(t.groupBy)}visitUpdateQuery(t){let i=this.parentNode!==void 0&&!R.is(this.parentNode)&&!c.is(this.parentNode)&&!Q.is(this.parentNode);if(this.parentNode===void 0&&t.explain)this.visitNode(t.explain),this.append(" ");if(i)this.append("(");if(t.with)this.visitNode(t.with),this.append(" ");if(this.append("update "),t.top)this.visitNode(t.top),this.append(" ");if(t.table)this.visitNode(t.table),this.append(" ");if(this.append("set "),t.updates)this.compileList(t.updates);if(t.output)this.append(" "),this.visitNode(t.output);if(t.from)this.append(" "),this.visitNode(t.from);if(t.joins){if(!t.from)throw 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(t.joins," ")}if(t.where)this.append(" "),this.visitNode(t.where);if(t.returning)this.append(" "),this.visitNode(t.returning);if(t.orderBy)this.append(" "),this.visitNode(t.orderBy);if(t.limit)this.append(" "),this.visitNode(t.limit);if(i)this.append(")");if(t.endModifiers?.length)this.append(" "),this.compileList(t.endModifiers," ")}visitColumnUpdate(t){this.visitNode(t.column),this.append(" = "),this.visitNode(t.value)}visitLimit(t){this.append("limit "),this.visitNode(t.limit)}visitOffset(t){this.append("offset "),this.visitNode(t.offset)}visitOnConflict(t){if(this.append("on conflict"),t.columns)this.append(" ("),this.compileList(t.columns),this.append(")");else if(t.constraint)this.append(" on constraint "),this.visitNode(t.constraint);else if(t.indexExpression)this.append(" ("),this.visitNode(t.indexExpression),this.append(")");if(t.indexWhere)this.append(" "),this.visitNode(t.indexWhere);if(t.doNothing===!0)this.append(" do nothing");else if(t.updates){if(this.append(" do update set "),this.compileList(t.updates),t.updateWhere)this.append(" "),this.visitNode(t.updateWhere)}}visitOnDuplicateKey(t){this.append("on duplicate key update "),this.compileList(t.updates)}visitCreateIndex(t){if(this.append("create "),t.unique)this.append("unique ");if(this.append("index "),t.ifNotExists)this.append("if not exists ");if(this.visitNode(t.name),t.table)this.append(" on "),this.visitNode(t.table);if(t.using)this.append(" using "),this.visitNode(t.using);if(t.columns)this.append(" ("),this.compileList(t.columns),this.append(")");if(t.nullsNotDistinct)this.append(" nulls not distinct");if(t.where)this.append(" "),this.visitNode(t.where)}visitDropIndex(t){if(this.append("drop index "),t.ifExists)this.append("if exists ");if(this.visitNode(t.name),t.table)this.append(" on "),this.visitNode(t.table);if(t.cascade)this.append(" cascade")}visitCreateSchema(t){if(this.append("create schema "),t.ifNotExists)this.append("if not exists ");this.visitNode(t.schema)}visitDropSchema(t){if(this.append("drop schema "),t.ifExists)this.append("if exists ");if(this.visitNode(t.schema),t.cascade)this.append(" cascade")}visitPrimaryKeyConstraint(t){if(t.name)this.append("constraint "),this.visitNode(t.name),this.append(" ");this.append("primary key ("),this.compileList(t.columns),this.append(")"),this.buildDeferrable(t)}buildDeferrable(t){if(t.deferrable!==void 0)if(t.deferrable)this.append(" deferrable");else this.append(" not deferrable");if(t.initiallyDeferred!==void 0)if(t.initiallyDeferred)this.append(" initially deferred");else this.append(" initially immediate")}visitUniqueConstraint(t){if(t.name)this.append("constraint "),this.visitNode(t.name),this.append(" ");if(this.append("unique"),t.nullsNotDistinct)this.append(" nulls not distinct");this.append(" ("),this.compileList(t.columns),this.append(")"),this.buildDeferrable(t)}visitCheckConstraint(t){if(t.name)this.append("constraint "),this.visitNode(t.name),this.append(" ");this.append("check ("),this.visitNode(t.expression),this.append(")")}visitForeignKeyConstraint(t){if(t.name)this.append("constraint "),this.visitNode(t.name),this.append(" ");if(this.append("foreign key ("),this.compileList(t.columns),this.append(") "),this.visitNode(t.references),t.onDelete)this.append(" on delete "),this.append(t.onDelete);if(t.onUpdate)this.append(" on update "),this.append(t.onUpdate);this.buildDeferrable(t)}visitList(t){this.compileList(t.items)}visitWith(t){if(this.append("with "),t.recursive)this.append("recursive ");this.compileList(t.expressions)}visitCommonTableExpression(t){if(this.visitNode(t.name),this.append(" as "),J(t.materialized)){if(!t.materialized)this.append("not ");this.append("materialized ")}this.visitNode(t.expression)}visitCommonTableExpressionName(t){if(this.visitNode(t.table),t.columns)this.append("("),this.compileList(t.columns),this.append(")")}visitAlterTable(t){if(this.append("alter table "),this.visitNode(t.table),this.append(" "),t.renameTo)this.append("rename to "),this.visitNode(t.renameTo);if(t.setSchema)this.append("set schema "),this.visitNode(t.setSchema);if(t.addConstraint)this.visitNode(t.addConstraint);if(t.dropConstraint)this.visitNode(t.dropConstraint);if(t.renameConstraint)this.visitNode(t.renameConstraint);if(t.columnAlterations)this.compileColumnAlterations(t.columnAlterations);if(t.addIndex)this.visitNode(t.addIndex);if(t.dropIndex)this.visitNode(t.dropIndex)}visitAddColumn(t){this.append("add column "),this.visitNode(t.column)}visitRenameColumn(t){this.append("rename column "),this.visitNode(t.column),this.append(" to "),this.visitNode(t.renameTo)}visitDropColumn(t){this.append("drop column "),this.visitNode(t.column)}visitAlterColumn(t){if(this.append("alter column "),this.visitNode(t.column),this.append(" "),t.dataType){if(this.announcesNewColumnDataType())this.append("type ");if(this.visitNode(t.dataType),t.dataTypeExpression)this.append("using "),this.visitNode(t.dataTypeExpression)}if(t.setDefault)this.append("set default "),this.visitNode(t.setDefault);if(t.dropDefault)this.append("drop default");if(t.setNotNull)this.append("set not null");if(t.dropNotNull)this.append("drop not null")}visitModifyColumn(t){this.append("modify column "),this.visitNode(t.column)}visitAddConstraint(t){this.append("add "),this.visitNode(t.constraint)}visitDropConstraint(t){if(this.append("drop constraint "),t.ifExists)this.append("if exists ");if(this.visitNode(t.constraintName),t.modifier==="cascade")this.append(" cascade");else if(t.modifier==="restrict")this.append(" restrict")}visitRenameConstraint(t){this.append("rename constraint "),this.visitNode(t.oldName),this.append(" to "),this.visitNode(t.newName)}visitSetOperation(t){if(this.append(t.operator),this.append(" "),t.all)this.append("all ");this.visitNode(t.expression)}visitCreateView(t){if(this.append("create "),t.orReplace)this.append("or replace ");if(t.materialized)this.append("materialized ");if(t.temporary)this.append("temporary ");if(this.append("view "),t.ifNotExists)this.append("if not exists ");if(this.visitNode(t.name),this.append(" "),t.columns)this.append("("),this.compileList(t.columns),this.append(") ");if(t.as)this.append("as "),this.visitNode(t.as)}visitRefreshMaterializedView(t){if(this.append("refresh materialized view "),t.concurrently)this.append("concurrently ");if(this.visitNode(t.name),t.withNoData)this.append(" with no data");else this.append(" with data")}visitDropView(t){if(this.append("drop "),t.materialized)this.append("materialized ");if(this.append("view "),t.ifExists)this.append("if exists ");if(this.visitNode(t.name),t.cascade)this.append(" cascade")}visitGenerated(t){if(this.append("generated "),t.always)this.append("always ");if(t.byDefault)this.append("by default ");if(this.append("as "),t.identity)this.append("identity");if(t.expression)this.append("("),this.visitNode(t.expression),this.append(")");if(t.stored)this.append(" stored")}visitDefaultValue(t){this.append("default "),this.visitNode(t.defaultValue)}visitSelectModifier(t){if(t.rawModifier)this.visitNode(t.rawModifier);else this.append(Nt[t.modifier]);if(t.of)this.append(" of "),this.compileList(t.of,", ")}visitCreateType(t){if(this.append("create type "),this.visitNode(t.name),t.enum)this.append(" as enum "),this.visitNode(t.enum)}visitDropType(t){if(this.append("drop type "),t.ifExists)this.append("if exists ");this.visitNode(t.name)}visitExplain(t){if(this.append("explain"),t.options||t.format){if(this.append(" "),this.append(this.getLeftExplainOptionsWrapper()),t.options){if(this.visitNode(t.options),t.format)this.append(this.getExplainOptionsDelimiter())}if(t.format)this.append("format"),this.append(this.getExplainOptionAssignment()),this.append(t.format);this.append(this.getRightExplainOptionsWrapper())}}visitDefaultInsertValue(t){this.append("default")}visitAggregateFunction(t){if(this.append(t.func),this.append("("),t.distinct)this.append("distinct ");if(this.compileList(t.aggregated),t.orderBy)this.append(" "),this.visitNode(t.orderBy);if(this.append(")"),t.withinGroup)this.append(" within group ("),this.visitNode(t.withinGroup),this.append(")");if(t.filter)this.append(" filter("),this.visitNode(t.filter),this.append(")");if(t.over)this.append(" "),this.visitNode(t.over)}visitOver(t){if(this.append("over("),t.partitionBy){if(this.visitNode(t.partitionBy),t.orderBy)this.append(" ")}if(t.orderBy)this.visitNode(t.orderBy);this.append(")")}visitPartitionBy(t){this.append("partition by "),this.compileList(t.items)}visitPartitionByItem(t){this.visitNode(t.partitionBy)}visitBinaryOperation(t){this.visitNode(t.leftOperand),this.append(" "),this.visitNode(t.operator),this.append(" "),this.visitNode(t.rightOperand)}visitUnaryOperation(t){if(this.visitNode(t.operator),!this.isMinusOperator(t.operator))this.append(" ");this.visitNode(t.operand)}isMinusOperator(t){return m.is(t)&&t.operator==="-"}visitUsing(t){this.append("using "),this.compileList(t.tables)}visitFunction(t){this.append(t.func),this.append("("),this.compileList(t.arguments),this.append(")")}visitCase(t){if(this.append("case"),t.value)this.append(" "),this.visitNode(t.value);if(t.when)this.append(" "),this.compileList(t.when," ");if(t.else)this.append(" else "),this.visitNode(t.else);if(this.append(" end"),t.isStatement)this.append(" case")}visitWhen(t){if(this.append("when "),this.visitNode(t.condition),t.result)this.append(" then "),this.visitNode(t.result)}visitJSONReference(t){this.visitNode(t.reference),this.visitNode(t.traversal)}visitJSONPath(t){if(t.inOperator)this.visitNode(t.inOperator);this.append("'$");for(let i of t.pathLegs)this.visitNode(i);this.append("'")}visitJSONPathLeg(t){let i=t.type==="ArrayLocation",h=String(t.value);if(i)this.append("["),this.append(this.sanitizeStringLiteral(h)),this.append("]");else this.append('."'),this.append(this.sanitizeJSONPathMemberValue(h)),this.append('"')}visitJSONOperatorChain(t){for(let i=0,h=t.values.length;i<h;i++){if(i===h-1)this.visitNode(t.operator);else this.append("->");this.visitNode(t.values[i])}}visitMergeQuery(t){if(t.with)this.visitNode(t.with),this.append(" ");if(this.append("merge "),t.top)this.visitNode(t.top),this.append(" ");if(this.append("into "),this.visitNode(t.into),t.using)this.append(" "),this.visitNode(t.using);if(t.whens)this.append(" "),this.compileList(t.whens," ");if(t.returning)this.append(" "),this.visitNode(t.returning);if(t.output)this.append(" "),this.visitNode(t.output);if(t.endModifiers?.length)this.append(" "),this.compileList(t.endModifiers," ")}visitMatched(t){if(t.not)this.append("not ");if(this.append("matched"),t.bySource)this.append(" by source")}visitAddIndex(t){if(this.append("add "),t.unique)this.append("unique ");if(this.append("index "),this.visitNode(t.name),t.columns)this.append(" ("),this.compileList(t.columns),this.append(")");if(t.using)this.append(" using "),this.visitNode(t.using)}visitCast(t){this.append("cast("),this.visitNode(t.expression),this.append(" as "),this.visitNode(t.dataType),this.append(")")}visitFetch(t){this.append("fetch next "),this.visitNode(t.rowCount),this.append(` rows ${t.modifier}`)}visitOutput(t){this.append("output "),this.compileList(t.selections)}visitTop(t){if(this.append(`top(${t.expression})`),t.modifiers)this.append(` ${t.modifiers}`)}visitOrAction(t){this.append(t.action)}visitCollate(t){this.append("collate "),this.visitNode(t.collation)}append(t){this.#t+=t}appendValue(t){this.addParameter(t),this.append(this.getCurrentParameterPlaceholder())}getLeftIdentifierWrapper(){return'"'}getRightIdentifierWrapper(){return'"'}getCurrentParameterPlaceholder(){return"$"+this.numParameters}getLeftExplainOptionsWrapper(){return"("}getExplainOptionAssignment(){return" "}getExplainOptionsDelimiter(){return", "}getRightExplainOptionsWrapper(){return")"}sanitizeIdentifier(t){let i=this.getLeftIdentifierWrapper(),h=this.getRightIdentifierWrapper(),f="";for(let C of t)if(f+=C,C===i)f+=i;else if(C===h)f+=h;return f}sanitizeStringLiteral(t){return t.replace(tt,"''")}sanitizeJSONPathMemberValue(t){return t.replace(it,(i)=>i==="'"?"''":"\\\"")}addParameter(t){this.#i.push(t)}appendImmediateValue(t){if(V(t))this.appendStringLiteral(t);else if(F(t)||J(t)||$(t))this.append(t.toString());else if(Y(t))this.append("null");else if(Z(t))this.appendImmediateValue(t.toISOString());else throw Error(`invalid immediate value ${t}`)}appendStringLiteral(t){this.append("'"),this.append(this.sanitizeStringLiteral(t)),this.append("'")}sortSelectModifiers(t){return t.sort((i,h)=>i.modifier&&h.modifier?P[i.modifier]-P[h.modifier]:1),N(t)}compileColumnAlterations(t){this.compileList(t)}announcesNewColumnDataType(){return!0}}var Nt=N({ForKeyShare:"for key share",ForNoKeyUpdate:"for no key update",ForUpdate:"for update",ForShare:"for share",NoWait:"nowait",SkipLocked:"skip locked",Distinct:"distinct"}),P=N({ForKeyShare:1,ForNoKeyUpdate:1,ForUpdate:1,ForShare:1,NoWait:2,SkipLocked:2,Distinct:0}),st=N({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"});class D{transformQuery(t){return t.node}async transformResult(t){return t.result}}var j=N({is(t){return t.kind==="AliasNode"},create(t,i){return N({kind:"AliasNode",node:t,alias:i})}});var g=N({is(t){return t.kind==="AndNode"},create(t,i){return N({kind:"AndNode",left:t,right:i})}});var l=N({is(t){return t.kind==="OrNode"},create(t,i){return N({kind:"OrNode",left:t,right:i})}});var w=N({is(t){return t.kind==="OnNode"},create(t){return N({kind:"OnNode",on:t})},cloneWithOperation(t,i,h){return N({...t,on:i==="And"?g.create(t.on,h):l.create(t.on,h)})}});var a=N({is(t){return t.kind==="JoinNode"},create(t,i){return N({kind:"JoinNode",joinType:t,table:i,on:void 0})},createWithOn(t,i,h){return N({kind:"JoinNode",joinType:t,table:i,on:w.create(h)})},cloneWithOn(t,i){return N({...t,on:t.on?w.cloneWithOperation(t.on,"And",i):w.create(i)})}});var y=N({is(t){return t.kind==="ListNode"},create(t){return N({kind:"ListNode",items:N(t)})}});function s(t){return t}class T{nodeStack=[];#t=N({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(t,i){if(!t)return t;this.nodeStack.push(t);let h=this.transformNodeImpl(t,i);return this.nodeStack.pop(),N(h)}transformNodeImpl(t,i){return this.#t[t.kind](t,i)}transformNodeList(t,i){if(!t)return t;return N(t.map((h)=>this.transformNode(h,i)))}transformSelectQuery(t,i){return s({kind:"SelectQueryNode",from:this.transformNode(t.from,i),selections:this.transformNodeList(t.selections,i),distinctOn:this.transformNodeList(t.distinctOn,i),joins:this.transformNodeList(t.joins,i),groupBy:this.transformNode(t.groupBy,i),orderBy:this.transformNode(t.orderBy,i),where:this.transformNode(t.where,i),frontModifiers:this.transformNodeList(t.frontModifiers,i),endModifiers:this.transformNodeList(t.endModifiers,i),limit:this.transformNode(t.limit,i),offset:this.transformNode(t.offset,i),with:this.transformNode(t.with,i),having:this.transformNode(t.having,i),explain:this.transformNode(t.explain,i),setOperations:this.transformNodeList(t.setOperations,i),fetch:this.transformNode(t.fetch,i),top:this.transformNode(t.top,i)})}transformSelection(t,i){return s({kind:"SelectionNode",selection:this.transformNode(t.selection,i)})}transformColumn(t,i){return s({kind:"ColumnNode",column:this.transformNode(t.column,i)})}transformAlias(t,i){return s({kind:"AliasNode",node:this.transformNode(t.node,i),alias:this.transformNode(t.alias,i)})}transformTable(t,i){return s({kind:"TableNode",table:this.transformNode(t.table,i)})}transformFrom(t,i){return s({kind:"FromNode",froms:this.transformNodeList(t.froms,i)})}transformReference(t,i){return s({kind:"ReferenceNode",column:this.transformNode(t.column,i),table:this.transformNode(t.table,i)})}transformAnd(t,i){return s({kind:"AndNode",left:this.transformNode(t.left,i),right:this.transformNode(t.right,i)})}transformOr(t,i){return s({kind:"OrNode",left:this.transformNode(t.left,i),right:this.transformNode(t.right,i)})}transformValueList(t,i){return s({kind:"ValueListNode",values:this.transformNodeList(t.values,i)})}transformParens(t,i){return s({kind:"ParensNode",node:this.transformNode(t.node,i)})}transformJoin(t,i){return s({kind:"JoinNode",joinType:t.joinType,table:this.transformNode(t.table,i),on:this.transformNode(t.on,i)})}transformRaw(t,i){return s({kind:"RawNode",sqlFragments:N([...t.sqlFragments]),parameters:this.transformNodeList(t.parameters,i)})}transformWhere(t,i){return s({kind:"WhereNode",where:this.transformNode(t.where,i)})}transformInsertQuery(t,i){return s({kind:"InsertQueryNode",into:this.transformNode(t.into,i),columns:this.transformNodeList(t.columns,i),values:this.transformNode(t.values,i),returning:this.transformNode(t.returning,i),onConflict:this.transformNode(t.onConflict,i),onDuplicateKey:this.transformNode(t.onDuplicateKey,i),endModifiers:this.transformNodeList(t.endModifiers,i),with:this.transformNode(t.with,i),ignore:t.ignore,orAction:this.transformNode(t.orAction,i),replace:t.replace,explain:this.transformNode(t.explain,i),defaultValues:t.defaultValues,top:this.transformNode(t.top,i),output:this.transformNode(t.output,i)})}transformValues(t,i){return s({kind:"ValuesNode",values:this.transformNodeList(t.values,i)})}transformDeleteQuery(t,i){return s({kind:"DeleteQueryNode",from:this.transformNode(t.from,i),using:this.transformNode(t.using,i),joins:this.transformNodeList(t.joins,i),where:this.transformNode(t.where,i),returning:this.transformNode(t.returning,i),endModifiers:this.transformNodeList(t.endModifiers,i),with:this.transformNode(t.with,i),orderBy:this.transformNode(t.orderBy,i),limit:this.transformNode(t.limit,i),explain:this.transformNode(t.explain,i),top:this.transformNode(t.top,i),output:this.transformNode(t.output,i)})}transformReturning(t,i){return s({kind:"ReturningNode",selections:this.transformNodeList(t.selections,i)})}transformCreateTable(t,i){return s({kind:"CreateTableNode",table:this.transformNode(t.table,i),columns:this.transformNodeList(t.columns,i),constraints:this.transformNodeList(t.constraints,i),temporary:t.temporary,ifNotExists:t.ifNotExists,onCommit:t.onCommit,frontModifiers:this.transformNodeList(t.frontModifiers,i),endModifiers:this.transformNodeList(t.endModifiers,i),selectQuery:this.transformNode(t.selectQuery,i)})}transformColumnDefinition(t,i){return s({kind:"ColumnDefinitionNode",column:this.transformNode(t.column,i),dataType:this.transformNode(t.dataType,i),references:this.transformNode(t.references,i),primaryKey:t.primaryKey,autoIncrement:t.autoIncrement,unique:t.unique,notNull:t.notNull,unsigned:t.unsigned,defaultTo:this.transformNode(t.defaultTo,i),check:this.transformNode(t.check,i),generated:this.transformNode(t.generated,i),frontModifiers:this.transformNodeList(t.frontModifiers,i),endModifiers:this.transformNodeList(t.endModifiers,i),nullsNotDistinct:t.nullsNotDistinct,identity:t.identity,ifNotExists:t.ifNotExists})}transformAddColumn(t,i){return s({kind:"AddColumnNode",column:this.transformNode(t.column,i)})}transformDropTable(t,i){return s({kind:"DropTableNode",table:this.transformNode(t.table,i),ifExists:t.ifExists,cascade:t.cascade})}transformOrderBy(t,i){return s({kind:"OrderByNode",items:this.transformNodeList(t.items,i)})}transformOrderByItem(t,i){return s({kind:"OrderByItemNode",orderBy:this.transformNode(t.orderBy,i),direction:this.transformNode(t.direction,i),collation:this.transformNode(t.collation,i),nulls:t.nulls})}transformGroupBy(t,i){return s({kind:"GroupByNode",items:this.transformNodeList(t.items,i)})}transformGroupByItem(t,i){return s({kind:"GroupByItemNode",groupBy:this.transformNode(t.groupBy,i)})}transformUpdateQuery(t,i){return s({kind:"UpdateQueryNode",table:this.transformNode(t.table,i),from:this.transformNode(t.from,i),joins:this.transformNodeList(t.joins,i),where:this.transformNode(t.where,i),updates:this.transformNodeList(t.updates,i),returning:this.transformNode(t.returning,i),endModifiers:this.transformNodeList(t.endModifiers,i),with:this.transformNode(t.with,i),explain:this.transformNode(t.explain,i),limit:this.transformNode(t.limit,i),top:this.transformNode(t.top,i),output:this.transformNode(t.output,i),orderBy:this.transformNode(t.orderBy,i)})}transformColumnUpdate(t,i){return s({kind:"ColumnUpdateNode",column:this.transformNode(t.column,i),value:this.transformNode(t.value,i)})}transformLimit(t,i){return s({kind:"LimitNode",limit:this.transformNode(t.limit,i)})}transformOffset(t,i){return s({kind:"OffsetNode",offset:this.transformNode(t.offset,i)})}transformOnConflict(t,i){return s({kind:"OnConflictNode",columns:this.transformNodeList(t.columns,i),constraint:this.transformNode(t.constraint,i),indexExpression:this.transformNode(t.indexExpression,i),indexWhere:this.transformNode(t.indexWhere,i),updates:this.transformNodeList(t.updates,i),updateWhere:this.transformNode(t.updateWhere,i),doNothing:t.doNothing})}transformOnDuplicateKey(t,i){return s({kind:"OnDuplicateKeyNode",updates:this.transformNodeList(t.updates,i)})}transformCreateIndex(t,i){return s({kind:"CreateIndexNode",name:this.transformNode(t.name,i),table:this.transformNode(t.table,i),columns:this.transformNodeList(t.columns,i),unique:t.unique,using:this.transformNode(t.using,i),ifNotExists:t.ifNotExists,where:this.transformNode(t.where,i),nullsNotDistinct:t.nullsNotDistinct})}transformList(t,i){return s({kind:"ListNode",items:this.transformNodeList(t.items,i)})}transformDropIndex(t,i){return s({kind:"DropIndexNode",name:this.transformNode(t.name,i),table:this.transformNode(t.table,i),ifExists:t.ifExists,cascade:t.cascade})}transformPrimaryKeyConstraint(t,i){return s({kind:"PrimaryKeyConstraintNode",columns:this.transformNodeList(t.columns,i),name:this.transformNode(t.name,i),deferrable:t.deferrable,initiallyDeferred:t.initiallyDeferred})}transformUniqueConstraint(t,i){return s({kind:"UniqueConstraintNode",columns:this.transformNodeList(t.columns,i),name:this.transformNode(t.name,i),nullsNotDistinct:t.nullsNotDistinct,deferrable:t.deferrable,initiallyDeferred:t.initiallyDeferred})}transformForeignKeyConstraint(t,i){return s({kind:"ForeignKeyConstraintNode",columns:this.transformNodeList(t.columns,i),references:this.transformNode(t.references,i),name:this.transformNode(t.name,i),onDelete:t.onDelete,onUpdate:t.onUpdate,deferrable:t.deferrable,initiallyDeferred:t.initiallyDeferred})}transformSetOperation(t,i){return s({kind:"SetOperationNode",operator:t.operator,expression:this.transformNode(t.expression,i),all:t.all})}transformReferences(t,i){return s({kind:"ReferencesNode",table:this.transformNode(t.table,i),columns:this.transformNodeList(t.columns,i),onDelete:t.onDelete,onUpdate:t.onUpdate})}transformCheckConstraint(t,i){return s({kind:"CheckConstraintNode",expression:this.transformNode(t.expression,i),name:this.transformNode(t.name,i)})}transformWith(t,i){return s({kind:"WithNode",expressions:this.transformNodeList(t.expressions,i),recursive:t.recursive})}transformCommonTableExpression(t,i){return s({kind:"CommonTableExpressionNode",name:this.transformNode(t.name,i),materialized:t.materialized,expression:this.transformNode(t.expression,i)})}transformCommonTableExpressionName(t,i){return s({kind:"CommonTableExpressionNameNode",table:this.transformNode(t.table,i),columns:this.transformNodeList(t.columns,i)})}transformHaving(t,i){return s({kind:"HavingNode",having:this.transformNode(t.having,i)})}transformCreateSchema(t,i){return s({kind:"CreateSchemaNode",schema:this.transformNode(t.schema,i),ifNotExists:t.ifNotExists})}transformDropSchema(t,i){return s({kind:"DropSchemaNode",schema:this.transformNode(t.schema,i),ifExists:t.ifExists,cascade:t.cascade})}transformAlterTable(t,i){return s({kind:"AlterTableNode",table:this.transformNode(t.table,i),renameTo:this.transformNode(t.renameTo,i),setSchema:this.transformNode(t.setSchema,i),columnAlterations:this.transformNodeList(t.columnAlterations,i),addConstraint:this.transformNode(t.addConstraint,i),dropConstraint:this.transformNode(t.dropConstraint,i),renameConstraint:this.transformNode(t.renameConstraint,i),addIndex:this.transformNode(t.addIndex,i),dropIndex:this.transformNode(t.dropIndex,i)})}transformDropColumn(t,i){return s({kind:"DropColumnNode",column:this.transformNode(t.column,i)})}transformRenameColumn(t,i){return s({kind:"RenameColumnNode",column:this.transformNode(t.column,i),renameTo:this.transformNode(t.renameTo,i)})}transformAlterColumn(t,i){return s({kind:"AlterColumnNode",column:this.transformNode(t.column,i),dataType:this.transformNode(t.dataType,i),dataTypeExpression:this.transformNode(t.dataTypeExpression,i),setDefault:this.transformNode(t.setDefault,i),dropDefault:t.dropDefault,setNotNull:t.setNotNull,dropNotNull:t.dropNotNull})}transformModifyColumn(t,i){return s({kind:"ModifyColumnNode",column:this.transformNode(t.column,i)})}transformAddConstraint(t,i){return s({kind:"AddConstraintNode",constraint:this.transformNode(t.constraint,i)})}transformDropConstraint(t,i){return s({kind:"DropConstraintNode",constraintName:this.transformNode(t.constraintName,i),ifExists:t.ifExists,modifier:t.modifier})}transformRenameConstraint(t,i){return s({kind:"RenameConstraintNode",oldName:this.transformNode(t.oldName,i),newName:this.transformNode(t.newName,i)})}transformCreateView(t,i){return s({kind:"CreateViewNode",name:this.transformNode(t.name,i),temporary:t.temporary,orReplace:t.orReplace,ifNotExists:t.ifNotExists,materialized:t.materialized,columns:this.transformNodeList(t.columns,i),as:this.transformNode(t.as,i)})}transformRefreshMaterializedView(t,i){return s({kind:"RefreshMaterializedViewNode",name:this.transformNode(t.name,i),concurrently:t.concurrently,withNoData:t.withNoData})}transformDropView(t,i){return s({kind:"DropViewNode",name:this.transformNode(t.name,i),ifExists:t.ifExists,materialized:t.materialized,cascade:t.cascade})}transformGenerated(t,i){return s({kind:"GeneratedNode",byDefault:t.byDefault,always:t.always,identity:t.identity,stored:t.stored,expression:this.transformNode(t.expression,i)})}transformDefaultValue(t,i){return s({kind:"DefaultValueNode",defaultValue:this.transformNode(t.defaultValue,i)})}transformOn(t,i){return s({kind:"OnNode",on:this.transformNode(t.on,i)})}transformSelectModifier(t,i){return s({kind:"SelectModifierNode",modifier:t.modifier,rawModifier:this.transformNode(t.rawModifier,i),of:this.transformNodeList(t.of,i)})}transformCreateType(t,i){return s({kind:"CreateTypeNode",name:this.transformNode(t.name,i),enum:this.transformNode(t.enum,i)})}transformDropType(t,i){return s({kind:"DropTypeNode",name:this.transformNode(t.name,i),ifExists:t.ifExists})}transformExplain(t,i){return s({kind:"ExplainNode",format:t.format,options:this.transformNode(t.options,i)})}transformSchemableIdentifier(t,i){return s({kind:"SchemableIdentifierNode",schema:this.transformNode(t.schema,i),identifier:this.transformNode(t.identifier,i)})}transformAggregateFunction(t,i){return s({kind:"AggregateFunctionNode",func:t.func,aggregated:this.transformNodeList(t.aggregated,i),distinct:t.distinct,orderBy:this.transformNode(t.orderBy,i),withinGroup:this.transformNode(t.withinGroup,i),filter:this.transformNode(t.filter,i),over:this.transformNode(t.over,i)})}transformOver(t,i){return s({kind:"OverNode",orderBy:this.transformNode(t.orderBy,i),partitionBy:this.transformNode(t.partitionBy,i)})}transformPartitionBy(t,i){return s({kind:"PartitionByNode",items:this.transformNodeList(t.items,i)})}transformPartitionByItem(t,i){return s({kind:"PartitionByItemNode",partitionBy:this.transformNode(t.partitionBy,i)})}transformBinaryOperation(t,i){return s({kind:"BinaryOperationNode",leftOperand:this.transformNode(t.leftOperand,i),operator:this.transformNode(t.operator,i),rightOperand:this.transformNode(t.rightOperand,i)})}transformUnaryOperation(t,i){return s({kind:"UnaryOperationNode",operator:this.transformNode(t.operator,i),operand:this.transformNode(t.operand,i)})}transformUsing(t,i){return s({kind:"UsingNode",tables:this.transformNodeList(t.tables,i)})}transformFunction(t,i){return s({kind:"FunctionNode",func:t.func,arguments:this.transformNodeList(t.arguments,i)})}transformCase(t,i){return s({kind:"CaseNode",value:this.transformNode(t.value,i),when:this.transformNodeList(t.when,i),else:this.transformNode(t.else,i),isStatement:t.isStatement})}transformWhen(t,i){return s({kind:"WhenNode",condition:this.transformNode(t.condition,i),result:this.transformNode(t.result,i)})}transformJSONReference(t,i){return s({kind:"JSONReferenceNode",reference:this.transformNode(t.reference,i),traversal:this.transformNode(t.traversal,i)})}transformJSONPath(t,i){return s({kind:"JSONPathNode",inOperator:this.transformNode(t.inOperator,i),pathLegs:this.transformNodeList(t.pathLegs,i)})}transformJSONPathLeg(t,i){return s({kind:"JSONPathLegNode",type:t.type,value:t.value})}transformJSONOperatorChain(t,i){return s({kind:"JSONOperatorChainNode",operator:this.transformNode(t.operator,i),values:this.transformNodeList(t.values,i)})}transformTuple(t,i){return s({kind:"TupleNode",values:this.transformNodeList(t.values,i)})}transformMergeQuery(t,i){return s({kind:"MergeQueryNode",into:this.transformNode(t.into,i),using:this.transformNode(t.using,i),whens:this.transformNodeList(t.whens,i),with:this.transformNode(t.with,i),top:this.transformNode(t.top,i),endModifiers:this.transformNodeList(t.endModifiers,i),output:this.transformNode(t.output,i),returning:this.transformNode(t.returning,i)})}transformMatched(t,i){return s({kind:"MatchedNode",not:t.not,bySource:t.bySource})}transformAddIndex(t,i){return s({kind:"AddIndexNode",name:this.transformNode(t.name,i),columns:this.transformNodeList(t.columns,i),unique:t.unique,using:this.transformNode(t.using,i),ifNotExists:t.ifNotExists})}transformCast(t,i){return s({kind:"CastNode",expression:this.transformNode(t.expression,i),dataType:this.transformNode(t.dataType,i)})}transformFetch(t,i){return s({kind:"FetchNode",rowCount:this.transformNode(t.rowCount,i),modifier:t.modifier})}transformTop(t,i){return s({kind:"TopNode",expression:t.expression,modifiers:t.modifiers})}transformOutput(t,i){return s({kind:"OutputNode",selections:this.transformNodeList(t.selections,i)})}transformDataType(t,i){return t}transformSelectAll(t,i){return t}transformIdentifier(t,i){return t}transformValue(t,i){return t}transformPrimitiveValueList(t,i){return t}transformOperator(t,i){return t}transformDefaultInsertValue(t,i){return t}transformOrAction(t,i){return t}transformCollate(t,i){return t}}var W=N({is(t){return t.kind==="TableNode"},create(t){return N({kind:"TableNode",table:p.create(t)})},createWithSchema(t,i){return N({kind:"TableNode",table:p.createWithSchema(t,i)})}});var u=N({is(t){return t.kind==="UsingNode"},create(t){return N({kind:"UsingNode",tables:N(t)})},cloneWithTables(t,i){return N({...t,tables:N([...t.tables,...i])})}});var ft=N({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}),vt={json_agg:!0,to_json:!0};class z extends T{#t;#i=new Set;#h=new Set;constructor(t){super();this.#t=t}transformNodeImpl(t,i){if(!this.#v(t))return super.transformNodeImpl(t,i);let h=this.#s(t);for(let v of h)this.#h.add(v);let f=this.#k(t);for(let v of f)this.#i.add(v);let C=super.transformNodeImpl(t,i);for(let v of f)this.#i.delete(v);for(let v of h)this.#h.delete(v);return C}transformSchemableIdentifier(t,i){let h=super.transformSchemableIdentifier(t,i);if(h.schema||!this.#i.has(t.identifier.name))return h;return{...h,schema:S.create(this.#t)}}transformReferences(t,i){let h=super.transformReferences(t,i);if(h.table.table.schema)return h;return{...h,table:W.createWithSchema(this.#t,h.table.table.identifier.name)}}transformAggregateFunction(t,i){return{...super.transformAggregateFunction({...t,aggregated:[]},i),aggregated:this.#N(t,i,"aggregated")}}transformFunction(t,i){return{...super.transformFunction({...t,arguments:[]},i),arguments:this.#N(t,i,"arguments")}}transformSelectModifier(t,i){return{...super.transformSelectModifier({...t,of:void 0},i),of:t.of?.map((h)=>W.is(h)&&!h.table.schema?{...h,table:this.transformIdentifier(h.table.identifier,i)}:this.transformNode(h,i))}}#N(t,i,h){return vt[t.func]?t[h].map((f)=>!W.is(f)||f.table.schema?this.transformNode(f,i):{...f,table:this.transformIdentifier(f.table.identifier,i)}):this.transformNodeList(t[h],i)}#v(t){return t.kind in ft}#k(t){let i=new Set;if("name"in t&&t.name&&p.is(t.name))this.#C(t.name,i);if("from"in t&&t.from)for(let h of t.from.froms)this.#f(h,i);if("into"in t&&t.into)this.#f(t.into,i);if("table"in t&&t.table)this.#f(t.table,i);if("joins"in t&&t.joins)for(let h of t.joins)this.#f(h.table,i);if("using"in t&&t.using)if(a.is(t.using))this.#f(t.using.table,i);else this.#f(t.using,i);return i}#s(t){let i=new Set;if("with"in t&&t.with)this.#c(t.with,i);return i}#f(t,i){if(W.is(t))return this.#C(t.table,i);if(j.is(t)&&W.is(t.node))return this.#C(t.node.table,i);if(y.is(t)){for(let h of t.items)this.#f(h,i);return}if(u.is(t)){for(let h of t.tables)this.#f(h,i);return}}#C(t,i){let h=t.identifier.name;if(!this.#i.has(h)&&!this.#h.has(h))i.add(h)}#c(t,i){for(let h of t.expressions){let f=h.name.table.table.identifier.name;if(!this.#h.has(f))i.add(f)}}}class H{#t;constructor(t){this.#t=new z(t)}transformQuery(t){return this.#t.transformNode(t.node,t.queryId)}async transformResult(t){return t.result}}var Ct="kysely_migration",I="kysely_migration_lock",Ot=!1,K="migration_lock",gi=N({__noMigrations__:!0});class kt{#t;constructor(t){this.#t=N(t)}async getMigrations(){let i=await this.#O(this.#N)?await this.#t.db.withPlugin(this.#s).selectFrom(this.#N).select(["name","timestamp"]).$narrowType().execute():[];return(await this.#V()).map(({name:f,...C})=>{let v=i.find((O)=>O.name===f);return{name:f,migration:C,executedAt:v?new Date(v.timestamp):void 0}})}async migrateToLatest(){return this.#i(()=>({direction:"Up",step:1/0}))}async migrateTo(t){return this.#i(({migrations:i,executedMigrations:h,pendingMigrations:f})=>{if(X(t)&&t.__noMigrations__===!0)return{direction:"Down",step:1/0};if(!i.find((O)=>O.name===t))throw Error(`migration "${t}" doesn't exist`);let C=h.indexOf(t),v=f.findIndex((O)=>O.name===t);if(C!==-1)return{direction:"Down",step:h.length-C-1};else if(v!==-1)return{direction:"Up",step:v+1};else throw Error(`migration "${t}" isn't executed or pending`)})}async migrateUp(){return this.#i(()=>({direction:"Up",step:1}))}async migrateDown(){return this.#i(()=>({direction:"Down",step:1}))}async#i(t){try{return await this.#f(),await this.#C(),await this.#c(),await this.#R(),await this.#w(t)}catch(i){if(i instanceof B)return i.resultSet;return{error:i}}}get#h(){return this.#t.migrationTableSchema}get#N(){return this.#t.migrationTableName??Ct}get#v(){return this.#t.migrationLockTableName??I}get#k(){return this.#t.allowUnorderedMigrations??Ot}get#s(){if(this.#h)return new H(this.#h);return new D}async#f(){if(!this.#h)return;if(await this.#S())return;try{await this.#p(this.#t.db.schema.createSchema(this.#h))}catch(i){if(!await this.#S())throw i}}async#C(){if(await this.#O(this.#N))return;try{await this.#p(this.#t.db.schema.withPlugin(this.#s).createTable(this.#N).addColumn("name","varchar(255)",(i)=>i.notNull().primaryKey()).addColumn("timestamp","varchar(255)",(i)=>i.notNull()))}catch(i){if(!await this.#O(this.#N))throw i}}async#c(){if(await this.#O(this.#v))return;try{await this.#p(this.#t.db.schema.withPlugin(this.#s).createTable(this.#v).addColumn("id","varchar(255)",(i)=>i.notNull().primaryKey()).addColumn("is_locked","integer",(i)=>i.notNull().defaultTo(0)))}catch(i){if(!await this.#O(this.#v))throw i}}async#R(){if(await this.#W())return;try{await this.#t.db.withPlugin(this.#s).insertInto(this.#v).values({id:K,is_locked:0}).execute()}catch(i){if(!await this.#W())throw i}}async#S(){return(await this.#t.db.introspection.getSchemas()).some((i)=>i.name===this.#h)}async#O(t){let i=this.#h;return(await this.#t.db.introspection.getTables({withInternalKyselyTables:!0})).some((f)=>f.name===t&&(!i||f.schema===i))}async#W(){return!!await this.#t.db.withPlugin(this.#s).selectFrom(this.#v).where("id","=",K).select("id").executeTakeFirst()}async#w(t){let i=this.#t.db.getExecutor().adapter,h=N({lockTable:this.#t.migrationLockTableName??I,lockRowId:K,lockTableSchema:this.#t.migrationTableSchema}),f=async(C)=>{try{await i.acquireMigrationLock(C,h);let v=await this.#B(C);if(v.migrations.length===0)return{results:[]};let{direction:O,step:k}=t(v);if(k<=0)return{results:[]};if(O==="Down")return await this.#T(C,v,k);else if(O==="Up")return await this.#z(C,v,k);return{results:[]}}finally{await i.releaseMigrationLock(C,h)}};if(i.supportsTransactionalDdl&&!this.#t.disableTransactions)return this.#t.db.transaction().execute(f);else return this.#t.db.connection().execute(f)}async#B(t){let i=await this.#V(),h=await this.#U(t);if(this.#Q(i,h),!this.#k)this.#D(i,h);let f=this.#J(i,h);return N({migrations:i,executedMigrations:h,lastMigration:G(h),pendingMigrations:f})}#J(t,i){return t.filter((h)=>{return!i.includes(h.name)})}async#V(){let t=await this.#t.provider.getMigrations();return Object.keys(t).sort().map((i)=>({...t[i],name:i}))}async#U(t){let i=await t.withPlugin(this.#s).selectFrom(this.#N).select(["name","timestamp"]).$narrowType().execute(),h=this.#t.nameComparator||((f,C)=>f.localeCompare(C));return i.sort((f,C)=>{if(f.timestamp===C.timestamp)return h(f.name,C.name);return new Date(f.timestamp).getTime()-new Date(C.timestamp).getTime()}).map((f)=>f.name)}#Q(t,i){for(let h of i)if(!t.some((f)=>f.name===h))throw Error(`corrupted migrations: previously executed migration ${h} is missing`)}#D(t,i){for(let h=0;h<i.length;++h)if(t[h].name!==i[h])throw Error(`corrupted migrations: expected previously executed migration ${i[h]} to be at index ${h} but ${t[h].name} was found in its place. New migrations must always have a name that comes alphabetically after the last executed migration.`)}async#T(t,i,h){let f=i.executedMigrations.slice().reverse().slice(0,h).map((v)=>{return i.migrations.find((O)=>O.name===v)}),C=f.map((v)=>{return{migrationName:v.name,direction:"Down",status:"NotExecuted"}});for(let v=0;v<C.length;++v){let O=f[v];try{if(O.down)await O.down(t),await t.withPlugin(this.#s).deleteFrom(this.#N).where("name","=",O.name).execute(),C[v]={migrationName:O.name,direction:"Down",status:"Success"}}catch(k){throw C[v]={migrationName:O.name,direction:"Down",status:"Error"},new B({error:k,results:C})}}return{results:C}}async#z(t,i,h){let C=i.pendingMigrations.slice(0,h).map((v)=>{return{migrationName:v.name,direction:"Up",status:"NotExecuted"}});for(let v=0;v<C.length;v++){let O=i.pendingMigrations[v];try{await O.up(t),await t.withPlugin(this.#s).insertInto(this.#N).values({name:O.name,timestamp:new Date().toISOString()}).execute(),C[v]={migrationName:O.name,direction:"Up",status:"Success"}}catch(k){throw C[v]={migrationName:O.name,direction:"Up",status:"Error"},new B({error:k,results:C})}}return{results:C}}async#p(t){if(this.#t.db.getExecutor().adapter.supportsCreateIfNotExists)t=t.ifNotExists();await t.execute()}}class B extends Error{#t;constructor(t){super();this.#t=t}get resultSet(){return this.#t}}
|
|
3
|
+
export{ct as ia,V as ja,F as ka,J as la,Y as ma,Z as na,$ as oa,pt as pa,St as qa,X as ra,N as sa,Wt as ta,r as ua,Vt as va,S as wa,Bt as xa,L as ya,p as za,j as Aa,W as Ba,g as Ca,l as Da,a as Ea,Ht as Fa,m as Ga,Kt as Ha,c as Ia,b as Ja,R as Ka,x as La,y as Ma,u as Na,Q as Oa,T as Pa,H as Qa,M as Ra,E as Sa,ht as Ta,Ct as Ua,I as Va};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{da as P,ea as J}from"./chunk-5t78zdc8.js";import{Ta as V,Ua as W,Va as X}from"./chunk-jsvz5f2k.js";import"./chunk-9zem8ffs.js";var Y=class{get supportsCreateIfNotExists(){return!0}get supportsTransactionalDdl(){return!1}get supportsReturning(){return!0}async acquireMigrationLock(){}async releaseMigrationLock(){}get supportsOutput(){return!0}},Z=class{#h;#j=new k;#z;#H;constructor(h){this.#h={...h}}async init(){if(this.#z=this.#h.database,this.#H=new $(this.#z),this.#h.onCreateConnection)await this.#h.onCreateConnection(this.#H)}async acquireConnection(){return await this.#j.lock(),this.#H}async beginTransaction(h){await h.executeQuery(J.raw("begin"))}async commitTransaction(h){await h.executeQuery(J.raw("commit"))}async rollbackTransaction(h){await h.executeQuery(J.raw("rollback"))}async releaseConnection(){this.#j.unlock()}async destroy(){this.#z?.close()}},$=class{#h;constructor(h){this.#h=h}executeQuery(h){let{sql:z,parameters:H}=h,j=this.#h.prepare(z).all(...H);return Promise.resolve({rows:j})}async*streamQuery(){throw Error("Streaming query is not supported by SQLite driver.")}},k=class{#h;#j;async lock(){while(this.#h!==void 0)await this.#h;this.#h=new Promise((h)=>{this.#j=h})}unlock(){let h=this.#j;this.#h=void 0,this.#j=void 0,h?.()}},w=class{#h;constructor(h){this.#h=h}async getSchemas(){return[]}async getTables(h={withInternalKyselyTables:!1}){let z=this.#h.selectFrom("sqlite_schema").where("type","=","table").where("name","not like","sqlite_%").select("name").$castTo();if(!h.withInternalKyselyTables)z=z.where("name","!=",W).where("name","!=",X);let H=await z.execute();return Promise.all(H.map(({name:j})=>this.#j(j)))}async getMetadata(h){return{tables:await this.getTables(h)}}async#j(h){let z=this.#h,H=(await z.selectFrom("sqlite_master").where("name","=",h).select("sql").$castTo().execute())[0]?.sql?.split(/[\(\),]/)?.find((j)=>j.toLowerCase().includes("autoincrement"))?.split(/\s+/)?.[0]?.replace(/["`]/g,"");return{name:h,columns:(await z.selectFrom(P`pragma_table_info(${h})`.as("table_info")).select(["name","type","notnull","dflt_value"]).execute()).map((j)=>({name:j.name,dataType:j.type,isNullable:!j.notnull,isAutoIncrementing:j.name===H,hasDefaultValue:j.dflt_value!=null})),isView:!0}}},K=class extends V{getCurrentParameterPlaceholder(){return"?"}getLeftIdentifierWrapper(){return'"'}getRightIdentifierWrapper(){return'"'}getAutoIncrement(){return"autoincrement"}},F=class{#h;constructor(h){this.#h={...h}}createDriver(){return new Z(this.#h)}createQueryCompiler(){return new K}createAdapter(){return new Y}createIntrospector(h){return new w(h)}};export{F as NodeSqliteDialect};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{F as t$}from"./chunk-7sx9g2gs.js";import{$ as __,G as e$,H as j,I as $W,J as UW,K as WW,L as HW,M as T_,N as o_,O as E_,P as ZW,Q as LW,R as MW,S as yW,T,U as h$,V as VW,W as zW,X as EW,Y as PW,Z as FW,_ as KW,aa as _$,ba as kW,ca as m,da as P,ea as v}from"./chunk-5t78zdc8.js";import{fa as g_,ga as IW,ha as QW}from"./chunk-cq2r8hc4.js";import{Ia as F_,Ja as OW,Pa as YW,Qa as v_,Sa as Y_,Ta as C_,Ua as r,Va as O_,ia as G$,ja as U$,ka as b$,la as qW,ma as fW,na as jW,oa as BW,pa as vW,qa as c,ra as u,sa as J,va as y,wa as f,xa as XW,ya as C,za as e}from"./chunk-jsvz5f2k.js";import{Za as V$}from"./chunk-9zem8ffs.js";var M=J({is(_){return _.kind==="AlterTableNode"},create(_){return J({kind:"AlterTableNode",table:_})},cloneWithTableProps(_,$){return J({..._,...$})},cloneWithColumnAlteration(_,$){return J({..._,columnAlterations:_.columnAlterations?[..._.columnAlterations,$]:[$]})}});var a=J({is(_){return _.kind==="CreateIndexNode"},create(_){return J({kind:"CreateIndexNode",name:f.create(_)})},cloneWith(_,$){return J({..._,...$})},cloneWithColumns(_,$){return J({..._,columns:[..._.columns||[],...$]})}});var n_=J({is(_){return _.kind==="CreateSchemaNode"},create(_,$){return J({kind:"CreateSchemaNode",schema:f.create(_),...$})},cloneWith(_,$){return J({..._,...$})}});var H_=J({is(_){return _.kind==="DropIndexNode"},create(_,$){return J({kind:"DropIndexNode",name:e.create(_),...$})},cloneWith(_,$){return J({..._,...$})}});var b_=J({is(_){return _.kind==="DropSchemaNode"},create(_,$){return J({kind:"DropSchemaNode",schema:f.create(_),...$})},cloneWith(_,$){return J({..._,...$})}});var c_=J({is(_){return _.kind==="DropTableNode"},create(_,$){return J({kind:"DropTableNode",table:_,...$})},cloneWith(_,$){return J({..._,...$})}});var E$=J({is(_){return _.kind==="AddColumnNode"},create(_){return J({kind:"AddColumnNode",column:_})}});var x=J({is(_){return _.kind==="ColumnDefinitionNode"},create(_,$){return J({kind:"ColumnDefinitionNode",column:j.create(_),dataType:$})},cloneWithFrontModifier(_,$){return J({..._,frontModifiers:_.frontModifiers?J([..._.frontModifiers,$]):[$]})},cloneWithEndModifier(_,$){return J({..._,endModifiers:_.endModifiers?J([..._.endModifiers,$]):[$]})},cloneWith(_,$){return J({..._,...$})}});var P$=J({is(_){return _.kind==="DropColumnNode"},create(_){return J({kind:"DropColumnNode",column:j.create(_)})}});var F$=J({is(_){return _.kind==="RenameColumnNode"},create(_,$){return J({kind:"RenameColumnNode",column:j.create(_),renameTo:j.create($)})}});var M_=J({is(_){return _.kind==="CheckConstraintNode"},create(_,$){return J({kind:"CheckConstraintNode",expression:_,name:$?f.create($):void 0})}});var o$=["no action","restrict","cascade","set null","set default"],S_=J({is(_){return _.kind==="ReferencesNode"},create(_,$){return J({kind:"ReferencesNode",table:_,columns:J([...$])})},cloneWithOnDelete(_,$){return J({..._,onDelete:$})},cloneWithOnUpdate(_,$){return J({..._,onUpdate:$})}});function i_(_){return e$(_)?_.toOperationNode():E_.createImmediate(_)}var u_=J({is(_){return _.kind==="GeneratedNode"},create(_){return J({kind:"GeneratedNode",..._})},createWithExpression(_){return J({kind:"GeneratedNode",always:!0,expression:_})},cloneWith(_,$){return J({..._,...$})}});var _W=J({is(_){return _.kind==="DefaultValueNode"},create(_){return J({kind:"DefaultValueNode",defaultValue:_})}});function A_(_){if(o$.includes(_))return _;throw Error(`invalid OnModifyForeignAction ${_}`)}class w{#_;constructor(_){this.#_=_}autoIncrement(){return new w(x.cloneWith(this.#_,{autoIncrement:!0}))}identity(){return new w(x.cloneWith(this.#_,{identity:!0}))}primaryKey(){return new w(x.cloneWith(this.#_,{primaryKey:!0}))}references(_){let $=WW(_);if(!$.table||$W.is($.column))throw Error(`invalid call references('${_}'). The reference must have format table.column or schema.table.column`);return new w(x.cloneWith(this.#_,{references:S_.create($.table,[$.column])}))}onDelete(_){if(!this.#_.references)throw Error("on delete constraint can only be added for foreign keys");return new w(x.cloneWith(this.#_,{references:S_.cloneWithOnDelete(this.#_.references,A_(_))}))}onUpdate(_){if(!this.#_.references)throw Error("on update constraint can only be added for foreign keys");return new w(x.cloneWith(this.#_,{references:S_.cloneWithOnUpdate(this.#_.references,A_(_))}))}unique(){return new w(x.cloneWith(this.#_,{unique:!0}))}notNull(){return new w(x.cloneWith(this.#_,{notNull:!0}))}unsigned(){return new w(x.cloneWith(this.#_,{unsigned:!0}))}defaultTo(_){return new w(x.cloneWith(this.#_,{defaultTo:_W.create(i_(_))}))}check(_){return new w(x.cloneWith(this.#_,{check:M_.create(_.toOperationNode())}))}generatedAlwaysAs(_){return new w(x.cloneWith(this.#_,{generated:u_.createWithExpression(_.toOperationNode())}))}generatedAlwaysAsIdentity(){return new w(x.cloneWith(this.#_,{generated:u_.create({identity:!0,always:!0})}))}generatedByDefaultAsIdentity(){return new w(x.cloneWith(this.#_,{generated:u_.create({identity:!0,byDefault:!0})}))}stored(){if(!this.#_.generated)throw Error("stored() can only be called after generatedAlwaysAs");return new w(x.cloneWith(this.#_,{generated:u_.cloneWith(this.#_.generated,{stored:!0})}))}modifyFront(_){return new w(x.cloneWithFrontModifier(this.#_,_.toOperationNode()))}nullsNotDistinct(){return new w(x.cloneWith(this.#_,{nullsNotDistinct:!0}))}ifNotExists(){return new w(x.cloneWith(this.#_,{ifNotExists:!0}))}modifyEnd(_){return new w(x.cloneWithEndModifier(this.#_,_.toOperationNode()))}$call(_){return _(this)}toOperationNode(){return this.#_}}var K$=J({is(_){return _.kind==="ModifyColumnNode"},create(_){return J({kind:"ModifyColumnNode",column:_})}});var s=J({is(_){return _.kind==="ForeignKeyConstraintNode"},create(_,$,W,Y){return J({kind:"ForeignKeyConstraintNode",columns:_,references:S_.create($,W),name:Y?f.create(Y):void 0})},cloneWith(_,$){return J({..._,...$})}});class d{#_;constructor(_){this.#_=_}onDelete(_){return new d(s.cloneWith(this.#_,{onDelete:A_(_)}))}onUpdate(_){return new d(s.cloneWith(this.#_,{onUpdate:A_(_)}))}deferrable(){return new d(s.cloneWith(this.#_,{deferrable:!0}))}notDeferrable(){return new d(s.cloneWith(this.#_,{deferrable:!1}))}initiallyDeferred(){return new d(s.cloneWith(this.#_,{initiallyDeferred:!0}))}initiallyImmediate(){return new d(s.cloneWith(this.#_,{initiallyDeferred:!1}))}$call(_){return _(this)}toOperationNode(){return this.#_}}var I_=J({is(_){return _.kind==="AddConstraintNode"},create(_){return J({kind:"AddConstraintNode",constraint:_})}});var l=J({is(_){return _.kind==="UniqueConstraintNode"},create(_,$,W){return J({kind:"UniqueConstraintNode",columns:J(_.map(j.create)),name:$?f.create($):void 0,nullsNotDistinct:W})},cloneWith(_,$){return J({..._,...$})}});var Q_=J({is(_){return _.kind==="DropConstraintNode"},create(_){return J({kind:"DropConstraintNode",constraintName:f.create(_)})},cloneWith(_,$){return J({..._,...$})}});var x_=J({is(_){return _.kind==="AlterColumnNode"},create(_,$,W){return J({kind:"AlterColumnNode",column:j.create(_),[$]:W})}});class r_{#_;constructor(_){this.#_=_}setDataType(_){return new w_(x_.create(this.#_,"dataType",__(_)))}setDefault(_){return new w_(x_.create(this.#_,"setDefault",i_(_)))}dropDefault(){return new w_(x_.create(this.#_,"dropDefault",!0))}setNotNull(){return new w_(x_.create(this.#_,"setNotNull",!0))}dropNotNull(){return new w_(x_.create(this.#_,"dropNotNull",!0))}$call(_){return _(this)}}class w_{#_;constructor(_){this.#_=_}toOperationNode(){return this.#_}}class U_{#_;constructor(_){this.#_=J(_)}toOperationNode(){return this.#_.executor.transformQuery(this.#_.node,this.#_.queryId)}compile(){return this.#_.executor.compileQuery(this.toOperationNode(),this.#_.queryId)}async execute(){await this.#_.executor.executeQuery(this.compile())}}class $_{#_;constructor(_){this.#_=J(_)}onDelete(_){return new $_({...this.#_,constraintBuilder:this.#_.constraintBuilder.onDelete(_)})}onUpdate(_){return new $_({...this.#_,constraintBuilder:this.#_.constraintBuilder.onUpdate(_)})}deferrable(){return new $_({...this.#_,constraintBuilder:this.#_.constraintBuilder.deferrable()})}notDeferrable(){return new $_({...this.#_,constraintBuilder:this.#_.constraintBuilder.notDeferrable()})}initiallyDeferred(){return new $_({...this.#_,constraintBuilder:this.#_.constraintBuilder.initiallyDeferred()})}initiallyImmediate(){return new $_({...this.#_,constraintBuilder:this.#_.constraintBuilder.initiallyImmediate()})}$call(_){return _(this)}toOperationNode(){return this.#_.executor.transformQuery(M.cloneWithTableProps(this.#_.node,{addConstraint:I_.create(this.#_.constraintBuilder.toOperationNode())}),this.#_.queryId)}compile(){return this.#_.executor.compileQuery(this.toOperationNode(),this.#_.queryId)}async execute(){await this.#_.executor.executeQuery(this.compile())}}class P_{#_;constructor(_){this.#_=J(_)}ifExists(){return new P_({...this.#_,node:M.cloneWithTableProps(this.#_.node,{dropConstraint:Q_.cloneWith(this.#_.node.dropConstraint,{ifExists:!0})})})}cascade(){return new P_({...this.#_,node:M.cloneWithTableProps(this.#_.node,{dropConstraint:Q_.cloneWith(this.#_.node.dropConstraint,{modifier:"cascade"})})})}restrict(){return new P_({...this.#_,node:M.cloneWithTableProps(this.#_.node,{dropConstraint:Q_.cloneWith(this.#_.node.dropConstraint,{modifier:"restrict"})})})}$call(_){return _(this)}toOperationNode(){return this.#_.executor.transformQuery(this.#_.node,this.#_.queryId)}compile(){return this.#_.executor.compileQuery(this.toOperationNode(),this.#_.queryId)}async execute(){await this.#_.executor.executeQuery(this.compile())}}var W_=J({is(_){return _.kind==="PrimaryKeyConstraintNode"},create(_,$){return J({kind:"PrimaryKeyConstraintNode",columns:J(_.map(j.create)),name:$?f.create($):void 0})},cloneWith(_,$){return J({..._,...$})}});var k_=J({is(_){return _.kind==="AddIndexNode"},create(_){return J({kind:"AddIndexNode",name:f.create(_)})},cloneWith(_,$){return J({..._,...$})},cloneWithColumns(_,$){return J({..._,columns:[..._.columns||[],...$]})}});class z_{#_;constructor(_){this.#_=J(_)}unique(){return new z_({...this.#_,node:M.cloneWithTableProps(this.#_.node,{addIndex:k_.cloneWith(this.#_.node.addIndex,{unique:!0})})})}column(_){return new z_({...this.#_,node:M.cloneWithTableProps(this.#_.node,{addIndex:k_.cloneWithColumns(this.#_.node.addIndex,[T_(_)])})})}columns(_){return new z_({...this.#_,node:M.cloneWithTableProps(this.#_.node,{addIndex:k_.cloneWithColumns(this.#_.node.addIndex,_.map(T_))})})}expression(_){return new z_({...this.#_,node:M.cloneWithTableProps(this.#_.node,{addIndex:k_.cloneWithColumns(this.#_.node.addIndex,[_.toOperationNode()])})})}using(_){return new z_({...this.#_,node:M.cloneWithTableProps(this.#_.node,{addIndex:k_.cloneWith(this.#_.node.addIndex,{using:F_.createWithSql(_)})})})}$call(_){return _(this)}toOperationNode(){return this.#_.executor.transformQuery(this.#_.node,this.#_.queryId)}compile(){return this.#_.executor.compileQuery(this.toOperationNode(),this.#_.queryId)}async execute(){await this.#_.executor.executeQuery(this.compile())}}class n{#_;constructor(_){this.#_=_}nullsNotDistinct(){return new n(l.cloneWith(this.#_,{nullsNotDistinct:!0}))}deferrable(){return new n(l.cloneWith(this.#_,{deferrable:!0}))}notDeferrable(){return new n(l.cloneWith(this.#_,{deferrable:!1}))}initiallyDeferred(){return new n(l.cloneWith(this.#_,{initiallyDeferred:!0}))}initiallyImmediate(){return new n(l.cloneWith(this.#_,{initiallyDeferred:!1}))}$call(_){return _(this)}toOperationNode(){return this.#_}}class J_{#_;constructor(_){this.#_=_}deferrable(){return new J_(W_.cloneWith(this.#_,{deferrable:!0}))}notDeferrable(){return new J_(W_.cloneWith(this.#_,{deferrable:!1}))}initiallyDeferred(){return new J_(W_.cloneWith(this.#_,{initiallyDeferred:!0}))}initiallyImmediate(){return new J_(W_.cloneWith(this.#_,{initiallyDeferred:!1}))}$call(_){return _(this)}toOperationNode(){return this.#_}}class p_{#_;constructor(_){this.#_=_}$call(_){return _(this)}toOperationNode(){return this.#_}}var JW=J({is(_){return _.kind==="RenameConstraintNode"},create(_,$){return J({kind:"RenameConstraintNode",oldName:f.create(_),newName:f.create($)})}});class R${#_;constructor(_){this.#_=J(_)}renameTo(_){return new U_({...this.#_,node:M.cloneWithTableProps(this.#_.node,{renameTo:m(_)})})}setSchema(_){return new U_({...this.#_,node:M.cloneWithTableProps(this.#_.node,{setSchema:f.create(_)})})}alterColumn(_,$){let W=$(new r_(_));return new t({...this.#_,node:M.cloneWithColumnAlteration(this.#_.node,W.toOperationNode())})}dropColumn(_){return new t({...this.#_,node:M.cloneWithColumnAlteration(this.#_.node,P$.create(_))})}renameColumn(_,$){return new t({...this.#_,node:M.cloneWithColumnAlteration(this.#_.node,F$.create(_,$))})}addColumn(_,$,W=y){let Y=W(new w(x.create(_,__($))));return new t({...this.#_,node:M.cloneWithColumnAlteration(this.#_.node,E$.create(Y.toOperationNode()))})}modifyColumn(_,$,W=y){let Y=W(new w(x.create(_,__($))));return new t({...this.#_,node:M.cloneWithColumnAlteration(this.#_.node,K$.create(Y.toOperationNode()))})}addUniqueConstraint(_,$,W=y){let Y=W(new n(l.create($,_)));return new U_({...this.#_,node:M.cloneWithTableProps(this.#_.node,{addConstraint:I_.create(Y.toOperationNode())})})}addCheckConstraint(_,$,W=y){let Y=W(new p_(M_.create($.toOperationNode(),_)));return new U_({...this.#_,node:M.cloneWithTableProps(this.#_.node,{addConstraint:I_.create(Y.toOperationNode())})})}addForeignKeyConstraint(_,$,W,Y,Z=y){let h=Z(new d(s.create($.map(j.create),m(W),Y.map(j.create),_)));return new $_({...this.#_,constraintBuilder:h})}addPrimaryKeyConstraint(_,$,W=y){let Y=W(new J_(W_.create($,_)));return new U_({...this.#_,node:M.cloneWithTableProps(this.#_.node,{addConstraint:I_.create(Y.toOperationNode())})})}dropConstraint(_){return new P_({...this.#_,node:M.cloneWithTableProps(this.#_.node,{dropConstraint:Q_.create(_)})})}renameConstraint(_,$){return new P_({...this.#_,node:M.cloneWithTableProps(this.#_.node,{renameConstraint:JW.create(_,$)})})}addIndex(_){return new z_({...this.#_,node:M.cloneWithTableProps(this.#_.node,{addIndex:k_.create(_)})})}dropIndex(_){return new U_({...this.#_,node:M.cloneWithTableProps(this.#_.node,{dropIndex:H_.create(_)})})}$call(_){return _(this)}}class t{#_;constructor(_){this.#_=J(_)}alterColumn(_,$){let W=$(new r_(_));return new t({...this.#_,node:M.cloneWithColumnAlteration(this.#_.node,W.toOperationNode())})}dropColumn(_){return new t({...this.#_,node:M.cloneWithColumnAlteration(this.#_.node,P$.create(_))})}renameColumn(_,$){return new t({...this.#_,node:M.cloneWithColumnAlteration(this.#_.node,F$.create(_,$))})}addColumn(_,$,W=y){let Y=W(new w(x.create(_,__($))));return new t({...this.#_,node:M.cloneWithColumnAlteration(this.#_.node,E$.create(Y.toOperationNode()))})}modifyColumn(_,$,W=y){let Y=W(new w(x.create(_,__($))));return new t({...this.#_,node:M.cloneWithColumnAlteration(this.#_.node,K$.create(Y.toOperationNode()))})}toOperationNode(){return this.#_.executor.transformQuery(this.#_.node,this.#_.queryId)}compile(){return this.#_.executor.compileQuery(this.toOperationNode(),this.#_.queryId)}async execute(){await this.#_.executor.executeQuery(this.compile())}}class a_ extends YW{transformPrimitiveValueList(_){return o_.create(_.values.map(E_.createImmediate))}transformValue(_){return E_.createImmediate(_.value)}}class b{#_;constructor(_){this.#_=J(_)}ifNotExists(){return new b({...this.#_,node:a.cloneWith(this.#_.node,{ifNotExists:!0})})}unique(){return new b({...this.#_,node:a.cloneWith(this.#_.node,{unique:!0})})}nullsNotDistinct(){return new b({...this.#_,node:a.cloneWith(this.#_.node,{nullsNotDistinct:!0})})}on(_){return new b({...this.#_,node:a.cloneWith(this.#_.node,{table:m(_)})})}column(_){return new b({...this.#_,node:a.cloneWithColumns(this.#_.node,[T_(_)])})}columns(_){return new b({...this.#_,node:a.cloneWithColumns(this.#_.node,_.map(T_))})}expression(_){return new b({...this.#_,node:a.cloneWithColumns(this.#_.node,[_.toOperationNode()])})}using(_){return new b({...this.#_,node:a.cloneWith(this.#_.node,{using:F_.createWithSql(_)})})}where(..._){let $=new a_;return new b({...this.#_,node:LW.cloneWithWhere(this.#_.node,$.transformNode(ZW(_),this.#_.queryId))})}$call(_){return _(this)}toOperationNode(){return this.#_.executor.transformQuery(this.#_.node,this.#_.queryId)}compile(){return this.#_.executor.compileQuery(this.toOperationNode(),this.#_.queryId)}async execute(){await this.#_.executor.executeQuery(this.compile())}}class e_{#_;constructor(_){this.#_=J(_)}ifNotExists(){return new e_({...this.#_,node:n_.cloneWith(this.#_.node,{ifNotExists:!0})})}$call(_){return _(this)}toOperationNode(){return this.#_.executor.transformQuery(this.#_.node,this.#_.queryId)}compile(){return this.#_.executor.compileQuery(this.toOperationNode(),this.#_.queryId)}async execute(){await this.#_.executor.executeQuery(this.compile())}}function GW(_){if(XW.includes(_))return _;throw Error(`invalid OnCommitAction ${_}`)}class g{#_;constructor(_){this.#_=J(_)}temporary(){return new g({...this.#_,node:C.cloneWith(this.#_.node,{temporary:!0})})}onCommit(_){return new g({...this.#_,node:C.cloneWith(this.#_.node,{onCommit:GW(_)})})}ifNotExists(){return new g({...this.#_,node:C.cloneWith(this.#_.node,{ifNotExists:!0})})}addColumn(_,$,W=y){let Y=W(new w(x.create(_,__($))));return new g({...this.#_,node:C.cloneWithColumn(this.#_.node,Y.toOperationNode())})}addPrimaryKeyConstraint(_,$,W=y){let Y=W(new J_(W_.create($,_)));return new g({...this.#_,node:C.cloneWithConstraint(this.#_.node,Y.toOperationNode())})}addUniqueConstraint(_,$,W=y){let Y=W(new n(l.create($,_)));return new g({...this.#_,node:C.cloneWithConstraint(this.#_.node,Y.toOperationNode())})}addCheckConstraint(_,$,W=y){let Y=W(new p_(M_.create($.toOperationNode(),_)));return new g({...this.#_,node:C.cloneWithConstraint(this.#_.node,Y.toOperationNode())})}addForeignKeyConstraint(_,$,W,Y,Z=y){let h=Z(new d(s.create($.map(j.create),m(W),Y.map(j.create),_)));return new g({...this.#_,node:C.cloneWithConstraint(this.#_.node,h.toOperationNode())})}modifyFront(_){return new g({...this.#_,node:C.cloneWithFrontModifier(this.#_.node,_.toOperationNode())})}modifyEnd(_){return new g({...this.#_,node:C.cloneWithEndModifier(this.#_.node,_.toOperationNode())})}as(_){return new g({...this.#_,node:C.cloneWith(this.#_.node,{selectQuery:_$(_)})})}$call(_){return _(this)}toOperationNode(){return this.#_.executor.transformQuery(this.#_.node,this.#_.queryId)}compile(){return this.#_.executor.compileQuery(this.toOperationNode(),this.#_.queryId)}async execute(){await this.#_.executor.executeQuery(this.compile())}}class D_{#_;constructor(_){this.#_=J(_)}on(_){return new D_({...this.#_,node:H_.cloneWith(this.#_.node,{table:m(_)})})}ifExists(){return new D_({...this.#_,node:H_.cloneWith(this.#_.node,{ifExists:!0})})}cascade(){return new D_({...this.#_,node:H_.cloneWith(this.#_.node,{cascade:!0})})}$call(_){return _(this)}toOperationNode(){return this.#_.executor.transformQuery(this.#_.node,this.#_.queryId)}compile(){return this.#_.executor.compileQuery(this.toOperationNode(),this.#_.queryId)}async execute(){await this.#_.executor.executeQuery(this.compile())}}class s_{#_;constructor(_){this.#_=J(_)}ifExists(){return new s_({...this.#_,node:b_.cloneWith(this.#_.node,{ifExists:!0})})}cascade(){return new s_({...this.#_,node:b_.cloneWith(this.#_.node,{cascade:!0})})}$call(_){return _(this)}toOperationNode(){return this.#_.executor.transformQuery(this.#_.node,this.#_.queryId)}compile(){return this.#_.executor.compileQuery(this.toOperationNode(),this.#_.queryId)}async execute(){await this.#_.executor.executeQuery(this.compile())}}class d_{#_;constructor(_){this.#_=J(_)}ifExists(){return new d_({...this.#_,node:c_.cloneWith(this.#_.node,{ifExists:!0})})}cascade(){return new d_({...this.#_,node:c_.cloneWith(this.#_.node,{cascade:!0})})}$call(_){return _(this)}toOperationNode(){return this.#_.executor.transformQuery(this.#_.node,this.#_.queryId)}compile(){return this.#_.executor.compileQuery(this.toOperationNode(),this.#_.queryId)}async execute(){await this.#_.executor.executeQuery(this.compile())}}class M${#_=new a_;transformQuery(_){return this.#_.transformNode(_.node,_.queryId)}transformResult(_){return Promise.resolve(_.result)}}class Z_{#_;constructor(_){this.#_=J(_)}temporary(){return new Z_({...this.#_,node:Y_.cloneWith(this.#_.node,{temporary:!0})})}materialized(){return new Z_({...this.#_,node:Y_.cloneWith(this.#_.node,{materialized:!0})})}ifNotExists(){return new Z_({...this.#_,node:Y_.cloneWith(this.#_.node,{ifNotExists:!0})})}orReplace(){return new Z_({...this.#_,node:Y_.cloneWith(this.#_.node,{orReplace:!0})})}columns(_){return new Z_({...this.#_,node:Y_.cloneWith(this.#_.node,{columns:_.map(HW)})})}as(_){let $=_.withPlugin(new M$).toOperationNode();return new Z_({...this.#_,node:Y_.cloneWith(this.#_.node,{as:$})})}$call(_){return _(this)}toOperationNode(){return this.#_.executor.transformQuery(this.#_.node,this.#_.queryId)}compile(){return this.#_.executor.compileQuery(this.toOperationNode(),this.#_.queryId)}async execute(){await this.#_.executor.executeQuery(this.compile())}}var N_=J({is(_){return _.kind==="DropViewNode"},create(_){return J({kind:"DropViewNode",name:e.create(_)})},cloneWith(_,$){return J({..._,...$})}});class q_{#_;constructor(_){this.#_=J(_)}materialized(){return new q_({...this.#_,node:N_.cloneWith(this.#_.node,{materialized:!0})})}ifExists(){return new q_({...this.#_,node:N_.cloneWith(this.#_.node,{ifExists:!0})})}cascade(){return new q_({...this.#_,node:N_.cloneWith(this.#_.node,{cascade:!0})})}$call(_){return _(this)}toOperationNode(){return this.#_.executor.transformQuery(this.#_.node,this.#_.queryId)}compile(){return this.#_.executor.compileQuery(this.toOperationNode(),this.#_.queryId)}async execute(){await this.#_.executor.executeQuery(this.compile())}}var $$=J({is(_){return _.kind==="CreateTypeNode"},create(_){return J({kind:"CreateTypeNode",name:_})},cloneWithEnum(_,$){return J({..._,enum:o_.create($.map(E_.createImmediate))})}});class W${#_;constructor(_){this.#_=J(_)}toOperationNode(){return this.#_.executor.transformQuery(this.#_.node,this.#_.queryId)}asEnum(_){return new W$({...this.#_,node:$$.cloneWithEnum(this.#_.node,_)})}$call(_){return _(this)}compile(){return this.#_.executor.compileQuery(this.toOperationNode(),this.#_.queryId)}async execute(){await this.#_.executor.executeQuery(this.compile())}}var J$=J({is(_){return _.kind==="DropTypeNode"},create(_){return J({kind:"DropTypeNode",name:_})},cloneWith(_,$){return J({..._,...$})}});class Y${#_;constructor(_){this.#_=J(_)}ifExists(){return new Y$({...this.#_,node:J$.cloneWith(this.#_.node,{ifExists:!0})})}$call(_){return _(this)}toOperationNode(){return this.#_.executor.transformQuery(this.#_.node,this.#_.queryId)}compile(){return this.#_.executor.compileQuery(this.toOperationNode(),this.#_.queryId)}async execute(){await this.#_.executor.executeQuery(this.compile())}}function S$(_){if(_.includes(".")){let W=_.split(".").map(aW);if(W.length===2)return e.createWithSchema(W[0],W[1]);else throw Error(`invalid schemable identifier ${_}`)}else return e.create(_)}function aW(_){return _.trim()}var f_=J({is(_){return _.kind==="RefreshMaterializedViewNode"},create(_){return J({kind:"RefreshMaterializedViewNode",name:e.create(_)})},cloneWith(_,$){return J({..._,...$})}});class j_{#_;constructor(_){this.#_=J(_)}concurrently(){return new j_({...this.#_,node:f_.cloneWith(this.#_.node,{concurrently:!0,withNoData:!1})})}withData(){return new j_({...this.#_,node:f_.cloneWith(this.#_.node,{withNoData:!1})})}withNoData(){return new j_({...this.#_,node:f_.cloneWith(this.#_.node,{withNoData:!0,concurrently:!1})})}$call(_){return _(this)}toOperationNode(){return this.#_.executor.transformQuery(this.#_.node,this.#_.queryId)}compile(){return this.#_.executor.compileQuery(this.toOperationNode(),this.#_.queryId)}async execute(){await this.#_.executor.executeQuery(this.compile())}}class B_{#_;constructor(_){this.#_=_}createTable(_){return new g({queryId:T(),executor:this.#_,node:C.create(m(_))})}dropTable(_){return new d_({queryId:T(),executor:this.#_,node:c_.create(m(_))})}createIndex(_){return new b({queryId:T(),executor:this.#_,node:a.create(_)})}dropIndex(_){return new D_({queryId:T(),executor:this.#_,node:H_.create(_)})}createSchema(_){return new e_({queryId:T(),executor:this.#_,node:n_.create(_)})}dropSchema(_){return new s_({queryId:T(),executor:this.#_,node:b_.create(_)})}alterTable(_){return new R$({queryId:T(),executor:this.#_,node:M.create(m(_))})}createView(_){return new Z_({queryId:T(),executor:this.#_,node:Y_.create(_)})}refreshMaterializedView(_){return new j_({queryId:T(),executor:this.#_,node:f_.create(_)})}dropView(_){return new q_({queryId:T(),executor:this.#_,node:N_.create(_)})}createType(_){return new W$({queryId:T(),executor:this.#_,node:$$.create(S$(_))})}dropType(_){return new Y$({queryId:T(),executor:this.#_,node:J$.create(S$(_))})}withPlugin(_){return new B_(this.#_.withPlugin(_))}withoutPlugins(){return new B_(this.#_.withoutPlugins())}withSchema(_){return new B_(this.#_.withPluginAtFront(new v_(_)))}}class A${ref(_){return new UW(_)}table(_){return new kW(_)}}class I${#_;constructor(_){this.#_=_}async provideConnection(_){let $=await this.#_.acquireConnection();try{return await _($)}finally{await this.#_.releaseConnection($)}}}class h_ extends zW{#_;#$;#W;constructor(_,$,W,Y=[]){super(Y);this.#_=_,this.#$=$,this.#W=W}get adapter(){return this.#$}compileQuery(_,$){return this.#_.compileQuery(_,$)}provideConnection(_){return this.#W.provideConnection(_)}withPlugins(_){return new h_(this.#_,this.#$,this.#W,[...this.plugins,..._])}withPlugin(_){return new h_(this.#_,this.#$,this.#W,[...this.plugins,_])}withPluginAtFront(_){return new h_(this.#_,this.#$,this.#W,[_,...this.plugins])}withConnectionProvider(_){return new h_(this.#_,this.#$,_,[...this.plugins])}withoutPlugins(){return new h_(this.#_,this.#$,this.#W,[])}}function Z$(){if(typeof performance<"u"&&c(performance.now))return performance.now();else return Date.now()}class Q${#_;#$;#W;#J;#Y;#Z=new WeakSet;constructor(_,$){this.#J=!1,this.#_=_,this.#$=$}async init(){if(this.#Y)throw Error("driver has already been destroyed");if(!this.#W)this.#W=this.#_.init().then(()=>{this.#J=!0}).catch((_)=>{return this.#W=void 0,Promise.reject(_)});await this.#W}async acquireConnection(){if(this.#Y)throw Error("driver has already been destroyed");if(!this.#J)await this.init();let _=await this.#_.acquireConnection();if(!this.#Z.has(_)){if(this.#X())this.#G(_);this.#Z.add(_)}return _}async releaseConnection(_){await this.#_.releaseConnection(_)}beginTransaction(_,$){return this.#_.beginTransaction(_,$)}commitTransaction(_){return this.#_.commitTransaction(_)}rollbackTransaction(_){return this.#_.rollbackTransaction(_)}savepoint(_,$,W){if(this.#_.savepoint)return this.#_.savepoint(_,$,W);throw Error("The `savepoint` method is not supported by this driver")}rollbackToSavepoint(_,$,W){if(this.#_.rollbackToSavepoint)return this.#_.rollbackToSavepoint(_,$,W);throw Error("The `rollbackToSavepoint` method is not supported by this driver")}releaseSavepoint(_,$,W){if(this.#_.releaseSavepoint)return this.#_.releaseSavepoint(_,$,W);throw Error("The `releaseSavepoint` method is not supported by this driver")}async destroy(){if(!this.#W)return;if(await this.#W,!this.#Y)this.#Y=this.#_.destroy().catch((_)=>{return this.#Y=void 0,Promise.reject(_)});await this.#Y}#X(){return this.#$.isLevelEnabled("query")||this.#$.isLevelEnabled("error")}#G(_){let{executeQuery:$,streamQuery:W}=_,Y=this;_.executeQuery=async(Z)=>{let h,k=Z$();try{return await $.call(_,Z)}catch(I){throw h=I,await Y.#L(I,Z,k),I}finally{if(!h)await Y.#H(Z,k)}},_.streamQuery=async function*(Z,h){let k,I=Z$();try{for await(let D of W.call(_,Z,h))yield D}catch(D){throw k=D,await Y.#L(D,Z,I),D}finally{if(!k)await Y.#H(Z,I,!0)}}}async#L(_,$,W){await this.#$.error(()=>({level:"error",error:_,query:$,queryDurationMillis:this.#U(W)}))}async#H(_,$,W=!1){await this.#$.query(()=>({level:"query",isStream:W,query:_,queryDurationMillis:this.#U($)}))}#U(_){return Z$()-_}}var sW=()=>{};class t_{#_;#$;constructor(_){this.#_=_}async provideConnection(_){while(this.#$)await this.#$.catch(sW);return this.#$=this.#W(_).finally(()=>{this.#$=void 0}),this.#$}async#W(_){return await _(this.#_)}}var dW=["read only","read write"],tW=["read uncommitted","read committed","repeatable read","serializable","snapshot"];function x$(_){if(_.accessMode&&!dW.includes(_.accessMode))throw Error(`invalid transaction access mode ${_.accessMode}`);if(_.isolationLevel&&!tW.includes(_.isolationLevel))throw Error(`invalid transaction isolation level ${_.isolationLevel}`)}var lW=["query","error"],e6=J(lW);class w${#_;#$;constructor(_){if(c(_))this.#$=_,this.#_=J({query:!0,error:!0});else this.#$=nW,this.#_=J({query:_.includes("query"),error:_.includes("error")})}isLevelEnabled(_){return this.#_[_]}async query(_){if(this.#_.query)await this.#$(_())}async error(_){if(this.#_.error)await this.#$(_())}}function nW(_){if(_.level==="query"){let $=`kysely:query:${_.isStream?"stream:":""}`;console.log(`${$} ${_.query.sql}`),console.log(`${$} duration: ${_.queryDurationMillis.toFixed(1)}ms`)}else if(_.level==="error")if(_.error instanceof Error)console.error(`kysely:error: ${_.error.stack??_.error.message}`);else console.error(`kysely:error: ${JSON.stringify({error:_.error,query:_.query.sql,queryDurationMillis:_.queryDurationMillis})}`)}function hW(_){return u(_)&&c(_.compile)}Symbol.asyncDispose??=Symbol("Symbol.asyncDispose");class i extends EW{#_;constructor(_){let $,W;if(iW(_))$={executor:_.executor},W={..._};else{let Y=_.dialect,Z=Y.createDriver(),h=Y.createQueryCompiler(),k=Y.createAdapter(),I=new w$(_.log??[]),D=new Q$(Z,I),B=new I$(D),o=new h_(h,k,B,_.plugins??[]);$={executor:o},W={config:_,executor:o,dialect:Y,driver:D}}super($);this.#_=J(W)}get schema(){return new B_(this.#_.executor)}get dynamic(){return new A$}get introspection(){return this.#_.dialect.createIntrospector(this.withoutPlugins())}case(_){return new KW({node:FW.create(G$(_)?void 0:_$(_))})}get fn(){return PW()}transaction(){return new L$({...this.#_})}startTransaction(){return new X$({...this.#_})}connection(){return new RW({...this.#_})}withPlugin(_){return new i({...this.#_,executor:this.#_.executor.withPlugin(_)})}withoutPlugins(){return new i({...this.#_,executor:this.#_.executor.withoutPlugins()})}withSchema(_){return new i({...this.#_,executor:this.#_.executor.withPluginAtFront(new v_(_))})}withTables(){return new i({...this.#_})}async destroy(){await this.#_.driver.destroy()}get isTransaction(){return!1}getExecutor(){return this.#_.executor}executeQuery(_,$){if($!==void 0)OW("Passing `queryId` in `db.executeQuery` is deprecated and will result in a compile-time error in the future.");let W=hW(_)?_.compile():_;return this.getExecutor().executeQuery(W)}async[Symbol.asyncDispose](){await this.destroy()}}class R_ extends i{#_;constructor(_){super(_);this.#_=_}get isTransaction(){return!0}transaction(){throw Error("calling the transaction method for a Transaction is not supported")}connection(){throw Error("calling the connection method for a Transaction is not supported")}async destroy(){throw Error("calling the destroy method for a Transaction is not supported")}withPlugin(_){return new R_({...this.#_,executor:this.#_.executor.withPlugin(_)})}withoutPlugins(){return new R_({...this.#_,executor:this.#_.executor.withoutPlugins()})}withSchema(_){return new R_({...this.#_,executor:this.#_.executor.withPluginAtFront(new v_(_))})}withTables(){return new R_({...this.#_})}}function iW(_){return u(_)&&u(_.config)&&u(_.driver)&&u(_.executor)&&u(_.dialect)}class RW{#_;constructor(_){this.#_=J(_)}async execute(_){return this.#_.executor.provideConnection(async($)=>{let W=this.#_.executor.withConnectionProvider(new t_($)),Y=new i({...this.#_,executor:W});return await _(Y)})}}class L${#_;constructor(_){this.#_=J(_)}setAccessMode(_){return new L$({...this.#_,accessMode:_})}setIsolationLevel(_){return new L$({...this.#_,isolationLevel:_})}async execute(_){let{isolationLevel:$,accessMode:W,...Y}=this.#_,Z={isolationLevel:$,accessMode:W};return x$(Z),this.#_.executor.provideConnection(async(h)=>{let k={isCommitted:!1,isRolledBack:!1},I=new X_(this.#_.executor.withConnectionProvider(new t_(h)),k),D=new R_({...Y,executor:I}),B=!1;try{await this.#_.driver.beginTransaction(h,Z),B=!0;let o=await _(D);return await this.#_.driver.commitTransaction(h),k.isCommitted=!0,o}catch(o){if(B)await this.#_.driver.rollbackTransaction(h),k.isRolledBack=!0;throw o}})}}class X${#_;constructor(_){this.#_=J(_)}setAccessMode(_){return new X$({...this.#_,accessMode:_})}setIsolationLevel(_){return new X$({...this.#_,isolationLevel:_})}async execute(){let{isolationLevel:_,accessMode:$,...W}=this.#_,Y={isolationLevel:_,accessMode:$};x$(Y);let Z=await VW(this.#_.executor);return await this.#_.driver.beginTransaction(Z.connection,Y),new L_({...W,connection:Z,executor:this.#_.executor.withConnectionProvider(new t_(Z.connection))})}}class L_ extends R_{#_;#$;#W;constructor(_){let $={isCommitted:!1,isRolledBack:!1};_={..._,executor:new X_(_.executor,$)};let{connection:W,...Y}=_;super(Y);this.#_=J(_),this.#W=$;let Z=T();this.#$=(h)=>_.executor.compileQuery(h,Z)}get isCommitted(){return this.#W.isCommitted}get isRolledBack(){return this.#W.isRolledBack}commit(){return K_(this.#W),new y_(async()=>{await this.#_.driver.commitTransaction(this.#_.connection.connection),this.#W.isCommitted=!0,this.#_.connection.release()})}rollback(){return K_(this.#W),new y_(async()=>{await this.#_.driver.rollbackTransaction(this.#_.connection.connection),this.#W.isRolledBack=!0,this.#_.connection.release()})}savepoint(_){return K_(this.#W),new y_(async()=>{return await this.#_.driver.savepoint?.(this.#_.connection.connection,_,this.#$),new L_({...this.#_})})}rollbackToSavepoint(_){return K_(this.#W),new y_(async()=>{return await this.#_.driver.rollbackToSavepoint?.(this.#_.connection.connection,_,this.#$),new L_({...this.#_})})}releaseSavepoint(_){return K_(this.#W),new y_(async()=>{return await this.#_.driver.releaseSavepoint?.(this.#_.connection.connection,_,this.#$),new L_({...this.#_})})}withPlugin(_){return new L_({...this.#_,executor:this.#_.executor.withPlugin(_)})}withoutPlugins(){return new L_({...this.#_,executor:this.#_.executor.withoutPlugins()})}withSchema(_){return new L_({...this.#_,executor:this.#_.executor.withPluginAtFront(new v_(_))})}withTables(){return new L_({...this.#_})}}class y_{#_;constructor(_){this.#_=_}async execute(){return await this.#_()}}function K_(_){if(_.isCommitted)throw Error("Transaction is already committed");if(_.isRolledBack)throw Error("Transaction is already rolled back")}class X_{#_;#$;constructor(_,$){if(_ instanceof X_)this.#_=_.#_;else this.#_=_;this.#$=$}get adapter(){return this.#_.adapter}get plugins(){return this.#_.plugins}transformQuery(_,$){return this.#_.transformQuery(_,$)}compileQuery(_,$){return this.#_.compileQuery(_,$)}provideConnection(_){return this.#_.provideConnection(_)}executeQuery(_){return K_(this.#$),this.#_.executeQuery(_)}stream(_,$){return K_(this.#$),this.#_.stream(_,$)}withConnectionProvider(_){return new X_(this.#_.withConnectionProvider(_),this.#$)}withPlugin(_){return new X_(this.#_.withPlugin(_),this.#$)}withPlugins(_){return new X_(this.#_.withPlugins(_),this.#$)}withPluginAtFront(_){return new X_(this.#_.withPluginAtFront(_),this.#$)}withoutPlugins(){return new X_(this.#_.withoutPlugins(),this.#$)}}function p(_,$){return F_.createWithChildren([F_.createWithSql(`${_} `),f.create($)])}class T${#_;#$=new AW;#W;#J;constructor(_){this.#_=J({..._})}async init(){if(this.#W=c(this.#_.database)?await this.#_.database():this.#_.database,this.#J=new SW(this.#W),this.#_.onCreateConnection)await this.#_.onCreateConnection(this.#J)}async acquireConnection(){return await this.#$.lock(),this.#J}async beginTransaction(_){await _.executeQuery(v.raw("begin"))}async commitTransaction(_){await _.executeQuery(v.raw("commit"))}async rollbackTransaction(_){await _.executeQuery(v.raw("rollback"))}async savepoint(_,$,W){await _.executeQuery(W(p("savepoint",$),T()))}async rollbackToSavepoint(_,$,W){await _.executeQuery(W(p("rollback to",$),T()))}async releaseSavepoint(_,$,W){await _.executeQuery(W(p("release",$),T()))}async releaseConnection(){this.#$.unlock()}async destroy(){this.#W?.close()}}class SW{#_;constructor(_){this.#_=_}executeQuery(_){let{sql:$,parameters:W}=_,Y=this.#_.prepare($);if(Y.reader)return Promise.resolve({rows:Y.all(W)});let{changes:Z,lastInsertRowid:h}=Y.run(W);return Promise.resolve({numAffectedRows:Z!==void 0&&Z!==null?BigInt(Z):void 0,insertId:h!==void 0&&h!==null?BigInt(h):void 0,rows:[]})}async*streamQuery(_,$){let{sql:W,parameters:Y,query:Z}=_,h=this.#_.prepare(W);if(MW.is(Z)){let k=h.iterate(Y);for(let I of k)yield{rows:[I]}}else throw Error("Sqlite driver only supports streaming of select queries")}}class AW{#_;#$;async lock(){while(this.#_)await this.#_;this.#_=new Promise((_)=>{this.#$=_})}unlock(){let _=this.#$;this.#_=void 0,this.#$=void 0,_?.()}}class D${#_;constructor(_){this.#_=_}async getSchemas(){return[]}async getTables(_={withInternalKyselyTables:!1}){return await this.#W(_)}async getMetadata(_){return{tables:await this.getTables(_)}}#$(_,$){let W=_.selectFrom("sqlite_master").where("type","in",["table","view"]).where("name","not like","sqlite_%").select(["name","sql","type"]).orderBy("name");if(!$.withInternalKyselyTables)W=W.where("name","!=",r).where("name","!=",O_);return W}async#W(_){let $=await this.#$(this.#_,_).execute(),W=await this.#_.with("table_list",(Z)=>this.#$(Z,_)).selectFrom(["table_list as tl",P`pragma_table_info(tl.name)`.as("p")]).select(["tl.name as table","p.cid","p.name","p.type","p.notnull","p.dflt_value","p.pk"]).orderBy("tl.name").orderBy("p.cid").execute(),Y={};for(let Z of W)Y[Z.table]??=[],Y[Z.table].push(Z);return $.map(({name:Z,sql:h,type:k})=>{let I=h?.split(/[\(\),]/)?.find((B)=>B.toLowerCase().includes("autoincrement"))?.trimStart()?.split(/\s+/)?.[0]?.replace(/["`]/g,""),D=Y[Z]??[];if(!I){let B=D.filter((o)=>o.pk>0);if(B.length===1&&B[0].type.toLowerCase()==="integer")I=B[0].name}return{name:Z,isView:k==="view",columns:D.map((B)=>({name:B.name,dataType:B.type,isNullable:!B.notnull,isAutoIncrementing:B.name===I,hasDefaultValue:B.dflt_value!=null,comment:void 0}))}})}}class H${#_;constructor(_){this.#_=J({..._})}createDriver(){return new T$(this.#_)}createQueryCompiler(){return new IW}createAdapter(){return new QW}createIntrospector(_){return new D$(_)}}var rW=/"/g;class N$ extends C_{sanitizeIdentifier(_){return _.replace(rW,'""')}}class q${#_;constructor(_){this.#_=_}async getSchemas(){return(await this.#_.selectFrom("pg_catalog.pg_namespace").select("nspname").$castTo().execute()).map(($)=>({name:$.nspname}))}async getTables(_={withInternalKyselyTables:!1}){let $=this.#_.selectFrom("pg_catalog.pg_attribute as a").innerJoin("pg_catalog.pg_class as c","a.attrelid","c.oid").innerJoin("pg_catalog.pg_namespace as ns","c.relnamespace","ns.oid").innerJoin("pg_catalog.pg_type as typ","a.atttypid","typ.oid").innerJoin("pg_catalog.pg_namespace as dtns","typ.typnamespace","dtns.oid").select(["a.attname as column","a.attnotnull as not_null","a.atthasdef as has_default","c.relname as table","c.relkind as table_type","ns.nspname as schema","typ.typname as type","dtns.nspname as type_schema",P`col_description(a.attrelid, a.attnum)`.as("column_description"),P`pg_get_serial_sequence(quote_ident(ns.nspname) || '.' || quote_ident(c.relname), a.attname)`.as("auto_incrementing")]).where("c.relkind","in",["r","v","p"]).where("ns.nspname","!~","^pg_").where("ns.nspname","!=","information_schema").where("ns.nspname","!=","crdb_internal").where(P`has_schema_privilege(ns.nspname, 'USAGE')`).where("a.attnum",">=",0).where("a.attisdropped","!=",!0).orderBy("ns.nspname").orderBy("c.relname").orderBy("a.attnum").$castTo();if(!_.withInternalKyselyTables)$=$.where("c.relname","!=",r).where("c.relname","!=",O_);let W=await $.execute();return this.#$(W)}async getMetadata(_){return{tables:await this.getTables(_)}}#$(_){let $=new Map;for(let W=0,Y=_.length;W<Y;W++){let Z=_[W],{schema:h,table:k}=Z,I=`schema:${h};table:${k}`;if(!$.has(I))$.set(I,J({columns:[],isView:Z.table_type==="v",name:k,schema:h}));$.get(I).columns.push(J({comment:Z.column_description??void 0,dataType:Z.type,dataTypeSchema:Z.type_schema,hasDefaultValue:Z.has_default,isAutoIncrementing:Z.auto_incrementing!==null,isNullable:!Z.not_null,name:Z.column}))}return Array.from($.values())}}var oW=BigInt("3853314791062309107");class f$ extends g_{get supportsTransactionalDdl(){return!0}get supportsReturning(){return!0}async acquireMigrationLock(_,$){await P`select pg_advisory_xact_lock(${P.lit(oW)})`.execute(_)}async releaseMigrationLock(_,$){}}function m_(_,$){if(eW(_)&&$.stack){let W=$.stack.split(`
|
|
3
|
+
`).slice(1).join(`
|
|
4
|
+
`);return _.stack+=`
|
|
5
|
+
${W}`,_}return _}function eW(_){return u(_)&&U$(_.stack)}var xW=Symbol();class j${#_;#$=new WeakMap;#W;constructor(_){this.#_=J({..._})}async init(){this.#W=c(this.#_.pool)?await this.#_.pool():this.#_.pool}async acquireConnection(){let _=await this.#J(),$=this.#$.get(_);if(!$){if($=new wW(_),this.#$.set(_,$),this.#_?.onCreateConnection)await this.#_.onCreateConnection($)}if(this.#_?.onReserveConnection)await this.#_.onReserveConnection($);return $}async#J(){return new Promise((_,$)=>{this.#W.getConnection(async(W,Y)=>{if(W)$(W);else _(Y)})})}async beginTransaction(_,$){if($.isolationLevel||$.accessMode){let W=[];if($.isolationLevel)W.push(`isolation level ${$.isolationLevel}`);if($.accessMode)W.push($.accessMode);let Y=`set transaction ${W.join(", ")}`;await _.executeQuery(v.raw(Y))}await _.executeQuery(v.raw("begin"))}async commitTransaction(_){await _.executeQuery(v.raw("commit"))}async rollbackTransaction(_){await _.executeQuery(v.raw("rollback"))}async savepoint(_,$,W){await _.executeQuery(W(p("savepoint",$),T()))}async rollbackToSavepoint(_,$,W){await _.executeQuery(W(p("rollback to",$),T()))}async releaseSavepoint(_,$,W){await _.executeQuery(W(p("release savepoint",$),T()))}async releaseConnection(_){_[xW]()}async destroy(){return new Promise((_,$)=>{this.#W.end((W)=>{if(W)$(W);else _()})})}}function _J(_){return u(_)&&"insertId"in _&&"affectedRows"in _}class wW{#_;constructor(_){this.#_=_}async executeQuery(_){try{let $=await this.#$(_);if(_J($)){let{insertId:W,affectedRows:Y,changedRows:Z}=$;return{insertId:W!==void 0&&W!==null&&W.toString()!=="0"?BigInt(W):void 0,numAffectedRows:Y!==void 0&&Y!==null?BigInt(Y):void 0,numChangedRows:Z!==void 0&&Z!==null?BigInt(Z):void 0,rows:[]}}else if(Array.isArray($))return{rows:$};return{rows:[]}}catch($){throw m_($,Error())}}#$(_){return new Promise(($,W)=>{this.#_.query(_.sql,_.parameters,(Y,Z)=>{if(Y)W(Y);else $(Z)})})}async*streamQuery(_,$){let W=this.#_.query(_.sql,_.parameters).stream({objectMode:!0});try{for await(let Y of W)yield{rows:[Y]}}catch(Y){if(Y&&typeof Y==="object"&&"code"in Y&&Y.code==="ERR_STREAM_PREMATURE_CLOSE")return;throw Y}}[xW](){this.#_.release()}}var $J=/[\\']/g,B$=/`/g,WJ=/[\\'"]/g;class v$ extends C_{getCurrentParameterPlaceholder(){return"?"}getLeftExplainOptionsWrapper(){return""}getExplainOptionAssignment(){return"="}getExplainOptionsDelimiter(){return" "}getRightExplainOptionsWrapper(){return""}getLeftIdentifierWrapper(){return B$.source}getRightIdentifierWrapper(){return B$.source}sanitizeIdentifier(_){return _.replace(B$,"``")}sanitizeStringLiteral(_){return _.replace($J,($)=>$==="\\"?"\\\\":"''")}sanitizeJSONPathMemberValue(_){return _.replace(WJ,($)=>$==="\\"?"\\\\\\\\":$==="'"?"''":'\\\\"')}visitCreateIndex(_){if(this.append("create "),_.unique)this.append("unique ");if(this.append("index "),_.ifNotExists)this.append("if not exists ");if(this.visitNode(_.name),_.using)this.append(" using "),this.visitNode(_.using);if(_.table)this.append(" on "),this.visitNode(_.table);if(_.columns)this.append(" ("),this.compileList(_.columns),this.append(")");if(_.where)this.append(" "),this.visitNode(_.where)}}class y${#_;constructor(_){this.#_=_}async getSchemas(){return(await this.#_.selectFrom("information_schema.schemata").select("schema_name").$castTo().execute()).map(($)=>({name:$.SCHEMA_NAME}))}async getTables(_={withInternalKyselyTables:!1}){let $=this.#_.selectFrom("information_schema.columns as columns").innerJoin("information_schema.tables as tables",(Y)=>Y.onRef("columns.TABLE_CATALOG","=","tables.TABLE_CATALOG").onRef("columns.TABLE_SCHEMA","=","tables.TABLE_SCHEMA").onRef("columns.TABLE_NAME","=","tables.TABLE_NAME")).select(["columns.COLUMN_NAME","columns.COLUMN_DEFAULT","columns.TABLE_NAME","columns.TABLE_SCHEMA","tables.TABLE_TYPE","columns.IS_NULLABLE","columns.DATA_TYPE","columns.EXTRA","columns.COLUMN_COMMENT"]).where("columns.TABLE_SCHEMA","=",P`database()`).orderBy("columns.TABLE_NAME").orderBy("columns.ORDINAL_POSITION").$castTo();if(!_.withInternalKyselyTables)$=$.where("columns.TABLE_NAME","!=",r).where("columns.TABLE_NAME","!=",O_);let W=await $.execute();return this.#$(W)}async getMetadata(_){return{tables:await this.getTables(_)}}#$(_){return _.reduce(($,W)=>{let Y=$.find((Z)=>Z.name===W.TABLE_NAME);if(!Y)Y=J({name:W.TABLE_NAME,isView:W.TABLE_TYPE==="VIEW",schema:W.TABLE_SCHEMA,columns:[]}),$.push(Y);return Y.columns.push(J({name:W.COLUMN_NAME,dataType:W.DATA_TYPE,isNullable:W.IS_NULLABLE==="YES",isAutoIncrementing:W.EXTRA.toLowerCase().includes("auto_increment"),hasDefaultValue:W.COLUMN_DEFAULT!==null,comment:W.COLUMN_COMMENT===""?void 0:W.COLUMN_COMMENT})),$},[])}}var TW="ea586330-2c93-47c8-908d-981d9d270f9d",JJ=3600;class C$ extends g_{get supportsTransactionalDdl(){return!1}get supportsReturning(){return!1}async acquireMigrationLock(_,$){await P`select get_lock(${P.lit(TW)}, ${P.lit(JJ)})`.execute(_)}async releaseMigrationLock(_,$){await P`select release_lock(${P.lit(TW)})`.execute(_)}}class k${#_;constructor(_){this.#_=_}createDriver(){return new j$(this.#_)}createQueryCompiler(){return new v$}createAdapter(){return new C$}createIntrospector(_){return new y$(_)}}var DW=Symbol();class g${#_;#$=new WeakMap;#W;constructor(_){this.#_=J({..._})}async init(){this.#W=c(this.#_.pool)?await this.#_.pool():this.#_.pool}async acquireConnection(){let _=await this.#W.connect(),$=this.#$.get(_);if(!$){if($=new NW(_,{cursor:this.#_.cursor??null}),this.#$.set(_,$),this.#_.onCreateConnection)await this.#_.onCreateConnection($)}if(this.#_.onReserveConnection)await this.#_.onReserveConnection($);return $}async beginTransaction(_,$){if($.isolationLevel||$.accessMode){let W="start transaction";if($.isolationLevel)W+=` isolation level ${$.isolationLevel}`;if($.accessMode)W+=` ${$.accessMode}`;await _.executeQuery(v.raw(W))}else await _.executeQuery(v.raw("begin"))}async commitTransaction(_){await _.executeQuery(v.raw("commit"))}async rollbackTransaction(_){await _.executeQuery(v.raw("rollback"))}async savepoint(_,$,W){await _.executeQuery(W(p("savepoint",$),T()))}async rollbackToSavepoint(_,$,W){await _.executeQuery(W(p("rollback to",$),T()))}async releaseSavepoint(_,$,W){await _.executeQuery(W(p("release",$),T()))}async releaseConnection(_){_[DW]()}async destroy(){if(this.#W){let _=this.#W;this.#W=void 0,await _.end()}}}class NW{#_;#$;constructor(_,$){this.#_=_,this.#$=$}async executeQuery(_){try{let{command:$,rowCount:W,rows:Y}=await this.#_.query(_.sql,[..._.parameters]);return{numAffectedRows:$==="INSERT"||$==="UPDATE"||$==="DELETE"||$==="MERGE"?BigInt(W):void 0,rows:Y??[]}}catch($){throw m_($,Error())}}async*streamQuery(_,$){if(!this.#$.cursor)throw Error("'cursor' is not present in your postgres dialect config. It's required to make streaming work in postgres.");if(!Number.isInteger($)||$<=0)throw Error("chunkSize must be a positive integer");let W=this.#_.query(new this.#$.cursor(_.sql,_.parameters.slice()));try{while(!0){let Y=await W.read($);if(Y.length===0)break;yield{rows:Y}}}finally{await W.close()}}[DW](){this.#_.release()}}class z${#_;constructor(_){this.#_=_}createDriver(){return new g$(this.#_)}createQueryCompiler(){return new N$}createAdapter(){return new f$}createIntrospector(_){return new q$(_)}}class m$ extends g_{get supportsCreateIfNotExists(){return!1}get supportsTransactionalDdl(){return!0}get supportsOutput(){return!0}async acquireMigrationLock(_){await P`exec sp_getapplock @DbPrincipal = ${P.lit("dbo")}, @Resource = ${P.lit(r)}, @LockMode = ${P.lit("Exclusive")}`.execute(_)}async releaseMigrationLock(){}}var CW=Symbol(),gW=Symbol(),mW=Symbol();class c${#_;#$;constructor(_){this.#_=J({..._});let{tarn:$,tedious:W,validateConnections:Y}=this.#_,{validateConnections:Z,...h}=$.options;this.#$=new $.Pool({...h,create:async()=>{let k=await W.connectionFactory();return await new bW(k,W).connect()},destroy:async(k)=>{await k[gW]()},validate:Y===!1||Z===!1?void 0:(k)=>k[mW]()})}async init(){}async acquireConnection(){return await this.#$.acquire().promise}async beginTransaction(_,$){await _.beginTransaction($)}async commitTransaction(_){await _.commitTransaction()}async rollbackTransaction(_){await _.rollbackTransaction()}async savepoint(_,$){await _.savepoint($)}async rollbackToSavepoint(_,$){await _.rollbackTransaction($)}async releaseConnection(_){if(this.#_.resetConnectionsOnRelease||this.#_.tedious.resetConnectionOnRelease)await _[CW]();this.#$.release(_)}async destroy(){await this.#$.destroy()}}class bW{#_;#$;#W;constructor(_,$){this.#_=_,this.#$=!1,this.#W=$}async beginTransaction(_){let{isolationLevel:$}=_;await new Promise((W,Y)=>this.#_.beginTransaction((Z)=>{if(Z)Y(Z);else W(void 0)},$?yW(8):void 0,$?this.#J($):void 0))}async commitTransaction(){await new Promise((_,$)=>this.#_.commitTransaction((W)=>{if(W)$(W);else _(void 0)}))}async connect(){let{promise:_,reject:$,resolve:W}=new h$;this.#_.connect((Z)=>{if(Z)return $(Z);W()}),this.#_.on("error",(Z)=>{if(Z instanceof Error&&"code"in Z&&Z.code==="ESOCKET")this.#$=!0;console.error(Z),$(Z)});function Y(){$(Error("The connection ended without ever completing the connection"))}return this.#_.once("end",Y),await _,this.#_.off("end",Y),this}async executeQuery(_){try{let $=new h$,W=new O$({compiledQuery:_,tedious:this.#W,onDone:$});this.#_.execSql(W.request);let{rowCount:Y,rows:Z}=await $.promise;return{numAffectedRows:Y!==void 0?BigInt(Y):void 0,rows:Z}}catch($){throw m_($,Error())}}async rollbackTransaction(_){await new Promise(($,W)=>this.#_.rollbackTransaction((Y)=>{if(Y)W(Y);else $(void 0)},_))}async savepoint(_){await new Promise(($,W)=>this.#_.saveTransaction((Y)=>{if(Y)W(Y);else $(void 0)},_))}async*streamQuery(_,$){if(!Number.isInteger($)||$<=0)throw Error("chunkSize must be a positive integer");let W=new O$({compiledQuery:_,streamChunkSize:$,tedious:this.#W});this.#_.execSql(W.request);try{while(!0){let Y=await W.readChunk();if(Y.length===0)break;if(yield{rows:Y},Y.length<$)break}}finally{await this.#Y(W)}}#J(_){let{ISOLATION_LEVEL:$}=this.#W,Y={"read committed":$.READ_COMMITTED,"read uncommitted":$.READ_UNCOMMITTED,"repeatable read":$.REPEATABLE_READ,serializable:$.SERIALIZABLE,snapshot:$.SNAPSHOT}[_];if(Y===void 0)throw Error(`Unknown isolation level: ${_}`);return Y}#Y(_){return new Promise(($)=>{if(_.request.once("requestCompleted",$),!this.#_.cancel())_.request.off("requestCompleted",$),$()})}[gW](){if("closed"in this.#_&&this.#_.closed)return Promise.resolve();return new Promise((_)=>{this.#_.once("end",_),this.#_.close()})}async[CW](){await new Promise((_,$)=>{this.#_.reset((W)=>{if(W)return $(W);_()})})}async[mW](){if(this.#$||this.#Z())return!1;try{let _=new h$,$=new O$({compiledQuery:v.raw("select 1"),onDone:_,tedious:this.#W});return this.#_.execSql($.request),await _.promise,!0}catch{return!1}}#Z(){return"closed"in this.#_&&Boolean(this.#_.closed)}}class O${#_;#$;#W;#J;#Y;#Z;constructor(_){let{compiledQuery:$,onDone:W,streamChunkSize:Y,tedious:Z}=_;if(this.#$=[],this.#W=Y,this.#J={},this.#Y=Z,W)this.#J.onDone=(k,I)=>{if(k==="chunkReady")return;if(delete this.#J.onDone,k==="error")return W.reject(I);W.resolve({rowCount:this.#Z,rows:this.#$})};this.#_=new this.#Y.Request($.sql,(h,k)=>{if(h)return Object.values(this.#J).forEach((I)=>I("error",h instanceof AggregateError?h.errors:h));this.#Z=k}),this.#X($.parameters),this.#G()}get request(){return this.#_}readChunk(){let _=this.readChunk.name;return new Promise(($,W)=>{this.#J[_]=(Y,Z)=>{if(delete this.#J[_],Y==="error")return W(Z);$(this.#$.splice(0,this.#W))},this.#_.resume()})}#X(_){for(let $=0;$<_.length;$++){let W=_[$];this.#_.addParameter(String($+1),this.#L(W),W)}}#G(){let _=this.#W?()=>{if(this.#W<=this.#$.length)this.#_.pause(),Object.values(this.#J).forEach((W)=>W("chunkReady"))}:()=>{},$=(W)=>{let Y={};for(let Z of W)Y[Z.metadata.colName]=Z.value;this.#$.push(Y),_()};this.#_.on("row",$),this.#_.once("requestCompleted",()=>{Object.values(this.#J).forEach((W)=>W("completed")),this.#_.off("row",$)})}#L(_){if(fW(_)||G$(_)||U$(_))return this.#Y.TYPES.NVarChar;if(BW(_)||b$(_)&&_%1===0)if(_<-2147483648||_>2147483647)return this.#Y.TYPES.BigInt;else return this.#Y.TYPES.Int;if(b$(_))return this.#Y.TYPES.Float;if(qW(_))return this.#Y.TYPES.Bit;if(jW(_))return this.#Y.TYPES.DateTime;if(vW(_))return this.#Y.TYPES.VarBinary;return this.#Y.TYPES.NVarChar}}class u${#_;constructor(_){this.#_=_}async getSchemas(){return await this.#_.selectFrom("sys.schemas").select("name").execute()}async getTables(_={withInternalKyselyTables:!1}){let $=await this.#_.selectFrom("sys.tables as tables").leftJoin("sys.schemas as table_schemas","table_schemas.schema_id","tables.schema_id").innerJoin("sys.columns as columns","columns.object_id","tables.object_id").innerJoin("sys.types as types","types.user_type_id","columns.user_type_id").leftJoin("sys.schemas as type_schemas","type_schemas.schema_id","types.schema_id").leftJoin("sys.extended_properties as comments",(Y)=>Y.onRef("comments.major_id","=","tables.object_id").onRef("comments.minor_id","=","columns.column_id").on("comments.name","=","MS_Description")).$if(!_.withInternalKyselyTables,(Y)=>Y.where("tables.name","!=",r).where("tables.name","!=",O_)).select(["tables.name as table_name",(Y)=>Y.ref("tables.type").$castTo().as("table_type"),"table_schemas.name as table_schema_name","columns.default_object_id as column_default_object_id","columns.generated_always_type_desc as column_generated_always_type","columns.is_computed as column_is_computed","columns.is_identity as column_is_identity","columns.is_nullable as column_is_nullable","columns.is_rowguidcol as column_is_rowguidcol","columns.name as column_name","types.is_nullable as type_is_nullable","types.name as type_name","type_schemas.name as type_schema_name","comments.value as column_comment"]).unionAll(this.#_.selectFrom("sys.views as views").leftJoin("sys.schemas as view_schemas","view_schemas.schema_id","views.schema_id").innerJoin("sys.columns as columns","columns.object_id","views.object_id").innerJoin("sys.types as types","types.user_type_id","columns.user_type_id").leftJoin("sys.schemas as type_schemas","type_schemas.schema_id","types.schema_id").leftJoin("sys.extended_properties as comments",(Y)=>Y.onRef("comments.major_id","=","views.object_id").onRef("comments.minor_id","=","columns.column_id").on("comments.name","=","MS_Description")).select(["views.name as table_name","views.type as table_type","view_schemas.name as table_schema_name","columns.default_object_id as column_default_object_id","columns.generated_always_type_desc as column_generated_always_type","columns.is_computed as column_is_computed","columns.is_identity as column_is_identity","columns.is_nullable as column_is_nullable","columns.is_rowguidcol as column_is_rowguidcol","columns.name as column_name","types.is_nullable as type_is_nullable","types.name as type_name","type_schemas.name as type_schema_name","comments.value as column_comment"])).orderBy("table_schema_name").orderBy("table_name").orderBy("column_name").execute(),W={};for(let Y of $){let Z=`${Y.table_schema_name}.${Y.table_name}`;(W[Z]=W[Z]||J({columns:[],isView:Y.table_type==="V ",name:Y.table_name,schema:Y.table_schema_name??void 0})).columns.push(J({dataType:Y.type_name,dataTypeSchema:Y.type_schema_name??void 0,hasDefaultValue:Y.column_default_object_id>0||Y.column_generated_always_type!=="NOT_APPLICABLE"||Y.column_is_identity||Y.column_is_computed||Y.column_is_rowguidcol,isAutoIncrementing:Y.column_is_identity,isNullable:Y.column_is_nullable&&Y.type_is_nullable,name:Y.column_name,comment:Y.column_comment??void 0}))}return Object.values(W)}async getMetadata(_){return{tables:await this.getTables(_)}}}var YJ=/^[a-z0-9_]$/i;class p$ extends C_{getCurrentParameterPlaceholder(){return`@${this.numParameters}`}visitOffset(_){super.visitOffset(_),this.append(" rows")}compileColumnAlterations(_){let $={};for(let Y of _){if(!$[Y.kind])$[Y.kind]=[];$[Y.kind].push(Y)}let W=!0;if($.AddColumnNode)this.append("add "),this.compileList($.AddColumnNode),W=!1;if($.AlterColumnNode){if(!W)this.append(", ");this.compileList($.AlterColumnNode)}if($.DropColumnNode){if(!W)this.append(", ");this.append("drop column "),this.compileList($.DropColumnNode)}if($.ModifyColumnNode){if(!W)this.append(", ");this.compileList($.ModifyColumnNode)}if($.RenameColumnNode){if(!W)this.append(", ");this.compileList($.RenameColumnNode)}}visitAddColumn(_){this.visitNode(_.column)}visitDropColumn(_){this.visitNode(_.column)}visitMergeQuery(_){super.visitMergeQuery(_),this.append(";")}visitCollate(_){this.append("collate ");let{name:$}=_.collation;for(let W of $)if(!YJ.test(W))throw Error(`Invalid collation: ${$}`);this.append($)}announcesNewColumnDataType(){return!1}}class a${#_;constructor(_){this.#_=_}createDriver(){return new c$(this.#_)}createQueryCompiler(){return new p$}createAdapter(){return new m$}createIntrospector(_){return new u$(_)}}function s$(_){return _.charAt(0).toUpperCase()+_.slice(1)}function cW(_){if(!_)return null;if("dialect"in _)return cW(_.dialect);if("createDriver"in _){if(_ instanceof H$)return"sqlite";if(_ instanceof k$)return"mysql";if(_ instanceof z$)return"postgres";if(_ instanceof a$)return"mssql"}if("aggregate"in _)return"sqlite";if("getConnection"in _)return"mysql";if("connect"in _)return"postgres";if("fileControl"in _)return"sqlite";if("open"in _&&"close"in _&&"prepare"in _)return"sqlite";if("batch"in _&&"exec"in _&&"prepare"in _)return"sqlite";return null}var e9=async(_)=>{let $=_.database;if(!$)return{kysely:null,databaseType:null,transaction:void 0};if("db"in $)return{kysely:$.db,databaseType:$.type,transaction:$.transaction};if("dialect"in $)return{kysely:new i({dialect:$.dialect}),databaseType:$.type,transaction:$.transaction};let W=void 0,Y=cW($);if("createDriver"in $)W=$;if("aggregate"in $&&!("createSession"in $))W=new H$({database:$});if("getConnection"in $)W=new k$($);if("connect"in $)W=new z$({pool:$});if("fileControl"in $){let{BunSqliteDialect:Z}=await import("./chunk-deg4vcxz.js");W=new Z({database:$})}if("createSession"in $){let Z=void 0;try{({DatabaseSync:Z}=await import("node:sqlite"))}catch(h){if(h!==null&&typeof h==="object"&&"code"in h&&h.code!=="ERR_UNKNOWN_BUILTIN_MODULE")throw h}if(Z&&$ instanceof Z){let{NodeSqliteDialect:h}=await import("./chunk-mary8ss4.js");W=new h({database:$})}}if("batch"in $&&"exec"in $&&"prepare"in $){let{D1SqliteDialect:Z}=await import("./chunk-06yecqzt.js");W=new Z({database:$})}return{kysely:W?new i({dialect:W}):null,databaseType:Y,transaction:void 0}};function d$(_,$,W){return W==="postgres"?P`${P.ref(_)} ILIKE ${$}`:P`LOWER(${P.ref(_)}) LIKE LOWER(${$})`}function ZJ(_,$){return{lhs:P`LOWER(${P.ref(_)})`,values:$.map((W)=>W.toLowerCase())}}function LJ(_,$){return{lhs:P`LOWER(${P.ref(_)})`,values:$.map((W)=>W.toLowerCase())}}function XJ(_,$){return{lhs:P`LOWER(${P.ref(_)})`,value:$.toLowerCase()}}function GJ(_,$){return{lhs:P`LOWER(${P.ref(_)})`,value:$.toLowerCase()}}var _0=(_,$)=>{let W=null,Y=(k,I=!1)=>{return({getFieldName:D,schema:B,getDefaultFieldName:o,getDefaultModelName:uW,getFieldAttributes:HJ,getModelName:V_})=>{let l$=(U)=>{let K=[],E=[];if(U)for(let[O,z]of Object.entries(U)){let G=B[uW(O)]?.fields,[H,F]=O.includes(".")?O.split("."):[void 0,O];if(!G)continue;G.id={type:"string"};for(let[N,L]of Object.entries(G))K.push(P`${P.ref(`join_${F}`)}.${P.ref(L.fieldName||N)} as ${P.ref(`_joined_${F}_${L.fieldName||N}`)}`),E.push({joinModel:O,joinModelRef:F,fieldName:L.fieldName||N})}return{allSelectsStr:E,allSelects:K}},n$=async(U,K,E,O)=>{let z;if($?.type==="mysql"){await K.execute();let G=U.id?"id":O.length>0&&O[0]?.field?O[0].field:"id";if(!U.id&&O.length===0)return z=await k.selectFrom(E).selectAll().orderBy(D({model:E,field:G}),"desc").limit(1).executeTakeFirst(),z;let H=U[G]!==void 0?U[G]:O[0]?.value;return z=await k.selectFrom(E).selectAll().orderBy(D({model:E,field:G}),"desc").where(D({model:E,field:G}),H===null?"is":"=",H).limit(1).executeTakeFirst(),z}if($?.type==="mssql")return z=await K.outputAll("inserted").executeTakeFirst(),z;return z=await K.returningAll().executeTakeFirst(),z};function G_(U,K){if(!K)return{and:null,or:null};let E={and:[],or:[]};return K.forEach((O)=>{let{field:z,value:G,operator:H="eq",connector:F="AND",mode:N="sensitive"}=O,L=G,S=D({model:U,field:z}),R=N==="insensitive"&&(typeof L==="string"||Array.isArray(L)&&L.every((V)=>typeof V==="string")),A=(V)=>{let X=`${U}.${S}`;if(H.toLowerCase()==="in"){if(R){let{lhs:q,values:Q}=ZJ(X,Array.isArray(L)?L:[L]);return V(q,"in",Q)}return V(X,"in",Array.isArray(L)?L:[L])}if(H.toLowerCase()==="not_in"){if(R){let{lhs:q,values:Q}=LJ(X,Array.isArray(L)?L:[L]);return V(q,"not in",Q)}return V(X,"not in",Array.isArray(L)?L:[L])}if(H==="contains"){if(R&&typeof L==="string")return d$(X,`%${L}%`,$?.type);return V(X,"like",`%${L}%`)}if(H==="starts_with"){if(R&&typeof L==="string")return d$(X,`${L}%`,$?.type);return V(X,"like",`${L}%`)}if(H==="ends_with"){if(R&&typeof L==="string")return d$(X,`%${L}`,$?.type);return V(X,"like",`%${L}`)}if(H==="eq"){if(L===null)return V(X,"is",null);if(R&&typeof L==="string"){let{lhs:q,value:Q}=XJ(X,L);return V(q,"=",Q)}return V(X,"=",L)}if(H==="ne"){if(L===null)return V(X,"is not",null);if(R&&typeof L==="string"){let{lhs:q,value:Q}=GJ(X,L);return V(q,"<>",Q)}return V(X,"<>",L)}if(H==="gt")return V(X,">",L);if(H==="gte")return V(X,">=",L);if(H==="lt")return V(X,"<",L);if(H==="lte")return V(X,"<=",L);return V(X,H,L)};if(F==="OR")E.or.push(A);else E.and.push(A)}),{and:E.and.length?E.and:null,or:E.or.length?E.or:null}}function i$(U,K,E){if(!K||!U.length)return U;let O=new Map;for(let G of U){let H={},F={};for(let[S]of Object.entries(K))F[V_(S)]={};for(let[S,R]of Object.entries(G)){let A=String(S),V=!1;for(let{joinModel:X,fieldName:q,joinModelRef:Q}of E)if(A===`_joined_${Q}_${q}`||A===`_Joined${s$(Q)}${s$(q)}`){F[V_(X)][D({model:X,field:q})]=R,V=!0;break}if(!V)H[S]=R}let N=H.id;if(!N)continue;if(!O.has(N)){let S={...H};for(let[R,A]of Object.entries(K))S[V_(R)]=A.relation==="one-to-one"?null:[];O.set(N,S)}let L=O.get(N);for(let[S,R]of Object.entries(K)){let A=R.relation==="one-to-one",V=R.limit??100,X=F[V_(S)],q=X&&Object.keys(X).length>0&&Object.values(X).some((Q)=>Q!==null&&Q!==void 0);if(A)L[V_(S)]=q?X:null;else{let Q=V_(S);if(Array.isArray(L[Q])&&q){if(L[Q].length>=V)continue;let l_=D({model:S,field:"id"}),r$=X[l_];if(r$){if(!L[Q].some((pW)=>pW[l_]===r$)&&L[Q].length<V)L[Q].push(X)}else if(L[Q].length<V)L[Q].push(X)}}}}let z=Array.from(O.values());for(let G of z)for(let[H,F]of Object.entries(K))if(F.relation!=="one-to-one"){let N=V_(H);if(Array.isArray(G[N])){let L=F.limit??100;if(G[N].length>L)G[N]=G[N].slice(0,L)}}return z}return{async create({data:U,model:K}){return await n$(U,k.insertInto(K).values(U),K,[])},async findOne({model:U,where:K,select:E,join:O}){let{and:z,or:G}=G_(U,K),H=k.selectFrom((R)=>{let A=R.selectFrom(U);if(z)A=A.where((V)=>V.and(z.map((X)=>X(V))));if(G)A=A.where((V)=>V.or(G.map((X)=>X(V))));if(E?.length&&E.length>0)A=A.select(E.map((V)=>D({model:U,field:V})));else A=A.selectAll();return A.as("primary")}).selectAll("primary");if(O)for(let[R,A]of Object.entries(O)){let[V,X]=R.includes(".")?R.split("."):[void 0,R];H=H.leftJoin(`${R} as join_${X}`,(q)=>q.onRef(`join_${X}.${A.on.to}`,"=",`primary.${A.on.from}`))}let{allSelectsStr:F,allSelects:N}=l$(O);H=H.select(N);let L=await H.execute();if(!L||!Array.isArray(L)||L.length===0)return null;let S=L[0];if(O)return i$(L,O,F)[0];return S},async findMany({model:U,where:K,limit:E,select:O,offset:z,sortBy:G,join:H}){let{and:F,or:N}=G_(U,K),L=k.selectFrom((V)=>{let X=V.selectFrom(U);if($?.type==="mssql"){if(z!==void 0){if(!G)X=X.orderBy(D({model:U,field:"id"}));X=X.offset(z).fetch(E||100)}else if(E!==void 0)X=X.top(E)}else{if(E!==void 0)X=X.limit(E);if(z!==void 0)X=X.offset(z)}if(G?.field)X=X.orderBy(`${D({model:U,field:G.field})}`,G.direction);if(F)X=X.where((q)=>q.and(F.map((Q)=>Q(q))));if(N)X=X.where((q)=>q.or(N.map((Q)=>Q(q))));if(O?.length&&O.length>0)X=X.select(O.map((q)=>D({model:U,field:q})));else X=X.selectAll();return X.as("primary")}).selectAll("primary");if(H)for(let[V,X]of Object.entries(H)){let[q,Q]=V.includes(".")?V.split("."):[void 0,V];L=L.leftJoin(`${V} as join_${Q}`,(l_)=>l_.onRef(`join_${Q}.${X.on.to}`,"=",`primary.${X.on.from}`))}let{allSelectsStr:S,allSelects:R}=l$(H);if(L=L.select(R),G?.field)L=L.orderBy(`${D({model:U,field:G.field})}`,G.direction);let A=await L.execute();if(!A)return[];if(H)return i$(A,H,S);return A},async update({model:U,where:K,update:E}){let{and:O,or:z}=G_(U,K),G=k.updateTable(U).set(E);if(O)G=G.where((H)=>H.and(O.map((F)=>F(H))));if(z)G=G.where((H)=>H.or(z.map((F)=>F(H))));return await n$(E,G,U,K)},async updateMany({model:U,where:K,update:E}){let{and:O,or:z}=G_(U,K),G=k.updateTable(U).set(E);if(O)G=G.where((F)=>F.and(O.map((N)=>N(F))));if(z)G=G.where((F)=>F.or(z.map((N)=>N(F))));let H=(await G.executeTakeFirst()).numUpdatedRows;return H>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:Number(H)},async count({model:U,where:K}){let{and:E,or:O}=G_(U,K),z=k.selectFrom(U).select(k.fn.count("id").as("count"));if(E)z=z.where((H)=>H.and(E.map((F)=>F(H))));if(O)z=z.where((H)=>H.or(O.map((F)=>F(H))));let G=await z.execute();if(typeof G[0].count==="number")return G[0].count;if(typeof G[0].count==="bigint")return Number(G[0].count);return parseInt(G[0].count)},async delete({model:U,where:K}){let{and:E,or:O}=G_(U,K),z=k.deleteFrom(U);if(E)z=z.where((G)=>G.and(E.map((H)=>H(G))));if(O)z=z.where((G)=>G.or(O.map((H)=>H(G))));await z.execute()},async deleteMany({model:U,where:K}){let{and:E,or:O}=G_(U,K),z=k.deleteFrom(U);if(E)z=z.where((H)=>H.and(E.map((F)=>F(H))));if(O)z=z.where((H)=>H.or(O.map((F)=>F(H))));let G=(await z.executeTakeFirst()).numDeletedRows;return G>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:Number(G)},async consumeOne({model:U,where:K}){let{and:E,or:O}=G_(U,K),z=(L)=>{if(E)L=L.where((S)=>S.and(E.map((R)=>R(S))));if(O)L=L.where((S)=>S.or(O.map((R)=>R(S))));return L},G=D({model:U,field:"id"}),H=async(L,S)=>{let R=S[G]??S.id;if(R===void 0||R===null)return null;let A=L.deleteFrom(U).where(`${U}.${G}`,"=",R);if($?.type==="mysql"){let V=await A.executeTakeFirst();return Number(V.numDeletedRows)>0?S:null}if($?.type==="mssql")return await A.outputAll("deleted").executeTakeFirst()??null;return await A.returningAll().executeTakeFirst()??null},F=async(L)=>{if($?.type==="mssql")return await L.outputAll("deleted").executeTakeFirst()??null;return await L.returningAll().executeTakeFirst()??null};if($?.type==="mysql"){let L=async(S)=>{let R=await z(S.selectFrom(U).selectAll().forUpdate()).limit(1).executeTakeFirst();if(!R)return null;return H(S,R)};return I?L(k):k.transaction().execute(L)}let N=z(k.selectFrom(U).select(`${U}.${G}`)).limit(1);return F(k.deleteFrom(U).where(`${U}.${G}`,"in",N))},options:$}}},Z=null;Z={config:{adapterId:"kysely",adapterName:"Kysely Adapter",usePlural:$?.usePlural,debugLogs:$?.debugLogs,supportsBooleans:$?.type==="sqlite"||$?.type==="mssql"||$?.type==="mysql"||!$?.type?!1:!0,supportsDates:$?.type==="sqlite"||$?.type==="mssql"||!$?.type?!1:!0,supportsJSON:$?.type==="postgres"?!0:!1,supportsArrays:!1,supportsUUIDs:$?.type==="postgres"?!0:!1,transaction:$?.transaction?(k)=>_.transaction().execute((I)=>{return k(t$({config:{...Z.config,transaction:!1},adapter:Y(I,!0)})(W))}):!1},adapter:Y(_)};let h=t$(Z);return(k)=>{return W=k,h(k)}};
|
|
6
|
+
export{cW as a,e9 as b,_0 as c};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// @bun
|