@prisma/studio-core 0.0.0-dev.202505062045 → 0.0.0-dev.202505062102
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-XS52QRY2.js → chunk-ACCGT3FH.js} +1 -1
- package/dist/data/pglite/index.cjs +1 -1
- package/dist/data/pglite/index.js +1 -1
- package/dist/data/postgres-core/index.cjs +1 -1
- package/dist/data/postgres-core/index.js +1 -1
- package/dist/ui/index.cjs +110 -110
- package/dist/ui/index.js +6 -6
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A as ei,B as g,C as B,a as E,b as z,c as Q,d as j,e as V,f as U,g as m,h as C,i as F,j as W,k as I,l as J,m as f,n as K,o as $,p as G,q as k,r as Y,s as H,t as w,u as T,v,w as X,x as Z,y as ii,z as ti}from"./chunk-P72NBTYE.js";var si={bool:{group:"boolean"},boolean:{group:"boolean"},bytea:{group:"string"},char:{group:"string"},citext:{group:"string"},date:{group:"datetime"},interval:{group:"string"},name:{group:"string"},varchar:{group:"string"},text:{group:"string"},time:{group:"time"},timestamp:{group:"datetime"},timestamptz:{group:"datetime"},"timestamp without time zone":{group:"datetime"},"timestamp with time zone":{group:"datetime"},timetz:{group:"time"},"time without time zone":{group:"time"},"time with time zone":{group:"datetime"},uuid:{group:"string"},int2:{group:"numeric"},int4:{group:"numeric"},int8:{group:"numeric"},smallint:{group:"numeric"},integer:{group:"numeric"},bigint:{group:"numeric"},decimal:{group:"numeric"},numeric:{group:"numeric"},real:{group:"numeric"},float4:{group:"numeric"},float8:{group:"numeric"},"double precision":{group:"numeric"},json:{group:"json"},jsonb:{group:"json"}};var P=class e{#i;constructor(i){this.#i=m(i)}get expressionType(){}get isRawBuilder(){return!0}as(i){return new q(this,i)}$castTo(){return new e({...this.#i})}$notNull(){return new e(this.#i)}withPlugin(i){return new e({...this.#i,plugins:this.#i.plugins!==void 0?m([...this.#i.plugins,i]):m([i])})}toOperationNode(){return this.#e(this.#t())}compile(i){return this.#s(this.#t(i))}async execute(i){let t=this.#t(i);return t.executeQuery(this.#s(t),this.#i.queryId)}#t(i){let t=i!==void 0?i.getExecutor():X;return this.#i.plugins!==void 0?t.withPlugins(this.#i.plugins):t}#e(i){return i.transformQuery(this.#i.rawNode,this.#i.queryId)}#s(i){return i.compileQuery(this.#e(i),this.#i.queryId)}};function N(e){return new P(e)}var q=class{#i;#t;constructor(i,t){this.#i=i,this.#t=t}get expression(){return this.#i}get alias(){return this.#t}get rawBuilder(){return this.#i}toOperationNode(){return W.create(this.#i.toOperationNode(),I(this.#t)?this.#t.toOperationNode():C.create(this.#t))}};var o=Object.assign((e,...i)=>N({queryId:v(),rawNode:f.create(e,i?.map(ri)??[])}),{ref(e){return N({queryId:v(),rawNode:f.createWithChild($(e))})},val(e){return N({queryId:v(),rawNode:f.createWithChild(k(e))})},value(e){return this.val(e)},table(e){return N({queryId:v(),rawNode:f.createWithChild(ii(e))})},id(...e){let i=new Array(e.length+1).fill(".");return i[0]="",i[i.length-1]="",N({queryId:v(),rawNode:f.create(i,e.map(C.create))})},lit(e){return N({queryId:v(),rawNode:f.createWithChild(G.createImmediate(e))})},literal(e){return this.lit(e)},raw(e){return N({queryId:v(),rawNode:f.createWithSql(e)})},join(e,i=o`, `){let t=new Array(Math.max(2*e.length-1,0)),s=i.toOperationNode();for(let r=0;r<e.length;++r)t[2*r]=ri(e[r]),r!==e.length-1&&(t[2*r+1]=s);return N({queryId:v(),rawNode:f.createWithChildren(t)})}});function ri(e){return I(e)?e.toOperationNode():k(e)}var O=class{nodeStack=[];get parentNode(){return this.nodeStack[this.nodeStack.length-2]}#i=m({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=i=>{this.nodeStack.push(i),this.#i[i.kind](i),this.nodeStack.pop()}};var Ni=/'/g,D=class extends O{#i="";#t=[];get numParameters(){return this.#t.length}compileQuery(i,t){return this.#i="",this.#t=[],this.nodeStack.splice(0,this.nodeStack.length),this.visitNode(i),m({query:i,queryId:t,sql:this.getSql(),parameters:[...this.#t]})}getSql(){return this.#i}visitSelectQuery(i){let t=this.parentNode!==void 0&&!Y.is(this.parentNode)&&!H.is(this.parentNode)&&!F.is(this.parentNode)&&!ti.is(this.parentNode)&&!Z.is(this.parentNode);this.parentNode===void 0&&i.explain&&(this.visitNode(i.explain),this.append(" ")),t&&this.append("("),i.with&&(this.visitNode(i.with),this.append(" ")),this.append("select"),i.distinctOn&&(this.append(" "),this.compileDistinctOn(i.distinctOn)),i.frontModifiers?.length&&(this.append(" "),this.compileList(i.frontModifiers," ")),i.top&&(this.append(" "),this.visitNode(i.top)),i.selections&&(this.append(" "),this.compileList(i.selections)),i.from&&(this.append(" "),this.visitNode(i.from)),i.joins&&(this.append(" "),this.compileList(i.joins," ")),i.where&&(this.append(" "),this.visitNode(i.where)),i.groupBy&&(this.append(" "),this.visitNode(i.groupBy)),i.having&&(this.append(" "),this.visitNode(i.having)),i.setOperations&&(this.append(" "),this.compileList(i.setOperations," ")),i.orderBy&&(this.append(" "),this.visitNode(i.orderBy)),i.limit&&(this.append(" "),this.visitNode(i.limit)),i.offset&&(this.append(" "),this.visitNode(i.offset)),i.fetch&&(this.append(" "),this.visitNode(i.fetch)),i.endModifiers?.length&&(this.append(" "),this.compileList(this.sortSelectModifiers([...i.endModifiers])," ")),t&&this.append(")")}visitFrom(i){this.append("from "),this.compileList(i.froms)}visitSelection(i){this.visitNode(i.selection)}visitColumn(i){this.visitNode(i.column)}compileDistinctOn(i){this.append("distinct on ("),this.compileList(i),this.append(")")}compileList(i,t=", "){let s=i.length-1;for(let r=0;r<=s;r++)this.visitNode(i[r]),r<s&&this.append(t)}visitWhere(i){this.append("where "),this.visitNode(i.where)}visitHaving(i){this.append("having "),this.visitNode(i.having)}visitInsertQuery(i){let t=this.nodeStack.find(T.is),s=t!==i;!s&&i.explain&&(this.visitNode(i.explain),this.append(" ")),s&&!w.is(t)&&this.append("("),i.with&&(this.visitNode(i.with),this.append(" ")),this.append(i.replace?"replace":"insert"),i.ignore&&(K("`InsertQueryNode.ignore` is deprecated. Use `InsertQueryNode.orAction` instead."),this.append(" ignore")),i.orAction&&(this.append(" "),this.visitNode(i.orAction)),i.top&&(this.append(" "),this.visitNode(i.top)),i.into&&(this.append(" into "),this.visitNode(i.into)),i.columns&&(this.append(" ("),this.compileList(i.columns),this.append(")")),i.output&&(this.append(" "),this.visitNode(i.output)),i.values&&(this.append(" "),this.visitNode(i.values)),i.defaultValues&&(this.append(" "),this.append("default values")),i.onConflict&&(this.append(" "),this.visitNode(i.onConflict)),i.onDuplicateKey&&(this.append(" "),this.visitNode(i.onDuplicateKey)),i.returning&&(this.append(" "),this.visitNode(i.returning)),s&&!w.is(t)&&this.append(")"),i.endModifiers?.length&&(this.append(" "),this.compileList(i.endModifiers," "))}visitValues(i){this.append("values "),this.compileList(i.values)}visitDeleteQuery(i){let t=this.nodeStack.find(T.is)!==i;!t&&i.explain&&(this.visitNode(i.explain),this.append(" ")),t&&this.append("("),i.with&&(this.visitNode(i.with),this.append(" ")),this.append("delete "),i.top&&(this.visitNode(i.top),this.append(" ")),this.visitNode(i.from),i.output&&(this.append(" "),this.visitNode(i.output)),i.using&&(this.append(" "),this.visitNode(i.using)),i.joins&&(this.append(" "),this.compileList(i.joins," ")),i.where&&(this.append(" "),this.visitNode(i.where)),i.orderBy&&(this.append(" "),this.visitNode(i.orderBy)),i.limit&&(this.append(" "),this.visitNode(i.limit)),i.returning&&(this.append(" "),this.visitNode(i.returning)),t&&this.append(")"),i.endModifiers?.length&&(this.append(" "),this.compileList(i.endModifiers," "))}visitReturning(i){this.append("returning "),this.compileList(i.selections)}visitAlias(i){this.visitNode(i.node),this.append(" as "),this.visitNode(i.alias)}visitReference(i){i.table&&(this.visitNode(i.table),this.append(".")),this.visitNode(i.column)}visitSelectAll(i){this.append("*")}visitIdentifier(i){this.append(this.getLeftIdentifierWrapper()),this.compileUnwrappedIdentifier(i),this.append(this.getRightIdentifierWrapper())}compileUnwrappedIdentifier(i){if(!E(i.name))throw new Error("a non-string identifier was passed to compileUnwrappedIdentifier.");this.append(this.sanitizeIdentifier(i.name))}visitAnd(i){this.visitNode(i.left),this.append(" and "),this.visitNode(i.right)}visitOr(i){this.visitNode(i.left),this.append(" or "),this.visitNode(i.right)}visitValue(i){i.immediate?this.appendImmediateValue(i.value):this.appendValue(i.value)}visitValueList(i){this.append("("),this.compileList(i.values),this.append(")")}visitTuple(i){this.append("("),this.compileList(i.values),this.append(")")}visitPrimitiveValueList(i){this.append("(");let{values:t}=i;for(let s=0;s<t.length;++s)this.appendValue(t[s]),s!==t.length-1&&this.append(", ");this.append(")")}visitParens(i){this.append("("),this.visitNode(i.node),this.append(")")}visitJoin(i){this.append(yi[i.joinType]),this.append(" "),this.visitNode(i.table),i.on&&(this.append(" "),this.visitNode(i.on))}visitOn(i){this.append("on "),this.visitNode(i.on)}visitRaw(i){let{sqlFragments:t,parameters:s}=i;for(let r=0;r<t.length;++r)this.append(t[r]),s.length>r&&this.visitNode(s[r])}visitOperator(i){this.append(i.operator)}visitTable(i){this.visitNode(i.table)}visitSchemableIdentifier(i){i.schema&&(this.visitNode(i.schema),this.append(".")),this.visitNode(i.identifier)}visitCreateTable(i){this.append("create "),i.frontModifiers&&i.frontModifiers.length>0&&(this.compileList(i.frontModifiers," "),this.append(" ")),i.temporary&&this.append("temporary "),this.append("table "),i.ifNotExists&&this.append("if not exists "),this.visitNode(i.table),i.selectQuery?(this.append(" as "),this.visitNode(i.selectQuery)):(this.append(" ("),this.compileList([...i.columns,...i.constraints??[]]),this.append(")"),i.onCommit&&(this.append(" on commit "),this.append(i.onCommit)),i.endModifiers&&i.endModifiers.length>0&&(this.append(" "),this.compileList(i.endModifiers," ")))}visitColumnDefinition(i){i.ifNotExists&&this.append("if not exists "),this.visitNode(i.column),this.append(" "),this.visitNode(i.dataType),i.unsigned&&this.append(" unsigned"),i.frontModifiers&&i.frontModifiers.length>0&&(this.append(" "),this.compileList(i.frontModifiers," ")),i.generated&&(this.append(" "),this.visitNode(i.generated)),i.identity&&this.append(" identity"),i.defaultTo&&(this.append(" "),this.visitNode(i.defaultTo)),i.notNull&&this.append(" not null"),i.unique&&this.append(" unique"),i.nullsNotDistinct&&this.append(" nulls not distinct"),i.primaryKey&&this.append(" primary key"),i.autoIncrement&&(this.append(" "),this.append(this.getAutoIncrement())),i.references&&(this.append(" "),this.visitNode(i.references)),i.check&&(this.append(" "),this.visitNode(i.check)),i.endModifiers&&i.endModifiers.length>0&&(this.append(" "),this.compileList(i.endModifiers," "))}getAutoIncrement(){return"auto_increment"}visitReferences(i){this.append("references "),this.visitNode(i.table),this.append(" ("),this.compileList(i.columns),this.append(")"),i.onDelete&&(this.append(" on delete "),this.append(i.onDelete)),i.onUpdate&&(this.append(" on update "),this.append(i.onUpdate))}visitDropTable(i){this.append("drop table "),i.ifExists&&this.append("if exists "),this.visitNode(i.table),i.cascade&&this.append(" cascade")}visitDataType(i){this.append(i.dataType)}visitOrderBy(i){this.append("order by "),this.compileList(i.items)}visitOrderByItem(i){this.visitNode(i.orderBy),i.collation&&(this.append(" "),this.visitNode(i.collation)),i.direction&&(this.append(" "),this.visitNode(i.direction)),i.nulls&&(this.append(" nulls "),this.append(i.nulls))}visitGroupBy(i){this.append("group by "),this.compileList(i.items)}visitGroupByItem(i){this.visitNode(i.groupBy)}visitUpdateQuery(i){let t=this.nodeStack.find(T.is),s=t!==i;if(!s&&i.explain&&(this.visitNode(i.explain),this.append(" ")),s&&!w.is(t)&&this.append("("),i.with&&(this.visitNode(i.with),this.append(" ")),this.append("update "),i.top&&(this.visitNode(i.top),this.append(" ")),i.table&&(this.visitNode(i.table),this.append(" ")),this.append("set "),i.updates&&this.compileList(i.updates),i.output&&(this.append(" "),this.visitNode(i.output)),i.from&&(this.append(" "),this.visitNode(i.from)),i.joins){if(!i.from)throw new Error("Joins in an update query are only supported as a part of a PostgreSQL 'update set from join' query. If you want to create a MySQL 'update join set' query, see https://kysely.dev/docs/examples/update/my-sql-joins");this.append(" "),this.compileList(i.joins," ")}i.where&&(this.append(" "),this.visitNode(i.where)),i.orderBy&&(this.append(" "),this.visitNode(i.orderBy)),i.limit&&(this.append(" "),this.visitNode(i.limit)),i.returning&&(this.append(" "),this.visitNode(i.returning)),s&&!w.is(t)&&this.append(")"),i.endModifiers?.length&&(this.append(" "),this.compileList(i.endModifiers," "))}visitColumnUpdate(i){this.visitNode(i.column),this.append(" = "),this.visitNode(i.value)}visitLimit(i){this.append("limit "),this.visitNode(i.limit)}visitOffset(i){this.append("offset "),this.visitNode(i.offset)}visitOnConflict(i){this.append("on conflict"),i.columns?(this.append(" ("),this.compileList(i.columns),this.append(")")):i.constraint?(this.append(" on constraint "),this.visitNode(i.constraint)):i.indexExpression&&(this.append(" ("),this.visitNode(i.indexExpression),this.append(")")),i.indexWhere&&(this.append(" "),this.visitNode(i.indexWhere)),i.doNothing===!0?this.append(" do nothing"):i.updates&&(this.append(" do update set "),this.compileList(i.updates),i.updateWhere&&(this.append(" "),this.visitNode(i.updateWhere)))}visitOnDuplicateKey(i){this.append("on duplicate key update "),this.compileList(i.updates)}visitCreateIndex(i){this.append("create "),i.unique&&this.append("unique "),this.append("index "),i.ifNotExists&&this.append("if not exists "),this.visitNode(i.name),i.table&&(this.append(" on "),this.visitNode(i.table)),i.using&&(this.append(" using "),this.visitNode(i.using)),i.columns&&(this.append(" ("),this.compileList(i.columns),this.append(")")),i.nullsNotDistinct&&this.append(" nulls not distinct"),i.where&&(this.append(" "),this.visitNode(i.where))}visitDropIndex(i){this.append("drop index "),i.ifExists&&this.append("if exists "),this.visitNode(i.name),i.table&&(this.append(" on "),this.visitNode(i.table)),i.cascade&&this.append(" cascade")}visitCreateSchema(i){this.append("create schema "),i.ifNotExists&&this.append("if not exists "),this.visitNode(i.schema)}visitDropSchema(i){this.append("drop schema "),i.ifExists&&this.append("if exists "),this.visitNode(i.schema),i.cascade&&this.append(" cascade")}visitPrimaryKeyConstraint(i){i.name&&(this.append("constraint "),this.visitNode(i.name),this.append(" ")),this.append("primary key ("),this.compileList(i.columns),this.append(")"),this.buildDeferrable(i)}buildDeferrable(i){i.deferrable!==void 0&&(i.deferrable?this.append(" deferrable"):this.append(" not deferrable")),i.initiallyDeferred!==void 0&&(i.initiallyDeferred?this.append(" initially deferred"):this.append(" initially immediate"))}visitUniqueConstraint(i){i.name&&(this.append("constraint "),this.visitNode(i.name),this.append(" ")),this.append("unique"),i.nullsNotDistinct&&this.append(" nulls not distinct"),this.append(" ("),this.compileList(i.columns),this.append(")"),this.buildDeferrable(i)}visitCheckConstraint(i){i.name&&(this.append("constraint "),this.visitNode(i.name),this.append(" ")),this.append("check ("),this.visitNode(i.expression),this.append(")")}visitForeignKeyConstraint(i){i.name&&(this.append("constraint "),this.visitNode(i.name),this.append(" ")),this.append("foreign key ("),this.compileList(i.columns),this.append(") "),this.visitNode(i.references),i.onDelete&&(this.append(" on delete "),this.append(i.onDelete)),i.onUpdate&&(this.append(" on update "),this.append(i.onUpdate)),this.buildDeferrable(i)}visitList(i){this.compileList(i.items)}visitWith(i){this.append("with "),i.recursive&&this.append("recursive "),this.compileList(i.expressions)}visitCommonTableExpression(i){this.visitNode(i.name),this.append(" as "),Q(i.materialized)&&(i.materialized||this.append("not "),this.append("materialized ")),this.visitNode(i.expression)}visitCommonTableExpressionName(i){this.visitNode(i.table),i.columns&&(this.append("("),this.compileList(i.columns),this.append(")"))}visitAlterTable(i){this.append("alter table "),this.visitNode(i.table),this.append(" "),i.renameTo&&(this.append("rename to "),this.visitNode(i.renameTo)),i.setSchema&&(this.append("set schema "),this.visitNode(i.setSchema)),i.addConstraint&&this.visitNode(i.addConstraint),i.dropConstraint&&this.visitNode(i.dropConstraint),i.renameConstraint&&this.visitNode(i.renameConstraint),i.columnAlterations&&this.compileColumnAlterations(i.columnAlterations),i.addIndex&&this.visitNode(i.addIndex),i.dropIndex&&this.visitNode(i.dropIndex)}visitAddColumn(i){this.append("add column "),this.visitNode(i.column)}visitRenameColumn(i){this.append("rename column "),this.visitNode(i.column),this.append(" to "),this.visitNode(i.renameTo)}visitDropColumn(i){this.append("drop column "),this.visitNode(i.column)}visitAlterColumn(i){this.append("alter column "),this.visitNode(i.column),this.append(" "),i.dataType&&(this.announcesNewColumnDataType()&&this.append("type "),this.visitNode(i.dataType),i.dataTypeExpression&&(this.append("using "),this.visitNode(i.dataTypeExpression))),i.setDefault&&(this.append("set default "),this.visitNode(i.setDefault)),i.dropDefault&&this.append("drop default"),i.setNotNull&&this.append("set not null"),i.dropNotNull&&this.append("drop not null")}visitModifyColumn(i){this.append("modify column "),this.visitNode(i.column)}visitAddConstraint(i){this.append("add "),this.visitNode(i.constraint)}visitDropConstraint(i){this.append("drop constraint "),i.ifExists&&this.append("if exists "),this.visitNode(i.constraintName),i.modifier==="cascade"?this.append(" cascade"):i.modifier==="restrict"&&this.append(" restrict")}visitRenameConstraint(i){this.append("rename constraint "),this.visitNode(i.oldName),this.append(" to "),this.visitNode(i.newName)}visitSetOperation(i){this.append(i.operator),this.append(" "),i.all&&this.append("all "),this.visitNode(i.expression)}visitCreateView(i){this.append("create "),i.orReplace&&this.append("or replace "),i.materialized&&this.append("materialized "),i.temporary&&this.append("temporary "),this.append("view "),i.ifNotExists&&this.append("if not exists "),this.visitNode(i.name),this.append(" "),i.columns&&(this.append("("),this.compileList(i.columns),this.append(") ")),i.as&&(this.append("as "),this.visitNode(i.as))}visitRefreshMaterializedView(i){this.append("refresh materialized view "),i.concurrently&&this.append("concurrently "),this.visitNode(i.name),i.withNoData?this.append(" with no data"):this.append(" with data")}visitDropView(i){this.append("drop "),i.materialized&&this.append("materialized "),this.append("view "),i.ifExists&&this.append("if exists "),this.visitNode(i.name),i.cascade&&this.append(" cascade")}visitGenerated(i){this.append("generated "),i.always&&this.append("always "),i.byDefault&&this.append("by default "),this.append("as "),i.identity&&this.append("identity"),i.expression&&(this.append("("),this.visitNode(i.expression),this.append(")")),i.stored&&this.append(" stored")}visitDefaultValue(i){this.append("default "),this.visitNode(i.defaultValue)}visitSelectModifier(i){i.rawModifier?this.visitNode(i.rawModifier):this.append(gi[i.modifier]),i.of&&(this.append(" of "),this.compileList(i.of,", "))}visitCreateType(i){this.append("create type "),this.visitNode(i.name),i.enum&&(this.append(" as enum "),this.visitNode(i.enum))}visitDropType(i){this.append("drop type "),i.ifExists&&this.append("if exists "),this.visitNode(i.name)}visitExplain(i){this.append("explain"),(i.options||i.format)&&(this.append(" "),this.append(this.getLeftExplainOptionsWrapper()),i.options&&(this.visitNode(i.options),i.format&&this.append(this.getExplainOptionsDelimiter())),i.format&&(this.append("format"),this.append(this.getExplainOptionAssignment()),this.append(i.format)),this.append(this.getRightExplainOptionsWrapper()))}visitDefaultInsertValue(i){this.append("default")}visitAggregateFunction(i){this.append(i.func),this.append("("),i.distinct&&this.append("distinct "),this.compileList(i.aggregated),i.orderBy&&(this.append(" "),this.visitNode(i.orderBy)),this.append(")"),i.withinGroup&&(this.append(" within group ("),this.visitNode(i.withinGroup),this.append(")")),i.filter&&(this.append(" filter("),this.visitNode(i.filter),this.append(")")),i.over&&(this.append(" "),this.visitNode(i.over))}visitOver(i){this.append("over("),i.partitionBy&&(this.visitNode(i.partitionBy),i.orderBy&&this.append(" ")),i.orderBy&&this.visitNode(i.orderBy),this.append(")")}visitPartitionBy(i){this.append("partition by "),this.compileList(i.items)}visitPartitionByItem(i){this.visitNode(i.partitionBy)}visitBinaryOperation(i){this.visitNode(i.leftOperand),this.append(" "),this.visitNode(i.operator),this.append(" "),this.visitNode(i.rightOperand)}visitUnaryOperation(i){this.visitNode(i.operator),this.isMinusOperator(i.operator)||this.append(" "),this.visitNode(i.operand)}isMinusOperator(i){return J.is(i)&&i.operator==="-"}visitUsing(i){this.append("using "),this.compileList(i.tables)}visitFunction(i){this.append(i.func),this.append("("),this.compileList(i.arguments),this.append(")")}visitCase(i){this.append("case"),i.value&&(this.append(" "),this.visitNode(i.value)),i.when&&(this.append(" "),this.compileList(i.when," ")),i.else&&(this.append(" else "),this.visitNode(i.else)),this.append(" end"),i.isStatement&&this.append(" case")}visitWhen(i){this.append("when "),this.visitNode(i.condition),i.result&&(this.append(" then "),this.visitNode(i.result))}visitJSONReference(i){this.visitNode(i.reference),this.visitNode(i.traversal)}visitJSONPath(i){i.inOperator&&this.visitNode(i.inOperator),this.append("'$");for(let t of i.pathLegs)this.visitNode(t);this.append("'")}visitJSONPathLeg(i){let t=i.type==="ArrayLocation";this.append(t?"[":"."),this.append(String(i.value)),t&&this.append("]")}visitJSONOperatorChain(i){for(let t=0,s=i.values.length;t<s;t++)t===s-1?this.visitNode(i.operator):this.append("->"),this.visitNode(i.values[t])}visitMergeQuery(i){i.with&&(this.visitNode(i.with),this.append(" ")),this.append("merge "),i.top&&(this.visitNode(i.top),this.append(" ")),this.append("into "),this.visitNode(i.into),i.using&&(this.append(" "),this.visitNode(i.using)),i.whens&&(this.append(" "),this.compileList(i.whens," ")),i.returning&&(this.append(" "),this.visitNode(i.returning)),i.output&&(this.append(" "),this.visitNode(i.output)),i.endModifiers?.length&&(this.append(" "),this.compileList(i.endModifiers," "))}visitMatched(i){i.not&&this.append("not "),this.append("matched"),i.bySource&&this.append(" by source")}visitAddIndex(i){this.append("add "),i.unique&&this.append("unique "),this.append("index "),this.visitNode(i.name),i.columns&&(this.append(" ("),this.compileList(i.columns),this.append(")")),i.using&&(this.append(" using "),this.visitNode(i.using))}visitCast(i){this.append("cast("),this.visitNode(i.expression),this.append(" as "),this.visitNode(i.dataType),this.append(")")}visitFetch(i){this.append("fetch next "),this.visitNode(i.rowCount),this.append(` rows ${i.modifier}`)}visitOutput(i){this.append("output "),this.compileList(i.selections)}visitTop(i){this.append(`top(${i.expression})`),i.modifiers&&this.append(` ${i.modifiers}`)}visitOrAction(i){this.append(i.action)}visitCollate(i){this.append("collate "),this.visitNode(i.collation)}append(i){this.#i+=i}appendValue(i){this.addParameter(i),this.append(this.getCurrentParameterPlaceholder())}getLeftIdentifierWrapper(){return'"'}getRightIdentifierWrapper(){return'"'}getCurrentParameterPlaceholder(){return"$"+this.numParameters}getLeftExplainOptionsWrapper(){return"("}getExplainOptionAssignment(){return" "}getExplainOptionsDelimiter(){return", "}getRightExplainOptionsWrapper(){return")"}sanitizeIdentifier(i){let t=this.getLeftIdentifierWrapper(),s=this.getRightIdentifierWrapper(),r="";for(let a of i)r+=a,a===t?r+=t:a===s&&(r+=s);return r}sanitizeStringLiteral(i){return i.replace(Ni,"''")}addParameter(i){this.#t.push(i)}appendImmediateValue(i){if(E(i))this.appendStringLiteral(i);else if(z(i)||Q(i))this.append(i.toString());else if(j(i))this.append("null");else if(V(i))this.appendImmediateValue(i.toISOString());else if(U(i))this.appendImmediateValue(i.toString());else throw new Error(`invalid immediate value ${i}`)}appendStringLiteral(i){this.append("'"),this.append(this.sanitizeStringLiteral(i)),this.append("'")}sortSelectModifiers(i){return i.sort((t,s)=>t.modifier&&s.modifier?ai[t.modifier]-ai[s.modifier]:1),m(i)}compileColumnAlterations(i){this.compileList(i)}announcesNewColumnDataType(){return!0}},gi=m({ForKeyShare:"for key share",ForNoKeyUpdate:"for no key update",ForUpdate:"for update",ForShare:"for share",NoWait:"nowait",SkipLocked:"skip locked",Distinct:"distinct"}),ai=m({ForKeyShare:1,ForNoKeyUpdate:1,ForUpdate:1,ForShare:1,NoWait:2,SkipLocked:2,Distinct:0}),yi=m({InnerJoin:"inner join",LeftJoin:"left join",RightJoin:"right join",FullJoin:"full join",CrossJoin:"cross join",LateralInnerJoin:"inner join lateral",LateralLeftJoin:"left join lateral",LateralCrossJoin:"cross join lateral",OuterApply:"outer apply",CrossApply:"cross apply",Using:"using"});var S=class{get supportsCreateIfNotExists(){return!0}get supportsTransactionalDdl(){return!1}get supportsReturning(){return!1}get supportsOutput(){return!1}};var bi=/"/g,L=class extends D{sanitizeIdentifier(i){return i.replace(bi,'""')}};var xi=BigInt("3853314791062309107"),A=class extends S{get supportsTransactionalDdl(){return!0}get supportsReturning(){return!0}async acquireMigrationLock(i,t){await o`select pg_advisory_xact_lock(${o.lit(xi)})`.execute(i)}async releaseMigrationLock(i,t){}};function y(e){return ei({...e,Adapter:A,QueryCompiler:L})}function ni(e,i){let{table:t,rows:s}=e,{name:r,schema:a,columns:n}=t,p=y(i),h=Object.keys(n),l={[h[0]]:o`default`};return g(p.withSchema(a).insertInto(r).values(s.map(u=>Object.keys(u).length===0?l:u)).returning(h).returning(u=>u.cast("ctid","text").as("ctid")))}function pi(e,i){let{pageIndex:t,pageSize:s,sortOrder:r,table:{name:a,schema:n,columns:p}}=e,h=y(i),l=Object.keys(p),u=h.withSchema(n).selectFrom(a).select(d=>d.cast(d.fn.coalesce(d.fn.countAll(),o.lit(0)),"text").as("oid"));return g(h.with("count",()=>u).withSchema(n).selectFrom([a,"count"]).select(o.ref("count.oid").$castTo().as("oid")).select(d=>d.cast("ctid","text").as("ctid")).select(l).$call(d=>r.reduce((b,x)=>b.orderBy(x.column,x.direction),d)).limit(s).offset(o.lit(BigInt(t)*BigInt(s))))}function It(){return[{created_at:new Date("2025-01-26T21:56:12.345Z"),ctid:"(0,1)",deleted_at:null,id:1,name:"John Doe",oid:"2",role:"admin"},{created_at:new Date("2025-01-26T20:56:12.345Z"),ctid:"(0,2)",deleted_at:null,id:2,name:"Jane Doe",oid:"2",role:"poweruser"}]}function oi(e,i){let{changes:t,row:s,table:{columns:r,name:a,schema:n}}=e,p=y(i),h=Object.keys(r);return g(p.withSchema(n).updateTable(a).set(t).$call(B([s],r)).returning(h).returning(l=>[l.cast("ctid","text").as("ctid"),l.cast(l.fn("floor",[l(l.fn("extract",[o`epoch from now()`]),"*",1e6)]),"text").as("__ps_updated_at__")]))}function hi(e,i){let{rows:t,table:{columns:s,name:r,schema:a}}=e,n=y(i);return g(n.withSchema(a).deleteFrom(r).$call(B(t,s)))}function di(e){return o`(select coalesce(json_agg(agg), '[]') from ${e} as agg)`}var wi="r",Ci="v",Ii=[wi,Ci];function li(e){return g(y(e).selectFrom("pg_catalog.pg_class as cls").innerJoin("pg_catalog.pg_namespace as ns","cls.relnamespace","ns.oid").$call(Ti).where("cls.relkind","in",Ii).select(i=>["ns.nspname as schema","cls.relname as name",di(i.selectFrom("pg_catalog.pg_attribute as att").innerJoin("pg_catalog.pg_type as typ","typ.oid","att.atttypid").innerJoin("pg_catalog.pg_namespace as tns","tns.oid","typ.typnamespace").leftJoin("pg_catalog.pg_constraint as con",t=>t.on("con.contype","=","p").onRef("con.conrelid","=","cls.oid").on(s=>s("att.attnum","=",s.fn.any("con.conkey")))).whereRef("att.attrelid","=","cls.oid").where("att.attnum",">=",0).where("att.attisdropped","!=",!0).where("att.attgenerated","=","").select(["att.attname as name","typ.typname as datatype","tns.nspname as datatype_schema"]).select(t=>[t("con.conkey","is not",null).$castTo().as("pk"),t("att.attgenerated","!=","").$castTo().as("computed"),t("att.attnotnull","!=",!0).$castTo().as("nullable"),t.fn.coalesce(t.selectFrom("pg_catalog.pg_enum as enm").whereRef("enm.enumtypid","=","typ.oid").select(s=>s.fn.jsonAgg(s.ref("enm.enumlabel")).as("o")),o`'[]'`).as("options")])).as("columns")]))}function ui(){return[{schema:"public",name:"users",columns:[{name:"id",datatype:"bigint",datatype_schema:"public",pk:!0,computed:!1,options:[],nullable:!0},{name:"name",datatype:"varchar",datatype_schema:"public",pk:!1,computed:!1,options:[],nullable:!0},{name:"role",datatype:"role",datatype_schema:"public",pk:!1,computed:!1,options:["admin","maintainer","member"],nullable:!0},{name:"created_at",datatype:"timestamptz",datatype_schema:"public",pk:!1,computed:!1,options:[],nullable:!0},{name:"deleted_at",datatype:"timestamptz",datatype_schema:"public",pk:!1,computed:!1,options:[],nullable:!0}]}]}function ci(){let e=y();return g(e.selectNoFrom(e.fn("current_setting",[o.lit("timezone")]).as("timezone")))}function mi(){return[{timezone:"UTC"}]}function Ti(e){return e.where("ns.nspname","!~","^pg_").where("ns.nspname","!=","information_schema")}function Mt(e){let{executor:i,...t}=e;return{defaultSchema:"public",async introspect(s){try{let r=li(t),a=ci(),[[n,p],[h,l]]=await Promise.all([i.execute(r,s),i.execute(a,s)]),u=n||h;if(u)return[u];let[d]=l;return d?[null,fi(p,d.timezone)]:[new Error("Timezone not found")]}catch(r){return[r]}},async query(s,r){try{let a=pi(s,t),[n,p]=await i.execute(a,r);return n?[n]:[null,{filteredRowCount:p[0]?.oid||"0",rows:p}]}catch(a){return[a]}},async insert(s,r){try{let a=ni(s,t),[n,p]=await i.execute(a,r);return n?[n]:[null,{rows:p}]}catch(a){return[a]}},async update(s,r){try{let a=oi(s,t),[n,p]=await i.execute(a,r);if(n)return[n];let[h]=p;return h?[null,{row:h}]:[new Error("Update failed")]}catch(a){return[a]}},async delete(s,r){try{let a=hi(s,t),[n]=await i.execute(a,r);return n?[n]:[null,s]}catch(a){return[a]}}}}function fi(e,i){return e.reduce((t,s)=>{let{schemas:r}=t,{columns:a,name:n,schema:p}=s,h=a.reduce((l,u)=>{let{datatype:d,datatype_schema:b,name:x,options:M,nullable:vi}=u,_=d.startsWith("_"),R=_?d.slice(1):d;return{...l,[x]:{datatype:{...si[R]||{group:M.length>0?"enum":"raw"},isArray:_,isNative:b==="pg_catalog",name:_?`${R}[]`:R,options:M,schema:b},isComputed:u.computed,isInPrimaryKey:u.pk,name:x,nullable:vi,schema:p,table:n}}},{});return(r[p]||={tables:{}}).tables[n]={columns:h,name:n,schema:p},t},{schemas:{public:{tables:{}}},timezone:i})}function zt(){let e=ui(),[{timezone:i}]=mi();return fi(e,i)}export{ni as a,pi as b,It as c,oi as d,hi as e,li as f,ui as g,ci as h,mi as i,Mt as j,zt as k};
|
|
1
|
+
import{A as ei,B as g,C as B,a as E,b as z,c as Q,d as j,e as V,f as U,g as m,h as C,i as F,j as W,k as I,l as J,m as f,n as K,o as $,p as G,q as k,r as Y,s as H,t as w,u as T,v,w as X,x as Z,y as ii,z as ti}from"./chunk-P72NBTYE.js";var si={bool:{group:"boolean"},boolean:{group:"boolean"},bytea:{group:"string"},char:{group:"string"},citext:{group:"string"},date:{group:"datetime"},interval:{group:"string"},name:{group:"string"},varchar:{group:"string"},text:{group:"string"},time:{group:"time"},timestamp:{group:"datetime"},timestamptz:{group:"datetime"},"timestamp without time zone":{group:"datetime"},"timestamp with time zone":{group:"datetime"},timetz:{group:"time"},"time without time zone":{group:"time"},"time with time zone":{group:"datetime"},uuid:{group:"string"},int2:{group:"numeric"},int4:{group:"numeric"},int8:{group:"numeric"},smallint:{group:"numeric"},integer:{group:"numeric"},bigint:{group:"numeric"},decimal:{group:"numeric"},numeric:{group:"numeric"},real:{group:"numeric"},float4:{group:"numeric"},float8:{group:"numeric"},"double precision":{group:"numeric"},json:{group:"json"},jsonb:{group:"json"}};var P=class e{#i;constructor(i){this.#i=m(i)}get expressionType(){}get isRawBuilder(){return!0}as(i){return new q(this,i)}$castTo(){return new e({...this.#i})}$notNull(){return new e(this.#i)}withPlugin(i){return new e({...this.#i,plugins:this.#i.plugins!==void 0?m([...this.#i.plugins,i]):m([i])})}toOperationNode(){return this.#e(this.#t())}compile(i){return this.#s(this.#t(i))}async execute(i){let t=this.#t(i);return t.executeQuery(this.#s(t),this.#i.queryId)}#t(i){let t=i!==void 0?i.getExecutor():X;return this.#i.plugins!==void 0?t.withPlugins(this.#i.plugins):t}#e(i){return i.transformQuery(this.#i.rawNode,this.#i.queryId)}#s(i){return i.compileQuery(this.#e(i),this.#i.queryId)}};function N(e){return new P(e)}var q=class{#i;#t;constructor(i,t){this.#i=i,this.#t=t}get expression(){return this.#i}get alias(){return this.#t}get rawBuilder(){return this.#i}toOperationNode(){return W.create(this.#i.toOperationNode(),I(this.#t)?this.#t.toOperationNode():C.create(this.#t))}};var o=Object.assign((e,...i)=>N({queryId:v(),rawNode:f.create(e,i?.map(ri)??[])}),{ref(e){return N({queryId:v(),rawNode:f.createWithChild($(e))})},val(e){return N({queryId:v(),rawNode:f.createWithChild(k(e))})},value(e){return this.val(e)},table(e){return N({queryId:v(),rawNode:f.createWithChild(ii(e))})},id(...e){let i=new Array(e.length+1).fill(".");return i[0]="",i[i.length-1]="",N({queryId:v(),rawNode:f.create(i,e.map(C.create))})},lit(e){return N({queryId:v(),rawNode:f.createWithChild(G.createImmediate(e))})},literal(e){return this.lit(e)},raw(e){return N({queryId:v(),rawNode:f.createWithSql(e)})},join(e,i=o`, `){let t=new Array(Math.max(2*e.length-1,0)),s=i.toOperationNode();for(let r=0;r<e.length;++r)t[2*r]=ri(e[r]),r!==e.length-1&&(t[2*r+1]=s);return N({queryId:v(),rawNode:f.createWithChildren(t)})}});function ri(e){return I(e)?e.toOperationNode():k(e)}var O=class{nodeStack=[];get parentNode(){return this.nodeStack[this.nodeStack.length-2]}#i=m({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=i=>{this.nodeStack.push(i),this.#i[i.kind](i),this.nodeStack.pop()}};var Ni=/'/g,D=class extends O{#i="";#t=[];get numParameters(){return this.#t.length}compileQuery(i,t){return this.#i="",this.#t=[],this.nodeStack.splice(0,this.nodeStack.length),this.visitNode(i),m({query:i,queryId:t,sql:this.getSql(),parameters:[...this.#t]})}getSql(){return this.#i}visitSelectQuery(i){let t=this.parentNode!==void 0&&!Y.is(this.parentNode)&&!H.is(this.parentNode)&&!F.is(this.parentNode)&&!ti.is(this.parentNode)&&!Z.is(this.parentNode);this.parentNode===void 0&&i.explain&&(this.visitNode(i.explain),this.append(" ")),t&&this.append("("),i.with&&(this.visitNode(i.with),this.append(" ")),this.append("select"),i.distinctOn&&(this.append(" "),this.compileDistinctOn(i.distinctOn)),i.frontModifiers?.length&&(this.append(" "),this.compileList(i.frontModifiers," ")),i.top&&(this.append(" "),this.visitNode(i.top)),i.selections&&(this.append(" "),this.compileList(i.selections)),i.from&&(this.append(" "),this.visitNode(i.from)),i.joins&&(this.append(" "),this.compileList(i.joins," ")),i.where&&(this.append(" "),this.visitNode(i.where)),i.groupBy&&(this.append(" "),this.visitNode(i.groupBy)),i.having&&(this.append(" "),this.visitNode(i.having)),i.setOperations&&(this.append(" "),this.compileList(i.setOperations," ")),i.orderBy&&(this.append(" "),this.visitNode(i.orderBy)),i.limit&&(this.append(" "),this.visitNode(i.limit)),i.offset&&(this.append(" "),this.visitNode(i.offset)),i.fetch&&(this.append(" "),this.visitNode(i.fetch)),i.endModifiers?.length&&(this.append(" "),this.compileList(this.sortSelectModifiers([...i.endModifiers])," ")),t&&this.append(")")}visitFrom(i){this.append("from "),this.compileList(i.froms)}visitSelection(i){this.visitNode(i.selection)}visitColumn(i){this.visitNode(i.column)}compileDistinctOn(i){this.append("distinct on ("),this.compileList(i),this.append(")")}compileList(i,t=", "){let s=i.length-1;for(let r=0;r<=s;r++)this.visitNode(i[r]),r<s&&this.append(t)}visitWhere(i){this.append("where "),this.visitNode(i.where)}visitHaving(i){this.append("having "),this.visitNode(i.having)}visitInsertQuery(i){let t=this.nodeStack.find(T.is),s=t!==i;!s&&i.explain&&(this.visitNode(i.explain),this.append(" ")),s&&!w.is(t)&&this.append("("),i.with&&(this.visitNode(i.with),this.append(" ")),this.append(i.replace?"replace":"insert"),i.ignore&&(K("`InsertQueryNode.ignore` is deprecated. Use `InsertQueryNode.orAction` instead."),this.append(" ignore")),i.orAction&&(this.append(" "),this.visitNode(i.orAction)),i.top&&(this.append(" "),this.visitNode(i.top)),i.into&&(this.append(" into "),this.visitNode(i.into)),i.columns&&(this.append(" ("),this.compileList(i.columns),this.append(")")),i.output&&(this.append(" "),this.visitNode(i.output)),i.values&&(this.append(" "),this.visitNode(i.values)),i.defaultValues&&(this.append(" "),this.append("default values")),i.onConflict&&(this.append(" "),this.visitNode(i.onConflict)),i.onDuplicateKey&&(this.append(" "),this.visitNode(i.onDuplicateKey)),i.returning&&(this.append(" "),this.visitNode(i.returning)),s&&!w.is(t)&&this.append(")"),i.endModifiers?.length&&(this.append(" "),this.compileList(i.endModifiers," "))}visitValues(i){this.append("values "),this.compileList(i.values)}visitDeleteQuery(i){let t=this.nodeStack.find(T.is)!==i;!t&&i.explain&&(this.visitNode(i.explain),this.append(" ")),t&&this.append("("),i.with&&(this.visitNode(i.with),this.append(" ")),this.append("delete "),i.top&&(this.visitNode(i.top),this.append(" ")),this.visitNode(i.from),i.output&&(this.append(" "),this.visitNode(i.output)),i.using&&(this.append(" "),this.visitNode(i.using)),i.joins&&(this.append(" "),this.compileList(i.joins," ")),i.where&&(this.append(" "),this.visitNode(i.where)),i.orderBy&&(this.append(" "),this.visitNode(i.orderBy)),i.limit&&(this.append(" "),this.visitNode(i.limit)),i.returning&&(this.append(" "),this.visitNode(i.returning)),t&&this.append(")"),i.endModifiers?.length&&(this.append(" "),this.compileList(i.endModifiers," "))}visitReturning(i){this.append("returning "),this.compileList(i.selections)}visitAlias(i){this.visitNode(i.node),this.append(" as "),this.visitNode(i.alias)}visitReference(i){i.table&&(this.visitNode(i.table),this.append(".")),this.visitNode(i.column)}visitSelectAll(i){this.append("*")}visitIdentifier(i){this.append(this.getLeftIdentifierWrapper()),this.compileUnwrappedIdentifier(i),this.append(this.getRightIdentifierWrapper())}compileUnwrappedIdentifier(i){if(!E(i.name))throw new Error("a non-string identifier was passed to compileUnwrappedIdentifier.");this.append(this.sanitizeIdentifier(i.name))}visitAnd(i){this.visitNode(i.left),this.append(" and "),this.visitNode(i.right)}visitOr(i){this.visitNode(i.left),this.append(" or "),this.visitNode(i.right)}visitValue(i){i.immediate?this.appendImmediateValue(i.value):this.appendValue(i.value)}visitValueList(i){this.append("("),this.compileList(i.values),this.append(")")}visitTuple(i){this.append("("),this.compileList(i.values),this.append(")")}visitPrimitiveValueList(i){this.append("(");let{values:t}=i;for(let s=0;s<t.length;++s)this.appendValue(t[s]),s!==t.length-1&&this.append(", ");this.append(")")}visitParens(i){this.append("("),this.visitNode(i.node),this.append(")")}visitJoin(i){this.append(yi[i.joinType]),this.append(" "),this.visitNode(i.table),i.on&&(this.append(" "),this.visitNode(i.on))}visitOn(i){this.append("on "),this.visitNode(i.on)}visitRaw(i){let{sqlFragments:t,parameters:s}=i;for(let r=0;r<t.length;++r)this.append(t[r]),s.length>r&&this.visitNode(s[r])}visitOperator(i){this.append(i.operator)}visitTable(i){this.visitNode(i.table)}visitSchemableIdentifier(i){i.schema&&(this.visitNode(i.schema),this.append(".")),this.visitNode(i.identifier)}visitCreateTable(i){this.append("create "),i.frontModifiers&&i.frontModifiers.length>0&&(this.compileList(i.frontModifiers," "),this.append(" ")),i.temporary&&this.append("temporary "),this.append("table "),i.ifNotExists&&this.append("if not exists "),this.visitNode(i.table),i.selectQuery?(this.append(" as "),this.visitNode(i.selectQuery)):(this.append(" ("),this.compileList([...i.columns,...i.constraints??[]]),this.append(")"),i.onCommit&&(this.append(" on commit "),this.append(i.onCommit)),i.endModifiers&&i.endModifiers.length>0&&(this.append(" "),this.compileList(i.endModifiers," ")))}visitColumnDefinition(i){i.ifNotExists&&this.append("if not exists "),this.visitNode(i.column),this.append(" "),this.visitNode(i.dataType),i.unsigned&&this.append(" unsigned"),i.frontModifiers&&i.frontModifiers.length>0&&(this.append(" "),this.compileList(i.frontModifiers," ")),i.generated&&(this.append(" "),this.visitNode(i.generated)),i.identity&&this.append(" identity"),i.defaultTo&&(this.append(" "),this.visitNode(i.defaultTo)),i.notNull&&this.append(" not null"),i.unique&&this.append(" unique"),i.nullsNotDistinct&&this.append(" nulls not distinct"),i.primaryKey&&this.append(" primary key"),i.autoIncrement&&(this.append(" "),this.append(this.getAutoIncrement())),i.references&&(this.append(" "),this.visitNode(i.references)),i.check&&(this.append(" "),this.visitNode(i.check)),i.endModifiers&&i.endModifiers.length>0&&(this.append(" "),this.compileList(i.endModifiers," "))}getAutoIncrement(){return"auto_increment"}visitReferences(i){this.append("references "),this.visitNode(i.table),this.append(" ("),this.compileList(i.columns),this.append(")"),i.onDelete&&(this.append(" on delete "),this.append(i.onDelete)),i.onUpdate&&(this.append(" on update "),this.append(i.onUpdate))}visitDropTable(i){this.append("drop table "),i.ifExists&&this.append("if exists "),this.visitNode(i.table),i.cascade&&this.append(" cascade")}visitDataType(i){this.append(i.dataType)}visitOrderBy(i){this.append("order by "),this.compileList(i.items)}visitOrderByItem(i){this.visitNode(i.orderBy),i.collation&&(this.append(" "),this.visitNode(i.collation)),i.direction&&(this.append(" "),this.visitNode(i.direction)),i.nulls&&(this.append(" nulls "),this.append(i.nulls))}visitGroupBy(i){this.append("group by "),this.compileList(i.items)}visitGroupByItem(i){this.visitNode(i.groupBy)}visitUpdateQuery(i){let t=this.nodeStack.find(T.is),s=t!==i;if(!s&&i.explain&&(this.visitNode(i.explain),this.append(" ")),s&&!w.is(t)&&this.append("("),i.with&&(this.visitNode(i.with),this.append(" ")),this.append("update "),i.top&&(this.visitNode(i.top),this.append(" ")),i.table&&(this.visitNode(i.table),this.append(" ")),this.append("set "),i.updates&&this.compileList(i.updates),i.output&&(this.append(" "),this.visitNode(i.output)),i.from&&(this.append(" "),this.visitNode(i.from)),i.joins){if(!i.from)throw new Error("Joins in an update query are only supported as a part of a PostgreSQL 'update set from join' query. If you want to create a MySQL 'update join set' query, see https://kysely.dev/docs/examples/update/my-sql-joins");this.append(" "),this.compileList(i.joins," ")}i.where&&(this.append(" "),this.visitNode(i.where)),i.orderBy&&(this.append(" "),this.visitNode(i.orderBy)),i.limit&&(this.append(" "),this.visitNode(i.limit)),i.returning&&(this.append(" "),this.visitNode(i.returning)),s&&!w.is(t)&&this.append(")"),i.endModifiers?.length&&(this.append(" "),this.compileList(i.endModifiers," "))}visitColumnUpdate(i){this.visitNode(i.column),this.append(" = "),this.visitNode(i.value)}visitLimit(i){this.append("limit "),this.visitNode(i.limit)}visitOffset(i){this.append("offset "),this.visitNode(i.offset)}visitOnConflict(i){this.append("on conflict"),i.columns?(this.append(" ("),this.compileList(i.columns),this.append(")")):i.constraint?(this.append(" on constraint "),this.visitNode(i.constraint)):i.indexExpression&&(this.append(" ("),this.visitNode(i.indexExpression),this.append(")")),i.indexWhere&&(this.append(" "),this.visitNode(i.indexWhere)),i.doNothing===!0?this.append(" do nothing"):i.updates&&(this.append(" do update set "),this.compileList(i.updates),i.updateWhere&&(this.append(" "),this.visitNode(i.updateWhere)))}visitOnDuplicateKey(i){this.append("on duplicate key update "),this.compileList(i.updates)}visitCreateIndex(i){this.append("create "),i.unique&&this.append("unique "),this.append("index "),i.ifNotExists&&this.append("if not exists "),this.visitNode(i.name),i.table&&(this.append(" on "),this.visitNode(i.table)),i.using&&(this.append(" using "),this.visitNode(i.using)),i.columns&&(this.append(" ("),this.compileList(i.columns),this.append(")")),i.nullsNotDistinct&&this.append(" nulls not distinct"),i.where&&(this.append(" "),this.visitNode(i.where))}visitDropIndex(i){this.append("drop index "),i.ifExists&&this.append("if exists "),this.visitNode(i.name),i.table&&(this.append(" on "),this.visitNode(i.table)),i.cascade&&this.append(" cascade")}visitCreateSchema(i){this.append("create schema "),i.ifNotExists&&this.append("if not exists "),this.visitNode(i.schema)}visitDropSchema(i){this.append("drop schema "),i.ifExists&&this.append("if exists "),this.visitNode(i.schema),i.cascade&&this.append(" cascade")}visitPrimaryKeyConstraint(i){i.name&&(this.append("constraint "),this.visitNode(i.name),this.append(" ")),this.append("primary key ("),this.compileList(i.columns),this.append(")"),this.buildDeferrable(i)}buildDeferrable(i){i.deferrable!==void 0&&(i.deferrable?this.append(" deferrable"):this.append(" not deferrable")),i.initiallyDeferred!==void 0&&(i.initiallyDeferred?this.append(" initially deferred"):this.append(" initially immediate"))}visitUniqueConstraint(i){i.name&&(this.append("constraint "),this.visitNode(i.name),this.append(" ")),this.append("unique"),i.nullsNotDistinct&&this.append(" nulls not distinct"),this.append(" ("),this.compileList(i.columns),this.append(")"),this.buildDeferrable(i)}visitCheckConstraint(i){i.name&&(this.append("constraint "),this.visitNode(i.name),this.append(" ")),this.append("check ("),this.visitNode(i.expression),this.append(")")}visitForeignKeyConstraint(i){i.name&&(this.append("constraint "),this.visitNode(i.name),this.append(" ")),this.append("foreign key ("),this.compileList(i.columns),this.append(") "),this.visitNode(i.references),i.onDelete&&(this.append(" on delete "),this.append(i.onDelete)),i.onUpdate&&(this.append(" on update "),this.append(i.onUpdate)),this.buildDeferrable(i)}visitList(i){this.compileList(i.items)}visitWith(i){this.append("with "),i.recursive&&this.append("recursive "),this.compileList(i.expressions)}visitCommonTableExpression(i){this.visitNode(i.name),this.append(" as "),Q(i.materialized)&&(i.materialized||this.append("not "),this.append("materialized ")),this.visitNode(i.expression)}visitCommonTableExpressionName(i){this.visitNode(i.table),i.columns&&(this.append("("),this.compileList(i.columns),this.append(")"))}visitAlterTable(i){this.append("alter table "),this.visitNode(i.table),this.append(" "),i.renameTo&&(this.append("rename to "),this.visitNode(i.renameTo)),i.setSchema&&(this.append("set schema "),this.visitNode(i.setSchema)),i.addConstraint&&this.visitNode(i.addConstraint),i.dropConstraint&&this.visitNode(i.dropConstraint),i.renameConstraint&&this.visitNode(i.renameConstraint),i.columnAlterations&&this.compileColumnAlterations(i.columnAlterations),i.addIndex&&this.visitNode(i.addIndex),i.dropIndex&&this.visitNode(i.dropIndex)}visitAddColumn(i){this.append("add column "),this.visitNode(i.column)}visitRenameColumn(i){this.append("rename column "),this.visitNode(i.column),this.append(" to "),this.visitNode(i.renameTo)}visitDropColumn(i){this.append("drop column "),this.visitNode(i.column)}visitAlterColumn(i){this.append("alter column "),this.visitNode(i.column),this.append(" "),i.dataType&&(this.announcesNewColumnDataType()&&this.append("type "),this.visitNode(i.dataType),i.dataTypeExpression&&(this.append("using "),this.visitNode(i.dataTypeExpression))),i.setDefault&&(this.append("set default "),this.visitNode(i.setDefault)),i.dropDefault&&this.append("drop default"),i.setNotNull&&this.append("set not null"),i.dropNotNull&&this.append("drop not null")}visitModifyColumn(i){this.append("modify column "),this.visitNode(i.column)}visitAddConstraint(i){this.append("add "),this.visitNode(i.constraint)}visitDropConstraint(i){this.append("drop constraint "),i.ifExists&&this.append("if exists "),this.visitNode(i.constraintName),i.modifier==="cascade"?this.append(" cascade"):i.modifier==="restrict"&&this.append(" restrict")}visitRenameConstraint(i){this.append("rename constraint "),this.visitNode(i.oldName),this.append(" to "),this.visitNode(i.newName)}visitSetOperation(i){this.append(i.operator),this.append(" "),i.all&&this.append("all "),this.visitNode(i.expression)}visitCreateView(i){this.append("create "),i.orReplace&&this.append("or replace "),i.materialized&&this.append("materialized "),i.temporary&&this.append("temporary "),this.append("view "),i.ifNotExists&&this.append("if not exists "),this.visitNode(i.name),this.append(" "),i.columns&&(this.append("("),this.compileList(i.columns),this.append(") ")),i.as&&(this.append("as "),this.visitNode(i.as))}visitRefreshMaterializedView(i){this.append("refresh materialized view "),i.concurrently&&this.append("concurrently "),this.visitNode(i.name),i.withNoData?this.append(" with no data"):this.append(" with data")}visitDropView(i){this.append("drop "),i.materialized&&this.append("materialized "),this.append("view "),i.ifExists&&this.append("if exists "),this.visitNode(i.name),i.cascade&&this.append(" cascade")}visitGenerated(i){this.append("generated "),i.always&&this.append("always "),i.byDefault&&this.append("by default "),this.append("as "),i.identity&&this.append("identity"),i.expression&&(this.append("("),this.visitNode(i.expression),this.append(")")),i.stored&&this.append(" stored")}visitDefaultValue(i){this.append("default "),this.visitNode(i.defaultValue)}visitSelectModifier(i){i.rawModifier?this.visitNode(i.rawModifier):this.append(gi[i.modifier]),i.of&&(this.append(" of "),this.compileList(i.of,", "))}visitCreateType(i){this.append("create type "),this.visitNode(i.name),i.enum&&(this.append(" as enum "),this.visitNode(i.enum))}visitDropType(i){this.append("drop type "),i.ifExists&&this.append("if exists "),this.visitNode(i.name)}visitExplain(i){this.append("explain"),(i.options||i.format)&&(this.append(" "),this.append(this.getLeftExplainOptionsWrapper()),i.options&&(this.visitNode(i.options),i.format&&this.append(this.getExplainOptionsDelimiter())),i.format&&(this.append("format"),this.append(this.getExplainOptionAssignment()),this.append(i.format)),this.append(this.getRightExplainOptionsWrapper()))}visitDefaultInsertValue(i){this.append("default")}visitAggregateFunction(i){this.append(i.func),this.append("("),i.distinct&&this.append("distinct "),this.compileList(i.aggregated),i.orderBy&&(this.append(" "),this.visitNode(i.orderBy)),this.append(")"),i.withinGroup&&(this.append(" within group ("),this.visitNode(i.withinGroup),this.append(")")),i.filter&&(this.append(" filter("),this.visitNode(i.filter),this.append(")")),i.over&&(this.append(" "),this.visitNode(i.over))}visitOver(i){this.append("over("),i.partitionBy&&(this.visitNode(i.partitionBy),i.orderBy&&this.append(" ")),i.orderBy&&this.visitNode(i.orderBy),this.append(")")}visitPartitionBy(i){this.append("partition by "),this.compileList(i.items)}visitPartitionByItem(i){this.visitNode(i.partitionBy)}visitBinaryOperation(i){this.visitNode(i.leftOperand),this.append(" "),this.visitNode(i.operator),this.append(" "),this.visitNode(i.rightOperand)}visitUnaryOperation(i){this.visitNode(i.operator),this.isMinusOperator(i.operator)||this.append(" "),this.visitNode(i.operand)}isMinusOperator(i){return J.is(i)&&i.operator==="-"}visitUsing(i){this.append("using "),this.compileList(i.tables)}visitFunction(i){this.append(i.func),this.append("("),this.compileList(i.arguments),this.append(")")}visitCase(i){this.append("case"),i.value&&(this.append(" "),this.visitNode(i.value)),i.when&&(this.append(" "),this.compileList(i.when," ")),i.else&&(this.append(" else "),this.visitNode(i.else)),this.append(" end"),i.isStatement&&this.append(" case")}visitWhen(i){this.append("when "),this.visitNode(i.condition),i.result&&(this.append(" then "),this.visitNode(i.result))}visitJSONReference(i){this.visitNode(i.reference),this.visitNode(i.traversal)}visitJSONPath(i){i.inOperator&&this.visitNode(i.inOperator),this.append("'$");for(let t of i.pathLegs)this.visitNode(t);this.append("'")}visitJSONPathLeg(i){let t=i.type==="ArrayLocation";this.append(t?"[":"."),this.append(String(i.value)),t&&this.append("]")}visitJSONOperatorChain(i){for(let t=0,s=i.values.length;t<s;t++)t===s-1?this.visitNode(i.operator):this.append("->"),this.visitNode(i.values[t])}visitMergeQuery(i){i.with&&(this.visitNode(i.with),this.append(" ")),this.append("merge "),i.top&&(this.visitNode(i.top),this.append(" ")),this.append("into "),this.visitNode(i.into),i.using&&(this.append(" "),this.visitNode(i.using)),i.whens&&(this.append(" "),this.compileList(i.whens," ")),i.returning&&(this.append(" "),this.visitNode(i.returning)),i.output&&(this.append(" "),this.visitNode(i.output)),i.endModifiers?.length&&(this.append(" "),this.compileList(i.endModifiers," "))}visitMatched(i){i.not&&this.append("not "),this.append("matched"),i.bySource&&this.append(" by source")}visitAddIndex(i){this.append("add "),i.unique&&this.append("unique "),this.append("index "),this.visitNode(i.name),i.columns&&(this.append(" ("),this.compileList(i.columns),this.append(")")),i.using&&(this.append(" using "),this.visitNode(i.using))}visitCast(i){this.append("cast("),this.visitNode(i.expression),this.append(" as "),this.visitNode(i.dataType),this.append(")")}visitFetch(i){this.append("fetch next "),this.visitNode(i.rowCount),this.append(` rows ${i.modifier}`)}visitOutput(i){this.append("output "),this.compileList(i.selections)}visitTop(i){this.append(`top(${i.expression})`),i.modifiers&&this.append(` ${i.modifiers}`)}visitOrAction(i){this.append(i.action)}visitCollate(i){this.append("collate "),this.visitNode(i.collation)}append(i){this.#i+=i}appendValue(i){this.addParameter(i),this.append(this.getCurrentParameterPlaceholder())}getLeftIdentifierWrapper(){return'"'}getRightIdentifierWrapper(){return'"'}getCurrentParameterPlaceholder(){return"$"+this.numParameters}getLeftExplainOptionsWrapper(){return"("}getExplainOptionAssignment(){return" "}getExplainOptionsDelimiter(){return", "}getRightExplainOptionsWrapper(){return")"}sanitizeIdentifier(i){let t=this.getLeftIdentifierWrapper(),s=this.getRightIdentifierWrapper(),r="";for(let a of i)r+=a,a===t?r+=t:a===s&&(r+=s);return r}sanitizeStringLiteral(i){return i.replace(Ni,"''")}addParameter(i){this.#t.push(i)}appendImmediateValue(i){if(E(i))this.appendStringLiteral(i);else if(z(i)||Q(i))this.append(i.toString());else if(j(i))this.append("null");else if(V(i))this.appendImmediateValue(i.toISOString());else if(U(i))this.appendImmediateValue(i.toString());else throw new Error(`invalid immediate value ${i}`)}appendStringLiteral(i){this.append("'"),this.append(this.sanitizeStringLiteral(i)),this.append("'")}sortSelectModifiers(i){return i.sort((t,s)=>t.modifier&&s.modifier?ai[t.modifier]-ai[s.modifier]:1),m(i)}compileColumnAlterations(i){this.compileList(i)}announcesNewColumnDataType(){return!0}},gi=m({ForKeyShare:"for key share",ForNoKeyUpdate:"for no key update",ForUpdate:"for update",ForShare:"for share",NoWait:"nowait",SkipLocked:"skip locked",Distinct:"distinct"}),ai=m({ForKeyShare:1,ForNoKeyUpdate:1,ForUpdate:1,ForShare:1,NoWait:2,SkipLocked:2,Distinct:0}),yi=m({InnerJoin:"inner join",LeftJoin:"left join",RightJoin:"right join",FullJoin:"full join",CrossJoin:"cross join",LateralInnerJoin:"inner join lateral",LateralLeftJoin:"left join lateral",LateralCrossJoin:"cross join lateral",OuterApply:"outer apply",CrossApply:"cross apply",Using:"using"});var S=class{get supportsCreateIfNotExists(){return!0}get supportsTransactionalDdl(){return!1}get supportsReturning(){return!1}get supportsOutput(){return!1}};var bi=/"/g,L=class extends D{sanitizeIdentifier(i){return i.replace(bi,'""')}};var xi=BigInt("3853314791062309107"),A=class extends S{get supportsTransactionalDdl(){return!0}get supportsReturning(){return!0}async acquireMigrationLock(i,t){await o`select pg_advisory_xact_lock(${o.lit(xi)})`.execute(i)}async releaseMigrationLock(i,t){}};function y(e){return ei({...e,Adapter:A,QueryCompiler:L})}function ni(e,i){let{table:t,rows:s}=e,{name:r,schema:a,columns:n}=t,p=y(i),h=Object.keys(n),l={[h[0]]:o`default`};return g(p.withSchema(a).insertInto(r).values(s.map(u=>Object.keys(u).length===0?l:u)).returning(h).returning(u=>u.cast("ctid","text").as("ctid")))}function pi(e,i){let{pageIndex:t,pageSize:s,sortOrder:r,table:{name:a,schema:n,columns:p}}=e,h=y(i),l=Object.keys(p),u=h.withSchema(n).selectFrom(a).select(d=>d.cast(d.fn.coalesce(d.fn.countAll(),o.lit(0)),"text").as("oid"));return g(h.with("count",()=>u).withSchema(n).selectFrom([a,"count"]).select(o.ref("count.oid").$castTo().as("oid")).select(d=>d.cast("ctid","text").as("ctid")).select(l).$call(d=>r.reduce((b,x)=>b.orderBy(x.column,x.direction),d)).limit(s).offset(o.lit(BigInt(t)*BigInt(s))))}function It(){return[{created_at:new Date("2025-01-26T21:56:12.345Z"),ctid:"(0,1)",deleted_at:null,id:1,name:"John Doe",oid:"2",role:"admin"},{created_at:new Date("2025-01-26T20:56:12.345Z"),ctid:"(0,2)",deleted_at:null,id:2,name:"Jane Doe",oid:"2",role:"poweruser"}]}function oi(e,i){let{changes:t,row:s,table:{columns:r,name:a,schema:n}}=e,p=y(i),h=Object.keys(r);return g(p.withSchema(n).updateTable(a).set(t).$call(B([s],r)).returning(h).returning(l=>[l.cast("ctid","text").as("ctid"),l.cast(l.fn("floor",[l(l.fn("extract",[o`epoch from now()`]),"*",1e6)]),"text").as("__ps_updated_at__")]))}function hi(e,i){let{rows:t,table:{columns:s,name:r,schema:a}}=e,n=y(i);return g(n.withSchema(a).deleteFrom(r).$call(B(t,s)))}function di(e){return o`(select coalesce(json_agg(agg), '[]') from ${e} as agg)`}var wi="r",Ci="v",Ii=[wi,Ci];function li(e){return g(y(e).selectFrom("pg_catalog.pg_class as cls").innerJoin("pg_catalog.pg_namespace as ns","cls.relnamespace","ns.oid").$call(Ti).where("cls.relkind","in",Ii).select(i=>["ns.nspname as schema","cls.relname as name",di(i.selectFrom("pg_catalog.pg_attribute as att").innerJoin("pg_catalog.pg_type as typ","typ.oid","att.atttypid").innerJoin("pg_catalog.pg_namespace as tns","tns.oid","typ.typnamespace").leftJoin("pg_catalog.pg_constraint as con",t=>t.on("con.contype","=","p").onRef("con.conrelid","=","cls.oid").on(s=>s("att.attnum","=",s.fn.any("con.conkey")))).whereRef("att.attrelid","=","cls.oid").where("att.attnum",">=",0).where("att.attisdropped","!=",!0).select(["att.attname as name","typ.typname as datatype","tns.nspname as datatype_schema"]).select(t=>[t("con.conkey","is not",null).$castTo().as("pk"),t("att.attgenerated","!=","").$castTo().as("computed"),t("att.attnotnull","!=",!0).$castTo().as("nullable"),t.fn.coalesce(t.selectFrom("pg_catalog.pg_enum as enm").whereRef("enm.enumtypid","=","typ.oid").select(s=>s.fn.jsonAgg(s.ref("enm.enumlabel")).as("o")),o`'[]'`).as("options")])).as("columns")]))}function ui(){return[{schema:"public",name:"users",columns:[{name:"id",datatype:"bigint",datatype_schema:"public",pk:!0,computed:!1,options:[],nullable:!0},{name:"name",datatype:"varchar",datatype_schema:"public",pk:!1,computed:!1,options:[],nullable:!0},{name:"role",datatype:"role",datatype_schema:"public",pk:!1,computed:!1,options:["admin","maintainer","member"],nullable:!0},{name:"created_at",datatype:"timestamptz",datatype_schema:"public",pk:!1,computed:!1,options:[],nullable:!0},{name:"deleted_at",datatype:"timestamptz",datatype_schema:"public",pk:!1,computed:!1,options:[],nullable:!0}]}]}function ci(){let e=y();return g(e.selectNoFrom(e.fn("current_setting",[o.lit("timezone")]).as("timezone")))}function mi(){return[{timezone:"UTC"}]}function Ti(e){return e.where("ns.nspname","!~","^pg_").where("ns.nspname","!=","information_schema")}function Mt(e){let{executor:i,...t}=e;return{defaultSchema:"public",async introspect(s){try{let r=li(t),a=ci(),[[n,p],[h,l]]=await Promise.all([i.execute(r,s),i.execute(a,s)]),u=n||h;if(u)return[u];let[d]=l;return d?[null,fi(p,d.timezone)]:[new Error("Timezone not found")]}catch(r){return[r]}},async query(s,r){try{let a=pi(s,t),[n,p]=await i.execute(a,r);return n?[n]:[null,{filteredRowCount:p[0]?.oid||"0",rows:p}]}catch(a){return[a]}},async insert(s,r){try{let a=ni(s,t),[n,p]=await i.execute(a,r);return n?[n]:[null,{rows:p}]}catch(a){return[a]}},async update(s,r){try{let a=oi(s,t),[n,p]=await i.execute(a,r);if(n)return[n];let[h]=p;return h?[null,{row:h}]:[new Error("Update failed")]}catch(a){return[a]}},async delete(s,r){try{let a=hi(s,t),[n]=await i.execute(a,r);return n?[n]:[null,s]}catch(a){return[a]}}}}function fi(e,i){return e.reduce((t,s)=>{let{schemas:r}=t,{columns:a,name:n,schema:p}=s,h=a.reduce((l,u)=>{let{datatype:d,datatype_schema:b,name:x,options:M,nullable:vi}=u,_=d.startsWith("_"),R=_?d.slice(1):d;return{...l,[x]:{datatype:{...si[R]||{group:M.length>0?"enum":"raw"},isArray:_,isNative:b==="pg_catalog",name:_?`${R}[]`:R,options:M,schema:b},isComputed:u.computed,isInPrimaryKey:u.pk,name:x,nullable:vi,schema:p,table:n}}},{});return(r[p]||={tables:{}}).tables[n]={columns:h,name:n,schema:p},t},{schemas:{public:{tables:{}}},timezone:i})}function zt(){let e=ui(),[{timezone:i}]=mi();return fi(e,i)}export{ni as a,pi as b,It as c,oi as d,hi as e,li as f,ui as g,ci as h,mi as i,Mt as j,zt as k};
|