@prisma/studio-core 0.0.0-dev.202503191520 → 0.0.0-dev.202503201500
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/data/postgres-core/index.ts +1 -0
- package/data/postgres-core/introspection.ts +98 -0
- package/data/query.ts +75 -0
- package/dist/data/index.cjs +1 -0
- package/dist/data/index.d.cts +127 -0
- package/dist/data/postgres-core/index.cjs +1 -0
- package/dist/data/postgres-core/index.d.cts +32 -0
- package/dist/data/postgres-core/index.d.ts +32 -0
- package/dist/data/postgres-core/index.js +1 -0
- package/dist/ui/index.cjs +1 -0
- package/dist/ui/index.d.cts +3 -0
- package/package.json +34 -11
- package/tsconfig.json +2 -1
- package/tsup.config.ts +6 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./introspection";
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { type Kysely, PostgresAdapter, PostgresQueryCompiler, type SelectQueryBuilder } from "kysely";
|
|
2
|
+
import { jsonArrayFrom } from "kysely/helpers/postgres";
|
|
3
|
+
|
|
4
|
+
import { type BuilderRequirements, compile, getBuilder, QueryResult } from "../query";
|
|
5
|
+
|
|
6
|
+
const REGULAR_TABLE_KIND = "r";
|
|
7
|
+
const VIEW_TABLE_KIND = "v";
|
|
8
|
+
const TABLE_KINDS = [REGULAR_TABLE_KIND, VIEW_TABLE_KIND] as const;
|
|
9
|
+
type TableKind = (typeof TABLE_KINDS)[number];
|
|
10
|
+
|
|
11
|
+
interface Database {
|
|
12
|
+
/** columns */
|
|
13
|
+
"pg_catalog.pg_attribute": {
|
|
14
|
+
/** column order number in its table */
|
|
15
|
+
attnum: number;
|
|
16
|
+
/** table/view identifier */
|
|
17
|
+
attrelid: string;
|
|
18
|
+
/** column name */
|
|
19
|
+
attname: string;
|
|
20
|
+
/** was the column dropped. dropped columns might not be 100% removed immediately. */
|
|
21
|
+
attisdropped: boolean;
|
|
22
|
+
};
|
|
23
|
+
/** resources, e.g. tables, sequences, etc. */
|
|
24
|
+
"pg_catalog.pg_class": {
|
|
25
|
+
/** resource id */
|
|
26
|
+
oid: number;
|
|
27
|
+
/** resource name */
|
|
28
|
+
relname: string;
|
|
29
|
+
/** schema id */
|
|
30
|
+
relnamespace: number;
|
|
31
|
+
/** resource kind: regular table, view */
|
|
32
|
+
relkind: TableKind;
|
|
33
|
+
};
|
|
34
|
+
/** schemas */
|
|
35
|
+
"pg_catalog.pg_namespace": {
|
|
36
|
+
/** schema name */
|
|
37
|
+
nspname: string;
|
|
38
|
+
/** schema id */
|
|
39
|
+
oid: number;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function getTablesQuery(requirements?: Omit<BuilderRequirements, "Adapter" | "Compiler">) {
|
|
44
|
+
return compile(
|
|
45
|
+
getPostgreSQLBuilder(requirements)
|
|
46
|
+
.selectFrom("pg_catalog.pg_class as cls")
|
|
47
|
+
.innerJoin("pg_catalog.pg_namespace as ns", "cls.relnamespace", "ns.oid")
|
|
48
|
+
.$call(excludeSystemTables)
|
|
49
|
+
// regular tables or views
|
|
50
|
+
.where("cls.relkind", "in", TABLE_KINDS)
|
|
51
|
+
.select((eb) => [
|
|
52
|
+
"ns.nspname as schema",
|
|
53
|
+
"cls.relname as name",
|
|
54
|
+
jsonArrayFrom(
|
|
55
|
+
eb
|
|
56
|
+
.selectFrom("pg_catalog.pg_attribute as att")
|
|
57
|
+
// column belongs to current table
|
|
58
|
+
.whereRef("att.attrelid", "=", "cls.oid")
|
|
59
|
+
// exclude system columns
|
|
60
|
+
.where("att.attnum", ">=", 0)
|
|
61
|
+
// exclude dropped columns
|
|
62
|
+
.where("att.attisdropped", "!=", true)
|
|
63
|
+
.select("att.attname as name"),
|
|
64
|
+
).as("columns"),
|
|
65
|
+
]),
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* For testing purposes.
|
|
71
|
+
*/
|
|
72
|
+
export function mockTablesQuery(): QueryResult<typeof getTablesQuery> {
|
|
73
|
+
return [
|
|
74
|
+
{
|
|
75
|
+
schema: "public",
|
|
76
|
+
name: "users",
|
|
77
|
+
columns: [{ name: "id" }, { name: "name" }, { name: "role" }, { name: "created_at" }],
|
|
78
|
+
},
|
|
79
|
+
];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* We don't want PostgreSQL internals in introspection results. To be used in `$call`.
|
|
84
|
+
*/
|
|
85
|
+
function excludeSystemTables<
|
|
86
|
+
T extends SelectQueryBuilder<
|
|
87
|
+
Database & { ns: Database["pg_catalog.pg_namespace"]; cls: Database["pg_catalog.pg_class"] },
|
|
88
|
+
"ns" | "cls",
|
|
89
|
+
any
|
|
90
|
+
>,
|
|
91
|
+
>(qb: T): T {
|
|
92
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
93
|
+
return qb.where(`ns.nspname`, `!~`, `^pg_`).where(`ns.nspname`, `!=`, `information_schema`) as any;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function getPostgreSQLBuilder(requirements?: Omit<BuilderRequirements, "Adapter" | "QueryCompiler">): Kysely<Database> {
|
|
97
|
+
return getBuilder({ ...requirements, Adapter: PostgresAdapter, QueryCompiler: PostgresQueryCompiler });
|
|
98
|
+
}
|
package/data/query.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Compilable,
|
|
3
|
+
type DialectAdapter,
|
|
4
|
+
DummyDriver,
|
|
5
|
+
Kysely,
|
|
6
|
+
type KyselyPlugin,
|
|
7
|
+
OperationNodeTransformer,
|
|
8
|
+
type PluginTransformQueryArgs,
|
|
9
|
+
type PluginTransformResultArgs,
|
|
10
|
+
type QueryCompiler,
|
|
11
|
+
type QueryResult as KyselyQueryResult,
|
|
12
|
+
type RootOperationNode,
|
|
13
|
+
type UnknownRow,
|
|
14
|
+
type ValueNode,
|
|
15
|
+
} from "kysely";
|
|
16
|
+
|
|
17
|
+
export interface BuilderRequirements {
|
|
18
|
+
Adapter: { new (): DialectAdapter };
|
|
19
|
+
noParameters?: boolean;
|
|
20
|
+
QueryCompiler: { new (): QueryCompiler };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getBuilder<DB>(requirements: BuilderRequirements): Kysely<DB> {
|
|
24
|
+
return new Kysely({
|
|
25
|
+
dialect: {
|
|
26
|
+
createAdapter: () => new requirements.Adapter(),
|
|
27
|
+
createDriver: () => new DummyDriver(),
|
|
28
|
+
// @ts-expect-error - we don't need built-in introspection in this case
|
|
29
|
+
createIntrospector: () => null,
|
|
30
|
+
createQueryCompiler: () => new requirements.QueryCompiler(),
|
|
31
|
+
},
|
|
32
|
+
plugins: [...(requirements.noParameters ? [new ImmediateValuePlugin()] : [])],
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A plugin that transforms all values to immediate values. This means their injected into the SQL string instead of populating the parameters array.
|
|
38
|
+
* In some situations, a database driver might not support parameters, and this plugin can be used to work around that.
|
|
39
|
+
*/
|
|
40
|
+
class ImmediateValuePlugin implements KyselyPlugin {
|
|
41
|
+
readonly #transformer = new ImmediateValueTransformer();
|
|
42
|
+
|
|
43
|
+
transformQuery(args: PluginTransformQueryArgs): RootOperationNode {
|
|
44
|
+
return this.#transformer.transformNode(args.node);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
transformResult(args: PluginTransformResultArgs): Promise<KyselyQueryResult<UnknownRow>> {
|
|
48
|
+
return Promise.resolve(args.result);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
class ImmediateValueTransformer extends OperationNodeTransformer {
|
|
53
|
+
override transformValue(node: ValueNode): ValueNode {
|
|
54
|
+
return { ...super.transformValue(node), immediate: true };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
declare const queryType: unique symbol;
|
|
59
|
+
export interface Query<T> {
|
|
60
|
+
[queryType]?: T;
|
|
61
|
+
parameters: readonly unknown[];
|
|
62
|
+
sql: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export type QueryResult<T> =
|
|
66
|
+
T extends Query<infer R> ? R[] : T extends (...args: any[]) => Query<infer R> ? R[] : never;
|
|
67
|
+
|
|
68
|
+
export function compile<T>(compileable: Compilable<T>): Query<T> {
|
|
69
|
+
const compiledQuery = compileable.compile();
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
parameters: compiledQuery.parameters,
|
|
73
|
+
sql: compiledQuery.sql,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var l=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var p=(a,e)=>{for(var r in e)l(a,r,{get:e[r],enumerable:!0})},o=(a,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of i(e))!m.call(a,s)&&s!==r&&l(a,s,{get:()=>e[s],enumerable:!(n=u(e,s))||n.enumerable});return a};var d=a=>o(l({},"__esModule",{value:!0}),a);var c={};p(c,{AdapterMock:()=>t});module.exports=d(c);var t=class{async introspect(){return[null,{schemas:{public:{tables:{users:{schema:"public",name:"users",columns:{id:{schema:"public",table:"users",name:"id",dataType:{name:"integer",args:[]},uiType:{kind:"number",isList:!1,max:1e4,min:0},defaults:null,nullable:!1,partOfPk:!0,reference:null},name:{schema:"public",table:"users",name:"name",dataType:{name:"varchar",args:[255]},uiType:{kind:"string",isList:!1,max:255,min:0},defaults:null,nullable:!1,partOfPk:!1,reference:null},role:{schema:"public",table:"users",name:"role",dataType:{name:"enum",args:[]},uiType:{kind:"enum",isList:!1,name:"UserRole",values:["admin","user","guest"]},defaults:"user",nullable:!1,partOfPk:!1,reference:null}}},posts:{schema:"public",name:"posts",columns:{id:{schema:"public",table:"posts",name:"id",dataType:{name:"integer",args:[]},uiType:{kind:"number",isList:!1,max:1e4,min:0},defaults:null,nullable:!1,partOfPk:!0,reference:null},title:{schema:"public",table:"posts",name:"title",dataType:{name:"varchar",args:[255]},uiType:{kind:"string",isList:!1,max:255,min:0},defaults:null,nullable:!1,partOfPk:!1,reference:null},content:{schema:"public",table:"posts",name:"content",dataType:{name:"text",args:[]},uiType:{kind:"string",isList:!1,max:1e4,min:0},defaults:null,nullable:!0,partOfPk:!1,reference:null},userId:{schema:"public",table:"posts",name:"userId",dataType:{name:"integer",args:[]},uiType:{kind:"number",isList:!1,max:1e4,min:0},defaults:null,nullable:!1,partOfPk:!1,reference:{schema:"public",name:"users",columns:{}}}}}},enums:{UserRole:{name:"UserRole",values:["admin","user","guest"]}}}},filters:{"=":!0,">=":!0,">":!0,"<=":!0,"<":!0,like:!0,ilike:!1,"is null":!0}}]}async query(e){return[null,{schema:"public",table:"users",fetchedAt:Date.now(),duration:35,count:2,rows:[{id:{column:"id",value:1,dataType:{name:"integer",args:[]},uiType:{kind:"number",isList:!1,max:1e4,min:0}},name:{column:"name",value:"Alice",dataType:{name:"varchar",args:[255]},uiType:{kind:"string",isList:!1,max:255,min:0}},role:{column:"role",value:"admin",dataType:{name:"enum",args:[]},uiType:{kind:"enum",isList:!1,name:"UserRole",values:["admin","user","guest"]}}},{id:{column:"id",value:2,dataType:{name:"integer",args:[]},uiType:{kind:"number",isList:!1,max:1e4,min:0}},name:{column:"name",value:"Bob",dataType:{name:"varchar",args:[255]},uiType:{kind:"string",isList:!1,max:255,min:0}},role:{column:"role",value:"user",dataType:{name:"enum",args:[]},uiType:{kind:"enum",isList:!1,name:"UserRole",values:["admin","user","guest"]}}}]}]}async mutate(e){throw new Error("Method not implemented.")}async alter(e){throw new Error("Method not implemented.")}async rawQuery(e){throw new Error("Method not implemented.")}};0&&(module.exports={AdapterMock});
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
type Either<E, R> = [E] | [null, R];
|
|
2
|
+
interface Adapter {
|
|
3
|
+
introspect(): Promise<Either<Error, InstrospectResult>>;
|
|
4
|
+
query(input: QueryInput): Promise<Either<Error, QueryResult>>;
|
|
5
|
+
mutate(inputs: MutateInput[]): Promise<Either<Error, MutateResult>>;
|
|
6
|
+
alter(inputs: AlterInput[]): Promise<Either<Error, AlterResult>>;
|
|
7
|
+
rawQuery(input: RawQueryInput): Promise<Either<Error, RawQueryResult>>;
|
|
8
|
+
}
|
|
9
|
+
type EnumName = string;
|
|
10
|
+
type TableName = string;
|
|
11
|
+
type ColumnName = string;
|
|
12
|
+
type SchemaName = string;
|
|
13
|
+
type InstrospectResult = {
|
|
14
|
+
schemas: Record<SchemaName, InstrospectSchemaMeta>;
|
|
15
|
+
filters: Record<QueryFilterOperator, boolean>;
|
|
16
|
+
};
|
|
17
|
+
type InstrospectSchemaMeta = {
|
|
18
|
+
tables: Record<TableName, InstrospectTableMeta>;
|
|
19
|
+
enums: Record<EnumName, EnumMeta>;
|
|
20
|
+
};
|
|
21
|
+
type InstrospectTableMeta = {
|
|
22
|
+
schema: SchemaName;
|
|
23
|
+
name: TableName;
|
|
24
|
+
columns: Record<ColumnName, InstrospectColumnMeta>;
|
|
25
|
+
};
|
|
26
|
+
type InstrospectColumnMeta = {
|
|
27
|
+
schema: SchemaName;
|
|
28
|
+
table: TableName;
|
|
29
|
+
name: ColumnName;
|
|
30
|
+
dataType: IntrospectDataType;
|
|
31
|
+
uiType: IntrospectUiType;
|
|
32
|
+
defaults: unknown;
|
|
33
|
+
nullable: boolean;
|
|
34
|
+
partOfPk: boolean;
|
|
35
|
+
reference: InstrospectTableMeta | null;
|
|
36
|
+
};
|
|
37
|
+
type IntrospectDataType = {
|
|
38
|
+
name: string;
|
|
39
|
+
args: (string | number)[];
|
|
40
|
+
};
|
|
41
|
+
type IntrospectUiType = {
|
|
42
|
+
kind: "string";
|
|
43
|
+
isList: boolean;
|
|
44
|
+
max: number;
|
|
45
|
+
min: number;
|
|
46
|
+
} | {
|
|
47
|
+
kind: "number";
|
|
48
|
+
isList: boolean;
|
|
49
|
+
max: number;
|
|
50
|
+
min: number;
|
|
51
|
+
} | {
|
|
52
|
+
kind: "decimal";
|
|
53
|
+
isList: boolean;
|
|
54
|
+
max: number;
|
|
55
|
+
min: number;
|
|
56
|
+
decimalPlaces: number;
|
|
57
|
+
} | {
|
|
58
|
+
kind: "boolean";
|
|
59
|
+
isList: boolean;
|
|
60
|
+
} | {
|
|
61
|
+
kind: "datetime";
|
|
62
|
+
isList: boolean;
|
|
63
|
+
} | {
|
|
64
|
+
kind: "json";
|
|
65
|
+
isList: boolean;
|
|
66
|
+
} | {
|
|
67
|
+
kind: "blob";
|
|
68
|
+
isList: boolean;
|
|
69
|
+
} | {
|
|
70
|
+
kind: "enum";
|
|
71
|
+
isList: boolean;
|
|
72
|
+
name: EnumName;
|
|
73
|
+
values: string[];
|
|
74
|
+
};
|
|
75
|
+
type EnumMeta = {
|
|
76
|
+
name: EnumName;
|
|
77
|
+
values: string[];
|
|
78
|
+
};
|
|
79
|
+
type QueryInput = {
|
|
80
|
+
schema: SchemaName;
|
|
81
|
+
table: TableName;
|
|
82
|
+
filters: QueryFilter[][];
|
|
83
|
+
sortings: QuerySorting[];
|
|
84
|
+
limit?: number;
|
|
85
|
+
offset?: number;
|
|
86
|
+
};
|
|
87
|
+
type QueryFilter = {
|
|
88
|
+
column: ColumnName;
|
|
89
|
+
operator: QueryFilterOperator;
|
|
90
|
+
value: unknown[] | InstrospectColumnMeta[];
|
|
91
|
+
not?: boolean;
|
|
92
|
+
};
|
|
93
|
+
type QuerySorting = {
|
|
94
|
+
column: ColumnName;
|
|
95
|
+
order: "asc" | "desc";
|
|
96
|
+
};
|
|
97
|
+
type QueryFilterOperator = "=" | ">=" | ">" | "<=" | "<" | "like" | "ilike" | "is null" | (string & {});
|
|
98
|
+
type QueryResult = {
|
|
99
|
+
schema: SchemaName;
|
|
100
|
+
table: TableName;
|
|
101
|
+
fetchedAt: number;
|
|
102
|
+
duration: number;
|
|
103
|
+
rows: Record<ColumnName, QueryResultColumn>[];
|
|
104
|
+
count: number;
|
|
105
|
+
};
|
|
106
|
+
type QueryResultColumn = {
|
|
107
|
+
column: ColumnName;
|
|
108
|
+
value: unknown;
|
|
109
|
+
dataType?: IntrospectDataType;
|
|
110
|
+
uiType?: IntrospectUiType;
|
|
111
|
+
};
|
|
112
|
+
type MutateInput = {};
|
|
113
|
+
type MutateResult = {};
|
|
114
|
+
type AlterInput = {};
|
|
115
|
+
type AlterResult = {};
|
|
116
|
+
type RawQueryInput = {};
|
|
117
|
+
type RawQueryResult = {};
|
|
118
|
+
|
|
119
|
+
declare class AdapterMock implements Adapter {
|
|
120
|
+
introspect(): Promise<Either<Error, InstrospectResult>>;
|
|
121
|
+
query(input: QueryInput): Promise<Either<Error, QueryResult>>;
|
|
122
|
+
mutate(inputs: MutateInput[]): Promise<Either<Error, MutateResult>>;
|
|
123
|
+
alter(inputs: AlterInput[]): Promise<Either<Error, AlterResult>>;
|
|
124
|
+
rawQuery(input: RawQueryInput): Promise<Either<Error, RawQueryResult>>;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export { type Adapter, AdapterMock };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var Fr=Object.defineProperty;var Io=Object.getOwnPropertyDescriptor;var So=Object.getOwnPropertyNames;var ko=Object.prototype.hasOwnProperty;var Ao=(t,e)=>{for(var i in e)Fr(t,i,{get:e[i],enumerable:!0})},Eo=(t,e,i,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of So(e))!ko.call(t,n)&&n!==i&&Fr(t,n,{get:()=>e[n],enumerable:!(o=Io(e,n))||o.enumerable});return t};var Ro=t=>Eo(Fr({},"__esModule",{value:!0}),t);var gn={};Ao(gn,{getTablesQuery:()=>yn,mockTablesQuery:()=>wn});module.exports=Ro(gn);function z(t){return typeof t>"u"||t===void 0}function g(t){return typeof t=="string"}function we(t){return typeof t=="number"}function Ae(t){return typeof t=="boolean"}function Fe(t){return t===null}function Ii(t){return t instanceof Date}function Me(t){return typeof t=="bigint"}function O(t){return typeof t=="function"}function Q(t){return typeof t=="object"&&t!==null}function r(t){return Object.freeze(t)}function mt(t){return E(t)?t:[t]}function E(t){return Array.isArray(t)}function te(t){return t}var c=r({is(t){return t.kind==="AlterTableNode"},create(t){return r({kind:"AlterTableNode",table:t})},cloneWithTableProps(t,e){return r({...t,...e})},cloneWithColumnAlteration(t,e){return r({...t,columnAlterations:t.columnAlterations?[...t.columnAlterations,e]:[e]})}});var d=r({is(t){return t.kind==="IdentifierNode"},create(t){return r({kind:"IdentifierNode",name:t})}});var G=r({is(t){return t.kind==="CreateIndexNode"},create(t){return r({kind:"CreateIndexNode",name:d.create(t)})},cloneWith(t,e){return r({...t,...e})},cloneWithColumns(t,e){return r({...t,columns:[...t.columns||[],...e]})}});var Kt=r({is(t){return t.kind==="CreateSchemaNode"},create(t,e){return r({kind:"CreateSchemaNode",schema:d.create(t),...e})},cloneWith(t,e){return r({...t,...e})}});var Si=["preserve rows","delete rows","drop"],R=r({is(t){return t.kind==="CreateTableNode"},create(t){return r({kind:"CreateTableNode",table:t,columns:r([])})},cloneWithColumn(t,e){return r({...t,columns:r([...t.columns,e])})},cloneWithConstraint(t,e){return r({...t,constraints:t.constraints?r([...t.constraints,e]):r([e])})},cloneWithFrontModifier(t,e){return r({...t,frontModifiers:t.frontModifiers?r([...t.frontModifiers,e]):r([e])})},cloneWithEndModifier(t,e){return r({...t,endModifiers:t.endModifiers?r([...t.endModifiers,e]):r([e])})},cloneWith(t,e){return r({...t,...e})}});var F=r({is(t){return t.kind==="SchemableIdentifierNode"},create(t){return r({kind:"SchemableIdentifierNode",identifier:d.create(t)})},createWithSchema(t,e){return r({kind:"SchemableIdentifierNode",schema:d.create(t),identifier:d.create(e)})}});var xe=r({is(t){return t.kind==="DropIndexNode"},create(t,e){return r({kind:"DropIndexNode",name:F.create(t),...e})},cloneWith(t,e){return r({...t,...e})}});var lt=r({is(t){return t.kind==="DropSchemaNode"},create(t,e){return r({kind:"DropSchemaNode",schema:d.create(t),...e})},cloneWith(t,e){return r({...t,...e})}});var ft=r({is(t){return t.kind==="DropTableNode"},create(t,e){return r({kind:"DropTableNode",table:t,...e})},cloneWith(t,e){return r({...t,...e})}});var D=r({is(t){return t.kind==="AliasNode"},create(t,e){return r({kind:"AliasNode",node:t,alias:e})}});var K=r({is(t){return t.kind==="TableNode"},create(t){return r({kind:"TableNode",table:F.create(t)})},createWithSchema(t,e){return r({kind:"TableNode",table:F.createWithSchema(t,e)})}});function x(t){return Q(t)&&O(t.toOperationNode)}function ki(t){return Q(t)&&"expressionType"in t&&x(t)}function Ai(t){return Q(t)&&"expression"in t&&g(t.alias)&&x(t)}var re=r({is(t){return t.kind==="SelectModifierNode"},create(t,e){return r({kind:"SelectModifierNode",modifier:t,of:e})},createWithExpression(t){return r({kind:"SelectModifierNode",rawModifier:t})}});var M=r({is(t){return t.kind==="AndNode"},create(t,e){return r({kind:"AndNode",left:t,right:e})}});var H=r({is(t){return t.kind==="OrNode"},create(t,e){return r({kind:"OrNode",left:t,right:e})}});var jt=r({is(t){return t.kind==="OnNode"},create(t){return r({kind:"OnNode",on:t})},cloneWithOperation(t,e,i){return r({...t,on:e==="And"?M.create(t.on,i):H.create(t.on,i)})}});var Oe=r({is(t){return t.kind==="JoinNode"},create(t,e){return r({kind:"JoinNode",joinType:t,table:e,on:void 0})},createWithOn(t,e,i){return r({kind:"JoinNode",joinType:t,table:e,on:jt.create(i)})},cloneWithOn(t,e){return r({...t,on:t.on?jt.cloneWithOperation(t.on,"And",e):jt.create(e)})}});var ge=r({is(t){return t.kind==="BinaryOperationNode"},create(t,e,i){return r({kind:"BinaryOperationNode",leftOperand:t,operator:e,rightOperand:i})}});var Do=["=","==","!=","<>",">",">=","<","<=","in","not in","is","is not","like","not like","match","ilike","not ilike","@>","<@","^@","&&","?","?&","?|","!<","!>","<=>","!~","~","~*","!~*","@@","@@@","!!","<->","regexp","is distinct from","is not distinct from"],Bo=["+","-","*","/","%","^","&","|","#","<<",">>"],Ei=["->","->>"],Lo=[...Do,...Bo,"&&","||"],Qo=["exists","not exists"],Po=["not","-",...Qo],Ri=[...Lo,...Ei,...Po,"between","between symmetric"],U=r({is(t){return t.kind==="OperatorNode"},create(t){return r({kind:"OperatorNode",operator:t})}});function Mr(t){return g(t)&&Ei.includes(t)}var h=r({is(t){return t.kind==="ColumnNode"},create(t){return r({kind:"ColumnNode",column:d.create(t)})}});var Ve=r({is(t){return t.kind==="SelectAllNode"},create(){return r({kind:"SelectAllNode"})}});var ze=r({is(t){return t.kind==="ReferenceNode"},create(t,e){return r({kind:"ReferenceNode",table:e,column:t})},createSelectAll(t){return r({kind:"ReferenceNode",table:t,column:Ve.create()})}});var Gt=class{#e;get dynamicReference(){return this.#e}get refType(){}constructor(e){this.#e=e}toOperationNode(){return Vr(this.#e)}};function Ht(t){return Q(t)&&x(t)&&g(t.dynamicReference)}var Yt=r({is(t){return t.kind==="OrderByItemNode"},create(t,e){return r({kind:"OrderByItemNode",orderBy:t,direction:e})}});var C=r({is(t){return t.kind==="RawNode"},create(t,e){return r({kind:"RawNode",sqlFragments:r(t),parameters:r(e)})},createWithSql(t){return C.create([t],[])},createWithChild(t){return C.create(["",""],[t])},createWithChildren(t){return C.create(new Array(t.length+1).fill(""),t)}});function Ur(t){return t==="asc"||t==="desc"}function ve(t){if(t.length===2)return[zr(t[0],t[1])];if(t.length===1){let[e]=t;return Array.isArray(e)?e.map(i=>zr(i)):[zr(e)]}throw new Error(`Invalid number of arguments at order by! expected 1-2, received ${t.length}`)}function zr(t,e){let i=Fo(t);if(Yt.is(i)){if(e)throw new Error("Cannot specify direction twice!");return i}return Yt.create(i,Di(e))}function Fo(t){if(he(t))return V(t);if(Ht(t))return t.toOperationNode();let[e,i]=t.split(" ");if(i){if(!Ur(i))throw new Error(`Invalid order by direction: ${i}`);return Yt.create(J(e),Di(i))}return J(t)}function Di(t){if(t)return t==="asc"||t==="desc"?C.createWithSql(t):t.toOperationNode()}var Ue=r({is(t){return t.kind==="JSONReferenceNode"},create(t,e){return r({kind:"JSONReferenceNode",reference:t,traversal:e})},cloneWithTraversal(t,e){return r({...t,traversal:e})}});var Xt=r({is(t){return t.kind==="JSONOperatorChainNode"},create(t){return r({kind:"JSONOperatorChainNode",operator:t,values:r([])})},cloneWithValue(t,e){return r({...t,values:r([...t.values,e])})}});var Ce=r({is(t){return t.kind==="JSONPathNode"},create(t){return r({kind:"JSONPathNode",inOperator:t,pathLegs:r([])})},cloneWithLeg(t,e){return r({...t,pathLegs:r([...t.pathLegs,e])})}});function Vr(t){return g(t)?J(t):t.toOperationNode()}function ce(t){return E(t)?t.map(e=>I(e)):[I(t)]}function I(t){return he(t)?V(t):Vr(t)}function Bi(t,e){let i=J(t);if(Mr(e))return Ue.create(i,Xt.create(U.create(e)));let o=e.slice(0,-1);if(Mr(o))return Ue.create(i,Ce.create(U.create(o)));throw new Error(`Invalid JSON operator: ${e}`)}function J(t){let e=".";if(!t.includes(e))return ze.create(h.create(t));let i=t.split(e).map($r);if(i.length===3)return Mo(i);if(i.length===2)return Vo(i);throw new Error(`invalid column reference ${t}`)}function Li(t){let e=" as ";if(t.includes(e)){let[i,o]=t.split(e).map($r);return D.create(J(i),d.create(o))}else return J(t)}function Jr(t){return h.create(t)}function Je(t){let e=" ";if(t.includes(e)){let[i,o]=t.split(e).map($r);if(!Ur(o))throw new Error(`invalid order direction "${o}" next to "${i}"`);return ve([i,o])[0]}else return Jr(t)}function Mo(t){let[e,i,o]=t;return ze.create(h.create(o),K.createWithSchema(e,i))}function Vo(t){let[e,i]=t;return ze.create(h.create(i),K.create(e))}function $r(t){return t.trim()}var Zt=r({is(t){return t.kind==="PrimitiveValueListNode"},create(t){return r({kind:"PrimitiveValueListNode",values:r([...t])})}});var $e=r({is(t){return t.kind==="ValueListNode"},create(t){return r({kind:"ValueListNode",values:r(t)})}});var S=r({is(t){return t.kind==="ValueNode"},create(t){return r({kind:"ValueNode",value:t})},createImmediate(t){return r({kind:"ValueNode",value:t,immediate:!0})}});function Qi(t){return E(t)?zo(t):N(t)}function N(t){return he(t)?V(t):S.create(t)}function _t(t){return we(t)||Ae(t)||Fe(t)}function Nt(t){if(!_t(t))throw new Error(`unsafe immediate value ${JSON.stringify(t)}`);return S.createImmediate(t)}function zo(t){return t.some(he)?$e.create(t.map(e=>N(e))):Zt.create(t)}var ie=r({is(t){return t.kind==="ParensNode"},create(t){return r({kind:"ParensNode",node:t})}});function y(t){if(t.length===3)return er(t[0],t[1],t[2]);if(t.length===1)return N(t[0]);throw new Error(`invalid arguments: ${JSON.stringify(t)}`)}function er(t,e,i){return Uo(e)&&Fi(i)?ge.create(I(t),Kr(e),S.createImmediate(i)):ge.create(I(t),Kr(e),Qi(i))}function W(t,e,i){return ge.create(I(t),Kr(e),I(i))}function jr(t,e){return Ke(Object.entries(t).filter(([,i])=>!z(i)).map(([i,o])=>er(i,Fi(o)?"is":"=",o)),e)}function Ke(t,e,i=!0){let o=e==="and"?M.create:H.create;if(t.length===0)return ge.create(S.createImmediate(1),U.create("="),S.createImmediate(e==="and"?1:0));let n=Pi(t[0]);for(let u=1;u<t.length;++u)n=o(n,Pi(t[u]));return t.length>1&&i?ie.create(n):n}function Uo(t){return t==="is"||t==="is not"}function Fi(t){return Fe(t)||Ae(t)}function Kr(t){if(g(t)&&Ri.includes(t))return U.create(t);if(x(t))return t.toOperationNode();throw new Error(`invalid operator ${JSON.stringify(t)}`)}function Pi(t){return x(t)?t.toOperationNode():t}var me=r({is(t){return t.kind==="OrderByNode"},create(t){return r({kind:"OrderByNode",items:r([...t])})},cloneWithItems(t,e){return r({...t,items:r([...t.items,...e])})}});var Gr=r({is(t){return t.kind==="PartitionByNode"},create(t){return r({kind:"PartitionByNode",items:r(t)})},cloneWithItems(t,e){return r({...t,items:r([...t.items,...e])})}});var yt=r({is(t){return t.kind==="OverNode"},create(){return r({kind:"OverNode"})},cloneWithOrderByItems(t,e){return r({...t,orderBy:t.orderBy?me.cloneWithItems(t.orderBy,e):me.create(e)})},cloneWithPartitionByItems(t,e){return r({...t,partitionBy:t.partitionBy?Gr.cloneWithItems(t.partitionBy,e):Gr.create(e)})}});var Ee=r({is(t){return t.kind==="FromNode"},create(t){return r({kind:"FromNode",froms:r(t)})},cloneWithFroms(t,e){return r({...t,froms:r([...t.froms,...e])})}});var Hr=r({is(t){return t.kind==="GroupByNode"},create(t){return r({kind:"GroupByNode",items:r(t)})},cloneWithItems(t,e){return r({...t,items:r([...t.items,...e])})}});var Yr=r({is(t){return t.kind==="HavingNode"},create(t){return r({kind:"HavingNode",having:t})},cloneWithOperation(t,e,i){return r({...t,having:e==="And"?M.create(t.having,i):H.create(t.having,i)})}});var p=r({is(t){return t.kind==="SelectQueryNode"},create(t){return r({kind:"SelectQueryNode",...t&&{with:t}})},createFrom(t,e){return r({kind:"SelectQueryNode",from:Ee.create(t),...e&&{with:e}})},cloneWithSelections(t,e){return r({...t,selections:t.selections?r([...t.selections,...e]):r(e)})},cloneWithDistinctOn(t,e){return r({...t,distinctOn:t.distinctOn?r([...t.distinctOn,...e]):r(e)})},cloneWithFrontModifier(t,e){return r({...t,frontModifiers:t.frontModifiers?r([...t.frontModifiers,e]):r([e])})},cloneWithEndModifier(t,e){return r({...t,endModifiers:t.endModifiers?r([...t.endModifiers,e]):r([e])})},cloneWithOrderByItems(t,e){return r({...t,orderBy:t.orderBy?me.cloneWithItems(t.orderBy,e):me.create(e)})},cloneWithGroupByItems(t,e){return r({...t,groupBy:t.groupBy?Hr.cloneWithItems(t.groupBy,e):Hr.create(e)})},cloneWithLimit(t,e){return r({...t,limit:e})},cloneWithOffset(t,e){return r({...t,offset:e})},cloneWithFetch(t,e){return r({...t,fetch:e})},cloneWithHaving(t,e){return r({...t,having:t.having?Yr.cloneWithOperation(t.having,"And",e):Yr.create(e)})},cloneWithSetOperations(t,e){return r({...t,setOperations:t.setOperations?r([...t.setOperations,...e]):r([...e])})},cloneWithoutSelections(t){return r({...t,selections:[]})},cloneWithoutLimit(t){return r({...t,limit:void 0})},cloneWithoutOffset(t){return r({...t,offset:void 0})},cloneWithoutOrderBy(t){return r({...t,orderBy:void 0})},cloneWithoutGroupBy(t){return r({...t,groupBy:void 0})}});function s(t,e){Object.defineProperties(t.prototype,{then:{enumerable:!1,value:()=>{throw new Error(e)}}})}var wt=class t{#e;constructor(e){this.#e=r(e)}on(...e){return new t({...this.#e,joinNode:Oe.cloneWithOn(this.#e.joinNode,y(e))})}onRef(e,i,o){return new t({...this.#e,joinNode:Oe.cloneWithOn(this.#e.joinNode,W(e,i,o))})}onTrue(){return new t({...this.#e,joinNode:Oe.cloneWithOn(this.#e.joinNode,C.createWithSql("true"))})}$call(e){return e(this)}toOperationNode(){return this.#e.joinNode}};s(wt,"don't await JoinBuilder instances. They are never executed directly and are always just a part of a query.");var Mi=r({is(t){return t.kind==="PartitionByItemNode"},create(t){return r({kind:"PartitionByItemNode",partitionBy:t})}});function Vi(t){return ce(t).map(Mi.create)}var xt=class t{#e;constructor(e){this.#e=r(e)}orderBy(e,i){return new t({overNode:yt.cloneWithOrderByItems(this.#e.overNode,ve([e,i]))})}partitionBy(e){return new t({overNode:yt.cloneWithPartitionByItems(this.#e.overNode,Vi(e))})}$call(e){return e(this)}toOperationNode(){return this.#e.overNode}};s(xt,"don't await OverBuilder instances. They are never executed directly and are always just a part of a query.");var je=r({is(t){return t.kind==="SelectionNode"},create(t){return r({kind:"SelectionNode",selection:t})},createSelectAll(){return r({kind:"SelectionNode",selection:Ve.create()})},createSelectAllFromTable(t){return r({kind:"SelectionNode",selection:ze.createSelectAll(t)})}});function k(t){return O(t)?k(t(Y())):E(t)?t.map(e=>zi(e)):[zi(t)]}function zi(t){return g(t)?je.create(Li(t)):Ht(t)?je.create(t.toOperationNode()):je.create(tr(t))}function B(t){return t?Array.isArray(t)?t.map(Ui):[Ui(t)]:[je.createSelectAll()]}function Ui(t){if(g(t))return je.createSelectAllFromTable(l(t));throw new Error(`invalid value selectAll expression: ${JSON.stringify(t)}`)}var Ji=r({is(t){return t.kind==="ValuesNode"},create(t){return r({kind:"ValuesNode",values:r(t)})}});var $i=r({is(t){return t.kind==="DefaultInsertValueNode"},create(){return r({kind:"DefaultInsertValueNode"})}});function rr(t){let e=O(t)?t(Y()):t,i=E(e)?e:r([e]);return Jo(i)}function Jo(t){let e=$o(t);return[r([...e.keys()].map(h.create)),Ji.create(t.map(i=>Ko(i,e)))]}function $o(t){let e=new Map;for(let i of t){let o=Object.keys(i);for(let n of o)!e.has(n)&&i[n]!==void 0&&e.set(n,e.size)}return e}function Ko(t,e){let i=Object.keys(t),o=Array.from({length:e.size}),n=!1;for(let v of i){let L=e.get(v);if(z(L))continue;let pe=t[v];(z(pe)||he(pe))&&(n=!0),o[L]=pe}if(i.length<e.size||n){let v=$i.create();return $e.create(o.map(L=>z(L)?v:N(L)))}return Zt.create(o)}var q=r({is(t){return t.kind==="InsertQueryNode"},create(t,e,i){return r({kind:"InsertQueryNode",into:t,...e&&{with:e},replace:i})},createWithoutInto(){return r({kind:"InsertQueryNode"})},cloneWith(t,e){return r({...t,...e})}});var oe=r({is(t){return t.kind==="UpdateQueryNode"},create(t,e){return r({kind:"UpdateQueryNode",table:t,...e&&{with:e}})},createWithoutTable(){return r({kind:"UpdateQueryNode"})},cloneWithFromItems(t,e){return r({...t,from:t.from?Ee.cloneWithFroms(t.from,e):Ee.create(e)})},cloneWithUpdates(t,e){return r({...t,updates:t.updates?r([...t.updates,...e]):e})},cloneWithLimit(t,e){return r({...t,limit:e})}});var Xr=r({is(t){return t.kind==="UsingNode"},create(t){return r({kind:"UsingNode",tables:r(t)})},cloneWithTables(t,e){return r({...t,tables:r([...t.tables,...e])})}});var ne=r({is(t){return t.kind==="DeleteQueryNode"},create(t,e){return r({kind:"DeleteQueryNode",from:Ee.create(t),...e&&{with:e}})},cloneWithOrderByItems(t,e){return r({...t,orderBy:t.orderBy?me.cloneWithItems(t.orderBy,e):me.create(e)})},cloneWithoutOrderBy(t){return r({...t,orderBy:void 0})},cloneWithLimit(t,e){return r({...t,limit:e})},cloneWithoutLimit(t){return r({...t,limit:void 0})},cloneWithUsing(t,e){return r({...t,using:t.using!==void 0?Xr.cloneWithTables(t.using,e):Xr.create(e)})}});var A=r({is(t){return t.kind==="WhereNode"},create(t){return r({kind:"WhereNode",where:t})},cloneWithOperation(t,e,i){return r({...t,where:e==="And"?M.create(t.where,i):H.create(t.where,i)})}});var Zr=r({is(t){return t.kind==="ReturningNode"},create(t){return r({kind:"ReturningNode",selections:r(t)})},cloneWithSelections(t,e){return r({...t,selections:t.selections?r([...t.selections,...e]):r(e)})}});var Ki=r({is(t){return t.kind==="ExplainNode"},create(t,e){return r({kind:"ExplainNode",format:t,options:e})}});var le=r({is(t){return t.kind==="WhenNode"},create(t){return r({kind:"WhenNode",condition:t})},cloneWithResult(t,e){return r({...t,result:e})}});var T=r({is(t){return t.kind==="MergeQueryNode"},create(t,e){return r({kind:"MergeQueryNode",into:t,...e&&{with:e}})},cloneWithUsing(t,e){return r({...t,using:e})},cloneWithWhen(t,e){return r({...t,whens:t.whens?r([...t.whens,e]):r([e])})},cloneWithThen(t,e){return r({...t,whens:t.whens?r([...t.whens.slice(0,-1),le.cloneWithResult(t.whens[t.whens.length-1],e)]):void 0})}});var _r=r({is(t){return t.kind==="OutputNode"},create(t){return r({kind:"OutputNode",selections:r(t)})},cloneWithSelections(t,e){return r({...t,selections:t.selections?r([...t.selections,...e]):r(e)})}});var a=r({is(t){return p.is(t)||q.is(t)||oe.is(t)||ne.is(t)||T.is(t)},cloneWithWhere(t,e){return r({...t,where:t.where?A.cloneWithOperation(t.where,"And",e):A.create(e)})},cloneWithJoin(t,e){return r({...t,joins:t.joins?r([...t.joins,e]):r([e])})},cloneWithReturning(t,e){return r({...t,returning:t.returning?Zr.cloneWithSelections(t.returning,e):Zr.create(e)})},cloneWithoutReturning(t){return r({...t,returning:void 0})},cloneWithoutWhere(t){return r({...t,where:void 0})},cloneWithExplain(t,e,i){return r({...t,explain:Ki.create(e,i?.toOperationNode())})},cloneWithTop(t,e){return r({...t,top:e})},cloneWithOutput(t,e){return r({...t,output:t.output?_r.cloneWithSelections(t.output,e):_r.create(e)})}});var ei=r({is(t){return t.kind==="ColumnUpdateNode"},create(t,e){return r({kind:"ColumnUpdateNode",column:t,value:e})}});function ji(...t){return t.length===2?[ei.create(I(t[0]),N(t[1]))]:Ot(t[0])}function Ot(t){let e=O(t)?t(Y()):t;return Object.entries(e).filter(([i,o])=>o!==void 0).map(([i,o])=>ei.create(h.create(i),N(o)))}var Gi=r({is(t){return t.kind==="OnDuplicateKeyNode"},create(t){return r({kind:"OnDuplicateKeyNode",updates:t})}});var ir=class{insertId;numInsertedOrUpdatedRows;constructor(e,i){this.insertId=e,this.numInsertedOrUpdatedRows=i}};var j=class extends Error{node;constructor(e){super("no result"),this.node=e}};function se(t){return Object.prototype.hasOwnProperty.call(t,"prototype")}var P=r({is(t){return t.kind==="OnConflictNode"},create(){return r({kind:"OnConflictNode"})},cloneWith(t,e){return r({...t,...e})},cloneWithIndexWhere(t,e){return r({...t,indexWhere:t.indexWhere?A.cloneWithOperation(t.indexWhere,"And",e):A.create(e)})},cloneWithIndexOrWhere(t,e){return r({...t,indexWhere:t.indexWhere?A.cloneWithOperation(t.indexWhere,"Or",e):A.create(e)})},cloneWithUpdateWhere(t,e){return r({...t,updateWhere:t.updateWhere?A.cloneWithOperation(t.updateWhere,"And",e):A.create(e)})},cloneWithUpdateOrWhere(t,e){return r({...t,updateWhere:t.updateWhere?A.cloneWithOperation(t.updateWhere,"Or",e):A.create(e)})},cloneWithoutIndexWhere(t){return r({...t,indexWhere:void 0})},cloneWithoutUpdateWhere(t){return r({...t,updateWhere:void 0})}});var gt=class t{#e;constructor(e){this.#e=r(e)}column(e){let i=h.create(e);return new t({...this.#e,onConflictNode:P.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?r([...this.#e.onConflictNode.columns,i]):r([i])})})}columns(e){let i=e.map(h.create);return new t({...this.#e,onConflictNode:P.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?r([...this.#e.onConflictNode.columns,...i]):r(i)})})}constraint(e){return new t({...this.#e,onConflictNode:P.cloneWith(this.#e.onConflictNode,{constraint:d.create(e)})})}expression(e){return new t({...this.#e,onConflictNode:P.cloneWith(this.#e.onConflictNode,{indexExpression:e.toOperationNode()})})}where(...e){return new t({...this.#e,onConflictNode:P.cloneWithIndexWhere(this.#e.onConflictNode,y(e))})}whereRef(e,i,o){return new t({...this.#e,onConflictNode:P.cloneWithIndexWhere(this.#e.onConflictNode,W(e,i,o))})}clearWhere(){return new t({...this.#e,onConflictNode:P.cloneWithoutIndexWhere(this.#e.onConflictNode)})}doNothing(){return new or({...this.#e,onConflictNode:P.cloneWith(this.#e.onConflictNode,{doNothing:!0})})}doUpdateSet(e){return new nr({...this.#e,onConflictNode:P.cloneWith(this.#e.onConflictNode,{updates:Ot(e)})})}$call(e){return e(this)}};s(gt,"don't await OnConflictBuilder instances.");var or=class{#e;constructor(e){this.#e=r(e)}toOperationNode(){return this.#e.onConflictNode}};s(or,"don't await OnConflictDoNothingBuilder instances.");var nr=class t{#e;constructor(e){this.#e=r(e)}where(...e){return new t({...this.#e,onConflictNode:P.cloneWithUpdateWhere(this.#e.onConflictNode,y(e))})}whereRef(e,i,o){return new t({...this.#e,onConflictNode:P.cloneWithUpdateWhere(this.#e.onConflictNode,W(e,i,o))})}clearWhere(){return new t({...this.#e,onConflictNode:P.cloneWithoutUpdateWhere(this.#e.onConflictNode)})}$call(e){return e(this)}toOperationNode(){return this.#e.onConflictNode}};s(nr,"don't await OnConflictUpdateBuilder instances.");var Hi=r({is(t){return t.kind==="TopNode"},create(t,e){return r({kind:"TopNode",expression:t,modifiers:e})}});function X(t,e){if(!we(t)&&!Me(t))throw new Error(`Invalid top expression: ${t}`);if(!z(e)&&!jo(e))throw new Error(`Invalid top modifiers: ${e}`);return Hi.create(t,e)}function jo(t){return t==="percent"||t==="with ties"||t==="percent with ties"}var Ge=class t{#e;constructor(e){this.#e=r(e)}values(e){let[i,o]=rr(e);return new t({...this.#e,queryNode:q.cloneWith(this.#e.queryNode,{columns:i,values:o})})}columns(e){return new t({...this.#e,queryNode:q.cloneWith(this.#e.queryNode,{columns:r(e.map(h.create))})})}expression(e){return new t({...this.#e,queryNode:q.cloneWith(this.#e.queryNode,{values:V(e)})})}defaultValues(){return new t({...this.#e,queryNode:q.cloneWith(this.#e.queryNode,{defaultValues:!0})})}ignore(){return new t({...this.#e,queryNode:q.cloneWith(this.#e.queryNode,{ignore:!0})})}top(e,i){return new t({...this.#e,queryNode:a.cloneWithTop(this.#e.queryNode,X(e,i))})}onConflict(e){return new t({...this.#e,queryNode:q.cloneWith(this.#e.queryNode,{onConflict:e(new gt({onConflictNode:P.create()})).toOperationNode()})})}onDuplicateKeyUpdate(e){return new t({...this.#e,queryNode:q.cloneWith(this.#e.queryNode,{onDuplicateKey:Gi.create(Ot(e))})})}returning(e){return new t({...this.#e,queryNode:a.cloneWithReturning(this.#e.queryNode,k(e))})}returningAll(){return new t({...this.#e,queryNode:a.cloneWithReturning(this.#e.queryNode,B())})}output(e){return new t({...this.#e,queryNode:a.cloneWithOutput(this.#e.queryNode,k(e))})}outputAll(e){return new t({...this.#e,queryNode:a.cloneWithOutput(this.#e.queryNode,B(e))})}clearReturning(){return new t({...this.#e,queryNode:a.cloneWithoutReturning(this.#e.queryNode)})}$call(e){return e(this)}$if(e,i){return e?i(this):new t({...this.#e})}$castTo(){return new t(this.#e)}$narrowType(){return new t(this.#e)}$assertType(){return new t(this.#e)}withPlugin(e){return new t({...this.#e,executor:this.#e.executor.withPlugin(e)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile(),i=await this.#e.executor.executeQuery(e,this.#e.queryId),{adapter:o}=this.#e.executor,n=e.query;return n.returning&&o.supportsReturning||n.output&&o.supportsOutput?i.rows:[new ir(i.insertId,i.numAffectedRows??i.numUpdatedOrDeletedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=j){let i=await this.executeTakeFirst();if(i===void 0)throw se(e)?new e(this.toOperationNode()):e(this.toOperationNode());return i}async*stream(e=100){let i=this.compile(),o=this.#e.executor.stream(i,e,this.#e.queryId);for await(let n of o)yield*n.rows}async explain(e,i){return await new t({...this.#e,queryNode:a.cloneWithExplain(this.#e.queryNode,e,i)}).execute()}};s(Ge,"don't await InsertQueryBuilder instances directly. To execute the query you need to call `execute` or `executeTakeFirst`.");var sr=class{numDeletedRows;constructor(e){this.numDeletedRows=e}};var He=r({is(t){return t.kind==="LimitNode"},create(t){return r({kind:"LimitNode",limit:t})}});var vt=class t{#e;constructor(e){this.#e=r(e)}where(...e){return new t({...this.#e,queryNode:a.cloneWithWhere(this.#e.queryNode,y(e))})}whereRef(e,i,o){return new t({...this.#e,queryNode:a.cloneWithWhere(this.#e.queryNode,W(e,i,o))})}clearWhere(){return new t({...this.#e,queryNode:a.cloneWithoutWhere(this.#e.queryNode)})}top(e,i){return new t({...this.#e,queryNode:a.cloneWithTop(this.#e.queryNode,X(e,i))})}using(e){return new t({...this.#e,queryNode:ne.cloneWithUsing(this.#e.queryNode,ae(e))})}innerJoin(...e){return new t({...this.#e,queryNode:a.cloneWithJoin(this.#e.queryNode,b("InnerJoin",e))})}leftJoin(...e){return new t({...this.#e,queryNode:a.cloneWithJoin(this.#e.queryNode,b("LeftJoin",e))})}rightJoin(...e){return new t({...this.#e,queryNode:a.cloneWithJoin(this.#e.queryNode,b("RightJoin",e))})}fullJoin(...e){return new t({...this.#e,queryNode:a.cloneWithJoin(this.#e.queryNode,b("FullJoin",e))})}returning(e){return new t({...this.#e,queryNode:a.cloneWithReturning(this.#e.queryNode,k(e))})}returningAll(e){return new t({...this.#e,queryNode:a.cloneWithReturning(this.#e.queryNode,B(e))})}output(e){return new t({...this.#e,queryNode:a.cloneWithOutput(this.#e.queryNode,k(e))})}outputAll(e){return new t({...this.#e,queryNode:a.cloneWithOutput(this.#e.queryNode,B(e))})}clearReturning(){return new t({...this.#e,queryNode:a.cloneWithoutReturning(this.#e.queryNode)})}clearLimit(){return new t({...this.#e,queryNode:ne.cloneWithoutLimit(this.#e.queryNode)})}clearOrderBy(){return new t({...this.#e,queryNode:ne.cloneWithoutOrderBy(this.#e.queryNode)})}orderBy(e,i){return new t({...this.#e,queryNode:ne.cloneWithOrderByItems(this.#e.queryNode,ve([e,i]))})}limit(e){return new t({...this.#e,queryNode:ne.cloneWithLimit(this.#e.queryNode,He.create(N(e)))})}$call(e){return e(this)}$if(e,i){return e?i(this):new t({...this.#e})}$castTo(){return new t(this.#e)}$narrowType(){return new t(this.#e)}$assertType(){return new t(this.#e)}withPlugin(e){return new t({...this.#e,executor:this.#e.executor.withPlugin(e)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile(),i=await this.#e.executor.executeQuery(e,this.#e.queryId),{adapter:o}=this.#e.executor,n=e.query;return n.returning&&o.supportsReturning||n.output&&o.supportsOutput?i.rows:[new sr(i.numAffectedRows??i.numUpdatedOrDeletedRows??BigInt(0))]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=j){let i=await this.executeTakeFirst();if(i===void 0)throw se(e)?new e(this.toOperationNode()):e(this.toOperationNode());return i}async*stream(e=100){let i=this.compile(),o=this.#e.executor.stream(i,e,this.#e.queryId);for await(let n of o)yield*n.rows}async explain(e,i){return await new t({...this.#e,queryNode:a.cloneWithExplain(this.#e.queryNode,e,i)}).execute()}};s(vt,"don't await DeleteQueryBuilder instances directly. To execute the query you need to call `execute` or `executeTakeFirst`.");var ar=class{numUpdatedRows;numChangedRows;constructor(e,i){this.numUpdatedRows=e,this.numChangedRows=i}};var Re=class t{#e;constructor(e){this.#e=r(e)}where(...e){return new t({...this.#e,queryNode:a.cloneWithWhere(this.#e.queryNode,y(e))})}whereRef(e,i,o){return new t({...this.#e,queryNode:a.cloneWithWhere(this.#e.queryNode,W(e,i,o))})}clearWhere(){return new t({...this.#e,queryNode:a.cloneWithoutWhere(this.#e.queryNode)})}top(e,i){return new t({...this.#e,queryNode:a.cloneWithTop(this.#e.queryNode,X(e,i))})}from(e){return new t({...this.#e,queryNode:oe.cloneWithFromItems(this.#e.queryNode,ae(e))})}innerJoin(...e){return new t({...this.#e,queryNode:a.cloneWithJoin(this.#e.queryNode,b("InnerJoin",e))})}leftJoin(...e){return new t({...this.#e,queryNode:a.cloneWithJoin(this.#e.queryNode,b("LeftJoin",e))})}rightJoin(...e){return new t({...this.#e,queryNode:a.cloneWithJoin(this.#e.queryNode,b("RightJoin",e))})}fullJoin(...e){return new t({...this.#e,queryNode:a.cloneWithJoin(this.#e.queryNode,b("FullJoin",e))})}limit(e){return new t({...this.#e,queryNode:oe.cloneWithLimit(this.#e.queryNode,He.create(N(e)))})}set(...e){return new t({...this.#e,queryNode:oe.cloneWithUpdates(this.#e.queryNode,ji(...e))})}returning(e){return new t({...this.#e,queryNode:a.cloneWithReturning(this.#e.queryNode,k(e))})}returningAll(e){return new t({...this.#e,queryNode:a.cloneWithReturning(this.#e.queryNode,B(e))})}output(e){return new t({...this.#e,queryNode:a.cloneWithOutput(this.#e.queryNode,k(e))})}outputAll(e){return new t({...this.#e,queryNode:a.cloneWithOutput(this.#e.queryNode,B(e))})}clearReturning(){return new t({...this.#e,queryNode:a.cloneWithoutReturning(this.#e.queryNode)})}$call(e){return e(this)}$if(e,i){return e?i(this):new t({...this.#e})}$castTo(){return new t(this.#e)}$narrowType(){return new t(this.#e)}$assertType(){return new t(this.#e)}withPlugin(e){return new t({...this.#e,executor:this.#e.executor.withPlugin(e)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile(),i=await this.#e.executor.executeQuery(e,this.#e.queryId),{adapter:o}=this.#e.executor,n=e.query;return n.returning&&o.supportsReturning||n.output&&o.supportsOutput?i.rows:[new ar(i.numAffectedRows??i.numUpdatedOrDeletedRows??BigInt(0),i.numChangedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=j){let i=await this.executeTakeFirst();if(i===void 0)throw se(e)?new e(this.toOperationNode()):e(this.toOperationNode());return i}async*stream(e=100){let i=this.compile(),o=this.#e.executor.stream(i,e,this.#e.queryId);for await(let n of o)yield*n.rows}async explain(e,i){return await new t({...this.#e,queryNode:a.cloneWithExplain(this.#e.queryNode,e,i)}).execute()}};s(Re,"don't await UpdateQueryBuilder instances directly. To execute the query you need to call `execute` or `executeTakeFirst`.");var ti=r({is(t){return t.kind==="CommonTableExpressionNameNode"},create(t,e){return r({kind:"CommonTableExpressionNameNode",table:K.create(t),columns:e?r(e.map(h.create)):void 0})}});var Ye=r({is(t){return t.kind==="CommonTableExpressionNode"},create(t,e){return r({kind:"CommonTableExpressionNode",name:t,expression:e})},cloneWith(t,e){return r({...t,...e})}});var Ct=class t{#e;constructor(e){this.#e=r(e)}materialized(){return new t({...this.#e,node:Ye.cloneWith(this.#e.node,{materialized:!0})})}notMaterialized(){return new t({...this.#e,node:Ye.cloneWith(this.#e.node,{materialized:!1})})}toOperationNode(){return this.#e.node}};s(Ct,"don't await CTEBuilder instances. They are never executed directly and are always just a part of a query.");function ri(t,e){let i=e(Xi()).toOperationNode();return O(t)?t(Go(i)).toOperationNode():Ye.create(Yi(t),i)}function Go(t){return e=>new Ct({node:Ye.create(Yi(e),t)})}function Yi(t){if(t.includes("(")){let e=t.split(/[\(\)]/),i=e[0],o=e[1].split(",").map(n=>n.trim());return ti.create(i,o)}else return ti.create(t)}var bt=r({is(t){return t.kind==="WithNode"},create(t,e){return r({kind:"WithNode",expressions:r([t]),...e})},cloneWithExpression(t,e){return r({...t,expressions:r([...t.expressions,e])})}});var Zi=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"];function _i(t){let e="";for(let i=0;i<t;++i)e+=Ho();return e}function Ho(){return Zi[~~(Math.random()*Zi.length)]}function m(){return new ii}var ii=class{#e;get queryId(){return this.#e===void 0&&(this.#e=_i(8)),this.#e}};var be=class{nodeStack=[];#e=r({AliasNode:this.transformAlias.bind(this),ColumnNode:this.transformColumn.bind(this),IdentifierNode:this.transformIdentifier.bind(this),SchemableIdentifierNode:this.transformSchemableIdentifier.bind(this),RawNode:this.transformRaw.bind(this),ReferenceNode:this.transformReference.bind(this),SelectQueryNode:this.transformSelectQuery.bind(this),SelectionNode:this.transformSelection.bind(this),TableNode:this.transformTable.bind(this),FromNode:this.transformFrom.bind(this),SelectAllNode:this.transformSelectAll.bind(this),AndNode:this.transformAnd.bind(this),OrNode:this.transformOr.bind(this),ValueNode:this.transformValue.bind(this),ValueListNode:this.transformValueList.bind(this),PrimitiveValueListNode:this.transformPrimitiveValueList.bind(this),ParensNode:this.transformParens.bind(this),JoinNode:this.transformJoin.bind(this),OperatorNode:this.transformOperator.bind(this),WhereNode:this.transformWhere.bind(this),InsertQueryNode:this.transformInsertQuery.bind(this),DeleteQueryNode:this.transformDeleteQuery.bind(this),ReturningNode:this.transformReturning.bind(this),CreateTableNode:this.transformCreateTable.bind(this),AddColumnNode:this.transformAddColumn.bind(this),ColumnDefinitionNode:this.transformColumnDefinition.bind(this),DropTableNode:this.transformDropTable.bind(this),DataTypeNode:this.transformDataType.bind(this),OrderByNode:this.transformOrderBy.bind(this),OrderByItemNode:this.transformOrderByItem.bind(this),GroupByNode:this.transformGroupBy.bind(this),GroupByItemNode:this.transformGroupByItem.bind(this),UpdateQueryNode:this.transformUpdateQuery.bind(this),ColumnUpdateNode:this.transformColumnUpdate.bind(this),LimitNode:this.transformLimit.bind(this),OffsetNode:this.transformOffset.bind(this),OnConflictNode:this.transformOnConflict.bind(this),OnDuplicateKeyNode:this.transformOnDuplicateKey.bind(this),CreateIndexNode:this.transformCreateIndex.bind(this),DropIndexNode:this.transformDropIndex.bind(this),ListNode:this.transformList.bind(this),PrimaryKeyConstraintNode:this.transformPrimaryKeyConstraint.bind(this),UniqueConstraintNode:this.transformUniqueConstraint.bind(this),ReferencesNode:this.transformReferences.bind(this),CheckConstraintNode:this.transformCheckConstraint.bind(this),WithNode:this.transformWith.bind(this),CommonTableExpressionNode:this.transformCommonTableExpression.bind(this),CommonTableExpressionNameNode:this.transformCommonTableExpressionName.bind(this),HavingNode:this.transformHaving.bind(this),CreateSchemaNode:this.transformCreateSchema.bind(this),DropSchemaNode:this.transformDropSchema.bind(this),AlterTableNode:this.transformAlterTable.bind(this),DropColumnNode:this.transformDropColumn.bind(this),RenameColumnNode:this.transformRenameColumn.bind(this),AlterColumnNode:this.transformAlterColumn.bind(this),ModifyColumnNode:this.transformModifyColumn.bind(this),AddConstraintNode:this.transformAddConstraint.bind(this),DropConstraintNode:this.transformDropConstraint.bind(this),ForeignKeyConstraintNode:this.transformForeignKeyConstraint.bind(this),CreateViewNode:this.transformCreateView.bind(this),DropViewNode:this.transformDropView.bind(this),GeneratedNode:this.transformGenerated.bind(this),DefaultValueNode:this.transformDefaultValue.bind(this),OnNode:this.transformOn.bind(this),ValuesNode:this.transformValues.bind(this),SelectModifierNode:this.transformSelectModifier.bind(this),CreateTypeNode:this.transformCreateType.bind(this),DropTypeNode:this.transformDropType.bind(this),ExplainNode:this.transformExplain.bind(this),DefaultInsertValueNode:this.transformDefaultInsertValue.bind(this),AggregateFunctionNode:this.transformAggregateFunction.bind(this),OverNode:this.transformOver.bind(this),PartitionByNode:this.transformPartitionBy.bind(this),PartitionByItemNode:this.transformPartitionByItem.bind(this),SetOperationNode:this.transformSetOperation.bind(this),BinaryOperationNode:this.transformBinaryOperation.bind(this),UnaryOperationNode:this.transformUnaryOperation.bind(this),UsingNode:this.transformUsing.bind(this),FunctionNode:this.transformFunction.bind(this),CaseNode:this.transformCase.bind(this),WhenNode:this.transformWhen.bind(this),JSONReferenceNode:this.transformJSONReference.bind(this),JSONPathNode:this.transformJSONPath.bind(this),JSONPathLegNode:this.transformJSONPathLeg.bind(this),JSONOperatorChainNode:this.transformJSONOperatorChain.bind(this),TupleNode:this.transformTuple.bind(this),MergeQueryNode:this.transformMergeQuery.bind(this),MatchedNode:this.transformMatched.bind(this),AddIndexNode:this.transformAddIndex.bind(this),CastNode:this.transformCast.bind(this),FetchNode:this.transformFetch.bind(this),TopNode:this.transformTop.bind(this),OutputNode:this.transformOutput.bind(this)});transformNode(e){if(!e)return e;this.nodeStack.push(e);let i=this.transformNodeImpl(e);return this.nodeStack.pop(),r(i)}transformNodeImpl(e){return this.#e[e.kind](e)}transformNodeList(e){return e&&r(e.map(i=>this.transformNode(i)))}transformSelectQuery(e){return{kind:"SelectQueryNode",from:this.transformNode(e.from),selections:this.transformNodeList(e.selections),distinctOn:this.transformNodeList(e.distinctOn),joins:this.transformNodeList(e.joins),groupBy:this.transformNode(e.groupBy),orderBy:this.transformNode(e.orderBy),where:this.transformNode(e.where),frontModifiers:this.transformNodeList(e.frontModifiers),endModifiers:this.transformNodeList(e.endModifiers),limit:this.transformNode(e.limit),offset:this.transformNode(e.offset),with:this.transformNode(e.with),having:this.transformNode(e.having),explain:this.transformNode(e.explain),setOperations:this.transformNodeList(e.setOperations),fetch:this.transformNode(e.fetch),top:this.transformNode(e.top)}}transformSelection(e){return{kind:"SelectionNode",selection:this.transformNode(e.selection)}}transformColumn(e){return{kind:"ColumnNode",column:this.transformNode(e.column)}}transformAlias(e){return{kind:"AliasNode",node:this.transformNode(e.node),alias:this.transformNode(e.alias)}}transformTable(e){return{kind:"TableNode",table:this.transformNode(e.table)}}transformFrom(e){return{kind:"FromNode",froms:this.transformNodeList(e.froms)}}transformReference(e){return{kind:"ReferenceNode",column:this.transformNode(e.column),table:this.transformNode(e.table)}}transformAnd(e){return{kind:"AndNode",left:this.transformNode(e.left),right:this.transformNode(e.right)}}transformOr(e){return{kind:"OrNode",left:this.transformNode(e.left),right:this.transformNode(e.right)}}transformValueList(e){return{kind:"ValueListNode",values:this.transformNodeList(e.values)}}transformParens(e){return{kind:"ParensNode",node:this.transformNode(e.node)}}transformJoin(e){return{kind:"JoinNode",joinType:e.joinType,table:this.transformNode(e.table),on:this.transformNode(e.on)}}transformRaw(e){return{kind:"RawNode",sqlFragments:r([...e.sqlFragments]),parameters:this.transformNodeList(e.parameters)}}transformWhere(e){return{kind:"WhereNode",where:this.transformNode(e.where)}}transformInsertQuery(e){return{kind:"InsertQueryNode",into:this.transformNode(e.into),columns:this.transformNodeList(e.columns),values:this.transformNode(e.values),returning:this.transformNode(e.returning),onConflict:this.transformNode(e.onConflict),onDuplicateKey:this.transformNode(e.onDuplicateKey),with:this.transformNode(e.with),ignore:e.ignore,replace:e.replace,explain:this.transformNode(e.explain),defaultValues:e.defaultValues,top:this.transformNode(e.top),output:this.transformNode(e.output)}}transformValues(e){return{kind:"ValuesNode",values:this.transformNodeList(e.values)}}transformDeleteQuery(e){return{kind:"DeleteQueryNode",from:this.transformNode(e.from),using:this.transformNode(e.using),joins:this.transformNodeList(e.joins),where:this.transformNode(e.where),returning:this.transformNode(e.returning),with:this.transformNode(e.with),orderBy:this.transformNode(e.orderBy),limit:this.transformNode(e.limit),explain:this.transformNode(e.explain),top:this.transformNode(e.top),output:this.transformNode(e.output)}}transformReturning(e){return{kind:"ReturningNode",selections:this.transformNodeList(e.selections)}}transformCreateTable(e){return{kind:"CreateTableNode",table:this.transformNode(e.table),columns:this.transformNodeList(e.columns),constraints:this.transformNodeList(e.constraints),temporary:e.temporary,ifNotExists:e.ifNotExists,onCommit:e.onCommit,frontModifiers:this.transformNodeList(e.frontModifiers),endModifiers:this.transformNodeList(e.endModifiers),selectQuery:this.transformNode(e.selectQuery)}}transformColumnDefinition(e){return{kind:"ColumnDefinitionNode",column:this.transformNode(e.column),dataType:this.transformNode(e.dataType),references:this.transformNode(e.references),primaryKey:e.primaryKey,autoIncrement:e.autoIncrement,unique:e.unique,notNull:e.notNull,unsigned:e.unsigned,defaultTo:this.transformNode(e.defaultTo),check:this.transformNode(e.check),generated:this.transformNode(e.generated),frontModifiers:this.transformNodeList(e.frontModifiers),endModifiers:this.transformNodeList(e.endModifiers),nullsNotDistinct:e.nullsNotDistinct,identity:e.identity,ifNotExists:e.ifNotExists}}transformAddColumn(e){return{kind:"AddColumnNode",column:this.transformNode(e.column)}}transformDropTable(e){return{kind:"DropTableNode",table:this.transformNode(e.table),ifExists:e.ifExists,cascade:e.cascade}}transformOrderBy(e){return{kind:"OrderByNode",items:this.transformNodeList(e.items)}}transformOrderByItem(e){return{kind:"OrderByItemNode",orderBy:this.transformNode(e.orderBy),direction:this.transformNode(e.direction)}}transformGroupBy(e){return{kind:"GroupByNode",items:this.transformNodeList(e.items)}}transformGroupByItem(e){return{kind:"GroupByItemNode",groupBy:this.transformNode(e.groupBy)}}transformUpdateQuery(e){return{kind:"UpdateQueryNode",table:this.transformNode(e.table),from:this.transformNode(e.from),joins:this.transformNodeList(e.joins),where:this.transformNode(e.where),updates:this.transformNodeList(e.updates),returning:this.transformNode(e.returning),with:this.transformNode(e.with),explain:this.transformNode(e.explain),limit:this.transformNode(e.limit),top:this.transformNode(e.top),output:this.transformNode(e.output)}}transformColumnUpdate(e){return{kind:"ColumnUpdateNode",column:this.transformNode(e.column),value:this.transformNode(e.value)}}transformLimit(e){return{kind:"LimitNode",limit:this.transformNode(e.limit)}}transformOffset(e){return{kind:"OffsetNode",offset:this.transformNode(e.offset)}}transformOnConflict(e){return{kind:"OnConflictNode",columns:this.transformNodeList(e.columns),constraint:this.transformNode(e.constraint),indexExpression:this.transformNode(e.indexExpression),indexWhere:this.transformNode(e.indexWhere),updates:this.transformNodeList(e.updates),updateWhere:this.transformNode(e.updateWhere),doNothing:e.doNothing}}transformOnDuplicateKey(e){return{kind:"OnDuplicateKeyNode",updates:this.transformNodeList(e.updates)}}transformCreateIndex(e){return{kind:"CreateIndexNode",name:this.transformNode(e.name),table:this.transformNode(e.table),columns:this.transformNodeList(e.columns),unique:e.unique,using:this.transformNode(e.using),ifNotExists:e.ifNotExists,where:this.transformNode(e.where),nullsNotDistinct:e.nullsNotDistinct}}transformList(e){return{kind:"ListNode",items:this.transformNodeList(e.items)}}transformDropIndex(e){return{kind:"DropIndexNode",name:this.transformNode(e.name),table:this.transformNode(e.table),ifExists:e.ifExists,cascade:e.cascade}}transformPrimaryKeyConstraint(e){return{kind:"PrimaryKeyConstraintNode",columns:this.transformNodeList(e.columns),name:this.transformNode(e.name)}}transformUniqueConstraint(e){return{kind:"UniqueConstraintNode",columns:this.transformNodeList(e.columns),name:this.transformNode(e.name),nullsNotDistinct:e.nullsNotDistinct}}transformForeignKeyConstraint(e){return{kind:"ForeignKeyConstraintNode",columns:this.transformNodeList(e.columns),references:this.transformNode(e.references),name:this.transformNode(e.name),onDelete:e.onDelete,onUpdate:e.onUpdate}}transformSetOperation(e){return{kind:"SetOperationNode",operator:e.operator,expression:this.transformNode(e.expression),all:e.all}}transformReferences(e){return{kind:"ReferencesNode",table:this.transformNode(e.table),columns:this.transformNodeList(e.columns),onDelete:e.onDelete,onUpdate:e.onUpdate}}transformCheckConstraint(e){return{kind:"CheckConstraintNode",expression:this.transformNode(e.expression),name:this.transformNode(e.name)}}transformWith(e){return{kind:"WithNode",expressions:this.transformNodeList(e.expressions),recursive:e.recursive}}transformCommonTableExpression(e){return{kind:"CommonTableExpressionNode",name:this.transformNode(e.name),materialized:e.materialized,expression:this.transformNode(e.expression)}}transformCommonTableExpressionName(e){return{kind:"CommonTableExpressionNameNode",table:this.transformNode(e.table),columns:this.transformNodeList(e.columns)}}transformHaving(e){return{kind:"HavingNode",having:this.transformNode(e.having)}}transformCreateSchema(e){return{kind:"CreateSchemaNode",schema:this.transformNode(e.schema),ifNotExists:e.ifNotExists}}transformDropSchema(e){return{kind:"DropSchemaNode",schema:this.transformNode(e.schema),ifExists:e.ifExists,cascade:e.cascade}}transformAlterTable(e){return{kind:"AlterTableNode",table:this.transformNode(e.table),renameTo:this.transformNode(e.renameTo),setSchema:this.transformNode(e.setSchema),columnAlterations:this.transformNodeList(e.columnAlterations),addConstraint:this.transformNode(e.addConstraint),dropConstraint:this.transformNode(e.dropConstraint),addIndex:this.transformNode(e.addIndex),dropIndex:this.transformNode(e.dropIndex)}}transformDropColumn(e){return{kind:"DropColumnNode",column:this.transformNode(e.column)}}transformRenameColumn(e){return{kind:"RenameColumnNode",column:this.transformNode(e.column),renameTo:this.transformNode(e.renameTo)}}transformAlterColumn(e){return{kind:"AlterColumnNode",column:this.transformNode(e.column),dataType:this.transformNode(e.dataType),dataTypeExpression:this.transformNode(e.dataTypeExpression),setDefault:this.transformNode(e.setDefault),dropDefault:e.dropDefault,setNotNull:e.setNotNull,dropNotNull:e.dropNotNull}}transformModifyColumn(e){return{kind:"ModifyColumnNode",column:this.transformNode(e.column)}}transformAddConstraint(e){return{kind:"AddConstraintNode",constraint:this.transformNode(e.constraint)}}transformDropConstraint(e){return{kind:"DropConstraintNode",constraintName:this.transformNode(e.constraintName),ifExists:e.ifExists,modifier:e.modifier}}transformCreateView(e){return{kind:"CreateViewNode",name:this.transformNode(e.name),temporary:e.temporary,orReplace:e.orReplace,ifNotExists:e.ifNotExists,materialized:e.materialized,columns:this.transformNodeList(e.columns),as:this.transformNode(e.as)}}transformDropView(e){return{kind:"DropViewNode",name:this.transformNode(e.name),ifExists:e.ifExists,materialized:e.materialized,cascade:e.cascade}}transformGenerated(e){return{kind:"GeneratedNode",byDefault:e.byDefault,always:e.always,identity:e.identity,stored:e.stored,expression:this.transformNode(e.expression)}}transformDefaultValue(e){return{kind:"DefaultValueNode",defaultValue:this.transformNode(e.defaultValue)}}transformOn(e){return{kind:"OnNode",on:this.transformNode(e.on)}}transformSelectModifier(e){return{kind:"SelectModifierNode",modifier:e.modifier,rawModifier:this.transformNode(e.rawModifier),of:this.transformNodeList(e.of)}}transformCreateType(e){return{kind:"CreateTypeNode",name:this.transformNode(e.name),enum:this.transformNode(e.enum)}}transformDropType(e){return{kind:"DropTypeNode",name:this.transformNode(e.name),ifExists:e.ifExists}}transformExplain(e){return{kind:"ExplainNode",format:e.format,options:this.transformNode(e.options)}}transformSchemableIdentifier(e){return{kind:"SchemableIdentifierNode",schema:this.transformNode(e.schema),identifier:this.transformNode(e.identifier)}}transformAggregateFunction(e){return{kind:"AggregateFunctionNode",aggregated:this.transformNodeList(e.aggregated),distinct:e.distinct,filter:this.transformNode(e.filter),func:e.func,over:this.transformNode(e.over)}}transformOver(e){return{kind:"OverNode",orderBy:this.transformNode(e.orderBy),partitionBy:this.transformNode(e.partitionBy)}}transformPartitionBy(e){return{kind:"PartitionByNode",items:this.transformNodeList(e.items)}}transformPartitionByItem(e){return{kind:"PartitionByItemNode",partitionBy:this.transformNode(e.partitionBy)}}transformBinaryOperation(e){return{kind:"BinaryOperationNode",leftOperand:this.transformNode(e.leftOperand),operator:this.transformNode(e.operator),rightOperand:this.transformNode(e.rightOperand)}}transformUnaryOperation(e){return{kind:"UnaryOperationNode",operator:this.transformNode(e.operator),operand:this.transformNode(e.operand)}}transformUsing(e){return{kind:"UsingNode",tables:this.transformNodeList(e.tables)}}transformFunction(e){return{kind:"FunctionNode",func:e.func,arguments:this.transformNodeList(e.arguments)}}transformCase(e){return{kind:"CaseNode",value:this.transformNode(e.value),when:this.transformNodeList(e.when),else:this.transformNode(e.else),isStatement:e.isStatement}}transformWhen(e){return{kind:"WhenNode",condition:this.transformNode(e.condition),result:this.transformNode(e.result)}}transformJSONReference(e){return{kind:"JSONReferenceNode",reference:this.transformNode(e.reference),traversal:this.transformNode(e.traversal)}}transformJSONPath(e){return{kind:"JSONPathNode",inOperator:this.transformNode(e.inOperator),pathLegs:this.transformNodeList(e.pathLegs)}}transformJSONPathLeg(e){return{kind:"JSONPathLegNode",type:e.type,value:e.value}}transformJSONOperatorChain(e){return{kind:"JSONOperatorChainNode",operator:this.transformNode(e.operator),values:this.transformNodeList(e.values)}}transformTuple(e){return{kind:"TupleNode",values:this.transformNodeList(e.values)}}transformMergeQuery(e){return{kind:"MergeQueryNode",into:this.transformNode(e.into),using:this.transformNode(e.using),whens:this.transformNodeList(e.whens),with:this.transformNode(e.with),top:this.transformNode(e.top),output:this.transformNode(e.output)}}transformMatched(e){return{kind:"MatchedNode",not:e.not,bySource:e.bySource}}transformAddIndex(e){return{kind:"AddIndexNode",name:this.transformNode(e.name),columns:this.transformNodeList(e.columns),unique:e.unique,using:this.transformNode(e.using),ifNotExists:e.ifNotExists}}transformCast(e){return{kind:"CastNode",expression:this.transformNode(e.expression),dataType:this.transformNode(e.dataType)}}transformFetch(e){return{kind:"FetchNode",rowCount:this.transformNode(e.rowCount),modifier:e.modifier}}transformTop(e){return{kind:"TopNode",expression:e.expression,modifiers:e.modifiers}}transformOutput(e){return{kind:"OutputNode",selections:this.transformNodeList(e.selections)}}transformDataType(e){return e}transformSelectAll(e){return e}transformIdentifier(e){return e}transformValue(e){return e}transformPrimitiveValueList(e){return e}transformOperator(e){return e}transformDefaultInsertValue(e){return e}};var Yo=r({AlterTableNode:!0,CreateIndexNode:!0,CreateSchemaNode:!0,CreateTableNode:!0,CreateTypeNode:!0,CreateViewNode:!0,DeleteQueryNode:!0,DropIndexNode:!0,DropSchemaNode:!0,DropTableNode:!0,DropTypeNode:!0,DropViewNode:!0,InsertQueryNode:!0,RawNode:!0,SelectQueryNode:!0,UpdateQueryNode:!0,MergeQueryNode:!0}),ur=class extends be{#e;#t=new Set;#r=new Set;constructor(e){super(),this.#e=e}transformNodeImpl(e){if(!this.#i(e))return super.transformNodeImpl(e);let i=this.#s(e);for(let u of i)this.#r.add(u);let o=this.#o(e);for(let u of o)this.#t.add(u);let n=super.transformNodeImpl(e);for(let u of o)this.#t.delete(u);for(let u of i)this.#r.delete(u);return n}transformSchemableIdentifier(e){let i=super.transformSchemableIdentifier(e);return i.schema||!this.#t.has(e.identifier.name)?i:{...i,schema:d.create(this.#e)}}transformReferences(e){let i=super.transformReferences(e);return i.table.table.schema?i:{...i,table:K.createWithSchema(this.#e,i.table.table.identifier.name)}}#i(e){return e.kind in Yo}#o(e){let i=new Set;if("name"in e&&e.name&&F.is(e.name)&&this.#a(e.name,i),"from"in e&&e.from)for(let o of e.from.froms)this.#n(o,i);if("into"in e&&e.into&&this.#n(e.into,i),"table"in e&&e.table&&this.#n(e.table,i),"joins"in e&&e.joins)for(let o of e.joins)this.#n(o.table,i);return"using"in e&&e.using&&this.#n(e.using,i),i}#s(e){let i=new Set;return"with"in e&&e.with&&this.#u(e.with,i),i}#n(e,i){let o=K.is(e)?e:D.is(e)&&K.is(e.node)?e.node:null;o&&this.#a(o.table,i)}#a(e,i){let o=e.identifier.name;!this.#t.has(o)&&!this.#r.has(o)&&i.add(o)}#u(e,i){for(let o of e.expressions){let n=o.name.table.table.identifier.name;this.#r.has(n)||i.add(n)}}};var Z=class{#e;constructor(e){this.#e=new ur(e)}transformQuery(e){return this.#e.transformNode(e.node)}async transformResult(e){return e.result}};var eo=r({is(t){return t.kind==="MatchedNode"},create(t,e=!1){return r({kind:"MatchedNode",not:t,bySource:e})}});function oi(t,e,i){return le.create(Ke([eo.create(!t.isMatched,t.bySource),...e&&e.length>0?[e.length===3&&i?W(e[0],e[1],e[2]):y(e)]:[]],"and",!1))}function Xe(t){return g(t)?C.create([t],[]):x(t)?t.toOperationNode():t}var Wt=class{#e;#t;#r;constructor(){this.#e=new Promise((e,i)=>{this.#r=i,this.#t=e})}get promise(){return this.#e}resolve=e=>{this.#t&&this.#t(e)};reject=e=>{this.#r&&this.#r(e)}};var to=new Set;function ro(t){to.has(t)||(to.add(t),console.log(t))}var Xo=r([]),Ze=class{#e;constructor(e=Xo){this.#e=e}get plugins(){return this.#e}transformQuery(e,i){for(let o of this.#e){let n=o.transformQuery({node:e,queryId:i});if(n.kind===e.kind)e=n;else throw new Error(["KyselyPlugin.transformQuery must return a node","of the same kind that was given to it.",`The plugin was given a ${e.kind}`,`but it returned a ${n.kind}`].join(" "))}return e}async executeQuery(e,i){return await this.provideConnection(async o=>{let n=await o.executeQuery(e),u=await this.#t(n,i);return Zo(n,u),u})}async*stream(e,i,o){let n=new Wt,u=new Wt;this.provideConnection(async L=>(n.resolve(L),await u.promise)).catch(L=>n.reject(L));let v=await n.promise;try{for await(let L of v.streamQuery(e,i))yield await this.#t(L,o)}finally{u.resolve()}}async#t(e,i){for(let o of this.#e)e=await o.transformResult({result:e,queryId:i});return e}};function Zo(t,e){let{numAffectedRows:i}=t;i===void 0&&t.numUpdatedOrDeletedRows===void 0||i!==void 0&&e.numAffectedRows!==void 0||ro("kysely:warning: outdated driver/plugin detected! QueryResult.numUpdatedOrDeletedRows is deprecated and will be removed in a future release.")}var ni=class t extends Ze{get adapter(){throw new Error("this query cannot be compiled to SQL")}compileQuery(){throw new Error("this query cannot be compiled to SQL")}provideConnection(){throw new Error("this query cannot be executed")}withConnectionProvider(){throw new Error("this query cannot have a connection provider")}withPlugin(e){return new t([...this.plugins,e])}withPlugins(e){return new t([...this.plugins,...e])}withPluginAtFront(e){return new t([e,...this.plugins])}withoutPlugins(){return new t([])}},We=new ni;var dr=class{numChangedRows;constructor(e){this.numChangedRows=e}};var qt=class t{#e;constructor(e){this.#e=r(e)}top(e,i){return new t({...this.#e,queryNode:a.cloneWithTop(this.#e.queryNode,X(e,i))})}using(...e){return new fe({...this.#e,queryNode:T.cloneWithUsing(this.#e.queryNode,b("Using",e))})}output(e){return new t({...this.#e,queryNode:a.cloneWithOutput(this.#e.queryNode,k(e))})}outputAll(e){return new t({...this.#e,queryNode:a.cloneWithOutput(this.#e.queryNode,B(e))})}};s(qt,"don't await MergeQueryBuilder instances directly. To execute the query you need to call `execute` when available.");var fe=class t{#e;constructor(e){this.#e=r(e)}top(e,i){return new t({...this.#e,queryNode:a.cloneWithTop(this.#e.queryNode,X(e,i))})}whenMatched(){return this.#t([])}whenMatchedAnd(...e){return this.#t(e)}whenMatchedAndRef(e,i,o){return this.#t([e,i,o],!0)}#t(e,i){return new Tt({...this.#e,queryNode:T.cloneWithWhen(this.#e.queryNode,oi({isMatched:!0},e,i))})}whenNotMatched(){return this.#r([])}whenNotMatchedAnd(...e){return this.#r(e)}whenNotMatchedAndRef(e,i,o){return this.#r([e,i,o],!0)}whenNotMatchedBySource(){return this.#r([],!1,!0)}whenNotMatchedBySourceAnd(...e){return this.#r(e,!1,!0)}whenNotMatchedBySourceAndRef(e,i,o){return this.#r([e,i,o],!0,!0)}output(e){return new t({...this.#e,queryNode:a.cloneWithOutput(this.#e.queryNode,k(e))})}outputAll(e){return new t({...this.#e,queryNode:a.cloneWithOutput(this.#e.queryNode,B(e))})}#r(e,i=!1,o=!1){let n={...this.#e,queryNode:T.cloneWithWhen(this.#e.queryNode,oi({isMatched:!1,bySource:o},e,i))},u=o?Tt:pr;return new u(n)}$call(e){return e(this)}$if(e,i){return e?i(this):new t({...this.#e})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile(),i=await this.#e.executor.executeQuery(e,this.#e.queryId);return e.query.output&&this.#e.executor.adapter.supportsOutput?i.rows:[new dr(i.numAffectedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=j){let i=await this.executeTakeFirst();if(i===void 0)throw se(e)?new e(this.toOperationNode()):e(this.toOperationNode());return i}};s(fe,"don't await WheneableMergeQueryBuilder instances directly. To execute the query you need to call `execute`.");var Tt=class{#e;constructor(e){this.#e=r(e)}thenDelete(){return new fe({...this.#e,queryNode:T.cloneWithThen(this.#e.queryNode,Xe("delete"))})}thenDoNothing(){return new fe({...this.#e,queryNode:T.cloneWithThen(this.#e.queryNode,Xe("do nothing"))})}thenUpdate(e){return new fe({...this.#e,queryNode:T.cloneWithThen(this.#e.queryNode,Xe(e(new Re({queryId:this.#e.queryId,executor:We,queryNode:oe.createWithoutTable()}))))})}thenUpdateSet(...e){return this.thenUpdate(i=>i.set(...e))}};s(Tt,"don't await MatchedThenableMergeQueryBuilder instances directly. To execute the query you need to call `execute` when available.");var pr=class{#e;constructor(e){this.#e=r(e)}thenDoNothing(){return new fe({...this.#e,queryNode:T.cloneWithThen(this.#e.queryNode,Xe("do nothing"))})}thenInsertValues(e){let[i,o]=rr(e);return new fe({...this.#e,queryNode:T.cloneWithThen(this.#e.queryNode,Xe(q.cloneWith(q.createWithoutInto(),{columns:i,values:o})))})}};s(pr,"don't await NotMatchedThenableMergeQueryBuilder instances directly. To execute the query you need to call `execute` when available.");var _e=class t{#e;constructor(e){this.#e=r(e)}selectFrom(e){return It({queryId:m(),executor:this.#e.executor,queryNode:p.createFrom(ae(e),this.#e.withNode)})}selectNoFrom(e){return It({queryId:m(),executor:this.#e.executor,queryNode:p.cloneWithSelections(p.create(this.#e.withNode),k(e))})}insertInto(e){return new Ge({queryId:m(),executor:this.#e.executor,queryNode:q.create(l(e),this.#e.withNode)})}replaceInto(e){return new Ge({queryId:m(),executor:this.#e.executor,queryNode:q.create(l(e),this.#e.withNode,!0)})}deleteFrom(e){return new vt({queryId:m(),executor:this.#e.executor,queryNode:ne.create(ae(e),this.#e.withNode)})}updateTable(e){return new Re({queryId:m(),executor:this.#e.executor,queryNode:oe.create(qe(e),this.#e.withNode)})}mergeInto(e){return new qt({queryId:m(),executor:this.#e.executor,queryNode:T.create(si(e),this.#e.withNode)})}with(e,i){let o=ri(e,i);return new t({...this.#e,withNode:this.#e.withNode?bt.cloneWithExpression(this.#e.withNode,o):bt.create(o)})}withRecursive(e,i){let o=ri(e,i);return new t({...this.#e,withNode:this.#e.withNode?bt.cloneWithExpression(this.#e.withNode,o):bt.create(o,{recursive:!0})})}withPlugin(e){return new t({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new t({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new t({...this.#e,executor:this.#e.executor.withPluginAtFront(new Z(e))})}};function Xi(){return new _e({executor:We})}function io(t,e){return new wt({joinNode:Oe.create(t,qe(e))})}function oo(){return new xt({overNode:yt.create()})}function b(t,e){if(e.length===3)return en(t,e[0],e[1],e[2]);if(e.length===2)return _o(t,e[0],e[1]);throw new Error("not implemented")}function _o(t,e,i){return i(io(t,e)).toOperationNode()}function en(t,e,i,o){return Oe.createWithOn(t,qe(e),W(i,"=",o))}var no=r({is(t){return t.kind==="OffsetNode"},create(t){return r({kind:"OffsetNode",offset:t})}});var so=r({is(t){return t.kind==="GroupByItemNode"},create(t){return r({kind:"GroupByItemNode",groupBy:t})}});function ao(t){return t=O(t)?t(Y()):t,ce(t).map(so.create)}var hr=r({is(t){return t.kind==="SetOperationNode"},create(t,e,i){return r({kind:"SetOperationNode",operator:t,expression:e,all:i})}});function De(t,e,i){return O(e)&&(e=e(cr())),E(e)||(e=[e]),e.map(o=>hr.create(t,V(o),i))}var f=class t{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new St(this,e)}or(...e){return new ai(H.create(this.#e,y(e)))}and(...e){return new ui(M.create(this.#e,y(e)))}$castTo(){return new t(this.#e)}$notNull(){return new t(this.#e)}toOperationNode(){return this.#e}},St=class{#e;#t;constructor(e,i){this.#e=e,this.#t=i}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return D.create(this.#e.toOperationNode(),x(this.#t)?this.#t.toOperationNode():d.create(this.#t))}},ai=class t{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new St(this,e)}or(...e){return new t(H.create(this.#e,y(e)))}$castTo(){return new t(this.#e)}toOperationNode(){return ie.create(this.#e)}},ui=class t{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new St(this,e)}and(...e){return new t(M.create(this.#e,y(e)))}$castTo(){return new t(this.#e)}toOperationNode(){return ie.create(this.#e)}};var uo={is(t){return t.kind==="FetchNode"},create(t,e){return{kind:"FetchNode",rowCount:S.create(t),modifier:e}}};function po(t,e){if(!we(t)&&!Me(t))throw new Error(`Invalid fetch row count: ${t}`);if(!tn(e))throw new Error(`Invalid fetch modifier: ${e}`);return uo.create(t,e)}function tn(t){return t==="only"||t==="with ties"}var mr=class t{#e;constructor(e){this.#e=r(e)}get expressionType(){}get isSelectQueryBuilder(){return!0}where(...e){return new t({...this.#e,queryNode:a.cloneWithWhere(this.#e.queryNode,y(e))})}whereRef(e,i,o){return new t({...this.#e,queryNode:a.cloneWithWhere(this.#e.queryNode,W(e,i,o))})}having(...e){return new t({...this.#e,queryNode:p.cloneWithHaving(this.#e.queryNode,y(e))})}havingRef(e,i,o){return new t({...this.#e,queryNode:p.cloneWithHaving(this.#e.queryNode,W(e,i,o))})}select(e){return new t({...this.#e,queryNode:p.cloneWithSelections(this.#e.queryNode,k(e))})}distinctOn(e){return new t({...this.#e,queryNode:p.cloneWithDistinctOn(this.#e.queryNode,ce(e))})}modifyFront(e){return new t({...this.#e,queryNode:p.cloneWithFrontModifier(this.#e.queryNode,re.createWithExpression(e.toOperationNode()))})}modifyEnd(e){return new t({...this.#e,queryNode:p.cloneWithEndModifier(this.#e.queryNode,re.createWithExpression(e.toOperationNode()))})}distinct(){return new t({...this.#e,queryNode:p.cloneWithFrontModifier(this.#e.queryNode,re.create("Distinct"))})}forUpdate(e){return new t({...this.#e,queryNode:p.cloneWithEndModifier(this.#e.queryNode,re.create("ForUpdate",e?mt(e).map(l):void 0))})}forShare(e){return new t({...this.#e,queryNode:p.cloneWithEndModifier(this.#e.queryNode,re.create("ForShare",e?mt(e).map(l):void 0))})}forKeyShare(e){return new t({...this.#e,queryNode:p.cloneWithEndModifier(this.#e.queryNode,re.create("ForKeyShare",e?mt(e).map(l):void 0))})}forNoKeyUpdate(e){return new t({...this.#e,queryNode:p.cloneWithEndModifier(this.#e.queryNode,re.create("ForNoKeyUpdate",e?mt(e).map(l):void 0))})}skipLocked(){return new t({...this.#e,queryNode:p.cloneWithEndModifier(this.#e.queryNode,re.create("SkipLocked"))})}noWait(){return new t({...this.#e,queryNode:p.cloneWithEndModifier(this.#e.queryNode,re.create("NoWait"))})}selectAll(e){return new t({...this.#e,queryNode:p.cloneWithSelections(this.#e.queryNode,B(e))})}innerJoin(...e){return new t({...this.#e,queryNode:a.cloneWithJoin(this.#e.queryNode,b("InnerJoin",e))})}leftJoin(...e){return new t({...this.#e,queryNode:a.cloneWithJoin(this.#e.queryNode,b("LeftJoin",e))})}rightJoin(...e){return new t({...this.#e,queryNode:a.cloneWithJoin(this.#e.queryNode,b("RightJoin",e))})}fullJoin(...e){return new t({...this.#e,queryNode:a.cloneWithJoin(this.#e.queryNode,b("FullJoin",e))})}innerJoinLateral(...e){return new t({...this.#e,queryNode:a.cloneWithJoin(this.#e.queryNode,b("LateralInnerJoin",e))})}leftJoinLateral(...e){return new t({...this.#e,queryNode:a.cloneWithJoin(this.#e.queryNode,b("LateralLeftJoin",e))})}orderBy(...e){return new t({...this.#e,queryNode:p.cloneWithOrderByItems(this.#e.queryNode,ve(e))})}groupBy(e){return new t({...this.#e,queryNode:p.cloneWithGroupByItems(this.#e.queryNode,ao(e))})}limit(e){return new t({...this.#e,queryNode:p.cloneWithLimit(this.#e.queryNode,He.create(N(e)))})}offset(e){return new t({...this.#e,queryNode:p.cloneWithOffset(this.#e.queryNode,no.create(N(e)))})}fetch(e,i="only"){return new t({...this.#e,queryNode:p.cloneWithFetch(this.#e.queryNode,po(e,i))})}top(e,i){return new t({...this.#e,queryNode:a.cloneWithTop(this.#e.queryNode,X(e,i))})}union(e){return new t({...this.#e,queryNode:p.cloneWithSetOperations(this.#e.queryNode,De("union",e,!1))})}unionAll(e){return new t({...this.#e,queryNode:p.cloneWithSetOperations(this.#e.queryNode,De("union",e,!0))})}intersect(e){return new t({...this.#e,queryNode:p.cloneWithSetOperations(this.#e.queryNode,De("intersect",e,!1))})}intersectAll(e){return new t({...this.#e,queryNode:p.cloneWithSetOperations(this.#e.queryNode,De("intersect",e,!0))})}except(e){return new t({...this.#e,queryNode:p.cloneWithSetOperations(this.#e.queryNode,De("except",e,!1))})}exceptAll(e){return new t({...this.#e,queryNode:p.cloneWithSetOperations(this.#e.queryNode,De("except",e,!0))})}as(e){return new lr(this,e)}clearSelect(){return new t({...this.#e,queryNode:p.cloneWithoutSelections(this.#e.queryNode)})}clearWhere(){return new t({...this.#e,queryNode:a.cloneWithoutWhere(this.#e.queryNode)})}clearLimit(){return new t({...this.#e,queryNode:p.cloneWithoutLimit(this.#e.queryNode)})}clearOffset(){return new t({...this.#e,queryNode:p.cloneWithoutOffset(this.#e.queryNode)})}clearOrderBy(){return new t({...this.#e,queryNode:p.cloneWithoutOrderBy(this.#e.queryNode)})}clearGroupBy(){return new t({...this.#e,queryNode:p.cloneWithoutGroupBy(this.#e.queryNode)})}$call(e){return e(this)}$if(e,i){return e?i(this):new t({...this.#e})}$castTo(){return new t(this.#e)}$narrowType(){return new t(this.#e)}$assertType(){return new t(this.#e)}$asTuple(){return new f(this.toOperationNode())}withPlugin(e){return new t({...this.#e,executor:this.#e.executor.withPlugin(e)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile();return(await this.#e.executor.executeQuery(e,this.#e.queryId)).rows}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=j){let i=await this.executeTakeFirst();if(i===void 0)throw se(e)?new e(this.toOperationNode()):e(this.toOperationNode());return i}async*stream(e=100){let i=this.compile(),o=this.#e.executor.stream(i,e,this.#e.queryId);for await(let n of o)yield*n.rows}async explain(e,i){return await new t({...this.#e,queryNode:a.cloneWithExplain(this.#e.queryNode,e,i)}).execute()}};s(mr,"don't await SelectQueryBuilder instances directly. To execute the query you need to call `execute` or `executeTakeFirst`.");function It(t){return new mr(t)}var lr=class{#e;#t;constructor(e,i){this.#e=e,this.#t=i}get expression(){return this.#e}get alias(){return this.#t}get isAliasedSelectQueryBuilder(){return!0}toOperationNode(){return D.create(this.#e.toOperationNode(),d.create(this.#t))}};s(lr,"don't await AliasedSelectQueryBuilder instances directly. AliasedSelectQueryBuilder should never be executed directly since it's always a part of another query.");var Ne=r({is(t){return t.kind==="AggregateFunctionNode"},create(t,e=[]){return r({kind:"AggregateFunctionNode",func:t,aggregated:e})},cloneWithDistinct(t){return r({...t,distinct:!0})},cloneWithFilter(t,e){return r({...t,filter:t.filter?A.cloneWithOperation(t.filter,"And",e):A.create(e)})},cloneWithOrFilter(t,e){return r({...t,filter:t.filter?A.cloneWithOperation(t.filter,"Or",e):A.create(e)})},cloneWithOver(t,e){return r({...t,over:e})}});var di=r({is(t){return t.kind==="FunctionNode"},create(t,e){return r({kind:"FunctionNode",func:t,arguments:e})}});var Be=class t{#e;constructor(e){this.#e=r(e)}get expressionType(){}as(e){return new pi(this,e)}distinct(){return new t({...this.#e,aggregateFunctionNode:Ne.cloneWithDistinct(this.#e.aggregateFunctionNode)})}filterWhere(...e){return new t({...this.#e,aggregateFunctionNode:Ne.cloneWithFilter(this.#e.aggregateFunctionNode,y(e))})}filterWhereRef(e,i,o){return new t({...this.#e,aggregateFunctionNode:Ne.cloneWithFilter(this.#e.aggregateFunctionNode,W(e,i,o))})}over(e){let i=oo();return new t({...this.#e,aggregateFunctionNode:Ne.cloneWithOver(this.#e.aggregateFunctionNode,(e?e(i):i).toOperationNode())})}$call(e){return e(this)}$castTo(){return new t(this.#e)}$notNull(){return new t(this.#e)}toOperationNode(){return this.#e.aggregateFunctionNode}};s(Be,"don't await AggregateFunctionBuilder instances. They are never executed directly and are always just a part of a query.");var pi=class{#e;#t;constructor(e,i){this.#e=e,this.#t=i}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return D.create(this.#e.toOperationNode(),d.create(this.#t))}};function fr(){let t=(i,o)=>new f(di.create(i,ce(o??[]))),e=(i,o)=>new Be({aggregateFunctionNode:Ne.create(i,o?ce(o):void 0)});return Object.assign(t,{agg:e,avg(i){return e("avg",[i])},coalesce(...i){return t("coalesce",i)},count(i){return e("count",[i])},countAll(i){return new Be({aggregateFunctionNode:Ne.create("count",B(i))})},max(i){return e("max",[i])},min(i){return e("min",[i])},sum(i){return e("sum",[i])},any(i){return t("any",[i])},jsonAgg(i){return new Be({aggregateFunctionNode:Ne.create("json_agg",[g(i)?l(i):i.toOperationNode()])})},toJson(i){return new f(di.create("to_json",[g(i)?l(i):i.toOperationNode()]))}})}var ho=r({is(t){return t.kind==="UnaryOperationNode"},create(t,e){return r({kind:"UnaryOperationNode",operator:t,operand:e})}});function co(t,e){return ho.create(U.create(t),I(e))}var $=r({is(t){return t.kind==="CaseNode"},create(t){return r({kind:"CaseNode",value:t})},cloneWithWhen(t,e){return r({...t,when:r(t.when?[...t.when,e]:[e])})},cloneWithThen(t,e){return r({...t,when:t.when?r([...t.when.slice(0,-1),le.cloneWithResult(t.when[t.when.length-1],e)]):void 0})},cloneWith(t,e){return r({...t,...e})}});var et=class{#e;constructor(e){this.#e=r(e)}when(...e){return new Nr({...this.#e,node:$.cloneWithWhen(this.#e.node,le.create(y(e)))})}},Nr=class{#e;constructor(e){this.#e=r(e)}then(e){return new hi({...this.#e,node:$.cloneWithThen(this.#e.node,_t(e)?Nt(e):N(e))})}},hi=class{#e;constructor(e){this.#e=r(e)}when(...e){return new Nr({...this.#e,node:$.cloneWithWhen(this.#e.node,le.create(y(e)))})}else(e){return new ci({...this.#e,node:$.cloneWith(this.#e.node,{else:_t(e)?Nt(e):N(e)})})}end(){return new f($.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new f($.cloneWith(this.#e.node,{isStatement:!0}))}},ci=class{#e;constructor(e){this.#e=r(e)}end(){return new f($.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new f($.cloneWith(this.#e.node,{isStatement:!0}))}};var mi=r({is(t){return t.kind==="JSONPathLegNode"},create(t,e){return r({kind:"JSONPathLegNode",type:t,value:e})}});var Te=class{#e;constructor(e){this.#e=e}at(e){return this.#t("ArrayLocation",e)}key(e){return this.#t("Member",e)}#t(e,i){return Ue.is(this.#e)?new yr(Ue.cloneWithTraversal(this.#e,Ce.is(this.#e.traversal)?Ce.cloneWithLeg(this.#e.traversal,mi.create(e,i)):Xt.cloneWithValue(this.#e.traversal,S.createImmediate(i)))):new yr(Ce.cloneWithLeg(this.#e,mi.create(e,i)))}},yr=class extends Te{#e;constructor(e){super(e),this.#e=e}get expressionType(){}as(e){return new li(this,e)}$castTo(){return new Te(this.#e)}$notNull(){return new Te(this.#e)}toOperationNode(){return this.#e}},li=class{#e;#t;constructor(e,i){this.#e=e,this.#t=i}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return D.create(this.#e.toOperationNode(),x(this.#t)?this.#t.toOperationNode():d.create(this.#t))}};var fi=r({is(t){return t.kind==="TupleNode"},create(t){return r({kind:"TupleNode",values:r(t)})}});var rn=["varchar","char","text","integer","int2","int4","int8","smallint","bigint","boolean","real","double precision","float4","float8","decimal","numeric","binary","bytea","date","datetime","time","timetz","timestamp","timestamptz","serial","bigserial","uuid","json","jsonb","blob","varbinary"],on=[/^varchar\(\d+\)$/,/^char\(\d+\)$/,/^decimal\(\d+, \d+\)$/,/^numeric\(\d+, \d+\)$/,/^binary\(\d+\)$/,/^datetime\(\d+\)$/,/^time\(\d+\)$/,/^timetz\(\d+\)$/,/^timestamp\(\d+\)$/,/^timestamptz\(\d+\)$/,/^varbinary\(\d+\)$/],mo=r({is(t){return t.kind==="DataTypeNode"},create(t){return r({kind:"DataTypeNode",dataType:t})}});function lo(t){return!!(rn.includes(t)||on.some(e=>e.test(t)))}function _(t){if(x(t))return t.toOperationNode();if(lo(t))return mo.create(t);throw new Error(`invalid column data type ${JSON.stringify(t)}`)}var fo=r({is(t){return t.kind==="CastNode"},create(t,e){return r({kind:"CastNode",expression:t,dataType:e})}});function cr(t=We){function e(n,u,v){return new f(er(n,u,v))}function i(n,u){return new f(co(n,u))}let o=Object.assign(e,{fn:void 0,eb:void 0,selectFrom(n){return It({queryId:m(),executor:t,queryNode:p.createFrom(ae(n))})},case(n){return new et({node:$.create(z(n)?void 0:I(n))})},ref(n,u){return z(u)?new f(J(n)):new Te(Bi(n,u))},jsonPath(){return new Te(Ce.create())},table(n){return new f(l(n))},val(n){return new f(N(n))},refTuple(...n){return new f(fi.create(n.map(I)))},tuple(...n){return new f(fi.create(n.map(N)))},lit(n){return new f(Nt(n))},unary:i,not(n){return i("not",n)},exists(n){return i("exists",n)},neg(n){return i("-",n)},between(n,u,v){return new f(ge.create(I(n),U.create("between"),M.create(N(u),N(v))))},betweenSymmetric(n,u,v){return new f(ge.create(I(n),U.create("between symmetric"),M.create(N(u),N(v))))},and(n){return E(n)?new f(Ke(n,"and")):new f(jr(n,"and"))},or(n){return E(n)?new f(Ke(n,"or")):new f(jr(n,"or"))},parens(...n){let u=y(n);return ie.is(u)?new f(u):new f(ie.create(u))},cast(n,u){return new f(fo.create(I(n),_(u)))},withSchema(n){return cr(t.withPluginAtFront(new Z(n)))}});return o.fn=fr(),o.eb=o,o}function Y(t){return cr()}function V(t){if(x(t))return t.toOperationNode();if(O(t))return t(Y()).toOperationNode();throw new Error(`invalid expression: ${JSON.stringify(t)}`)}function tr(t){if(x(t))return t.toOperationNode();if(O(t))return t(Y()).toOperationNode();throw new Error(`invalid aliased expression: ${JSON.stringify(t)}`)}function he(t){return ki(t)||Ai(t)||O(t)}function ae(t){return E(t)?t.map(e=>qe(e)):[qe(t)]}function qe(t){return g(t)?si(t):tr(t)}function si(t){let e=" as ";if(t.includes(e)){let[i,o]=t.split(e).map(No);return D.create(l(i),d.create(o))}else return l(t)}function l(t){let e=".";if(t.includes(e)){let[i,o]=t.split(e).map(No);return K.createWithSchema(i,o)}else return K.create(t)}function No(t){return t.trim()}var Ni=r({is(t){return t.kind==="AddColumnNode"},create(t){return r({kind:"AddColumnNode",column:t})}});var w=r({is(t){return t.kind==="ColumnDefinitionNode"},create(t,e){return r({kind:"ColumnDefinitionNode",column:h.create(t),dataType:e})},cloneWithFrontModifier(t,e){return r({...t,frontModifiers:t.frontModifiers?r([...t.frontModifiers,e]):[e]})},cloneWithEndModifier(t,e){return r({...t,endModifiers:t.endModifiers?r([...t.endModifiers,e]):[e]})},cloneWith(t,e){return r({...t,...e})}});var yi=r({is(t){return t.kind==="DropColumnNode"},create(t){return r({kind:"DropColumnNode",column:h.create(t)})}});var wi=r({is(t){return t.kind==="RenameColumnNode"},create(t,e){return r({kind:"RenameColumnNode",column:h.create(t),renameTo:h.create(e)})}});var tt=r({is(t){return t.kind==="CheckConstraintNode"},create(t,e){return r({kind:"CheckConstraintNode",expression:t,name:e?d.create(e):void 0})}});var yo=["no action","restrict","cascade","set null","set default"],rt=r({is(t){return t.kind==="ReferencesNode"},create(t,e){return r({kind:"ReferencesNode",table:t,columns:r([...e])})},cloneWithOnDelete(t,e){return r({...t,onDelete:e})},cloneWithOnUpdate(t,e){return r({...t,onUpdate:e})}});function wr(t){return x(t)?t.toOperationNode():S.createImmediate(t)}var kt=r({is(t){return t.kind==="GeneratedNode"},create(t){return r({kind:"GeneratedNode",...t})},createWithExpression(t){return r({kind:"GeneratedNode",always:!0,expression:t})},cloneWith(t,e){return r({...t,...e})}});var wo=r({is(t){return t.kind==="DefaultValueNode"},create(t){return r({kind:"DefaultValueNode",defaultValue:t})}});function it(t){if(yo.includes(t))return t;throw new Error(`invalid OnModifyForeignAction ${t}`)}var ue=class t{#e;constructor(e){this.#e=e}autoIncrement(){return new t(w.cloneWith(this.#e,{autoIncrement:!0}))}identity(){return new t(w.cloneWith(this.#e,{identity:!0}))}primaryKey(){return new t(w.cloneWith(this.#e,{primaryKey:!0}))}references(e){let i=J(e);if(!i.table||Ve.is(i.column))throw new Error(`invalid call references('${e}'). The reference must have format table.column or schema.table.column`);return new t(w.cloneWith(this.#e,{references:rt.create(i.table,[i.column])}))}onDelete(e){if(!this.#e.references)throw new Error("on delete constraint can only be added for foreign keys");return new t(w.cloneWith(this.#e,{references:rt.cloneWithOnDelete(this.#e.references,it(e))}))}onUpdate(e){if(!this.#e.references)throw new Error("on update constraint can only be added for foreign keys");return new t(w.cloneWith(this.#e,{references:rt.cloneWithOnUpdate(this.#e.references,it(e))}))}unique(){return new t(w.cloneWith(this.#e,{unique:!0}))}notNull(){return new t(w.cloneWith(this.#e,{notNull:!0}))}unsigned(){return new t(w.cloneWith(this.#e,{unsigned:!0}))}defaultTo(e){return new t(w.cloneWith(this.#e,{defaultTo:wo.create(wr(e))}))}check(e){return new t(w.cloneWith(this.#e,{check:tt.create(e.toOperationNode())}))}generatedAlwaysAs(e){return new t(w.cloneWith(this.#e,{generated:kt.createWithExpression(e.toOperationNode())}))}generatedAlwaysAsIdentity(){return new t(w.cloneWith(this.#e,{generated:kt.create({identity:!0,always:!0})}))}generatedByDefaultAsIdentity(){return new t(w.cloneWith(this.#e,{generated:kt.create({identity:!0,byDefault:!0})}))}stored(){if(!this.#e.generated)throw new Error("stored() can only be called after generatedAlwaysAs");return new t(w.cloneWith(this.#e,{generated:kt.cloneWith(this.#e.generated,{stored:!0})}))}modifyFront(e){return new t(w.cloneWithFrontModifier(this.#e,e.toOperationNode()))}nullsNotDistinct(){return new t(w.cloneWith(this.#e,{nullsNotDistinct:!0}))}ifNotExists(){return new t(w.cloneWith(this.#e,{ifNotExists:!0}))}modifyEnd(e){return new t(w.cloneWithEndModifier(this.#e,e.toOperationNode()))}$call(e){return e(this)}toOperationNode(){return this.#e}};s(ue,"don't await ColumnDefinitionBuilder instances directly.");var xi=r({is(t){return t.kind==="ModifyColumnNode"},create(t){return r({kind:"ModifyColumnNode",column:t})}});var Le=r({is(t){return t.kind==="ForeignKeyConstraintNode"},create(t,e,i,o){return r({kind:"ForeignKeyConstraintNode",columns:t,references:rt.create(e,i),name:o?d.create(o):void 0})},cloneWith(t,e){return r({...t,...e})}});var Qe=class t{#e;constructor(e){this.#e=e}onDelete(e){return new t(Le.cloneWith(this.#e,{onDelete:it(e)}))}onUpdate(e){return new t(Le.cloneWith(this.#e,{onUpdate:it(e)}))}$call(e){return e(this)}toOperationNode(){return this.#e}};s(Qe,"don't await ForeignKeyConstraintBuilder instances directly.");var ot=r({is(t){return t.kind==="AddConstraintNode"},create(t){return r({kind:"AddConstraintNode",constraint:t})}});var nt=r({is(t){return t.kind==="UniqueConstraintNode"},create(t,e,i){return r({kind:"UniqueConstraintNode",columns:r(t.map(h.create)),name:e?d.create(e):void 0,nullsNotDistinct:i})},cloneWith(t,e){return r({...t,...e})}});var st=r({is(t){return t.kind==="DropConstraintNode"},create(t){return r({kind:"DropConstraintNode",constraintName:d.create(t)})},cloneWith(t,e){return r({...t,...e})}});var at=r({is(t){return t.kind==="AlterColumnNode"},create(t,e,i){return r({kind:"AlterColumnNode",column:h.create(t),[e]:i})}});var ut=class{#e;constructor(e){this.#e=e}setDataType(e){return new Ie(at.create(this.#e,"dataType",_(e)))}setDefault(e){return new Ie(at.create(this.#e,"setDefault",wr(e)))}dropDefault(){return new Ie(at.create(this.#e,"dropDefault",!0))}setNotNull(){return new Ie(at.create(this.#e,"setNotNull",!0))}dropNotNull(){return new Ie(at.create(this.#e,"dropNotNull",!0))}$call(e){return e(this)}};s(ut,"don't await AlterColumnBuilder instances");var Ie=class{#e;constructor(e){this.#e=e}toOperationNode(){return this.#e}};s(Ie,"don't await AlteredColumnBuilder instances");var de=class{#e;constructor(e){this.#e=r(e)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};s(de,"don't await AlterTableExecutor instances directly. To execute the query you need to call `execute`");var At=class t{#e;constructor(e){this.#e=r(e)}onDelete(e){return new t({...this.#e,constraintBuilder:this.#e.constraintBuilder.onDelete(e)})}onUpdate(e){return new t({...this.#e,constraintBuilder:this.#e.constraintBuilder.onUpdate(e)})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(c.cloneWithTableProps(this.#e.node,{addConstraint:ot.create(this.#e.constraintBuilder.toOperationNode())}),this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};s(At,"don't await AlterTableAddForeignKeyConstraintBuilder instances directly. To execute the query you need to call `execute`");var Et=class t{#e;constructor(e){this.#e=r(e)}ifExists(){return new t({...this.#e,node:c.cloneWithTableProps(this.#e.node,{dropConstraint:st.cloneWith(this.#e.node.dropConstraint,{ifExists:!0})})})}cascade(){return new t({...this.#e,node:c.cloneWithTableProps(this.#e.node,{dropConstraint:st.cloneWith(this.#e.node.dropConstraint,{modifier:"cascade"})})})}restrict(){return new t({...this.#e,node:c.cloneWithTableProps(this.#e.node,{dropConstraint:st.cloneWith(this.#e.node.dropConstraint,{modifier:"restrict"})})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};s(Et,"don't await AlterTableDropConstraintBuilder instances directly. To execute the query you need to call `execute`");var xr=r({is(t){return t.kind==="PrimaryKeyConstraintNode"},create(t,e){return r({kind:"PrimaryKeyConstraintNode",columns:r(t.map(h.create)),name:e?d.create(e):void 0})}});var Se=r({is(t){return t.kind==="AddIndexNode"},create(t){return r({kind:"AddIndexNode",name:d.create(t)})},cloneWith(t,e){return r({...t,...e})},cloneWithColumns(t,e){return r({...t,columns:[...t.columns||[],...e]})}});var Rt=class t{#e;constructor(e){this.#e=r(e)}unique(){return new t({...this.#e,node:c.cloneWithTableProps(this.#e.node,{addIndex:Se.cloneWith(this.#e.node.addIndex,{unique:!0})})})}column(e){return new t({...this.#e,node:c.cloneWithTableProps(this.#e.node,{addIndex:Se.cloneWithColumns(this.#e.node.addIndex,[Je(e)])})})}columns(e){return new t({...this.#e,node:c.cloneWithTableProps(this.#e.node,{addIndex:Se.cloneWithColumns(this.#e.node.addIndex,e.map(Je))})})}expression(e){return new t({...this.#e,node:c.cloneWithTableProps(this.#e.node,{addIndex:Se.cloneWithColumns(this.#e.node.addIndex,[e.toOperationNode()])})})}using(e){return new t({...this.#e,node:c.cloneWithTableProps(this.#e.node,{addIndex:Se.cloneWith(this.#e.node.addIndex,{using:C.createWithSql(e)})})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};s(Rt,"don't await AlterTableAddIndexBuilder instances directly. To execute the query you need to call `execute`");var Pe=class t{#e;constructor(e){this.#e=e}toOperationNode(){return this.#e}nullsNotDistinct(){return new t(nt.cloneWith(this.#e,{nullsNotDistinct:!0}))}};s(Pe,"don't await UniqueConstraintNodeBuilder instances directly.");var Dt=class{#e;constructor(e){this.#e=r(e)}renameTo(e){return new de({...this.#e,node:c.cloneWithTableProps(this.#e.node,{renameTo:l(e)})})}setSchema(e){return new de({...this.#e,node:c.cloneWithTableProps(this.#e.node,{setSchema:d.create(e)})})}alterColumn(e,i){let o=i(new ut(e));return new ke({...this.#e,node:c.cloneWithColumnAlteration(this.#e.node,o.toOperationNode())})}dropColumn(e){return new ke({...this.#e,node:c.cloneWithColumnAlteration(this.#e.node,yi.create(e))})}renameColumn(e,i){return new ke({...this.#e,node:c.cloneWithColumnAlteration(this.#e.node,wi.create(e,i))})}addColumn(e,i,o=te){let n=o(new ue(w.create(e,_(i))));return new ke({...this.#e,node:c.cloneWithColumnAlteration(this.#e.node,Ni.create(n.toOperationNode()))})}modifyColumn(e,i,o=te){let n=o(new ue(w.create(e,_(i))));return new ke({...this.#e,node:c.cloneWithColumnAlteration(this.#e.node,xi.create(n.toOperationNode()))})}addUniqueConstraint(e,i,o=te){let n=o(new Pe(nt.create(i,e)));return new de({...this.#e,node:c.cloneWithTableProps(this.#e.node,{addConstraint:ot.create(n.toOperationNode())})})}addCheckConstraint(e,i){return new de({...this.#e,node:c.cloneWithTableProps(this.#e.node,{addConstraint:ot.create(tt.create(i.toOperationNode(),e))})})}addForeignKeyConstraint(e,i,o,n){return new At({...this.#e,constraintBuilder:new Qe(Le.create(i.map(h.create),l(o),n.map(h.create),e))})}addPrimaryKeyConstraint(e,i){return new de({...this.#e,node:c.cloneWithTableProps(this.#e.node,{addConstraint:ot.create(xr.create(i,e))})})}dropConstraint(e){return new Et({...this.#e,node:c.cloneWithTableProps(this.#e.node,{dropConstraint:st.create(e)})})}addIndex(e){return new Rt({...this.#e,node:c.cloneWithTableProps(this.#e.node,{addIndex:Se.create(e)})})}dropIndex(e){return new de({...this.#e,node:c.cloneWithTableProps(this.#e.node,{dropIndex:xe.create(e)})})}$call(e){return e(this)}};s(Dt,"don't await AlterTableBuilder instances");var ke=class t{#e;constructor(e){this.#e=r(e)}alterColumn(e,i){let o=i(new ut(e));return new t({...this.#e,node:c.cloneWithColumnAlteration(this.#e.node,o.toOperationNode())})}dropColumn(e){return new t({...this.#e,node:c.cloneWithColumnAlteration(this.#e.node,yi.create(e))})}renameColumn(e,i){return new t({...this.#e,node:c.cloneWithColumnAlteration(this.#e.node,wi.create(e,i))})}addColumn(e,i,o=te){let n=o(new ue(w.create(e,_(i))));return new t({...this.#e,node:c.cloneWithColumnAlteration(this.#e.node,Ni.create(n.toOperationNode()))})}modifyColumn(e,i,o=te){let n=o(new ue(w.create(e,_(i))));return new t({...this.#e,node:c.cloneWithColumnAlteration(this.#e.node,xi.create(n.toOperationNode()))})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};s(ke,"don't await AlterTableColumnAlteringBuilder instances directly. To execute the query you need to call `execute`");var dt=class extends be{transformValue(e){return{...super.transformValue(e),immediate:!0}}};var Bt=class t{#e;constructor(e){this.#e=r(e)}ifNotExists(){return new t({...this.#e,node:G.cloneWith(this.#e.node,{ifNotExists:!0})})}unique(){return new t({...this.#e,node:G.cloneWith(this.#e.node,{unique:!0})})}nullsNotDistinct(){return new t({...this.#e,node:G.cloneWith(this.#e.node,{nullsNotDistinct:!0})})}on(e){return new t({...this.#e,node:G.cloneWith(this.#e.node,{table:l(e)})})}column(e){return new t({...this.#e,node:G.cloneWithColumns(this.#e.node,[Je(e)])})}columns(e){return new t({...this.#e,node:G.cloneWithColumns(this.#e.node,e.map(Je))})}expression(e){return new t({...this.#e,node:G.cloneWithColumns(this.#e.node,[e.toOperationNode()])})}using(e){return new t({...this.#e,node:G.cloneWith(this.#e.node,{using:C.createWithSql(e)})})}where(...e){let i=new dt;return new t({...this.#e,node:a.cloneWithWhere(this.#e.node,i.transformNode(y(e)))})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};s(Bt,"don't await CreateIndexBuilder instances directly. To execute the query you need to call `execute`");var Lt=class t{#e;constructor(e){this.#e=r(e)}ifNotExists(){return new t({...this.#e,node:Kt.cloneWith(this.#e.node,{ifNotExists:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};s(Lt,"don't await CreateSchemaBuilder instances directly. To execute the query you need to call `execute`");function xo(t){if(Si.includes(t))return t;throw new Error(`invalid OnCommitAction ${t}`)}var Qt=class t{#e;constructor(e){this.#e=r(e)}temporary(){return new t({...this.#e,node:R.cloneWith(this.#e.node,{temporary:!0})})}onCommit(e){return new t({...this.#e,node:R.cloneWith(this.#e.node,{onCommit:xo(e)})})}ifNotExists(){return new t({...this.#e,node:R.cloneWith(this.#e.node,{ifNotExists:!0})})}addColumn(e,i,o=te){let n=o(new ue(w.create(e,_(i))));return new t({...this.#e,node:R.cloneWithColumn(this.#e.node,n.toOperationNode())})}addPrimaryKeyConstraint(e,i){return new t({...this.#e,node:R.cloneWithConstraint(this.#e.node,xr.create(i,e))})}addUniqueConstraint(e,i,o=te){let n=o(new Pe(nt.create(i,e)));return new t({...this.#e,node:R.cloneWithConstraint(this.#e.node,n.toOperationNode())})}addCheckConstraint(e,i){return new t({...this.#e,node:R.cloneWithConstraint(this.#e.node,tt.create(i.toOperationNode(),e))})}addForeignKeyConstraint(e,i,o,n,u=te){let v=u(new Qe(Le.create(i.map(h.create),l(o),n.map(h.create),e)));return new t({...this.#e,node:R.cloneWithConstraint(this.#e.node,v.toOperationNode())})}modifyFront(e){return new t({...this.#e,node:R.cloneWithFrontModifier(this.#e.node,e.toOperationNode())})}modifyEnd(e){return new t({...this.#e,node:R.cloneWithEndModifier(this.#e.node,e.toOperationNode())})}as(e){return new t({...this.#e,node:R.cloneWith(this.#e.node,{selectQuery:V(e)})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};s(Qt,"don't await CreateTableBuilder instances directly. To execute the query you need to call `execute`");var Pt=class t{#e;constructor(e){this.#e=r(e)}on(e){return new t({...this.#e,node:xe.cloneWith(this.#e.node,{table:l(e)})})}ifExists(){return new t({...this.#e,node:xe.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:xe.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};s(Pt,"don't await DropIndexBuilder instances directly. To execute the query you need to call `execute`");var Ft=class t{#e;constructor(e){this.#e=r(e)}ifExists(){return new t({...this.#e,node:lt.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:lt.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};s(Ft,"don't await DropSchemaBuilder instances directly. To execute the query you need to call `execute`");var Mt=class t{#e;constructor(e){this.#e=r(e)}ifExists(){return new t({...this.#e,node:ft.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:ft.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};s(Mt,"don't await DropTableBuilder instances directly. To execute the query you need to call `execute`");var ee=r({is(t){return t.kind==="CreateViewNode"},create(t){return r({kind:"CreateViewNode",name:F.create(t)})},cloneWith(t,e){return r({...t,...e})}});var Or=class{#e=new dt;transformQuery(e){return this.#e.transformNode(e.node)}transformResult(e){return Promise.resolve(e.result)}};var Vt=class t{#e;constructor(e){this.#e=r(e)}temporary(){return new t({...this.#e,node:ee.cloneWith(this.#e.node,{temporary:!0})})}materialized(){return new t({...this.#e,node:ee.cloneWith(this.#e.node,{materialized:!0})})}ifNotExists(){return new t({...this.#e,node:ee.cloneWith(this.#e.node,{ifNotExists:!0})})}orReplace(){return new t({...this.#e,node:ee.cloneWith(this.#e.node,{orReplace:!0})})}columns(e){return new t({...this.#e,node:ee.cloneWith(this.#e.node,{columns:e.map(Jr)})})}as(e){let i=e.withPlugin(new Or).toOperationNode();return new t({...this.#e,node:ee.cloneWith(this.#e.node,{as:i})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};s(Vt,"don't await CreateViewBuilder instances directly. To execute the query you need to call `execute`");var pt=r({is(t){return t.kind==="DropViewNode"},create(t){return r({kind:"DropViewNode",name:F.create(t)})},cloneWith(t,e){return r({...t,...e})}});var zt=class t{#e;constructor(e){this.#e=r(e)}materialized(){return new t({...this.#e,node:pt.cloneWith(this.#e.node,{materialized:!0})})}ifExists(){return new t({...this.#e,node:pt.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:pt.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};s(zt,"don't await DropViewBuilder instances directly. To execute the query you need to call `execute`");var gr=r({is(t){return t.kind==="CreateTypeNode"},create(t){return r({kind:"CreateTypeNode",name:t})},cloneWithEnum(t,e){return r({...t,enum:$e.create(e.map(i=>S.createImmediate(i)))})}});var Ut=class t{#e;constructor(e){this.#e=r(e)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}asEnum(e){return new t({...this.#e,node:gr.cloneWithEnum(this.#e.node,e)})}$call(e){return e(this)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};s(Ut,"don't await CreateTypeBuilder instances directly. To execute the query you need to call `execute`");var vr=r({is(t){return t.kind==="DropTypeNode"},create(t){return r({kind:"DropTypeNode",name:t})},cloneWith(t,e){return r({...t,...e})}});var Jt=class t{#e;constructor(e){this.#e=r(e)}ifExists(){return new t({...this.#e,node:vr.cloneWith(this.#e.node,{ifExists:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};s(Jt,"don't await DropTypeBuilder instances directly. To execute the query you need to call `execute`");function Oi(t){let e=".";if(t.includes(e)){let i=t.split(e).map(nn);if(i.length===2)return F.createWithSchema(i[0],i[1]);throw new Error(`invalid schemable identifier ${t}`)}else return F.create(t)}function nn(t){return t.trim()}var Cr=class t{#e;constructor(e){this.#e=e}createTable(e){return new Qt({queryId:m(),executor:this.#e,node:R.create(l(e))})}dropTable(e){return new Mt({queryId:m(),executor:this.#e,node:ft.create(l(e))})}createIndex(e){return new Bt({queryId:m(),executor:this.#e,node:G.create(e)})}dropIndex(e){return new Pt({queryId:m(),executor:this.#e,node:xe.create(e)})}createSchema(e){return new Lt({queryId:m(),executor:this.#e,node:Kt.create(e)})}dropSchema(e){return new Ft({queryId:m(),executor:this.#e,node:lt.create(e)})}alterTable(e){return new Dt({queryId:m(),executor:this.#e,node:c.create(l(e))})}createView(e){return new Vt({queryId:m(),executor:this.#e,node:ee.create(e)})}dropView(e){return new zt({queryId:m(),executor:this.#e,node:pt.create(e)})}createType(e){return new Ut({queryId:m(),executor:this.#e,node:gr.create(Oi(e))})}dropType(e){return new Jt({queryId:m(),executor:this.#e,node:vr.create(Oi(e))})}withPlugin(e){return new t(this.#e.withPlugin(e))}withoutPlugins(){return new t(this.#e.withoutPlugins())}withSchema(e){return new t(this.#e.withPluginAtFront(new Z(e)))}};var br=class{ref(e){return new Gt(e)}};var Wr=class{#e;constructor(e){this.#e=e}async provideConnection(e){let i=await this.#e.acquireConnection();try{return await e(i)}finally{await this.#e.releaseConnection(i)}}};var qr=class t extends Ze{#e;#t;#r;constructor(e,i,o,n=[]){super(n),this.#e=e,this.#t=i,this.#r=o}get adapter(){return this.#t}compileQuery(e){return this.#e.compileQuery(e)}provideConnection(e){return this.#r.provideConnection(e)}withPlugins(e){return new t(this.#e,this.#t,this.#r,[...this.plugins,...e])}withPlugin(e){return new t(this.#e,this.#t,this.#r,[...this.plugins,e])}withPluginAtFront(e){return new t(this.#e,this.#t,this.#r,[e,...this.plugins])}withConnectionProvider(e){return new t(this.#e,this.#t,e,[...this.plugins])}withoutPlugins(){return new t(this.#e,this.#t,this.#r,[])}};function gi(){return typeof performance<"u"&&O(performance.now)?performance.now():Date.now()}var Tr=class{#e;#t;#r;#i;#o;#s=new WeakSet;constructor(e,i){this.#i=!1,this.#e=e,this.#t=i}async init(){if(this.#o)throw new Error("driver has already been destroyed");this.#r||(this.#r=this.#e.init().then(()=>{this.#i=!0}).catch(e=>(this.#r=void 0,Promise.reject(e)))),await this.#r}async acquireConnection(){if(this.#o)throw new Error("driver has already been destroyed");this.#i||await this.init();let e=await this.#e.acquireConnection();return this.#s.has(e)||(this.#n()&&this.#a(e),this.#s.add(e)),e}async releaseConnection(e){await this.#e.releaseConnection(e)}beginTransaction(e,i){return this.#e.beginTransaction(e,i)}commitTransaction(e){return this.#e.commitTransaction(e)}rollbackTransaction(e){return this.#e.rollbackTransaction(e)}async destroy(){this.#r&&(await this.#r,this.#o||(this.#o=this.#e.destroy().catch(e=>(this.#o=void 0,Promise.reject(e)))),await this.#o)}#n(){return this.#t.isLevelEnabled("query")||this.#t.isLevelEnabled("error")}#a(e){let i=e.executeQuery;e.executeQuery=async o=>{let n,u=gi();try{return await i.call(e,o)}catch(v){throw n=v,await this.#u(v,o,u),v}finally{n||await this.#p(o,u)}}}async#u(e,i,o){await this.#t.error(()=>({level:"error",error:e,query:i,queryDurationMillis:this.#d(o)}))}async#p(e,i){await this.#t.query(()=>({level:"query",query:e,queryDurationMillis:this.#d(i)}))}#d(e){return gi()-e}};var sn=()=>{},$t=class{#e;#t;constructor(e){this.#e=e}async provideConnection(e){for(;this.#t;)await this.#t.catch(sn);return this.#t=this.#r(e).finally(()=>{this.#t=void 0}),this.#t}async#r(e){return await e(this.#e)}};var Oo=["read uncommitted","read committed","repeatable read","serializable","snapshot"];var eO=r(["query","error"]),Ir=class{#e;#t;constructor(e){O(e)?(this.#t=e,this.#e=r({query:!0,error:!0})):(this.#t=an,this.#e=r({query:e.includes("query"),error:e.includes("error")}))}isLevelEnabled(e){return this.#e[e]}async query(e){this.#e.query&&await this.#t(e())}async error(e){this.#e.error&&await this.#t(e())}};function an(t){t.level==="query"?(console.log(`kysely:query: ${t.query.sql}`),console.log(`kysely:query: duration: ${t.queryDurationMillis.toFixed(1)}ms`)):t.level==="error"&&(t.error instanceof Error?console.error(`kysely:error: ${t.error.stack??t.error.message}`):console.error(`kysely:error: ${JSON.stringify({error:t.error,query:t.query.sql,queryDurationMillis:t.queryDurationMillis})}`))}function go(t){return Q(t)&&O(t.compile)}var ht=class t extends _e{#e;constructor(e){let i,o;if(un(e))i={executor:e.executor},o={...e};else{let n=e.dialect,u=n.createDriver(),v=n.createQueryCompiler(),L=n.createAdapter(),pe=new Ir(e.log??[]),qi=new Tr(u,pe),To=new Wr(qi),Ti=new qr(v,L,To,e.plugins??[]);i={executor:Ti},o={config:e,executor:Ti,dialect:n,driver:qi}}super(i),this.#e=r(o)}get schema(){return new Cr(this.#e.executor)}get dynamic(){return new br}get introspection(){return this.#e.dialect.createIntrospector(this.withoutPlugins())}case(e){return new et({node:$.create(z(e)?void 0:V(e))})}get fn(){return fr()}transaction(){return new kr({...this.#e})}connection(){return new Sr({...this.#e})}withPlugin(e){return new t({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new t({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new t({...this.#e,executor:this.#e.executor.withPluginAtFront(new Z(e))})}withTables(){return new t({...this.#e})}async destroy(){await this.#e.driver.destroy()}get isTransaction(){return!1}getExecutor(){return this.#e.executor}executeQuery(e,i=m()){let o=go(e)?e.compile():e;return this.getExecutor().executeQuery(o,i)}},vi=class t extends ht{#e;constructor(e){super(e),this.#e=e}get isTransaction(){return!0}transaction(){throw new Error("calling the transaction method for a Transaction is not supported")}connection(){throw new Error("calling the connection method for a Transaction is not supported")}async destroy(){throw new Error("calling the destroy method for a Transaction is not supported")}withPlugin(e){return new t({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new t({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new t({...this.#e,executor:this.#e.executor.withPluginAtFront(new Z(e))})}withTables(){return new t({...this.#e})}};function un(t){return Q(t)&&Q(t.config)&&Q(t.driver)&&Q(t.executor)&&Q(t.dialect)}var Sr=class{#e;constructor(e){this.#e=r(e)}async execute(e){return this.#e.executor.provideConnection(async i=>{let o=this.#e.executor.withConnectionProvider(new $t(i)),n=new ht({...this.#e,executor:o});return await e(n)})}};s(Sr,"don't await ConnectionBuilder instances directly. To execute the query you need to call the `execute` method");var kr=class t{#e;constructor(e){this.#e=r(e)}setIsolationLevel(e){return new t({...this.#e,isolationLevel:e})}async execute(e){let{isolationLevel:i,...o}=this.#e,n={isolationLevel:i};return dn(n),this.#e.executor.provideConnection(async u=>{let v=this.#e.executor.withConnectionProvider(new $t(u)),L=new vi({...o,executor:v});try{await this.#e.driver.beginTransaction(u,n);let pe=await e(L);return await this.#e.driver.commitTransaction(u),pe}catch(pe){throw await this.#e.driver.rollbackTransaction(u),pe}})}};s(kr,"don't await TransactionBuilder instances directly. To execute the transaction you need to call the `execute` method");function dn(t){if(t.isolationLevel&&!Oo.includes(t.isolationLevel))throw new Error(`invalid transaction isolation level ${t.isolationLevel}`)}var Ar=class t{#e;constructor(e){this.#e=r(e)}get expressionType(){}get isRawBuilder(){return!0}as(e){return new Er(this,e)}$castTo(){return new t({...this.#e})}$notNull(){return new t(this.#e)}withPlugin(e){return new t({...this.#e,plugins:this.#e.plugins!==void 0?r([...this.#e.plugins,e]):r([e])})}toOperationNode(){return this.#r(this.#t())}compile(e){return this.#i(this.#t(e))}async execute(e){let i=this.#t(e);return i.executeQuery(this.#i(i),this.#e.queryId)}#t(e){let i=e!==void 0?e.getExecutor():We;return this.#e.plugins!==void 0?i.withPlugins(this.#e.plugins):i}#r(e){return e.transformQuery(this.#e.rawNode,this.#e.queryId)}#i(e){return e.compileQuery(this.#r(e),this.#e.queryId)}};function ye(t){return new Ar(t)}s(Ar,"don't await RawBuilder instances directly. To execute the query you need to call `execute`");var Er=class{#e;#t;constructor(e,i){this.#e=e,this.#t=i}get expression(){return this.#e}get alias(){return this.#t}get rawBuilder(){return this.#e}toOperationNode(){return D.create(this.#e.toOperationNode(),x(this.#t)?this.#t.toOperationNode():d.create(this.#t))}};s(Er,"don't await AliasedRawBuilder instances directly. AliasedRawBuilder should never be executed directly since it's always a part of another query.");var ct=Object.assign((t,...e)=>ye({queryId:m(),rawNode:C.create(t,e?.map(vo)??[])}),{ref(t){return ye({queryId:m(),rawNode:C.createWithChild(J(t))})},val(t){return ye({queryId:m(),rawNode:C.createWithChild(N(t))})},value(t){return this.val(t)},table(t){return ye({queryId:m(),rawNode:C.createWithChild(l(t))})},id(...t){let e=new Array(t.length+1).fill(".");return e[0]="",e[e.length-1]="",ye({queryId:m(),rawNode:C.create(e,t.map(d.create))})},lit(t){return ye({queryId:m(),rawNode:C.createWithChild(S.createImmediate(t))})},literal(t){return this.lit(t)},raw(t){return ye({queryId:m(),rawNode:C.createWithSql(t)})},join(t,e=ct`, `){let i=new Array(2*t.length-1),o=e.toOperationNode();for(let n=0;n<t.length;++n)i[2*n]=vo(t[n]),n!==t.length-1&&(i[2*n+1]=o);return ye({queryId:m(),rawNode:C.createWithChildren(i)})}});function vo(t){return x(t)?t.toOperationNode():N(t)}var Rr=class{nodeStack=[];get parentNode(){return this.nodeStack[this.nodeStack.length-2]}#e=r({AliasNode:this.visitAlias.bind(this),ColumnNode:this.visitColumn.bind(this),IdentifierNode:this.visitIdentifier.bind(this),SchemableIdentifierNode:this.visitSchemableIdentifier.bind(this),RawNode:this.visitRaw.bind(this),ReferenceNode:this.visitReference.bind(this),SelectQueryNode:this.visitSelectQuery.bind(this),SelectionNode:this.visitSelection.bind(this),TableNode:this.visitTable.bind(this),FromNode:this.visitFrom.bind(this),SelectAllNode:this.visitSelectAll.bind(this),AndNode:this.visitAnd.bind(this),OrNode:this.visitOr.bind(this),ValueNode:this.visitValue.bind(this),ValueListNode:this.visitValueList.bind(this),PrimitiveValueListNode:this.visitPrimitiveValueList.bind(this),ParensNode:this.visitParens.bind(this),JoinNode:this.visitJoin.bind(this),OperatorNode:this.visitOperator.bind(this),WhereNode:this.visitWhere.bind(this),InsertQueryNode:this.visitInsertQuery.bind(this),DeleteQueryNode:this.visitDeleteQuery.bind(this),ReturningNode:this.visitReturning.bind(this),CreateTableNode:this.visitCreateTable.bind(this),AddColumnNode:this.visitAddColumn.bind(this),ColumnDefinitionNode:this.visitColumnDefinition.bind(this),DropTableNode:this.visitDropTable.bind(this),DataTypeNode:this.visitDataType.bind(this),OrderByNode:this.visitOrderBy.bind(this),OrderByItemNode:this.visitOrderByItem.bind(this),GroupByNode:this.visitGroupBy.bind(this),GroupByItemNode:this.visitGroupByItem.bind(this),UpdateQueryNode:this.visitUpdateQuery.bind(this),ColumnUpdateNode:this.visitColumnUpdate.bind(this),LimitNode:this.visitLimit.bind(this),OffsetNode:this.visitOffset.bind(this),OnConflictNode:this.visitOnConflict.bind(this),OnDuplicateKeyNode:this.visitOnDuplicateKey.bind(this),CreateIndexNode:this.visitCreateIndex.bind(this),DropIndexNode:this.visitDropIndex.bind(this),ListNode:this.visitList.bind(this),PrimaryKeyConstraintNode:this.visitPrimaryKeyConstraint.bind(this),UniqueConstraintNode:this.visitUniqueConstraint.bind(this),ReferencesNode:this.visitReferences.bind(this),CheckConstraintNode:this.visitCheckConstraint.bind(this),WithNode:this.visitWith.bind(this),CommonTableExpressionNode:this.visitCommonTableExpression.bind(this),CommonTableExpressionNameNode:this.visitCommonTableExpressionName.bind(this),HavingNode:this.visitHaving.bind(this),CreateSchemaNode:this.visitCreateSchema.bind(this),DropSchemaNode:this.visitDropSchema.bind(this),AlterTableNode:this.visitAlterTable.bind(this),DropColumnNode:this.visitDropColumn.bind(this),RenameColumnNode:this.visitRenameColumn.bind(this),AlterColumnNode:this.visitAlterColumn.bind(this),ModifyColumnNode:this.visitModifyColumn.bind(this),AddConstraintNode:this.visitAddConstraint.bind(this),DropConstraintNode:this.visitDropConstraint.bind(this),ForeignKeyConstraintNode:this.visitForeignKeyConstraint.bind(this),CreateViewNode:this.visitCreateView.bind(this),DropViewNode:this.visitDropView.bind(this),GeneratedNode:this.visitGenerated.bind(this),DefaultValueNode:this.visitDefaultValue.bind(this),OnNode:this.visitOn.bind(this),ValuesNode:this.visitValues.bind(this),SelectModifierNode:this.visitSelectModifier.bind(this),CreateTypeNode:this.visitCreateType.bind(this),DropTypeNode:this.visitDropType.bind(this),ExplainNode:this.visitExplain.bind(this),DefaultInsertValueNode:this.visitDefaultInsertValue.bind(this),AggregateFunctionNode:this.visitAggregateFunction.bind(this),OverNode:this.visitOver.bind(this),PartitionByNode:this.visitPartitionBy.bind(this),PartitionByItemNode:this.visitPartitionByItem.bind(this),SetOperationNode:this.visitSetOperation.bind(this),BinaryOperationNode:this.visitBinaryOperation.bind(this),UnaryOperationNode:this.visitUnaryOperation.bind(this),UsingNode:this.visitUsing.bind(this),FunctionNode:this.visitFunction.bind(this),CaseNode:this.visitCase.bind(this),WhenNode:this.visitWhen.bind(this),JSONReferenceNode:this.visitJSONReference.bind(this),JSONPathNode:this.visitJSONPath.bind(this),JSONPathLegNode:this.visitJSONPathLeg.bind(this),JSONOperatorChainNode:this.visitJSONOperatorChain.bind(this),TupleNode:this.visitTuple.bind(this),MergeQueryNode:this.visitMergeQuery.bind(this),MatchedNode:this.visitMatched.bind(this),AddIndexNode:this.visitAddIndex.bind(this),CastNode:this.visitCast.bind(this),FetchNode:this.visitFetch.bind(this),TopNode:this.visitTop.bind(this),OutputNode:this.visitOutput.bind(this)});visitNode=e=>{this.nodeStack.push(e),this.#e[e.kind](e),this.nodeStack.pop()}};var Dr=class extends Rr{#e="";#t=[];get numParameters(){return this.#t.length}compileQuery(e){return this.#e="",this.#t=[],this.nodeStack.splice(0,this.nodeStack.length),this.visitNode(e),r({query:e,sql:this.getSql(),parameters:[...this.#t]})}getSql(){return this.#e}visitSelectQuery(e){let i=this.parentNode!==void 0&&!ie.is(this.parentNode)&&!q.is(this.parentNode)&&!R.is(this.parentNode)&&!ee.is(this.parentNode)&&!hr.is(this.parentNode);this.parentNode===void 0&&e.explain&&(this.visitNode(e.explain),this.append(" ")),i&&this.append("("),e.with&&(this.visitNode(e.with),this.append(" ")),this.append("select"),e.distinctOn&&(this.append(" "),this.compileDistinctOn(e.distinctOn)),e.frontModifiers?.length&&(this.append(" "),this.compileList(e.frontModifiers," ")),e.top&&(this.append(" "),this.visitNode(e.top)),e.selections&&(this.append(" "),this.compileList(e.selections)),e.from&&(this.append(" "),this.visitNode(e.from)),e.joins&&(this.append(" "),this.compileList(e.joins," ")),e.where&&(this.append(" "),this.visitNode(e.where)),e.groupBy&&(this.append(" "),this.visitNode(e.groupBy)),e.having&&(this.append(" "),this.visitNode(e.having)),e.setOperations&&(this.append(" "),this.compileList(e.setOperations," ")),e.orderBy&&(this.append(" "),this.visitNode(e.orderBy)),e.limit&&(this.append(" "),this.visitNode(e.limit)),e.offset&&(this.append(" "),this.visitNode(e.offset)),e.fetch&&(this.append(" "),this.visitNode(e.fetch)),e.endModifiers?.length&&(this.append(" "),this.compileList(this.sortSelectModifiers([...e.endModifiers])," ")),i&&this.append(")")}visitFrom(e){this.append("from "),this.compileList(e.froms)}visitSelection(e){this.visitNode(e.selection)}visitColumn(e){this.visitNode(e.column)}compileDistinctOn(e){this.append("distinct on ("),this.compileList(e),this.append(")")}compileList(e,i=", "){let o=e.length-1;for(let n=0;n<=o;n++)this.visitNode(e[n]),n<o&&this.append(i)}visitWhere(e){this.append("where "),this.visitNode(e.where)}visitHaving(e){this.append("having "),this.visitNode(e.having)}visitInsertQuery(e){let i=this.nodeStack.find(a.is),o=i!==e;!o&&e.explain&&(this.visitNode(e.explain),this.append(" ")),o&&!T.is(i)&&this.append("("),e.with&&(this.visitNode(e.with),this.append(" ")),this.append(e.replace?"replace":"insert"),e.ignore&&this.append(" ignore"),e.top&&(this.append(" "),this.visitNode(e.top)),e.into&&(this.append(" into "),this.visitNode(e.into)),e.columns&&(this.append(" ("),this.compileList(e.columns),this.append(")")),e.output&&(this.append(" "),this.visitNode(e.output)),e.values&&(this.append(" "),this.visitNode(e.values)),e.defaultValues&&(this.append(" "),this.append("default values")),e.onConflict&&(this.append(" "),this.visitNode(e.onConflict)),e.onDuplicateKey&&(this.append(" "),this.visitNode(e.onDuplicateKey)),e.returning&&(this.append(" "),this.visitNode(e.returning)),o&&!T.is(i)&&this.append(")")}visitValues(e){this.append("values "),this.compileList(e.values)}visitDeleteQuery(e){let i=this.nodeStack.find(a.is)!==e;!i&&e.explain&&(this.visitNode(e.explain),this.append(" ")),i&&this.append("("),e.with&&(this.visitNode(e.with),this.append(" ")),this.append("delete "),e.top&&(this.visitNode(e.top),this.append(" ")),this.visitNode(e.from),e.output&&(this.append(" "),this.visitNode(e.output)),e.using&&(this.append(" "),this.visitNode(e.using)),e.joins&&(this.append(" "),this.compileList(e.joins," ")),e.where&&(this.append(" "),this.visitNode(e.where)),e.orderBy&&(this.append(" "),this.visitNode(e.orderBy)),e.limit&&(this.append(" "),this.visitNode(e.limit)),e.returning&&(this.append(" "),this.visitNode(e.returning)),i&&this.append(")")}visitReturning(e){this.append("returning "),this.compileList(e.selections)}visitAlias(e){this.visitNode(e.node),this.append(" as "),this.visitNode(e.alias)}visitReference(e){e.table&&(this.visitNode(e.table),this.append(".")),this.visitNode(e.column)}visitSelectAll(e){this.append("*")}visitIdentifier(e){this.append(this.getLeftIdentifierWrapper()),this.compileUnwrappedIdentifier(e),this.append(this.getRightIdentifierWrapper())}compileUnwrappedIdentifier(e){if(!g(e.name))throw new Error("a non-string identifier was passed to compileUnwrappedIdentifier.");this.append(this.sanitizeIdentifier(e.name))}visitAnd(e){this.visitNode(e.left),this.append(" and "),this.visitNode(e.right)}visitOr(e){this.visitNode(e.left),this.append(" or "),this.visitNode(e.right)}visitValue(e){e.immediate?this.appendImmediateValue(e.value):this.appendValue(e.value)}visitValueList(e){this.append("("),this.compileList(e.values),this.append(")")}visitTuple(e){this.append("("),this.compileList(e.values),this.append(")")}visitPrimitiveValueList(e){this.append("(");let{values:i}=e;for(let o=0;o<i.length;++o)this.appendValue(i[o]),o!==i.length-1&&this.append(", ");this.append(")")}visitParens(e){this.append("("),this.visitNode(e.node),this.append(")")}visitJoin(e){this.append(hn[e.joinType]),this.append(" "),this.visitNode(e.table),e.on&&(this.append(" "),this.visitNode(e.on))}visitOn(e){this.append("on "),this.visitNode(e.on)}visitRaw(e){let{sqlFragments:i,parameters:o}=e;for(let n=0;n<i.length;++n)this.append(i[n]),o.length>n&&this.visitNode(o[n])}visitOperator(e){this.append(e.operator)}visitTable(e){this.visitNode(e.table)}visitSchemableIdentifier(e){e.schema&&(this.visitNode(e.schema),this.append(".")),this.visitNode(e.identifier)}visitCreateTable(e){this.append("create "),e.frontModifiers&&e.frontModifiers.length>0&&(this.compileList(e.frontModifiers," "),this.append(" ")),e.temporary&&this.append("temporary "),this.append("table "),e.ifNotExists&&this.append("if not exists "),this.visitNode(e.table),e.selectQuery?(this.append(" as "),this.visitNode(e.selectQuery)):(this.append(" ("),this.compileList([...e.columns,...e.constraints??[]]),this.append(")"),e.onCommit&&(this.append(" on commit "),this.append(e.onCommit)),e.endModifiers&&e.endModifiers.length>0&&(this.append(" "),this.compileList(e.endModifiers," ")))}visitColumnDefinition(e){e.ifNotExists&&this.append("if not exists "),this.visitNode(e.column),this.append(" "),this.visitNode(e.dataType),e.unsigned&&this.append(" unsigned"),e.frontModifiers&&e.frontModifiers.length>0&&(this.append(" "),this.compileList(e.frontModifiers," ")),e.generated&&(this.append(" "),this.visitNode(e.generated)),e.identity&&this.append(" identity"),e.defaultTo&&(this.append(" "),this.visitNode(e.defaultTo)),e.notNull&&this.append(" not null"),e.unique&&this.append(" unique"),e.nullsNotDistinct&&this.append(" nulls not distinct"),e.primaryKey&&this.append(" primary key"),e.autoIncrement&&(this.append(" "),this.append(this.getAutoIncrement())),e.references&&(this.append(" "),this.visitNode(e.references)),e.check&&(this.append(" "),this.visitNode(e.check)),e.endModifiers&&e.endModifiers.length>0&&(this.append(" "),this.compileList(e.endModifiers," "))}getAutoIncrement(){return"auto_increment"}visitReferences(e){this.append("references "),this.visitNode(e.table),this.append(" ("),this.compileList(e.columns),this.append(")"),e.onDelete&&(this.append(" on delete "),this.append(e.onDelete)),e.onUpdate&&(this.append(" on update "),this.append(e.onUpdate))}visitDropTable(e){this.append("drop table "),e.ifExists&&this.append("if exists "),this.visitNode(e.table),e.cascade&&this.append(" cascade")}visitDataType(e){this.append(e.dataType)}visitOrderBy(e){this.append("order by "),this.compileList(e.items)}visitOrderByItem(e){this.visitNode(e.orderBy),e.direction&&(this.append(" "),this.visitNode(e.direction))}visitGroupBy(e){this.append("group by "),this.compileList(e.items)}visitGroupByItem(e){this.visitNode(e.groupBy)}visitUpdateQuery(e){let i=this.nodeStack.find(a.is),o=i!==e;!o&&e.explain&&(this.visitNode(e.explain),this.append(" ")),o&&!T.is(i)&&this.append("("),e.with&&(this.visitNode(e.with),this.append(" ")),this.append("update "),e.top&&(this.visitNode(e.top),this.append(" ")),e.table&&(this.visitNode(e.table),this.append(" ")),this.append("set "),e.updates&&this.compileList(e.updates),e.output&&(this.append(" "),this.visitNode(e.output)),e.from&&(this.append(" "),this.visitNode(e.from)),e.joins&&(this.append(" "),this.compileList(e.joins," ")),e.where&&(this.append(" "),this.visitNode(e.where)),e.limit&&(this.append(" "),this.visitNode(e.limit)),e.returning&&(this.append(" "),this.visitNode(e.returning)),o&&!T.is(i)&&this.append(")")}visitColumnUpdate(e){this.visitNode(e.column),this.append(" = "),this.visitNode(e.value)}visitLimit(e){this.append("limit "),this.visitNode(e.limit)}visitOffset(e){this.append("offset "),this.visitNode(e.offset)}visitOnConflict(e){this.append("on conflict"),e.columns?(this.append(" ("),this.compileList(e.columns),this.append(")")):e.constraint?(this.append(" on constraint "),this.visitNode(e.constraint)):e.indexExpression&&(this.append(" ("),this.visitNode(e.indexExpression),this.append(")")),e.indexWhere&&(this.append(" "),this.visitNode(e.indexWhere)),e.doNothing===!0?this.append(" do nothing"):e.updates&&(this.append(" do update set "),this.compileList(e.updates),e.updateWhere&&(this.append(" "),this.visitNode(e.updateWhere)))}visitOnDuplicateKey(e){this.append("on duplicate key update "),this.compileList(e.updates)}visitCreateIndex(e){this.append("create "),e.unique&&this.append("unique "),this.append("index "),e.ifNotExists&&this.append("if not exists "),this.visitNode(e.name),e.table&&(this.append(" on "),this.visitNode(e.table)),e.using&&(this.append(" using "),this.visitNode(e.using)),e.columns&&(this.append(" ("),this.compileList(e.columns),this.append(")")),e.nullsNotDistinct&&this.append(" nulls not distinct"),e.where&&(this.append(" "),this.visitNode(e.where))}visitDropIndex(e){this.append("drop index "),e.ifExists&&this.append("if exists "),this.visitNode(e.name),e.table&&(this.append(" on "),this.visitNode(e.table)),e.cascade&&this.append(" cascade")}visitCreateSchema(e){this.append("create schema "),e.ifNotExists&&this.append("if not exists "),this.visitNode(e.schema)}visitDropSchema(e){this.append("drop schema "),e.ifExists&&this.append("if exists "),this.visitNode(e.schema),e.cascade&&this.append(" cascade")}visitPrimaryKeyConstraint(e){e.name&&(this.append("constraint "),this.visitNode(e.name),this.append(" ")),this.append("primary key ("),this.compileList(e.columns),this.append(")")}visitUniqueConstraint(e){e.name&&(this.append("constraint "),this.visitNode(e.name),this.append(" ")),this.append("unique"),e.nullsNotDistinct&&this.append(" nulls not distinct"),this.append(" ("),this.compileList(e.columns),this.append(")")}visitCheckConstraint(e){e.name&&(this.append("constraint "),this.visitNode(e.name),this.append(" ")),this.append("check ("),this.visitNode(e.expression),this.append(")")}visitForeignKeyConstraint(e){e.name&&(this.append("constraint "),this.visitNode(e.name),this.append(" ")),this.append("foreign key ("),this.compileList(e.columns),this.append(") "),this.visitNode(e.references),e.onDelete&&(this.append(" on delete "),this.append(e.onDelete)),e.onUpdate&&(this.append(" on update "),this.append(e.onUpdate))}visitList(e){this.compileList(e.items)}visitWith(e){this.append("with "),e.recursive&&this.append("recursive "),this.compileList(e.expressions)}visitCommonTableExpression(e){this.visitNode(e.name),this.append(" as "),Ae(e.materialized)&&(e.materialized||this.append("not "),this.append("materialized ")),this.visitNode(e.expression)}visitCommonTableExpressionName(e){this.visitNode(e.table),e.columns&&(this.append("("),this.compileList(e.columns),this.append(")"))}visitAlterTable(e){this.append("alter table "),this.visitNode(e.table),this.append(" "),e.renameTo&&(this.append("rename to "),this.visitNode(e.renameTo)),e.setSchema&&(this.append("set schema "),this.visitNode(e.setSchema)),e.addConstraint&&this.visitNode(e.addConstraint),e.dropConstraint&&this.visitNode(e.dropConstraint),e.columnAlterations&&this.compileColumnAlterations(e.columnAlterations),e.addIndex&&this.visitNode(e.addIndex),e.dropIndex&&this.visitNode(e.dropIndex)}visitAddColumn(e){this.append("add column "),this.visitNode(e.column)}visitRenameColumn(e){this.append("rename column "),this.visitNode(e.column),this.append(" to "),this.visitNode(e.renameTo)}visitDropColumn(e){this.append("drop column "),this.visitNode(e.column)}visitAlterColumn(e){this.append("alter column "),this.visitNode(e.column),this.append(" "),e.dataType&&(this.announcesNewColumnDataType()&&this.append("type "),this.visitNode(e.dataType),e.dataTypeExpression&&(this.append("using "),this.visitNode(e.dataTypeExpression))),e.setDefault&&(this.append("set default "),this.visitNode(e.setDefault)),e.dropDefault&&this.append("drop default"),e.setNotNull&&this.append("set not null"),e.dropNotNull&&this.append("drop not null")}visitModifyColumn(e){this.append("modify column "),this.visitNode(e.column)}visitAddConstraint(e){this.append("add "),this.visitNode(e.constraint)}visitDropConstraint(e){this.append("drop constraint "),e.ifExists&&this.append("if exists "),this.visitNode(e.constraintName),e.modifier==="cascade"?this.append(" cascade"):e.modifier==="restrict"&&this.append(" restrict")}visitSetOperation(e){this.append(e.operator),this.append(" "),e.all&&this.append("all "),this.visitNode(e.expression)}visitCreateView(e){this.append("create "),e.orReplace&&this.append("or replace "),e.materialized&&this.append("materialized "),e.temporary&&this.append("temporary "),this.append("view "),e.ifNotExists&&this.append("if not exists "),this.visitNode(e.name),this.append(" "),e.columns&&(this.append("("),this.compileList(e.columns),this.append(") ")),e.as&&(this.append("as "),this.visitNode(e.as))}visitDropView(e){this.append("drop "),e.materialized&&this.append("materialized "),this.append("view "),e.ifExists&&this.append("if exists "),this.visitNode(e.name),e.cascade&&this.append(" cascade")}visitGenerated(e){this.append("generated "),e.always&&this.append("always "),e.byDefault&&this.append("by default "),this.append("as "),e.identity&&this.append("identity"),e.expression&&(this.append("("),this.visitNode(e.expression),this.append(")")),e.stored&&this.append(" stored")}visitDefaultValue(e){this.append("default "),this.visitNode(e.defaultValue)}visitSelectModifier(e){e.rawModifier?this.visitNode(e.rawModifier):this.append(pn[e.modifier]),e.of&&(this.append(" of "),this.compileList(e.of,", "))}visitCreateType(e){this.append("create type "),this.visitNode(e.name),e.enum&&(this.append(" as enum "),this.visitNode(e.enum))}visitDropType(e){this.append("drop type "),e.ifExists&&this.append("if exists "),this.visitNode(e.name)}visitExplain(e){this.append("explain"),(e.options||e.format)&&(this.append(" "),this.append(this.getLeftExplainOptionsWrapper()),e.options&&(this.visitNode(e.options),e.format&&this.append(this.getExplainOptionsDelimiter())),e.format&&(this.append("format"),this.append(this.getExplainOptionAssignment()),this.append(e.format)),this.append(this.getRightExplainOptionsWrapper()))}visitDefaultInsertValue(e){this.append("default")}visitAggregateFunction(e){this.append(e.func),this.append("("),e.distinct&&this.append("distinct "),this.compileList(e.aggregated),this.append(")"),e.filter&&(this.append(" filter("),this.visitNode(e.filter),this.append(")")),e.over&&(this.append(" "),this.visitNode(e.over))}visitOver(e){this.append("over("),e.partitionBy&&(this.visitNode(e.partitionBy),e.orderBy&&this.append(" ")),e.orderBy&&this.visitNode(e.orderBy),this.append(")")}visitPartitionBy(e){this.append("partition by "),this.compileList(e.items)}visitPartitionByItem(e){this.visitNode(e.partitionBy)}visitBinaryOperation(e){this.visitNode(e.leftOperand),this.append(" "),this.visitNode(e.operator),this.append(" "),this.visitNode(e.rightOperand)}visitUnaryOperation(e){this.visitNode(e.operator),this.isMinusOperator(e.operator)||this.append(" "),this.visitNode(e.operand)}isMinusOperator(e){return U.is(e)&&e.operator==="-"}visitUsing(e){this.append("using "),this.compileList(e.tables)}visitFunction(e){this.append(e.func),this.append("("),this.compileList(e.arguments),this.append(")")}visitCase(e){this.append("case"),e.value&&(this.append(" "),this.visitNode(e.value)),e.when&&(this.append(" "),this.compileList(e.when," ")),e.else&&(this.append(" else "),this.visitNode(e.else)),this.append(" end"),e.isStatement&&this.append(" case")}visitWhen(e){this.append("when "),this.visitNode(e.condition),e.result&&(this.append(" then "),this.visitNode(e.result))}visitJSONReference(e){this.visitNode(e.reference),this.visitNode(e.traversal)}visitJSONPath(e){e.inOperator&&this.visitNode(e.inOperator),this.append("'$");for(let i of e.pathLegs)this.visitNode(i);this.append("'")}visitJSONPathLeg(e){let i=e.type==="ArrayLocation";this.append(i?"[":"."),this.append(String(e.value)),i&&this.append("]")}visitJSONOperatorChain(e){for(let i=0,o=e.values.length;i<o;i++)i===o-1?this.visitNode(e.operator):this.append("->"),this.visitNode(e.values[i])}visitMergeQuery(e){e.with&&(this.visitNode(e.with),this.append(" ")),this.append("merge "),e.top&&(this.visitNode(e.top),this.append(" ")),this.append("into "),this.visitNode(e.into),e.using&&(this.append(" "),this.visitNode(e.using)),e.whens&&(this.append(" "),this.compileList(e.whens," ")),e.output&&(this.append(" "),this.visitNode(e.output))}visitMatched(e){e.not&&this.append("not "),this.append("matched"),e.bySource&&this.append(" by source")}visitAddIndex(e){this.append("add "),e.unique&&this.append("unique "),this.append("index "),this.visitNode(e.name),e.columns&&(this.append(" ("),this.compileList(e.columns),this.append(")")),e.using&&(this.append(" using "),this.visitNode(e.using))}visitCast(e){this.append("cast("),this.visitNode(e.expression),this.append(" as "),this.visitNode(e.dataType),this.append(")")}visitFetch(e){this.append("fetch next "),this.visitNode(e.rowCount),this.append(` rows ${e.modifier}`)}visitOutput(e){this.append("output "),this.compileList(e.selections)}visitTop(e){this.append(`top(${e.expression})`),e.modifiers&&this.append(` ${e.modifiers}`)}append(e){this.#e+=e}appendValue(e){this.addParameter(e),this.append(this.getCurrentParameterPlaceholder())}getLeftIdentifierWrapper(){return'"'}getRightIdentifierWrapper(){return'"'}getCurrentParameterPlaceholder(){return"$"+this.numParameters}getLeftExplainOptionsWrapper(){return"("}getExplainOptionAssignment(){return" "}getExplainOptionsDelimiter(){return", "}getRightExplainOptionsWrapper(){return")"}sanitizeIdentifier(e){let i=this.getLeftIdentifierWrapper(),o=this.getRightIdentifierWrapper(),n="";for(let u of e)n+=u,u===i?n+=i:u===o&&(n+=o);return n}addParameter(e){this.#t.push(e)}appendImmediateValue(e){if(g(e))this.append(`'${e}'`);else if(we(e)||Ae(e))this.append(e.toString());else if(Fe(e))this.append("null");else if(Ii(e))this.appendImmediateValue(e.toISOString());else if(Me(e))this.appendImmediateValue(e.toString());else throw new Error(`invalid immediate value ${e}`)}sortSelectModifiers(e){return e.sort((i,o)=>i.modifier&&o.modifier?Co[i.modifier]-Co[o.modifier]:1),r(e)}compileColumnAlterations(e){this.compileList(e)}announcesNewColumnDataType(){return!0}},pn=r({ForKeyShare:"for key share",ForNoKeyUpdate:"for no key update",ForUpdate:"for update",ForShare:"for share",NoWait:"nowait",SkipLocked:"skip locked",Distinct:"distinct"}),Co=r({ForKeyShare:1,ForNoKeyUpdate:1,ForUpdate:1,ForShare:1,NoWait:2,SkipLocked:2,Distinct:0}),hn=r({InnerJoin:"inner join",LeftJoin:"left join",RightJoin:"right join",FullJoin:"full join",LateralInnerJoin:"inner join lateral",LateralLeftJoin:"left join lateral",Using:"using"});var Br=class{async init(){}async acquireConnection(){return new Ci}async beginTransaction(){}async commitTransaction(){}async rollbackTransaction(){}async releaseConnection(){}async destroy(){}},Ci=class{async executeQuery(){return{rows:[]}}async*streamQuery(){}};var Lr=class{get supportsCreateIfNotExists(){return!0}get supportsTransactionalDdl(){return!1}get supportsReturning(){return!1}get supportsOutput(){return!1}};var cn=/"/g,Qr=class extends Dr{sanitizeIdentifier(e){return e.replace(cn,'""')}};var mn=BigInt("3853314791062309107"),Pr=class extends Lr{get supportsTransactionalDdl(){return!0}get supportsReturning(){return!0}async acquireMigrationLock(e,i){await ct`select pg_advisory_xact_lock(${ct.lit(mn)})`.execute(e)}async releaseMigrationLock(e,i){}};function bo(t){return ct`(select coalesce(json_agg(agg), '[]') from ${t} as agg)`}function Wo(t){return new ht({dialect:{createAdapter:()=>new t.Adapter,createDriver:()=>new Br,createIntrospector:()=>null,createQueryCompiler:()=>new t.QueryCompiler},plugins:[...t.noParameters?[new bi]:[]]})}var bi=class{#e=new Wi;transformQuery(e){return this.#e.transformNode(e.node)}transformResult(e){return Promise.resolve(e.result)}},Wi=class extends be{transformValue(e){return{...super.transformValue(e),immediate:!0}}};function qo(t){let e=t.compile();return{parameters:e.parameters,sql:e.sql}}var ln="r",fn="v",Nn=[ln,fn];function yn(t){return qo(On(t).selectFrom("pg_catalog.pg_class as cls").innerJoin("pg_catalog.pg_namespace as ns","cls.relnamespace","ns.oid").$call(xn).where("cls.relkind","in",Nn).select(e=>["ns.nspname as schema","cls.relname as name",bo(e.selectFrom("pg_catalog.pg_attribute as att").whereRef("att.attrelid","=","cls.oid").where("att.attnum",">=",0).where("att.attisdropped","!=",!0).select("att.attname as name")).as("columns")]))}function wn(){return[{schema:"public",name:"users",columns:[{name:"id"},{name:"name"},{name:"role"},{name:"created_at"}]}]}function xn(t){return t.where("ns.nspname","!~","^pg_").where("ns.nspname","!=","information_schema")}function On(t){return Wo({...t,Adapter:Pr,QueryCompiler:Qr})}0&&(module.exports={getTablesQuery,mockTablesQuery});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { DialectAdapter, QueryCompiler } from 'kysely';
|
|
2
|
+
|
|
3
|
+
interface BuilderRequirements {
|
|
4
|
+
Adapter: {
|
|
5
|
+
new (): DialectAdapter;
|
|
6
|
+
};
|
|
7
|
+
noParameters?: boolean;
|
|
8
|
+
QueryCompiler: {
|
|
9
|
+
new (): QueryCompiler;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
declare const queryType: unique symbol;
|
|
13
|
+
interface Query<T> {
|
|
14
|
+
[queryType]?: T;
|
|
15
|
+
parameters: readonly unknown[];
|
|
16
|
+
sql: string;
|
|
17
|
+
}
|
|
18
|
+
type QueryResult<T> = T extends Query<infer R> ? R[] : T extends (...args: any[]) => Query<infer R> ? R[] : never;
|
|
19
|
+
|
|
20
|
+
declare function getTablesQuery(requirements?: Omit<BuilderRequirements, "Adapter" | "Compiler">): Query<{
|
|
21
|
+
schema: string;
|
|
22
|
+
name: string;
|
|
23
|
+
columns: {
|
|
24
|
+
name: string;
|
|
25
|
+
}[];
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
* For testing purposes.
|
|
29
|
+
*/
|
|
30
|
+
declare function mockTablesQuery(): QueryResult<typeof getTablesQuery>;
|
|
31
|
+
|
|
32
|
+
export { getTablesQuery, mockTablesQuery };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { DialectAdapter, QueryCompiler } from 'kysely';
|
|
2
|
+
|
|
3
|
+
interface BuilderRequirements {
|
|
4
|
+
Adapter: {
|
|
5
|
+
new (): DialectAdapter;
|
|
6
|
+
};
|
|
7
|
+
noParameters?: boolean;
|
|
8
|
+
QueryCompiler: {
|
|
9
|
+
new (): QueryCompiler;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
declare const queryType: unique symbol;
|
|
13
|
+
interface Query<T> {
|
|
14
|
+
[queryType]?: T;
|
|
15
|
+
parameters: readonly unknown[];
|
|
16
|
+
sql: string;
|
|
17
|
+
}
|
|
18
|
+
type QueryResult<T> = T extends Query<infer R> ? R[] : T extends (...args: any[]) => Query<infer R> ? R[] : never;
|
|
19
|
+
|
|
20
|
+
declare function getTablesQuery(requirements?: Omit<BuilderRequirements, "Adapter" | "Compiler">): Query<{
|
|
21
|
+
schema: string;
|
|
22
|
+
name: string;
|
|
23
|
+
columns: {
|
|
24
|
+
name: string;
|
|
25
|
+
}[];
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
* For testing purposes.
|
|
29
|
+
*/
|
|
30
|
+
declare function mockTablesQuery(): QueryResult<typeof getTablesQuery>;
|
|
31
|
+
|
|
32
|
+
export { getTablesQuery, mockTablesQuery };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function z(t){return typeof t>"u"||t===void 0}function g(t){return typeof t=="string"}function we(t){return typeof t=="number"}function Ae(t){return typeof t=="boolean"}function Fe(t){return t===null}function Ti(t){return t instanceof Date}function Me(t){return typeof t=="bigint"}function O(t){return typeof t=="function"}function Q(t){return typeof t=="object"&&t!==null}function r(t){return Object.freeze(t)}function mt(t){return E(t)?t:[t]}function E(t){return Array.isArray(t)}function te(t){return t}var c=r({is(t){return t.kind==="AlterTableNode"},create(t){return r({kind:"AlterTableNode",table:t})},cloneWithTableProps(t,e){return r({...t,...e})},cloneWithColumnAlteration(t,e){return r({...t,columnAlterations:t.columnAlterations?[...t.columnAlterations,e]:[e]})}});var d=r({is(t){return t.kind==="IdentifierNode"},create(t){return r({kind:"IdentifierNode",name:t})}});var G=r({is(t){return t.kind==="CreateIndexNode"},create(t){return r({kind:"CreateIndexNode",name:d.create(t)})},cloneWith(t,e){return r({...t,...e})},cloneWithColumns(t,e){return r({...t,columns:[...t.columns||[],...e]})}});var Kt=r({is(t){return t.kind==="CreateSchemaNode"},create(t,e){return r({kind:"CreateSchemaNode",schema:d.create(t),...e})},cloneWith(t,e){return r({...t,...e})}});var Ii=["preserve rows","delete rows","drop"],R=r({is(t){return t.kind==="CreateTableNode"},create(t){return r({kind:"CreateTableNode",table:t,columns:r([])})},cloneWithColumn(t,e){return r({...t,columns:r([...t.columns,e])})},cloneWithConstraint(t,e){return r({...t,constraints:t.constraints?r([...t.constraints,e]):r([e])})},cloneWithFrontModifier(t,e){return r({...t,frontModifiers:t.frontModifiers?r([...t.frontModifiers,e]):r([e])})},cloneWithEndModifier(t,e){return r({...t,endModifiers:t.endModifiers?r([...t.endModifiers,e]):r([e])})},cloneWith(t,e){return r({...t,...e})}});var F=r({is(t){return t.kind==="SchemableIdentifierNode"},create(t){return r({kind:"SchemableIdentifierNode",identifier:d.create(t)})},createWithSchema(t,e){return r({kind:"SchemableIdentifierNode",schema:d.create(t),identifier:d.create(e)})}});var xe=r({is(t){return t.kind==="DropIndexNode"},create(t,e){return r({kind:"DropIndexNode",name:F.create(t),...e})},cloneWith(t,e){return r({...t,...e})}});var lt=r({is(t){return t.kind==="DropSchemaNode"},create(t,e){return r({kind:"DropSchemaNode",schema:d.create(t),...e})},cloneWith(t,e){return r({...t,...e})}});var ft=r({is(t){return t.kind==="DropTableNode"},create(t,e){return r({kind:"DropTableNode",table:t,...e})},cloneWith(t,e){return r({...t,...e})}});var D=r({is(t){return t.kind==="AliasNode"},create(t,e){return r({kind:"AliasNode",node:t,alias:e})}});var K=r({is(t){return t.kind==="TableNode"},create(t){return r({kind:"TableNode",table:F.create(t)})},createWithSchema(t,e){return r({kind:"TableNode",table:F.createWithSchema(t,e)})}});function x(t){return Q(t)&&O(t.toOperationNode)}function Si(t){return Q(t)&&"expressionType"in t&&x(t)}function ki(t){return Q(t)&&"expression"in t&&g(t.alias)&&x(t)}var re=r({is(t){return t.kind==="SelectModifierNode"},create(t,e){return r({kind:"SelectModifierNode",modifier:t,of:e})},createWithExpression(t){return r({kind:"SelectModifierNode",rawModifier:t})}});var M=r({is(t){return t.kind==="AndNode"},create(t,e){return r({kind:"AndNode",left:t,right:e})}});var H=r({is(t){return t.kind==="OrNode"},create(t,e){return r({kind:"OrNode",left:t,right:e})}});var jt=r({is(t){return t.kind==="OnNode"},create(t){return r({kind:"OnNode",on:t})},cloneWithOperation(t,e,i){return r({...t,on:e==="And"?M.create(t.on,i):H.create(t.on,i)})}});var Oe=r({is(t){return t.kind==="JoinNode"},create(t,e){return r({kind:"JoinNode",joinType:t,table:e,on:void 0})},createWithOn(t,e,i){return r({kind:"JoinNode",joinType:t,table:e,on:jt.create(i)})},cloneWithOn(t,e){return r({...t,on:t.on?jt.cloneWithOperation(t.on,"And",e):jt.create(e)})}});var ge=r({is(t){return t.kind==="BinaryOperationNode"},create(t,e,i){return r({kind:"BinaryOperationNode",leftOperand:t,operator:e,rightOperand:i})}});var To=["=","==","!=","<>",">",">=","<","<=","in","not in","is","is not","like","not like","match","ilike","not ilike","@>","<@","^@","&&","?","?&","?|","!<","!>","<=>","!~","~","~*","!~*","@@","@@@","!!","<->","regexp","is distinct from","is not distinct from"],Io=["+","-","*","/","%","^","&","|","#","<<",">>"],Ai=["->","->>"],So=[...To,...Io,"&&","||"],ko=["exists","not exists"],Ao=["not","-",...ko],Ei=[...So,...Ai,...Ao,"between","between symmetric"],U=r({is(t){return t.kind==="OperatorNode"},create(t){return r({kind:"OperatorNode",operator:t})}});function Fr(t){return g(t)&&Ai.includes(t)}var h=r({is(t){return t.kind==="ColumnNode"},create(t){return r({kind:"ColumnNode",column:d.create(t)})}});var Ve=r({is(t){return t.kind==="SelectAllNode"},create(){return r({kind:"SelectAllNode"})}});var ze=r({is(t){return t.kind==="ReferenceNode"},create(t,e){return r({kind:"ReferenceNode",table:e,column:t})},createSelectAll(t){return r({kind:"ReferenceNode",table:t,column:Ve.create()})}});var Gt=class{#e;get dynamicReference(){return this.#e}get refType(){}constructor(e){this.#e=e}toOperationNode(){return Mr(this.#e)}};function Ht(t){return Q(t)&&x(t)&&g(t.dynamicReference)}var Yt=r({is(t){return t.kind==="OrderByItemNode"},create(t,e){return r({kind:"OrderByItemNode",orderBy:t,direction:e})}});var C=r({is(t){return t.kind==="RawNode"},create(t,e){return r({kind:"RawNode",sqlFragments:r(t),parameters:r(e)})},createWithSql(t){return C.create([t],[])},createWithChild(t){return C.create(["",""],[t])},createWithChildren(t){return C.create(new Array(t.length+1).fill(""),t)}});function zr(t){return t==="asc"||t==="desc"}function ve(t){if(t.length===2)return[Vr(t[0],t[1])];if(t.length===1){let[e]=t;return Array.isArray(e)?e.map(i=>Vr(i)):[Vr(e)]}throw new Error(`Invalid number of arguments at order by! expected 1-2, received ${t.length}`)}function Vr(t,e){let i=Eo(t);if(Yt.is(i)){if(e)throw new Error("Cannot specify direction twice!");return i}return Yt.create(i,Ri(e))}function Eo(t){if(he(t))return V(t);if(Ht(t))return t.toOperationNode();let[e,i]=t.split(" ");if(i){if(!zr(i))throw new Error(`Invalid order by direction: ${i}`);return Yt.create(J(e),Ri(i))}return J(t)}function Ri(t){if(t)return t==="asc"||t==="desc"?C.createWithSql(t):t.toOperationNode()}var Ue=r({is(t){return t.kind==="JSONReferenceNode"},create(t,e){return r({kind:"JSONReferenceNode",reference:t,traversal:e})},cloneWithTraversal(t,e){return r({...t,traversal:e})}});var Xt=r({is(t){return t.kind==="JSONOperatorChainNode"},create(t){return r({kind:"JSONOperatorChainNode",operator:t,values:r([])})},cloneWithValue(t,e){return r({...t,values:r([...t.values,e])})}});var Ce=r({is(t){return t.kind==="JSONPathNode"},create(t){return r({kind:"JSONPathNode",inOperator:t,pathLegs:r([])})},cloneWithLeg(t,e){return r({...t,pathLegs:r([...t.pathLegs,e])})}});function Mr(t){return g(t)?J(t):t.toOperationNode()}function ce(t){return E(t)?t.map(e=>I(e)):[I(t)]}function I(t){return he(t)?V(t):Mr(t)}function Di(t,e){let i=J(t);if(Fr(e))return Ue.create(i,Xt.create(U.create(e)));let o=e.slice(0,-1);if(Fr(o))return Ue.create(i,Ce.create(U.create(o)));throw new Error(`Invalid JSON operator: ${e}`)}function J(t){let e=".";if(!t.includes(e))return ze.create(h.create(t));let i=t.split(e).map(Jr);if(i.length===3)return Ro(i);if(i.length===2)return Do(i);throw new Error(`invalid column reference ${t}`)}function Bi(t){let e=" as ";if(t.includes(e)){let[i,o]=t.split(e).map(Jr);return D.create(J(i),d.create(o))}else return J(t)}function Ur(t){return h.create(t)}function Je(t){let e=" ";if(t.includes(e)){let[i,o]=t.split(e).map(Jr);if(!zr(o))throw new Error(`invalid order direction "${o}" next to "${i}"`);return ve([i,o])[0]}else return Ur(t)}function Ro(t){let[e,i,o]=t;return ze.create(h.create(o),K.createWithSchema(e,i))}function Do(t){let[e,i]=t;return ze.create(h.create(i),K.create(e))}function Jr(t){return t.trim()}var Zt=r({is(t){return t.kind==="PrimitiveValueListNode"},create(t){return r({kind:"PrimitiveValueListNode",values:r([...t])})}});var $e=r({is(t){return t.kind==="ValueListNode"},create(t){return r({kind:"ValueListNode",values:r(t)})}});var S=r({is(t){return t.kind==="ValueNode"},create(t){return r({kind:"ValueNode",value:t})},createImmediate(t){return r({kind:"ValueNode",value:t,immediate:!0})}});function Li(t){return E(t)?Bo(t):N(t)}function N(t){return he(t)?V(t):S.create(t)}function _t(t){return we(t)||Ae(t)||Fe(t)}function Nt(t){if(!_t(t))throw new Error(`unsafe immediate value ${JSON.stringify(t)}`);return S.createImmediate(t)}function Bo(t){return t.some(he)?$e.create(t.map(e=>N(e))):Zt.create(t)}var ie=r({is(t){return t.kind==="ParensNode"},create(t){return r({kind:"ParensNode",node:t})}});function y(t){if(t.length===3)return er(t[0],t[1],t[2]);if(t.length===1)return N(t[0]);throw new Error(`invalid arguments: ${JSON.stringify(t)}`)}function er(t,e,i){return Lo(e)&&Pi(i)?ge.create(I(t),$r(e),S.createImmediate(i)):ge.create(I(t),$r(e),Li(i))}function W(t,e,i){return ge.create(I(t),$r(e),I(i))}function Kr(t,e){return Ke(Object.entries(t).filter(([,i])=>!z(i)).map(([i,o])=>er(i,Pi(o)?"is":"=",o)),e)}function Ke(t,e,i=!0){let o=e==="and"?M.create:H.create;if(t.length===0)return ge.create(S.createImmediate(1),U.create("="),S.createImmediate(e==="and"?1:0));let n=Qi(t[0]);for(let u=1;u<t.length;++u)n=o(n,Qi(t[u]));return t.length>1&&i?ie.create(n):n}function Lo(t){return t==="is"||t==="is not"}function Pi(t){return Fe(t)||Ae(t)}function $r(t){if(g(t)&&Ei.includes(t))return U.create(t);if(x(t))return t.toOperationNode();throw new Error(`invalid operator ${JSON.stringify(t)}`)}function Qi(t){return x(t)?t.toOperationNode():t}var me=r({is(t){return t.kind==="OrderByNode"},create(t){return r({kind:"OrderByNode",items:r([...t])})},cloneWithItems(t,e){return r({...t,items:r([...t.items,...e])})}});var jr=r({is(t){return t.kind==="PartitionByNode"},create(t){return r({kind:"PartitionByNode",items:r(t)})},cloneWithItems(t,e){return r({...t,items:r([...t.items,...e])})}});var yt=r({is(t){return t.kind==="OverNode"},create(){return r({kind:"OverNode"})},cloneWithOrderByItems(t,e){return r({...t,orderBy:t.orderBy?me.cloneWithItems(t.orderBy,e):me.create(e)})},cloneWithPartitionByItems(t,e){return r({...t,partitionBy:t.partitionBy?jr.cloneWithItems(t.partitionBy,e):jr.create(e)})}});var Ee=r({is(t){return t.kind==="FromNode"},create(t){return r({kind:"FromNode",froms:r(t)})},cloneWithFroms(t,e){return r({...t,froms:r([...t.froms,...e])})}});var Gr=r({is(t){return t.kind==="GroupByNode"},create(t){return r({kind:"GroupByNode",items:r(t)})},cloneWithItems(t,e){return r({...t,items:r([...t.items,...e])})}});var Hr=r({is(t){return t.kind==="HavingNode"},create(t){return r({kind:"HavingNode",having:t})},cloneWithOperation(t,e,i){return r({...t,having:e==="And"?M.create(t.having,i):H.create(t.having,i)})}});var p=r({is(t){return t.kind==="SelectQueryNode"},create(t){return r({kind:"SelectQueryNode",...t&&{with:t}})},createFrom(t,e){return r({kind:"SelectQueryNode",from:Ee.create(t),...e&&{with:e}})},cloneWithSelections(t,e){return r({...t,selections:t.selections?r([...t.selections,...e]):r(e)})},cloneWithDistinctOn(t,e){return r({...t,distinctOn:t.distinctOn?r([...t.distinctOn,...e]):r(e)})},cloneWithFrontModifier(t,e){return r({...t,frontModifiers:t.frontModifiers?r([...t.frontModifiers,e]):r([e])})},cloneWithEndModifier(t,e){return r({...t,endModifiers:t.endModifiers?r([...t.endModifiers,e]):r([e])})},cloneWithOrderByItems(t,e){return r({...t,orderBy:t.orderBy?me.cloneWithItems(t.orderBy,e):me.create(e)})},cloneWithGroupByItems(t,e){return r({...t,groupBy:t.groupBy?Gr.cloneWithItems(t.groupBy,e):Gr.create(e)})},cloneWithLimit(t,e){return r({...t,limit:e})},cloneWithOffset(t,e){return r({...t,offset:e})},cloneWithFetch(t,e){return r({...t,fetch:e})},cloneWithHaving(t,e){return r({...t,having:t.having?Hr.cloneWithOperation(t.having,"And",e):Hr.create(e)})},cloneWithSetOperations(t,e){return r({...t,setOperations:t.setOperations?r([...t.setOperations,...e]):r([...e])})},cloneWithoutSelections(t){return r({...t,selections:[]})},cloneWithoutLimit(t){return r({...t,limit:void 0})},cloneWithoutOffset(t){return r({...t,offset:void 0})},cloneWithoutOrderBy(t){return r({...t,orderBy:void 0})},cloneWithoutGroupBy(t){return r({...t,groupBy:void 0})}});function s(t,e){Object.defineProperties(t.prototype,{then:{enumerable:!1,value:()=>{throw new Error(e)}}})}var wt=class t{#e;constructor(e){this.#e=r(e)}on(...e){return new t({...this.#e,joinNode:Oe.cloneWithOn(this.#e.joinNode,y(e))})}onRef(e,i,o){return new t({...this.#e,joinNode:Oe.cloneWithOn(this.#e.joinNode,W(e,i,o))})}onTrue(){return new t({...this.#e,joinNode:Oe.cloneWithOn(this.#e.joinNode,C.createWithSql("true"))})}$call(e){return e(this)}toOperationNode(){return this.#e.joinNode}};s(wt,"don't await JoinBuilder instances. They are never executed directly and are always just a part of a query.");var Fi=r({is(t){return t.kind==="PartitionByItemNode"},create(t){return r({kind:"PartitionByItemNode",partitionBy:t})}});function Mi(t){return ce(t).map(Fi.create)}var xt=class t{#e;constructor(e){this.#e=r(e)}orderBy(e,i){return new t({overNode:yt.cloneWithOrderByItems(this.#e.overNode,ve([e,i]))})}partitionBy(e){return new t({overNode:yt.cloneWithPartitionByItems(this.#e.overNode,Mi(e))})}$call(e){return e(this)}toOperationNode(){return this.#e.overNode}};s(xt,"don't await OverBuilder instances. They are never executed directly and are always just a part of a query.");var je=r({is(t){return t.kind==="SelectionNode"},create(t){return r({kind:"SelectionNode",selection:t})},createSelectAll(){return r({kind:"SelectionNode",selection:Ve.create()})},createSelectAllFromTable(t){return r({kind:"SelectionNode",selection:ze.createSelectAll(t)})}});function k(t){return O(t)?k(t(Y())):E(t)?t.map(e=>Vi(e)):[Vi(t)]}function Vi(t){return g(t)?je.create(Bi(t)):Ht(t)?je.create(t.toOperationNode()):je.create(tr(t))}function B(t){return t?Array.isArray(t)?t.map(zi):[zi(t)]:[je.createSelectAll()]}function zi(t){if(g(t))return je.createSelectAllFromTable(l(t));throw new Error(`invalid value selectAll expression: ${JSON.stringify(t)}`)}var Ui=r({is(t){return t.kind==="ValuesNode"},create(t){return r({kind:"ValuesNode",values:r(t)})}});var Ji=r({is(t){return t.kind==="DefaultInsertValueNode"},create(){return r({kind:"DefaultInsertValueNode"})}});function rr(t){let e=O(t)?t(Y()):t,i=E(e)?e:r([e]);return Qo(i)}function Qo(t){let e=Po(t);return[r([...e.keys()].map(h.create)),Ui.create(t.map(i=>Fo(i,e)))]}function Po(t){let e=new Map;for(let i of t){let o=Object.keys(i);for(let n of o)!e.has(n)&&i[n]!==void 0&&e.set(n,e.size)}return e}function Fo(t,e){let i=Object.keys(t),o=Array.from({length:e.size}),n=!1;for(let v of i){let L=e.get(v);if(z(L))continue;let pe=t[v];(z(pe)||he(pe))&&(n=!0),o[L]=pe}if(i.length<e.size||n){let v=Ji.create();return $e.create(o.map(L=>z(L)?v:N(L)))}return Zt.create(o)}var q=r({is(t){return t.kind==="InsertQueryNode"},create(t,e,i){return r({kind:"InsertQueryNode",into:t,...e&&{with:e},replace:i})},createWithoutInto(){return r({kind:"InsertQueryNode"})},cloneWith(t,e){return r({...t,...e})}});var oe=r({is(t){return t.kind==="UpdateQueryNode"},create(t,e){return r({kind:"UpdateQueryNode",table:t,...e&&{with:e}})},createWithoutTable(){return r({kind:"UpdateQueryNode"})},cloneWithFromItems(t,e){return r({...t,from:t.from?Ee.cloneWithFroms(t.from,e):Ee.create(e)})},cloneWithUpdates(t,e){return r({...t,updates:t.updates?r([...t.updates,...e]):e})},cloneWithLimit(t,e){return r({...t,limit:e})}});var Yr=r({is(t){return t.kind==="UsingNode"},create(t){return r({kind:"UsingNode",tables:r(t)})},cloneWithTables(t,e){return r({...t,tables:r([...t.tables,...e])})}});var ne=r({is(t){return t.kind==="DeleteQueryNode"},create(t,e){return r({kind:"DeleteQueryNode",from:Ee.create(t),...e&&{with:e}})},cloneWithOrderByItems(t,e){return r({...t,orderBy:t.orderBy?me.cloneWithItems(t.orderBy,e):me.create(e)})},cloneWithoutOrderBy(t){return r({...t,orderBy:void 0})},cloneWithLimit(t,e){return r({...t,limit:e})},cloneWithoutLimit(t){return r({...t,limit:void 0})},cloneWithUsing(t,e){return r({...t,using:t.using!==void 0?Yr.cloneWithTables(t.using,e):Yr.create(e)})}});var A=r({is(t){return t.kind==="WhereNode"},create(t){return r({kind:"WhereNode",where:t})},cloneWithOperation(t,e,i){return r({...t,where:e==="And"?M.create(t.where,i):H.create(t.where,i)})}});var Xr=r({is(t){return t.kind==="ReturningNode"},create(t){return r({kind:"ReturningNode",selections:r(t)})},cloneWithSelections(t,e){return r({...t,selections:t.selections?r([...t.selections,...e]):r(e)})}});var $i=r({is(t){return t.kind==="ExplainNode"},create(t,e){return r({kind:"ExplainNode",format:t,options:e})}});var le=r({is(t){return t.kind==="WhenNode"},create(t){return r({kind:"WhenNode",condition:t})},cloneWithResult(t,e){return r({...t,result:e})}});var T=r({is(t){return t.kind==="MergeQueryNode"},create(t,e){return r({kind:"MergeQueryNode",into:t,...e&&{with:e}})},cloneWithUsing(t,e){return r({...t,using:e})},cloneWithWhen(t,e){return r({...t,whens:t.whens?r([...t.whens,e]):r([e])})},cloneWithThen(t,e){return r({...t,whens:t.whens?r([...t.whens.slice(0,-1),le.cloneWithResult(t.whens[t.whens.length-1],e)]):void 0})}});var Zr=r({is(t){return t.kind==="OutputNode"},create(t){return r({kind:"OutputNode",selections:r(t)})},cloneWithSelections(t,e){return r({...t,selections:t.selections?r([...t.selections,...e]):r(e)})}});var a=r({is(t){return p.is(t)||q.is(t)||oe.is(t)||ne.is(t)||T.is(t)},cloneWithWhere(t,e){return r({...t,where:t.where?A.cloneWithOperation(t.where,"And",e):A.create(e)})},cloneWithJoin(t,e){return r({...t,joins:t.joins?r([...t.joins,e]):r([e])})},cloneWithReturning(t,e){return r({...t,returning:t.returning?Xr.cloneWithSelections(t.returning,e):Xr.create(e)})},cloneWithoutReturning(t){return r({...t,returning:void 0})},cloneWithoutWhere(t){return r({...t,where:void 0})},cloneWithExplain(t,e,i){return r({...t,explain:$i.create(e,i?.toOperationNode())})},cloneWithTop(t,e){return r({...t,top:e})},cloneWithOutput(t,e){return r({...t,output:t.output?Zr.cloneWithSelections(t.output,e):Zr.create(e)})}});var _r=r({is(t){return t.kind==="ColumnUpdateNode"},create(t,e){return r({kind:"ColumnUpdateNode",column:t,value:e})}});function Ki(...t){return t.length===2?[_r.create(I(t[0]),N(t[1]))]:Ot(t[0])}function Ot(t){let e=O(t)?t(Y()):t;return Object.entries(e).filter(([i,o])=>o!==void 0).map(([i,o])=>_r.create(h.create(i),N(o)))}var ji=r({is(t){return t.kind==="OnDuplicateKeyNode"},create(t){return r({kind:"OnDuplicateKeyNode",updates:t})}});var ir=class{insertId;numInsertedOrUpdatedRows;constructor(e,i){this.insertId=e,this.numInsertedOrUpdatedRows=i}};var j=class extends Error{node;constructor(e){super("no result"),this.node=e}};function se(t){return Object.prototype.hasOwnProperty.call(t,"prototype")}var P=r({is(t){return t.kind==="OnConflictNode"},create(){return r({kind:"OnConflictNode"})},cloneWith(t,e){return r({...t,...e})},cloneWithIndexWhere(t,e){return r({...t,indexWhere:t.indexWhere?A.cloneWithOperation(t.indexWhere,"And",e):A.create(e)})},cloneWithIndexOrWhere(t,e){return r({...t,indexWhere:t.indexWhere?A.cloneWithOperation(t.indexWhere,"Or",e):A.create(e)})},cloneWithUpdateWhere(t,e){return r({...t,updateWhere:t.updateWhere?A.cloneWithOperation(t.updateWhere,"And",e):A.create(e)})},cloneWithUpdateOrWhere(t,e){return r({...t,updateWhere:t.updateWhere?A.cloneWithOperation(t.updateWhere,"Or",e):A.create(e)})},cloneWithoutIndexWhere(t){return r({...t,indexWhere:void 0})},cloneWithoutUpdateWhere(t){return r({...t,updateWhere:void 0})}});var gt=class t{#e;constructor(e){this.#e=r(e)}column(e){let i=h.create(e);return new t({...this.#e,onConflictNode:P.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?r([...this.#e.onConflictNode.columns,i]):r([i])})})}columns(e){let i=e.map(h.create);return new t({...this.#e,onConflictNode:P.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?r([...this.#e.onConflictNode.columns,...i]):r(i)})})}constraint(e){return new t({...this.#e,onConflictNode:P.cloneWith(this.#e.onConflictNode,{constraint:d.create(e)})})}expression(e){return new t({...this.#e,onConflictNode:P.cloneWith(this.#e.onConflictNode,{indexExpression:e.toOperationNode()})})}where(...e){return new t({...this.#e,onConflictNode:P.cloneWithIndexWhere(this.#e.onConflictNode,y(e))})}whereRef(e,i,o){return new t({...this.#e,onConflictNode:P.cloneWithIndexWhere(this.#e.onConflictNode,W(e,i,o))})}clearWhere(){return new t({...this.#e,onConflictNode:P.cloneWithoutIndexWhere(this.#e.onConflictNode)})}doNothing(){return new or({...this.#e,onConflictNode:P.cloneWith(this.#e.onConflictNode,{doNothing:!0})})}doUpdateSet(e){return new nr({...this.#e,onConflictNode:P.cloneWith(this.#e.onConflictNode,{updates:Ot(e)})})}$call(e){return e(this)}};s(gt,"don't await OnConflictBuilder instances.");var or=class{#e;constructor(e){this.#e=r(e)}toOperationNode(){return this.#e.onConflictNode}};s(or,"don't await OnConflictDoNothingBuilder instances.");var nr=class t{#e;constructor(e){this.#e=r(e)}where(...e){return new t({...this.#e,onConflictNode:P.cloneWithUpdateWhere(this.#e.onConflictNode,y(e))})}whereRef(e,i,o){return new t({...this.#e,onConflictNode:P.cloneWithUpdateWhere(this.#e.onConflictNode,W(e,i,o))})}clearWhere(){return new t({...this.#e,onConflictNode:P.cloneWithoutUpdateWhere(this.#e.onConflictNode)})}$call(e){return e(this)}toOperationNode(){return this.#e.onConflictNode}};s(nr,"don't await OnConflictUpdateBuilder instances.");var Gi=r({is(t){return t.kind==="TopNode"},create(t,e){return r({kind:"TopNode",expression:t,modifiers:e})}});function X(t,e){if(!we(t)&&!Me(t))throw new Error(`Invalid top expression: ${t}`);if(!z(e)&&!Mo(e))throw new Error(`Invalid top modifiers: ${e}`);return Gi.create(t,e)}function Mo(t){return t==="percent"||t==="with ties"||t==="percent with ties"}var Ge=class t{#e;constructor(e){this.#e=r(e)}values(e){let[i,o]=rr(e);return new t({...this.#e,queryNode:q.cloneWith(this.#e.queryNode,{columns:i,values:o})})}columns(e){return new t({...this.#e,queryNode:q.cloneWith(this.#e.queryNode,{columns:r(e.map(h.create))})})}expression(e){return new t({...this.#e,queryNode:q.cloneWith(this.#e.queryNode,{values:V(e)})})}defaultValues(){return new t({...this.#e,queryNode:q.cloneWith(this.#e.queryNode,{defaultValues:!0})})}ignore(){return new t({...this.#e,queryNode:q.cloneWith(this.#e.queryNode,{ignore:!0})})}top(e,i){return new t({...this.#e,queryNode:a.cloneWithTop(this.#e.queryNode,X(e,i))})}onConflict(e){return new t({...this.#e,queryNode:q.cloneWith(this.#e.queryNode,{onConflict:e(new gt({onConflictNode:P.create()})).toOperationNode()})})}onDuplicateKeyUpdate(e){return new t({...this.#e,queryNode:q.cloneWith(this.#e.queryNode,{onDuplicateKey:ji.create(Ot(e))})})}returning(e){return new t({...this.#e,queryNode:a.cloneWithReturning(this.#e.queryNode,k(e))})}returningAll(){return new t({...this.#e,queryNode:a.cloneWithReturning(this.#e.queryNode,B())})}output(e){return new t({...this.#e,queryNode:a.cloneWithOutput(this.#e.queryNode,k(e))})}outputAll(e){return new t({...this.#e,queryNode:a.cloneWithOutput(this.#e.queryNode,B(e))})}clearReturning(){return new t({...this.#e,queryNode:a.cloneWithoutReturning(this.#e.queryNode)})}$call(e){return e(this)}$if(e,i){return e?i(this):new t({...this.#e})}$castTo(){return new t(this.#e)}$narrowType(){return new t(this.#e)}$assertType(){return new t(this.#e)}withPlugin(e){return new t({...this.#e,executor:this.#e.executor.withPlugin(e)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile(),i=await this.#e.executor.executeQuery(e,this.#e.queryId),{adapter:o}=this.#e.executor,n=e.query;return n.returning&&o.supportsReturning||n.output&&o.supportsOutput?i.rows:[new ir(i.insertId,i.numAffectedRows??i.numUpdatedOrDeletedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=j){let i=await this.executeTakeFirst();if(i===void 0)throw se(e)?new e(this.toOperationNode()):e(this.toOperationNode());return i}async*stream(e=100){let i=this.compile(),o=this.#e.executor.stream(i,e,this.#e.queryId);for await(let n of o)yield*n.rows}async explain(e,i){return await new t({...this.#e,queryNode:a.cloneWithExplain(this.#e.queryNode,e,i)}).execute()}};s(Ge,"don't await InsertQueryBuilder instances directly. To execute the query you need to call `execute` or `executeTakeFirst`.");var sr=class{numDeletedRows;constructor(e){this.numDeletedRows=e}};var He=r({is(t){return t.kind==="LimitNode"},create(t){return r({kind:"LimitNode",limit:t})}});var vt=class t{#e;constructor(e){this.#e=r(e)}where(...e){return new t({...this.#e,queryNode:a.cloneWithWhere(this.#e.queryNode,y(e))})}whereRef(e,i,o){return new t({...this.#e,queryNode:a.cloneWithWhere(this.#e.queryNode,W(e,i,o))})}clearWhere(){return new t({...this.#e,queryNode:a.cloneWithoutWhere(this.#e.queryNode)})}top(e,i){return new t({...this.#e,queryNode:a.cloneWithTop(this.#e.queryNode,X(e,i))})}using(e){return new t({...this.#e,queryNode:ne.cloneWithUsing(this.#e.queryNode,ae(e))})}innerJoin(...e){return new t({...this.#e,queryNode:a.cloneWithJoin(this.#e.queryNode,b("InnerJoin",e))})}leftJoin(...e){return new t({...this.#e,queryNode:a.cloneWithJoin(this.#e.queryNode,b("LeftJoin",e))})}rightJoin(...e){return new t({...this.#e,queryNode:a.cloneWithJoin(this.#e.queryNode,b("RightJoin",e))})}fullJoin(...e){return new t({...this.#e,queryNode:a.cloneWithJoin(this.#e.queryNode,b("FullJoin",e))})}returning(e){return new t({...this.#e,queryNode:a.cloneWithReturning(this.#e.queryNode,k(e))})}returningAll(e){return new t({...this.#e,queryNode:a.cloneWithReturning(this.#e.queryNode,B(e))})}output(e){return new t({...this.#e,queryNode:a.cloneWithOutput(this.#e.queryNode,k(e))})}outputAll(e){return new t({...this.#e,queryNode:a.cloneWithOutput(this.#e.queryNode,B(e))})}clearReturning(){return new t({...this.#e,queryNode:a.cloneWithoutReturning(this.#e.queryNode)})}clearLimit(){return new t({...this.#e,queryNode:ne.cloneWithoutLimit(this.#e.queryNode)})}clearOrderBy(){return new t({...this.#e,queryNode:ne.cloneWithoutOrderBy(this.#e.queryNode)})}orderBy(e,i){return new t({...this.#e,queryNode:ne.cloneWithOrderByItems(this.#e.queryNode,ve([e,i]))})}limit(e){return new t({...this.#e,queryNode:ne.cloneWithLimit(this.#e.queryNode,He.create(N(e)))})}$call(e){return e(this)}$if(e,i){return e?i(this):new t({...this.#e})}$castTo(){return new t(this.#e)}$narrowType(){return new t(this.#e)}$assertType(){return new t(this.#e)}withPlugin(e){return new t({...this.#e,executor:this.#e.executor.withPlugin(e)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile(),i=await this.#e.executor.executeQuery(e,this.#e.queryId),{adapter:o}=this.#e.executor,n=e.query;return n.returning&&o.supportsReturning||n.output&&o.supportsOutput?i.rows:[new sr(i.numAffectedRows??i.numUpdatedOrDeletedRows??BigInt(0))]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=j){let i=await this.executeTakeFirst();if(i===void 0)throw se(e)?new e(this.toOperationNode()):e(this.toOperationNode());return i}async*stream(e=100){let i=this.compile(),o=this.#e.executor.stream(i,e,this.#e.queryId);for await(let n of o)yield*n.rows}async explain(e,i){return await new t({...this.#e,queryNode:a.cloneWithExplain(this.#e.queryNode,e,i)}).execute()}};s(vt,"don't await DeleteQueryBuilder instances directly. To execute the query you need to call `execute` or `executeTakeFirst`.");var ar=class{numUpdatedRows;numChangedRows;constructor(e,i){this.numUpdatedRows=e,this.numChangedRows=i}};var Re=class t{#e;constructor(e){this.#e=r(e)}where(...e){return new t({...this.#e,queryNode:a.cloneWithWhere(this.#e.queryNode,y(e))})}whereRef(e,i,o){return new t({...this.#e,queryNode:a.cloneWithWhere(this.#e.queryNode,W(e,i,o))})}clearWhere(){return new t({...this.#e,queryNode:a.cloneWithoutWhere(this.#e.queryNode)})}top(e,i){return new t({...this.#e,queryNode:a.cloneWithTop(this.#e.queryNode,X(e,i))})}from(e){return new t({...this.#e,queryNode:oe.cloneWithFromItems(this.#e.queryNode,ae(e))})}innerJoin(...e){return new t({...this.#e,queryNode:a.cloneWithJoin(this.#e.queryNode,b("InnerJoin",e))})}leftJoin(...e){return new t({...this.#e,queryNode:a.cloneWithJoin(this.#e.queryNode,b("LeftJoin",e))})}rightJoin(...e){return new t({...this.#e,queryNode:a.cloneWithJoin(this.#e.queryNode,b("RightJoin",e))})}fullJoin(...e){return new t({...this.#e,queryNode:a.cloneWithJoin(this.#e.queryNode,b("FullJoin",e))})}limit(e){return new t({...this.#e,queryNode:oe.cloneWithLimit(this.#e.queryNode,He.create(N(e)))})}set(...e){return new t({...this.#e,queryNode:oe.cloneWithUpdates(this.#e.queryNode,Ki(...e))})}returning(e){return new t({...this.#e,queryNode:a.cloneWithReturning(this.#e.queryNode,k(e))})}returningAll(e){return new t({...this.#e,queryNode:a.cloneWithReturning(this.#e.queryNode,B(e))})}output(e){return new t({...this.#e,queryNode:a.cloneWithOutput(this.#e.queryNode,k(e))})}outputAll(e){return new t({...this.#e,queryNode:a.cloneWithOutput(this.#e.queryNode,B(e))})}clearReturning(){return new t({...this.#e,queryNode:a.cloneWithoutReturning(this.#e.queryNode)})}$call(e){return e(this)}$if(e,i){return e?i(this):new t({...this.#e})}$castTo(){return new t(this.#e)}$narrowType(){return new t(this.#e)}$assertType(){return new t(this.#e)}withPlugin(e){return new t({...this.#e,executor:this.#e.executor.withPlugin(e)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile(),i=await this.#e.executor.executeQuery(e,this.#e.queryId),{adapter:o}=this.#e.executor,n=e.query;return n.returning&&o.supportsReturning||n.output&&o.supportsOutput?i.rows:[new ar(i.numAffectedRows??i.numUpdatedOrDeletedRows??BigInt(0),i.numChangedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=j){let i=await this.executeTakeFirst();if(i===void 0)throw se(e)?new e(this.toOperationNode()):e(this.toOperationNode());return i}async*stream(e=100){let i=this.compile(),o=this.#e.executor.stream(i,e,this.#e.queryId);for await(let n of o)yield*n.rows}async explain(e,i){return await new t({...this.#e,queryNode:a.cloneWithExplain(this.#e.queryNode,e,i)}).execute()}};s(Re,"don't await UpdateQueryBuilder instances directly. To execute the query you need to call `execute` or `executeTakeFirst`.");var ei=r({is(t){return t.kind==="CommonTableExpressionNameNode"},create(t,e){return r({kind:"CommonTableExpressionNameNode",table:K.create(t),columns:e?r(e.map(h.create)):void 0})}});var Ye=r({is(t){return t.kind==="CommonTableExpressionNode"},create(t,e){return r({kind:"CommonTableExpressionNode",name:t,expression:e})},cloneWith(t,e){return r({...t,...e})}});var Ct=class t{#e;constructor(e){this.#e=r(e)}materialized(){return new t({...this.#e,node:Ye.cloneWith(this.#e.node,{materialized:!0})})}notMaterialized(){return new t({...this.#e,node:Ye.cloneWith(this.#e.node,{materialized:!1})})}toOperationNode(){return this.#e.node}};s(Ct,"don't await CTEBuilder instances. They are never executed directly and are always just a part of a query.");function ti(t,e){let i=e(Yi()).toOperationNode();return O(t)?t(Vo(i)).toOperationNode():Ye.create(Hi(t),i)}function Vo(t){return e=>new Ct({node:Ye.create(Hi(e),t)})}function Hi(t){if(t.includes("(")){let e=t.split(/[\(\)]/),i=e[0],o=e[1].split(",").map(n=>n.trim());return ei.create(i,o)}else return ei.create(t)}var bt=r({is(t){return t.kind==="WithNode"},create(t,e){return r({kind:"WithNode",expressions:r([t]),...e})},cloneWithExpression(t,e){return r({...t,expressions:r([...t.expressions,e])})}});var Xi=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"];function Zi(t){let e="";for(let i=0;i<t;++i)e+=zo();return e}function zo(){return Xi[~~(Math.random()*Xi.length)]}function m(){return new ri}var ri=class{#e;get queryId(){return this.#e===void 0&&(this.#e=Zi(8)),this.#e}};var be=class{nodeStack=[];#e=r({AliasNode:this.transformAlias.bind(this),ColumnNode:this.transformColumn.bind(this),IdentifierNode:this.transformIdentifier.bind(this),SchemableIdentifierNode:this.transformSchemableIdentifier.bind(this),RawNode:this.transformRaw.bind(this),ReferenceNode:this.transformReference.bind(this),SelectQueryNode:this.transformSelectQuery.bind(this),SelectionNode:this.transformSelection.bind(this),TableNode:this.transformTable.bind(this),FromNode:this.transformFrom.bind(this),SelectAllNode:this.transformSelectAll.bind(this),AndNode:this.transformAnd.bind(this),OrNode:this.transformOr.bind(this),ValueNode:this.transformValue.bind(this),ValueListNode:this.transformValueList.bind(this),PrimitiveValueListNode:this.transformPrimitiveValueList.bind(this),ParensNode:this.transformParens.bind(this),JoinNode:this.transformJoin.bind(this),OperatorNode:this.transformOperator.bind(this),WhereNode:this.transformWhere.bind(this),InsertQueryNode:this.transformInsertQuery.bind(this),DeleteQueryNode:this.transformDeleteQuery.bind(this),ReturningNode:this.transformReturning.bind(this),CreateTableNode:this.transformCreateTable.bind(this),AddColumnNode:this.transformAddColumn.bind(this),ColumnDefinitionNode:this.transformColumnDefinition.bind(this),DropTableNode:this.transformDropTable.bind(this),DataTypeNode:this.transformDataType.bind(this),OrderByNode:this.transformOrderBy.bind(this),OrderByItemNode:this.transformOrderByItem.bind(this),GroupByNode:this.transformGroupBy.bind(this),GroupByItemNode:this.transformGroupByItem.bind(this),UpdateQueryNode:this.transformUpdateQuery.bind(this),ColumnUpdateNode:this.transformColumnUpdate.bind(this),LimitNode:this.transformLimit.bind(this),OffsetNode:this.transformOffset.bind(this),OnConflictNode:this.transformOnConflict.bind(this),OnDuplicateKeyNode:this.transformOnDuplicateKey.bind(this),CreateIndexNode:this.transformCreateIndex.bind(this),DropIndexNode:this.transformDropIndex.bind(this),ListNode:this.transformList.bind(this),PrimaryKeyConstraintNode:this.transformPrimaryKeyConstraint.bind(this),UniqueConstraintNode:this.transformUniqueConstraint.bind(this),ReferencesNode:this.transformReferences.bind(this),CheckConstraintNode:this.transformCheckConstraint.bind(this),WithNode:this.transformWith.bind(this),CommonTableExpressionNode:this.transformCommonTableExpression.bind(this),CommonTableExpressionNameNode:this.transformCommonTableExpressionName.bind(this),HavingNode:this.transformHaving.bind(this),CreateSchemaNode:this.transformCreateSchema.bind(this),DropSchemaNode:this.transformDropSchema.bind(this),AlterTableNode:this.transformAlterTable.bind(this),DropColumnNode:this.transformDropColumn.bind(this),RenameColumnNode:this.transformRenameColumn.bind(this),AlterColumnNode:this.transformAlterColumn.bind(this),ModifyColumnNode:this.transformModifyColumn.bind(this),AddConstraintNode:this.transformAddConstraint.bind(this),DropConstraintNode:this.transformDropConstraint.bind(this),ForeignKeyConstraintNode:this.transformForeignKeyConstraint.bind(this),CreateViewNode:this.transformCreateView.bind(this),DropViewNode:this.transformDropView.bind(this),GeneratedNode:this.transformGenerated.bind(this),DefaultValueNode:this.transformDefaultValue.bind(this),OnNode:this.transformOn.bind(this),ValuesNode:this.transformValues.bind(this),SelectModifierNode:this.transformSelectModifier.bind(this),CreateTypeNode:this.transformCreateType.bind(this),DropTypeNode:this.transformDropType.bind(this),ExplainNode:this.transformExplain.bind(this),DefaultInsertValueNode:this.transformDefaultInsertValue.bind(this),AggregateFunctionNode:this.transformAggregateFunction.bind(this),OverNode:this.transformOver.bind(this),PartitionByNode:this.transformPartitionBy.bind(this),PartitionByItemNode:this.transformPartitionByItem.bind(this),SetOperationNode:this.transformSetOperation.bind(this),BinaryOperationNode:this.transformBinaryOperation.bind(this),UnaryOperationNode:this.transformUnaryOperation.bind(this),UsingNode:this.transformUsing.bind(this),FunctionNode:this.transformFunction.bind(this),CaseNode:this.transformCase.bind(this),WhenNode:this.transformWhen.bind(this),JSONReferenceNode:this.transformJSONReference.bind(this),JSONPathNode:this.transformJSONPath.bind(this),JSONPathLegNode:this.transformJSONPathLeg.bind(this),JSONOperatorChainNode:this.transformJSONOperatorChain.bind(this),TupleNode:this.transformTuple.bind(this),MergeQueryNode:this.transformMergeQuery.bind(this),MatchedNode:this.transformMatched.bind(this),AddIndexNode:this.transformAddIndex.bind(this),CastNode:this.transformCast.bind(this),FetchNode:this.transformFetch.bind(this),TopNode:this.transformTop.bind(this),OutputNode:this.transformOutput.bind(this)});transformNode(e){if(!e)return e;this.nodeStack.push(e);let i=this.transformNodeImpl(e);return this.nodeStack.pop(),r(i)}transformNodeImpl(e){return this.#e[e.kind](e)}transformNodeList(e){return e&&r(e.map(i=>this.transformNode(i)))}transformSelectQuery(e){return{kind:"SelectQueryNode",from:this.transformNode(e.from),selections:this.transformNodeList(e.selections),distinctOn:this.transformNodeList(e.distinctOn),joins:this.transformNodeList(e.joins),groupBy:this.transformNode(e.groupBy),orderBy:this.transformNode(e.orderBy),where:this.transformNode(e.where),frontModifiers:this.transformNodeList(e.frontModifiers),endModifiers:this.transformNodeList(e.endModifiers),limit:this.transformNode(e.limit),offset:this.transformNode(e.offset),with:this.transformNode(e.with),having:this.transformNode(e.having),explain:this.transformNode(e.explain),setOperations:this.transformNodeList(e.setOperations),fetch:this.transformNode(e.fetch),top:this.transformNode(e.top)}}transformSelection(e){return{kind:"SelectionNode",selection:this.transformNode(e.selection)}}transformColumn(e){return{kind:"ColumnNode",column:this.transformNode(e.column)}}transformAlias(e){return{kind:"AliasNode",node:this.transformNode(e.node),alias:this.transformNode(e.alias)}}transformTable(e){return{kind:"TableNode",table:this.transformNode(e.table)}}transformFrom(e){return{kind:"FromNode",froms:this.transformNodeList(e.froms)}}transformReference(e){return{kind:"ReferenceNode",column:this.transformNode(e.column),table:this.transformNode(e.table)}}transformAnd(e){return{kind:"AndNode",left:this.transformNode(e.left),right:this.transformNode(e.right)}}transformOr(e){return{kind:"OrNode",left:this.transformNode(e.left),right:this.transformNode(e.right)}}transformValueList(e){return{kind:"ValueListNode",values:this.transformNodeList(e.values)}}transformParens(e){return{kind:"ParensNode",node:this.transformNode(e.node)}}transformJoin(e){return{kind:"JoinNode",joinType:e.joinType,table:this.transformNode(e.table),on:this.transformNode(e.on)}}transformRaw(e){return{kind:"RawNode",sqlFragments:r([...e.sqlFragments]),parameters:this.transformNodeList(e.parameters)}}transformWhere(e){return{kind:"WhereNode",where:this.transformNode(e.where)}}transformInsertQuery(e){return{kind:"InsertQueryNode",into:this.transformNode(e.into),columns:this.transformNodeList(e.columns),values:this.transformNode(e.values),returning:this.transformNode(e.returning),onConflict:this.transformNode(e.onConflict),onDuplicateKey:this.transformNode(e.onDuplicateKey),with:this.transformNode(e.with),ignore:e.ignore,replace:e.replace,explain:this.transformNode(e.explain),defaultValues:e.defaultValues,top:this.transformNode(e.top),output:this.transformNode(e.output)}}transformValues(e){return{kind:"ValuesNode",values:this.transformNodeList(e.values)}}transformDeleteQuery(e){return{kind:"DeleteQueryNode",from:this.transformNode(e.from),using:this.transformNode(e.using),joins:this.transformNodeList(e.joins),where:this.transformNode(e.where),returning:this.transformNode(e.returning),with:this.transformNode(e.with),orderBy:this.transformNode(e.orderBy),limit:this.transformNode(e.limit),explain:this.transformNode(e.explain),top:this.transformNode(e.top),output:this.transformNode(e.output)}}transformReturning(e){return{kind:"ReturningNode",selections:this.transformNodeList(e.selections)}}transformCreateTable(e){return{kind:"CreateTableNode",table:this.transformNode(e.table),columns:this.transformNodeList(e.columns),constraints:this.transformNodeList(e.constraints),temporary:e.temporary,ifNotExists:e.ifNotExists,onCommit:e.onCommit,frontModifiers:this.transformNodeList(e.frontModifiers),endModifiers:this.transformNodeList(e.endModifiers),selectQuery:this.transformNode(e.selectQuery)}}transformColumnDefinition(e){return{kind:"ColumnDefinitionNode",column:this.transformNode(e.column),dataType:this.transformNode(e.dataType),references:this.transformNode(e.references),primaryKey:e.primaryKey,autoIncrement:e.autoIncrement,unique:e.unique,notNull:e.notNull,unsigned:e.unsigned,defaultTo:this.transformNode(e.defaultTo),check:this.transformNode(e.check),generated:this.transformNode(e.generated),frontModifiers:this.transformNodeList(e.frontModifiers),endModifiers:this.transformNodeList(e.endModifiers),nullsNotDistinct:e.nullsNotDistinct,identity:e.identity,ifNotExists:e.ifNotExists}}transformAddColumn(e){return{kind:"AddColumnNode",column:this.transformNode(e.column)}}transformDropTable(e){return{kind:"DropTableNode",table:this.transformNode(e.table),ifExists:e.ifExists,cascade:e.cascade}}transformOrderBy(e){return{kind:"OrderByNode",items:this.transformNodeList(e.items)}}transformOrderByItem(e){return{kind:"OrderByItemNode",orderBy:this.transformNode(e.orderBy),direction:this.transformNode(e.direction)}}transformGroupBy(e){return{kind:"GroupByNode",items:this.transformNodeList(e.items)}}transformGroupByItem(e){return{kind:"GroupByItemNode",groupBy:this.transformNode(e.groupBy)}}transformUpdateQuery(e){return{kind:"UpdateQueryNode",table:this.transformNode(e.table),from:this.transformNode(e.from),joins:this.transformNodeList(e.joins),where:this.transformNode(e.where),updates:this.transformNodeList(e.updates),returning:this.transformNode(e.returning),with:this.transformNode(e.with),explain:this.transformNode(e.explain),limit:this.transformNode(e.limit),top:this.transformNode(e.top),output:this.transformNode(e.output)}}transformColumnUpdate(e){return{kind:"ColumnUpdateNode",column:this.transformNode(e.column),value:this.transformNode(e.value)}}transformLimit(e){return{kind:"LimitNode",limit:this.transformNode(e.limit)}}transformOffset(e){return{kind:"OffsetNode",offset:this.transformNode(e.offset)}}transformOnConflict(e){return{kind:"OnConflictNode",columns:this.transformNodeList(e.columns),constraint:this.transformNode(e.constraint),indexExpression:this.transformNode(e.indexExpression),indexWhere:this.transformNode(e.indexWhere),updates:this.transformNodeList(e.updates),updateWhere:this.transformNode(e.updateWhere),doNothing:e.doNothing}}transformOnDuplicateKey(e){return{kind:"OnDuplicateKeyNode",updates:this.transformNodeList(e.updates)}}transformCreateIndex(e){return{kind:"CreateIndexNode",name:this.transformNode(e.name),table:this.transformNode(e.table),columns:this.transformNodeList(e.columns),unique:e.unique,using:this.transformNode(e.using),ifNotExists:e.ifNotExists,where:this.transformNode(e.where),nullsNotDistinct:e.nullsNotDistinct}}transformList(e){return{kind:"ListNode",items:this.transformNodeList(e.items)}}transformDropIndex(e){return{kind:"DropIndexNode",name:this.transformNode(e.name),table:this.transformNode(e.table),ifExists:e.ifExists,cascade:e.cascade}}transformPrimaryKeyConstraint(e){return{kind:"PrimaryKeyConstraintNode",columns:this.transformNodeList(e.columns),name:this.transformNode(e.name)}}transformUniqueConstraint(e){return{kind:"UniqueConstraintNode",columns:this.transformNodeList(e.columns),name:this.transformNode(e.name),nullsNotDistinct:e.nullsNotDistinct}}transformForeignKeyConstraint(e){return{kind:"ForeignKeyConstraintNode",columns:this.transformNodeList(e.columns),references:this.transformNode(e.references),name:this.transformNode(e.name),onDelete:e.onDelete,onUpdate:e.onUpdate}}transformSetOperation(e){return{kind:"SetOperationNode",operator:e.operator,expression:this.transformNode(e.expression),all:e.all}}transformReferences(e){return{kind:"ReferencesNode",table:this.transformNode(e.table),columns:this.transformNodeList(e.columns),onDelete:e.onDelete,onUpdate:e.onUpdate}}transformCheckConstraint(e){return{kind:"CheckConstraintNode",expression:this.transformNode(e.expression),name:this.transformNode(e.name)}}transformWith(e){return{kind:"WithNode",expressions:this.transformNodeList(e.expressions),recursive:e.recursive}}transformCommonTableExpression(e){return{kind:"CommonTableExpressionNode",name:this.transformNode(e.name),materialized:e.materialized,expression:this.transformNode(e.expression)}}transformCommonTableExpressionName(e){return{kind:"CommonTableExpressionNameNode",table:this.transformNode(e.table),columns:this.transformNodeList(e.columns)}}transformHaving(e){return{kind:"HavingNode",having:this.transformNode(e.having)}}transformCreateSchema(e){return{kind:"CreateSchemaNode",schema:this.transformNode(e.schema),ifNotExists:e.ifNotExists}}transformDropSchema(e){return{kind:"DropSchemaNode",schema:this.transformNode(e.schema),ifExists:e.ifExists,cascade:e.cascade}}transformAlterTable(e){return{kind:"AlterTableNode",table:this.transformNode(e.table),renameTo:this.transformNode(e.renameTo),setSchema:this.transformNode(e.setSchema),columnAlterations:this.transformNodeList(e.columnAlterations),addConstraint:this.transformNode(e.addConstraint),dropConstraint:this.transformNode(e.dropConstraint),addIndex:this.transformNode(e.addIndex),dropIndex:this.transformNode(e.dropIndex)}}transformDropColumn(e){return{kind:"DropColumnNode",column:this.transformNode(e.column)}}transformRenameColumn(e){return{kind:"RenameColumnNode",column:this.transformNode(e.column),renameTo:this.transformNode(e.renameTo)}}transformAlterColumn(e){return{kind:"AlterColumnNode",column:this.transformNode(e.column),dataType:this.transformNode(e.dataType),dataTypeExpression:this.transformNode(e.dataTypeExpression),setDefault:this.transformNode(e.setDefault),dropDefault:e.dropDefault,setNotNull:e.setNotNull,dropNotNull:e.dropNotNull}}transformModifyColumn(e){return{kind:"ModifyColumnNode",column:this.transformNode(e.column)}}transformAddConstraint(e){return{kind:"AddConstraintNode",constraint:this.transformNode(e.constraint)}}transformDropConstraint(e){return{kind:"DropConstraintNode",constraintName:this.transformNode(e.constraintName),ifExists:e.ifExists,modifier:e.modifier}}transformCreateView(e){return{kind:"CreateViewNode",name:this.transformNode(e.name),temporary:e.temporary,orReplace:e.orReplace,ifNotExists:e.ifNotExists,materialized:e.materialized,columns:this.transformNodeList(e.columns),as:this.transformNode(e.as)}}transformDropView(e){return{kind:"DropViewNode",name:this.transformNode(e.name),ifExists:e.ifExists,materialized:e.materialized,cascade:e.cascade}}transformGenerated(e){return{kind:"GeneratedNode",byDefault:e.byDefault,always:e.always,identity:e.identity,stored:e.stored,expression:this.transformNode(e.expression)}}transformDefaultValue(e){return{kind:"DefaultValueNode",defaultValue:this.transformNode(e.defaultValue)}}transformOn(e){return{kind:"OnNode",on:this.transformNode(e.on)}}transformSelectModifier(e){return{kind:"SelectModifierNode",modifier:e.modifier,rawModifier:this.transformNode(e.rawModifier),of:this.transformNodeList(e.of)}}transformCreateType(e){return{kind:"CreateTypeNode",name:this.transformNode(e.name),enum:this.transformNode(e.enum)}}transformDropType(e){return{kind:"DropTypeNode",name:this.transformNode(e.name),ifExists:e.ifExists}}transformExplain(e){return{kind:"ExplainNode",format:e.format,options:this.transformNode(e.options)}}transformSchemableIdentifier(e){return{kind:"SchemableIdentifierNode",schema:this.transformNode(e.schema),identifier:this.transformNode(e.identifier)}}transformAggregateFunction(e){return{kind:"AggregateFunctionNode",aggregated:this.transformNodeList(e.aggregated),distinct:e.distinct,filter:this.transformNode(e.filter),func:e.func,over:this.transformNode(e.over)}}transformOver(e){return{kind:"OverNode",orderBy:this.transformNode(e.orderBy),partitionBy:this.transformNode(e.partitionBy)}}transformPartitionBy(e){return{kind:"PartitionByNode",items:this.transformNodeList(e.items)}}transformPartitionByItem(e){return{kind:"PartitionByItemNode",partitionBy:this.transformNode(e.partitionBy)}}transformBinaryOperation(e){return{kind:"BinaryOperationNode",leftOperand:this.transformNode(e.leftOperand),operator:this.transformNode(e.operator),rightOperand:this.transformNode(e.rightOperand)}}transformUnaryOperation(e){return{kind:"UnaryOperationNode",operator:this.transformNode(e.operator),operand:this.transformNode(e.operand)}}transformUsing(e){return{kind:"UsingNode",tables:this.transformNodeList(e.tables)}}transformFunction(e){return{kind:"FunctionNode",func:e.func,arguments:this.transformNodeList(e.arguments)}}transformCase(e){return{kind:"CaseNode",value:this.transformNode(e.value),when:this.transformNodeList(e.when),else:this.transformNode(e.else),isStatement:e.isStatement}}transformWhen(e){return{kind:"WhenNode",condition:this.transformNode(e.condition),result:this.transformNode(e.result)}}transformJSONReference(e){return{kind:"JSONReferenceNode",reference:this.transformNode(e.reference),traversal:this.transformNode(e.traversal)}}transformJSONPath(e){return{kind:"JSONPathNode",inOperator:this.transformNode(e.inOperator),pathLegs:this.transformNodeList(e.pathLegs)}}transformJSONPathLeg(e){return{kind:"JSONPathLegNode",type:e.type,value:e.value}}transformJSONOperatorChain(e){return{kind:"JSONOperatorChainNode",operator:this.transformNode(e.operator),values:this.transformNodeList(e.values)}}transformTuple(e){return{kind:"TupleNode",values:this.transformNodeList(e.values)}}transformMergeQuery(e){return{kind:"MergeQueryNode",into:this.transformNode(e.into),using:this.transformNode(e.using),whens:this.transformNodeList(e.whens),with:this.transformNode(e.with),top:this.transformNode(e.top),output:this.transformNode(e.output)}}transformMatched(e){return{kind:"MatchedNode",not:e.not,bySource:e.bySource}}transformAddIndex(e){return{kind:"AddIndexNode",name:this.transformNode(e.name),columns:this.transformNodeList(e.columns),unique:e.unique,using:this.transformNode(e.using),ifNotExists:e.ifNotExists}}transformCast(e){return{kind:"CastNode",expression:this.transformNode(e.expression),dataType:this.transformNode(e.dataType)}}transformFetch(e){return{kind:"FetchNode",rowCount:this.transformNode(e.rowCount),modifier:e.modifier}}transformTop(e){return{kind:"TopNode",expression:e.expression,modifiers:e.modifiers}}transformOutput(e){return{kind:"OutputNode",selections:this.transformNodeList(e.selections)}}transformDataType(e){return e}transformSelectAll(e){return e}transformIdentifier(e){return e}transformValue(e){return e}transformPrimitiveValueList(e){return e}transformOperator(e){return e}transformDefaultInsertValue(e){return e}};var Uo=r({AlterTableNode:!0,CreateIndexNode:!0,CreateSchemaNode:!0,CreateTableNode:!0,CreateTypeNode:!0,CreateViewNode:!0,DeleteQueryNode:!0,DropIndexNode:!0,DropSchemaNode:!0,DropTableNode:!0,DropTypeNode:!0,DropViewNode:!0,InsertQueryNode:!0,RawNode:!0,SelectQueryNode:!0,UpdateQueryNode:!0,MergeQueryNode:!0}),ur=class extends be{#e;#t=new Set;#r=new Set;constructor(e){super(),this.#e=e}transformNodeImpl(e){if(!this.#i(e))return super.transformNodeImpl(e);let i=this.#s(e);for(let u of i)this.#r.add(u);let o=this.#o(e);for(let u of o)this.#t.add(u);let n=super.transformNodeImpl(e);for(let u of o)this.#t.delete(u);for(let u of i)this.#r.delete(u);return n}transformSchemableIdentifier(e){let i=super.transformSchemableIdentifier(e);return i.schema||!this.#t.has(e.identifier.name)?i:{...i,schema:d.create(this.#e)}}transformReferences(e){let i=super.transformReferences(e);return i.table.table.schema?i:{...i,table:K.createWithSchema(this.#e,i.table.table.identifier.name)}}#i(e){return e.kind in Uo}#o(e){let i=new Set;if("name"in e&&e.name&&F.is(e.name)&&this.#a(e.name,i),"from"in e&&e.from)for(let o of e.from.froms)this.#n(o,i);if("into"in e&&e.into&&this.#n(e.into,i),"table"in e&&e.table&&this.#n(e.table,i),"joins"in e&&e.joins)for(let o of e.joins)this.#n(o.table,i);return"using"in e&&e.using&&this.#n(e.using,i),i}#s(e){let i=new Set;return"with"in e&&e.with&&this.#u(e.with,i),i}#n(e,i){let o=K.is(e)?e:D.is(e)&&K.is(e.node)?e.node:null;o&&this.#a(o.table,i)}#a(e,i){let o=e.identifier.name;!this.#t.has(o)&&!this.#r.has(o)&&i.add(o)}#u(e,i){for(let o of e.expressions){let n=o.name.table.table.identifier.name;this.#r.has(n)||i.add(n)}}};var Z=class{#e;constructor(e){this.#e=new ur(e)}transformQuery(e){return this.#e.transformNode(e.node)}async transformResult(e){return e.result}};var _i=r({is(t){return t.kind==="MatchedNode"},create(t,e=!1){return r({kind:"MatchedNode",not:t,bySource:e})}});function ii(t,e,i){return le.create(Ke([_i.create(!t.isMatched,t.bySource),...e&&e.length>0?[e.length===3&&i?W(e[0],e[1],e[2]):y(e)]:[]],"and",!1))}function Xe(t){return g(t)?C.create([t],[]):x(t)?t.toOperationNode():t}var Wt=class{#e;#t;#r;constructor(){this.#e=new Promise((e,i)=>{this.#r=i,this.#t=e})}get promise(){return this.#e}resolve=e=>{this.#t&&this.#t(e)};reject=e=>{this.#r&&this.#r(e)}};var eo=new Set;function to(t){eo.has(t)||(eo.add(t),console.log(t))}var Jo=r([]),Ze=class{#e;constructor(e=Jo){this.#e=e}get plugins(){return this.#e}transformQuery(e,i){for(let o of this.#e){let n=o.transformQuery({node:e,queryId:i});if(n.kind===e.kind)e=n;else throw new Error(["KyselyPlugin.transformQuery must return a node","of the same kind that was given to it.",`The plugin was given a ${e.kind}`,`but it returned a ${n.kind}`].join(" "))}return e}async executeQuery(e,i){return await this.provideConnection(async o=>{let n=await o.executeQuery(e),u=await this.#t(n,i);return $o(n,u),u})}async*stream(e,i,o){let n=new Wt,u=new Wt;this.provideConnection(async L=>(n.resolve(L),await u.promise)).catch(L=>n.reject(L));let v=await n.promise;try{for await(let L of v.streamQuery(e,i))yield await this.#t(L,o)}finally{u.resolve()}}async#t(e,i){for(let o of this.#e)e=await o.transformResult({result:e,queryId:i});return e}};function $o(t,e){let{numAffectedRows:i}=t;i===void 0&&t.numUpdatedOrDeletedRows===void 0||i!==void 0&&e.numAffectedRows!==void 0||to("kysely:warning: outdated driver/plugin detected! QueryResult.numUpdatedOrDeletedRows is deprecated and will be removed in a future release.")}var oi=class t extends Ze{get adapter(){throw new Error("this query cannot be compiled to SQL")}compileQuery(){throw new Error("this query cannot be compiled to SQL")}provideConnection(){throw new Error("this query cannot be executed")}withConnectionProvider(){throw new Error("this query cannot have a connection provider")}withPlugin(e){return new t([...this.plugins,e])}withPlugins(e){return new t([...this.plugins,...e])}withPluginAtFront(e){return new t([e,...this.plugins])}withoutPlugins(){return new t([])}},We=new oi;var dr=class{numChangedRows;constructor(e){this.numChangedRows=e}};var qt=class t{#e;constructor(e){this.#e=r(e)}top(e,i){return new t({...this.#e,queryNode:a.cloneWithTop(this.#e.queryNode,X(e,i))})}using(...e){return new fe({...this.#e,queryNode:T.cloneWithUsing(this.#e.queryNode,b("Using",e))})}output(e){return new t({...this.#e,queryNode:a.cloneWithOutput(this.#e.queryNode,k(e))})}outputAll(e){return new t({...this.#e,queryNode:a.cloneWithOutput(this.#e.queryNode,B(e))})}};s(qt,"don't await MergeQueryBuilder instances directly. To execute the query you need to call `execute` when available.");var fe=class t{#e;constructor(e){this.#e=r(e)}top(e,i){return new t({...this.#e,queryNode:a.cloneWithTop(this.#e.queryNode,X(e,i))})}whenMatched(){return this.#t([])}whenMatchedAnd(...e){return this.#t(e)}whenMatchedAndRef(e,i,o){return this.#t([e,i,o],!0)}#t(e,i){return new Tt({...this.#e,queryNode:T.cloneWithWhen(this.#e.queryNode,ii({isMatched:!0},e,i))})}whenNotMatched(){return this.#r([])}whenNotMatchedAnd(...e){return this.#r(e)}whenNotMatchedAndRef(e,i,o){return this.#r([e,i,o],!0)}whenNotMatchedBySource(){return this.#r([],!1,!0)}whenNotMatchedBySourceAnd(...e){return this.#r(e,!1,!0)}whenNotMatchedBySourceAndRef(e,i,o){return this.#r([e,i,o],!0,!0)}output(e){return new t({...this.#e,queryNode:a.cloneWithOutput(this.#e.queryNode,k(e))})}outputAll(e){return new t({...this.#e,queryNode:a.cloneWithOutput(this.#e.queryNode,B(e))})}#r(e,i=!1,o=!1){let n={...this.#e,queryNode:T.cloneWithWhen(this.#e.queryNode,ii({isMatched:!1,bySource:o},e,i))},u=o?Tt:pr;return new u(n)}$call(e){return e(this)}$if(e,i){return e?i(this):new t({...this.#e})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile(),i=await this.#e.executor.executeQuery(e,this.#e.queryId);return e.query.output&&this.#e.executor.adapter.supportsOutput?i.rows:[new dr(i.numAffectedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=j){let i=await this.executeTakeFirst();if(i===void 0)throw se(e)?new e(this.toOperationNode()):e(this.toOperationNode());return i}};s(fe,"don't await WheneableMergeQueryBuilder instances directly. To execute the query you need to call `execute`.");var Tt=class{#e;constructor(e){this.#e=r(e)}thenDelete(){return new fe({...this.#e,queryNode:T.cloneWithThen(this.#e.queryNode,Xe("delete"))})}thenDoNothing(){return new fe({...this.#e,queryNode:T.cloneWithThen(this.#e.queryNode,Xe("do nothing"))})}thenUpdate(e){return new fe({...this.#e,queryNode:T.cloneWithThen(this.#e.queryNode,Xe(e(new Re({queryId:this.#e.queryId,executor:We,queryNode:oe.createWithoutTable()}))))})}thenUpdateSet(...e){return this.thenUpdate(i=>i.set(...e))}};s(Tt,"don't await MatchedThenableMergeQueryBuilder instances directly. To execute the query you need to call `execute` when available.");var pr=class{#e;constructor(e){this.#e=r(e)}thenDoNothing(){return new fe({...this.#e,queryNode:T.cloneWithThen(this.#e.queryNode,Xe("do nothing"))})}thenInsertValues(e){let[i,o]=rr(e);return new fe({...this.#e,queryNode:T.cloneWithThen(this.#e.queryNode,Xe(q.cloneWith(q.createWithoutInto(),{columns:i,values:o})))})}};s(pr,"don't await NotMatchedThenableMergeQueryBuilder instances directly. To execute the query you need to call `execute` when available.");var _e=class t{#e;constructor(e){this.#e=r(e)}selectFrom(e){return It({queryId:m(),executor:this.#e.executor,queryNode:p.createFrom(ae(e),this.#e.withNode)})}selectNoFrom(e){return It({queryId:m(),executor:this.#e.executor,queryNode:p.cloneWithSelections(p.create(this.#e.withNode),k(e))})}insertInto(e){return new Ge({queryId:m(),executor:this.#e.executor,queryNode:q.create(l(e),this.#e.withNode)})}replaceInto(e){return new Ge({queryId:m(),executor:this.#e.executor,queryNode:q.create(l(e),this.#e.withNode,!0)})}deleteFrom(e){return new vt({queryId:m(),executor:this.#e.executor,queryNode:ne.create(ae(e),this.#e.withNode)})}updateTable(e){return new Re({queryId:m(),executor:this.#e.executor,queryNode:oe.create(qe(e),this.#e.withNode)})}mergeInto(e){return new qt({queryId:m(),executor:this.#e.executor,queryNode:T.create(ni(e),this.#e.withNode)})}with(e,i){let o=ti(e,i);return new t({...this.#e,withNode:this.#e.withNode?bt.cloneWithExpression(this.#e.withNode,o):bt.create(o)})}withRecursive(e,i){let o=ti(e,i);return new t({...this.#e,withNode:this.#e.withNode?bt.cloneWithExpression(this.#e.withNode,o):bt.create(o,{recursive:!0})})}withPlugin(e){return new t({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new t({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new t({...this.#e,executor:this.#e.executor.withPluginAtFront(new Z(e))})}};function Yi(){return new _e({executor:We})}function ro(t,e){return new wt({joinNode:Oe.create(t,qe(e))})}function io(){return new xt({overNode:yt.create()})}function b(t,e){if(e.length===3)return jo(t,e[0],e[1],e[2]);if(e.length===2)return Ko(t,e[0],e[1]);throw new Error("not implemented")}function Ko(t,e,i){return i(ro(t,e)).toOperationNode()}function jo(t,e,i,o){return Oe.createWithOn(t,qe(e),W(i,"=",o))}var oo=r({is(t){return t.kind==="OffsetNode"},create(t){return r({kind:"OffsetNode",offset:t})}});var no=r({is(t){return t.kind==="GroupByItemNode"},create(t){return r({kind:"GroupByItemNode",groupBy:t})}});function so(t){return t=O(t)?t(Y()):t,ce(t).map(no.create)}var hr=r({is(t){return t.kind==="SetOperationNode"},create(t,e,i){return r({kind:"SetOperationNode",operator:t,expression:e,all:i})}});function De(t,e,i){return O(e)&&(e=e(cr())),E(e)||(e=[e]),e.map(o=>hr.create(t,V(o),i))}var f=class t{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new St(this,e)}or(...e){return new si(H.create(this.#e,y(e)))}and(...e){return new ai(M.create(this.#e,y(e)))}$castTo(){return new t(this.#e)}$notNull(){return new t(this.#e)}toOperationNode(){return this.#e}},St=class{#e;#t;constructor(e,i){this.#e=e,this.#t=i}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return D.create(this.#e.toOperationNode(),x(this.#t)?this.#t.toOperationNode():d.create(this.#t))}},si=class t{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new St(this,e)}or(...e){return new t(H.create(this.#e,y(e)))}$castTo(){return new t(this.#e)}toOperationNode(){return ie.create(this.#e)}},ai=class t{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new St(this,e)}and(...e){return new t(M.create(this.#e,y(e)))}$castTo(){return new t(this.#e)}toOperationNode(){return ie.create(this.#e)}};var ao={is(t){return t.kind==="FetchNode"},create(t,e){return{kind:"FetchNode",rowCount:S.create(t),modifier:e}}};function uo(t,e){if(!we(t)&&!Me(t))throw new Error(`Invalid fetch row count: ${t}`);if(!Go(e))throw new Error(`Invalid fetch modifier: ${e}`);return ao.create(t,e)}function Go(t){return t==="only"||t==="with ties"}var mr=class t{#e;constructor(e){this.#e=r(e)}get expressionType(){}get isSelectQueryBuilder(){return!0}where(...e){return new t({...this.#e,queryNode:a.cloneWithWhere(this.#e.queryNode,y(e))})}whereRef(e,i,o){return new t({...this.#e,queryNode:a.cloneWithWhere(this.#e.queryNode,W(e,i,o))})}having(...e){return new t({...this.#e,queryNode:p.cloneWithHaving(this.#e.queryNode,y(e))})}havingRef(e,i,o){return new t({...this.#e,queryNode:p.cloneWithHaving(this.#e.queryNode,W(e,i,o))})}select(e){return new t({...this.#e,queryNode:p.cloneWithSelections(this.#e.queryNode,k(e))})}distinctOn(e){return new t({...this.#e,queryNode:p.cloneWithDistinctOn(this.#e.queryNode,ce(e))})}modifyFront(e){return new t({...this.#e,queryNode:p.cloneWithFrontModifier(this.#e.queryNode,re.createWithExpression(e.toOperationNode()))})}modifyEnd(e){return new t({...this.#e,queryNode:p.cloneWithEndModifier(this.#e.queryNode,re.createWithExpression(e.toOperationNode()))})}distinct(){return new t({...this.#e,queryNode:p.cloneWithFrontModifier(this.#e.queryNode,re.create("Distinct"))})}forUpdate(e){return new t({...this.#e,queryNode:p.cloneWithEndModifier(this.#e.queryNode,re.create("ForUpdate",e?mt(e).map(l):void 0))})}forShare(e){return new t({...this.#e,queryNode:p.cloneWithEndModifier(this.#e.queryNode,re.create("ForShare",e?mt(e).map(l):void 0))})}forKeyShare(e){return new t({...this.#e,queryNode:p.cloneWithEndModifier(this.#e.queryNode,re.create("ForKeyShare",e?mt(e).map(l):void 0))})}forNoKeyUpdate(e){return new t({...this.#e,queryNode:p.cloneWithEndModifier(this.#e.queryNode,re.create("ForNoKeyUpdate",e?mt(e).map(l):void 0))})}skipLocked(){return new t({...this.#e,queryNode:p.cloneWithEndModifier(this.#e.queryNode,re.create("SkipLocked"))})}noWait(){return new t({...this.#e,queryNode:p.cloneWithEndModifier(this.#e.queryNode,re.create("NoWait"))})}selectAll(e){return new t({...this.#e,queryNode:p.cloneWithSelections(this.#e.queryNode,B(e))})}innerJoin(...e){return new t({...this.#e,queryNode:a.cloneWithJoin(this.#e.queryNode,b("InnerJoin",e))})}leftJoin(...e){return new t({...this.#e,queryNode:a.cloneWithJoin(this.#e.queryNode,b("LeftJoin",e))})}rightJoin(...e){return new t({...this.#e,queryNode:a.cloneWithJoin(this.#e.queryNode,b("RightJoin",e))})}fullJoin(...e){return new t({...this.#e,queryNode:a.cloneWithJoin(this.#e.queryNode,b("FullJoin",e))})}innerJoinLateral(...e){return new t({...this.#e,queryNode:a.cloneWithJoin(this.#e.queryNode,b("LateralInnerJoin",e))})}leftJoinLateral(...e){return new t({...this.#e,queryNode:a.cloneWithJoin(this.#e.queryNode,b("LateralLeftJoin",e))})}orderBy(...e){return new t({...this.#e,queryNode:p.cloneWithOrderByItems(this.#e.queryNode,ve(e))})}groupBy(e){return new t({...this.#e,queryNode:p.cloneWithGroupByItems(this.#e.queryNode,so(e))})}limit(e){return new t({...this.#e,queryNode:p.cloneWithLimit(this.#e.queryNode,He.create(N(e)))})}offset(e){return new t({...this.#e,queryNode:p.cloneWithOffset(this.#e.queryNode,oo.create(N(e)))})}fetch(e,i="only"){return new t({...this.#e,queryNode:p.cloneWithFetch(this.#e.queryNode,uo(e,i))})}top(e,i){return new t({...this.#e,queryNode:a.cloneWithTop(this.#e.queryNode,X(e,i))})}union(e){return new t({...this.#e,queryNode:p.cloneWithSetOperations(this.#e.queryNode,De("union",e,!1))})}unionAll(e){return new t({...this.#e,queryNode:p.cloneWithSetOperations(this.#e.queryNode,De("union",e,!0))})}intersect(e){return new t({...this.#e,queryNode:p.cloneWithSetOperations(this.#e.queryNode,De("intersect",e,!1))})}intersectAll(e){return new t({...this.#e,queryNode:p.cloneWithSetOperations(this.#e.queryNode,De("intersect",e,!0))})}except(e){return new t({...this.#e,queryNode:p.cloneWithSetOperations(this.#e.queryNode,De("except",e,!1))})}exceptAll(e){return new t({...this.#e,queryNode:p.cloneWithSetOperations(this.#e.queryNode,De("except",e,!0))})}as(e){return new lr(this,e)}clearSelect(){return new t({...this.#e,queryNode:p.cloneWithoutSelections(this.#e.queryNode)})}clearWhere(){return new t({...this.#e,queryNode:a.cloneWithoutWhere(this.#e.queryNode)})}clearLimit(){return new t({...this.#e,queryNode:p.cloneWithoutLimit(this.#e.queryNode)})}clearOffset(){return new t({...this.#e,queryNode:p.cloneWithoutOffset(this.#e.queryNode)})}clearOrderBy(){return new t({...this.#e,queryNode:p.cloneWithoutOrderBy(this.#e.queryNode)})}clearGroupBy(){return new t({...this.#e,queryNode:p.cloneWithoutGroupBy(this.#e.queryNode)})}$call(e){return e(this)}$if(e,i){return e?i(this):new t({...this.#e})}$castTo(){return new t(this.#e)}$narrowType(){return new t(this.#e)}$assertType(){return new t(this.#e)}$asTuple(){return new f(this.toOperationNode())}withPlugin(e){return new t({...this.#e,executor:this.#e.executor.withPlugin(e)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile();return(await this.#e.executor.executeQuery(e,this.#e.queryId)).rows}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=j){let i=await this.executeTakeFirst();if(i===void 0)throw se(e)?new e(this.toOperationNode()):e(this.toOperationNode());return i}async*stream(e=100){let i=this.compile(),o=this.#e.executor.stream(i,e,this.#e.queryId);for await(let n of o)yield*n.rows}async explain(e,i){return await new t({...this.#e,queryNode:a.cloneWithExplain(this.#e.queryNode,e,i)}).execute()}};s(mr,"don't await SelectQueryBuilder instances directly. To execute the query you need to call `execute` or `executeTakeFirst`.");function It(t){return new mr(t)}var lr=class{#e;#t;constructor(e,i){this.#e=e,this.#t=i}get expression(){return this.#e}get alias(){return this.#t}get isAliasedSelectQueryBuilder(){return!0}toOperationNode(){return D.create(this.#e.toOperationNode(),d.create(this.#t))}};s(lr,"don't await AliasedSelectQueryBuilder instances directly. AliasedSelectQueryBuilder should never be executed directly since it's always a part of another query.");var Ne=r({is(t){return t.kind==="AggregateFunctionNode"},create(t,e=[]){return r({kind:"AggregateFunctionNode",func:t,aggregated:e})},cloneWithDistinct(t){return r({...t,distinct:!0})},cloneWithFilter(t,e){return r({...t,filter:t.filter?A.cloneWithOperation(t.filter,"And",e):A.create(e)})},cloneWithOrFilter(t,e){return r({...t,filter:t.filter?A.cloneWithOperation(t.filter,"Or",e):A.create(e)})},cloneWithOver(t,e){return r({...t,over:e})}});var ui=r({is(t){return t.kind==="FunctionNode"},create(t,e){return r({kind:"FunctionNode",func:t,arguments:e})}});var Be=class t{#e;constructor(e){this.#e=r(e)}get expressionType(){}as(e){return new di(this,e)}distinct(){return new t({...this.#e,aggregateFunctionNode:Ne.cloneWithDistinct(this.#e.aggregateFunctionNode)})}filterWhere(...e){return new t({...this.#e,aggregateFunctionNode:Ne.cloneWithFilter(this.#e.aggregateFunctionNode,y(e))})}filterWhereRef(e,i,o){return new t({...this.#e,aggregateFunctionNode:Ne.cloneWithFilter(this.#e.aggregateFunctionNode,W(e,i,o))})}over(e){let i=io();return new t({...this.#e,aggregateFunctionNode:Ne.cloneWithOver(this.#e.aggregateFunctionNode,(e?e(i):i).toOperationNode())})}$call(e){return e(this)}$castTo(){return new t(this.#e)}$notNull(){return new t(this.#e)}toOperationNode(){return this.#e.aggregateFunctionNode}};s(Be,"don't await AggregateFunctionBuilder instances. They are never executed directly and are always just a part of a query.");var di=class{#e;#t;constructor(e,i){this.#e=e,this.#t=i}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return D.create(this.#e.toOperationNode(),d.create(this.#t))}};function fr(){let t=(i,o)=>new f(ui.create(i,ce(o??[]))),e=(i,o)=>new Be({aggregateFunctionNode:Ne.create(i,o?ce(o):void 0)});return Object.assign(t,{agg:e,avg(i){return e("avg",[i])},coalesce(...i){return t("coalesce",i)},count(i){return e("count",[i])},countAll(i){return new Be({aggregateFunctionNode:Ne.create("count",B(i))})},max(i){return e("max",[i])},min(i){return e("min",[i])},sum(i){return e("sum",[i])},any(i){return t("any",[i])},jsonAgg(i){return new Be({aggregateFunctionNode:Ne.create("json_agg",[g(i)?l(i):i.toOperationNode()])})},toJson(i){return new f(ui.create("to_json",[g(i)?l(i):i.toOperationNode()]))}})}var po=r({is(t){return t.kind==="UnaryOperationNode"},create(t,e){return r({kind:"UnaryOperationNode",operator:t,operand:e})}});function ho(t,e){return po.create(U.create(t),I(e))}var $=r({is(t){return t.kind==="CaseNode"},create(t){return r({kind:"CaseNode",value:t})},cloneWithWhen(t,e){return r({...t,when:r(t.when?[...t.when,e]:[e])})},cloneWithThen(t,e){return r({...t,when:t.when?r([...t.when.slice(0,-1),le.cloneWithResult(t.when[t.when.length-1],e)]):void 0})},cloneWith(t,e){return r({...t,...e})}});var et=class{#e;constructor(e){this.#e=r(e)}when(...e){return new Nr({...this.#e,node:$.cloneWithWhen(this.#e.node,le.create(y(e)))})}},Nr=class{#e;constructor(e){this.#e=r(e)}then(e){return new pi({...this.#e,node:$.cloneWithThen(this.#e.node,_t(e)?Nt(e):N(e))})}},pi=class{#e;constructor(e){this.#e=r(e)}when(...e){return new Nr({...this.#e,node:$.cloneWithWhen(this.#e.node,le.create(y(e)))})}else(e){return new hi({...this.#e,node:$.cloneWith(this.#e.node,{else:_t(e)?Nt(e):N(e)})})}end(){return new f($.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new f($.cloneWith(this.#e.node,{isStatement:!0}))}},hi=class{#e;constructor(e){this.#e=r(e)}end(){return new f($.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new f($.cloneWith(this.#e.node,{isStatement:!0}))}};var ci=r({is(t){return t.kind==="JSONPathLegNode"},create(t,e){return r({kind:"JSONPathLegNode",type:t,value:e})}});var Te=class{#e;constructor(e){this.#e=e}at(e){return this.#t("ArrayLocation",e)}key(e){return this.#t("Member",e)}#t(e,i){return Ue.is(this.#e)?new yr(Ue.cloneWithTraversal(this.#e,Ce.is(this.#e.traversal)?Ce.cloneWithLeg(this.#e.traversal,ci.create(e,i)):Xt.cloneWithValue(this.#e.traversal,S.createImmediate(i)))):new yr(Ce.cloneWithLeg(this.#e,ci.create(e,i)))}},yr=class extends Te{#e;constructor(e){super(e),this.#e=e}get expressionType(){}as(e){return new mi(this,e)}$castTo(){return new Te(this.#e)}$notNull(){return new Te(this.#e)}toOperationNode(){return this.#e}},mi=class{#e;#t;constructor(e,i){this.#e=e,this.#t=i}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return D.create(this.#e.toOperationNode(),x(this.#t)?this.#t.toOperationNode():d.create(this.#t))}};var li=r({is(t){return t.kind==="TupleNode"},create(t){return r({kind:"TupleNode",values:r(t)})}});var Ho=["varchar","char","text","integer","int2","int4","int8","smallint","bigint","boolean","real","double precision","float4","float8","decimal","numeric","binary","bytea","date","datetime","time","timetz","timestamp","timestamptz","serial","bigserial","uuid","json","jsonb","blob","varbinary"],Yo=[/^varchar\(\d+\)$/,/^char\(\d+\)$/,/^decimal\(\d+, \d+\)$/,/^numeric\(\d+, \d+\)$/,/^binary\(\d+\)$/,/^datetime\(\d+\)$/,/^time\(\d+\)$/,/^timetz\(\d+\)$/,/^timestamp\(\d+\)$/,/^timestamptz\(\d+\)$/,/^varbinary\(\d+\)$/],co=r({is(t){return t.kind==="DataTypeNode"},create(t){return r({kind:"DataTypeNode",dataType:t})}});function mo(t){return!!(Ho.includes(t)||Yo.some(e=>e.test(t)))}function _(t){if(x(t))return t.toOperationNode();if(mo(t))return co.create(t);throw new Error(`invalid column data type ${JSON.stringify(t)}`)}var lo=r({is(t){return t.kind==="CastNode"},create(t,e){return r({kind:"CastNode",expression:t,dataType:e})}});function cr(t=We){function e(n,u,v){return new f(er(n,u,v))}function i(n,u){return new f(ho(n,u))}let o=Object.assign(e,{fn:void 0,eb:void 0,selectFrom(n){return It({queryId:m(),executor:t,queryNode:p.createFrom(ae(n))})},case(n){return new et({node:$.create(z(n)?void 0:I(n))})},ref(n,u){return z(u)?new f(J(n)):new Te(Di(n,u))},jsonPath(){return new Te(Ce.create())},table(n){return new f(l(n))},val(n){return new f(N(n))},refTuple(...n){return new f(li.create(n.map(I)))},tuple(...n){return new f(li.create(n.map(N)))},lit(n){return new f(Nt(n))},unary:i,not(n){return i("not",n)},exists(n){return i("exists",n)},neg(n){return i("-",n)},between(n,u,v){return new f(ge.create(I(n),U.create("between"),M.create(N(u),N(v))))},betweenSymmetric(n,u,v){return new f(ge.create(I(n),U.create("between symmetric"),M.create(N(u),N(v))))},and(n){return E(n)?new f(Ke(n,"and")):new f(Kr(n,"and"))},or(n){return E(n)?new f(Ke(n,"or")):new f(Kr(n,"or"))},parens(...n){let u=y(n);return ie.is(u)?new f(u):new f(ie.create(u))},cast(n,u){return new f(lo.create(I(n),_(u)))},withSchema(n){return cr(t.withPluginAtFront(new Z(n)))}});return o.fn=fr(),o.eb=o,o}function Y(t){return cr()}function V(t){if(x(t))return t.toOperationNode();if(O(t))return t(Y()).toOperationNode();throw new Error(`invalid expression: ${JSON.stringify(t)}`)}function tr(t){if(x(t))return t.toOperationNode();if(O(t))return t(Y()).toOperationNode();throw new Error(`invalid aliased expression: ${JSON.stringify(t)}`)}function he(t){return Si(t)||ki(t)||O(t)}function ae(t){return E(t)?t.map(e=>qe(e)):[qe(t)]}function qe(t){return g(t)?ni(t):tr(t)}function ni(t){let e=" as ";if(t.includes(e)){let[i,o]=t.split(e).map(fo);return D.create(l(i),d.create(o))}else return l(t)}function l(t){let e=".";if(t.includes(e)){let[i,o]=t.split(e).map(fo);return K.createWithSchema(i,o)}else return K.create(t)}function fo(t){return t.trim()}var fi=r({is(t){return t.kind==="AddColumnNode"},create(t){return r({kind:"AddColumnNode",column:t})}});var w=r({is(t){return t.kind==="ColumnDefinitionNode"},create(t,e){return r({kind:"ColumnDefinitionNode",column:h.create(t),dataType:e})},cloneWithFrontModifier(t,e){return r({...t,frontModifiers:t.frontModifiers?r([...t.frontModifiers,e]):[e]})},cloneWithEndModifier(t,e){return r({...t,endModifiers:t.endModifiers?r([...t.endModifiers,e]):[e]})},cloneWith(t,e){return r({...t,...e})}});var Ni=r({is(t){return t.kind==="DropColumnNode"},create(t){return r({kind:"DropColumnNode",column:h.create(t)})}});var yi=r({is(t){return t.kind==="RenameColumnNode"},create(t,e){return r({kind:"RenameColumnNode",column:h.create(t),renameTo:h.create(e)})}});var tt=r({is(t){return t.kind==="CheckConstraintNode"},create(t,e){return r({kind:"CheckConstraintNode",expression:t,name:e?d.create(e):void 0})}});var No=["no action","restrict","cascade","set null","set default"],rt=r({is(t){return t.kind==="ReferencesNode"},create(t,e){return r({kind:"ReferencesNode",table:t,columns:r([...e])})},cloneWithOnDelete(t,e){return r({...t,onDelete:e})},cloneWithOnUpdate(t,e){return r({...t,onUpdate:e})}});function wr(t){return x(t)?t.toOperationNode():S.createImmediate(t)}var kt=r({is(t){return t.kind==="GeneratedNode"},create(t){return r({kind:"GeneratedNode",...t})},createWithExpression(t){return r({kind:"GeneratedNode",always:!0,expression:t})},cloneWith(t,e){return r({...t,...e})}});var yo=r({is(t){return t.kind==="DefaultValueNode"},create(t){return r({kind:"DefaultValueNode",defaultValue:t})}});function it(t){if(No.includes(t))return t;throw new Error(`invalid OnModifyForeignAction ${t}`)}var ue=class t{#e;constructor(e){this.#e=e}autoIncrement(){return new t(w.cloneWith(this.#e,{autoIncrement:!0}))}identity(){return new t(w.cloneWith(this.#e,{identity:!0}))}primaryKey(){return new t(w.cloneWith(this.#e,{primaryKey:!0}))}references(e){let i=J(e);if(!i.table||Ve.is(i.column))throw new Error(`invalid call references('${e}'). The reference must have format table.column or schema.table.column`);return new t(w.cloneWith(this.#e,{references:rt.create(i.table,[i.column])}))}onDelete(e){if(!this.#e.references)throw new Error("on delete constraint can only be added for foreign keys");return new t(w.cloneWith(this.#e,{references:rt.cloneWithOnDelete(this.#e.references,it(e))}))}onUpdate(e){if(!this.#e.references)throw new Error("on update constraint can only be added for foreign keys");return new t(w.cloneWith(this.#e,{references:rt.cloneWithOnUpdate(this.#e.references,it(e))}))}unique(){return new t(w.cloneWith(this.#e,{unique:!0}))}notNull(){return new t(w.cloneWith(this.#e,{notNull:!0}))}unsigned(){return new t(w.cloneWith(this.#e,{unsigned:!0}))}defaultTo(e){return new t(w.cloneWith(this.#e,{defaultTo:yo.create(wr(e))}))}check(e){return new t(w.cloneWith(this.#e,{check:tt.create(e.toOperationNode())}))}generatedAlwaysAs(e){return new t(w.cloneWith(this.#e,{generated:kt.createWithExpression(e.toOperationNode())}))}generatedAlwaysAsIdentity(){return new t(w.cloneWith(this.#e,{generated:kt.create({identity:!0,always:!0})}))}generatedByDefaultAsIdentity(){return new t(w.cloneWith(this.#e,{generated:kt.create({identity:!0,byDefault:!0})}))}stored(){if(!this.#e.generated)throw new Error("stored() can only be called after generatedAlwaysAs");return new t(w.cloneWith(this.#e,{generated:kt.cloneWith(this.#e.generated,{stored:!0})}))}modifyFront(e){return new t(w.cloneWithFrontModifier(this.#e,e.toOperationNode()))}nullsNotDistinct(){return new t(w.cloneWith(this.#e,{nullsNotDistinct:!0}))}ifNotExists(){return new t(w.cloneWith(this.#e,{ifNotExists:!0}))}modifyEnd(e){return new t(w.cloneWithEndModifier(this.#e,e.toOperationNode()))}$call(e){return e(this)}toOperationNode(){return this.#e}};s(ue,"don't await ColumnDefinitionBuilder instances directly.");var wi=r({is(t){return t.kind==="ModifyColumnNode"},create(t){return r({kind:"ModifyColumnNode",column:t})}});var Le=r({is(t){return t.kind==="ForeignKeyConstraintNode"},create(t,e,i,o){return r({kind:"ForeignKeyConstraintNode",columns:t,references:rt.create(e,i),name:o?d.create(o):void 0})},cloneWith(t,e){return r({...t,...e})}});var Qe=class t{#e;constructor(e){this.#e=e}onDelete(e){return new t(Le.cloneWith(this.#e,{onDelete:it(e)}))}onUpdate(e){return new t(Le.cloneWith(this.#e,{onUpdate:it(e)}))}$call(e){return e(this)}toOperationNode(){return this.#e}};s(Qe,"don't await ForeignKeyConstraintBuilder instances directly.");var ot=r({is(t){return t.kind==="AddConstraintNode"},create(t){return r({kind:"AddConstraintNode",constraint:t})}});var nt=r({is(t){return t.kind==="UniqueConstraintNode"},create(t,e,i){return r({kind:"UniqueConstraintNode",columns:r(t.map(h.create)),name:e?d.create(e):void 0,nullsNotDistinct:i})},cloneWith(t,e){return r({...t,...e})}});var st=r({is(t){return t.kind==="DropConstraintNode"},create(t){return r({kind:"DropConstraintNode",constraintName:d.create(t)})},cloneWith(t,e){return r({...t,...e})}});var at=r({is(t){return t.kind==="AlterColumnNode"},create(t,e,i){return r({kind:"AlterColumnNode",column:h.create(t),[e]:i})}});var ut=class{#e;constructor(e){this.#e=e}setDataType(e){return new Ie(at.create(this.#e,"dataType",_(e)))}setDefault(e){return new Ie(at.create(this.#e,"setDefault",wr(e)))}dropDefault(){return new Ie(at.create(this.#e,"dropDefault",!0))}setNotNull(){return new Ie(at.create(this.#e,"setNotNull",!0))}dropNotNull(){return new Ie(at.create(this.#e,"dropNotNull",!0))}$call(e){return e(this)}};s(ut,"don't await AlterColumnBuilder instances");var Ie=class{#e;constructor(e){this.#e=e}toOperationNode(){return this.#e}};s(Ie,"don't await AlteredColumnBuilder instances");var de=class{#e;constructor(e){this.#e=r(e)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};s(de,"don't await AlterTableExecutor instances directly. To execute the query you need to call `execute`");var At=class t{#e;constructor(e){this.#e=r(e)}onDelete(e){return new t({...this.#e,constraintBuilder:this.#e.constraintBuilder.onDelete(e)})}onUpdate(e){return new t({...this.#e,constraintBuilder:this.#e.constraintBuilder.onUpdate(e)})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(c.cloneWithTableProps(this.#e.node,{addConstraint:ot.create(this.#e.constraintBuilder.toOperationNode())}),this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};s(At,"don't await AlterTableAddForeignKeyConstraintBuilder instances directly. To execute the query you need to call `execute`");var Et=class t{#e;constructor(e){this.#e=r(e)}ifExists(){return new t({...this.#e,node:c.cloneWithTableProps(this.#e.node,{dropConstraint:st.cloneWith(this.#e.node.dropConstraint,{ifExists:!0})})})}cascade(){return new t({...this.#e,node:c.cloneWithTableProps(this.#e.node,{dropConstraint:st.cloneWith(this.#e.node.dropConstraint,{modifier:"cascade"})})})}restrict(){return new t({...this.#e,node:c.cloneWithTableProps(this.#e.node,{dropConstraint:st.cloneWith(this.#e.node.dropConstraint,{modifier:"restrict"})})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};s(Et,"don't await AlterTableDropConstraintBuilder instances directly. To execute the query you need to call `execute`");var xr=r({is(t){return t.kind==="PrimaryKeyConstraintNode"},create(t,e){return r({kind:"PrimaryKeyConstraintNode",columns:r(t.map(h.create)),name:e?d.create(e):void 0})}});var Se=r({is(t){return t.kind==="AddIndexNode"},create(t){return r({kind:"AddIndexNode",name:d.create(t)})},cloneWith(t,e){return r({...t,...e})},cloneWithColumns(t,e){return r({...t,columns:[...t.columns||[],...e]})}});var Rt=class t{#e;constructor(e){this.#e=r(e)}unique(){return new t({...this.#e,node:c.cloneWithTableProps(this.#e.node,{addIndex:Se.cloneWith(this.#e.node.addIndex,{unique:!0})})})}column(e){return new t({...this.#e,node:c.cloneWithTableProps(this.#e.node,{addIndex:Se.cloneWithColumns(this.#e.node.addIndex,[Je(e)])})})}columns(e){return new t({...this.#e,node:c.cloneWithTableProps(this.#e.node,{addIndex:Se.cloneWithColumns(this.#e.node.addIndex,e.map(Je))})})}expression(e){return new t({...this.#e,node:c.cloneWithTableProps(this.#e.node,{addIndex:Se.cloneWithColumns(this.#e.node.addIndex,[e.toOperationNode()])})})}using(e){return new t({...this.#e,node:c.cloneWithTableProps(this.#e.node,{addIndex:Se.cloneWith(this.#e.node.addIndex,{using:C.createWithSql(e)})})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};s(Rt,"don't await AlterTableAddIndexBuilder instances directly. To execute the query you need to call `execute`");var Pe=class t{#e;constructor(e){this.#e=e}toOperationNode(){return this.#e}nullsNotDistinct(){return new t(nt.cloneWith(this.#e,{nullsNotDistinct:!0}))}};s(Pe,"don't await UniqueConstraintNodeBuilder instances directly.");var Dt=class{#e;constructor(e){this.#e=r(e)}renameTo(e){return new de({...this.#e,node:c.cloneWithTableProps(this.#e.node,{renameTo:l(e)})})}setSchema(e){return new de({...this.#e,node:c.cloneWithTableProps(this.#e.node,{setSchema:d.create(e)})})}alterColumn(e,i){let o=i(new ut(e));return new ke({...this.#e,node:c.cloneWithColumnAlteration(this.#e.node,o.toOperationNode())})}dropColumn(e){return new ke({...this.#e,node:c.cloneWithColumnAlteration(this.#e.node,Ni.create(e))})}renameColumn(e,i){return new ke({...this.#e,node:c.cloneWithColumnAlteration(this.#e.node,yi.create(e,i))})}addColumn(e,i,o=te){let n=o(new ue(w.create(e,_(i))));return new ke({...this.#e,node:c.cloneWithColumnAlteration(this.#e.node,fi.create(n.toOperationNode()))})}modifyColumn(e,i,o=te){let n=o(new ue(w.create(e,_(i))));return new ke({...this.#e,node:c.cloneWithColumnAlteration(this.#e.node,wi.create(n.toOperationNode()))})}addUniqueConstraint(e,i,o=te){let n=o(new Pe(nt.create(i,e)));return new de({...this.#e,node:c.cloneWithTableProps(this.#e.node,{addConstraint:ot.create(n.toOperationNode())})})}addCheckConstraint(e,i){return new de({...this.#e,node:c.cloneWithTableProps(this.#e.node,{addConstraint:ot.create(tt.create(i.toOperationNode(),e))})})}addForeignKeyConstraint(e,i,o,n){return new At({...this.#e,constraintBuilder:new Qe(Le.create(i.map(h.create),l(o),n.map(h.create),e))})}addPrimaryKeyConstraint(e,i){return new de({...this.#e,node:c.cloneWithTableProps(this.#e.node,{addConstraint:ot.create(xr.create(i,e))})})}dropConstraint(e){return new Et({...this.#e,node:c.cloneWithTableProps(this.#e.node,{dropConstraint:st.create(e)})})}addIndex(e){return new Rt({...this.#e,node:c.cloneWithTableProps(this.#e.node,{addIndex:Se.create(e)})})}dropIndex(e){return new de({...this.#e,node:c.cloneWithTableProps(this.#e.node,{dropIndex:xe.create(e)})})}$call(e){return e(this)}};s(Dt,"don't await AlterTableBuilder instances");var ke=class t{#e;constructor(e){this.#e=r(e)}alterColumn(e,i){let o=i(new ut(e));return new t({...this.#e,node:c.cloneWithColumnAlteration(this.#e.node,o.toOperationNode())})}dropColumn(e){return new t({...this.#e,node:c.cloneWithColumnAlteration(this.#e.node,Ni.create(e))})}renameColumn(e,i){return new t({...this.#e,node:c.cloneWithColumnAlteration(this.#e.node,yi.create(e,i))})}addColumn(e,i,o=te){let n=o(new ue(w.create(e,_(i))));return new t({...this.#e,node:c.cloneWithColumnAlteration(this.#e.node,fi.create(n.toOperationNode()))})}modifyColumn(e,i,o=te){let n=o(new ue(w.create(e,_(i))));return new t({...this.#e,node:c.cloneWithColumnAlteration(this.#e.node,wi.create(n.toOperationNode()))})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};s(ke,"don't await AlterTableColumnAlteringBuilder instances directly. To execute the query you need to call `execute`");var dt=class extends be{transformValue(e){return{...super.transformValue(e),immediate:!0}}};var Bt=class t{#e;constructor(e){this.#e=r(e)}ifNotExists(){return new t({...this.#e,node:G.cloneWith(this.#e.node,{ifNotExists:!0})})}unique(){return new t({...this.#e,node:G.cloneWith(this.#e.node,{unique:!0})})}nullsNotDistinct(){return new t({...this.#e,node:G.cloneWith(this.#e.node,{nullsNotDistinct:!0})})}on(e){return new t({...this.#e,node:G.cloneWith(this.#e.node,{table:l(e)})})}column(e){return new t({...this.#e,node:G.cloneWithColumns(this.#e.node,[Je(e)])})}columns(e){return new t({...this.#e,node:G.cloneWithColumns(this.#e.node,e.map(Je))})}expression(e){return new t({...this.#e,node:G.cloneWithColumns(this.#e.node,[e.toOperationNode()])})}using(e){return new t({...this.#e,node:G.cloneWith(this.#e.node,{using:C.createWithSql(e)})})}where(...e){let i=new dt;return new t({...this.#e,node:a.cloneWithWhere(this.#e.node,i.transformNode(y(e)))})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};s(Bt,"don't await CreateIndexBuilder instances directly. To execute the query you need to call `execute`");var Lt=class t{#e;constructor(e){this.#e=r(e)}ifNotExists(){return new t({...this.#e,node:Kt.cloneWith(this.#e.node,{ifNotExists:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};s(Lt,"don't await CreateSchemaBuilder instances directly. To execute the query you need to call `execute`");function wo(t){if(Ii.includes(t))return t;throw new Error(`invalid OnCommitAction ${t}`)}var Qt=class t{#e;constructor(e){this.#e=r(e)}temporary(){return new t({...this.#e,node:R.cloneWith(this.#e.node,{temporary:!0})})}onCommit(e){return new t({...this.#e,node:R.cloneWith(this.#e.node,{onCommit:wo(e)})})}ifNotExists(){return new t({...this.#e,node:R.cloneWith(this.#e.node,{ifNotExists:!0})})}addColumn(e,i,o=te){let n=o(new ue(w.create(e,_(i))));return new t({...this.#e,node:R.cloneWithColumn(this.#e.node,n.toOperationNode())})}addPrimaryKeyConstraint(e,i){return new t({...this.#e,node:R.cloneWithConstraint(this.#e.node,xr.create(i,e))})}addUniqueConstraint(e,i,o=te){let n=o(new Pe(nt.create(i,e)));return new t({...this.#e,node:R.cloneWithConstraint(this.#e.node,n.toOperationNode())})}addCheckConstraint(e,i){return new t({...this.#e,node:R.cloneWithConstraint(this.#e.node,tt.create(i.toOperationNode(),e))})}addForeignKeyConstraint(e,i,o,n,u=te){let v=u(new Qe(Le.create(i.map(h.create),l(o),n.map(h.create),e)));return new t({...this.#e,node:R.cloneWithConstraint(this.#e.node,v.toOperationNode())})}modifyFront(e){return new t({...this.#e,node:R.cloneWithFrontModifier(this.#e.node,e.toOperationNode())})}modifyEnd(e){return new t({...this.#e,node:R.cloneWithEndModifier(this.#e.node,e.toOperationNode())})}as(e){return new t({...this.#e,node:R.cloneWith(this.#e.node,{selectQuery:V(e)})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};s(Qt,"don't await CreateTableBuilder instances directly. To execute the query you need to call `execute`");var Pt=class t{#e;constructor(e){this.#e=r(e)}on(e){return new t({...this.#e,node:xe.cloneWith(this.#e.node,{table:l(e)})})}ifExists(){return new t({...this.#e,node:xe.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:xe.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};s(Pt,"don't await DropIndexBuilder instances directly. To execute the query you need to call `execute`");var Ft=class t{#e;constructor(e){this.#e=r(e)}ifExists(){return new t({...this.#e,node:lt.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:lt.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};s(Ft,"don't await DropSchemaBuilder instances directly. To execute the query you need to call `execute`");var Mt=class t{#e;constructor(e){this.#e=r(e)}ifExists(){return new t({...this.#e,node:ft.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:ft.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};s(Mt,"don't await DropTableBuilder instances directly. To execute the query you need to call `execute`");var ee=r({is(t){return t.kind==="CreateViewNode"},create(t){return r({kind:"CreateViewNode",name:F.create(t)})},cloneWith(t,e){return r({...t,...e})}});var Or=class{#e=new dt;transformQuery(e){return this.#e.transformNode(e.node)}transformResult(e){return Promise.resolve(e.result)}};var Vt=class t{#e;constructor(e){this.#e=r(e)}temporary(){return new t({...this.#e,node:ee.cloneWith(this.#e.node,{temporary:!0})})}materialized(){return new t({...this.#e,node:ee.cloneWith(this.#e.node,{materialized:!0})})}ifNotExists(){return new t({...this.#e,node:ee.cloneWith(this.#e.node,{ifNotExists:!0})})}orReplace(){return new t({...this.#e,node:ee.cloneWith(this.#e.node,{orReplace:!0})})}columns(e){return new t({...this.#e,node:ee.cloneWith(this.#e.node,{columns:e.map(Ur)})})}as(e){let i=e.withPlugin(new Or).toOperationNode();return new t({...this.#e,node:ee.cloneWith(this.#e.node,{as:i})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};s(Vt,"don't await CreateViewBuilder instances directly. To execute the query you need to call `execute`");var pt=r({is(t){return t.kind==="DropViewNode"},create(t){return r({kind:"DropViewNode",name:F.create(t)})},cloneWith(t,e){return r({...t,...e})}});var zt=class t{#e;constructor(e){this.#e=r(e)}materialized(){return new t({...this.#e,node:pt.cloneWith(this.#e.node,{materialized:!0})})}ifExists(){return new t({...this.#e,node:pt.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:pt.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};s(zt,"don't await DropViewBuilder instances directly. To execute the query you need to call `execute`");var gr=r({is(t){return t.kind==="CreateTypeNode"},create(t){return r({kind:"CreateTypeNode",name:t})},cloneWithEnum(t,e){return r({...t,enum:$e.create(e.map(i=>S.createImmediate(i)))})}});var Ut=class t{#e;constructor(e){this.#e=r(e)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}asEnum(e){return new t({...this.#e,node:gr.cloneWithEnum(this.#e.node,e)})}$call(e){return e(this)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};s(Ut,"don't await CreateTypeBuilder instances directly. To execute the query you need to call `execute`");var vr=r({is(t){return t.kind==="DropTypeNode"},create(t){return r({kind:"DropTypeNode",name:t})},cloneWith(t,e){return r({...t,...e})}});var Jt=class t{#e;constructor(e){this.#e=r(e)}ifExists(){return new t({...this.#e,node:vr.cloneWith(this.#e.node,{ifExists:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};s(Jt,"don't await DropTypeBuilder instances directly. To execute the query you need to call `execute`");function xi(t){let e=".";if(t.includes(e)){let i=t.split(e).map(Xo);if(i.length===2)return F.createWithSchema(i[0],i[1]);throw new Error(`invalid schemable identifier ${t}`)}else return F.create(t)}function Xo(t){return t.trim()}var Cr=class t{#e;constructor(e){this.#e=e}createTable(e){return new Qt({queryId:m(),executor:this.#e,node:R.create(l(e))})}dropTable(e){return new Mt({queryId:m(),executor:this.#e,node:ft.create(l(e))})}createIndex(e){return new Bt({queryId:m(),executor:this.#e,node:G.create(e)})}dropIndex(e){return new Pt({queryId:m(),executor:this.#e,node:xe.create(e)})}createSchema(e){return new Lt({queryId:m(),executor:this.#e,node:Kt.create(e)})}dropSchema(e){return new Ft({queryId:m(),executor:this.#e,node:lt.create(e)})}alterTable(e){return new Dt({queryId:m(),executor:this.#e,node:c.create(l(e))})}createView(e){return new Vt({queryId:m(),executor:this.#e,node:ee.create(e)})}dropView(e){return new zt({queryId:m(),executor:this.#e,node:pt.create(e)})}createType(e){return new Ut({queryId:m(),executor:this.#e,node:gr.create(xi(e))})}dropType(e){return new Jt({queryId:m(),executor:this.#e,node:vr.create(xi(e))})}withPlugin(e){return new t(this.#e.withPlugin(e))}withoutPlugins(){return new t(this.#e.withoutPlugins())}withSchema(e){return new t(this.#e.withPluginAtFront(new Z(e)))}};var br=class{ref(e){return new Gt(e)}};var Wr=class{#e;constructor(e){this.#e=e}async provideConnection(e){let i=await this.#e.acquireConnection();try{return await e(i)}finally{await this.#e.releaseConnection(i)}}};var qr=class t extends Ze{#e;#t;#r;constructor(e,i,o,n=[]){super(n),this.#e=e,this.#t=i,this.#r=o}get adapter(){return this.#t}compileQuery(e){return this.#e.compileQuery(e)}provideConnection(e){return this.#r.provideConnection(e)}withPlugins(e){return new t(this.#e,this.#t,this.#r,[...this.plugins,...e])}withPlugin(e){return new t(this.#e,this.#t,this.#r,[...this.plugins,e])}withPluginAtFront(e){return new t(this.#e,this.#t,this.#r,[e,...this.plugins])}withConnectionProvider(e){return new t(this.#e,this.#t,e,[...this.plugins])}withoutPlugins(){return new t(this.#e,this.#t,this.#r,[])}};function Oi(){return typeof performance<"u"&&O(performance.now)?performance.now():Date.now()}var Tr=class{#e;#t;#r;#i;#o;#s=new WeakSet;constructor(e,i){this.#i=!1,this.#e=e,this.#t=i}async init(){if(this.#o)throw new Error("driver has already been destroyed");this.#r||(this.#r=this.#e.init().then(()=>{this.#i=!0}).catch(e=>(this.#r=void 0,Promise.reject(e)))),await this.#r}async acquireConnection(){if(this.#o)throw new Error("driver has already been destroyed");this.#i||await this.init();let e=await this.#e.acquireConnection();return this.#s.has(e)||(this.#n()&&this.#a(e),this.#s.add(e)),e}async releaseConnection(e){await this.#e.releaseConnection(e)}beginTransaction(e,i){return this.#e.beginTransaction(e,i)}commitTransaction(e){return this.#e.commitTransaction(e)}rollbackTransaction(e){return this.#e.rollbackTransaction(e)}async destroy(){this.#r&&(await this.#r,this.#o||(this.#o=this.#e.destroy().catch(e=>(this.#o=void 0,Promise.reject(e)))),await this.#o)}#n(){return this.#t.isLevelEnabled("query")||this.#t.isLevelEnabled("error")}#a(e){let i=e.executeQuery;e.executeQuery=async o=>{let n,u=Oi();try{return await i.call(e,o)}catch(v){throw n=v,await this.#u(v,o,u),v}finally{n||await this.#p(o,u)}}}async#u(e,i,o){await this.#t.error(()=>({level:"error",error:e,query:i,queryDurationMillis:this.#d(o)}))}async#p(e,i){await this.#t.query(()=>({level:"query",query:e,queryDurationMillis:this.#d(i)}))}#d(e){return Oi()-e}};var Zo=()=>{},$t=class{#e;#t;constructor(e){this.#e=e}async provideConnection(e){for(;this.#t;)await this.#t.catch(Zo);return this.#t=this.#r(e).finally(()=>{this.#t=void 0}),this.#t}async#r(e){return await e(this.#e)}};var xo=["read uncommitted","read committed","repeatable read","serializable","snapshot"];var Ux=r(["query","error"]),Ir=class{#e;#t;constructor(e){O(e)?(this.#t=e,this.#e=r({query:!0,error:!0})):(this.#t=_o,this.#e=r({query:e.includes("query"),error:e.includes("error")}))}isLevelEnabled(e){return this.#e[e]}async query(e){this.#e.query&&await this.#t(e())}async error(e){this.#e.error&&await this.#t(e())}};function _o(t){t.level==="query"?(console.log(`kysely:query: ${t.query.sql}`),console.log(`kysely:query: duration: ${t.queryDurationMillis.toFixed(1)}ms`)):t.level==="error"&&(t.error instanceof Error?console.error(`kysely:error: ${t.error.stack??t.error.message}`):console.error(`kysely:error: ${JSON.stringify({error:t.error,query:t.query.sql,queryDurationMillis:t.queryDurationMillis})}`))}function Oo(t){return Q(t)&&O(t.compile)}var ht=class t extends _e{#e;constructor(e){let i,o;if(en(e))i={executor:e.executor},o={...e};else{let n=e.dialect,u=n.createDriver(),v=n.createQueryCompiler(),L=n.createAdapter(),pe=new Ir(e.log??[]),Wi=new Tr(u,pe),qo=new Wr(Wi),qi=new qr(v,L,qo,e.plugins??[]);i={executor:qi},o={config:e,executor:qi,dialect:n,driver:Wi}}super(i),this.#e=r(o)}get schema(){return new Cr(this.#e.executor)}get dynamic(){return new br}get introspection(){return this.#e.dialect.createIntrospector(this.withoutPlugins())}case(e){return new et({node:$.create(z(e)?void 0:V(e))})}get fn(){return fr()}transaction(){return new kr({...this.#e})}connection(){return new Sr({...this.#e})}withPlugin(e){return new t({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new t({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new t({...this.#e,executor:this.#e.executor.withPluginAtFront(new Z(e))})}withTables(){return new t({...this.#e})}async destroy(){await this.#e.driver.destroy()}get isTransaction(){return!1}getExecutor(){return this.#e.executor}executeQuery(e,i=m()){let o=Oo(e)?e.compile():e;return this.getExecutor().executeQuery(o,i)}},gi=class t extends ht{#e;constructor(e){super(e),this.#e=e}get isTransaction(){return!0}transaction(){throw new Error("calling the transaction method for a Transaction is not supported")}connection(){throw new Error("calling the connection method for a Transaction is not supported")}async destroy(){throw new Error("calling the destroy method for a Transaction is not supported")}withPlugin(e){return new t({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new t({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new t({...this.#e,executor:this.#e.executor.withPluginAtFront(new Z(e))})}withTables(){return new t({...this.#e})}};function en(t){return Q(t)&&Q(t.config)&&Q(t.driver)&&Q(t.executor)&&Q(t.dialect)}var Sr=class{#e;constructor(e){this.#e=r(e)}async execute(e){return this.#e.executor.provideConnection(async i=>{let o=this.#e.executor.withConnectionProvider(new $t(i)),n=new ht({...this.#e,executor:o});return await e(n)})}};s(Sr,"don't await ConnectionBuilder instances directly. To execute the query you need to call the `execute` method");var kr=class t{#e;constructor(e){this.#e=r(e)}setIsolationLevel(e){return new t({...this.#e,isolationLevel:e})}async execute(e){let{isolationLevel:i,...o}=this.#e,n={isolationLevel:i};return tn(n),this.#e.executor.provideConnection(async u=>{let v=this.#e.executor.withConnectionProvider(new $t(u)),L=new gi({...o,executor:v});try{await this.#e.driver.beginTransaction(u,n);let pe=await e(L);return await this.#e.driver.commitTransaction(u),pe}catch(pe){throw await this.#e.driver.rollbackTransaction(u),pe}})}};s(kr,"don't await TransactionBuilder instances directly. To execute the transaction you need to call the `execute` method");function tn(t){if(t.isolationLevel&&!xo.includes(t.isolationLevel))throw new Error(`invalid transaction isolation level ${t.isolationLevel}`)}var Ar=class t{#e;constructor(e){this.#e=r(e)}get expressionType(){}get isRawBuilder(){return!0}as(e){return new Er(this,e)}$castTo(){return new t({...this.#e})}$notNull(){return new t(this.#e)}withPlugin(e){return new t({...this.#e,plugins:this.#e.plugins!==void 0?r([...this.#e.plugins,e]):r([e])})}toOperationNode(){return this.#r(this.#t())}compile(e){return this.#i(this.#t(e))}async execute(e){let i=this.#t(e);return i.executeQuery(this.#i(i),this.#e.queryId)}#t(e){let i=e!==void 0?e.getExecutor():We;return this.#e.plugins!==void 0?i.withPlugins(this.#e.plugins):i}#r(e){return e.transformQuery(this.#e.rawNode,this.#e.queryId)}#i(e){return e.compileQuery(this.#r(e),this.#e.queryId)}};function ye(t){return new Ar(t)}s(Ar,"don't await RawBuilder instances directly. To execute the query you need to call `execute`");var Er=class{#e;#t;constructor(e,i){this.#e=e,this.#t=i}get expression(){return this.#e}get alias(){return this.#t}get rawBuilder(){return this.#e}toOperationNode(){return D.create(this.#e.toOperationNode(),x(this.#t)?this.#t.toOperationNode():d.create(this.#t))}};s(Er,"don't await AliasedRawBuilder instances directly. AliasedRawBuilder should never be executed directly since it's always a part of another query.");var ct=Object.assign((t,...e)=>ye({queryId:m(),rawNode:C.create(t,e?.map(go)??[])}),{ref(t){return ye({queryId:m(),rawNode:C.createWithChild(J(t))})},val(t){return ye({queryId:m(),rawNode:C.createWithChild(N(t))})},value(t){return this.val(t)},table(t){return ye({queryId:m(),rawNode:C.createWithChild(l(t))})},id(...t){let e=new Array(t.length+1).fill(".");return e[0]="",e[e.length-1]="",ye({queryId:m(),rawNode:C.create(e,t.map(d.create))})},lit(t){return ye({queryId:m(),rawNode:C.createWithChild(S.createImmediate(t))})},literal(t){return this.lit(t)},raw(t){return ye({queryId:m(),rawNode:C.createWithSql(t)})},join(t,e=ct`, `){let i=new Array(2*t.length-1),o=e.toOperationNode();for(let n=0;n<t.length;++n)i[2*n]=go(t[n]),n!==t.length-1&&(i[2*n+1]=o);return ye({queryId:m(),rawNode:C.createWithChildren(i)})}});function go(t){return x(t)?t.toOperationNode():N(t)}var Rr=class{nodeStack=[];get parentNode(){return this.nodeStack[this.nodeStack.length-2]}#e=r({AliasNode:this.visitAlias.bind(this),ColumnNode:this.visitColumn.bind(this),IdentifierNode:this.visitIdentifier.bind(this),SchemableIdentifierNode:this.visitSchemableIdentifier.bind(this),RawNode:this.visitRaw.bind(this),ReferenceNode:this.visitReference.bind(this),SelectQueryNode:this.visitSelectQuery.bind(this),SelectionNode:this.visitSelection.bind(this),TableNode:this.visitTable.bind(this),FromNode:this.visitFrom.bind(this),SelectAllNode:this.visitSelectAll.bind(this),AndNode:this.visitAnd.bind(this),OrNode:this.visitOr.bind(this),ValueNode:this.visitValue.bind(this),ValueListNode:this.visitValueList.bind(this),PrimitiveValueListNode:this.visitPrimitiveValueList.bind(this),ParensNode:this.visitParens.bind(this),JoinNode:this.visitJoin.bind(this),OperatorNode:this.visitOperator.bind(this),WhereNode:this.visitWhere.bind(this),InsertQueryNode:this.visitInsertQuery.bind(this),DeleteQueryNode:this.visitDeleteQuery.bind(this),ReturningNode:this.visitReturning.bind(this),CreateTableNode:this.visitCreateTable.bind(this),AddColumnNode:this.visitAddColumn.bind(this),ColumnDefinitionNode:this.visitColumnDefinition.bind(this),DropTableNode:this.visitDropTable.bind(this),DataTypeNode:this.visitDataType.bind(this),OrderByNode:this.visitOrderBy.bind(this),OrderByItemNode:this.visitOrderByItem.bind(this),GroupByNode:this.visitGroupBy.bind(this),GroupByItemNode:this.visitGroupByItem.bind(this),UpdateQueryNode:this.visitUpdateQuery.bind(this),ColumnUpdateNode:this.visitColumnUpdate.bind(this),LimitNode:this.visitLimit.bind(this),OffsetNode:this.visitOffset.bind(this),OnConflictNode:this.visitOnConflict.bind(this),OnDuplicateKeyNode:this.visitOnDuplicateKey.bind(this),CreateIndexNode:this.visitCreateIndex.bind(this),DropIndexNode:this.visitDropIndex.bind(this),ListNode:this.visitList.bind(this),PrimaryKeyConstraintNode:this.visitPrimaryKeyConstraint.bind(this),UniqueConstraintNode:this.visitUniqueConstraint.bind(this),ReferencesNode:this.visitReferences.bind(this),CheckConstraintNode:this.visitCheckConstraint.bind(this),WithNode:this.visitWith.bind(this),CommonTableExpressionNode:this.visitCommonTableExpression.bind(this),CommonTableExpressionNameNode:this.visitCommonTableExpressionName.bind(this),HavingNode:this.visitHaving.bind(this),CreateSchemaNode:this.visitCreateSchema.bind(this),DropSchemaNode:this.visitDropSchema.bind(this),AlterTableNode:this.visitAlterTable.bind(this),DropColumnNode:this.visitDropColumn.bind(this),RenameColumnNode:this.visitRenameColumn.bind(this),AlterColumnNode:this.visitAlterColumn.bind(this),ModifyColumnNode:this.visitModifyColumn.bind(this),AddConstraintNode:this.visitAddConstraint.bind(this),DropConstraintNode:this.visitDropConstraint.bind(this),ForeignKeyConstraintNode:this.visitForeignKeyConstraint.bind(this),CreateViewNode:this.visitCreateView.bind(this),DropViewNode:this.visitDropView.bind(this),GeneratedNode:this.visitGenerated.bind(this),DefaultValueNode:this.visitDefaultValue.bind(this),OnNode:this.visitOn.bind(this),ValuesNode:this.visitValues.bind(this),SelectModifierNode:this.visitSelectModifier.bind(this),CreateTypeNode:this.visitCreateType.bind(this),DropTypeNode:this.visitDropType.bind(this),ExplainNode:this.visitExplain.bind(this),DefaultInsertValueNode:this.visitDefaultInsertValue.bind(this),AggregateFunctionNode:this.visitAggregateFunction.bind(this),OverNode:this.visitOver.bind(this),PartitionByNode:this.visitPartitionBy.bind(this),PartitionByItemNode:this.visitPartitionByItem.bind(this),SetOperationNode:this.visitSetOperation.bind(this),BinaryOperationNode:this.visitBinaryOperation.bind(this),UnaryOperationNode:this.visitUnaryOperation.bind(this),UsingNode:this.visitUsing.bind(this),FunctionNode:this.visitFunction.bind(this),CaseNode:this.visitCase.bind(this),WhenNode:this.visitWhen.bind(this),JSONReferenceNode:this.visitJSONReference.bind(this),JSONPathNode:this.visitJSONPath.bind(this),JSONPathLegNode:this.visitJSONPathLeg.bind(this),JSONOperatorChainNode:this.visitJSONOperatorChain.bind(this),TupleNode:this.visitTuple.bind(this),MergeQueryNode:this.visitMergeQuery.bind(this),MatchedNode:this.visitMatched.bind(this),AddIndexNode:this.visitAddIndex.bind(this),CastNode:this.visitCast.bind(this),FetchNode:this.visitFetch.bind(this),TopNode:this.visitTop.bind(this),OutputNode:this.visitOutput.bind(this)});visitNode=e=>{this.nodeStack.push(e),this.#e[e.kind](e),this.nodeStack.pop()}};var Dr=class extends Rr{#e="";#t=[];get numParameters(){return this.#t.length}compileQuery(e){return this.#e="",this.#t=[],this.nodeStack.splice(0,this.nodeStack.length),this.visitNode(e),r({query:e,sql:this.getSql(),parameters:[...this.#t]})}getSql(){return this.#e}visitSelectQuery(e){let i=this.parentNode!==void 0&&!ie.is(this.parentNode)&&!q.is(this.parentNode)&&!R.is(this.parentNode)&&!ee.is(this.parentNode)&&!hr.is(this.parentNode);this.parentNode===void 0&&e.explain&&(this.visitNode(e.explain),this.append(" ")),i&&this.append("("),e.with&&(this.visitNode(e.with),this.append(" ")),this.append("select"),e.distinctOn&&(this.append(" "),this.compileDistinctOn(e.distinctOn)),e.frontModifiers?.length&&(this.append(" "),this.compileList(e.frontModifiers," ")),e.top&&(this.append(" "),this.visitNode(e.top)),e.selections&&(this.append(" "),this.compileList(e.selections)),e.from&&(this.append(" "),this.visitNode(e.from)),e.joins&&(this.append(" "),this.compileList(e.joins," ")),e.where&&(this.append(" "),this.visitNode(e.where)),e.groupBy&&(this.append(" "),this.visitNode(e.groupBy)),e.having&&(this.append(" "),this.visitNode(e.having)),e.setOperations&&(this.append(" "),this.compileList(e.setOperations," ")),e.orderBy&&(this.append(" "),this.visitNode(e.orderBy)),e.limit&&(this.append(" "),this.visitNode(e.limit)),e.offset&&(this.append(" "),this.visitNode(e.offset)),e.fetch&&(this.append(" "),this.visitNode(e.fetch)),e.endModifiers?.length&&(this.append(" "),this.compileList(this.sortSelectModifiers([...e.endModifiers])," ")),i&&this.append(")")}visitFrom(e){this.append("from "),this.compileList(e.froms)}visitSelection(e){this.visitNode(e.selection)}visitColumn(e){this.visitNode(e.column)}compileDistinctOn(e){this.append("distinct on ("),this.compileList(e),this.append(")")}compileList(e,i=", "){let o=e.length-1;for(let n=0;n<=o;n++)this.visitNode(e[n]),n<o&&this.append(i)}visitWhere(e){this.append("where "),this.visitNode(e.where)}visitHaving(e){this.append("having "),this.visitNode(e.having)}visitInsertQuery(e){let i=this.nodeStack.find(a.is),o=i!==e;!o&&e.explain&&(this.visitNode(e.explain),this.append(" ")),o&&!T.is(i)&&this.append("("),e.with&&(this.visitNode(e.with),this.append(" ")),this.append(e.replace?"replace":"insert"),e.ignore&&this.append(" ignore"),e.top&&(this.append(" "),this.visitNode(e.top)),e.into&&(this.append(" into "),this.visitNode(e.into)),e.columns&&(this.append(" ("),this.compileList(e.columns),this.append(")")),e.output&&(this.append(" "),this.visitNode(e.output)),e.values&&(this.append(" "),this.visitNode(e.values)),e.defaultValues&&(this.append(" "),this.append("default values")),e.onConflict&&(this.append(" "),this.visitNode(e.onConflict)),e.onDuplicateKey&&(this.append(" "),this.visitNode(e.onDuplicateKey)),e.returning&&(this.append(" "),this.visitNode(e.returning)),o&&!T.is(i)&&this.append(")")}visitValues(e){this.append("values "),this.compileList(e.values)}visitDeleteQuery(e){let i=this.nodeStack.find(a.is)!==e;!i&&e.explain&&(this.visitNode(e.explain),this.append(" ")),i&&this.append("("),e.with&&(this.visitNode(e.with),this.append(" ")),this.append("delete "),e.top&&(this.visitNode(e.top),this.append(" ")),this.visitNode(e.from),e.output&&(this.append(" "),this.visitNode(e.output)),e.using&&(this.append(" "),this.visitNode(e.using)),e.joins&&(this.append(" "),this.compileList(e.joins," ")),e.where&&(this.append(" "),this.visitNode(e.where)),e.orderBy&&(this.append(" "),this.visitNode(e.orderBy)),e.limit&&(this.append(" "),this.visitNode(e.limit)),e.returning&&(this.append(" "),this.visitNode(e.returning)),i&&this.append(")")}visitReturning(e){this.append("returning "),this.compileList(e.selections)}visitAlias(e){this.visitNode(e.node),this.append(" as "),this.visitNode(e.alias)}visitReference(e){e.table&&(this.visitNode(e.table),this.append(".")),this.visitNode(e.column)}visitSelectAll(e){this.append("*")}visitIdentifier(e){this.append(this.getLeftIdentifierWrapper()),this.compileUnwrappedIdentifier(e),this.append(this.getRightIdentifierWrapper())}compileUnwrappedIdentifier(e){if(!g(e.name))throw new Error("a non-string identifier was passed to compileUnwrappedIdentifier.");this.append(this.sanitizeIdentifier(e.name))}visitAnd(e){this.visitNode(e.left),this.append(" and "),this.visitNode(e.right)}visitOr(e){this.visitNode(e.left),this.append(" or "),this.visitNode(e.right)}visitValue(e){e.immediate?this.appendImmediateValue(e.value):this.appendValue(e.value)}visitValueList(e){this.append("("),this.compileList(e.values),this.append(")")}visitTuple(e){this.append("("),this.compileList(e.values),this.append(")")}visitPrimitiveValueList(e){this.append("(");let{values:i}=e;for(let o=0;o<i.length;++o)this.appendValue(i[o]),o!==i.length-1&&this.append(", ");this.append(")")}visitParens(e){this.append("("),this.visitNode(e.node),this.append(")")}visitJoin(e){this.append(on[e.joinType]),this.append(" "),this.visitNode(e.table),e.on&&(this.append(" "),this.visitNode(e.on))}visitOn(e){this.append("on "),this.visitNode(e.on)}visitRaw(e){let{sqlFragments:i,parameters:o}=e;for(let n=0;n<i.length;++n)this.append(i[n]),o.length>n&&this.visitNode(o[n])}visitOperator(e){this.append(e.operator)}visitTable(e){this.visitNode(e.table)}visitSchemableIdentifier(e){e.schema&&(this.visitNode(e.schema),this.append(".")),this.visitNode(e.identifier)}visitCreateTable(e){this.append("create "),e.frontModifiers&&e.frontModifiers.length>0&&(this.compileList(e.frontModifiers," "),this.append(" ")),e.temporary&&this.append("temporary "),this.append("table "),e.ifNotExists&&this.append("if not exists "),this.visitNode(e.table),e.selectQuery?(this.append(" as "),this.visitNode(e.selectQuery)):(this.append(" ("),this.compileList([...e.columns,...e.constraints??[]]),this.append(")"),e.onCommit&&(this.append(" on commit "),this.append(e.onCommit)),e.endModifiers&&e.endModifiers.length>0&&(this.append(" "),this.compileList(e.endModifiers," ")))}visitColumnDefinition(e){e.ifNotExists&&this.append("if not exists "),this.visitNode(e.column),this.append(" "),this.visitNode(e.dataType),e.unsigned&&this.append(" unsigned"),e.frontModifiers&&e.frontModifiers.length>0&&(this.append(" "),this.compileList(e.frontModifiers," ")),e.generated&&(this.append(" "),this.visitNode(e.generated)),e.identity&&this.append(" identity"),e.defaultTo&&(this.append(" "),this.visitNode(e.defaultTo)),e.notNull&&this.append(" not null"),e.unique&&this.append(" unique"),e.nullsNotDistinct&&this.append(" nulls not distinct"),e.primaryKey&&this.append(" primary key"),e.autoIncrement&&(this.append(" "),this.append(this.getAutoIncrement())),e.references&&(this.append(" "),this.visitNode(e.references)),e.check&&(this.append(" "),this.visitNode(e.check)),e.endModifiers&&e.endModifiers.length>0&&(this.append(" "),this.compileList(e.endModifiers," "))}getAutoIncrement(){return"auto_increment"}visitReferences(e){this.append("references "),this.visitNode(e.table),this.append(" ("),this.compileList(e.columns),this.append(")"),e.onDelete&&(this.append(" on delete "),this.append(e.onDelete)),e.onUpdate&&(this.append(" on update "),this.append(e.onUpdate))}visitDropTable(e){this.append("drop table "),e.ifExists&&this.append("if exists "),this.visitNode(e.table),e.cascade&&this.append(" cascade")}visitDataType(e){this.append(e.dataType)}visitOrderBy(e){this.append("order by "),this.compileList(e.items)}visitOrderByItem(e){this.visitNode(e.orderBy),e.direction&&(this.append(" "),this.visitNode(e.direction))}visitGroupBy(e){this.append("group by "),this.compileList(e.items)}visitGroupByItem(e){this.visitNode(e.groupBy)}visitUpdateQuery(e){let i=this.nodeStack.find(a.is),o=i!==e;!o&&e.explain&&(this.visitNode(e.explain),this.append(" ")),o&&!T.is(i)&&this.append("("),e.with&&(this.visitNode(e.with),this.append(" ")),this.append("update "),e.top&&(this.visitNode(e.top),this.append(" ")),e.table&&(this.visitNode(e.table),this.append(" ")),this.append("set "),e.updates&&this.compileList(e.updates),e.output&&(this.append(" "),this.visitNode(e.output)),e.from&&(this.append(" "),this.visitNode(e.from)),e.joins&&(this.append(" "),this.compileList(e.joins," ")),e.where&&(this.append(" "),this.visitNode(e.where)),e.limit&&(this.append(" "),this.visitNode(e.limit)),e.returning&&(this.append(" "),this.visitNode(e.returning)),o&&!T.is(i)&&this.append(")")}visitColumnUpdate(e){this.visitNode(e.column),this.append(" = "),this.visitNode(e.value)}visitLimit(e){this.append("limit "),this.visitNode(e.limit)}visitOffset(e){this.append("offset "),this.visitNode(e.offset)}visitOnConflict(e){this.append("on conflict"),e.columns?(this.append(" ("),this.compileList(e.columns),this.append(")")):e.constraint?(this.append(" on constraint "),this.visitNode(e.constraint)):e.indexExpression&&(this.append(" ("),this.visitNode(e.indexExpression),this.append(")")),e.indexWhere&&(this.append(" "),this.visitNode(e.indexWhere)),e.doNothing===!0?this.append(" do nothing"):e.updates&&(this.append(" do update set "),this.compileList(e.updates),e.updateWhere&&(this.append(" "),this.visitNode(e.updateWhere)))}visitOnDuplicateKey(e){this.append("on duplicate key update "),this.compileList(e.updates)}visitCreateIndex(e){this.append("create "),e.unique&&this.append("unique "),this.append("index "),e.ifNotExists&&this.append("if not exists "),this.visitNode(e.name),e.table&&(this.append(" on "),this.visitNode(e.table)),e.using&&(this.append(" using "),this.visitNode(e.using)),e.columns&&(this.append(" ("),this.compileList(e.columns),this.append(")")),e.nullsNotDistinct&&this.append(" nulls not distinct"),e.where&&(this.append(" "),this.visitNode(e.where))}visitDropIndex(e){this.append("drop index "),e.ifExists&&this.append("if exists "),this.visitNode(e.name),e.table&&(this.append(" on "),this.visitNode(e.table)),e.cascade&&this.append(" cascade")}visitCreateSchema(e){this.append("create schema "),e.ifNotExists&&this.append("if not exists "),this.visitNode(e.schema)}visitDropSchema(e){this.append("drop schema "),e.ifExists&&this.append("if exists "),this.visitNode(e.schema),e.cascade&&this.append(" cascade")}visitPrimaryKeyConstraint(e){e.name&&(this.append("constraint "),this.visitNode(e.name),this.append(" ")),this.append("primary key ("),this.compileList(e.columns),this.append(")")}visitUniqueConstraint(e){e.name&&(this.append("constraint "),this.visitNode(e.name),this.append(" ")),this.append("unique"),e.nullsNotDistinct&&this.append(" nulls not distinct"),this.append(" ("),this.compileList(e.columns),this.append(")")}visitCheckConstraint(e){e.name&&(this.append("constraint "),this.visitNode(e.name),this.append(" ")),this.append("check ("),this.visitNode(e.expression),this.append(")")}visitForeignKeyConstraint(e){e.name&&(this.append("constraint "),this.visitNode(e.name),this.append(" ")),this.append("foreign key ("),this.compileList(e.columns),this.append(") "),this.visitNode(e.references),e.onDelete&&(this.append(" on delete "),this.append(e.onDelete)),e.onUpdate&&(this.append(" on update "),this.append(e.onUpdate))}visitList(e){this.compileList(e.items)}visitWith(e){this.append("with "),e.recursive&&this.append("recursive "),this.compileList(e.expressions)}visitCommonTableExpression(e){this.visitNode(e.name),this.append(" as "),Ae(e.materialized)&&(e.materialized||this.append("not "),this.append("materialized ")),this.visitNode(e.expression)}visitCommonTableExpressionName(e){this.visitNode(e.table),e.columns&&(this.append("("),this.compileList(e.columns),this.append(")"))}visitAlterTable(e){this.append("alter table "),this.visitNode(e.table),this.append(" "),e.renameTo&&(this.append("rename to "),this.visitNode(e.renameTo)),e.setSchema&&(this.append("set schema "),this.visitNode(e.setSchema)),e.addConstraint&&this.visitNode(e.addConstraint),e.dropConstraint&&this.visitNode(e.dropConstraint),e.columnAlterations&&this.compileColumnAlterations(e.columnAlterations),e.addIndex&&this.visitNode(e.addIndex),e.dropIndex&&this.visitNode(e.dropIndex)}visitAddColumn(e){this.append("add column "),this.visitNode(e.column)}visitRenameColumn(e){this.append("rename column "),this.visitNode(e.column),this.append(" to "),this.visitNode(e.renameTo)}visitDropColumn(e){this.append("drop column "),this.visitNode(e.column)}visitAlterColumn(e){this.append("alter column "),this.visitNode(e.column),this.append(" "),e.dataType&&(this.announcesNewColumnDataType()&&this.append("type "),this.visitNode(e.dataType),e.dataTypeExpression&&(this.append("using "),this.visitNode(e.dataTypeExpression))),e.setDefault&&(this.append("set default "),this.visitNode(e.setDefault)),e.dropDefault&&this.append("drop default"),e.setNotNull&&this.append("set not null"),e.dropNotNull&&this.append("drop not null")}visitModifyColumn(e){this.append("modify column "),this.visitNode(e.column)}visitAddConstraint(e){this.append("add "),this.visitNode(e.constraint)}visitDropConstraint(e){this.append("drop constraint "),e.ifExists&&this.append("if exists "),this.visitNode(e.constraintName),e.modifier==="cascade"?this.append(" cascade"):e.modifier==="restrict"&&this.append(" restrict")}visitSetOperation(e){this.append(e.operator),this.append(" "),e.all&&this.append("all "),this.visitNode(e.expression)}visitCreateView(e){this.append("create "),e.orReplace&&this.append("or replace "),e.materialized&&this.append("materialized "),e.temporary&&this.append("temporary "),this.append("view "),e.ifNotExists&&this.append("if not exists "),this.visitNode(e.name),this.append(" "),e.columns&&(this.append("("),this.compileList(e.columns),this.append(") ")),e.as&&(this.append("as "),this.visitNode(e.as))}visitDropView(e){this.append("drop "),e.materialized&&this.append("materialized "),this.append("view "),e.ifExists&&this.append("if exists "),this.visitNode(e.name),e.cascade&&this.append(" cascade")}visitGenerated(e){this.append("generated "),e.always&&this.append("always "),e.byDefault&&this.append("by default "),this.append("as "),e.identity&&this.append("identity"),e.expression&&(this.append("("),this.visitNode(e.expression),this.append(")")),e.stored&&this.append(" stored")}visitDefaultValue(e){this.append("default "),this.visitNode(e.defaultValue)}visitSelectModifier(e){e.rawModifier?this.visitNode(e.rawModifier):this.append(rn[e.modifier]),e.of&&(this.append(" of "),this.compileList(e.of,", "))}visitCreateType(e){this.append("create type "),this.visitNode(e.name),e.enum&&(this.append(" as enum "),this.visitNode(e.enum))}visitDropType(e){this.append("drop type "),e.ifExists&&this.append("if exists "),this.visitNode(e.name)}visitExplain(e){this.append("explain"),(e.options||e.format)&&(this.append(" "),this.append(this.getLeftExplainOptionsWrapper()),e.options&&(this.visitNode(e.options),e.format&&this.append(this.getExplainOptionsDelimiter())),e.format&&(this.append("format"),this.append(this.getExplainOptionAssignment()),this.append(e.format)),this.append(this.getRightExplainOptionsWrapper()))}visitDefaultInsertValue(e){this.append("default")}visitAggregateFunction(e){this.append(e.func),this.append("("),e.distinct&&this.append("distinct "),this.compileList(e.aggregated),this.append(")"),e.filter&&(this.append(" filter("),this.visitNode(e.filter),this.append(")")),e.over&&(this.append(" "),this.visitNode(e.over))}visitOver(e){this.append("over("),e.partitionBy&&(this.visitNode(e.partitionBy),e.orderBy&&this.append(" ")),e.orderBy&&this.visitNode(e.orderBy),this.append(")")}visitPartitionBy(e){this.append("partition by "),this.compileList(e.items)}visitPartitionByItem(e){this.visitNode(e.partitionBy)}visitBinaryOperation(e){this.visitNode(e.leftOperand),this.append(" "),this.visitNode(e.operator),this.append(" "),this.visitNode(e.rightOperand)}visitUnaryOperation(e){this.visitNode(e.operator),this.isMinusOperator(e.operator)||this.append(" "),this.visitNode(e.operand)}isMinusOperator(e){return U.is(e)&&e.operator==="-"}visitUsing(e){this.append("using "),this.compileList(e.tables)}visitFunction(e){this.append(e.func),this.append("("),this.compileList(e.arguments),this.append(")")}visitCase(e){this.append("case"),e.value&&(this.append(" "),this.visitNode(e.value)),e.when&&(this.append(" "),this.compileList(e.when," ")),e.else&&(this.append(" else "),this.visitNode(e.else)),this.append(" end"),e.isStatement&&this.append(" case")}visitWhen(e){this.append("when "),this.visitNode(e.condition),e.result&&(this.append(" then "),this.visitNode(e.result))}visitJSONReference(e){this.visitNode(e.reference),this.visitNode(e.traversal)}visitJSONPath(e){e.inOperator&&this.visitNode(e.inOperator),this.append("'$");for(let i of e.pathLegs)this.visitNode(i);this.append("'")}visitJSONPathLeg(e){let i=e.type==="ArrayLocation";this.append(i?"[":"."),this.append(String(e.value)),i&&this.append("]")}visitJSONOperatorChain(e){for(let i=0,o=e.values.length;i<o;i++)i===o-1?this.visitNode(e.operator):this.append("->"),this.visitNode(e.values[i])}visitMergeQuery(e){e.with&&(this.visitNode(e.with),this.append(" ")),this.append("merge "),e.top&&(this.visitNode(e.top),this.append(" ")),this.append("into "),this.visitNode(e.into),e.using&&(this.append(" "),this.visitNode(e.using)),e.whens&&(this.append(" "),this.compileList(e.whens," ")),e.output&&(this.append(" "),this.visitNode(e.output))}visitMatched(e){e.not&&this.append("not "),this.append("matched"),e.bySource&&this.append(" by source")}visitAddIndex(e){this.append("add "),e.unique&&this.append("unique "),this.append("index "),this.visitNode(e.name),e.columns&&(this.append(" ("),this.compileList(e.columns),this.append(")")),e.using&&(this.append(" using "),this.visitNode(e.using))}visitCast(e){this.append("cast("),this.visitNode(e.expression),this.append(" as "),this.visitNode(e.dataType),this.append(")")}visitFetch(e){this.append("fetch next "),this.visitNode(e.rowCount),this.append(` rows ${e.modifier}`)}visitOutput(e){this.append("output "),this.compileList(e.selections)}visitTop(e){this.append(`top(${e.expression})`),e.modifiers&&this.append(` ${e.modifiers}`)}append(e){this.#e+=e}appendValue(e){this.addParameter(e),this.append(this.getCurrentParameterPlaceholder())}getLeftIdentifierWrapper(){return'"'}getRightIdentifierWrapper(){return'"'}getCurrentParameterPlaceholder(){return"$"+this.numParameters}getLeftExplainOptionsWrapper(){return"("}getExplainOptionAssignment(){return" "}getExplainOptionsDelimiter(){return", "}getRightExplainOptionsWrapper(){return")"}sanitizeIdentifier(e){let i=this.getLeftIdentifierWrapper(),o=this.getRightIdentifierWrapper(),n="";for(let u of e)n+=u,u===i?n+=i:u===o&&(n+=o);return n}addParameter(e){this.#t.push(e)}appendImmediateValue(e){if(g(e))this.append(`'${e}'`);else if(we(e)||Ae(e))this.append(e.toString());else if(Fe(e))this.append("null");else if(Ti(e))this.appendImmediateValue(e.toISOString());else if(Me(e))this.appendImmediateValue(e.toString());else throw new Error(`invalid immediate value ${e}`)}sortSelectModifiers(e){return e.sort((i,o)=>i.modifier&&o.modifier?vo[i.modifier]-vo[o.modifier]:1),r(e)}compileColumnAlterations(e){this.compileList(e)}announcesNewColumnDataType(){return!0}},rn=r({ForKeyShare:"for key share",ForNoKeyUpdate:"for no key update",ForUpdate:"for update",ForShare:"for share",NoWait:"nowait",SkipLocked:"skip locked",Distinct:"distinct"}),vo=r({ForKeyShare:1,ForNoKeyUpdate:1,ForUpdate:1,ForShare:1,NoWait:2,SkipLocked:2,Distinct:0}),on=r({InnerJoin:"inner join",LeftJoin:"left join",RightJoin:"right join",FullJoin:"full join",LateralInnerJoin:"inner join lateral",LateralLeftJoin:"left join lateral",Using:"using"});var Br=class{async init(){}async acquireConnection(){return new vi}async beginTransaction(){}async commitTransaction(){}async rollbackTransaction(){}async releaseConnection(){}async destroy(){}},vi=class{async executeQuery(){return{rows:[]}}async*streamQuery(){}};var Lr=class{get supportsCreateIfNotExists(){return!0}get supportsTransactionalDdl(){return!1}get supportsReturning(){return!1}get supportsOutput(){return!1}};var nn=/"/g,Qr=class extends Dr{sanitizeIdentifier(e){return e.replace(nn,'""')}};var sn=BigInt("3853314791062309107"),Pr=class extends Lr{get supportsTransactionalDdl(){return!0}get supportsReturning(){return!0}async acquireMigrationLock(e,i){await ct`select pg_advisory_xact_lock(${ct.lit(sn)})`.execute(e)}async releaseMigrationLock(e,i){}};function Co(t){return ct`(select coalesce(json_agg(agg), '[]') from ${t} as agg)`}function bo(t){return new ht({dialect:{createAdapter:()=>new t.Adapter,createDriver:()=>new Br,createIntrospector:()=>null,createQueryCompiler:()=>new t.QueryCompiler},plugins:[...t.noParameters?[new Ci]:[]]})}var Ci=class{#e=new bi;transformQuery(e){return this.#e.transformNode(e.node)}transformResult(e){return Promise.resolve(e.result)}},bi=class extends be{transformValue(e){return{...super.transformValue(e),immediate:!0}}};function Wo(t){let e=t.compile();return{parameters:e.parameters,sql:e.sql}}var an="r",un="v",dn=[an,un];function ig(t){return Wo(hn(t).selectFrom("pg_catalog.pg_class as cls").innerJoin("pg_catalog.pg_namespace as ns","cls.relnamespace","ns.oid").$call(pn).where("cls.relkind","in",dn).select(e=>["ns.nspname as schema","cls.relname as name",Co(e.selectFrom("pg_catalog.pg_attribute as att").whereRef("att.attrelid","=","cls.oid").where("att.attnum",">=",0).where("att.attisdropped","!=",!0).select("att.attname as name")).as("columns")]))}function og(){return[{schema:"public",name:"users",columns:[{name:"id"},{name:"name"},{name:"role"},{name:"created_at"}]}]}function pn(t){return t.where("ns.nspname","!~","^pg_").where("ns.nspname","!=","information_schema")}function hn(t){return bo({...t,Adapter:Pr,QueryCompiler:Qr})}export{ig as getTablesQuery,og as mockTablesQuery};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var n=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var H=(o,l)=>{for(var d in l)n(o,d,{get:l[d],enumerable:!0})},W=(o,l,d,r)=>{if(l&&typeof l=="object"||typeof l=="function")for(let e of f(l))!u.call(o,e)&&e!==d&&n(o,e,{get:()=>l[e],enumerable:!(r=c(l,e))||r.enumerable});return o};var a=o=>W(n({},"__esModule",{value:!0}),o);var g={};H(g,{default:()=>t});module.exports=a(g);function t(){console.log("Hello World")}
|
package/package.json
CHANGED
|
@@ -1,21 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/studio-core",
|
|
3
|
-
"version": "0.0.0-dev.
|
|
3
|
+
"version": "0.0.0-dev.202503201500",
|
|
4
4
|
"description": "Modular Prisma Studio components",
|
|
5
|
-
"sideEffects": false,
|
|
6
|
-
"main": "./dist/data/index.js",
|
|
7
|
-
"types": "./dist/data/index.d.ts",
|
|
8
5
|
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
9
7
|
"exports": {
|
|
10
8
|
"./data": {
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
"import": {
|
|
10
|
+
"types": "./dist/data/index.d.ts",
|
|
11
|
+
"default": "./dist/data/index.js"
|
|
12
|
+
},
|
|
13
|
+
"require": {
|
|
14
|
+
"types": "./dist/data/index.d.cts",
|
|
15
|
+
"default": "./dist/data/index.cjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"./data/postgres-core": {
|
|
19
|
+
"import": {
|
|
20
|
+
"types": "./dist/data/postgres-core/index.d.ts",
|
|
21
|
+
"default": "./dist/data/postgres-core/index.js"
|
|
22
|
+
},
|
|
23
|
+
"require": {
|
|
24
|
+
"types": "./dist/data/postgres-core/index.d.cts",
|
|
25
|
+
"default": "./dist/data/postgres-core/index.cjs"
|
|
26
|
+
}
|
|
14
27
|
},
|
|
15
28
|
"./ui": {
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
29
|
+
"import": {
|
|
30
|
+
"types": "./dist/ui/index.d.ts",
|
|
31
|
+
"default": "./dist/ui/index.js"
|
|
32
|
+
},
|
|
33
|
+
"require": {
|
|
34
|
+
"types": "./dist/ui/index.d.cts",
|
|
35
|
+
"default": "./dist/ui/index.cjs"
|
|
36
|
+
}
|
|
19
37
|
}
|
|
20
38
|
},
|
|
21
39
|
"keywords": [],
|
|
@@ -26,13 +44,18 @@
|
|
|
26
44
|
"tsx": "4.17.0",
|
|
27
45
|
"typescript": "5.5.4"
|
|
28
46
|
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@arethetypeswrong/cli": "0.17.4",
|
|
49
|
+
"kysely": "0.27.4"
|
|
50
|
+
},
|
|
29
51
|
"peerDependencies": {
|
|
30
52
|
"@types/react": "18.3.3",
|
|
31
53
|
"react": "18.3.0-canary-a870b2d54-20240314"
|
|
32
54
|
},
|
|
33
55
|
"scripts": {
|
|
34
56
|
"build": "tsup",
|
|
35
|
-
"
|
|
57
|
+
"check:exports": "attw --pack . --profile node16",
|
|
58
|
+
"typecheck": "tsc",
|
|
36
59
|
"lint": "eslint --fix .",
|
|
37
60
|
"test": ""
|
|
38
61
|
}
|
package/tsconfig.json
CHANGED
package/tsup.config.ts
CHANGED
|
@@ -4,8 +4,12 @@ export default defineConfig({
|
|
|
4
4
|
cjsInterop: true,
|
|
5
5
|
clean: true,
|
|
6
6
|
dts: true,
|
|
7
|
-
entry: ["./data/index.ts", "./ui/index.tsx"],
|
|
8
|
-
format: ["esm"],
|
|
7
|
+
entry: ["./data/index.ts", "./data/postgres-core/index.ts", "./ui/index.tsx"],
|
|
8
|
+
format: ["cjs", "esm"],
|
|
9
9
|
minify: true,
|
|
10
|
+
noExternal: [
|
|
11
|
+
// we want to hide the fact that we are using kysely, i guess.
|
|
12
|
+
"kysely",
|
|
13
|
+
],
|
|
10
14
|
outDir: "dist",
|
|
11
15
|
});
|