postgrelize 0.0.0-stage → 1.0.0
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/CHANGELOG.md +269 -0
- package/LICENSE +21 -0
- package/README.md +131 -2
- package/dist/associations/association-accessors.d.ts +21 -0
- package/dist/associations/association-key-types.d.ts +44 -0
- package/dist/associations/association-keys.d.ts +98 -0
- package/dist/associations/association-lookup.d.ts +26 -0
- package/dist/associations/association-shape.d.ts +25 -0
- package/dist/associations/association.d.ts +95 -0
- package/dist/associations/belongs-to-many.d.ts +86 -0
- package/dist/associations/belongs-to.d.ts +45 -0
- package/dist/associations/has-many.d.ts +79 -0
- package/dist/associations/has-one.d.ts +44 -0
- package/dist/associations/include-assembler.d.ts +21 -0
- package/dist/associations/include-columns.d.ts +24 -0
- package/dist/associations/include-joins.d.ts +17 -0
- package/dist/associations/include-loader.d.ts +48 -0
- package/dist/associations/include-order.d.ts +22 -0
- package/dist/associations/include-query-builder.d.ts +54 -0
- package/dist/associations/include-resolver.d.ts +29 -0
- package/dist/associations/include-rows.d.ts +47 -0
- package/dist/associations/include-sub-query.d.ts +35 -0
- package/dist/associations/include.d.ts +112 -0
- package/dist/associations/junction-keys.d.ts +23 -0
- package/dist/associations/nested-creator.d.ts +44 -0
- package/dist/associations/nested-saver.d.ts +30 -0
- package/dist/associations/owner-keys.d.ts +34 -0
- package/dist/associations/separate-include-loader.d.ts +24 -0
- package/dist/associations/types.d.ts +139 -0
- package/dist/connection/connection-config.d.ts +33 -0
- package/dist/connection/connection-manager.d.ts +65 -0
- package/dist/connection/connection-types.d.ts +21 -0
- package/dist/connection/copy-from-stdin.d.ts +52 -0
- package/dist/connection/copy-runner.d.ts +30 -0
- package/dist/connection/copy-to-stdout.d.ts +49 -0
- package/dist/connection/copy.d.ts +22 -0
- package/dist/connection/notifications.d.ts +28 -0
- package/dist/connection/options.d.ts +158 -0
- package/dist/connection/query-logger.d.ts +41 -0
- package/dist/connection/replica-router.d.ts +20 -0
- package/dist/connection/statement-cache.d.ts +36 -0
- package/dist/connection/statement-timeout.d.ts +22 -0
- package/dist/data-types/abstract-data-type.d.ts +58 -0
- package/dist/data-types/array-literal-parser.d.ts +17 -0
- package/dist/data-types/array-type.d.ts +18 -0
- package/dist/data-types/bit-type.d.ts +14 -0
- package/dist/data-types/blob-type.d.ts +12 -0
- package/dist/data-types/char-type.d.ts +12 -0
- package/dist/data-types/composite-fields.d.ts +26 -0
- package/dist/data-types/composite-type.d.ts +32 -0
- package/dist/data-types/data-types.d.ts +172 -0
- package/dist/data-types/date-type.d.ts +14 -0
- package/dist/data-types/decimal-type.d.ts +13 -0
- package/dist/data-types/default-value-generator.d.ts +15 -0
- package/dist/data-types/enum-type.d.ts +19 -0
- package/dist/data-types/ewkb-reader.d.ts +18 -0
- package/dist/data-types/ewkb-writer.d.ts +17 -0
- package/dist/data-types/float-type.d.ts +12 -0
- package/dist/data-types/geometric-text.d.ts +65 -0
- package/dist/data-types/geometric-type.d.ts +46 -0
- package/dist/data-types/hstore-type.d.ts +16 -0
- package/dist/data-types/integer-type.d.ts +24 -0
- package/dist/data-types/json-type.d.ts +16 -0
- package/dist/data-types/multirange-type.d.ts +19 -0
- package/dist/data-types/range-type.d.ts +28 -0
- package/dist/data-types/record-text.d.ts +29 -0
- package/dist/data-types/scalar-type.d.ts +13 -0
- package/dist/data-types/spatial-type.d.ts +20 -0
- package/dist/data-types/string-type.d.ts +12 -0
- package/dist/data-types/text-type.d.ts +12 -0
- package/dist/data-types/timestamp-type.d.ts +15 -0
- package/dist/data-types/virtual-type.d.ts +15 -0
- package/dist/data-types/wall-clock.d.ts +14 -0
- package/dist/ddl/column-ddl.d.ts +73 -0
- package/dist/ddl/constraint-ddl.d.ts +30 -0
- package/dist/ddl/ddl-generator.d.ts +181 -0
- package/dist/ddl/ddl-guards.d.ts +60 -0
- package/dist/ddl/ddl-types.d.ts +193 -0
- package/dist/ddl/enum-ddl.d.ts +42 -0
- package/dist/ddl/extension-ddl.d.ts +57 -0
- package/dist/ddl/function-ddl.d.ts +98 -0
- package/dist/ddl/index-ddl.d.ts +29 -0
- package/dist/ddl/index-element-ddl.d.ts +19 -0
- package/dist/ddl/partition-ddl.d.ts +88 -0
- package/dist/ddl/partition-types.d.ts +94 -0
- package/dist/ddl/policy-ddl.d.ts +137 -0
- package/dist/ddl/routine-guards.d.ts +63 -0
- package/dist/ddl/sequence-ddl.d.ts +103 -0
- package/dist/ddl/sql-literal.d.ts +61 -0
- package/dist/ddl/table-ddl.d.ts +35 -0
- package/dist/ddl/trigger-ddl.d.ts +81 -0
- package/dist/ddl/view-ddl.d.ts +122 -0
- package/dist/decorators/association-applier.d.ts +18 -0
- package/dist/decorators/association-decorators.d.ts +72 -0
- package/dist/decorators/column-decorators.d.ts +147 -0
- package/dist/decorators/decorator-factory.d.ts +45 -0
- package/dist/decorators/decorator-signature.d.ts +26 -0
- package/dist/decorators/decorator-types.d.ts +24 -0
- package/dist/decorators/foreign-key-decorator.d.ts +21 -0
- package/dist/decorators/hook-decorators.d.ts +393 -0
- package/dist/decorators/init-arguments.d.ts +29 -0
- package/dist/decorators/model-decorators.d.ts +18 -0
- package/dist/decorators/model-metadata.d.ts +70 -0
- package/dist/decorators/table-decorators.d.ts +43 -0
- package/dist/decorators/timestamp-decorators.d.ts +38 -0
- package/dist/errors/base-error.d.ts +40 -0
- package/dist/errors/connection-errors.d.ts +152 -0
- package/dist/errors/database-errors.d.ts +152 -0
- package/dist/errors/errors.d.ts +5 -0
- package/dist/errors/map-pg-error.d.ts +27 -0
- package/dist/errors/misc-errors.d.ts +188 -0
- package/dist/errors/validation-errors.d.ts +117 -0
- package/dist/exports-core.d.ts +15 -0
- package/dist/exports-decorators.d.ts +8 -0
- package/dist/exports-errors.d.ts +2 -0
- package/dist/exports-model.d.ts +21 -0
- package/dist/exports-schema.d.ts +19 -0
- package/dist/expressions/call-expressions.d.ts +54 -0
- package/dist/expressions/condition-expressions.d.ts +51 -0
- package/dist/expressions/expression.d.ts +52 -0
- package/dist/expressions/jsonpath-helpers.d.ts +37 -0
- package/dist/expressions/methods.d.ts +188 -0
- package/dist/expressions/op.d.ts +182 -0
- package/dist/expressions/query-expressions.d.ts +110 -0
- package/dist/expressions/row-expressions.d.ts +35 -0
- package/dist/expressions/search-helpers.d.ts +138 -0
- package/dist/expressions/trigram-helpers.d.ts +40 -0
- package/dist/hooks/hooks.d.ts +125 -0
- package/dist/index.cjs +20461 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +20332 -0
- package/dist/index.js.map +1 -0
- package/dist/model/attribute-columns.d.ts +85 -0
- package/dist/model/attribute-normalizer.d.ts +42 -0
- package/dist/model/attribute-options.d.ts +121 -0
- package/dist/model/bulk-insert-builder.d.ts +24 -0
- package/dist/model/bulk-options.d.ts +173 -0
- package/dist/model/copy-options.d.ts +51 -0
- package/dist/model/cte-builder.d.ts +134 -0
- package/dist/model/definition-normalizer.d.ts +26 -0
- package/dist/model/delete-query-builder.d.ts +42 -0
- package/dist/model/find-options.d.ts +144 -0
- package/dist/model/find-query-builder.d.ts +38 -0
- package/dist/model/insert-query-builder.d.ts +41 -0
- package/dist/model/instance-destroyer.d.ts +44 -0
- package/dist/model/instance-lifecycle-services.d.ts +61 -0
- package/dist/model/instance-lifecycle.d.ts +128 -0
- package/dist/model/instance-saver.d.ts +25 -0
- package/dist/model/instance-state.d.ts +48 -0
- package/dist/model/instance-validation.d.ts +35 -0
- package/dist/model/instance-values.d.ts +80 -0
- package/dist/model/instance-writer.d.ts +59 -0
- package/dist/model/join-source-builder.d.ts +25 -0
- package/dist/model/lateral-keys-builder.d.ts +25 -0
- package/dist/model/merge-action-builder.d.ts +31 -0
- package/dist/model/merge-options.d.ts +72 -0
- package/dist/model/merge-query-builder.d.ts +29 -0
- package/dist/model/merge-source-builder.d.ts +22 -0
- package/dist/model/mixins/model-aggregates.d.ts +69 -0
- package/dist/model/mixins/model-associations.d.ts +73 -0
- package/dist/model/mixins/model-constructor.d.ts +7 -0
- package/dist/model/mixins/model-finders.d.ts +124 -0
- package/dist/model/mixins/model-hooks.d.ts +138 -0
- package/dist/model/mixins/model-postgres.d.ts +198 -0
- package/dist/model/mixins/model-schema-binding.d.ts +36 -0
- package/dist/model/mixins/model-schema.d.ts +55 -0
- package/dist/model/mixins/model-scopes.d.ts +57 -0
- package/dist/model/mixins/model-writers.d.ts +175 -0
- package/dist/model/mixins/named-hooks.d.ts +28 -0
- package/dist/model/model-accessors.d.ts +22 -0
- package/dist/model/model-base.d.ts +83 -0
- package/dist/model/model-definition.d.ts +130 -0
- package/dist/model/model-instance-persistence.d.ts +132 -0
- package/dist/model/model-instance-values.d.ts +154 -0
- package/dist/model/model-operations.d.ts +22 -0
- package/dist/model/model-registry.d.ts +139 -0
- package/dist/model/model-services.d.ts +46 -0
- package/dist/model/model-state.d.ts +60 -0
- package/dist/model/model-values.d.ts +86 -0
- package/dist/model/model.d.ts +560 -0
- package/dist/model/on-conflict-builder.d.ts +111 -0
- package/dist/model/operations/bulk-create-operation.d.ts +40 -0
- package/dist/model/operations/copy-from-source.d.ts +51 -0
- package/dist/model/operations/copy-operation.d.ts +54 -0
- package/dist/model/operations/count-operation.d.ts +52 -0
- package/dist/model/operations/create-operation.d.ts +31 -0
- package/dist/model/operations/destroy-operation.d.ts +65 -0
- package/dist/model/operations/find-cursor.d.ts +23 -0
- package/dist/model/operations/find-lookups.d.ts +89 -0
- package/dist/model/operations/find-operation.d.ts +47 -0
- package/dist/model/operations/increment-operation.d.ts +40 -0
- package/dist/model/operations/insert-operation.d.ts +71 -0
- package/dist/model/operations/merge-operation.d.ts +56 -0
- package/dist/model/operations/model-operation.d.ts +33 -0
- package/dist/model/operations/update-operation.d.ts +45 -0
- package/dist/model/operations/upsert-operation.d.ts +39 -0
- package/dist/model/options.d.ts +103 -0
- package/dist/model/returning-old.d.ts +52 -0
- package/dist/model/row-mapper.d.ts +78 -0
- package/dist/model/row-plan.d.ts +31 -0
- package/dist/model/runtime.d.ts +54 -0
- package/dist/model/scope-registry.d.ts +81 -0
- package/dist/model/select-aggregates.d.ts +37 -0
- package/dist/model/select-lock.d.ts +13 -0
- package/dist/model/select-options.d.ts +92 -0
- package/dist/model/select-query-builder.d.ts +73 -0
- package/dist/model/select-targets.d.ts +77 -0
- package/dist/model/source-option-builder.d.ts +23 -0
- package/dist/model/source-options.d.ts +108 -0
- package/dist/model/statement-builder.d.ts +77 -0
- package/dist/model/statement-services.d.ts +2 -0
- package/dist/model/sync-hooks.d.ts +18 -0
- package/dist/model/table-sample-builder.d.ts +13 -0
- package/dist/model/types.d.ts +85 -0
- package/dist/model/unnest-insert-builder.d.ts +24 -0
- package/dist/model/update-query-builder.d.ts +39 -0
- package/dist/model/v6-conflict-builder.d.ts +37 -0
- package/dist/model/value-cloner.d.ts +17 -0
- package/dist/model/values-writer.d.ts +12 -0
- package/dist/model/where-options.d.ts +164 -0
- package/dist/model/write-options.d.ts +160 -0
- package/dist/model/written-rows.d.ts +56 -0
- package/dist/query/query-result-shaper.d.ts +91 -0
- package/dist/query/raw-query.d.ts +27 -0
- package/dist/query-interface/alter-planner.d.ts +40 -0
- package/dist/query-interface/bulk-data.d.ts +44 -0
- package/dist/query-interface/column-commands.d.ts +52 -0
- package/dist/query-interface/column-describer.d.ts +17 -0
- package/dist/query-interface/enum-commands.d.ts +36 -0
- package/dist/query-interface/index-commands.d.ts +57 -0
- package/dist/query-interface/model-tables.d.ts +58 -0
- package/dist/query-interface/object-commands.d.ts +71 -0
- package/dist/query-interface/partition-commands.d.ts +43 -0
- package/dist/query-interface/policy-commands.d.ts +54 -0
- package/dist/query-interface/query-interface-objects.d.ts +108 -0
- package/dist/query-interface/query-interface-partitions.d.ts +66 -0
- package/dist/query-interface/query-interface-policies.d.ts +86 -0
- package/dist/query-interface/query-interface-routines.d.ts +120 -0
- package/dist/query-interface/query-interface-tables.d.ts +179 -0
- package/dist/query-interface/query-interface-types.d.ts +62 -0
- package/dist/query-interface/query-interface-views.d.ts +84 -0
- package/dist/query-interface/query-interface.d.ts +256 -0
- package/dist/query-interface/routine-commands.d.ts +71 -0
- package/dist/query-interface/schema-synchronizer.d.ts +99 -0
- package/dist/query-interface/statement-runner.d.ts +40 -0
- package/dist/query-interface/sync-planner.d.ts +26 -0
- package/dist/query-interface/table-commands.d.ts +63 -0
- package/dist/query-interface/table-introspector.d.ts +58 -0
- package/dist/query-interface/view-commands.d.ts +47 -0
- package/dist/sequelize/sequelize-base.d.ts +196 -0
- package/dist/sequelize/sequelize-constructor.d.ts +7 -0
- package/dist/sequelize/sequelize-hooks.d.ts +86 -0
- package/dist/sequelize/sequelize-internals.d.ts +87 -0
- package/dist/sequelize/sequelize-notifications.d.ts +66 -0
- package/dist/sequelize/sequelize-schema.d.ts +106 -0
- package/dist/sequelize/sequelize-transactions.d.ts +96 -0
- package/dist/sequelize.d.ts +790 -0
- package/dist/sql/ast-clauses.d.ts +137 -0
- package/dist/sql/ast-expressions.d.ts +88 -0
- package/dist/sql/ast-statements.d.ts +80 -0
- package/dist/sql/ast.d.ts +21 -0
- package/dist/sql/compile.d.ts +21 -0
- package/dist/sql/dml-compiler.d.ts +54 -0
- package/dist/sql/expression-compiler.d.ts +56 -0
- package/dist/sql/from-compiler.d.ts +39 -0
- package/dist/sql/identifier-quoter.d.ts +15 -0
- package/dist/sql/merge-compiler.d.ts +20 -0
- package/dist/sql/order.d.ts +15 -0
- package/dist/sql/query-compiler.d.ts +45 -0
- package/dist/sql/sql-chunks.d.ts +50 -0
- package/dist/sql/with-compiler.d.ts +19 -0
- package/dist/transaction/advisory-locks.d.ts +28 -0
- package/dist/transaction/transaction-constants.d.ts +35 -0
- package/dist/transaction/transaction-runner.d.ts +60 -0
- package/dist/transaction/transaction-starter.d.ts +25 -0
- package/dist/transaction/transaction-statements.d.ts +28 -0
- package/dist/transaction/transaction.d.ts +198 -0
- package/dist/validation/attribute-validators.d.ts +23 -0
- package/dist/validation/builtin-attribute-validator.d.ts +19 -0
- package/dist/validation/builtin-validators.d.ts +16 -0
- package/dist/validation/core-validator.d.ts +16 -0
- package/dist/validation/custom-validators.d.ts +13 -0
- package/dist/validation/instance-validator.d.ts +25 -0
- package/dist/validation/schema-items.d.ts +22 -0
- package/dist/validation/standard-schema-validator.d.ts +30 -0
- package/dist/validation/standard-schema.d.ts +39 -0
- package/dist/validation/types.d.ts +36 -0
- package/dist/validation/validation-target.d.ts +13 -0
- package/dist/where/comparison-compiler.d.ts +27 -0
- package/dist/where/condition-compiler.d.ts +18 -0
- package/dist/where/operand-resolver.d.ts +10 -0
- package/dist/where/operator-allowlist.d.ts +14 -0
- package/dist/where/where-support.d.ts +52 -0
- package/dist/where/where.d.ts +46 -0
- package/dist/where/window-compiler.d.ts +14 -0
- package/llm/USAGE.md +423 -0
- package/package.json +102 -4
- package/skills/postgrelize/SKILL.md +57 -0
- package/skills/postgrelize/reference/associations.md +108 -0
- package/skills/postgrelize/reference/errors.md +37 -0
- package/skills/postgrelize/reference/migrating-from-sequelize.md +15 -0
- package/skills/postgrelize/reference/postgresql-features.md +157 -0
- package/skills/postgrelize/reference/querying.md +111 -0
- package/skills/postgrelize/reference/schema.md +135 -0
- package/skills/postgrelize/reference/security.md +34 -0
- package/skills/postgrelize/reference/transactions-and-sessions.md +122 -0
- package/skills/postgrelize/reference/writing.md +198 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/** Function reference: a plain name (`'touch'`, `'app.touch'`) or `{ name, schema }` (quoted exactly). */
|
|
2
|
+
export type FunctionName = string | Readonly<{
|
|
3
|
+
/** Function name, quoted exactly. */
|
|
4
|
+
name: string;
|
|
5
|
+
/** Schema name, quoted exactly. */
|
|
6
|
+
schema?: string;
|
|
7
|
+
}>;
|
|
8
|
+
/** Parameter of a function. */
|
|
9
|
+
export type FunctionParam = Readonly<{
|
|
10
|
+
/** SQL type, e.g. `'integer'`, `'varchar(10)'`, `'text[]'`. */
|
|
11
|
+
type: string;
|
|
12
|
+
/** Parameter name (identifier word). */
|
|
13
|
+
name?: string;
|
|
14
|
+
/** `IN`, `OUT`, `INOUT` or `VARIADIC`. */
|
|
15
|
+
direction?: string;
|
|
16
|
+
}>;
|
|
17
|
+
/** Local variable declared before `BEGIN`. */
|
|
18
|
+
export type FunctionVariable = Readonly<{
|
|
19
|
+
/** Variable name (identifier word). */
|
|
20
|
+
name: string;
|
|
21
|
+
/** SQL type. */
|
|
22
|
+
type: string;
|
|
23
|
+
/** Initial value, rendered as a literal. */
|
|
24
|
+
default?: unknown;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Options of `createFunction`.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const options: CreateFunctionOptions = {
|
|
32
|
+
* force: true,
|
|
33
|
+
* variables: [{ name: 'limit_rows', type: 'integer', default: 100 }],
|
|
34
|
+
* };
|
|
35
|
+
* await queryInterface.createFunction('f', [], 'integer', 'plpgsql', 'RETURN limit_rows;', [], options);
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export type CreateFunctionOptions = Readonly<{
|
|
39
|
+
/** Local variables (`DECLARE name type := default;`). */
|
|
40
|
+
variables?: readonly FunctionVariable[];
|
|
41
|
+
/** `CREATE OR REPLACE FUNCTION`. */
|
|
42
|
+
force?: boolean;
|
|
43
|
+
}>;
|
|
44
|
+
/**
|
|
45
|
+
* Options of `dropFunction`.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* const options: DropFunctionOptions = { ifExists: true, cascade: true };
|
|
50
|
+
* await queryInterface.dropFunction('f', [], options);
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export type DropFunctionOptions = Readonly<{
|
|
54
|
+
/** Adds `IF EXISTS`. */
|
|
55
|
+
ifExists?: boolean;
|
|
56
|
+
/** `CASCADE` instead of the default `RESTRICT`. */
|
|
57
|
+
cascade?: boolean;
|
|
58
|
+
}>;
|
|
59
|
+
/**
|
|
60
|
+
* `CREATE`, `DROP` and `ALTER ... RENAME` statements for functions (Sequelize v6 shapes).
|
|
61
|
+
*
|
|
62
|
+
* @internal
|
|
63
|
+
*/
|
|
64
|
+
export declare class FunctionDdl {
|
|
65
|
+
#private;
|
|
66
|
+
/**
|
|
67
|
+
* `CREATE [OR REPLACE] FUNCTION` statement; the body is wrapped in `BEGIN ... END;` like v6.
|
|
68
|
+
*
|
|
69
|
+
* @param name - Function name.
|
|
70
|
+
* @param params - Parameters.
|
|
71
|
+
* @param returnType - Return type.
|
|
72
|
+
* @param language - Language word.
|
|
73
|
+
* @param body - Trusted SQL / PL/pgSQL text.
|
|
74
|
+
* @param optionsArray - Characteristic keywords.
|
|
75
|
+
* @param options - Statement options.
|
|
76
|
+
* @returns Statement.
|
|
77
|
+
* @throws Error for missing parts or values outside the guards.
|
|
78
|
+
*/
|
|
79
|
+
createSql(name: FunctionName, params: readonly FunctionParam[], returnType: string, language: string, body: string, optionsArray: readonly string[], options: CreateFunctionOptions): string;
|
|
80
|
+
/**
|
|
81
|
+
* `DROP FUNCTION` statement (`RESTRICT` unless `cascade`).
|
|
82
|
+
*
|
|
83
|
+
* @param name - Function name.
|
|
84
|
+
* @param params - Parameters identifying the overload.
|
|
85
|
+
* @param options - Statement options.
|
|
86
|
+
* @returns Statement.
|
|
87
|
+
*/
|
|
88
|
+
dropSql(name: FunctionName, params: readonly FunctionParam[], options: DropFunctionOptions): string;
|
|
89
|
+
/**
|
|
90
|
+
* `ALTER FUNCTION ... RENAME TO` statement.
|
|
91
|
+
*
|
|
92
|
+
* @param name - Current name.
|
|
93
|
+
* @param params - Parameters identifying the overload.
|
|
94
|
+
* @param newName - New unqualified name.
|
|
95
|
+
* @returns Statement.
|
|
96
|
+
*/
|
|
97
|
+
renameSql(name: FunctionName, params: readonly FunctionParam[], newName: string): string;
|
|
98
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { IndexField, IndexOptions } from './ddl-types.ts';
|
|
2
|
+
import { TableName } from './sql-literal.ts';
|
|
3
|
+
/**
|
|
4
|
+
* `CREATE INDEX` statements and v6 default index names.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare class IndexDdl {
|
|
9
|
+
#private;
|
|
10
|
+
/**
|
|
11
|
+
* Default index name (v6 `Utils.nameIndex`).
|
|
12
|
+
*
|
|
13
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
14
|
+
* @param fields - Indexed fields.
|
|
15
|
+
* @returns Index name.
|
|
16
|
+
*/
|
|
17
|
+
indexName(table: TableName, fields: readonly IndexField[]): string;
|
|
18
|
+
/**
|
|
19
|
+
* `CREATE [UNIQUE] INDEX` statement.
|
|
20
|
+
*
|
|
21
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
22
|
+
* @param options - Index options.
|
|
23
|
+
* @param defaultSchema - Schema used when the table reference has none.
|
|
24
|
+
* @returns Statement.
|
|
25
|
+
* @throws Error without fields, with an invalid method / operator class, or with an expression
|
|
26
|
+
* field and no name.
|
|
27
|
+
*/
|
|
28
|
+
createIndexSql(table: TableName, options: IndexOptions, defaultSchema?: string): string;
|
|
29
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { IndexField } from './ddl-types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* One element of an index or EXCLUDE constraint: a quoted column or a trusted SQL expression with
|
|
4
|
+
* collation, operator class, order and nulls ordering.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare class IndexElementDdl {
|
|
9
|
+
#private;
|
|
10
|
+
/**
|
|
11
|
+
* SQL of an element.
|
|
12
|
+
*
|
|
13
|
+
* @param field - Column name or field object.
|
|
14
|
+
* @param operator - Default operator class.
|
|
15
|
+
* @returns Element SQL.
|
|
16
|
+
* @throws Error for an empty expression or an invalid operator class.
|
|
17
|
+
*/
|
|
18
|
+
elementSql(field: IndexField, operator: string | undefined): string;
|
|
19
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { PartitionBoundSpec, PartitionKey } from './partition-types.ts';
|
|
2
|
+
import { TableName } from './sql-literal.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Options of `createPartition`.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* await queryInterface.createPartition(
|
|
9
|
+
* 'events',
|
|
10
|
+
* 'events_2026',
|
|
11
|
+
* { from: ['2026-01-01'], to: ['2027-01-01'] },
|
|
12
|
+
* { ifNotExists: true, partitionBy: { strategy: 'list', columns: ['kind'] } },
|
|
13
|
+
* );
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export type CreatePartitionOptions = Readonly<{
|
|
17
|
+
/** Makes the partition itself partitioned. */
|
|
18
|
+
partitionBy?: PartitionKey;
|
|
19
|
+
/** `IF NOT EXISTS`. */
|
|
20
|
+
ifNotExists?: boolean;
|
|
21
|
+
}>;
|
|
22
|
+
/**
|
|
23
|
+
* Options of `detachPartition`.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* await queryInterface.detachPartition('events', 'events_2026', { concurrently: true });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export type DetachPartitionOptions = Readonly<{
|
|
31
|
+
/** `DETACH PARTITION ... CONCURRENTLY` (cannot run inside a transaction). */
|
|
32
|
+
concurrently?: boolean;
|
|
33
|
+
/** `DETACH PARTITION ... FINALIZE`, completing an interrupted concurrent detach. */
|
|
34
|
+
finalize?: boolean;
|
|
35
|
+
}>;
|
|
36
|
+
/**
|
|
37
|
+
* Declarative partitioning statements: `PARTITION BY`, `PARTITION OF`, `ATTACH` and `DETACH`.
|
|
38
|
+
*
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
export declare class PartitionDdl {
|
|
42
|
+
#private;
|
|
43
|
+
/**
|
|
44
|
+
* ` PARTITION BY ...` clause of `CREATE TABLE`.
|
|
45
|
+
*
|
|
46
|
+
* @param key - Strategy and key columns.
|
|
47
|
+
* @returns Clause with a leading space.
|
|
48
|
+
* @throws Error for an unknown strategy, no columns or an invalid operator class.
|
|
49
|
+
*/
|
|
50
|
+
partitionBySql(key: PartitionKey): string;
|
|
51
|
+
/**
|
|
52
|
+
* `CREATE TABLE ... PARTITION OF` statement.
|
|
53
|
+
*
|
|
54
|
+
* @param parent - Partitioned table.
|
|
55
|
+
* @param partition - New partition name.
|
|
56
|
+
* @param bound - Bounds.
|
|
57
|
+
* @param options - Sub-partitioning and `ifNotExists`.
|
|
58
|
+
* @returns Statement.
|
|
59
|
+
*/
|
|
60
|
+
createPartitionSql(parent: TableName, partition: TableName, bound: PartitionBoundSpec, options?: CreatePartitionOptions): string;
|
|
61
|
+
/**
|
|
62
|
+
* `ALTER TABLE ... ATTACH PARTITION` statement.
|
|
63
|
+
*
|
|
64
|
+
* @param parent - Partitioned table.
|
|
65
|
+
* @param partition - Existing table to attach.
|
|
66
|
+
* @param bound - Bounds.
|
|
67
|
+
* @returns Statement.
|
|
68
|
+
*/
|
|
69
|
+
attachPartitionSql(parent: TableName, partition: TableName, bound: PartitionBoundSpec): string;
|
|
70
|
+
/**
|
|
71
|
+
* `ALTER TABLE ... DETACH PARTITION` statement.
|
|
72
|
+
*
|
|
73
|
+
* @param parent - Partitioned table.
|
|
74
|
+
* @param partition - Partition to detach.
|
|
75
|
+
* @param options - `concurrently` or `finalize`.
|
|
76
|
+
* @returns Statement.
|
|
77
|
+
* @throws Error when both options are set.
|
|
78
|
+
*/
|
|
79
|
+
detachPartitionSql(parent: TableName, partition: TableName, options?: DetachPartitionOptions): string;
|
|
80
|
+
/**
|
|
81
|
+
* `FOR VALUES ...` or `DEFAULT` clause.
|
|
82
|
+
*
|
|
83
|
+
* @param bound - Bounds.
|
|
84
|
+
* @returns Clause.
|
|
85
|
+
* @throws Error for an unknown bound shape or non-integer modulus / remainder.
|
|
86
|
+
*/
|
|
87
|
+
boundSql(bound: PartitionBoundSpec): string;
|
|
88
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/** Partitioning method of a partitioned table. */
|
|
2
|
+
export type PartitionStrategy = 'range' | 'list' | 'hash';
|
|
3
|
+
/** Marker of a `MINVALUE` / `MAXVALUE` bound inside a range partition bound. */
|
|
4
|
+
export type PartitionBoundMarker = Readonly<{
|
|
5
|
+
/** Keyword the marker renders as. */
|
|
6
|
+
keyword: 'MINVALUE' | 'MAXVALUE';
|
|
7
|
+
}>;
|
|
8
|
+
/**
|
|
9
|
+
* `MINVALUE` and `MAXVALUE` for the `from` / `to` lists of a range partition bound. They are
|
|
10
|
+
* markers, not strings, so a string value can never be read as a keyword.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* await queryInterface.createPartition('events', 'events_old', {
|
|
15
|
+
* from: [PartitionBound.MINVALUE],
|
|
16
|
+
* to: ['2020-01-01'],
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare const PartitionBound: {
|
|
21
|
+
/** Lowest possible value of a range column. */
|
|
22
|
+
readonly MINVALUE: Readonly<Readonly<{
|
|
23
|
+
/** Keyword the marker renders as. */
|
|
24
|
+
keyword: "MINVALUE" | "MAXVALUE";
|
|
25
|
+
}>>;
|
|
26
|
+
/** Highest possible value of a range column. */
|
|
27
|
+
readonly MAXVALUE: Readonly<Readonly<{
|
|
28
|
+
/** Keyword the marker renders as. */
|
|
29
|
+
keyword: "MINVALUE" | "MAXVALUE";
|
|
30
|
+
}>>;
|
|
31
|
+
};
|
|
32
|
+
/** Element of a partition key: a column, or an expression (trusted SQL) with collation and operator class. */
|
|
33
|
+
export type PartitionKeyElement = string | Readonly<{
|
|
34
|
+
/** Column name. */
|
|
35
|
+
name: string;
|
|
36
|
+
/** Collation name. */
|
|
37
|
+
collate?: string;
|
|
38
|
+
/** Operator class. */
|
|
39
|
+
operator?: string;
|
|
40
|
+
/** Not used for a column element. */
|
|
41
|
+
expression?: undefined;
|
|
42
|
+
}> | Readonly<{
|
|
43
|
+
/** Trusted SQL expression, wrapped in parentheses. */
|
|
44
|
+
expression: string;
|
|
45
|
+
/** Collation name. */
|
|
46
|
+
collate?: string;
|
|
47
|
+
/** Operator class. */
|
|
48
|
+
operator?: string;
|
|
49
|
+
/** Not used for an expression element. */
|
|
50
|
+
name?: undefined;
|
|
51
|
+
}>;
|
|
52
|
+
/**
|
|
53
|
+
* Partition key of `createTable({ partitionBy })` and of a sub-partitioned partition.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* const key: PartitionKey = { strategy: 'range', columns: ['createdAt'] };
|
|
58
|
+
* await queryInterface.createTable('events', { createdAt: DataTypes.DATE }, { partitionBy: key });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export type PartitionKey = Readonly<{
|
|
62
|
+
/** `'range'`, `'list'` or `'hash'`. */
|
|
63
|
+
strategy: PartitionStrategy;
|
|
64
|
+
/** Key columns or expressions. */
|
|
65
|
+
columns: readonly PartitionKeyElement[];
|
|
66
|
+
}>;
|
|
67
|
+
/**
|
|
68
|
+
* Bounds of a partition: `{ in }` (list), `{ from, to }` (range; `PartitionBound.MINVALUE` /
|
|
69
|
+
* `MAXVALUE` allowed), `{ modulus, remainder }` (hash) or `{ default: true }`. Values are rendered
|
|
70
|
+
* as literals.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* const bound: PartitionBoundSpec = { from: ['2026-01-01'], to: ['2027-01-01'] };
|
|
75
|
+
* await queryInterface.createPartition('events', 'events_2026', bound);
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export type PartitionBoundSpec = Readonly<{
|
|
79
|
+
/** List partition: the values the partition holds. */
|
|
80
|
+
in: readonly unknown[];
|
|
81
|
+
}> | Readonly<{
|
|
82
|
+
/** Range partition: inclusive lower bound, one value per key column. */
|
|
83
|
+
from: readonly unknown[];
|
|
84
|
+
/** Range partition: exclusive upper bound, one value per key column. */
|
|
85
|
+
to: readonly unknown[];
|
|
86
|
+
}> | Readonly<{
|
|
87
|
+
/** Hash partition: modulus. */
|
|
88
|
+
modulus: number;
|
|
89
|
+
/** Hash partition: remainder, `0 <= remainder < modulus`. */
|
|
90
|
+
remainder: number;
|
|
91
|
+
}> | Readonly<{
|
|
92
|
+
/** Default partition, receiving rows that match no other partition. */
|
|
93
|
+
default: true;
|
|
94
|
+
}>;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { TableName } from './sql-literal.ts';
|
|
2
|
+
/** Condition of a policy: SQL text (trusted) or a where object (values rendered as literals). */
|
|
3
|
+
export type PolicyCondition = string | Readonly<Record<string | symbol, unknown>>;
|
|
4
|
+
/**
|
|
5
|
+
* Options of `enableRowLevelSecurity`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const options: EnableRowLevelSecurityOptions = { force: true };
|
|
10
|
+
* await queryInterface.enableRowLevelSecurity('documents', options);
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export type EnableRowLevelSecurityOptions = Readonly<{
|
|
14
|
+
/** Also `FORCE ROW LEVEL SECURITY`: the table owner is subject to the policies too. */
|
|
15
|
+
force?: boolean;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* Options of `disableRowLevelSecurity`.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const options: DisableRowLevelSecurityOptions = { noForce: true };
|
|
23
|
+
* await queryInterface.disableRowLevelSecurity('documents', options);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export type DisableRowLevelSecurityOptions = Readonly<{
|
|
27
|
+
/** Also `NO FORCE ROW LEVEL SECURITY`. */
|
|
28
|
+
noForce?: boolean;
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* Options of `createPolicy`.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* const options: CreatePolicyOptions = {
|
|
36
|
+
* command: 'select',
|
|
37
|
+
* roles: ['app_user'],
|
|
38
|
+
* using: "tenant_id = current_setting('app.tenant_id')::int",
|
|
39
|
+
* };
|
|
40
|
+
* await queryInterface.createPolicy('documents', 'tenant_isolation', options);
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export type CreatePolicyOptions = Readonly<{
|
|
44
|
+
/** Command the policy applies to; defaults to `'all'`. */
|
|
45
|
+
command?: 'all' | 'select' | 'insert' | 'update' | 'delete';
|
|
46
|
+
/** `'permissive'` (default) or `'restrictive'`. */
|
|
47
|
+
kind?: 'permissive' | 'restrictive';
|
|
48
|
+
/** Roles the policy applies to: role names, or `'public'`, `'current_user'`, `'current_role'`, `'session_user'`. */
|
|
49
|
+
roles?: readonly string[];
|
|
50
|
+
/** `USING (...)`: which existing rows are visible. SQL text is trusted; a where object is compiled with literals. */
|
|
51
|
+
using?: PolicyCondition;
|
|
52
|
+
/** `WITH CHECK (...)`: which new rows may be written. Same forms as `using`. */
|
|
53
|
+
withCheck?: PolicyCondition;
|
|
54
|
+
}>;
|
|
55
|
+
/**
|
|
56
|
+
* Options of `alterPolicy`.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* const options: AlterPolicyOptions = { roles: ['app_user', 'app_admin'], rename: 'tenant_rows' };
|
|
61
|
+
* await queryInterface.alterPolicy('documents', 'tenant_isolation', options);
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export type AlterPolicyOptions = Readonly<Pick<CreatePolicyOptions, 'roles' | 'using' | 'withCheck'> & {
|
|
65
|
+
/** New policy name (applied after the other changes). */
|
|
66
|
+
rename?: string;
|
|
67
|
+
}>;
|
|
68
|
+
/**
|
|
69
|
+
* Options of `dropPolicy`.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* const options: DropPolicyOptions = { ifExists: true };
|
|
74
|
+
* await queryInterface.dropPolicy('documents', 'tenant_isolation', options);
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export type DropPolicyOptions = Readonly<{
|
|
78
|
+
/** Adds `IF EXISTS`. */
|
|
79
|
+
ifExists?: boolean;
|
|
80
|
+
/** Also drops objects that depend on the policy. */
|
|
81
|
+
cascade?: boolean;
|
|
82
|
+
}>;
|
|
83
|
+
/**
|
|
84
|
+
* Row-level security DDL: `ENABLE` / `DISABLE ROW LEVEL SECURITY` and `CREATE` / `ALTER` / `DROP
|
|
85
|
+
* POLICY`. Names and roles are quoted; commands and kinds are allowlisted; string conditions are
|
|
86
|
+
* trusted SQL (ADR-025).
|
|
87
|
+
*
|
|
88
|
+
* @internal
|
|
89
|
+
*/
|
|
90
|
+
export declare class PolicyDdl {
|
|
91
|
+
#private;
|
|
92
|
+
/**
|
|
93
|
+
* `ALTER TABLE ... ENABLE ROW LEVEL SECURITY` statement.
|
|
94
|
+
*
|
|
95
|
+
* @param table - Table.
|
|
96
|
+
* @param options - Statement options.
|
|
97
|
+
* @returns Statement.
|
|
98
|
+
*/
|
|
99
|
+
enableSql(table: TableName, options: EnableRowLevelSecurityOptions): string;
|
|
100
|
+
/**
|
|
101
|
+
* `ALTER TABLE ... DISABLE ROW LEVEL SECURITY` statement.
|
|
102
|
+
*
|
|
103
|
+
* @param table - Table.
|
|
104
|
+
* @param options - Statement options.
|
|
105
|
+
* @returns Statement.
|
|
106
|
+
*/
|
|
107
|
+
disableSql(table: TableName, options: DisableRowLevelSecurityOptions): string;
|
|
108
|
+
/**
|
|
109
|
+
* `CREATE POLICY` statement.
|
|
110
|
+
*
|
|
111
|
+
* @param table - Table.
|
|
112
|
+
* @param name - Policy name.
|
|
113
|
+
* @param options - Policy options.
|
|
114
|
+
* @returns Statement.
|
|
115
|
+
* @throws Error for an unknown command or kind.
|
|
116
|
+
*/
|
|
117
|
+
createSql(table: TableName, name: string, options: CreatePolicyOptions): string;
|
|
118
|
+
/**
|
|
119
|
+
* `ALTER POLICY` statements (the change, then the rename).
|
|
120
|
+
*
|
|
121
|
+
* @param table - Table.
|
|
122
|
+
* @param name - Policy name.
|
|
123
|
+
* @param options - Changes.
|
|
124
|
+
* @returns Statements.
|
|
125
|
+
* @throws Error without any change.
|
|
126
|
+
*/
|
|
127
|
+
alterSql(table: TableName, name: string, options: AlterPolicyOptions): readonly string[];
|
|
128
|
+
/**
|
|
129
|
+
* `DROP POLICY` statement.
|
|
130
|
+
*
|
|
131
|
+
* @param table - Table.
|
|
132
|
+
* @param name - Policy name.
|
|
133
|
+
* @param options - Statement options.
|
|
134
|
+
* @returns Statement.
|
|
135
|
+
*/
|
|
136
|
+
dropSql(table: TableName, name: string, options: DropPolicyOptions): string;
|
|
137
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Allowlists and patterns for the keywords and type names of functions and triggers that cannot be
|
|
3
|
+
* quoted (ADR-020, ADR-025).
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export declare class RoutineGuards {
|
|
8
|
+
/**
|
|
9
|
+
* A plain identifier word (parameter, variable, language), rendered unquoted so it folds like v6.
|
|
10
|
+
*
|
|
11
|
+
* @param value - Word.
|
|
12
|
+
* @param kind - Kind named in the error.
|
|
13
|
+
* @returns The word.
|
|
14
|
+
* @throws Error for anything but `[A-Za-z_]\w*`.
|
|
15
|
+
*/
|
|
16
|
+
word(value: string, kind: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* A type name: words, an optional schema, a length / precision and array brackets.
|
|
19
|
+
*
|
|
20
|
+
* @param value - Type as written in SQL.
|
|
21
|
+
* @param kind - Kind named in the error.
|
|
22
|
+
* @returns The type.
|
|
23
|
+
* @throws Error for anything that is not a type name.
|
|
24
|
+
*/
|
|
25
|
+
typeName(value: string, kind: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Parameter direction keyword.
|
|
28
|
+
*
|
|
29
|
+
* @param value - Direction.
|
|
30
|
+
* @returns Upper-case direction.
|
|
31
|
+
* @throws Error outside `IN`, `OUT`, `INOUT`, `VARIADIC`.
|
|
32
|
+
*/
|
|
33
|
+
direction(value: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* Function characteristic keywords (`IMMUTABLE`, `SECURITY DEFINER`, `COST n`, ...).
|
|
36
|
+
*
|
|
37
|
+
* @param options - Keywords as given.
|
|
38
|
+
* @returns Normalized keywords.
|
|
39
|
+
* @throws Error for a keyword outside the allowlist.
|
|
40
|
+
*/
|
|
41
|
+
functionOptions(options: readonly string[]): readonly string[];
|
|
42
|
+
/**
|
|
43
|
+
* Trigger clauses: row / statement level, deferrability, `REFERENCING` transition tables and
|
|
44
|
+
* `WHEN (condition)`. The condition is trusted SQL.
|
|
45
|
+
*
|
|
46
|
+
* @param options - Clauses as given.
|
|
47
|
+
* @returns Normalized clauses (`WHEN` kept as written).
|
|
48
|
+
* @throws Error for a clause outside the allowlist.
|
|
49
|
+
*/
|
|
50
|
+
triggerOptions(options: readonly string[]): readonly string[];
|
|
51
|
+
/**
|
|
52
|
+
* Function name: a word or `schema.word` string (unquoted, folds like v6) or `{ name, schema }`
|
|
53
|
+
* (quoted exactly).
|
|
54
|
+
*
|
|
55
|
+
* @param name - Function name.
|
|
56
|
+
* @returns SQL name.
|
|
57
|
+
* @throws Error for a string that is not one or two identifier words.
|
|
58
|
+
*/
|
|
59
|
+
functionName(name: string | Readonly<{
|
|
60
|
+
name: string;
|
|
61
|
+
schema?: string;
|
|
62
|
+
}>): string;
|
|
63
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { TableName } from './sql-literal.ts';
|
|
2
|
+
/** Whole number accepted in sequence options. */
|
|
3
|
+
export type SequenceNumber = number | bigint;
|
|
4
|
+
/** Column that owns a sequence (the sequence is dropped with the column). */
|
|
5
|
+
export type SequenceOwner = Readonly<{
|
|
6
|
+
/** Owning table. */
|
|
7
|
+
table: TableName;
|
|
8
|
+
/** Owning column. */
|
|
9
|
+
column: string;
|
|
10
|
+
}>;
|
|
11
|
+
/**
|
|
12
|
+
* Options of `createSequence`.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const options: CreateSequenceOptions = { dataType: 'bigint', start: 1000, cache: 10 };
|
|
17
|
+
* await queryInterface.createSequence('invoice_number', options);
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export type CreateSequenceOptions = Readonly<{
|
|
21
|
+
/** `AS smallint | integer | bigint`. */
|
|
22
|
+
dataType?: 'smallint' | 'integer' | 'bigint';
|
|
23
|
+
/** `START WITH`. */
|
|
24
|
+
start?: SequenceNumber;
|
|
25
|
+
/** `INCREMENT BY`. */
|
|
26
|
+
increment?: SequenceNumber;
|
|
27
|
+
/** `MINVALUE`; `false` renders `NO MINVALUE`. */
|
|
28
|
+
minValue?: SequenceNumber | false;
|
|
29
|
+
/** `MAXVALUE`; `false` renders `NO MAXVALUE`. */
|
|
30
|
+
maxValue?: SequenceNumber | false;
|
|
31
|
+
/** `CACHE`. */
|
|
32
|
+
cache?: SequenceNumber;
|
|
33
|
+
/** `CYCLE` / `NO CYCLE`. */
|
|
34
|
+
cycle?: boolean;
|
|
35
|
+
/** `OWNED BY table.column`; `null` renders `OWNED BY NONE`. */
|
|
36
|
+
ownedBy?: SequenceOwner | null;
|
|
37
|
+
/** Adds `IF NOT EXISTS`. */
|
|
38
|
+
ifNotExists?: boolean;
|
|
39
|
+
}>;
|
|
40
|
+
/**
|
|
41
|
+
* Options of `alterSequence`.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* const options: AlterSequenceOptions = { restartWith: 1, cycle: true };
|
|
46
|
+
* await queryInterface.alterSequence('invoice_number', options);
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export type AlterSequenceOptions = Omit<CreateSequenceOptions, 'dataType' | 'start' | 'ifNotExists'> & Readonly<{
|
|
50
|
+
/** `RESTART WITH n`; `true` renders a bare `RESTART` (back to the start value). */
|
|
51
|
+
restartWith?: SequenceNumber | true;
|
|
52
|
+
/** Adds `IF EXISTS`. */
|
|
53
|
+
ifExists?: boolean;
|
|
54
|
+
}>;
|
|
55
|
+
/**
|
|
56
|
+
* Options of `dropSequence`.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* const options: DropSequenceOptions = { ifExists: true };
|
|
61
|
+
* await queryInterface.dropSequence('invoice_number', options);
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export type DropSequenceOptions = Readonly<{
|
|
65
|
+
/** Adds `IF EXISTS`. */
|
|
66
|
+
ifExists?: boolean;
|
|
67
|
+
/** Also drops objects that depend on the sequence. */
|
|
68
|
+
cascade?: boolean;
|
|
69
|
+
}>;
|
|
70
|
+
/**
|
|
71
|
+
* `CREATE`, `ALTER` and `DROP SEQUENCE` statements. Numbers must be whole; names are quoted.
|
|
72
|
+
*
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
export declare class SequenceDdl {
|
|
76
|
+
#private;
|
|
77
|
+
/**
|
|
78
|
+
* `CREATE SEQUENCE` statement.
|
|
79
|
+
*
|
|
80
|
+
* @param name - Sequence name.
|
|
81
|
+
* @param options - Sequence options.
|
|
82
|
+
* @returns Statement.
|
|
83
|
+
* @throws Error for an unknown data type or a non-integer number.
|
|
84
|
+
*/
|
|
85
|
+
createSql(name: TableName, options: CreateSequenceOptions): string;
|
|
86
|
+
/**
|
|
87
|
+
* `ALTER SEQUENCE` statement.
|
|
88
|
+
*
|
|
89
|
+
* @param name - Sequence name.
|
|
90
|
+
* @param options - Properties to change.
|
|
91
|
+
* @returns Statement.
|
|
92
|
+
* @throws Error without any property or with a non-integer number.
|
|
93
|
+
*/
|
|
94
|
+
alterSql(name: TableName, options: AlterSequenceOptions): string;
|
|
95
|
+
/**
|
|
96
|
+
* `DROP SEQUENCE` statement.
|
|
97
|
+
*
|
|
98
|
+
* @param name - Sequence name.
|
|
99
|
+
* @param options - Statement options.
|
|
100
|
+
* @returns Statement.
|
|
101
|
+
*/
|
|
102
|
+
dropSql(name: TableName, options: DropSequenceOptions): string;
|
|
103
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { CompiledQuery } from '../sql/compile.ts';
|
|
2
|
+
import { ExprNode } from '../sql/ast.ts';
|
|
3
|
+
/** Table reference accepted by QueryInterface: a name or `{ tableName, schema }`. */
|
|
4
|
+
export type TableName = string | QualifiedTable;
|
|
5
|
+
/** Schema-qualified table reference. */
|
|
6
|
+
export type QualifiedTable = Readonly<{
|
|
7
|
+
/** Table name. */
|
|
8
|
+
tableName: string;
|
|
9
|
+
/** Schema name. */
|
|
10
|
+
schema?: string;
|
|
11
|
+
}>;
|
|
12
|
+
/**
|
|
13
|
+
* Renders values as PostgreSQL literals and table references as quoted names, for DDL where bind
|
|
14
|
+
* parameters are not allowed (ADR-010).
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export declare class SqlLiteral {
|
|
19
|
+
#private;
|
|
20
|
+
/**
|
|
21
|
+
* Renders a value as a PostgreSQL literal. Strings with backslashes use the `E'...'` form.
|
|
22
|
+
*
|
|
23
|
+
* @param value - Value to render.
|
|
24
|
+
* @returns SQL literal.
|
|
25
|
+
* @throws Error for non-finite numbers and strings with NUL characters.
|
|
26
|
+
*/
|
|
27
|
+
escape(value: unknown): string;
|
|
28
|
+
/**
|
|
29
|
+
* Replaces `$n` placeholders of a compiled query with escaped literals.
|
|
30
|
+
*
|
|
31
|
+
* @param query - Compiled query.
|
|
32
|
+
* @returns SQL text without placeholders.
|
|
33
|
+
*/
|
|
34
|
+
inlineValues(query: CompiledQuery): string;
|
|
35
|
+
/**
|
|
36
|
+
* Compiles an expression node and inlines its values (for DDL).
|
|
37
|
+
*
|
|
38
|
+
* @param node - Expression node.
|
|
39
|
+
* @returns SQL text without placeholders.
|
|
40
|
+
*/
|
|
41
|
+
inlineExpr(node: ExprNode): string;
|
|
42
|
+
/**
|
|
43
|
+
* Splits a table reference into name and schema.
|
|
44
|
+
*
|
|
45
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
46
|
+
* @param defaultSchema - Schema used when the reference has none.
|
|
47
|
+
* @returns Table name and schema.
|
|
48
|
+
*/
|
|
49
|
+
tableParts(table: TableName, defaultSchema?: string): Readonly<{
|
|
50
|
+
name: string;
|
|
51
|
+
schema: string | undefined;
|
|
52
|
+
}>;
|
|
53
|
+
/**
|
|
54
|
+
* Quoted, schema-qualified table name.
|
|
55
|
+
*
|
|
56
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
57
|
+
* @param defaultSchema - Schema used when the reference has none.
|
|
58
|
+
* @returns Quoted table name.
|
|
59
|
+
*/
|
|
60
|
+
quoteTable(table: TableName, defaultSchema?: string): string;
|
|
61
|
+
}
|