postgrelize 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +269 -0
- package/LICENSE +21 -0
- package/README.md +131 -2
- package/dist/associations/association-accessors.d.ts +21 -0
- package/dist/associations/association-key-types.d.ts +44 -0
- package/dist/associations/association-keys.d.ts +98 -0
- package/dist/associations/association-lookup.d.ts +26 -0
- package/dist/associations/association-shape.d.ts +25 -0
- package/dist/associations/association.d.ts +95 -0
- package/dist/associations/belongs-to-many.d.ts +86 -0
- package/dist/associations/belongs-to.d.ts +45 -0
- package/dist/associations/has-many.d.ts +79 -0
- package/dist/associations/has-one.d.ts +44 -0
- package/dist/associations/include-assembler.d.ts +21 -0
- package/dist/associations/include-columns.d.ts +24 -0
- package/dist/associations/include-joins.d.ts +17 -0
- package/dist/associations/include-loader.d.ts +48 -0
- package/dist/associations/include-order.d.ts +22 -0
- package/dist/associations/include-query-builder.d.ts +54 -0
- package/dist/associations/include-resolver.d.ts +29 -0
- package/dist/associations/include-rows.d.ts +47 -0
- package/dist/associations/include-sub-query.d.ts +35 -0
- package/dist/associations/include.d.ts +112 -0
- package/dist/associations/junction-keys.d.ts +23 -0
- package/dist/associations/nested-creator.d.ts +44 -0
- package/dist/associations/nested-saver.d.ts +30 -0
- package/dist/associations/owner-keys.d.ts +34 -0
- package/dist/associations/separate-include-loader.d.ts +24 -0
- package/dist/associations/types.d.ts +139 -0
- package/dist/connection/connection-config.d.ts +33 -0
- package/dist/connection/connection-manager.d.ts +65 -0
- package/dist/connection/connection-types.d.ts +21 -0
- package/dist/connection/copy-from-stdin.d.ts +52 -0
- package/dist/connection/copy-runner.d.ts +30 -0
- package/dist/connection/copy-to-stdout.d.ts +49 -0
- package/dist/connection/copy.d.ts +22 -0
- package/dist/connection/notifications.d.ts +28 -0
- package/dist/connection/options.d.ts +158 -0
- package/dist/connection/query-logger.d.ts +41 -0
- package/dist/connection/replica-router.d.ts +20 -0
- package/dist/connection/statement-cache.d.ts +36 -0
- package/dist/connection/statement-timeout.d.ts +22 -0
- package/dist/data-types/abstract-data-type.d.ts +58 -0
- package/dist/data-types/array-literal-parser.d.ts +17 -0
- package/dist/data-types/array-type.d.ts +18 -0
- package/dist/data-types/bit-type.d.ts +14 -0
- package/dist/data-types/blob-type.d.ts +12 -0
- package/dist/data-types/char-type.d.ts +12 -0
- package/dist/data-types/composite-fields.d.ts +26 -0
- package/dist/data-types/composite-type.d.ts +32 -0
- package/dist/data-types/data-types.d.ts +172 -0
- package/dist/data-types/date-type.d.ts +14 -0
- package/dist/data-types/decimal-type.d.ts +13 -0
- package/dist/data-types/default-value-generator.d.ts +15 -0
- package/dist/data-types/enum-type.d.ts +19 -0
- package/dist/data-types/ewkb-reader.d.ts +18 -0
- package/dist/data-types/ewkb-writer.d.ts +17 -0
- package/dist/data-types/float-type.d.ts +12 -0
- package/dist/data-types/geometric-text.d.ts +65 -0
- package/dist/data-types/geometric-type.d.ts +46 -0
- package/dist/data-types/hstore-type.d.ts +16 -0
- package/dist/data-types/integer-type.d.ts +24 -0
- package/dist/data-types/json-type.d.ts +16 -0
- package/dist/data-types/multirange-type.d.ts +19 -0
- package/dist/data-types/range-type.d.ts +28 -0
- package/dist/data-types/record-text.d.ts +29 -0
- package/dist/data-types/scalar-type.d.ts +13 -0
- package/dist/data-types/spatial-type.d.ts +20 -0
- package/dist/data-types/string-type.d.ts +12 -0
- package/dist/data-types/text-type.d.ts +12 -0
- package/dist/data-types/timestamp-type.d.ts +15 -0
- package/dist/data-types/virtual-type.d.ts +15 -0
- package/dist/data-types/wall-clock.d.ts +14 -0
- package/dist/ddl/column-ddl.d.ts +73 -0
- package/dist/ddl/constraint-ddl.d.ts +30 -0
- package/dist/ddl/ddl-generator.d.ts +181 -0
- package/dist/ddl/ddl-guards.d.ts +60 -0
- package/dist/ddl/ddl-types.d.ts +193 -0
- package/dist/ddl/enum-ddl.d.ts +42 -0
- package/dist/ddl/extension-ddl.d.ts +57 -0
- package/dist/ddl/function-ddl.d.ts +98 -0
- package/dist/ddl/index-ddl.d.ts +29 -0
- package/dist/ddl/index-element-ddl.d.ts +19 -0
- package/dist/ddl/partition-ddl.d.ts +88 -0
- package/dist/ddl/partition-types.d.ts +94 -0
- package/dist/ddl/policy-ddl.d.ts +137 -0
- package/dist/ddl/routine-guards.d.ts +63 -0
- package/dist/ddl/sequence-ddl.d.ts +103 -0
- package/dist/ddl/sql-literal.d.ts +61 -0
- package/dist/ddl/table-ddl.d.ts +35 -0
- package/dist/ddl/trigger-ddl.d.ts +81 -0
- package/dist/ddl/view-ddl.d.ts +122 -0
- package/dist/decorators/association-applier.d.ts +18 -0
- package/dist/decorators/association-decorators.d.ts +72 -0
- package/dist/decorators/column-decorators.d.ts +147 -0
- package/dist/decorators/decorator-factory.d.ts +45 -0
- package/dist/decorators/decorator-signature.d.ts +26 -0
- package/dist/decorators/decorator-types.d.ts +24 -0
- package/dist/decorators/foreign-key-decorator.d.ts +21 -0
- package/dist/decorators/hook-decorators.d.ts +393 -0
- package/dist/decorators/init-arguments.d.ts +29 -0
- package/dist/decorators/model-decorators.d.ts +18 -0
- package/dist/decorators/model-metadata.d.ts +70 -0
- package/dist/decorators/table-decorators.d.ts +43 -0
- package/dist/decorators/timestamp-decorators.d.ts +38 -0
- package/dist/errors/base-error.d.ts +40 -0
- package/dist/errors/connection-errors.d.ts +152 -0
- package/dist/errors/database-errors.d.ts +152 -0
- package/dist/errors/errors.d.ts +5 -0
- package/dist/errors/map-pg-error.d.ts +27 -0
- package/dist/errors/misc-errors.d.ts +188 -0
- package/dist/errors/validation-errors.d.ts +117 -0
- package/dist/exports-core.d.ts +15 -0
- package/dist/exports-decorators.d.ts +8 -0
- package/dist/exports-errors.d.ts +2 -0
- package/dist/exports-model.d.ts +21 -0
- package/dist/exports-schema.d.ts +19 -0
- package/dist/expressions/call-expressions.d.ts +54 -0
- package/dist/expressions/condition-expressions.d.ts +51 -0
- package/dist/expressions/expression.d.ts +52 -0
- package/dist/expressions/jsonpath-helpers.d.ts +37 -0
- package/dist/expressions/methods.d.ts +188 -0
- package/dist/expressions/op.d.ts +182 -0
- package/dist/expressions/query-expressions.d.ts +110 -0
- package/dist/expressions/row-expressions.d.ts +35 -0
- package/dist/expressions/search-helpers.d.ts +138 -0
- package/dist/expressions/trigram-helpers.d.ts +40 -0
- package/dist/hooks/hooks.d.ts +125 -0
- package/dist/index.cjs +20461 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +20332 -0
- package/dist/index.js.map +1 -0
- package/dist/model/attribute-columns.d.ts +85 -0
- package/dist/model/attribute-normalizer.d.ts +42 -0
- package/dist/model/attribute-options.d.ts +121 -0
- package/dist/model/bulk-insert-builder.d.ts +24 -0
- package/dist/model/bulk-options.d.ts +173 -0
- package/dist/model/copy-options.d.ts +51 -0
- package/dist/model/cte-builder.d.ts +134 -0
- package/dist/model/definition-normalizer.d.ts +26 -0
- package/dist/model/delete-query-builder.d.ts +42 -0
- package/dist/model/find-options.d.ts +144 -0
- package/dist/model/find-query-builder.d.ts +38 -0
- package/dist/model/insert-query-builder.d.ts +41 -0
- package/dist/model/instance-destroyer.d.ts +44 -0
- package/dist/model/instance-lifecycle-services.d.ts +61 -0
- package/dist/model/instance-lifecycle.d.ts +128 -0
- package/dist/model/instance-saver.d.ts +25 -0
- package/dist/model/instance-state.d.ts +48 -0
- package/dist/model/instance-validation.d.ts +35 -0
- package/dist/model/instance-values.d.ts +80 -0
- package/dist/model/instance-writer.d.ts +59 -0
- package/dist/model/join-source-builder.d.ts +25 -0
- package/dist/model/lateral-keys-builder.d.ts +25 -0
- package/dist/model/merge-action-builder.d.ts +31 -0
- package/dist/model/merge-options.d.ts +72 -0
- package/dist/model/merge-query-builder.d.ts +29 -0
- package/dist/model/merge-source-builder.d.ts +22 -0
- package/dist/model/mixins/model-aggregates.d.ts +69 -0
- package/dist/model/mixins/model-associations.d.ts +73 -0
- package/dist/model/mixins/model-constructor.d.ts +7 -0
- package/dist/model/mixins/model-finders.d.ts +124 -0
- package/dist/model/mixins/model-hooks.d.ts +138 -0
- package/dist/model/mixins/model-postgres.d.ts +198 -0
- package/dist/model/mixins/model-schema-binding.d.ts +36 -0
- package/dist/model/mixins/model-schema.d.ts +55 -0
- package/dist/model/mixins/model-scopes.d.ts +57 -0
- package/dist/model/mixins/model-writers.d.ts +175 -0
- package/dist/model/mixins/named-hooks.d.ts +28 -0
- package/dist/model/model-accessors.d.ts +22 -0
- package/dist/model/model-base.d.ts +83 -0
- package/dist/model/model-definition.d.ts +130 -0
- package/dist/model/model-instance-persistence.d.ts +132 -0
- package/dist/model/model-instance-values.d.ts +154 -0
- package/dist/model/model-operations.d.ts +22 -0
- package/dist/model/model-registry.d.ts +139 -0
- package/dist/model/model-services.d.ts +46 -0
- package/dist/model/model-state.d.ts +60 -0
- package/dist/model/model-values.d.ts +86 -0
- package/dist/model/model.d.ts +560 -0
- package/dist/model/on-conflict-builder.d.ts +111 -0
- package/dist/model/operations/bulk-create-operation.d.ts +40 -0
- package/dist/model/operations/copy-from-source.d.ts +51 -0
- package/dist/model/operations/copy-operation.d.ts +54 -0
- package/dist/model/operations/count-operation.d.ts +52 -0
- package/dist/model/operations/create-operation.d.ts +31 -0
- package/dist/model/operations/destroy-operation.d.ts +65 -0
- package/dist/model/operations/find-cursor.d.ts +23 -0
- package/dist/model/operations/find-lookups.d.ts +89 -0
- package/dist/model/operations/find-operation.d.ts +47 -0
- package/dist/model/operations/increment-operation.d.ts +40 -0
- package/dist/model/operations/insert-operation.d.ts +71 -0
- package/dist/model/operations/merge-operation.d.ts +56 -0
- package/dist/model/operations/model-operation.d.ts +33 -0
- package/dist/model/operations/update-operation.d.ts +45 -0
- package/dist/model/operations/upsert-operation.d.ts +39 -0
- package/dist/model/options.d.ts +103 -0
- package/dist/model/returning-old.d.ts +52 -0
- package/dist/model/row-mapper.d.ts +78 -0
- package/dist/model/row-plan.d.ts +31 -0
- package/dist/model/runtime.d.ts +54 -0
- package/dist/model/scope-registry.d.ts +81 -0
- package/dist/model/select-aggregates.d.ts +37 -0
- package/dist/model/select-lock.d.ts +13 -0
- package/dist/model/select-options.d.ts +92 -0
- package/dist/model/select-query-builder.d.ts +73 -0
- package/dist/model/select-targets.d.ts +77 -0
- package/dist/model/source-option-builder.d.ts +23 -0
- package/dist/model/source-options.d.ts +108 -0
- package/dist/model/statement-builder.d.ts +77 -0
- package/dist/model/statement-services.d.ts +2 -0
- package/dist/model/sync-hooks.d.ts +18 -0
- package/dist/model/table-sample-builder.d.ts +13 -0
- package/dist/model/types.d.ts +85 -0
- package/dist/model/unnest-insert-builder.d.ts +24 -0
- package/dist/model/update-query-builder.d.ts +39 -0
- package/dist/model/v6-conflict-builder.d.ts +37 -0
- package/dist/model/value-cloner.d.ts +17 -0
- package/dist/model/values-writer.d.ts +12 -0
- package/dist/model/where-options.d.ts +164 -0
- package/dist/model/write-options.d.ts +160 -0
- package/dist/model/written-rows.d.ts +56 -0
- package/dist/query/query-result-shaper.d.ts +91 -0
- package/dist/query/raw-query.d.ts +27 -0
- package/dist/query-interface/alter-planner.d.ts +40 -0
- package/dist/query-interface/bulk-data.d.ts +44 -0
- package/dist/query-interface/column-commands.d.ts +52 -0
- package/dist/query-interface/column-describer.d.ts +17 -0
- package/dist/query-interface/enum-commands.d.ts +36 -0
- package/dist/query-interface/index-commands.d.ts +57 -0
- package/dist/query-interface/model-tables.d.ts +58 -0
- package/dist/query-interface/object-commands.d.ts +71 -0
- package/dist/query-interface/partition-commands.d.ts +43 -0
- package/dist/query-interface/policy-commands.d.ts +54 -0
- package/dist/query-interface/query-interface-objects.d.ts +108 -0
- package/dist/query-interface/query-interface-partitions.d.ts +66 -0
- package/dist/query-interface/query-interface-policies.d.ts +86 -0
- package/dist/query-interface/query-interface-routines.d.ts +120 -0
- package/dist/query-interface/query-interface-tables.d.ts +179 -0
- package/dist/query-interface/query-interface-types.d.ts +62 -0
- package/dist/query-interface/query-interface-views.d.ts +84 -0
- package/dist/query-interface/query-interface.d.ts +256 -0
- package/dist/query-interface/routine-commands.d.ts +71 -0
- package/dist/query-interface/schema-synchronizer.d.ts +99 -0
- package/dist/query-interface/statement-runner.d.ts +40 -0
- package/dist/query-interface/sync-planner.d.ts +26 -0
- package/dist/query-interface/table-commands.d.ts +63 -0
- package/dist/query-interface/table-introspector.d.ts +58 -0
- package/dist/query-interface/view-commands.d.ts +47 -0
- package/dist/sequelize/sequelize-base.d.ts +196 -0
- package/dist/sequelize/sequelize-constructor.d.ts +7 -0
- package/dist/sequelize/sequelize-hooks.d.ts +86 -0
- package/dist/sequelize/sequelize-internals.d.ts +87 -0
- package/dist/sequelize/sequelize-notifications.d.ts +66 -0
- package/dist/sequelize/sequelize-schema.d.ts +106 -0
- package/dist/sequelize/sequelize-transactions.d.ts +96 -0
- package/dist/sequelize.d.ts +790 -0
- package/dist/sql/ast-clauses.d.ts +137 -0
- package/dist/sql/ast-expressions.d.ts +88 -0
- package/dist/sql/ast-statements.d.ts +80 -0
- package/dist/sql/ast.d.ts +21 -0
- package/dist/sql/compile.d.ts +21 -0
- package/dist/sql/dml-compiler.d.ts +54 -0
- package/dist/sql/expression-compiler.d.ts +56 -0
- package/dist/sql/from-compiler.d.ts +39 -0
- package/dist/sql/identifier-quoter.d.ts +15 -0
- package/dist/sql/merge-compiler.d.ts +20 -0
- package/dist/sql/order.d.ts +15 -0
- package/dist/sql/query-compiler.d.ts +45 -0
- package/dist/sql/sql-chunks.d.ts +50 -0
- package/dist/sql/with-compiler.d.ts +19 -0
- package/dist/transaction/advisory-locks.d.ts +28 -0
- package/dist/transaction/transaction-constants.d.ts +35 -0
- package/dist/transaction/transaction-runner.d.ts +60 -0
- package/dist/transaction/transaction-starter.d.ts +25 -0
- package/dist/transaction/transaction-statements.d.ts +28 -0
- package/dist/transaction/transaction.d.ts +198 -0
- package/dist/validation/attribute-validators.d.ts +23 -0
- package/dist/validation/builtin-attribute-validator.d.ts +19 -0
- package/dist/validation/builtin-validators.d.ts +16 -0
- package/dist/validation/core-validator.d.ts +16 -0
- package/dist/validation/custom-validators.d.ts +13 -0
- package/dist/validation/instance-validator.d.ts +25 -0
- package/dist/validation/schema-items.d.ts +22 -0
- package/dist/validation/standard-schema-validator.d.ts +30 -0
- package/dist/validation/standard-schema.d.ts +39 -0
- package/dist/validation/types.d.ts +36 -0
- package/dist/validation/validation-target.d.ts +13 -0
- package/dist/where/comparison-compiler.d.ts +27 -0
- package/dist/where/condition-compiler.d.ts +18 -0
- package/dist/where/operand-resolver.d.ts +10 -0
- package/dist/where/operator-allowlist.d.ts +14 -0
- package/dist/where/where-support.d.ts +52 -0
- package/dist/where/where.d.ts +46 -0
- package/dist/where/window-compiler.d.ts +14 -0
- package/llm/USAGE.md +423 -0
- package/package.json +102 -4
- package/skills/postgrelize/SKILL.md +57 -0
- package/skills/postgrelize/reference/associations.md +108 -0
- package/skills/postgrelize/reference/errors.md +37 -0
- package/skills/postgrelize/reference/migrating-from-sequelize.md +15 -0
- package/skills/postgrelize/reference/postgresql-features.md +157 -0
- package/skills/postgrelize/reference/querying.md +111 -0
- package/skills/postgrelize/reference/schema.md +135 -0
- package/skills/postgrelize/reference/security.md +34 -0
- package/skills/postgrelize/reference/transactions-and-sessions.md +122 -0
- package/skills/postgrelize/reference/writing.md +198 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { HookFunction, HookType } from '../../hooks/hooks.ts';
|
|
2
|
+
import { AnyModel, ModelStatic } from '../options.ts';
|
|
3
|
+
import { NamedHookAdder } from './named-hooks.ts';
|
|
4
|
+
import { ModelConstructor } from './model-constructor.ts';
|
|
5
|
+
/**
|
|
6
|
+
* Hook statics of `Model`: `addHook`, `removeHook`, `hasHook(s)`, `runHooks` and the named adders (`Model.beforeCreate(fn)`, ...).
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare const ModelHooks: <TBase extends ModelConstructor>(Base: TBase) => {
|
|
11
|
+
new (...args: any[]): {
|
|
12
|
+
get wasInserted(): boolean | undefined;
|
|
13
|
+
get oldValues(): Readonly<Record<string, unknown>> | null | undefined;
|
|
14
|
+
get sequelize(): import('../runtime.ts').RuntimeOwner;
|
|
15
|
+
};
|
|
16
|
+
/** Adds a `beforeValidate` hook: `Model.beforeValidate(fn)` or `Model.beforeValidate(name, fn)`. */
|
|
17
|
+
beforeValidate: NamedHookAdder;
|
|
18
|
+
/** Adds a `afterValidate` hook: `Model.afterValidate(fn)` or `Model.afterValidate(name, fn)`. */
|
|
19
|
+
afterValidate: NamedHookAdder;
|
|
20
|
+
/** Adds a `validationFailed` hook: `Model.validationFailed(fn)` or `Model.validationFailed(name, fn)`. */
|
|
21
|
+
validationFailed: NamedHookAdder;
|
|
22
|
+
/** Adds a `beforeCreate` hook: `Model.beforeCreate(fn)` or `Model.beforeCreate(name, fn)`. */
|
|
23
|
+
beforeCreate: NamedHookAdder;
|
|
24
|
+
/** Adds a `afterCreate` hook: `Model.afterCreate(fn)` or `Model.afterCreate(name, fn)`. */
|
|
25
|
+
afterCreate: NamedHookAdder;
|
|
26
|
+
/** Adds a `beforeUpdate` hook: `Model.beforeUpdate(fn)` or `Model.beforeUpdate(name, fn)`. */
|
|
27
|
+
beforeUpdate: NamedHookAdder;
|
|
28
|
+
/** Adds a `afterUpdate` hook: `Model.afterUpdate(fn)` or `Model.afterUpdate(name, fn)`. */
|
|
29
|
+
afterUpdate: NamedHookAdder;
|
|
30
|
+
/** Adds a `beforeSave` hook: `Model.beforeSave(fn)` or `Model.beforeSave(name, fn)`. */
|
|
31
|
+
beforeSave: NamedHookAdder;
|
|
32
|
+
/** Adds a `afterSave` hook: `Model.afterSave(fn)` or `Model.afterSave(name, fn)`. */
|
|
33
|
+
afterSave: NamedHookAdder;
|
|
34
|
+
/** Adds a `beforeDestroy` hook: `Model.beforeDestroy(fn)` or `Model.beforeDestroy(name, fn)`. */
|
|
35
|
+
beforeDestroy: NamedHookAdder;
|
|
36
|
+
/** Adds a `afterDestroy` hook: `Model.afterDestroy(fn)` or `Model.afterDestroy(name, fn)`. */
|
|
37
|
+
afterDestroy: NamedHookAdder;
|
|
38
|
+
/** Adds a `beforeRestore` hook: `Model.beforeRestore(fn)` or `Model.beforeRestore(name, fn)`. */
|
|
39
|
+
beforeRestore: NamedHookAdder;
|
|
40
|
+
/** Adds a `afterRestore` hook: `Model.afterRestore(fn)` or `Model.afterRestore(name, fn)`. */
|
|
41
|
+
afterRestore: NamedHookAdder;
|
|
42
|
+
/** Adds a `beforeUpsert` hook: `Model.beforeUpsert(fn)` or `Model.beforeUpsert(name, fn)`. */
|
|
43
|
+
beforeUpsert: NamedHookAdder;
|
|
44
|
+
/** Adds a `afterUpsert` hook: `Model.afterUpsert(fn)` or `Model.afterUpsert(name, fn)`. */
|
|
45
|
+
afterUpsert: NamedHookAdder;
|
|
46
|
+
/** Adds a `beforeBulkCreate` hook: `Model.beforeBulkCreate(fn)` or `Model.beforeBulkCreate(name, fn)`. */
|
|
47
|
+
beforeBulkCreate: NamedHookAdder;
|
|
48
|
+
/** Adds a `afterBulkCreate` hook: `Model.afterBulkCreate(fn)` or `Model.afterBulkCreate(name, fn)`. */
|
|
49
|
+
afterBulkCreate: NamedHookAdder;
|
|
50
|
+
/** Adds a `beforeBulkUpdate` hook: `Model.beforeBulkUpdate(fn)` or `Model.beforeBulkUpdate(name, fn)`. */
|
|
51
|
+
beforeBulkUpdate: NamedHookAdder;
|
|
52
|
+
/** Adds a `afterBulkUpdate` hook: `Model.afterBulkUpdate(fn)` or `Model.afterBulkUpdate(name, fn)`. */
|
|
53
|
+
afterBulkUpdate: NamedHookAdder;
|
|
54
|
+
/** Adds a `beforeBulkDestroy` hook: `Model.beforeBulkDestroy(fn)` or `Model.beforeBulkDestroy(name, fn)`. */
|
|
55
|
+
beforeBulkDestroy: NamedHookAdder;
|
|
56
|
+
/** Adds a `afterBulkDestroy` hook: `Model.afterBulkDestroy(fn)` or `Model.afterBulkDestroy(name, fn)`. */
|
|
57
|
+
afterBulkDestroy: NamedHookAdder;
|
|
58
|
+
/** Adds a `beforeBulkRestore` hook: `Model.beforeBulkRestore(fn)` or `Model.beforeBulkRestore(name, fn)`. */
|
|
59
|
+
beforeBulkRestore: NamedHookAdder;
|
|
60
|
+
/** Adds a `afterBulkRestore` hook: `Model.afterBulkRestore(fn)` or `Model.afterBulkRestore(name, fn)`. */
|
|
61
|
+
afterBulkRestore: NamedHookAdder;
|
|
62
|
+
/** Adds a `beforeFind` hook: `Model.beforeFind(fn)` or `Model.beforeFind(name, fn)`. */
|
|
63
|
+
beforeFind: NamedHookAdder;
|
|
64
|
+
/** Adds a `beforeFindAfterExpandIncludeAll` hook: `Model.beforeFindAfterExpandIncludeAll(fn)` or `Model.beforeFindAfterExpandIncludeAll(name, fn)`. */
|
|
65
|
+
beforeFindAfterExpandIncludeAll: NamedHookAdder;
|
|
66
|
+
/** Adds a `beforeFindAfterOptions` hook: `Model.beforeFindAfterOptions(fn)` or `Model.beforeFindAfterOptions(name, fn)`. */
|
|
67
|
+
beforeFindAfterOptions: NamedHookAdder;
|
|
68
|
+
/** Adds a `afterFind` hook: `Model.afterFind(fn)` or `Model.afterFind(name, fn)`. */
|
|
69
|
+
afterFind: NamedHookAdder;
|
|
70
|
+
/** Adds a `beforeCount` hook: `Model.beforeCount(fn)` or `Model.beforeCount(name, fn)`. */
|
|
71
|
+
beforeCount: NamedHookAdder;
|
|
72
|
+
/**
|
|
73
|
+
* Registers a hook function for a lifecycle event of this model, same as the named adders such as
|
|
74
|
+
* `Model.beforeCreate(fn)`. Hooks of one type run in registration order.
|
|
75
|
+
*
|
|
76
|
+
* @param this - The model class.
|
|
77
|
+
* @param type - Hook type, e.g. `'beforeCreate'`.
|
|
78
|
+
* @param nameOrFn - Hook name (to remove it later) or the hook function.
|
|
79
|
+
* @param fn - Hook function when a name is given.
|
|
80
|
+
* @returns The model class.
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* User.addHook('beforeCreate', 'normalizeEmail', async (instance: User) => {
|
|
84
|
+
* instance.set('email', String(instance.get('email')).toLowerCase());
|
|
85
|
+
* });
|
|
86
|
+
* ```
|
|
87
|
+
* @see [Hooks guide](/guide/hooks-validation)
|
|
88
|
+
*/
|
|
89
|
+
addHook<MS extends ModelStatic<AnyModel>>(this: MS, type: HookType, nameOrFn: string | HookFunction, fn?: HookFunction): MS;
|
|
90
|
+
/**
|
|
91
|
+
* Removes hooks of a type from this model: one by name or function, or all of them.
|
|
92
|
+
*
|
|
93
|
+
* @param this - The model class.
|
|
94
|
+
* @param type - Hook type.
|
|
95
|
+
* @param nameOrFn - Hook name or function; all hooks of the type when omitted.
|
|
96
|
+
* @returns The model class.
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* User.removeHook('beforeCreate', 'normalizeEmail');
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
removeHook<MS extends ModelStatic<AnyModel>>(this: MS, type: HookType, nameOrFn?: string | HookFunction): MS;
|
|
103
|
+
/**
|
|
104
|
+
* Checks whether hooks of the type are registered on the model.
|
|
105
|
+
*
|
|
106
|
+
* @param type - Hook type.
|
|
107
|
+
* @returns True when at least one hook exists, `false` after all were removed and
|
|
108
|
+
* `undefined` (typed `boolean`, like Sequelize v6) for a type that never had a hook.
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* const registered = User.hasHook('beforeCreate');
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
hasHook(type: HookType): boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Alias of {@link Model.hasHook}.
|
|
117
|
+
*
|
|
118
|
+
* @param type - Hook type.
|
|
119
|
+
* @returns Same as {@link Model.hasHook}.
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* const registered = User.hasHooks('afterFind');
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
hasHooks(type: HookType): boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Runs the hooks of a type with the given arguments (model hooks, then Sequelize-level hooks).
|
|
128
|
+
*
|
|
129
|
+
* @param type - Hook type.
|
|
130
|
+
* @param args - Hook arguments.
|
|
131
|
+
* @returns Resolves when all hooks finished.
|
|
132
|
+
* @example
|
|
133
|
+
* ```ts
|
|
134
|
+
* await User.runHooks('beforeCreate', user, {});
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
runHooks(type: HookType, ...args: readonly unknown[]): Promise<void>;
|
|
138
|
+
} & TBase;
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { Subquery, WriteStatement } from '../../expressions/methods.ts';
|
|
2
|
+
import { MergeOptions } from '../merge-query-builder.ts';
|
|
3
|
+
import { UpdateStatementOptions, WriteStatementOptions } from '../statement-builder.ts';
|
|
4
|
+
import { MergeResult } from '../operations/merge-operation.ts';
|
|
5
|
+
import { AnyModel, Attributes, CopyFromOptions, CopyToOptions, CreationAttributes, FindOptions, InsertFromOptions, InsertOptions, ModelStatic } from '../options.ts';
|
|
6
|
+
import { QueryOptionsBase } from '../runtime.ts';
|
|
7
|
+
import { ModelConstructor } from './model-constructor.ts';
|
|
8
|
+
/**
|
|
9
|
+
* PostgreSQL extension statics of `Model`: `insert`, `insertFrom`, `merge`, `subquery`, `updateStatement`, `deleteStatement`, `insertStatement`, `findEach`, `copyFrom`, `copyTo`.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export declare const ModelPostgres: <TBase extends ModelConstructor>(Base: TBase) => {
|
|
14
|
+
new (...args: any[]): {
|
|
15
|
+
get wasInserted(): boolean | undefined;
|
|
16
|
+
get oldValues(): Readonly<Record<string, unknown>> | null | undefined;
|
|
17
|
+
get sequelize(): import('../runtime.ts').RuntimeOwner;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Inserts rows with `INSERT ... ON CONFLICT` and returns the inserted or updated rows. Unlike
|
|
21
|
+
* `bulkCreate`, rows skipped by `DO NOTHING` or by the `DO UPDATE ... WHERE` condition are not
|
|
22
|
+
* returned. Each instance has `wasInserted`. PostgreSQL extension.
|
|
23
|
+
*
|
|
24
|
+
* @param this - The model class.
|
|
25
|
+
* @param values - Attribute values of one row or several rows.
|
|
26
|
+
* @param options - Insert options (`onConflict`, `fields`, `hooks`, `validate`, `overriding`, `returningOld`, query options).
|
|
27
|
+
* @returns Instances of the rows written by the statement.
|
|
28
|
+
* @see {@link Model.bulkCreate} for the Sequelize v6 variant.
|
|
29
|
+
* @see [Bulk writes guide](/guide/bulk-writes)
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const items = [{ sku: 'a-1', qty: 5 }];
|
|
33
|
+
* const rows = await Product.insert(items, {
|
|
34
|
+
* onConflict: { target: ['sku'], action: { update: { qty: literal('"Product"."qty" + EXCLUDED."qty"') } } },
|
|
35
|
+
* });
|
|
36
|
+
* const inserted = rows.filter((row) => row.wasInserted);
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
insert<M extends AnyModel>(this: ModelStatic<M>, values: CreationAttributes<M> | readonly CreationAttributes<M>[], options?: InsertOptions<Attributes<M>>): Promise<M[]>;
|
|
40
|
+
/**
|
|
41
|
+
* `INSERT INTO ... SELECT`: inserts the rows produced by a subquery. Returns the inserted (or, with
|
|
42
|
+
* `onConflict`, updated) rows with `wasInserted`. PostgreSQL extension.
|
|
43
|
+
*
|
|
44
|
+
* @param this - The target model class.
|
|
45
|
+
* @param source - Subquery from `Model.subquery()`; its columns must match `options.columns`.
|
|
46
|
+
* @param options - Target columns, `onConflict` and query options.
|
|
47
|
+
* @returns Written rows.
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* await Task.insertFrom(
|
|
51
|
+
* Post.subquery({ attributes: ['id', 'title'], where: { published: false } }),
|
|
52
|
+
* { columns: ['postId', 'title'] },
|
|
53
|
+
* );
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
insertFrom<M extends AnyModel>(this: ModelStatic<M>, source: Subquery, options: InsertFromOptions<Attributes<M>>): Promise<M[]>;
|
|
57
|
+
/**
|
|
58
|
+
* `MERGE INTO ... USING ...` (PostgreSQL 15+). With `returning: true` (PostgreSQL 17+) returns the
|
|
59
|
+
* written rows with the action taken. PostgreSQL extension.
|
|
60
|
+
*
|
|
61
|
+
* @param this - The model class.
|
|
62
|
+
* @param options - Source, join condition and WHEN clauses.
|
|
63
|
+
* @returns Affected row count and, with `returning`, `{ action, instance }` per row.
|
|
64
|
+
* @throws DatabaseError when the server rejects the statement (for example on PostgreSQL older than 15).
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* await Product.merge({
|
|
68
|
+
* source: [{ sku: 'a', qty: 5 }],
|
|
69
|
+
* on: { sku: col('source.sku') },
|
|
70
|
+
* whenMatched: { update: { qty: literal('"Product"."qty" + "source"."qty"') } },
|
|
71
|
+
* whenNotMatched: { insert: true },
|
|
72
|
+
* });
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
merge<M extends AnyModel>(this: ModelStatic<M>, options: MergeOptions<Attributes<M>> & QueryOptionsBase & Readonly<{
|
|
76
|
+
/** Return written rows (PostgreSQL 17+). */
|
|
77
|
+
returning?: boolean;
|
|
78
|
+
/** With `returning`: expose pre-statement values as `instance.oldValues` (PostgreSQL 18+). */
|
|
79
|
+
returningOld?: boolean;
|
|
80
|
+
}>): Promise<MergeResult<M>>;
|
|
81
|
+
/**
|
|
82
|
+
* Builds a SELECT that can be embedded in another query: in `where` (`[Op.in]`, `=`, `exists()`),
|
|
83
|
+
* in `attributes` (scalar subquery) and as a source of `insertFrom` / `merge`. Default scope and
|
|
84
|
+
* paranoid filter apply; values stay bound parameters of the outer statement. PostgreSQL extension.
|
|
85
|
+
*
|
|
86
|
+
* @param this - The model class the subquery selects from.
|
|
87
|
+
* @param options - Find options (`attributes`, `where`, `order`, `limit`, `include`, ...) and `as` (table alias).
|
|
88
|
+
* @returns Subquery expression.
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* await User.findAll({ where: { id: { [Op.in]: Post.subquery({ attributes: ['userId'], where: { published: true } }) } } });
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
subquery<M extends AnyModel>(this: ModelStatic<M>, options?: FindOptions<Attributes<M>> & Readonly<{
|
|
95
|
+
as?: string;
|
|
96
|
+
}>): Subquery;
|
|
97
|
+
/**
|
|
98
|
+
* Builds an `UPDATE` for a data-modifying CTE (`with`); nothing runs until the outer query does.
|
|
99
|
+
* No hooks or validation run; `updatedAt` is set unless `silent`. With `returning: true` the CTE
|
|
100
|
+
* can be read through `source`. Queries with such a CTE always use the writer. PostgreSQL extension.
|
|
101
|
+
*
|
|
102
|
+
* @param this - The model class.
|
|
103
|
+
* @param values - New attribute values.
|
|
104
|
+
* @param options - `where`, `returning`, `silent`.
|
|
105
|
+
* @returns Statement for the `with` option.
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* const bumped = Task.updateStatement({ done: true }, { where: { id: 1 }, returning: true });
|
|
109
|
+
* const rows = await Task.findAll({ with: { bumped }, source: 'bumped' });
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
updateStatement<M extends AnyModel>(this: ModelStatic<M>, values: Partial<Attributes<M>>, options?: UpdateStatementOptions<Attributes<M>>): WriteStatement;
|
|
113
|
+
/**
|
|
114
|
+
* Builds a `DELETE` for a data-modifying CTE (`with`). It is a real delete, also for paranoid
|
|
115
|
+
* models, and ignores the paranoid filter. With `returning: true` the deleted rows can be read
|
|
116
|
+
* through `source`, e.g. to move them to another table. PostgreSQL extension.
|
|
117
|
+
*
|
|
118
|
+
* @param this - The model class.
|
|
119
|
+
* @param options - `where`, `returning`.
|
|
120
|
+
* @returns Statement for the `with` option.
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* const done = Task.deleteStatement({ where: { done: true }, returning: true });
|
|
124
|
+
* const removed = await Task.findAll({ with: { done }, source: 'done' });
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
deleteStatement<M extends AnyModel>(this: ModelStatic<M>, options?: WriteStatementOptions<Attributes<M>>): WriteStatement;
|
|
128
|
+
/**
|
|
129
|
+
* Builds an `INSERT` of attribute-keyed rows for a data-modifying CTE (`with`). Defaults and
|
|
130
|
+
* timestamps are filled in; no hooks or validation run. PostgreSQL extension.
|
|
131
|
+
*
|
|
132
|
+
* @param this - The model class.
|
|
133
|
+
* @param rows - Rows to insert (at least one).
|
|
134
|
+
* @param options - `returning`.
|
|
135
|
+
* @returns Statement for the `with` option.
|
|
136
|
+
* @throws Error without rows.
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* const added = Task.insertStatement([{ title: 'write docs' }], { returning: true });
|
|
140
|
+
* const rows = await Task.findAll({ with: { added }, source: 'added' });
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
insertStatement<M extends AnyModel>(this: ModelStatic<M>, rows: readonly CreationAttributes<M>[], options?: Pick<WriteStatementOptions<Attributes<M>>, "returning">): WriteStatement;
|
|
144
|
+
/**
|
|
145
|
+
* Streams rows with a server-side cursor (`DECLARE ... CURSOR` + `FETCH n`), so large result sets
|
|
146
|
+
* are not loaded at once. Runs inside `options.transaction` or its own transaction; the cursor is
|
|
147
|
+
* closed when iteration ends or is stopped early. Joined includes are not supported. PostgreSQL extension.
|
|
148
|
+
*
|
|
149
|
+
* @param this - The model class.
|
|
150
|
+
* @param options - Find options.
|
|
151
|
+
* @param cursor - `batchSize` (rows per FETCH, default 100).
|
|
152
|
+
* @returns Async iterator of instances.
|
|
153
|
+
* @example
|
|
154
|
+
* ```ts
|
|
155
|
+
* for await (const user of User.findEach({ where: { active: true } }, { batchSize: 500 })) {
|
|
156
|
+
* console.log(user.get('email'));
|
|
157
|
+
* }
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
findEach<M extends AnyModel>(this: ModelStatic<M>, options?: FindOptions<Attributes<M>>, cursor?: Readonly<{
|
|
161
|
+
batchSize?: number;
|
|
162
|
+
}>): AsyncGenerator<M, void, undefined>;
|
|
163
|
+
/**
|
|
164
|
+
* Bulk-loads rows with `COPY ... FROM STDIN` (text format) — much faster than INSERT for large
|
|
165
|
+
* volumes. No hooks or validation run; missing values are written as `NULL`. `createdAt` /
|
|
166
|
+
* `updatedAt` are filled when the model has timestamps. PostgreSQL extension.
|
|
167
|
+
*
|
|
168
|
+
* @param this - The model class.
|
|
169
|
+
* @param rows - Rows (array, iterable or async iterable of attribute values).
|
|
170
|
+
* @param options - `columns` (attribute names; default: keys of the first row of an array) and query options.
|
|
171
|
+
* @returns Number of copied rows.
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* const copied = await Task.copyFrom(
|
|
175
|
+
* [{ title: 'first' }, { title: 'second' }],
|
|
176
|
+
* { columns: ['title'] },
|
|
177
|
+
* );
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
copyFrom<M extends AnyModel>(this: ModelStatic<M>, rows: Iterable<CreationAttributes<M>> | AsyncIterable<CreationAttributes<M>>, options?: CopyFromOptions<Attributes<M>>): Promise<number>;
|
|
181
|
+
/**
|
|
182
|
+
* Streams `COPY (SELECT ...) TO STDOUT` output — the fastest way to export rows (e.g. CSV). Default
|
|
183
|
+
* scope, paranoid filter, `with` / `source` and includes apply. Values of the query are inlined as
|
|
184
|
+
* escaped literals because COPY cannot take parameters (ADR-013). Stopping early drains the rest
|
|
185
|
+
* before the connection is released. PostgreSQL extension.
|
|
186
|
+
*
|
|
187
|
+
* @param this - The model class.
|
|
188
|
+
* @param options - Find options and output format (`format`, `header`, ...).
|
|
189
|
+
* @returns Async iterator of raw output chunks.
|
|
190
|
+
* @example
|
|
191
|
+
* ```ts
|
|
192
|
+
* for await (const chunk of User.copyTo({ attributes: ['id', 'email'], format: 'csv', header: true })) {
|
|
193
|
+
* process.stdout.write(chunk);
|
|
194
|
+
* }
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
copyTo<M extends AnyModel>(this: ModelStatic<M>, options?: CopyToOptions<Attributes<M>>): AsyncGenerator<Buffer, void, undefined>;
|
|
198
|
+
} & TBase;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { AnyModel, ModelStatic } from '../options.ts';
|
|
2
|
+
import { ModelConstructor } from './model-constructor.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Schema binding static of `Model`: `schema`.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare const ModelSchemaBinding: <TBase extends ModelConstructor>(Base: TBase) => {
|
|
9
|
+
new (...args: any[]): {
|
|
10
|
+
get wasInserted(): boolean | undefined;
|
|
11
|
+
get oldValues(): Readonly<Record<string, unknown>> | null | undefined;
|
|
12
|
+
get sequelize(): import('../runtime.ts').RuntimeOwner;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Returns a model class whose queries target a PostgreSQL schema, like Sequelize v6.
|
|
16
|
+
*
|
|
17
|
+
* The copy has the attributes, hooks, scopes and associations of this model as they are at
|
|
18
|
+
* the time of the call and keeps the scope selection of this class. Changes made to the
|
|
19
|
+
* original afterwards are not seen by the copy.
|
|
20
|
+
*
|
|
21
|
+
* @param this - The model class being bound.
|
|
22
|
+
* @param schema - Schema name.
|
|
23
|
+
* @param options - Separator between schema and table reported by `getTableName` (a string,
|
|
24
|
+
* or `{ schemaDelimiter }`); PostgreSQL always qualifies with `.` in SQL. Defaults to `.`.
|
|
25
|
+
* @returns Schema-bound model class (instances are instances of this model).
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const TenantUser = User.schema('tenant_a');
|
|
29
|
+
* await TenantUser.findAll(); // SELECT ... FROM "tenant_a"."users"
|
|
30
|
+
* TenantUser.getTableName(); // { tableName: 'users', schema: 'tenant_a', delimiter: '.' }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
schema<MS extends ModelStatic<AnyModel>>(this: MS, schema: string, options?: string | Readonly<{
|
|
34
|
+
schemaDelimiter?: string;
|
|
35
|
+
}>): MS;
|
|
36
|
+
} & TBase;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { DropOptions, SyncOptions } from '../../query-interface/schema-synchronizer.ts';
|
|
2
|
+
import { AnyModel, ModelStatic } from '../options.ts';
|
|
3
|
+
import { QueryOptionsBase } from '../runtime.ts';
|
|
4
|
+
import { ModelConstructor } from './model-constructor.ts';
|
|
5
|
+
/**
|
|
6
|
+
* Schema statics of `Model`: `sync`, `drop`, `truncate`.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare const ModelSchema: <TBase extends ModelConstructor>(Base: TBase) => {
|
|
11
|
+
new (...args: any[]): {
|
|
12
|
+
get wasInserted(): boolean | undefined;
|
|
13
|
+
get oldValues(): Readonly<Record<string, unknown>> | null | undefined;
|
|
14
|
+
get sequelize(): import('../runtime.ts').RuntimeOwner;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Creates the table of this model and its indexes when missing. `force: true` drops it first
|
|
18
|
+
* (with `CASCADE`); `alter` changes an existing table to match the model.
|
|
19
|
+
*
|
|
20
|
+
* @param this - The model class.
|
|
21
|
+
* @param options - `force`, `alter`, `match`, `schema` and query options.
|
|
22
|
+
* @returns The model class.
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* await User.sync({ alter: true });
|
|
26
|
+
* ```
|
|
27
|
+
* @see [Schema guide](/guide/schema)
|
|
28
|
+
*/
|
|
29
|
+
sync<MS extends ModelStatic<AnyModel>>(this: MS, options?: SyncOptions): Promise<MS>;
|
|
30
|
+
/**
|
|
31
|
+
* Drops the table of this model and the enum types it owns.
|
|
32
|
+
*
|
|
33
|
+
* @param options - `cascade`, `schema` and query options.
|
|
34
|
+
* @returns Resolves when done.
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* await Task.drop({ cascade: true });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
drop(options?: DropOptions): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Removes all rows with `TRUNCATE`, without running hooks.
|
|
43
|
+
*
|
|
44
|
+
* @param options - `cascade`, `restartIdentity` and query options.
|
|
45
|
+
* @returns Resolves when done.
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* await Task.truncate({ restartIdentity: true, cascade: true });
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
truncate(options?: QueryOptionsBase & Readonly<{
|
|
52
|
+
cascade?: boolean;
|
|
53
|
+
restartIdentity?: boolean;
|
|
54
|
+
}>): Promise<void>;
|
|
55
|
+
} & TBase;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { AnyModel, ModelStatic } from '../options.ts';
|
|
2
|
+
import { ScopeDefinition, ScopeSelector } from '../scope-registry.ts';
|
|
3
|
+
import { ModelConstructor } from './model-constructor.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Scope statics of `Model`: `scope`, `unscoped`, `addScope`.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export declare const ModelScopes: <TBase extends ModelConstructor>(Base: TBase) => {
|
|
10
|
+
new (...args: any[]): {
|
|
11
|
+
get wasInserted(): boolean | undefined;
|
|
12
|
+
get oldValues(): Readonly<Record<string, unknown>> | null | undefined;
|
|
13
|
+
get sequelize(): import('../runtime.ts').RuntimeOwner;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Creates a model class that applies the given scopes to its queries instead of the default
|
|
17
|
+
* scope. The original class is not changed.
|
|
18
|
+
*
|
|
19
|
+
* @param this - The model class.
|
|
20
|
+
* @param selectors - Scope names, `{ method: [name, ...args] }`, inline options, `'defaultScope'`, or `null`.
|
|
21
|
+
* @returns Scoped model class (instances are instances of this model).
|
|
22
|
+
* @throws Error when a named scope does not exist.
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* await User.scope('active', { method: ['olderThan', 18] }).findAll();
|
|
26
|
+
* ```
|
|
27
|
+
* @see [Querying guide](/guide/querying)
|
|
28
|
+
*/
|
|
29
|
+
scope<MS extends ModelStatic<AnyModel>>(this: MS, ...selectors: readonly (ScopeSelector | readonly ScopeSelector[])[]): MS;
|
|
30
|
+
/**
|
|
31
|
+
* Creates a model class that applies no scope at all, not even the default scope.
|
|
32
|
+
*
|
|
33
|
+
* @param this - The model class.
|
|
34
|
+
* @returns Unscoped model class.
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* const everyone = await User.unscoped().findAll();
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
unscoped<MS extends ModelStatic<AnyModel>>(this: MS): MS;
|
|
41
|
+
/**
|
|
42
|
+
* Adds a named scope (or replaces the default scope with name `'defaultScope'`).
|
|
43
|
+
*
|
|
44
|
+
* @param name - Scope name.
|
|
45
|
+
* @param scope - Options or a function returning options.
|
|
46
|
+
* @param options - `override: true` replaces an existing scope.
|
|
47
|
+
* @throws Error when the scope exists and `override` is not set.
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* User.addScope('active', { where: { active: true } });
|
|
51
|
+
* User.addScope('olderThan', (age: number) => ({ where: { age: { [Op.gt]: age } } }));
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
addScope(name: string, scope: ScopeDefinition, options?: Readonly<{
|
|
55
|
+
override?: boolean;
|
|
56
|
+
}>): void;
|
|
57
|
+
} & TBase;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { AnyModel, AttributeAmounts, Attributes, BuildOptions, BulkCreateOptions, CreateOptions, CreationAttributes, DestroyOptions, IncrementOptions, ModelStatic, RestoreOptions, UpdateOptions, UpsertOptions, Values } from '../options.ts';
|
|
2
|
+
import { ModelConstructor } from './model-constructor.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Write statics of `Model`: `build`, `bulkBuild`, `create`, `bulkCreate`, `upsert`, `update`, `destroy`, `restore`, `increment`, `decrement`.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare const ModelWriters: <TBase extends ModelConstructor>(Base: TBase) => {
|
|
9
|
+
new (...args: any[]): {
|
|
10
|
+
get wasInserted(): boolean | undefined;
|
|
11
|
+
get oldValues(): Readonly<Record<string, unknown>> | null | undefined;
|
|
12
|
+
get sequelize(): import('../runtime.ts').RuntimeOwner;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Builds a new instance in memory without touching the database; call `save()` to insert it.
|
|
16
|
+
* Defaults and custom setters are applied.
|
|
17
|
+
*
|
|
18
|
+
* @param this - The model class.
|
|
19
|
+
* @param values - Attribute values.
|
|
20
|
+
* @param options - Build options.
|
|
21
|
+
* @returns New instance.
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* const user = User.build({ email: 'ada@example.com' });
|
|
25
|
+
* await user.save();
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
build<M extends AnyModel>(this: ModelStatic<M>, values?: CreationAttributes<M> | Values, options?: BuildOptions): M;
|
|
29
|
+
/**
|
|
30
|
+
* Builds several new instances in memory, same as calling {@link Model.build} for each record.
|
|
31
|
+
*
|
|
32
|
+
* @param this - The model class.
|
|
33
|
+
* @param records - Attribute values per instance.
|
|
34
|
+
* @param options - Build options.
|
|
35
|
+
* @returns New instances.
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* const tags = Tag.bulkBuild([{ name: 'news' }, { name: 'sports' }]);
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
bulkBuild<M extends AnyModel>(this: ModelStatic<M>, records: readonly (CreationAttributes<M> | Values)[], options?: BuildOptions): M[];
|
|
42
|
+
/**
|
|
43
|
+
* Builds an instance and inserts it with `INSERT ... RETURNING`, running validation and the
|
|
44
|
+
* create/save hooks. With `onConflict` (PostgreSQL extension) the insert may be skipped or turned
|
|
45
|
+
* into an update, and `instance.wasInserted` tells which happened.
|
|
46
|
+
*
|
|
47
|
+
* @param this - The model class.
|
|
48
|
+
* @param values - Attribute values.
|
|
49
|
+
* @param options - Create options (`fields`, `hooks`, `validate`, `include`, `onConflict`, query options).
|
|
50
|
+
* @returns Saved instance.
|
|
51
|
+
* @throws ValidationError when validation fails.
|
|
52
|
+
* @throws UniqueConstraintError when a unique constraint is violated.
|
|
53
|
+
* @throws ForeignKeyConstraintError when a foreign key constraint is violated.
|
|
54
|
+
* @throws DatabaseError for other database errors.
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* const user = await User.create({ email: 'ada@example.com' }, { transaction });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
create<M extends AnyModel>(this: ModelStatic<M>, values?: CreationAttributes<M>, options?: CreateOptions<Attributes<M>>): Promise<M>;
|
|
61
|
+
/**
|
|
62
|
+
* Inserts many rows with one multi-row `INSERT ... RETURNING`. Runs `beforeBulkCreate` and
|
|
63
|
+
* `afterBulkCreate` hooks; rows are not validated unless `validate: true`. `ignoreDuplicates`,
|
|
64
|
+
* `updateOnDuplicate` and `onConflict` map to `ON CONFLICT`; `individualHooks` or `include`
|
|
65
|
+
* insert row by row like Sequelize v6.
|
|
66
|
+
*
|
|
67
|
+
* @param this - The model class.
|
|
68
|
+
* @param records - Attribute values per row.
|
|
69
|
+
* @param options - Bulk create options.
|
|
70
|
+
* @returns Instances with values returned by the database.
|
|
71
|
+
* @throws ValidationError with `validate: true` when a row is invalid.
|
|
72
|
+
* @throws UniqueConstraintError when a unique constraint is violated and no conflict handling is set.
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* const tags = await Tag.bulkCreate([{ name: 'news' }, { name: 'sports' }], { ignoreDuplicates: true });
|
|
76
|
+
* ```
|
|
77
|
+
* @see {@link Model.insert} for the PostgreSQL variant that returns only the rows actually written.
|
|
78
|
+
*/
|
|
79
|
+
bulkCreate<M extends AnyModel>(this: ModelStatic<M>, records: readonly CreationAttributes<M>[], options?: BulkCreateOptions<Attributes<M>>): Promise<M[]>;
|
|
80
|
+
/**
|
|
81
|
+
* Inserts a row, or updates it when it conflicts with a unique key (`INSERT ... ON CONFLICT DO UPDATE`,
|
|
82
|
+
* Sequelize v6 `upsert`). Runs the `beforeUpsert` and `afterUpsert` hooks.
|
|
83
|
+
*
|
|
84
|
+
* @param this - The model class.
|
|
85
|
+
* @param values - Attribute values.
|
|
86
|
+
* @param options - Upsert options (`conflictFields`, `fields`, `onConflict`, query options).
|
|
87
|
+
* @returns `[instance, null]` like Sequelize v6, or `[instance, created]` with `onConflict`.
|
|
88
|
+
* @throws ValidationError when validation fails.
|
|
89
|
+
* @throws UniqueConstraintError when a unique constraint other than the conflict target is violated.
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* const [user] = await User.upsert({ email: 'ada@example.com', name: 'Ada' }, { conflictFields: ['email'] });
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
upsert<M extends AnyModel>(this: ModelStatic<M>, values: CreationAttributes<M>, options?: UpsertOptions<Attributes<M>>): Promise<[M, boolean | null]>;
|
|
96
|
+
/**
|
|
97
|
+
* Updates all rows matching `where` with one `UPDATE` and refreshes `updatedAt` unless `silent`.
|
|
98
|
+
* Values are validated unless `validate: false`; bulk hooks run unless `hooks: false`.
|
|
99
|
+
*
|
|
100
|
+
* @param this - The model class.
|
|
101
|
+
* @param values - New attribute values.
|
|
102
|
+
* @param options - Update options; `where` is required.
|
|
103
|
+
* @returns `[affectedCount]`, or `[affectedCount, rows]` with `returning: true`.
|
|
104
|
+
* @throws ValidationError when the new values are invalid.
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* const [count] = await Post.update({ published: true }, { where: { userId: 1 } });
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
update<M extends AnyModel>(this: ModelStatic<M>, values: Partial<Attributes<M>>, options: UpdateOptions<Attributes<M>>): Promise<[affectedCount: number, affectedRows?: M[]]>;
|
|
111
|
+
/**
|
|
112
|
+
* Deletes rows matching `where` and returns the deleted instances (`DELETE ... RETURNING`, a
|
|
113
|
+
* PostgreSQL extension). For paranoid models the rows are soft-deleted unless `force: true`.
|
|
114
|
+
*
|
|
115
|
+
* @param this - The model class.
|
|
116
|
+
* @param options - Destroy options with `returning: true`.
|
|
117
|
+
* @returns Deleted instances.
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* const removed = await Post.destroy({ where: { published: false }, returning: true });
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
destroy<M extends AnyModel>(this: ModelStatic<M>, options: DestroyOptions<Attributes<M>> & Readonly<{
|
|
124
|
+
returning: true;
|
|
125
|
+
}>): Promise<M[]>;
|
|
126
|
+
/**
|
|
127
|
+
* Deletes rows matching `where` (`truncate: true` empties the table instead). For paranoid models
|
|
128
|
+
* the rows are soft-deleted (`deletedAt` is set) unless `force: true`. Runs bulk destroy hooks
|
|
129
|
+
* unless `hooks: false`.
|
|
130
|
+
*
|
|
131
|
+
* @param this - The model class.
|
|
132
|
+
* @param options - Destroy options.
|
|
133
|
+
* @returns Number of deleted rows.
|
|
134
|
+
*/
|
|
135
|
+
destroy<M extends AnyModel>(this: ModelStatic<M>, options?: DestroyOptions<Attributes<M>>): Promise<number>;
|
|
136
|
+
/**
|
|
137
|
+
* Restores soft-deleted rows of a paranoid model by setting `deletedAt` back to `NULL`.
|
|
138
|
+
*
|
|
139
|
+
* @param this - The model class.
|
|
140
|
+
* @param options - Rows to restore and hook options.
|
|
141
|
+
* @returns Resolves when done.
|
|
142
|
+
* @throws Error when the model is not paranoid.
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* await Post.restore({ where: { userId: 1 } });
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
restore<M extends AnyModel>(this: ModelStatic<M>, options?: RestoreOptions<Attributes<M>>): Promise<void>;
|
|
149
|
+
/**
|
|
150
|
+
* Atomically increments numeric attributes of the rows matching `where` (`SET x = x + by`).
|
|
151
|
+
*
|
|
152
|
+
* @param this - The model class.
|
|
153
|
+
* @param fields - Attribute name(s), or a map of attribute to amount.
|
|
154
|
+
* @param options - Increment options (`where`, `by` default 1, `silent`, query options).
|
|
155
|
+
* @returns `[affectedRows, affectedCount]`: the updated instances and their number.
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* await Post.increment('views', { by: 1, where: { id: 5 } });
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
increment<M extends AnyModel>(this: ModelStatic<M>, fields: AttributeAmounts<Attributes<M>>, options?: IncrementOptions<Attributes<M>>): Promise<[affectedRows: M[], affectedCount: number]>;
|
|
162
|
+
/**
|
|
163
|
+
* Atomically decrements numeric attributes of the rows matching `where` (`SET x = x - by`).
|
|
164
|
+
*
|
|
165
|
+
* @param this - The model class.
|
|
166
|
+
* @param fields - Attribute name(s), or a map of attribute to amount.
|
|
167
|
+
* @param options - Decrement options (`where`, `by` default 1, `silent`, query options).
|
|
168
|
+
* @returns `[affectedRows, affectedCount]`: the updated instances and their number.
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* await Product.decrement({ stock: 3 }, { where: { id: 7 } });
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
decrement<M extends AnyModel>(this: ModelStatic<M>, fields: AttributeAmounts<Attributes<M>>, options?: IncrementOptions<Attributes<M>>): Promise<[affectedRows: M[], affectedCount: number]>;
|
|
175
|
+
} & TBase;
|