postgrelize 0.0.0-stage → 1.1.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 +289 -0
- package/LICENSE +21 -0
- package/README.md +131 -2
- package/dist/associations/alias-minifier.d.ts +43 -0
- 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/after-connect-hook.d.ts +24 -0
- package/dist/connection/connect-hooks.d.ts +26 -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 +165 -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 +176 -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 +204 -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 +186 -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 +232 -0
- package/dist/errors/validation-errors.d.ts +141 -0
- package/dist/exports-associations.d.ts +6 -0
- package/dist/exports-core.d.ts +95 -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/logic.d.ts +25 -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 +21864 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +21688 -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/inflector.d.ts +28 -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 +88 -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 +113 -0
- package/dist/model/mixins/model-constructor.d.ts +7 -0
- package/dist/model/mixins/model-finders.d.ts +140 -0
- package/dist/model/mixins/model-hooks.d.ts +142 -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 +100 -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 +197 -0
- package/dist/model/model-operations.d.ts +22 -0
- package/dist/model/model-registry.d.ts +152 -0
- package/dist/model/model-services.d.ts +46 -0
- package/dist/model/model-state.d.ts +68 -0
- package/dist/model/model-values.d.ts +86 -0
- package/dist/model/model.d.ts +629 -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 +99 -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 +56 -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/package-version.d.ts +8 -0
- package/dist/query/query-result-shaper.d.ts +93 -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-catalog.d.ts +180 -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 +110 -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/instance-hook-adders.d.ts +72 -0
- package/dist/sequelize/sequelize-base.d.ts +196 -0
- package/dist/sequelize/sequelize-constructor.d.ts +7 -0
- package/dist/sequelize/sequelize-helpers.d.ts +133 -0
- package/dist/sequelize/sequelize-hooks.d.ts +99 -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 +125 -0
- package/dist/sequelize/sequelize-transactions.d.ts +96 -0
- package/dist/sequelize.d.ts +1175 -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/cls-namespace.d.ts +44 -0
- package/dist/transaction/transaction-constants.d.ts +35 -0
- package/dist/transaction/transaction-runner.d.ts +78 -0
- package/dist/transaction/transaction-starter.d.ts +25 -0
- package/dist/transaction/transaction-statements.d.ts +29 -0
- package/dist/transaction/transaction.d.ts +201 -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 +103 -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,108 @@
|
|
|
1
|
+
import { CreateExtensionOptions, DropExtensionOptions } from '../ddl/extension-ddl.ts';
|
|
2
|
+
import { AlterSequenceOptions, CreateSequenceOptions, DropSequenceOptions, SequenceNumber } from '../ddl/sequence-ddl.ts';
|
|
3
|
+
import { TableName } from '../ddl/sql-literal.ts';
|
|
4
|
+
import { QueryOptionsBase, RuntimeOwner } from '../model/runtime.ts';
|
|
5
|
+
import { QueryInterfaceTables } from './query-interface-tables.ts';
|
|
6
|
+
/**
|
|
7
|
+
* Schema object part of {@link QueryInterface}: extensions and sequences.
|
|
8
|
+
*/
|
|
9
|
+
export declare class QueryInterfaceObjects extends QueryInterfaceTables {
|
|
10
|
+
#private;
|
|
11
|
+
/**
|
|
12
|
+
* @param sequelize - Owning `Sequelize` instance.
|
|
13
|
+
*/
|
|
14
|
+
constructor(sequelize: RuntimeOwner);
|
|
15
|
+
/**
|
|
16
|
+
* Installs an extension with `CREATE EXTENSION`. Needs the privileges PostgreSQL requires for that extension (superuser or a trusted extension).
|
|
17
|
+
*
|
|
18
|
+
* @param name - Extension name, quoted as an identifier.
|
|
19
|
+
* @param options - `ifNotExists`, `schema`, `version`, `cascade` and query options.
|
|
20
|
+
* @throws DatabaseError when the extension is not available on the server or the role may not install it.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* await queryInterface.createExtension('pg_trgm', { ifNotExists: true });
|
|
25
|
+
* ```
|
|
26
|
+
* @see [Schema guide](/guide/schema)
|
|
27
|
+
*/
|
|
28
|
+
createExtension(name: string, options?: CreateExtensionOptions & QueryOptionsBase): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Removes an extension with `DROP EXTENSION`.
|
|
31
|
+
*
|
|
32
|
+
* @param name - Extension name.
|
|
33
|
+
* @param options - `ifExists`, `cascade` and query options.
|
|
34
|
+
* @throws DatabaseError when objects depend on the extension and `cascade` is not set.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* await queryInterface.dropExtension('pg_trgm', { ifExists: true });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
dropExtension(name: string, options?: DropExtensionOptions & QueryOptionsBase): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Creates a sequence with `CREATE SEQUENCE`. Numbers must be whole (`number` or `bigint`).
|
|
44
|
+
*
|
|
45
|
+
* @param name - Sequence name or `{ tableName, schema }`.
|
|
46
|
+
* @param options - Sequence properties and query options.
|
|
47
|
+
* @throws Error for an unknown `dataType` or a non-integer number.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* await queryInterface.createSequence('invoice_number', { start: 1000, increment: 1, cache: 10 });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
createSequence(name: TableName, options?: CreateSequenceOptions & QueryOptionsBase): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Changes a sequence with `ALTER SEQUENCE`.
|
|
57
|
+
*
|
|
58
|
+
* @param name - Sequence name or `{ tableName, schema }`.
|
|
59
|
+
* @param options - Properties to change (at least one) and query options.
|
|
60
|
+
* @throws Error when no property is given or a number is not whole.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* await queryInterface.alterSequence('invoice_number', { restartWith: 5000, cycle: false });
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
alterSequence(name: TableName, options?: AlterSequenceOptions & QueryOptionsBase): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Drops a sequence with `DROP SEQUENCE`.
|
|
70
|
+
*
|
|
71
|
+
* @param name - Sequence name or `{ tableName, schema }`.
|
|
72
|
+
* @param options - `ifExists`, `cascade` and query options.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* await queryInterface.dropSequence('invoice_number', { ifExists: true });
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
dropSequence(name: TableName, options?: DropSequenceOptions & QueryOptionsBase): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Advances a sequence and returns the new value (`SELECT nextval(...)`; the name is bound).
|
|
82
|
+
*
|
|
83
|
+
* @param name - Sequence name or `{ tableName, schema }`.
|
|
84
|
+
* @param options - Query options.
|
|
85
|
+
* @returns The value as text, so bigint values stay exact.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* const next = await queryInterface.nextval('invoice_number');
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
nextval(name: TableName, options?: QueryOptionsBase): Promise<string>;
|
|
93
|
+
/**
|
|
94
|
+
* Sets the current value of a sequence (`SELECT setval(...)`; name and value are bound).
|
|
95
|
+
*
|
|
96
|
+
* @param name - Sequence name or `{ tableName, schema }`.
|
|
97
|
+
* @param value - New value (`number` or `bigint`).
|
|
98
|
+
* @param isCalled - `true` (default): the next `nextval` returns `value + increment`; `false`: it returns `value`.
|
|
99
|
+
* @param options - Query options.
|
|
100
|
+
* @returns The value set, as text.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* await queryInterface.setval('invoice_number', 9000, false);
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
setval(name: TableName, value: SequenceNumber, isCalled?: boolean, options?: QueryOptionsBase): Promise<string>;
|
|
108
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { CreatePartitionOptions, DetachPartitionOptions } from '../ddl/partition-ddl.ts';
|
|
2
|
+
import { PartitionBoundSpec } from '../ddl/partition-types.ts';
|
|
3
|
+
import { TableName } from '../ddl/sql-literal.ts';
|
|
4
|
+
import { QueryOptionsBase, RuntimeOwner } from '../model/runtime.ts';
|
|
5
|
+
import { QueryInterfacePolicies } from './query-interface-policies.ts';
|
|
6
|
+
/**
|
|
7
|
+
* Declarative partitioning part of {@link QueryInterface}.
|
|
8
|
+
*/
|
|
9
|
+
export declare class QueryInterfacePartitions extends QueryInterfacePolicies {
|
|
10
|
+
#private;
|
|
11
|
+
/**
|
|
12
|
+
* @param sequelize - Owning `Sequelize` instance.
|
|
13
|
+
*/
|
|
14
|
+
constructor(sequelize: RuntimeOwner);
|
|
15
|
+
/**
|
|
16
|
+
* Creates a partition of a partitioned table (`CREATE TABLE ... PARTITION OF`). The partitioned parent comes from `createTable` with `partitionBy`.
|
|
17
|
+
*
|
|
18
|
+
* @param parent - Partitioned table name or `{ tableName, schema }`.
|
|
19
|
+
* @param partition - New partition name or `{ tableName, schema }`.
|
|
20
|
+
* @param bound - `{ in }` (list), `{ from, to }` (range), `{ modulus, remainder }` (hash) or `{ default: true }`; values are rendered as literals.
|
|
21
|
+
* @param options - `partitionBy` (sub-partitioning), `ifNotExists` and query options.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* await queryInterface.createTable('events', { at: DataTypes.DATE }, {
|
|
26
|
+
* partitionBy: { strategy: 'range', columns: ['at'] },
|
|
27
|
+
* });
|
|
28
|
+
* await queryInterface.createPartition('events', 'events_2026', {
|
|
29
|
+
* from: ['2026-01-01'],
|
|
30
|
+
* to: ['2027-01-01'],
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
* @see [Constraints and indexes guide](/guide/constraints-indexes)
|
|
34
|
+
*/
|
|
35
|
+
createPartition(parent: TableName, partition: TableName, bound: PartitionBoundSpec, options?: CreatePartitionOptions & QueryOptionsBase): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Attaches an existing table as a partition (`ALTER TABLE ... ATTACH PARTITION`). PostgreSQL scans the table to check the bounds unless a matching `CHECK` constraint exists.
|
|
38
|
+
*
|
|
39
|
+
* @param parent - Partitioned table name or `{ tableName, schema }`.
|
|
40
|
+
* @param partition - Existing table name or `{ tableName, schema }`.
|
|
41
|
+
* @param bound - Partition bounds, see {@link QueryInterface.createPartition}.
|
|
42
|
+
* @param options - Query options.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* await queryInterface.attachPartition('events', 'events_2027', {
|
|
47
|
+
* from: ['2027-01-01'],
|
|
48
|
+
* to: ['2028-01-01'],
|
|
49
|
+
* });
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
attachPartition(parent: TableName, partition: TableName, bound: PartitionBoundSpec, options?: QueryOptionsBase): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Detaches a partition, keeping it as a standalone table (`ALTER TABLE ... DETACH PARTITION`).
|
|
55
|
+
*
|
|
56
|
+
* @param parent - Partitioned table name or `{ tableName, schema }`.
|
|
57
|
+
* @param partition - Partition name or `{ tableName, schema }`.
|
|
58
|
+
* @param options - `concurrently` (PostgreSQL 14+, not inside a transaction), `finalize` and query options.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* await queryInterface.detachPartition('events', 'events_2026', { concurrently: true });
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
detachPartition(parent: TableName, partition: TableName, options?: DetachPartitionOptions & QueryOptionsBase): Promise<void>;
|
|
66
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { AlterPolicyOptions, CreatePolicyOptions, DisableRowLevelSecurityOptions, DropPolicyOptions, EnableRowLevelSecurityOptions } from '../ddl/policy-ddl.ts';
|
|
2
|
+
import { TableName } from '../ddl/sql-literal.ts';
|
|
3
|
+
import { QueryOptionsBase, RuntimeOwner } from '../model/runtime.ts';
|
|
4
|
+
import { QueryInterfaceViews } from './query-interface-views.ts';
|
|
5
|
+
/**
|
|
6
|
+
* Row-level security part of {@link QueryInterface}.
|
|
7
|
+
*/
|
|
8
|
+
export declare class QueryInterfacePolicies extends QueryInterfaceViews {
|
|
9
|
+
#private;
|
|
10
|
+
/**
|
|
11
|
+
* @param sequelize - Owning `Sequelize` instance.
|
|
12
|
+
*/
|
|
13
|
+
constructor(sequelize: RuntimeOwner);
|
|
14
|
+
/**
|
|
15
|
+
* Turns on row-level security for a table (`ALTER TABLE ... ENABLE ROW LEVEL SECURITY`). Without policies, non-owners see no rows.
|
|
16
|
+
*
|
|
17
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
18
|
+
* @param options - `force` (also applies to the table owner) and query options.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* await queryInterface.enableRowLevelSecurity('documents', { force: true });
|
|
23
|
+
* ```
|
|
24
|
+
* @see [Schema objects guide](/guide/schema-objects)
|
|
25
|
+
*/
|
|
26
|
+
enableRowLevelSecurity(table: TableName, options?: EnableRowLevelSecurityOptions & QueryOptionsBase): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Turns off row-level security for a table (`ALTER TABLE ... DISABLE ROW LEVEL SECURITY`); policies are kept.
|
|
29
|
+
*
|
|
30
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
31
|
+
* @param options - `noForce` and query options.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* await queryInterface.disableRowLevelSecurity('documents', { noForce: true });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
disableRowLevelSecurity(table: TableName, options?: DisableRowLevelSecurityOptions & QueryOptionsBase): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Creates a row-level security policy with `CREATE POLICY`.
|
|
41
|
+
*
|
|
42
|
+
* `using` and `withCheck` are SQL text you provide (not escaped, never build them from user input) or a where object, whose values are rendered as escaped literals. Session variables set with the `settings` transaction option work in conditions: `"tenant_id = current_setting('app.tenant_id')::int"`.
|
|
43
|
+
*
|
|
44
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
45
|
+
* @param name - Policy name.
|
|
46
|
+
* @param options - `command`, `kind`, `roles`, `using`, `withCheck` and query options.
|
|
47
|
+
* @throws Error for an unknown `command` or `kind`, empty `roles` or an empty condition.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* await queryInterface.createPolicy('documents', 'tenant_isolation', {
|
|
52
|
+
* roles: ['app_user'],
|
|
53
|
+
* using: "tenant_id = current_setting('app.tenant_id')::int",
|
|
54
|
+
* withCheck: "tenant_id = current_setting('app.tenant_id')::int",
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
createPolicy(table: TableName, name: string, options?: CreatePolicyOptions & QueryOptionsBase): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Changes a policy with `ALTER POLICY`: roles, conditions and name (`rename`, applied last).
|
|
61
|
+
*
|
|
62
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
63
|
+
* @param name - Current policy name.
|
|
64
|
+
* @param options - Changes (at least one) and query options.
|
|
65
|
+
* @throws Error when no change is given.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* await queryInterface.alterPolicy('documents', 'tenant_isolation', { roles: ['app_user', 'app_admin'] });
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
alterPolicy(table: TableName, name: string, options?: AlterPolicyOptions & QueryOptionsBase): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Drops a policy with `DROP POLICY`.
|
|
75
|
+
*
|
|
76
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
77
|
+
* @param name - Policy name.
|
|
78
|
+
* @param options - `ifExists`, `cascade` and query options.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* await queryInterface.dropPolicy('documents', 'tenant_isolation', { ifExists: true });
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
dropPolicy(table: TableName, name: string, options?: DropPolicyOptions & QueryOptionsBase): Promise<void>;
|
|
86
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { CreateFunctionOptions, DropFunctionOptions, FunctionName, FunctionParam } from '../ddl/function-ddl.ts';
|
|
2
|
+
import { TableName } from '../ddl/sql-literal.ts';
|
|
3
|
+
import { CreateTriggerOptions, DropTriggerOptions, TriggerArgument, TriggerEvent, TriggerTiming } from '../ddl/trigger-ddl.ts';
|
|
4
|
+
import { QueryOptionsBase, RuntimeOwner } from '../model/runtime.ts';
|
|
5
|
+
import { QueryInterfaceObjects } from './query-interface-objects.ts';
|
|
6
|
+
/**
|
|
7
|
+
* Function and trigger part of {@link QueryInterface}.
|
|
8
|
+
*/
|
|
9
|
+
export declare class QueryInterfaceRoutines extends QueryInterfaceObjects {
|
|
10
|
+
#private;
|
|
11
|
+
/**
|
|
12
|
+
* @param sequelize - Owning `Sequelize` instance.
|
|
13
|
+
*/
|
|
14
|
+
constructor(sequelize: RuntimeOwner);
|
|
15
|
+
/**
|
|
16
|
+
* Creates a function with `CREATE [OR REPLACE] FUNCTION` (Sequelize v6 `createFunction`). The body is wrapped in `BEGIN ... END;` as in v6.
|
|
17
|
+
*
|
|
18
|
+
* The `body` is SQL text you provide: it is not escaped, so never build it from user input. Names, parameter names and the language are validated identifier words; types and characteristic keywords are checked against strict patterns and allowlists. A function name given as a string is unquoted (folds to lower case, like v6); use `{ name, schema }` for an exact quoted name.
|
|
19
|
+
*
|
|
20
|
+
* @param name - Function name (`'touch'`, `'app.touch'` or `{ name, schema }`).
|
|
21
|
+
* @param params - Parameters `{ type, name?, direction? }`; pass `[]` for none.
|
|
22
|
+
* @param returnType - Return type, e.g. `'trigger'`, `'integer'`, `'SETOF text'`.
|
|
23
|
+
* @param language - Language, e.g. `'plpgsql'`.
|
|
24
|
+
* @param body - Trusted function body without `BEGIN` / `END`.
|
|
25
|
+
* @param optionsArray - Characteristic keywords such as `'IMMUTABLE'`, `'SECURITY DEFINER'`, `'COST 10'`.
|
|
26
|
+
* @param options - `variables`, `force` (`OR REPLACE`) and query options.
|
|
27
|
+
* @throws Error when a part is missing or fails validation.
|
|
28
|
+
* @throws DatabaseError when PostgreSQL rejects the function.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* await queryInterface.createFunction(
|
|
33
|
+
* 'touch_updated_at',
|
|
34
|
+
* [],
|
|
35
|
+
* 'trigger',
|
|
36
|
+
* 'plpgsql',
|
|
37
|
+
* 'NEW."updatedAt" := now(); RETURN NEW;',
|
|
38
|
+
* ['VOLATILE'],
|
|
39
|
+
* { force: true },
|
|
40
|
+
* );
|
|
41
|
+
* ```
|
|
42
|
+
* @see [Schema objects guide](/guide/schema-objects)
|
|
43
|
+
*/
|
|
44
|
+
createFunction(name: FunctionName, params: readonly FunctionParam[], returnType: string, language: string, body: string, optionsArray?: readonly string[], options?: CreateFunctionOptions & QueryOptionsBase): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Drops a function with `DROP FUNCTION ... RESTRICT` (Sequelize v6 `dropFunction`).
|
|
47
|
+
*
|
|
48
|
+
* @param name - Function name.
|
|
49
|
+
* @param params - Parameters that identify the overload; pass `[]` for none.
|
|
50
|
+
* @param options - `ifExists`, `cascade` and query options.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* await queryInterface.dropFunction('touch_updated_at', [], { ifExists: true });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
dropFunction(name: FunctionName, params: readonly FunctionParam[], options?: DropFunctionOptions & QueryOptionsBase): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Renames a function with `ALTER FUNCTION ... RENAME TO` (Sequelize v6 `renameFunction`).
|
|
60
|
+
*
|
|
61
|
+
* @param name - Current function name.
|
|
62
|
+
* @param params - Parameters that identify the overload.
|
|
63
|
+
* @param newName - New unqualified name.
|
|
64
|
+
* @param options - Query options.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* await queryInterface.renameFunction('touch_updated_at', [], 'set_updated_at');
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
renameFunction(name: FunctionName, params: readonly FunctionParam[], newName: string, options?: QueryOptionsBase): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Creates a trigger with `CREATE TRIGGER` (Sequelize v6 `createTrigger`; `'after_constraint'` creates a `CONSTRAINT TRIGGER`).
|
|
74
|
+
*
|
|
75
|
+
* `functionArgs` are rendered as literals (v6 rendered typed parameter declarations, which PostgreSQL rejects). The `optionsArray` clauses are checked against an allowlist (`'FOR EACH ROW'`, `'FOR EACH STATEMENT'`, `'DEFERRABLE'`, `'INITIALLY DEFERRED'`, `REFERENCING ... TABLE AS name`); a `WHEN (condition)` clause is trusted SQL and is not escaped.
|
|
76
|
+
*
|
|
77
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
78
|
+
* @param name - Trigger name.
|
|
79
|
+
* @param timing - `'before'`, `'after'`, `'instead_of'` or `'after_constraint'`.
|
|
80
|
+
* @param events - Events that fire the trigger: `'insert'`, `'update'`, `'delete'`, `'truncate'`.
|
|
81
|
+
* @param functionName - Trigger function (see {@link QueryInterface.createFunction}).
|
|
82
|
+
* @param functionArgs - Literal arguments for the function; pass `[]` for none.
|
|
83
|
+
* @param optionsArray - Clauses such as `['FOR EACH ROW']`.
|
|
84
|
+
* @param options - `replace` (`OR REPLACE`, PostgreSQL 14+) and query options.
|
|
85
|
+
* @throws Error for an unknown timing, event or clause.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* await queryInterface.createTrigger('Posts', 'posts_touch', 'before', ['insert', 'update'], 'touch_updated_at', [], ['FOR EACH ROW']);
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
createTrigger(table: TableName, name: string, timing: TriggerTiming, events: readonly TriggerEvent[], functionName: FunctionName, functionArgs?: readonly TriggerArgument[], optionsArray?: readonly string[], options?: CreateTriggerOptions & QueryOptionsBase): Promise<void>;
|
|
93
|
+
/**
|
|
94
|
+
* Drops a trigger with `DROP TRIGGER ... RESTRICT` (Sequelize v6 `dropTrigger`).
|
|
95
|
+
*
|
|
96
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
97
|
+
* @param name - Trigger name.
|
|
98
|
+
* @param options - `ifExists`, `cascade` and query options.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* await queryInterface.dropTrigger('Posts', 'posts_touch', { ifExists: true });
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
dropTrigger(table: TableName, name: string, options?: DropTriggerOptions & QueryOptionsBase): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Renames a trigger with `ALTER TRIGGER ... RENAME TO` (Sequelize v6 `renameTrigger`).
|
|
108
|
+
*
|
|
109
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
110
|
+
* @param name - Current trigger name.
|
|
111
|
+
* @param newName - New trigger name.
|
|
112
|
+
* @param options - Query options.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* await queryInterface.renameTrigger('Posts', 'posts_touch', 'posts_set_updated_at');
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
renameTrigger(table: TableName, name: string, newName: string, options?: QueryOptionsBase): Promise<void>;
|
|
120
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { TableName } from '../ddl/sql-literal.ts';
|
|
2
|
+
import { ModelAttributes } from '../model/model-definition.ts';
|
|
3
|
+
import { QueryOptionsBase, RuntimeOwner } from '../model/runtime.ts';
|
|
4
|
+
import { ColumnDescription, CreateTableOptions, DropTableOptions, ForeignKeyReference } from './query-interface-types.ts';
|
|
5
|
+
/**
|
|
6
|
+
* Schema and table part of {@link QueryInterface}: schemas, tables and catalog lookups.
|
|
7
|
+
*/
|
|
8
|
+
export declare class QueryInterfaceTables {
|
|
9
|
+
#private;
|
|
10
|
+
/** Owning `Sequelize` instance. */
|
|
11
|
+
readonly sequelize: RuntimeOwner;
|
|
12
|
+
/**
|
|
13
|
+
* @param sequelize - Owning `Sequelize` instance.
|
|
14
|
+
*/
|
|
15
|
+
constructor(sequelize: RuntimeOwner);
|
|
16
|
+
/**
|
|
17
|
+
* Runs `CREATE SCHEMA IF NOT EXISTS` for a schema.
|
|
18
|
+
*
|
|
19
|
+
* @param schema - Schema name.
|
|
20
|
+
* @param options - Query options.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* await queryInterface.createSchema('tenant_1');
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
createSchema(schema: string, options?: QueryOptionsBase): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Runs `DROP SCHEMA IF EXISTS ... CASCADE`, removing the schema and everything in it.
|
|
30
|
+
*
|
|
31
|
+
* @param schema - Schema name.
|
|
32
|
+
* @param options - Query options.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* await queryInterface.dropSchema('tenant_1');
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
dropSchema(schema: string, options?: QueryOptionsBase): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Lists application schemas, leaving out `public`, `information_schema` and `pg_*` schemas.
|
|
42
|
+
*
|
|
43
|
+
* @param options - Query options.
|
|
44
|
+
* @returns Schema names.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* const schemas = await queryInterface.showAllSchemas();
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
showAllSchemas(options?: QueryOptionsBase): Promise<string[]>;
|
|
52
|
+
/**
|
|
53
|
+
* Drops, with `CASCADE`, every schema listed by {@link QueryInterface.showAllSchemas} Destructive.
|
|
54
|
+
*
|
|
55
|
+
* @param options - Query options.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* await queryInterface.dropAllSchemas();
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
dropAllSchemas(options?: QueryOptionsBase): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Creates a table together with the enum types its columns need, if the table does not exist yet. Foreign keys, defaults and comments come from the attribute definitions.
|
|
65
|
+
*
|
|
66
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
67
|
+
* @param attributes - Column definitions keyed by column name.
|
|
68
|
+
* @param options - Comment and query options.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* await queryInterface.createTable(
|
|
73
|
+
* { tableName: 'posts', schema: 'tenant_1' },
|
|
74
|
+
* {
|
|
75
|
+
* id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
|
|
76
|
+
* title: { type: DataTypes.STRING, allowNull: false },
|
|
77
|
+
* },
|
|
78
|
+
* { comment: 'Blog posts' },
|
|
79
|
+
* );
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
createTable(table: TableName, attributes: ModelAttributes, options?: CreateTableOptions): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Runs `DROP TABLE IF EXISTS` for a table; it does not drop the table's enum types.
|
|
85
|
+
*
|
|
86
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
87
|
+
* @param options - `cascade` and query options.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* await queryInterface.dropTable('posts', { cascade: true });
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
dropTable(table: TableName, options?: DropTableOptions): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Drops every table of the current schema with `CASCADE`, except the skipped ones. Destructive.
|
|
97
|
+
*
|
|
98
|
+
* @param options - `skip`: table names to keep, plus query options.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* await queryInterface.dropAllTables({ skip: ['SequelizeMeta'] });
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
dropAllTables(options?: QueryOptionsBase & Readonly<{
|
|
106
|
+
skip?: readonly string[];
|
|
107
|
+
}>): Promise<void>;
|
|
108
|
+
/**
|
|
109
|
+
* Renames a table with `ALTER TABLE ... RENAME TO`; the schema of `after` is ignored.
|
|
110
|
+
*
|
|
111
|
+
* @param before - Current table.
|
|
112
|
+
* @param after - New table name.
|
|
113
|
+
* @param options - Query options.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* await queryInterface.renameTable('posts', 'articles');
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
renameTable(before: TableName, after: TableName, options?: QueryOptionsBase): Promise<void>;
|
|
121
|
+
/**
|
|
122
|
+
* Tells whether a table exists in its schema (the current schema when none is given).
|
|
123
|
+
*
|
|
124
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
125
|
+
* @param options - Query options.
|
|
126
|
+
* @returns True when the table exists.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* if (!(await queryInterface.tableExists('posts'))) {
|
|
131
|
+
* await queryInterface.createTable('posts', { title: DataTypes.STRING });
|
|
132
|
+
* }
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
tableExists(table: TableName, options?: QueryOptionsBase): Promise<boolean>;
|
|
136
|
+
/**
|
|
137
|
+
* Lists the table names of the current schema in alphabetical order.
|
|
138
|
+
*
|
|
139
|
+
* @param options - Query options.
|
|
140
|
+
* @returns Table names.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* const tables = await queryInterface.showAllTables(); // e.g. ['posts', 'users']
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
showAllTables(options?: QueryOptionsBase): Promise<string[]>;
|
|
148
|
+
/**
|
|
149
|
+
* Reads the column metadata of a table from the catalog.
|
|
150
|
+
*
|
|
151
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
152
|
+
* @param options - `schema` and query options.
|
|
153
|
+
* @returns Column descriptions keyed by column name.
|
|
154
|
+
* @throws Error when the table does not exist.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* const columns = await queryInterface.describeTable('users');
|
|
159
|
+
* const emailNullable = columns['email']?.allowNull;
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
describeTable(table: TableName, options?: QueryOptionsBase & Readonly<{
|
|
163
|
+
schema?: string;
|
|
164
|
+
}>): Promise<Record<string, ColumnDescription>>;
|
|
165
|
+
/**
|
|
166
|
+
* Lists the foreign key columns of a table with the table and column each one references.
|
|
167
|
+
*
|
|
168
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
169
|
+
* @param options - Query options.
|
|
170
|
+
* @returns Constraint name, column and referenced table/column per foreign key column.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* const references = await queryInterface.getForeignKeyReferencesForTable('posts');
|
|
175
|
+
* const targets = references.map((reference) => reference.referencedTableName);
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
getForeignKeyReferencesForTable(table: TableName, options?: QueryOptionsBase): Promise<ForeignKeyReference[]>;
|
|
179
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { PartitionKey } from '../ddl/partition-types.ts';
|
|
2
|
+
import { QueryOptionsBase } from '../model/runtime.ts';
|
|
3
|
+
/** Column description returned by `describeTable` (Sequelize v6 shape). */
|
|
4
|
+
export type ColumnDescription = Readonly<{
|
|
5
|
+
/** Upper-case SQL type, e.g. `'CHARACTER VARYING(255)'`. */
|
|
6
|
+
type: string;
|
|
7
|
+
/** Whether `NULL` is allowed. */
|
|
8
|
+
allowNull: boolean;
|
|
9
|
+
/** Default expression without casts and quotes. */
|
|
10
|
+
defaultValue: unknown;
|
|
11
|
+
/** Column comment. */
|
|
12
|
+
comment: string | null;
|
|
13
|
+
/** Enum labels. */
|
|
14
|
+
special: readonly string[];
|
|
15
|
+
/** Part of the primary key. */
|
|
16
|
+
primaryKey: boolean;
|
|
17
|
+
}>;
|
|
18
|
+
/** Foreign key column of a table. */
|
|
19
|
+
export type ForeignKeyReference = Readonly<{
|
|
20
|
+
/** Constraint name. */
|
|
21
|
+
constraintName: string;
|
|
22
|
+
/** Referencing column. */
|
|
23
|
+
columnName: string;
|
|
24
|
+
/** Referenced table. */
|
|
25
|
+
referencedTableName: string;
|
|
26
|
+
/** Referenced column. */
|
|
27
|
+
referencedColumnName: string;
|
|
28
|
+
}>;
|
|
29
|
+
/**
|
|
30
|
+
* Options of `createTable`: a table comment, the table persistence and the common query options.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* const options: CreateTableOptions = { comment: 'Blog posts', transaction };
|
|
35
|
+
* await queryInterface.createTable('posts', { title: DataTypes.STRING }, options);
|
|
36
|
+
* await queryInterface.createTable('scratch', { n: DataTypes.INTEGER }, { temporary: true, transaction });
|
|
37
|
+
* await queryInterface.createTable('events', { at: DataTypes.DATE }, { partitionBy: { strategy: 'range', columns: ['at'] } });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export type CreateTableOptions = QueryOptionsBase & Readonly<{
|
|
41
|
+
/** Table comment. */
|
|
42
|
+
comment?: string;
|
|
43
|
+
/** `CREATE UNLOGGED TABLE`: not written to the WAL, faster writes, emptied after a crash and not replicated. */
|
|
44
|
+
unlogged?: boolean;
|
|
45
|
+
/** `CREATE TEMPORARY TABLE`: lives as long as the database session (one pooled connection, so pass a `transaction` or use `pool.max = 1`), is dropped automatically and cannot have a schema. Cannot be combined with `unlogged`. */
|
|
46
|
+
temporary?: boolean;
|
|
47
|
+
/** `PARTITION BY RANGE | LIST | HASH (...)`: creates a partitioned table; add partitions with `createPartition`. PostgreSQL requires primary and unique keys to include the partition columns. */
|
|
48
|
+
partitionBy?: PartitionKey;
|
|
49
|
+
}>;
|
|
50
|
+
/**
|
|
51
|
+
* Options of `dropTable`: `cascade` plus the common query options.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const options: DropTableOptions = { cascade: true };
|
|
56
|
+
* await queryInterface.dropTable('posts', options);
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export type DropTableOptions = QueryOptionsBase & Readonly<{
|
|
60
|
+
/** `DROP TABLE ... CASCADE`. */
|
|
61
|
+
cascade?: boolean;
|
|
62
|
+
}>;
|