durcno 1.0.0-alpha.17 → 1.0.0-alpha.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin.cjs CHANGED
@@ -10457,7 +10457,7 @@ async function status(options) {
10457
10457
  }
10458
10458
 
10459
10459
  // src/cli/index.ts
10460
- program.version("1.0.0-alpha.16");
10460
+ program.version("1.0.0-alpha.17");
10461
10461
  var Options = {
10462
10462
  config: ["--config <path>", "Path to the config file"]
10463
10463
  };
@@ -1,5 +1,5 @@
1
1
  import { BasicTypes, Or } from "../types.mjs";
2
- import { AnyScalarSqlFn } from "../functions/index.mjs";
2
+ import { AnyAggregateSqlFn, AnyScalarSqlFn, AnySqlFn } from "../functions/index.mjs";
3
3
  import { SelectQuery } from "../query-builders/select.mjs";
4
4
  import { AnyColumn } from "../table.mjs";
5
5
  import { Arg, IsArg } from "../query-builders/pre.mjs";
@@ -25,6 +25,16 @@ type AnyFilter = Filter<any, any>;
25
25
  */
26
26
  type FilterExpression<TScopeColumns extends AnyColumn, TPrepare extends boolean = false> = Filter<TScopeColumns, TPrepare extends true ? boolean : false> | Sql;
27
27
  type StdCondition = FilterExpression<AnyColumn>;
28
+ /**
29
+ * A HAVING clause expression. Structurally identical to `FilterExpression` but
30
+ * signals intent — it is used in `.having()` rather than `.where()`.
31
+ *
32
+ * Note: TypeScript does not prevent aggregate `SqlFn` expressions from being
33
+ * passed to `.where()` at the type level (the `$Columns` phantom traces back to
34
+ * `AnyColumn` regardless of aggregate/scalar kind). PostgreSQL will reject such
35
+ * queries at runtime. This is a known limitation.
36
+ */
37
+ type HavingExpression<TScopeColumns extends AnyColumn, TPrepare extends boolean = false> = FilterExpression<TScopeColumns, TPrepare>;
28
38
  type HasArg<T> = T extends {
29
39
  $HasArg: true;
30
40
  } ? true : false;
@@ -35,7 +45,7 @@ declare class ComparisonLeftIsColumn<TLeft extends AnyColumn, TOp extends string
35
45
  constructor(field: TLeft, op: TOp, right: TRight);
36
46
  toQuery(query: Query, ctx?: QueryContext): void;
37
47
  }
