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,85 @@
|
|
|
1
|
+
import { ExprNode, SetItem, TableRef } from '../sql/ast.ts';
|
|
2
|
+
import { WhereCompiler } from '../where/where.ts';
|
|
3
|
+
import { AttributeDefinition, ModelDefinition } from './model-definition.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Maps model attributes to SQL pieces shared by the statement builders: table reference, where
|
|
6
|
+
* compiler resolving attribute names, stored columns, bound column values, SET items, RETURNING
|
|
7
|
+
* lists, primary-key and paranoid conditions.
|
|
8
|
+
*/
|
|
9
|
+
export declare class AttributeColumns {
|
|
10
|
+
/**
|
|
11
|
+
* Table reference of the model.
|
|
12
|
+
*
|
|
13
|
+
* @param definition - Model definition.
|
|
14
|
+
* @param alias - Table alias.
|
|
15
|
+
* @returns Table reference.
|
|
16
|
+
*/
|
|
17
|
+
table(definition: ModelDefinition, alias?: string): TableRef;
|
|
18
|
+
/**
|
|
19
|
+
* Where compiler resolving attribute names of the model.
|
|
20
|
+
*
|
|
21
|
+
* @param definition - Model definition.
|
|
22
|
+
* @param alias - Table alias used to qualify columns.
|
|
23
|
+
* @param inAsAnyThreshold - Lists at least this long compile to `= ANY($n)`.
|
|
24
|
+
* @returns Where compiler.
|
|
25
|
+
*/
|
|
26
|
+
whereCompiler(definition: ModelDefinition, alias: string | undefined, inAsAnyThreshold?: number): WhereCompiler;
|
|
27
|
+
/**
|
|
28
|
+
* Compiles a `where` / `having` option; empty conditions give `undefined`.
|
|
29
|
+
*
|
|
30
|
+
* @param where - Condition.
|
|
31
|
+
* @param ctx - Where compiler of the model.
|
|
32
|
+
* @returns Expression or `undefined`.
|
|
33
|
+
*/
|
|
34
|
+
where(where: unknown, ctx: WhereCompiler): ExprNode | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Attributes stored in the table (not virtual).
|
|
37
|
+
*
|
|
38
|
+
* @param definition - Model definition.
|
|
39
|
+
* @returns Stored attributes in definition order.
|
|
40
|
+
*/
|
|
41
|
+
stored(definition: ModelDefinition): readonly AttributeDefinition[];
|
|
42
|
+
/**
|
|
43
|
+
* Column value for INSERT / UPDATE: bound parameter, expression, or generated default.
|
|
44
|
+
*
|
|
45
|
+
* @param attribute - Attribute of the column (`undefined` for unknown names).
|
|
46
|
+
* @param value - Value or expression.
|
|
47
|
+
* @param ctx - Where compiler of the model.
|
|
48
|
+
* @returns Value expression.
|
|
49
|
+
*/
|
|
50
|
+
value(attribute: AttributeDefinition | undefined, value: unknown, ctx: WhereCompiler): ExprNode;
|
|
51
|
+
/**
|
|
52
|
+
* SET items from attribute-keyed values (`undefined` values and generated columns are skipped).
|
|
53
|
+
*
|
|
54
|
+
* @param definition - Model definition.
|
|
55
|
+
* @param values - Values by attribute name.
|
|
56
|
+
* @param ctx - Where compiler used for expressions.
|
|
57
|
+
* @returns SET items.
|
|
58
|
+
*/
|
|
59
|
+
setItems(definition: ModelDefinition, values: Readonly<Record<string, unknown>>, ctx?: WhereCompiler): readonly SetItem[];
|
|
60
|
+
/**
|
|
61
|
+
* RETURNING list: all stored columns aliased to attribute names.
|
|
62
|
+
*
|
|
63
|
+
* @param definition - Model definition.
|
|
64
|
+
* @param alias - Table alias.
|
|
65
|
+
* @returns Column list.
|
|
66
|
+
*/
|
|
67
|
+
returningAll(definition: ModelDefinition, alias?: string): readonly ExprNode[];
|
|
68
|
+
/**
|
|
69
|
+
* Primary-key where object for an instance.
|
|
70
|
+
*
|
|
71
|
+
* @param definition - Model definition.
|
|
72
|
+
* @param values - Instance values.
|
|
73
|
+
* @returns `{ [primaryKey]: value }`.
|
|
74
|
+
*/
|
|
75
|
+
primaryKeyWhere(definition: ModelDefinition, values: Readonly<Record<string, unknown>>): Readonly<Record<string, unknown>>;
|
|
76
|
+
/**
|
|
77
|
+
* Adds `deletedAt IS NULL` to `where` for paranoid models unless `paranoid: false`.
|
|
78
|
+
*
|
|
79
|
+
* @param definition - Model definition.
|
|
80
|
+
* @param where - Condition.
|
|
81
|
+
* @param paranoid - `paranoid` option.
|
|
82
|
+
* @returns Condition.
|
|
83
|
+
*/
|
|
84
|
+
paranoid(definition: ModelDefinition, where: unknown, paranoid: boolean | undefined): unknown;
|
|
85
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { DataTypeInput } from '../data-types/data-types.ts';
|
|
2
|
+
import { AttributeDefinition, AttributeOptions } from './attribute-options.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Normalizes declared attributes (`Model.init` input) into attribute definitions.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare class AttributeNormalizer {
|
|
9
|
+
#private;
|
|
10
|
+
/**
|
|
11
|
+
* Normalizes one attribute: column name, data type instance, `allowNull` default.
|
|
12
|
+
*
|
|
13
|
+
* @param name - Attribute name.
|
|
14
|
+
* @param input - Data type or column options.
|
|
15
|
+
* @param underscored - Derive the column name in snake case.
|
|
16
|
+
* @returns Frozen attribute definition.
|
|
17
|
+
*/
|
|
18
|
+
attribute(name: string, input: DataTypeInput | AttributeOptions, underscored: boolean): AttributeDefinition;
|
|
19
|
+
/**
|
|
20
|
+
* Whether a declared attribute is given as column options rather than as a bare type.
|
|
21
|
+
*
|
|
22
|
+
* @param value - Declared attribute.
|
|
23
|
+
* @returns True for column options.
|
|
24
|
+
*/
|
|
25
|
+
isOptions(value: DataTypeInput | AttributeOptions): value is AttributeOptions;
|
|
26
|
+
/**
|
|
27
|
+
* Snake-cases a name when `underscored` is set.
|
|
28
|
+
*
|
|
29
|
+
* @param name - Name.
|
|
30
|
+
* @param underscored - `underscored` option.
|
|
31
|
+
* @returns The name.
|
|
32
|
+
*/
|
|
33
|
+
underscoredIf(name: string, underscored: boolean): string;
|
|
34
|
+
/**
|
|
35
|
+
* Unique keys from attribute `unique` options.
|
|
36
|
+
*
|
|
37
|
+
* @param tableName - Table name (prefix of default key names).
|
|
38
|
+
* @param list - Normalized attributes in definition order.
|
|
39
|
+
* @returns Key name → attribute names (in definition order).
|
|
40
|
+
*/
|
|
41
|
+
uniqueKeys(tableName: string, list: readonly AttributeDefinition[]): ReadonlyMap<string, readonly string[]>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { DataType, DataTypeInput } from '../data-types/data-types.ts';
|
|
2
|
+
import { DeferrableValue } from '../ddl/ddl-generator.ts';
|
|
3
|
+
import { AttributeValidateOptions } from '../validation/types.ts';
|
|
4
|
+
/** Definition of a generated column. */
|
|
5
|
+
export type GeneratedColumn = Readonly<{
|
|
6
|
+
/** Expression computing the value, e.g. `literal('"price" * "qty"')`. */
|
|
7
|
+
as: unknown;
|
|
8
|
+
/** `true` for `STORED`, `false` for `VIRTUAL` (PostgreSQL 18+ only).
|
|
9
|
+
* @defaultValue true */
|
|
10
|
+
stored?: boolean;
|
|
11
|
+
}>;
|
|
12
|
+
/**
|
|
13
|
+
* Named unique constraint of an attribute.
|
|
14
|
+
*
|
|
15
|
+
* Give several attributes the same `name` to form one composite unique key.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const email: UniqueOptions = { name: 'users_email_unique', msg: 'Email already taken', nullsNotDistinct: true };
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export type UniqueOptions = Readonly<{
|
|
23
|
+
/** Constraint name; attributes with the same name form a composite unique key. */
|
|
24
|
+
name?: string;
|
|
25
|
+
/** Validation message used when the constraint is violated. */
|
|
26
|
+
msg?: string;
|
|
27
|
+
/** `UNIQUE NULLS NOT DISTINCT`: treat NULLs as equal. PostgreSQL extension. */
|
|
28
|
+
nullsNotDistinct?: boolean;
|
|
29
|
+
}>;
|
|
30
|
+
/** Table referenced by a foreign key. */
|
|
31
|
+
export type ReferencedTable = Readonly<{
|
|
32
|
+
/** Referenced table name. */
|
|
33
|
+
tableName: string;
|
|
34
|
+
/** Referenced table schema. */
|
|
35
|
+
schema?: string;
|
|
36
|
+
}>;
|
|
37
|
+
/**
|
|
38
|
+
* Foreign key target of an attribute.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* const ref: ReferenceOptions = { model: 'Users', key: 'id', deferrable: Deferrable.INITIALLY_DEFERRED };
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export type ReferenceOptions = Readonly<{
|
|
46
|
+
/** Referenced model name, or an object with the referenced table name. */
|
|
47
|
+
model: string | ReferencedTable;
|
|
48
|
+
/** Referenced column. Default: primary key. */
|
|
49
|
+
key?: string;
|
|
50
|
+
/** Deferrable mode of the foreign key constraint. */
|
|
51
|
+
deferrable?: DeferrableValue;
|
|
52
|
+
}>;
|
|
53
|
+
/**
|
|
54
|
+
* Column definition of a model attribute (Sequelize v6 `ModelAttributeColumnOptions`).
|
|
55
|
+
*
|
|
56
|
+
* `sync()` turns these into `CREATE TABLE` column definitions; validators run before INSERT / UPDATE.
|
|
57
|
+
*
|
|
58
|
+
* @see {@link Model.init}
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* const attr: AttributeOptions = {
|
|
63
|
+
* type: DataTypes.STRING,
|
|
64
|
+
* allowNull: false,
|
|
65
|
+
* unique: true,
|
|
66
|
+
* validate: { isEmail: true },
|
|
67
|
+
* };
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export type AttributeOptions = Readonly<{
|
|
71
|
+
/** Column type; a `DataTypes` entry or its factory call. */
|
|
72
|
+
type: DataTypeInput;
|
|
73
|
+
/** Whether `NULL` is allowed.
|
|
74
|
+
* @defaultValue true */
|
|
75
|
+
allowNull?: boolean;
|
|
76
|
+
/** Default value: a literal value, an expression, or `DataTypes.NOW` / `DataTypes.UUIDV4`. */
|
|
77
|
+
defaultValue?: unknown;
|
|
78
|
+
/** Part of the primary key. Without any primary key, an `id` attribute is added.
|
|
79
|
+
* @defaultValue false */
|
|
80
|
+
primaryKey?: boolean;
|
|
81
|
+
/** Generated by a sequence (`SERIAL`, or an identity column with `identity`).
|
|
82
|
+
* @defaultValue false */
|
|
83
|
+
autoIncrement?: boolean;
|
|
84
|
+
/** `GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY` instead of `SERIAL`. PostgreSQL extension. */
|
|
85
|
+
identity?: 'always' | 'byDefault';
|
|
86
|
+
/** Generated column `GENERATED ALWAYS AS (expression) STORED`; never written by INSERT/UPDATE. PostgreSQL extension. */
|
|
87
|
+
generated?: GeneratedColumn;
|
|
88
|
+
/** Column name, if different from the attribute name. Default: the attribute name. */
|
|
89
|
+
field?: string;
|
|
90
|
+
/** Unique constraint: `true`, a constraint name, or `{ name, msg }`. */
|
|
91
|
+
unique?: boolean | string | UniqueOptions;
|
|
92
|
+
/** Column comment (`COMMENT ON COLUMN`) written by `sync()`. */
|
|
93
|
+
comment?: string;
|
|
94
|
+
/** Foreign key reference. */
|
|
95
|
+
references?: string | ReferenceOptions;
|
|
96
|
+
/** `ON DELETE` action of the foreign key, e.g. `'CASCADE'`; needs `references`. */
|
|
97
|
+
onDelete?: string;
|
|
98
|
+
/** `ON UPDATE` action of the foreign key, e.g. `'CASCADE'`; needs `references`. */
|
|
99
|
+
onUpdate?: string;
|
|
100
|
+
/** Validators run before INSERT / UPDATE. */
|
|
101
|
+
validate?: AttributeValidateOptions;
|
|
102
|
+
/** Custom getter, called with the model instance as `this`. */
|
|
103
|
+
get?: (this: never) => unknown;
|
|
104
|
+
/** Custom setter, called with the model instance as `this`. */
|
|
105
|
+
set?: (this: never, value: never) => void;
|
|
106
|
+
}>;
|
|
107
|
+
/** Attributes passed to `Model.init` / `sequelize.define`: a type or full column options per attribute. */
|
|
108
|
+
export type ModelAttributes = Readonly<Record<string, DataTypeInput | AttributeOptions>>;
|
|
109
|
+
/** Normalized attribute (exposed as `Model.rawAttributes[name]`). */
|
|
110
|
+
export type AttributeDefinition = Readonly<Omit<AttributeOptions, 'type' | 'field'> & {
|
|
111
|
+
/** Attribute name. */
|
|
112
|
+
fieldName: string;
|
|
113
|
+
/** Column name. */
|
|
114
|
+
field: string;
|
|
115
|
+
/** Normalized column type. */
|
|
116
|
+
type: DataType;
|
|
117
|
+
/** Whether `NULL` is allowed. */
|
|
118
|
+
allowNull: boolean;
|
|
119
|
+
/** Added automatically (`id`, timestamps). */
|
|
120
|
+
_autoGenerated?: boolean;
|
|
121
|
+
}>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CompiledQuery, SqlCompiler } from '../sql/compile.ts';
|
|
2
|
+
import { InsertQueryBuilder } from './insert-query-builder.ts';
|
|
3
|
+
import { ModelDefinition } from './model-definition.ts';
|
|
4
|
+
import { OnConflictBuilder } from './on-conflict-builder.ts';
|
|
5
|
+
import { BulkCreateOptions } from './options.ts';
|
|
6
|
+
import { UnnestInsertBuilder } from './unnest-insert-builder.ts';
|
|
7
|
+
/** Builds the INSERT of `Model.bulkCreate`: multi-row `VALUES`, or `unnest` arrays with `unnest: true`. */
|
|
8
|
+
export declare class BulkInsertBuilder {
|
|
9
|
+
#private;
|
|
10
|
+
/**
|
|
11
|
+
* @param inserts - VALUES INSERT builder.
|
|
12
|
+
* @param unnests - `unnest` INSERT builder.
|
|
13
|
+
* @param conflicts - Sequelize v6 conflict options builder.
|
|
14
|
+
* @param compiler - SQL compiler.
|
|
15
|
+
*/
|
|
16
|
+
constructor(inserts: InsertQueryBuilder, unnests: UnnestInsertBuilder, conflicts: OnConflictBuilder, compiler: SqlCompiler);
|
|
17
|
+
/**
|
|
18
|
+
* @param definition - Model definition.
|
|
19
|
+
* @param rows - Values by attribute name.
|
|
20
|
+
* @param options - Bulk create options.
|
|
21
|
+
* @returns The compiled INSERT.
|
|
22
|
+
*/
|
|
23
|
+
build(definition: ModelDefinition, rows: readonly Readonly<Record<string, unknown>>[], options: BulkCreateOptions): CompiledQuery;
|
|
24
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { IncludeOption } from '../associations/include.ts';
|
|
2
|
+
import { JoinSources } from './join-source-builder.ts';
|
|
3
|
+
import { OnConflictOptions } from './on-conflict-builder.ts';
|
|
4
|
+
import { Values } from './options.ts';
|
|
5
|
+
import { QueryOptionsBase } from './runtime.ts';
|
|
6
|
+
import { WhereOptions } from './types.ts';
|
|
7
|
+
import { SaveOptions } from './write-options.ts';
|
|
8
|
+
/**
|
|
9
|
+
* Options of `bulkCreate`.
|
|
10
|
+
*
|
|
11
|
+
* Extends {@link SaveOptions}. Rows are inserted with one `INSERT` unless `individualHooks` or `include` is set. Validation is off by default (unlike `create`).
|
|
12
|
+
*
|
|
13
|
+
* @see {@link Model.bulkCreate}
|
|
14
|
+
* @see {@link OnConflictOptions}
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const rows = [{ email: 'a@example.com', name: 'Ann' }];
|
|
19
|
+
* await User.bulkCreate(rows, {
|
|
20
|
+
* updateOnDuplicate: ['name'],
|
|
21
|
+
* conflictAttributes: ['email'],
|
|
22
|
+
* transaction,
|
|
23
|
+
* });
|
|
24
|
+
* const opts: BulkCreateOptions<User> = { ignoreDuplicates: true };
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export type BulkCreateOptions<T = Values> = SaveOptions<T> & Readonly<{
|
|
28
|
+
/**
|
|
29
|
+
* Insert with one array parameter per column (`INSERT … SELECT * FROM unnest($1::type[], …)`) instead of
|
|
30
|
+
* one parameter per cell, so batches are not capped by PostgreSQL's 65535 parameters. Every row must
|
|
31
|
+
* provide every column; `ARRAY` columns and conflict options are not supported. PostgreSQL extension.
|
|
32
|
+
* @defaultValue false */
|
|
33
|
+
unnest?: boolean;
|
|
34
|
+
/** Add `ON CONFLICT DO NOTHING`, skipping rows that violate a unique constraint.
|
|
35
|
+
* @defaultValue false */
|
|
36
|
+
ignoreDuplicates?: boolean;
|
|
37
|
+
/** Run per-instance `create` hooks (rows are then inserted one by one, like v6).
|
|
38
|
+
* @defaultValue false */
|
|
39
|
+
individualHooks?: boolean;
|
|
40
|
+
/** Create associated rows from nested values (rows are inserted one by one). */
|
|
41
|
+
include?: IncludeOption;
|
|
42
|
+
/** Attributes updated from the proposed row on conflict (`DO UPDATE SET a = EXCLUDED.a`). */
|
|
43
|
+
updateOnDuplicate?: readonly (keyof T & string)[];
|
|
44
|
+
/** Conflict target attributes for `updateOnDuplicate`. Default: first unique key, else primary key. */
|
|
45
|
+
conflictAttributes?: readonly (keyof T & string)[];
|
|
46
|
+
/** Predicate of a partial unique index used as conflict target. */
|
|
47
|
+
conflictWhere?: WhereOptions<T>;
|
|
48
|
+
/** Advanced `ON CONFLICT` handling; cannot be combined with the options above. PostgreSQL extension. */
|
|
49
|
+
onConflict?: OnConflictOptions<T>;
|
|
50
|
+
}>;
|
|
51
|
+
/**
|
|
52
|
+
* Hook switches shared by bulk `update`, `destroy` and `restore`.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* const opts: BulkHookOptions = { hooks: true, individualHooks: true };
|
|
57
|
+
* await User.destroy({ where: { active: false }, ...opts });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export type BulkHookOptions = Readonly<{
|
|
61
|
+
/** Run the bulk hooks (`beforeBulkUpdate`, `beforeBulkDestroy`, ...).
|
|
62
|
+
* @defaultValue true */
|
|
63
|
+
hooks?: boolean;
|
|
64
|
+
/** Also run per-instance hooks; rows are loaded first, which costs an extra query.
|
|
65
|
+
* @defaultValue false */
|
|
66
|
+
individualHooks?: boolean;
|
|
67
|
+
}>;
|
|
68
|
+
/**
|
|
69
|
+
* Options of static `update`.
|
|
70
|
+
*
|
|
71
|
+
* Extends {@link BulkHookOptions}. Updates `updatedAt` unless `silent`.
|
|
72
|
+
*
|
|
73
|
+
* @see {@link Model.update}
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* const [count] = await User.update(
|
|
78
|
+
* { active: false },
|
|
79
|
+
* { where: { lastLogin: { [Op.lt]: new Date('2020-01-01') } }, transaction },
|
|
80
|
+
* );
|
|
81
|
+
* const opts: UpdateOptions<Task> = { where: { done: false }, returning: true };
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export type UpdateOptions<T = Values> = QueryOptionsBase & Readonly<{
|
|
85
|
+
/** Rows to update. */
|
|
86
|
+
where: WhereOptions<T>;
|
|
87
|
+
/** Attributes to update; others are ignored. */
|
|
88
|
+
fields?: readonly (keyof T & string)[];
|
|
89
|
+
/** Do not update `updatedAt`.
|
|
90
|
+
* @defaultValue false */
|
|
91
|
+
silent?: boolean;
|
|
92
|
+
/** Return updated rows as the second element of the result. */
|
|
93
|
+
returning?: boolean;
|
|
94
|
+
/** With `returning`: expose values before the update as `instance.oldValues`. PostgreSQL 18+. */
|
|
95
|
+
returningOld?: boolean;
|
|
96
|
+
/** Validate the new values.
|
|
97
|
+
* @defaultValue true */
|
|
98
|
+
validate?: boolean;
|
|
99
|
+
/** For paranoid models: `false` also updates soft-deleted rows.
|
|
100
|
+
* @defaultValue true */
|
|
101
|
+
paranoid?: boolean;
|
|
102
|
+
/** Extra relations (`UPDATE ... FROM`), keyed by alias; reference them with `col('alias.attr')`. PostgreSQL extension. */
|
|
103
|
+
from?: JoinSources;
|
|
104
|
+
}> & BulkHookOptions;
|
|
105
|
+
/**
|
|
106
|
+
* Options of static `destroy`.
|
|
107
|
+
*
|
|
108
|
+
* Extends {@link BulkHookOptions}. Paranoid models are soft-deleted (`deletedAt` set) unless `force`.
|
|
109
|
+
*
|
|
110
|
+
* @see {@link Model.destroy}
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* await Post.destroy({ where: { draft: true }, force: true });
|
|
115
|
+
* const opts: DestroyOptions<Task> = { truncate: true, cascade: true, restartIdentity: true };
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export type DestroyOptions<T = Values> = QueryOptionsBase & Readonly<{
|
|
119
|
+
/** Rows to delete. */
|
|
120
|
+
where?: WhereOptions<T>;
|
|
121
|
+
/** Delete at most this many rows. */
|
|
122
|
+
limit?: number;
|
|
123
|
+
/** Use `TRUNCATE` instead of `DELETE`.
|
|
124
|
+
* @defaultValue false */
|
|
125
|
+
truncate?: boolean;
|
|
126
|
+
/** With `truncate`: add `CASCADE`.
|
|
127
|
+
* @defaultValue false */
|
|
128
|
+
cascade?: boolean;
|
|
129
|
+
/** With `truncate`: add `RESTART IDENTITY`.
|
|
130
|
+
* @defaultValue false */
|
|
131
|
+
restartIdentity?: boolean;
|
|
132
|
+
/** Return deleted rows instead of their count (`DELETE ... RETURNING`). PostgreSQL extension. */
|
|
133
|
+
returning?: boolean;
|
|
134
|
+
/** For paranoid models: delete rows instead of setting `deletedAt`.
|
|
135
|
+
* @defaultValue false */
|
|
136
|
+
force?: boolean;
|
|
137
|
+
/** Extra relations (`DELETE ... USING`), keyed by alias. PostgreSQL extension. */
|
|
138
|
+
using?: JoinSources;
|
|
139
|
+
}> & BulkHookOptions;
|
|
140
|
+
/**
|
|
141
|
+
* Options of static `restore`, which clears `deletedAt` of soft-deleted rows of paranoid models.
|
|
142
|
+
*
|
|
143
|
+
* @see {@link Model.restore}
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* await Post.restore({ where: { authorId: 1 }, transaction });
|
|
148
|
+
* const opts: RestoreOptions<Post> = { hooks: false };
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
export type RestoreOptions<T = Values> = QueryOptionsBase & Readonly<{
|
|
152
|
+
/** Rows to restore; all soft-deleted rows when omitted. */
|
|
153
|
+
where?: WhereOptions<T>;
|
|
154
|
+
}> & BulkHookOptions;
|
|
155
|
+
/**
|
|
156
|
+
* Options of instance `destroy`.
|
|
157
|
+
*
|
|
158
|
+
* @see {@link Model.destroy}
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```ts
|
|
162
|
+
* await post.destroy({ force: true, transaction });
|
|
163
|
+
* const opts: InstanceDestroyOptions = { hooks: false };
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
export type InstanceDestroyOptions = QueryOptionsBase & Readonly<{
|
|
167
|
+
/** For paranoid models: delete the row instead of setting `deletedAt`.
|
|
168
|
+
* @defaultValue false */
|
|
169
|
+
force?: boolean;
|
|
170
|
+
/** Run `beforeDestroy` / `afterDestroy` hooks.
|
|
171
|
+
* @defaultValue true */
|
|
172
|
+
hooks?: boolean;
|
|
173
|
+
}>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { FindOptions } from './find-options.ts';
|
|
2
|
+
import { Values } from './options.ts';
|
|
3
|
+
import { QueryOptionsBase } from './runtime.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Options of `Model.copyFrom`, which loads rows with `COPY ... FROM STDIN`. PostgreSQL extension.
|
|
6
|
+
*
|
|
7
|
+
* @see {@link Model.copyFrom}
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const opts: CopyFromOptions<User> = { columns: ['name', 'email'], transaction };
|
|
12
|
+
* await User.copyFrom([{ name: 'Ann', email: 'a@example.com' }], opts);
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export type CopyFromOptions<T = Values> = QueryOptionsBase & Readonly<{
|
|
16
|
+
/** Attributes to copy, in row order; default: keys of the first row of an array source. */
|
|
17
|
+
columns?: readonly (keyof T & string)[];
|
|
18
|
+
}>;
|
|
19
|
+
/**
|
|
20
|
+
* Output format options of `Model.copyTo` (`COPY ... TO STDOUT`). PostgreSQL extension.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* const format: CopyToFormatOptions = { format: 'csv', header: true, delimiter: ';', nullString: '' };
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export type CopyToFormatOptions = Readonly<{
|
|
28
|
+
/** Output format.
|
|
29
|
+
* @defaultValue 'text' */
|
|
30
|
+
format?: 'text' | 'csv' | 'binary';
|
|
31
|
+
/** Emit a header line (csv).
|
|
32
|
+
* @defaultValue false */
|
|
33
|
+
header?: boolean;
|
|
34
|
+
/** Single-character field delimiter. Default: tab for `text`, comma for `csv`. */
|
|
35
|
+
delimiter?: string;
|
|
36
|
+
/** String written for NULL values. Default: `\N` for `text`, empty for `csv`. */
|
|
37
|
+
nullString?: string;
|
|
38
|
+
/** Single-character quote (csv). Default: `"`. */
|
|
39
|
+
quote?: string;
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Options of `Model.copyTo`: a finder query that selects the exported rows plus the output format.
|
|
43
|
+
*
|
|
44
|
+
* @see {@link Model.copyTo}
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* const opts: CopyToOptions<User> = { where: { active: true }, order: [['id', 'ASC']], format: 'csv', header: true };
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export type CopyToOptions<T = Values> = FindOptions<T> & CopyToFormatOptions;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { Subquery, WriteStatement } from '../expressions/methods.ts';
|
|
2
|
+
import { FromItem, QueryNode, SelectNode, WithClause } from '../sql/ast.ts';
|
|
3
|
+
import { JoinSourceBuilder, JoinSources } from './join-source-builder.ts';
|
|
4
|
+
import { ModelDefinition } from './model-definition.ts';
|
|
5
|
+
/**
|
|
6
|
+
* Common table expression of the `with` option. PostgreSQL extension.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const cte: CteDefinition = {
|
|
11
|
+
* query: Task.subquery({ attributes: ['id'], where: { parentId: null } }),
|
|
12
|
+
* unionAll: true,
|
|
13
|
+
* materialized: false,
|
|
14
|
+
* };
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export type CteDefinition = Readonly<{
|
|
18
|
+
/** Non-recursive part, or a data-modifying statement with `returning` (never with `recursive`). */
|
|
19
|
+
query: Subquery | WriteStatement;
|
|
20
|
+
/** Recursive part (makes the whole clause `WITH RECURSIVE`); reference the CTE through `from`. */
|
|
21
|
+
recursive?: Subquery;
|
|
22
|
+
/** `UNION ALL` (default) or `UNION` between `query` and `recursive`. */
|
|
23
|
+
unionAll?: boolean;
|
|
24
|
+
/** `MATERIALIZED` / `NOT MATERIALIZED` hint. */
|
|
25
|
+
materialized?: boolean;
|
|
26
|
+
/** `SEARCH … FIRST BY … SET …`: adds a column that orders the rows breadth or depth first. Needs `recursive`. */
|
|
27
|
+
search?: CteSearchOptions;
|
|
28
|
+
/** `CYCLE … SET … [USING …]`: marks rows that revisit a key, and stops the recursion there. Needs `recursive`. */
|
|
29
|
+
cycle?: CteCycleOptions;
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* `search` of a recursive CTE definition.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* const search: CteSearchOptions = { by: ['id'], mode: 'breadth', set: 'ordercol' };
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export type CteSearchOptions = Readonly<{
|
|
40
|
+
/** Columns of the CTE that define the order. */
|
|
41
|
+
by: readonly string[];
|
|
42
|
+
/** Traversal order.
|
|
43
|
+
* @defaultValue 'depth' */
|
|
44
|
+
mode?: 'breadth' | 'depth';
|
|
45
|
+
/** Name of the added ordering column. */
|
|
46
|
+
set: string;
|
|
47
|
+
}>;
|
|
48
|
+
/**
|
|
49
|
+
* `cycle` of a recursive CTE definition.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* const cycle: CteCycleOptions = { columns: ['id'], set: 'is_cycle', using: 'path' };
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export type CteCycleOptions = Readonly<{
|
|
57
|
+
/** Columns that identify a visited row. */
|
|
58
|
+
columns: readonly string[];
|
|
59
|
+
/** Name of the added boolean column that is true on the row that closes a cycle. */
|
|
60
|
+
set: string;
|
|
61
|
+
/** Name of the added array column with the path of visited keys (required: PostgreSQL 16 and 17 need it). */
|
|
62
|
+
using: string;
|
|
63
|
+
}>;
|
|
64
|
+
/** `with` option: CTEs by name. */
|
|
65
|
+
export type WithOption = Readonly<Record<string, Subquery | WriteStatement | CteDefinition>>;
|
|
66
|
+
/**
|
|
67
|
+
* CTE-related find options. PostgreSQL extension.
|
|
68
|
+
*
|
|
69
|
+
* Combined into {@link FindOptions} and {@link CountOptions}.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* const opts: CteFindOptions = {
|
|
74
|
+
* with: { recent: { query: Post.subquery({ where: { published: true } }) } },
|
|
75
|
+
* source: 'recent',
|
|
76
|
+
* };
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export type CteFindOptions = Readonly<{
|
|
80
|
+
/** Common table expressions (`WITH [RECURSIVE] ...`). */
|
|
81
|
+
with?: WithOption;
|
|
82
|
+
/**
|
|
83
|
+
* Read model rows from this relation instead of the model table: a CTE or table name, or a
|
|
84
|
+
* subquery such as a set operation (`a.union(b)`), aliased with the model name. Columns are
|
|
85
|
+
* named like the attributes.
|
|
86
|
+
*/
|
|
87
|
+
source?: string | Subquery;
|
|
88
|
+
/** Extra relations (`FROM "Model", "alias"`), keyed by alias; correlate them in `where`. */
|
|
89
|
+
from?: JoinSources;
|
|
90
|
+
}>;
|
|
91
|
+
/**
|
|
92
|
+
* Resolves the CTE-related find options (PostgreSQL extension): the `WITH [RECURSIVE]` clause,
|
|
93
|
+
* extra FROM relations, and the definition used when rows come from a `source` relation.
|
|
94
|
+
*/
|
|
95
|
+
export declare class CteBuilder {
|
|
96
|
+
#private;
|
|
97
|
+
/**
|
|
98
|
+
* @param joins - Converts `from` relations into FROM items.
|
|
99
|
+
*/
|
|
100
|
+
constructor(joins: JoinSourceBuilder);
|
|
101
|
+
/**
|
|
102
|
+
* Builds the `WITH` clause of the `with` option.
|
|
103
|
+
*
|
|
104
|
+
* @param option - CTEs by name.
|
|
105
|
+
* @returns WITH clause, or `undefined` without CTEs.
|
|
106
|
+
*/
|
|
107
|
+
withClause(option: WithOption | undefined): WithClause | undefined;
|
|
108
|
+
/**
|
|
109
|
+
* Definition used when rows come from `source`: same attributes, columns named like attributes.
|
|
110
|
+
*
|
|
111
|
+
* @param definition - Model definition.
|
|
112
|
+
* @param source - `source` option.
|
|
113
|
+
* @returns The definition itself without `source`.
|
|
114
|
+
*/
|
|
115
|
+
sourceDefinition(definition: ModelDefinition, source: string | Subquery | undefined): ModelDefinition;
|
|
116
|
+
/**
|
|
117
|
+
* Resolved CTE options for the select builder.
|
|
118
|
+
*
|
|
119
|
+
* @param options - Find options.
|
|
120
|
+
* @returns `withClause` / `extraFrom` when present.
|
|
121
|
+
*/
|
|
122
|
+
selectOptions(options: CteFindOptions): Readonly<{
|
|
123
|
+
withClause?: WithClause;
|
|
124
|
+
extraFrom?: readonly FromItem[];
|
|
125
|
+
fromQuery?: QueryNode;
|
|
126
|
+
}>;
|
|
127
|
+
/**
|
|
128
|
+
* Route of a statement: `'write'` when a CTE modifies data, so it never goes to a replica.
|
|
129
|
+
*
|
|
130
|
+
* @param select - Built SELECT.
|
|
131
|
+
* @returns `'read'` or `'write'`.
|
|
132
|
+
*/
|
|
133
|
+
route(select: SelectNode): 'read' | 'write';
|
|
134
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ModelDefaults } from '../connection/options.ts';
|
|
2
|
+
import { ModelAttributes } from './attribute-options.ts';
|
|
3
|
+
import { DefinitionOptions, ModelDefinitionFields } from './model-definition.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Normalizes `Model.init` arguments into the fields of a model definition, applying Sequelize v6
|
|
6
|
+
* defaults (table name, automatic primary key, timestamps, paranoid, version, unique keys).
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare class DefinitionNormalizer {
|
|
11
|
+
#private;
|
|
12
|
+
/**
|
|
13
|
+
* @param className - Class name (default model name).
|
|
14
|
+
* @param declared - Declared attributes.
|
|
15
|
+
* @param options - Model options.
|
|
16
|
+
* @param defaults - `define` defaults of the Sequelize instance.
|
|
17
|
+
* @param associationAttributes - Attributes added by associations (foreign keys).
|
|
18
|
+
*/
|
|
19
|
+
constructor(className: string, declared: ModelAttributes, options: DefinitionOptions, defaults: ModelDefaults, associationAttributes: ModelAttributes);
|
|
20
|
+
/**
|
|
21
|
+
* Normalized definition fields.
|
|
22
|
+
*
|
|
23
|
+
* @returns The fields.
|
|
24
|
+
*/
|
|
25
|
+
fields(): ModelDefinitionFields;
|
|
26
|
+
}
|