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,20 @@
|
|
|
1
|
+
import { AbstractDataType } from './abstract-data-type.ts';
|
|
2
|
+
/**
|
|
3
|
+
* PostGIS `GEOMETRY(type, srid)` / `GEOGRAPHY(type, srid)`; values are GeoJSON geometry objects
|
|
4
|
+
* (reading hex EWKB, writing hex EWKB), like Sequelize v6.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare class SpatialType extends AbstractDataType {
|
|
9
|
+
#private;
|
|
10
|
+
/** Converts hex EWKB into GeoJSON; other values (WKT, objects) are kept. */
|
|
11
|
+
readonly parse: (value: unknown) => unknown;
|
|
12
|
+
/** Converts a GeoJSON object into hex EWKB bound as one parameter; text is kept. */
|
|
13
|
+
readonly serialize: (value: unknown) => unknown;
|
|
14
|
+
/**
|
|
15
|
+
* @param key - `'GEOMETRY'` or `'GEOGRAPHY'` (also the SQL type name).
|
|
16
|
+
* @param shape - Geometry type, e.g. `'POINT'`.
|
|
17
|
+
* @param srid - Spatial reference id.
|
|
18
|
+
*/
|
|
19
|
+
constructor(key: 'GEOMETRY' | 'GEOGRAPHY', shape?: string, srid?: number);
|
|
20
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AbstractDataType } from './abstract-data-type.ts';
|
|
2
|
+
/**
|
|
3
|
+
* `VARCHAR(length)` (`DataTypes.STRING`).
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export declare class StringType extends AbstractDataType {
|
|
8
|
+
/**
|
|
9
|
+
* @param length - Maximum length; default 255.
|
|
10
|
+
*/
|
|
11
|
+
constructor(length?: number);
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AbstractDataType } from './abstract-data-type.ts';
|
|
2
|
+
/**
|
|
3
|
+
* `TEXT` (`DataTypes.TEXT`).
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export declare class TextType extends AbstractDataType {
|
|
8
|
+
/**
|
|
9
|
+
* @param _size - MySQL size; accepted for compatibility and ignored.
|
|
10
|
+
*/
|
|
11
|
+
constructor(_size?: 'tiny' | 'medium' | 'long');
|
|
12
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AbstractDataType } from './abstract-data-type.ts';
|
|
2
|
+
/**
|
|
3
|
+
* `TIMESTAMP WITHOUT TIME ZONE` (`DataTypes.TIMESTAMP`); values are `Date` objects whose local
|
|
4
|
+
* wall-clock time is the stored time.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare class TimestampType extends AbstractDataType {
|
|
9
|
+
/** Converts a driver string into a `Date` (local time). */
|
|
10
|
+
readonly parse: (value: unknown) => unknown;
|
|
11
|
+
/**
|
|
12
|
+
* @param fsp - Fractional seconds precision.
|
|
13
|
+
*/
|
|
14
|
+
constructor(fsp?: number);
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AbstractDataType, DataTypeInput } from './abstract-data-type.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Attribute that is not stored in the database (`DataTypes.VIRTUAL`).
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export declare class VirtualType extends AbstractDataType {
|
|
8
|
+
/** The attribute is not stored in the database. */
|
|
9
|
+
readonly isVirtual = true;
|
|
10
|
+
/**
|
|
11
|
+
* @param returnType - Type of the computed value.
|
|
12
|
+
* @param _fields - Dependency fields; accepted for compatibility and ignored.
|
|
13
|
+
*/
|
|
14
|
+
constructor(returnType?: DataTypeInput, _fields?: readonly string[]);
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats dates as local wall-clock text, the stored form of `TIMESTAMP WITHOUT TIME ZONE`.
|
|
3
|
+
*
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export declare class WallClock {
|
|
7
|
+
/**
|
|
8
|
+
* Formats a date in the process time zone.
|
|
9
|
+
*
|
|
10
|
+
* @param date - Date to format.
|
|
11
|
+
* @returns `YYYY-MM-DD HH:MM:SS.mmm`.
|
|
12
|
+
*/
|
|
13
|
+
format(date: Date): string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { AttributeDefinition } from '../model/model-definition.ts';
|
|
2
|
+
import { ColumnDefinition, ColumnSqlOptions } from './ddl-types.ts';
|
|
3
|
+
import { EnumDdl } from './enum-ddl.ts';
|
|
4
|
+
import { TableName } from './sql-literal.ts';
|
|
5
|
+
/**
|
|
6
|
+
* Column parts of DDL: the SQL type, `DEFAULT`, `REFERENCES`, column definitions and comments.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare class ColumnDdl {
|
|
11
|
+
#private;
|
|
12
|
+
/**
|
|
13
|
+
* @param enums - Enum type names.
|
|
14
|
+
*/
|
|
15
|
+
constructor(enums: EnumDdl);
|
|
16
|
+
/**
|
|
17
|
+
* Converts a normalized attribute to a column definition.
|
|
18
|
+
*
|
|
19
|
+
* @param attribute - Normalized attribute.
|
|
20
|
+
* @returns Column definition.
|
|
21
|
+
*/
|
|
22
|
+
columnOf(attribute: AttributeDefinition): ColumnDefinition;
|
|
23
|
+
/**
|
|
24
|
+
* SQL type of a column (SERIAL for auto-increment integers, enum type names).
|
|
25
|
+
*
|
|
26
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
27
|
+
* @param column - Column definition.
|
|
28
|
+
* @returns SQL type.
|
|
29
|
+
*/
|
|
30
|
+
columnType(table: TableName, column: ColumnDefinition): string;
|
|
31
|
+
/**
|
|
32
|
+
* `DEFAULT ...` clause value.
|
|
33
|
+
*
|
|
34
|
+
* @param column - Column definition.
|
|
35
|
+
* @returns SQL of the default, or `undefined` for client-side defaults.
|
|
36
|
+
*/
|
|
37
|
+
defaultSql(column: ColumnDefinition): string | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* `REFERENCES ...` clause.
|
|
40
|
+
*
|
|
41
|
+
* @param column - Column definition.
|
|
42
|
+
* @param defaultSchema - Schema of the referenced table when it has none.
|
|
43
|
+
* @returns SQL of the clause, or `undefined` without references.
|
|
44
|
+
*/
|
|
45
|
+
referencesSql(column: ColumnDefinition, defaultSchema?: string): string | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* One column of `CREATE TABLE` / `ADD COLUMN`.
|
|
48
|
+
*
|
|
49
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
50
|
+
* @param column - Column definition.
|
|
51
|
+
* @param options - `inlinePrimaryKey` and the default schema of references.
|
|
52
|
+
* @returns Column SQL.
|
|
53
|
+
*/
|
|
54
|
+
columnSql(table: TableName, column: ColumnDefinition, options?: ColumnSqlOptions): string;
|
|
55
|
+
/**
|
|
56
|
+
* `COMMENT ON COLUMN` for a column with a comment.
|
|
57
|
+
*
|
|
58
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
59
|
+
* @param column - Column name and comment.
|
|
60
|
+
* @returns The statement, or nothing without a comment.
|
|
61
|
+
*/
|
|
62
|
+
commentSql(table: TableName, column: Readonly<{
|
|
63
|
+
field: string;
|
|
64
|
+
comment?: string;
|
|
65
|
+
}>): readonly string[];
|
|
66
|
+
/**
|
|
67
|
+
* Whether a `unique` option has `nullsNotDistinct: true`.
|
|
68
|
+
*
|
|
69
|
+
* @param unique - `unique` option of a column.
|
|
70
|
+
* @returns The flag.
|
|
71
|
+
*/
|
|
72
|
+
nullsNotDistinct(unique: ColumnDefinition['unique']): boolean;
|
|
73
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ConstraintOptions } from './ddl-types.ts';
|
|
2
|
+
import { TableName } from './sql-literal.ts';
|
|
3
|
+
/**
|
|
4
|
+
* `ALTER TABLE ... ADD CONSTRAINT` statements (check, unique, primary, foreign key and exclusion constraints).
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare class ConstraintDdl {
|
|
9
|
+
#private;
|
|
10
|
+
/**
|
|
11
|
+
* `ALTER TABLE ... ADD CONSTRAINT` statement.
|
|
12
|
+
*
|
|
13
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
14
|
+
* @param options - Constraint definition.
|
|
15
|
+
* @param defaultSchema - Schema used when a table reference has none.
|
|
16
|
+
* @returns Statement.
|
|
17
|
+
* @throws Error for an unknown constraint type, a foreign key without references, an `exclude`
|
|
18
|
+
* without elements or a `notValid` on a constraint that cannot be `NOT VALID`.
|
|
19
|
+
*/
|
|
20
|
+
addConstraintSql(table: TableName, options: ConstraintOptions, defaultSchema?: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* `ALTER TABLE ... VALIDATE CONSTRAINT` statement.
|
|
23
|
+
*
|
|
24
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
25
|
+
* @param name - Constraint name.
|
|
26
|
+
* @param defaultSchema - Schema used when the table reference has none.
|
|
27
|
+
* @returns Statement.
|
|
28
|
+
*/
|
|
29
|
+
validateConstraintSql(table: TableName, name: string, defaultSchema?: string): string;
|
|
30
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { AttributeDefinition } from '../model/model-definition.ts';
|
|
2
|
+
import { ColumnDefinition, ConstraintOptions, CreateTableOptions, DeferrableValue, IndexField, IndexOptions } from './ddl-types.ts';
|
|
3
|
+
import { CreatePartitionOptions, DetachPartitionOptions } from './partition-ddl.ts';
|
|
4
|
+
import { PartitionBoundSpec } from './partition-types.ts';
|
|
5
|
+
import { TableName } from './sql-literal.ts';
|
|
6
|
+
export { Deferrable, type ColumnDefinition, type ConstraintOptions, type DeferrableValue, type ExcludeElement, type IndexField, type IndexOptions, } from './ddl-types.ts';
|
|
7
|
+
/**
|
|
8
|
+
* Generates DDL statements (tables, columns, enum types, indexes, constraints, comments,
|
|
9
|
+
* references) for PostgreSQL. Values are inlined as escaped literals.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export declare class DdlGenerator {
|
|
14
|
+
#private;
|
|
15
|
+
/**
|
|
16
|
+
* SQL of a `Deferrable` value; anything that is not one of them is rejected.
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
static deferrableSql(value: DeferrableValue): string;
|
|
21
|
+
/**
|
|
22
|
+
* Converts a normalized attribute to a column definition.
|
|
23
|
+
*
|
|
24
|
+
* @param attribute - Normalized attribute.
|
|
25
|
+
* @returns Column definition.
|
|
26
|
+
*/
|
|
27
|
+
columnOf(attribute: AttributeDefinition): ColumnDefinition;
|
|
28
|
+
/**
|
|
29
|
+
* Name of the PostgreSQL enum type of a column (`enum_<table>_<column>`, v6).
|
|
30
|
+
*
|
|
31
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
32
|
+
* @param field - Column name.
|
|
33
|
+
* @returns Unquoted enum type name.
|
|
34
|
+
*/
|
|
35
|
+
enumTypeName(table: TableName, field: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* SQL type of a column (SERIAL for auto-increment integers, enum type names).
|
|
38
|
+
*
|
|
39
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
40
|
+
* @param column - Column definition.
|
|
41
|
+
* @returns SQL type.
|
|
42
|
+
*/
|
|
43
|
+
columnType(table: TableName, column: ColumnDefinition): string;
|
|
44
|
+
/**
|
|
45
|
+
* `DEFAULT ...` clause value.
|
|
46
|
+
*
|
|
47
|
+
* @param column - Column definition.
|
|
48
|
+
* @returns SQL of the default, or `undefined` for client-side defaults.
|
|
49
|
+
*/
|
|
50
|
+
defaultSql(column: ColumnDefinition): string | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* `REFERENCES ...` clause.
|
|
53
|
+
*
|
|
54
|
+
* @param column - Column definition.
|
|
55
|
+
* @param defaultSchema - Schema of the referenced table when it has none.
|
|
56
|
+
* @returns SQL of the clause, or `undefined` without references.
|
|
57
|
+
*/
|
|
58
|
+
referencesSql(column: ColumnDefinition, defaultSchema?: string): string | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* One column of `CREATE TABLE` / `ADD COLUMN`.
|
|
61
|
+
*
|
|
62
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
63
|
+
* @param column - Column definition.
|
|
64
|
+
* @param options - `inlinePrimaryKey` and the default schema of references.
|
|
65
|
+
* @returns Column SQL.
|
|
66
|
+
*/
|
|
67
|
+
columnSql(table: TableName, column: ColumnDefinition, options?: Readonly<{
|
|
68
|
+
inlinePrimaryKey?: boolean;
|
|
69
|
+
defaultSchema?: string;
|
|
70
|
+
}>): string;
|
|
71
|
+
/**
|
|
72
|
+
* `CREATE TYPE ... AS ENUM` wrapped so an existing type is not an error (v6).
|
|
73
|
+
*
|
|
74
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
75
|
+
* @param column - Column definition.
|
|
76
|
+
* @returns Statement, or `undefined` for non-enum columns.
|
|
77
|
+
*/
|
|
78
|
+
createEnumSql(table: TableName, column: ColumnDefinition): string | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Statements creating a table: enum types, `CREATE TABLE IF NOT EXISTS`, comments.
|
|
81
|
+
*
|
|
82
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
83
|
+
* @param columns - Column definitions.
|
|
84
|
+
* @param options - Table comment, persistence (`unlogged`, `temporary`), default schema and `ifNotExists` (default true).
|
|
85
|
+
* @returns Statements in execution order.
|
|
86
|
+
*/
|
|
87
|
+
createTableSql(table: TableName, columns: readonly ColumnDefinition[], options?: CreateTableOptions): readonly string[];
|
|
88
|
+
/**
|
|
89
|
+
* `COMMENT ON COLUMN` for a column with a comment.
|
|
90
|
+
*
|
|
91
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
92
|
+
* @param column - Column name and comment.
|
|
93
|
+
* @returns The statement, or nothing without a comment.
|
|
94
|
+
*/
|
|
95
|
+
columnCommentSql(table: TableName, column: Readonly<{
|
|
96
|
+
field: string;
|
|
97
|
+
comment?: string;
|
|
98
|
+
}>): readonly string[];
|
|
99
|
+
/**
|
|
100
|
+
* `ALTER TYPE ... ADD VALUE IF NOT EXISTS` for every enum value of a column.
|
|
101
|
+
*
|
|
102
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
103
|
+
* @param column - Column definition.
|
|
104
|
+
* @returns Statements; empty for non-enum columns.
|
|
105
|
+
*/
|
|
106
|
+
addEnumValuesSql(table: TableName, column: ColumnDefinition): readonly string[];
|
|
107
|
+
/**
|
|
108
|
+
* `ALTER TABLE ... ALTER COLUMN` statements bringing a column to its definition (v6 changeColumn).
|
|
109
|
+
*
|
|
110
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
111
|
+
* @param column - Column definition.
|
|
112
|
+
* @param defaultSchema - Schema used when the table reference has none.
|
|
113
|
+
* @returns Statements in execution order.
|
|
114
|
+
*/
|
|
115
|
+
changeColumnSql(table: TableName, column: ColumnDefinition, defaultSchema?: string): readonly string[];
|
|
116
|
+
/**
|
|
117
|
+
* Default index name (v6 `Utils.nameIndex`).
|
|
118
|
+
*
|
|
119
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
120
|
+
* @param fields - Indexed fields.
|
|
121
|
+
* @returns Index name.
|
|
122
|
+
*/
|
|
123
|
+
indexName(table: TableName, fields: readonly IndexField[]): string;
|
|
124
|
+
/**
|
|
125
|
+
* `CREATE [UNIQUE] INDEX` statement.
|
|
126
|
+
*
|
|
127
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
128
|
+
* @param options - Index options.
|
|
129
|
+
* @param defaultSchema - Schema used when the table reference has none.
|
|
130
|
+
* @returns Statement.
|
|
131
|
+
* @throws Error without fields or with an invalid method / operator class.
|
|
132
|
+
*/
|
|
133
|
+
createIndexSql(table: TableName, options: IndexOptions, defaultSchema?: string): string;
|
|
134
|
+
/**
|
|
135
|
+
* `ALTER TABLE ... ADD CONSTRAINT` statement.
|
|
136
|
+
*
|
|
137
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
138
|
+
* @param options - Constraint definition.
|
|
139
|
+
* @param defaultSchema - Schema used when a table reference has none.
|
|
140
|
+
* @returns Statement.
|
|
141
|
+
* @throws Error for an unknown constraint type or a foreign key without references.
|
|
142
|
+
*/
|
|
143
|
+
addConstraintSql(table: TableName, options: ConstraintOptions, defaultSchema?: string): string;
|
|
144
|
+
/**
|
|
145
|
+
* `ALTER TABLE ... VALIDATE CONSTRAINT` statement.
|
|
146
|
+
*
|
|
147
|
+
* @param table - Table name or `{ tableName, schema }`.
|
|
148
|
+
* @param name - Constraint name.
|
|
149
|
+
* @param defaultSchema - Schema used when the table reference has none.
|
|
150
|
+
* @returns Statement.
|
|
151
|
+
*/
|
|
152
|
+
validateConstraintSql(table: TableName, name: string, defaultSchema?: string): string;
|
|
153
|
+
/**
|
|
154
|
+
* `CREATE TABLE ... PARTITION OF` statement.
|
|
155
|
+
*
|
|
156
|
+
* @param parent - Partitioned table.
|
|
157
|
+
* @param partition - New partition name.
|
|
158
|
+
* @param bound - Bounds.
|
|
159
|
+
* @param options - Sub-partitioning and `ifNotExists`.
|
|
160
|
+
* @returns Statement.
|
|
161
|
+
*/
|
|
162
|
+
createPartitionSql(parent: TableName, partition: TableName, bound: PartitionBoundSpec, options?: CreatePartitionOptions): string;
|
|
163
|
+
/**
|
|
164
|
+
* `ALTER TABLE ... ATTACH PARTITION` statement.
|
|
165
|
+
*
|
|
166
|
+
* @param parent - Partitioned table.
|
|
167
|
+
* @param partition - Existing table to attach.
|
|
168
|
+
* @param bound - Bounds.
|
|
169
|
+
* @returns Statement.
|
|
170
|
+
*/
|
|
171
|
+
attachPartitionSql(parent: TableName, partition: TableName, bound: PartitionBoundSpec): string;
|
|
172
|
+
/**
|
|
173
|
+
* `ALTER TABLE ... DETACH PARTITION` statement.
|
|
174
|
+
*
|
|
175
|
+
* @param parent - Partitioned table.
|
|
176
|
+
* @param partition - Partition to detach.
|
|
177
|
+
* @param options - `concurrently` or `finalize`.
|
|
178
|
+
* @returns Statement.
|
|
179
|
+
*/
|
|
180
|
+
detachPartitionSql(parent: TableName, partition: TableName, options?: DetachPartitionOptions): string;
|
|
181
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { DeferrableValue } from './ddl-types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Allowlists for the DDL keywords that cannot be quoted: referential actions, deferrable modes,
|
|
4
|
+
* index methods and operator classes (ADR-020).
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare class DdlGuards {
|
|
9
|
+
/**
|
|
10
|
+
* SQL of a `Deferrable` value; anything that is not one of them is rejected.
|
|
11
|
+
*
|
|
12
|
+
* @param value - Deferrable value.
|
|
13
|
+
* @returns SQL of the mode.
|
|
14
|
+
* @throws Error for anything but a `Deferrable` constant.
|
|
15
|
+
*/
|
|
16
|
+
deferrableSql(value: DeferrableValue): string;
|
|
17
|
+
/**
|
|
18
|
+
* Normalized referential action (`ON DELETE` / `ON UPDATE`).
|
|
19
|
+
*
|
|
20
|
+
* @param action - Action as given.
|
|
21
|
+
* @returns Upper-case action.
|
|
22
|
+
* @throws Error for an action outside the allowlist.
|
|
23
|
+
*/
|
|
24
|
+
action(action: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* A plain identifier word (index method, operator class), rendered unquoted.
|
|
27
|
+
*
|
|
28
|
+
* @param value - Word.
|
|
29
|
+
* @param kind - Kind named in the error.
|
|
30
|
+
* @returns The word.
|
|
31
|
+
* @throws Error for anything but `[A-Za-z_][\w]*`.
|
|
32
|
+
*/
|
|
33
|
+
word(value: string, kind: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* An operator symbol (EXCLUDE `WITH` operator), rendered unquoted.
|
|
36
|
+
*
|
|
37
|
+
* @param value - Operator such as `&&` or `=`.
|
|
38
|
+
* @returns The operator.
|
|
39
|
+
* @throws Error for anything but 1-63 operator characters, or one that opens a comment.
|
|
40
|
+
*/
|
|
41
|
+
operator(value: string): string;
|
|
42
|
+
/**
|
|
43
|
+
* A whole number rendered into DDL (sequence bounds, cache size); anything else is rejected.
|
|
44
|
+
*
|
|
45
|
+
* @param value - Number or bigint.
|
|
46
|
+
* @param kind - Kind named in the error.
|
|
47
|
+
* @returns Decimal text of the number.
|
|
48
|
+
* @throws Error for non-integers and unsafe numbers.
|
|
49
|
+
*/
|
|
50
|
+
integer(value: number | bigint, kind: string): string;
|
|
51
|
+
/**
|
|
52
|
+
* ` ON DELETE ... ON UPDATE ... <deferrable>` suffix of a foreign key; empty parts are omitted.
|
|
53
|
+
*
|
|
54
|
+
* @param onDelete - `ON DELETE` action.
|
|
55
|
+
* @param onUpdate - `ON UPDATE` action.
|
|
56
|
+
* @param deferrable - Deferrable mode.
|
|
57
|
+
* @returns SQL suffix.
|
|
58
|
+
*/
|
|
59
|
+
foreignKeySuffix(onDelete: string | undefined, onUpdate: string | undefined, deferrable: DeferrableValue | undefined): string;
|
|
60
|
+
}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { DataType } from '../data-types/data-types.ts';
|
|
2
|
+
import { AttributeDefinition } from '../model/model-definition.ts';
|
|
3
|
+
import { PartitionKey } from './partition-types.ts';
|
|
4
|
+
import { TableName } from './sql-literal.ts';
|
|
5
|
+
/** Values made by `Deferrable.SET_DEFERRED` / `SET_IMMEDIATE`; the only `SET CONSTRAINTS` statements a transaction accepts. */
|
|
6
|
+
export declare const SET_CONSTRAINTS_VALUES: WeakSet<object>;
|
|
7
|
+
/** `Deferrable.SET_DEFERRED` / `SET_IMMEDIATE`: usable bare (all constraints) or called with constraint names. */
|
|
8
|
+
export type ConstraintModeSetter = DeferrableValue & ((constraints?: readonly string[]) => DeferrableValue);
|
|
9
|
+
/** `Deferrable` setting of a foreign key or transaction (Sequelize v6 `Deferrable`). */
|
|
10
|
+
export type DeferrableValue = Readonly<{
|
|
11
|
+
/** SQL of the mode, e.g. `DEFERRABLE INITIALLY DEFERRED`. */
|
|
12
|
+
sql: string;
|
|
13
|
+
}>;
|
|
14
|
+
/**
|
|
15
|
+
* Deferrable constraint modes (Sequelize v6 `Deferrable`).
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* await queryInterface.addColumn('posts', 'userId', {
|
|
20
|
+
* type: DataTypes.INTEGER,
|
|
21
|
+
* references: { model: 'Users', key: 'id', deferrable: Deferrable.INITIALLY_DEFERRED },
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare const Deferrable: {
|
|
26
|
+
/** `DEFERRABLE INITIALLY IMMEDIATE`. */
|
|
27
|
+
readonly INITIALLY_IMMEDIATE: Readonly<Readonly<{
|
|
28
|
+
/** SQL of the mode, e.g. `DEFERRABLE INITIALLY DEFERRED`. */
|
|
29
|
+
sql: string;
|
|
30
|
+
}>>;
|
|
31
|
+
/** `DEFERRABLE INITIALLY DEFERRED`. */
|
|
32
|
+
readonly INITIALLY_DEFERRED: Readonly<Readonly<{
|
|
33
|
+
/** SQL of the mode, e.g. `DEFERRABLE INITIALLY DEFERRED`. */
|
|
34
|
+
sql: string;
|
|
35
|
+
}>>;
|
|
36
|
+
/** `NOT DEFERRABLE`. */
|
|
37
|
+
readonly NOT: Readonly<Readonly<{
|
|
38
|
+
/** SQL of the mode, e.g. `DEFERRABLE INITIALLY DEFERRED`. */
|
|
39
|
+
sql: string;
|
|
40
|
+
}>>;
|
|
41
|
+
/**
|
|
42
|
+
* `SET CONSTRAINTS ... DEFERRED`: for the `deferrable` option of `sequelize.transaction()`, defers the given constraints
|
|
43
|
+
* (all of them when used bare or called without names) for the rest of the transaction.
|
|
44
|
+
*/
|
|
45
|
+
readonly SET_DEFERRED: ConstraintModeSetter;
|
|
46
|
+
/** `SET CONSTRAINTS ... IMMEDIATE`: the counterpart of `SET_DEFERRED`. */
|
|
47
|
+
readonly SET_IMMEDIATE: ConstraintModeSetter;
|
|
48
|
+
};
|
|
49
|
+
/** Column definition as used by DDL builders. */
|
|
50
|
+
export type ColumnDefinition = Readonly<{
|
|
51
|
+
name: string;
|
|
52
|
+
field: string;
|
|
53
|
+
type: DataType;
|
|
54
|
+
allowNull: boolean;
|
|
55
|
+
primaryKey: boolean;
|
|
56
|
+
autoIncrement: boolean;
|
|
57
|
+
defaultValue: unknown;
|
|
58
|
+
unique: AttributeDefinition['unique'];
|
|
59
|
+
comment: string | undefined;
|
|
60
|
+
references: AttributeDefinition['references'];
|
|
61
|
+
onDelete: string | undefined;
|
|
62
|
+
onUpdate: string | undefined;
|
|
63
|
+
identity: 'always' | 'byDefault' | undefined;
|
|
64
|
+
generated: AttributeDefinition['generated'];
|
|
65
|
+
}>;
|
|
66
|
+
/** Modifiers shared by every index element. */
|
|
67
|
+
type IndexElementModifiers = Readonly<{
|
|
68
|
+
/** `ASC` / `DESC`. */
|
|
69
|
+
order?: 'ASC' | 'DESC';
|
|
70
|
+
/** `NULLS FIRST` / `NULLS LAST`. PostgreSQL extension. */
|
|
71
|
+
nulls?: 'FIRST' | 'LAST';
|
|
72
|
+
/** Collation name (quoted identifier). */
|
|
73
|
+
collate?: string;
|
|
74
|
+
/** Operator class, e.g. `'jsonb_path_ops'`. */
|
|
75
|
+
operator?: string;
|
|
76
|
+
}>;
|
|
77
|
+
/**
|
|
78
|
+
* Index field: a column name, `{ name, order, nulls, collate, operator }` or an expression
|
|
79
|
+
* `{ expression, ... }`. The `expression` is trusted SQL (not escaped): never build it from user
|
|
80
|
+
* input. An index with an expression field needs an explicit `name`.
|
|
81
|
+
*/
|
|
82
|
+
export type IndexField = string | (IndexElementModifiers & Readonly<{
|
|
83
|
+
/** Column name. */
|
|
84
|
+
name: string;
|
|
85
|
+
/** Not used for a column field. */
|
|
86
|
+
expression?: undefined;
|
|
87
|
+
}>) | (IndexElementModifiers & Readonly<{
|
|
88
|
+
/** Trusted SQL expression, wrapped in parentheses. */
|
|
89
|
+
expression: string;
|
|
90
|
+
/** Not used for an expression field. */
|
|
91
|
+
name?: undefined;
|
|
92
|
+
}>);
|
|
93
|
+
/**
|
|
94
|
+
* Options of `addIndex` and model `indexes` (Sequelize v6 `IndexesOptions`).
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* const options: IndexOptions = {
|
|
99
|
+
* fields: ['email'],
|
|
100
|
+
* unique: true,
|
|
101
|
+
* where: { active: true },
|
|
102
|
+
* using: 'btree',
|
|
103
|
+
* };
|
|
104
|
+
* await queryInterface.addIndex('users', options);
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export type IndexOptions = Readonly<{
|
|
108
|
+
/** Indexed columns. */
|
|
109
|
+
fields?: readonly IndexField[];
|
|
110
|
+
/** Index name; default `underscore(<table>_<fields>)`. Required when a field is an expression. */
|
|
111
|
+
name?: string;
|
|
112
|
+
/** Unique index. */
|
|
113
|
+
unique?: boolean;
|
|
114
|
+
/** `NULLS NOT DISTINCT` for unique indexes. PostgreSQL extension. */
|
|
115
|
+
nullsNotDistinct?: boolean;
|
|
116
|
+
/** Index method: `btree`, `hash`, `gist`, `gin`, `brin`, ... */
|
|
117
|
+
using?: string;
|
|
118
|
+
/** Default operator class for all fields. */
|
|
119
|
+
operator?: string;
|
|
120
|
+
/** Partial index predicate. */
|
|
121
|
+
where?: unknown;
|
|
122
|
+
/** `CREATE INDEX CONCURRENTLY`. */
|
|
123
|
+
concurrently?: boolean;
|
|
124
|
+
/** Covering index columns (`INCLUDE (...)`). */
|
|
125
|
+
include?: readonly string[];
|
|
126
|
+
/** `IF NOT EXISTS`. */
|
|
127
|
+
ifNotExists?: boolean;
|
|
128
|
+
}>;
|
|
129
|
+
/**
|
|
130
|
+
* One element of an `exclude` constraint: an index field plus the operator it is compared with.
|
|
131
|
+
* The `expression`, when used, is trusted SQL.
|
|
132
|
+
*/
|
|
133
|
+
export type ExcludeElement = Exclude<IndexField, string> & Readonly<{
|
|
134
|
+
/** Exclusion operator, e.g. `'&&'` or `'='` (operator characters only). */
|
|
135
|
+
with: string;
|
|
136
|
+
}>;
|
|
137
|
+
/**
|
|
138
|
+
* Options of `addConstraint` (Sequelize v6).
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```ts
|
|
142
|
+
* const options: ConstraintOptions = {
|
|
143
|
+
* type: 'foreign key',
|
|
144
|
+
* fields: ['userId'],
|
|
145
|
+
* name: 'posts_user_fk',
|
|
146
|
+
* references: { table: 'users', field: 'id' },
|
|
147
|
+
* onDelete: 'CASCADE',
|
|
148
|
+
* };
|
|
149
|
+
* await queryInterface.addConstraint('posts', options);
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
export type ConstraintOptions = Readonly<{
|
|
153
|
+
/** Constraint kind. */
|
|
154
|
+
type: 'check' | 'unique' | 'primary key' | 'foreign key' | 'exclude' | 'CHECK' | 'UNIQUE' | 'PRIMARY KEY' | 'FOREIGN KEY' | 'EXCLUDE';
|
|
155
|
+
/** Constrained columns. Not used by `exclude` (see `exclude`). */
|
|
156
|
+
fields?: readonly string[];
|
|
157
|
+
/** Constraint name. */
|
|
158
|
+
name?: string;
|
|
159
|
+
/** Check condition, or the partial predicate of an `exclude` constraint (where object). */
|
|
160
|
+
where?: unknown;
|
|
161
|
+
/** Foreign key target. */
|
|
162
|
+
references?: Readonly<{
|
|
163
|
+
/** Referenced table. */ table: TableName;
|
|
164
|
+
/** Referenced column. */ field: string;
|
|
165
|
+
/** Referenced columns, replacing `field` (needed with `period`). */ fields?: readonly string[];
|
|
166
|
+
}>;
|
|
167
|
+
/** `ON DELETE` action. */
|
|
168
|
+
onDelete?: string;
|
|
169
|
+
/** `ON UPDATE` action. */
|
|
170
|
+
onUpdate?: string;
|
|
171
|
+
/** Deferrable mode. */
|
|
172
|
+
deferrable?: DeferrableValue;
|
|
173
|
+
/** `NULLS NOT DISTINCT` for unique constraints. PostgreSQL extension. */
|
|
174
|
+
nullsNotDistinct?: boolean;
|
|
175
|
+
/** Exclusion elements: `{ column | expression, with }`. Required by `exclude`. PostgreSQL extension. */
|
|
176
|
+
exclude?: readonly ExcludeElement[];
|
|
177
|
+
/** Index method of an `exclude` constraint (`gist`, `spgist`, `btree`, ...). */
|
|
178
|
+
using?: string;
|
|
179
|
+
/** Covering columns of an `exclude` constraint (`INCLUDE (...)`). */
|
|
180
|
+
include?: readonly string[];
|
|
181
|
+
/** Last field of a `unique` / `primary key` constraint is `WITHOUT OVERLAPS` (temporal key, PostgreSQL 18). */
|
|
182
|
+
withoutOverlaps?: boolean;
|
|
183
|
+
/** Last field (and last referenced field) of a foreign key is `PERIOD` (PostgreSQL 18). */
|
|
184
|
+
period?: boolean;
|
|
185
|
+
/** `false` adds `NOT ENFORCED` (check and foreign key, PostgreSQL 18). */
|
|
186
|
+
enforced?: boolean;
|
|
187
|
+
/** Adds `NOT VALID` (check and foreign key only); run `validateConstraint` later. PostgreSQL extension. */
|
|
188
|
+
notValid?: boolean;
|
|
189
|
+
}>;
|
|
190
|
+
/** Options of a column inside `CREATE TABLE` / `ADD COLUMN`. */
|
|
191
|
+
export type ColumnSqlOptions = Readonly<{
|
|
192
|
+
inlinePrimaryKey?: boolean;
|
|
193
|
+
defaultSchema?: string;
|
|
194
|
+
}>;
|
|
195
|
+
/** Options of `CREATE TABLE`. */
|
|
196
|
+
export type CreateTableOptions = Readonly<{
|
|
197
|
+
comment?: string;
|
|
198
|
+
unlogged?: boolean;
|
|
199
|
+
temporary?: boolean;
|
|
200
|
+
defaultSchema?: string;
|
|
201
|
+
ifNotExists?: boolean;
|
|
202
|
+
partitionBy?: PartitionKey;
|
|
203
|
+
}>;
|
|
204
|
+
export {};
|