38
- declare class ComparisonLeftIsSqlFn<TLeft extends AnyScalarSqlFn, TOp extends string, TRight extends BasicTypes | AnyScalarSqlFn> extends Filter<TLeft["$Columns"] | (TRight extends AnyScalarSqlFn ? TRight["$Columns"] : never), HasArg<TLeft> extends true ? true : HasArg<TRight>> {
48
+ declare class ComparisonLeftIsSqlFn<TLeft extends AnySqlFn, TOp extends string, TRight extends BasicTypes | AnySqlFn> extends Filter<TLeft["$Columns"] | (TRight extends AnyScalarSqlFn ? TRight["$Columns"] : never), HasArg<TLeft> extends true ? true : HasArg<TRight>> {
39
49
  readonly left: TLeft;
40
50
  readonly op: TOp;
41
51
  readonly right: TRight;
@@ -46,26 +56,38 @@ declare function eq<TLeft extends AnyColumn, TRight extends TLeft["ValType"]>(le
46
56
  declare function eq<TLeft extends AnyColumn, TRight extends Arg<TLeft["ValType"]> | AnyColumn | AnyScalarSqlFn>(left: TLeft, right: TRight): ComparisonLeftIsColumn<TLeft, "=", TRight>;
47
57
  declare function eq<TLeft extends AnyScalarSqlFn, TRight extends BasicTypes>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, "=", TRight>;
48
58
  declare function eq<TLeft extends AnyScalarSqlFn, TRight extends AnyScalarSqlFn>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, "=", TRight>;
59
+ declare function eq<TLeft extends AnyAggregateSqlFn, TRight extends BasicTypes>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, "=", TRight>;
60
+ declare function eq<TLeft extends AnyAggregateSqlFn, TRight extends AnyAggregateSqlFn>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, "=", TRight>;
49
61
  declare function ne<TLeft extends AnyColumn, TRight extends TLeft["ValType"]>(left: TLeft, right: TRight): ComparisonLeftIsColumn<TLeft, "!=", TRight>;
50
62
  declare function ne<TLeft extends AnyColumn, TRight extends Arg<TLeft["ValType"]> | AnyColumn | AnyScalarSqlFn>(left: TLeft, right: TRight): ComparisonLeftIsColumn<TLeft, "!=", TRight>;
51
63
  declare function ne<TLeft extends AnyScalarSqlFn, TRight extends BasicTypes>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, "!=", TRight>;
52
64
  declare function ne<TLeft extends AnyScalarSqlFn, TRight extends AnyScalarSqlFn>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, "!=", TRight>;
65
+ declare function ne<TLeft extends AnyAggregateSqlFn, TRight extends BasicTypes>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, "!=", TRight>;
66
+ declare function ne<TLeft extends AnyAggregateSqlFn, TRight extends AnyAggregateSqlFn>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, "!=", TRight>;
53
67
  declare function gt<TLeft extends AnyColumn, TRight extends TLeft["ValType"]>(left: TLeft, right: TRight): ComparisonLeftIsColumn<TLeft, ">", TRight>;
54
68
  declare function gt<TLeft extends AnyColumn, TRight extends Arg<TLeft["ValType"]> | AnyColumn | AnyScalarSqlFn>(left: TLeft, right: TRight): ComparisonLeftIsColumn<TLeft, ">", TRight>;
55
69
  declare function gt<TLeft extends AnyScalarSqlFn, TRight extends BasicTypes>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, ">", TRight>;
56
70
  declare function gt<TLeft extends AnyScalarSqlFn, TRight extends AnyScalarSqlFn>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, ">", TRight>;
71
+ declare function gt<TLeft extends AnyAggregateSqlFn, TRight extends BasicTypes>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, ">", TRight>;
72
+ declare function gt<TLeft extends AnyAggregateSqlFn, TRight extends AnyAggregateSqlFn>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, ">", TRight>;
57
73
  declare function gte<TLeft extends AnyColumn, TRight extends TLeft["ValType"]>(left: TLeft, right: TRight): ComparisonLeftIsColumn<TLeft, ">=", TRight>;
58
74
  declare function gte<TLeft extends AnyColumn, TRight extends Arg<TLeft["ValType"]> | AnyColumn | AnyScalarSqlFn>(left: TLeft, right: TRight): ComparisonLeftIsColumn<TLeft, ">=", TRight>;
59
75
  declare function gte<TLeft extends AnyScalarSqlFn, TRight extends BasicTypes>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, ">=", TRight>;
60
76
  declare function gte<TLeft extends AnyScalarSqlFn, TRight extends AnyScalarSqlFn>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, ">=", TRight>;
77
+ declare function gte<TLeft extends AnyAggregateSqlFn, TRight extends BasicTypes>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, ">=", TRight>;
78
+ declare function gte<TLeft extends AnyAggregateSqlFn, TRight extends AnyAggregateSqlFn>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, ">=", TRight>;
61
79
  declare function lt<TLeft extends AnyColumn, TRight extends TLeft["ValType"]>(left: TLeft, right: TRight): ComparisonLeftIsColumn<TLeft, "<", TRight>;
62
80
  declare function lt<TLeft extends AnyColumn, TRight extends Arg<TLeft["ValType"]> | AnyColumn | AnyScalarSqlFn>(left: TLeft, right: TRight): ComparisonLeftIsColumn<TLeft, "<", TRight>;
63
81
  declare function lt<TLeft extends AnyScalarSqlFn, TRight extends BasicTypes>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, "<", TRight>;
64
82
  declare function lt<TLeft extends AnyScalarSqlFn, TRight extends AnyScalarSqlFn>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, "<", TRight>;
83
+ declare function lt<TLeft extends AnyAggregateSqlFn, TRight extends BasicTypes>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, "<", TRight>;
84
+ declare function lt<TLeft extends AnyAggregateSqlFn, TRight extends AnyAggregateSqlFn>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, "<", TRight>;
65
85
  declare function lte<TLeft extends AnyColumn, TRight extends TLeft["ValType"]>(left: TLeft, right: TRight): ComparisonLeftIsColumn<TLeft, "<=", TRight>;
66
86
  declare function lte<TLeft extends AnyColumn, TRight extends Arg<TLeft["ValType"]> | AnyColumn | AnyScalarSqlFn>(left: TLeft, right: TRight): ComparisonLeftIsColumn<TLeft, "<=", TRight>;
67
87
  declare function lte<TLeft extends AnyScalarSqlFn, TRight extends BasicTypes>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, "<=", TRight>;
68
88
  declare function lte<TLeft extends AnyScalarSqlFn, TRight extends AnyScalarSqlFn>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, "<=", TRight>;
89
+ declare function lte<TLeft extends AnyAggregateSqlFn, TRight extends BasicTypes>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, "<=", TRight>;
90
+ declare function lte<TLeft extends AnyAggregateSqlFn, TRight extends AnyAggregateSqlFn>(left: TLeft, right: TRight): ComparisonLeftIsSqlFn<TLeft, "<=", TRight>;
69
91
  declare class IsNullCondition<TCol extends AnyColumn> extends Filter<TCol, false> {
70
92
  readonly field: TCol;
71
93
  constructor(field: TCol);
@@ -78,7 +100,7 @@ declare class IsNotNullCondition<TCol extends AnyColumn> extends Filter<TCol, fa
78
100
  toQuery(query: Query, ctx?: QueryContext): void;
79
101
  }
80
102
  declare function isNotNull<TCol extends AnyColumn>(field: TCol): IsNotNullCondition<TCol>;
81
- type InSelectQuery<TArg extends boolean, TReturn> = SelectQuery<any, any, any, any, any, TArg, any, any, Record<string, TReturn>[]>;
103
+ type InSelectQuery<TArg extends boolean, TReturn> = SelectQuery<any, any, any, any, any, TArg, any, any, any, any, Record<string, TReturn>[]>;
82
104
  declare class InCondition<TCol extends AnyColumn, TArg extends boolean> extends Filter<TCol, TArg> {
83
105
  readonly field: TCol;
84
106
  readonly values: TCol["ValType"][] | InSelectQuery<TArg, TCol["ValType"]>;
@@ -106,4 +128,4 @@ declare class OrCondition<TConditions extends (AnyFilter | Sql)[]> extends Filte
106
128
  }
107
129
  declare function or<TConditions extends (AnyFilter | Sql)[]>(...conditions: TConditions): OrCondition<TConditions>;
108
130
  //#endregion
109
- export { AnyFilter, Filter, FilterExpression, StdCondition, and, eq, gt, gte, isIn, isNotNull, isNull, lt, lte, ne, notIn, or };
131
+ export { AnyFilter, Filter, FilterExpression, HavingExpression, StdCondition, and, eq, gt, gte, isIn, isNotNull, isNull, lt, lte, ne, notIn, or };
@@ -59,6 +59,7 @@ declare abstract class SqlFn<TColumn extends AnyColumn, THasArg extends boolean
59
59
  }
60
60
  type AnySqlFn = SqlFn<any, any, any, any, any>;
61
61
  type AnyScalarSqlFn = SqlFn<any, any, "scalar", any, any>;
62
+ type AnyAggregateSqlFn = SqlFn<any, any, "aggregate", any, any>;
62
63
  /**
63
64
  * Extracts the table column(s) referenced by a scalar expression.
64
65
  * For a raw column, returns the column itself.
@@ -104,4 +105,4 @@ declare function uuidv4(): Sql;
104
105
  */
105
106
  declare function uuidv7(): Sql;
106
107
  //#endregion
107
- export { AnyScalarSqlFn, AnySqlFn, ExprColumns, HasArg, SqlFn, now, uuidv4, uuidv7 };
108
+ export { AnyAggregateSqlFn, AnyScalarSqlFn, AnySqlFn, ExprColumns, HasArg, SqlFn, now, uuidv4, uuidv7 };
@@ -1,9 +1,9 @@
1
- import { CustomStatement, DDLStatement, DDLStatementType } from "./statement.mjs";
2
- import { CreateIndexBuilder, DropIndexStatement } from "./indexes.mjs";
3
- import { CreateSchemaStatement, DropSchemaStatement } from "./schema.mjs";
4
- import { CreateSequenceStatement, DropSequenceStatement, SequenceOptions } from "./sequence.mjs";
5
- import { AlterTableBuilder, ColumnOptions, CreateTableBuilder, DropTableStatement, RenameTableStatement } from "./table.mjs";
6
- import { AlterTypeBuilder, CreateTypeStatement, DropTypeStatement } from "./types.mjs";
1
+ import { CustomStatement, DDLStatement, DDLStatementType, custom } from "./statement.mjs";
2
+ import { CreateIndexBuilder, DropIndexStatement, createIndex, dropIndex } from "./indexes.mjs";
3
+ import { CreateSchemaStatement, DropSchemaStatement, createSchema, dropSchema } from "./schema.mjs";
4
+ import { CreateSequenceStatement, DropSequenceStatement, SequenceOptions, createSequence, dropSequence } from "./sequence.mjs";
5
+ import { AlterTableBuilder, ColumnOptions, CreateTableBuilder, DropTableStatement, RenameTableStatement, alterTable, createTable, dropTable, renameTable } from "./table.mjs";
6
+ import { AlterTypeBuilder, CreateTypeStatement, DropTypeStatement, alterType, createType, dropType } from "./types.mjs";
7
7
 
8
8
  //#region src/migration/ddl/index.d.ts
9
9
  /**
@@ -25,147 +25,20 @@ import { AlterTypeBuilder, CreateTypeStatement, DropTypeStatement } from "./type
25
25
  * ```
26
26
  */
27
27
  declare const ddl: {
28
- /**
29
- * Create a new schema.
30
- *
31
- * @param name - The schema name.
32
- * @returns A {@link CreateSchemaStatement}.
33
- */
34
- createSchema(name: string): CreateSchemaStatement;
35
- /**
36
- * Drop a schema.
37
- *
38
- * @param name - The schema name.
39
- * @returns A {@link DropSchemaStatement}.
40
- */
41
- dropSchema(name: string): DropSchemaStatement;
42
- /**
43
- * Create a new PostgreSQL type.
44
- *
45
- * Currently supports enum types only.
46
- *
47
- * @param schema - The schema the type belongs to.
48
- * @param name - The type name.
49
- * @param definition - The type definition. Currently only `{ asEnum: string[] }` is supported.
50
- * @returns A {@link CreateTypeStatement}.
51
- *
52
- * @example
53
- * ```typescript
54
- * ddl.createType('public', 'user_type', { asEnum: ['admin', 'user'] });
55
- * ```
56
- */
57
- createType(schema: string, name: string, definition: {
58
- asEnum: string[];
59
- }): CreateTypeStatement;
60
- /**
61
- * Drop an existing PostgreSQL type.
62
- *
63
- * @param schema - The schema the type belongs to.
64
- * @param name - The type name.
65
- * @returns A {@link DropTypeStatement}.
66
- *
67
- * @example
68
- * ```typescript
69
- * ddl.dropType('public', 'user_type');
70
- * ```
71
- */
72
- dropType(schema: string, name: string): DropTypeStatement;
73
- /**
74
- * Alter an existing type. Returns a chainable {@link AlterTypeBuilder}.
75
- *
76
- * Currently supports enum value operations only.
77
- *
78
- * @param schema - The schema the type belongs to.
79
- * @param name - The type name.
80
- * @returns An {@link AlterTypeBuilder} for chaining `.addValue()`.
81
- *
82
- * @example
83
- * ```typescript
84
- * ddl.alterType('public', 'user_type')
85
- * .addValue('moderator', { after: 'admin' })
86
- * .addValue('guest');
87
- * ```
88
- */
89
- alterType(schema: string, name: string): AlterTypeBuilder;
90
- /**
91
- * Create a new sequence.
92
- *
93
- * @param schema - The schema the sequence belongs to.
94
- * @param name - The sequence name.
95
- * @param options - Optional sequence configuration.
96
- * @returns A {@link CreateSequenceStatement}.
97
- */
98
- createSequence(schema: string, name: string, options?: SequenceOptions): CreateSequenceStatement;
99
- /**
100
- * Drop a sequence.
101
- *
102
- * @param schema - The schema the sequence belongs to.
103
- * @param name - The sequence name.
104
- * @returns A {@link DropSequenceStatement}.
105
- */
106
- dropSequence(schema: string, name: string): DropSequenceStatement;
107
- /**
108
- * Create a new table. Returns a chainable {@link CreateTableBuilder}.
109
- *
110
- * @param schema - The schema to create the table in.
111
- * @param name - The table name.
112
- * @returns A {@link CreateTableBuilder} for chaining `.column()`, `.check()`, etc.
113
- */
114
- createTable(schema: string, name: string): CreateTableBuilder;
115
- /**
116
- * Drop a table.
117
- *
118
- * @param schema - The schema of the table.
119
- * @param name - The table name.
120
- * @returns A {@link DropTableStatement}.
121
- */
122
- dropTable(schema: string, name: string): DropTableStatement;
123
- /**
124
- * Rename a table.
125
- *
126
- * @param schema - The schema of the table.
127
- * @param oldName - The current table name.
128
- * @param newName - The new table name.
129
- * @returns A {@link RenameTableStatement}.
130
- */
131
- renameTable(schema: string, oldName: string, newName: string): RenameTableStatement;
132
- /**
133
- * Alter an existing table. Returns a chainable {@link AlterTableBuilder}.
134
- *
135
- * @param schema - The schema of the table.
136
- * @param name - The table name.
137
- * @returns An {@link AlterTableBuilder} for chaining `.addColumn()`, `.dropColumn()`, etc.
138
- */
139
- alterTable(schema: string, name: string): AlterTableBuilder;
140
- /**
141
- * Create an index. Returns a chainable {@link CreateIndexBuilder}.
142
- *
143
- * @param name - The index name.
144
- * @returns A {@link CreateIndexBuilder} for chaining `.on()`, `.using()`, `.unique()`.
145
- *
146
- * @example
147
- * ```typescript
148
- * ddl.createIndex('idx_users_email')
149
- * .on('public', 'users', ['email'])
150
- * .using('btree')
151
- * .unique();
152
- * ```
153
- */
154
- createIndex(name: string): CreateIndexBuilder;
155
- /**
156
- * Drop an index.
157
- *
158
- * @param name - The index name.
159
- * @returns A {@link DropIndexStatement}.
160
- */
161
- dropIndex(name: string): DropIndexStatement;
162
- /**
163
- * Create a custom SQL statement. Preserved during migration regeneration.
164
- *
165
- * @param sql - The raw SQL string.
166
- * @returns A {@link CustomStatement}.
167
- */
168
- custom(sql: string): CustomStatement;
28
+ createSchema: typeof createSchema;
29
+ dropSchema: typeof dropSchema;
30
+ createType: typeof createType;
31
+ dropType: typeof dropType;
32
+ alterType: typeof alterType;
33
+ createSequence: typeof createSequence;
34
+ dropSequence: typeof dropSequence;
35
+ createTable: typeof createTable;
36
+ dropTable: typeof dropTable;
37
+ renameTable: typeof renameTable;
38
+ alterTable: typeof alterTable;
39
+ createIndex: typeof createIndex;
40
+ dropIndex: typeof dropIndex;
41
+ custom: typeof custom;
169
42
  };
170
43
  //#endregion
171
44
  export { ddl };
@@ -1,9 +1,9 @@
1
- import { CustomStatement } from "./statement.mjs";
2
- import { CreateIndexBuilder, DropIndexStatement } from "./indexes.mjs";
3
- import { CreateSchemaStatement, DropSchemaStatement } from "./schema.mjs";
4
- import { CreateSequenceStatement, DropSequenceStatement } from "./sequence.mjs";
5
- import { AlterTableBuilder, CreateTableBuilder, DropTableStatement, RenameTableStatement } from "./table.mjs";
6
- import { AlterTypeBuilder, CreateTypeStatement, DropTypeStatement } from "./types.mjs";
1
+ import { custom } from "./statement.mjs";
2
+ import { createIndex, dropIndex } from "./indexes.mjs";
3
+ import { createSchema, dropSchema } from "./schema.mjs";
4
+ import { createSequence, dropSequence } from "./sequence.mjs";
5
+ import { alterTable, createTable, dropTable, renameTable } from "./table.mjs";
6
+ import { alterType, createType, dropType } from "./types.mjs";
7
7
  //#region src/migration/ddl/index.ts
8
8
  /**
9
9
  * The main DDL builder entry point.
@@ -24,173 +24,20 @@ import { AlterTypeBuilder, CreateTypeStatement, DropTypeStatement } from "./type
24
24
  * ```
25
25
  */
26
26
  const ddl = {
27
- /**
28
- * Create a new schema.
29
- *
30
- * @param name - The schema name.
31
- * @returns A {@link CreateSchemaStatement}.
32
- */
33
- createSchema(name) {
34
- return new CreateSchemaStatement(name);
35
- },
36
- /**
37
- * Drop a schema.
38
- *
39
- * @param name - The schema name.
40
- * @returns A {@link DropSchemaStatement}.
41
- */
42
- dropSchema(name) {
43
- return new DropSchemaStatement(name);
44
- },
45
- /**
46
- * Create a new PostgreSQL type.
47
- *
48
- * Currently supports enum types only.
49
- *
50
- * @param schema - The schema the type belongs to.
51
- * @param name - The type name.
52
- * @param definition - The type definition. Currently only `{ asEnum: string[] }` is supported.
53
- * @returns A {@link CreateTypeStatement}.
54
- *
55
- * @example
56
- * ```typescript
57
- * ddl.createType('public', 'user_type', { asEnum: ['admin', 'user'] });
58
- * ```
59
- */
60
- createType(schema, name, definition) {
61
- return new CreateTypeStatement(schema, name, definition);
62
- },
63
- /**
64
- * Drop an existing PostgreSQL type.
65
- *
66
- * @param schema - The schema the type belongs to.
67
- * @param name - The type name.
68
- * @returns A {@link DropTypeStatement}.
69
- *
70
- * @example
71
- * ```typescript
72
- * ddl.dropType('public', 'user_type');
73
- * ```
74
- */
75
- dropType(schema, name) {
76
- return new DropTypeStatement(schema, name);
77
- },
78
- /**
79
- * Alter an existing type. Returns a chainable {@link AlterTypeBuilder}.
80
- *
81
- * Currently supports enum value operations only.
82
- *
83
- * @param schema - The schema the type belongs to.
84
- * @param name - The type name.
85
- * @returns An {@link AlterTypeBuilder} for chaining `.addValue()`.
86
- *
87
- * @example
88
- * ```typescript
89
- * ddl.alterType('public', 'user_type')
90
- * .addValue('moderator', { after: 'admin' })
91
- * .addValue('guest');
92
- * ```
93
- */
94
- alterType(schema, name) {
95
- return new AlterTypeBuilder(schema, name);
96
- },
97
- /**
98
- * Create a new sequence.
99
- *
100
- * @param schema - The schema the sequence belongs to.
101
- * @param name - The sequence name.
102
- * @param options - Optional sequence configuration.
103
- * @returns A {@link CreateSequenceStatement}.
104
- */
105
- createSequence(schema, name, options) {
106
- return new CreateSequenceStatement(schema, name, options);
107
- },
108
- /**
109
- * Drop a sequence.
110
- *
111
- * @param schema - The schema the sequence belongs to.
112
- * @param name - The sequence name.
113
- * @returns A {@link DropSequenceStatement}.
114
- */
115
- dropSequence(schema, name) {
116
- return new DropSequenceStatement(schema, name);
117
- },
118
- /**
119
- * Create a new table. Returns a chainable {@link CreateTableBuilder}.
120
- *
121
- * @param schema - The schema to create the table in.
122
- * @param name - The table name.
123
- * @returns A {@link CreateTableBuilder} for chaining `.column()`, `.check()`, etc.
124
- */
125
- createTable(schema, name) {
126
- return new CreateTableBuilder(schema, name);
127
- },
128
- /**
129
- * Drop a table.
130
- *
131
- * @param schema - The schema of the table.
132
- * @param name - The table name.
133
- * @returns A {@link DropTableStatement}.
134
- */
135
- dropTable(schema, name) {
136
- return new DropTableStatement(schema, name);
137
- },
138
- /**
139
- * Rename a table.
140
- *
141
- * @param schema - The schema of the table.
142
- * @param oldName - The current table name.
143
- * @param newName - The new table name.
144
- * @returns A {@link RenameTableStatement}.
145
- */
146
- renameTable(schema, oldName, newName) {
147
- return new RenameTableStatement(schema, oldName, newName);
148
- },
149
- /**
150
- * Alter an existing table. Returns a chainable {@link AlterTableBuilder}.
151
- *
152
- * @param schema - The schema of the table.
153
- * @param name - The table name.
154
- * @returns An {@link AlterTableBuilder} for chaining `.addColumn()`, `.dropColumn()`, etc.
155
- */
156
- alterTable(schema, name) {
157
- return new AlterTableBuilder(schema, name);
158
- },
159
- /**
160
- * Create an index. Returns a chainable {@link CreateIndexBuilder}.
161
- *
162
- * @param name - The index name.
163
- * @returns A {@link CreateIndexBuilder} for chaining `.on()`, `.using()`, `.unique()`.
164
- *
165
- * @example
166
- * ```typescript
167
- * ddl.createIndex('idx_users_email')
168
- * .on('public', 'users', ['email'])
169
- * .using('btree')
170
- * .unique();
171
- * ```
172
- */
173
- createIndex(name) {
174
- return new CreateIndexBuilder(name);
175
- },
176
- /**
177
- * Drop an index.
178
- *
179
- * @param name - The index name.
180
- * @returns A {@link DropIndexStatement}.
181
- */
182
- dropIndex(name) {
183
- return new DropIndexStatement(name);
184
- },
185
- /**
186
- * Create a custom SQL statement. Preserved during migration regeneration.
187
- *
188
- * @param sql - The raw SQL string.
189
- * @returns A {@link CustomStatement}.
190
- */
191
- custom(sql) {
192
- return new CustomStatement(sql);
193
- }
27
+ createSchema,
28
+ dropSchema,
29
+ createType,
30
+ dropType,
31
+ alterType,
32
+ createSequence,
33
+ dropSequence,
34
+ createTable,
35
+ dropTable,
36
+ renameTable,
37
+ alterTable,
38
+ createIndex,
39
+ dropIndex,
40
+ custom
194
41
  };
195
42
  //#endregion
196
43
  export { ddl };
@@ -3,6 +3,21 @@ import { Snapshot } from "../snapshot.mjs";
3
3
  import { DDLStatement } from "./statement.mjs";
4
4
 
5
5
  //#region src/migration/ddl/indexes.d.ts
6
+ /**
7
+ * Create an index. Returns a chainable {@link CreateIndexBuilder}.
8
+ *
9
+ * @param name - The index name.
10
+ * @returns A {@link CreateIndexBuilder} for chaining `.on()`, `.using()`, `.unique()`.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * ddl.createIndex('idx_users_email')
15
+ * .on('public', 'users', ['email'])
16
+ * .using('btree')
17
+ * .unique();
18
+ * ```
19
+ */
20
+ declare function createIndex(name: string): CreateIndexBuilder;
6
21
  /**
7
22
  * Chainable builder that constructs a `CREATE INDEX` DDL statement.
8
23
  *
@@ -69,6 +84,13 @@ declare class CreateIndexBuilder extends DDLStatement {
69
84
  toSQL(): string;
70
85
  applyToSnapshot(snapshot: Snapshot): void;
71
86
  }
87
+ /**
88
+ * Drop an index.
89
+ *
90
+ * @param name - The index name.
91
+ * @returns A {@link DropIndexStatement}.
92
+ */
93
+ declare function dropIndex(name: string): DropIndexStatement;
72
94
  /**
73
95
  * DDL statement builder that drops an existing index.
74
96
  *
@@ -107,4 +129,4 @@ declare class DropIndexStatement extends DDLStatement {
107
129
  applyToSnapshot(snapshot: Snapshot): void;
108
130
  }
109
131
  //#endregion
110
- export { CreateIndexBuilder, DropIndexStatement };
132
+ export { CreateIndexBuilder, DropIndexStatement, createIndex, dropIndex };
@@ -1,6 +1,23 @@
1
1
  import { DDLStatement } from "./statement.mjs";
2
2
  //#region src/migration/ddl/indexes.ts
3
3
  /**
4
+ * Create an index. Returns a chainable {@link CreateIndexBuilder}.
5
+ *
6
+ * @param name - The index name.
7
+ * @returns A {@link CreateIndexBuilder} for chaining `.on()`, `.using()`, `.unique()`.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * ddl.createIndex('idx_users_email')
12
+ * .on('public', 'users', ['email'])
13
+ * .using('btree')
14
+ * .unique();
15
+ * ```
16
+ */
17
+ function createIndex(name) {
18
+ return new CreateIndexBuilder(name);
19
+ }
20
+ /**
4
21
  * Chainable builder that constructs a `CREATE INDEX` DDL statement.
5
22
  *
6
23
  * Use {@link ddl.createIndex} to obtain an instance, then chain `.on()`,
@@ -107,6 +124,15 @@ var CreateIndexBuilder = class extends DDLStatement {
107
124
  }
108
125
  };
109
126
  /**
127
+ * Drop an index.
128
+ *
129
+ * @param name - The index name.
130
+ * @returns A {@link DropIndexStatement}.
131
+ */
132
+ function dropIndex(name) {
133
+ return new DropIndexStatement(name);
134
+ }
135
+ /**
110
136
  * DDL statement builder that drops an existing index.
111
137
  *
112
138
  * Generates: `DROP INDEX [CONCURRENTLY] <name>;`
@@ -156,4 +182,4 @@ var DropIndexStatement = class extends DDLStatement {
156
182
  }
157
183
  };
158
184
  //#endregion
159
- export { CreateIndexBuilder, DropIndexStatement };
185
+ export { CreateIndexBuilder, DropIndexStatement, createIndex, dropIndex };
@@ -2,6 +2,13 @@ import { Snapshot } from "../snapshot.mjs";
2
2
  import { DDLStatement } from "./statement.mjs";
3
3
 
4
4
  //#region src/migration/ddl/schema.d.ts
5
+ /**
6
+ * Create a new schema.
7
+ *
8
+ * @param name - The schema name.
9
+ * @returns A {@link CreateSchemaStatement}.
10
+ */
11
+ declare function createSchema(name: string): CreateSchemaStatement;
5
12
  /**
6
13
  * DDL statement that creates a new PostgreSQL schema.
7
14
  *
@@ -27,6 +34,13 @@ declare class CreateSchemaStatement extends DDLStatement {
27
34
  /** Schemas are not tracked in snapshot, so this is a no-op. */
28
35
  applyToSnapshot(_snapshot: Snapshot): void;
29
36
  }
37
+ /**
38
+ * Drop a schema.
39
+ *
40
+ * @param name - The schema name.
41
+ * @returns A {@link DropSchemaStatement}.
42
+ */
43
+ declare function dropSchema(name: string): DropSchemaStatement;
30
44
  /**
31
45
  * DDL statement that drops an existing PostgreSQL schema.
32
46
  *
@@ -53,4 +67,4 @@ declare class DropSchemaStatement extends DDLStatement {
53
67
  applyToSnapshot(_snapshot: Snapshot): void;
54
68
  }
55
69
  //#endregion
56
- export { CreateSchemaStatement, DropSchemaStatement };
70
+ export { CreateSchemaStatement, DropSchemaStatement, createSchema, dropSchema };
@@ -1,6 +1,15 @@
1
1
  import { DDLStatement } from "./statement.mjs";
2
2
  //#region src/migration/ddl/schema.ts
3
3
  /**
4
+ * Create a new schema.
5
+ *
6
+ * @param name - The schema name.
7
+ * @returns A {@link CreateSchemaStatement}.
8
+ */
9
+ function createSchema(name) {
10
+ return new CreateSchemaStatement(name);
11
+ }
12
+ /**
4
13
  * DDL statement that creates a new PostgreSQL schema.
5
14
  *
6
15
  * Generates: `CREATE SCHEMA <name>;`
@@ -30,6 +39,15 @@ var CreateSchemaStatement = class extends DDLStatement {
30
39
  applyToSnapshot(_snapshot) {}
31
40
  };
32
41
  /**
42
+ * Drop a schema.
43
+ *
44
+ * @param name - The schema name.
45
+ * @returns A {@link DropSchemaStatement}.
46
+ */
47
+ function dropSchema(name) {
48
+ return new DropSchemaStatement(name);
49
+ }
50
+ /**
33
51
  * DDL statement that drops an existing PostgreSQL schema.
34
52
  *
35
53
  * Generates: `DROP SCHEMA <name>;`
@@ -59,4 +77,4 @@ var DropSchemaStatement = class extends DDLStatement {
59
77
  applyToSnapshot(_snapshot) {}
60
78
  };
61
79
  //#endregion
62
- export { CreateSchemaStatement, DropSchemaStatement };
80
+ export { CreateSchemaStatement, DropSchemaStatement, createSchema, dropSchema };