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,47 @@
|
|
|
1
|
+
import { AttributeDefinition, ModelDefinition } from '../model/model-definition.ts';
|
|
2
|
+
import { AnyModel, ModelStatic } from '../model/options.ts';
|
|
3
|
+
import { IncludeNode } from './include.ts';
|
|
4
|
+
type Model = ModelStatic<AnyModel>;
|
|
5
|
+
/** Result row keyed by column alias (`Posts.title` for included columns). */
|
|
6
|
+
export type IncludeRow = Readonly<Record<string, unknown>>;
|
|
7
|
+
/** Builds an instance of `model` from loaded values. */
|
|
8
|
+
export type InstanceBuilder = (model: Model, values: Readonly<Record<string, unknown>>) => AnyModel;
|
|
9
|
+
/** Reads and parses the values of included models out of joined result rows. */
|
|
10
|
+
export declare class IncludeRows {
|
|
11
|
+
#private;
|
|
12
|
+
/**
|
|
13
|
+
* Value parsed with an attribute's data type.
|
|
14
|
+
*
|
|
15
|
+
* @param attribute - Attribute definition, if known.
|
|
16
|
+
* @param value - Raw value.
|
|
17
|
+
* @returns Parsed value (`null` / `undefined` are kept).
|
|
18
|
+
*/
|
|
19
|
+
parseValue(attribute: AttributeDefinition | undefined, value: unknown): unknown;
|
|
20
|
+
/**
|
|
21
|
+
* Values of the columns directly under `path` (`Posts.title` → `title`), parsed.
|
|
22
|
+
*
|
|
23
|
+
* @param definition - Definition of the included model.
|
|
24
|
+
* @param row - Joined row.
|
|
25
|
+
* @param path - Result path of the include.
|
|
26
|
+
* @returns Attribute values.
|
|
27
|
+
*/
|
|
28
|
+
valuesAt(definition: ModelDefinition, row: IncludeRow, path: string): Record<string, unknown>;
|
|
29
|
+
/**
|
|
30
|
+
* Identity of an instance for de-duplication: its primary key, else all values.
|
|
31
|
+
*
|
|
32
|
+
* @param definition - Model definition.
|
|
33
|
+
* @param values - Attribute values.
|
|
34
|
+
* @returns Identity, or `undefined` when every value is `null` (no row joined).
|
|
35
|
+
*/
|
|
36
|
+
identity(definition: ModelDefinition, values: Readonly<Record<string, unknown>>): string | number | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Parses a joined raw row: included keys are parsed with the included model's data types.
|
|
39
|
+
*
|
|
40
|
+
* @param includes - Include tree.
|
|
41
|
+
* @param row - Joined row.
|
|
42
|
+
* @param parseMain - Parses a row with the main model's data types; must return a new object.
|
|
43
|
+
* @returns Parsed row.
|
|
44
|
+
*/
|
|
45
|
+
parseRaw(includes: readonly IncludeNode[], row: IncludeRow, parseMain: (row: IncludeRow) => Readonly<Record<string, unknown>>): Record<string, unknown>;
|
|
46
|
+
}
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ModelDefinition } from '../model/model-definition.ts';
|
|
2
|
+
import { ExprNode } from '../sql/ast.ts';
|
|
3
|
+
import { IncludeNode } from './include.ts';
|
|
4
|
+
import { IncludeJoins } from './include-joins.ts';
|
|
5
|
+
/** Decides the v6 sub-query form of a find with includes and builds its `EXISTS` filters. */
|
|
6
|
+
export declare class IncludeSubQuery {
|
|
7
|
+
#private;
|
|
8
|
+
/**
|
|
9
|
+
* @param joins - Builds the joins the `EXISTS` filters are made of.
|
|
10
|
+
*/
|
|
11
|
+
constructor(joins: IncludeJoins);
|
|
12
|
+
/**
|
|
13
|
+
* Whether `limit`/`offset` must go into a subquery of the main table (v6 rules). A top-level
|
|
14
|
+
* `where` that references a joined include cannot run inside that subquery, so it disables it.
|
|
15
|
+
*
|
|
16
|
+
* @param includes - Joined includes.
|
|
17
|
+
* @param options - Limit / offset / subQuery of the find.
|
|
18
|
+
* @param where - Compiled top-level condition.
|
|
19
|
+
* @returns True for the sub-query form.
|
|
20
|
+
*/
|
|
21
|
+
needsSubQuery(includes: readonly IncludeNode[], options: Readonly<{
|
|
22
|
+
limit?: number | null;
|
|
23
|
+
offset?: number | null;
|
|
24
|
+
subQuery?: boolean;
|
|
25
|
+
}>, where?: ExprNode): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* `EXISTS` condition that keeps the rows of the main table having a matching required include.
|
|
28
|
+
*
|
|
29
|
+
* @param parent - Main model definition.
|
|
30
|
+
* @param parentAlias - Main table alias.
|
|
31
|
+
* @param node - Required include.
|
|
32
|
+
* @returns Condition.
|
|
33
|
+
*/
|
|
34
|
+
existsFilter(parent: ModelDefinition, parentAlias: string, node: IncludeNode): ExprNode;
|
|
35
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { ModelDefinition } from '../model/model-definition.ts';
|
|
2
|
+
import { AnyModel, ModelStatic } from '../model/options.ts';
|
|
3
|
+
import { FindAttributeOptions } from '../model/select-query-builder.ts';
|
|
4
|
+
import { Association } from './types.ts';
|
|
5
|
+
type Model = ModelStatic<AnyModel>;
|
|
6
|
+
/**
|
|
7
|
+
* Options of the junction table of an included belongsToMany association.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const through: IncludeThroughOptions = { attributes: ['role'], where: { role: 'owner' } };
|
|
12
|
+
* const rows = await Project.findAll({ include: [{ model: User, through }] });
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export type IncludeThroughOptions = Readonly<{
|
|
16
|
+
/** Junction attributes to select (`[]` for none). Default: all. */
|
|
17
|
+
attributes?: FindAttributeOptions;
|
|
18
|
+
/** Filter on junction rows; see {@link WhereOptions}. */
|
|
19
|
+
where?: unknown;
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* One `include` entry (Sequelize v6 `IncludeOptions`): which association to load and how.
|
|
23
|
+
*
|
|
24
|
+
* Name the association with `model`, `as` or `association`. Eager loading uses JOINs (see the guide), except `separate`, which runs another query.
|
|
25
|
+
*
|
|
26
|
+
* @see {@link FindOptions}
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const opts: IncludeOptions = {
|
|
31
|
+
* model: Post,
|
|
32
|
+
* as: 'posts',
|
|
33
|
+
* where: { published: true },
|
|
34
|
+
* required: false,
|
|
35
|
+
* attributes: ['id', 'title'],
|
|
36
|
+
* include: [{ model: Tag }],
|
|
37
|
+
* };
|
|
38
|
+
* const users = await User.findAll({ include: [opts] });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export type IncludeOptions = Readonly<{
|
|
42
|
+
/** Associated model; the association is looked up by model (and `as`). */
|
|
43
|
+
model?: Model;
|
|
44
|
+
/** Alias of the association, as given when it was defined. */
|
|
45
|
+
as?: string;
|
|
46
|
+
/** Association object or alias. */
|
|
47
|
+
association?: Association | string;
|
|
48
|
+
/** Filter on the included rows; makes the include required unless `required: false`. See {@link WhereOptions}. */
|
|
49
|
+
where?: unknown;
|
|
50
|
+
/** `INNER JOIN` (true) or `LEFT OUTER JOIN` (false). */
|
|
51
|
+
required?: boolean;
|
|
52
|
+
/** Use `RIGHT OUTER JOIN`.
|
|
53
|
+
* @defaultValue false */
|
|
54
|
+
right?: boolean;
|
|
55
|
+
/** Selected attributes. */
|
|
56
|
+
attributes?: FindAttributeOptions;
|
|
57
|
+
/** Nested includes. */
|
|
58
|
+
include?: IncludeOption;
|
|
59
|
+
/** Load a hasMany association with a separate query instead of a JOIN.
|
|
60
|
+
* @defaultValue false */
|
|
61
|
+
separate?: boolean;
|
|
62
|
+
/** Junction options for belongsToMany. */
|
|
63
|
+
through?: IncludeThroughOptions;
|
|
64
|
+
/**
|
|
65
|
+
* Fetch only the first `limit` rows per parent in the database (`JOIN LATERAL` over the parent
|
|
66
|
+
* keys) instead of loading every child and trimming in memory. Needs `separate` and `limit`.
|
|
67
|
+
* PostgreSQL extension.
|
|
68
|
+
*
|
|
69
|
+
* @defaultValue false
|
|
70
|
+
*/
|
|
71
|
+
lateral?: boolean;
|
|
72
|
+
/** Order of a separate include. */
|
|
73
|
+
order?: unknown;
|
|
74
|
+
/** Maximum rows per include of a separate include. */
|
|
75
|
+
limit?: number;
|
|
76
|
+
/** For paranoid targets: `false` includes soft-deleted rows.
|
|
77
|
+
* @defaultValue true */
|
|
78
|
+
paranoid?: boolean;
|
|
79
|
+
/** Include every association of the model (`{ all: true }`).
|
|
80
|
+
* @defaultValue false */
|
|
81
|
+
all?: boolean;
|
|
82
|
+
}>;
|
|
83
|
+
/** `include` option: a model, an alias, include options, or a list of them. */
|
|
84
|
+
export type IncludeOption = Model | string | IncludeOptions | readonly (Model | string | IncludeOptions)[];
|
|
85
|
+
/** Normalized include. */
|
|
86
|
+
export type IncludeNode = Readonly<{
|
|
87
|
+
association: Association;
|
|
88
|
+
model: Model;
|
|
89
|
+
definition: ModelDefinition;
|
|
90
|
+
as: string;
|
|
91
|
+
alias: string;
|
|
92
|
+
path: string;
|
|
93
|
+
where: unknown;
|
|
94
|
+
required: boolean;
|
|
95
|
+
right: boolean;
|
|
96
|
+
attributes: FindAttributeOptions | undefined;
|
|
97
|
+
separate: boolean;
|
|
98
|
+
lateral: boolean;
|
|
99
|
+
paranoid: boolean;
|
|
100
|
+
order: unknown;
|
|
101
|
+
limit: number | undefined;
|
|
102
|
+
through: Readonly<{
|
|
103
|
+
model: Model;
|
|
104
|
+
definition: ModelDefinition;
|
|
105
|
+
alias: string;
|
|
106
|
+
path: string;
|
|
107
|
+
attributes: FindAttributeOptions | undefined;
|
|
108
|
+
where: unknown;
|
|
109
|
+
}> | undefined;
|
|
110
|
+
children: readonly IncludeNode[];
|
|
111
|
+
}>;
|
|
112
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AnyModel, ModelStatic } from '../model/options.ts';
|
|
2
|
+
import { AssociationKeys, TargetKeys } from './association-keys.ts';
|
|
3
|
+
import { BelongsToManyOptions } from './types.ts';
|
|
4
|
+
type Model = ModelStatic<AnyModel>;
|
|
5
|
+
/** Resolves alias and keys of belongsToMany and defines the junction model's key attributes. */
|
|
6
|
+
export declare class JunctionKeys {
|
|
7
|
+
#private;
|
|
8
|
+
/**
|
|
9
|
+
* @param keys - Naming and foreign key attribute rules.
|
|
10
|
+
*/
|
|
11
|
+
constructor(keys: AssociationKeys);
|
|
12
|
+
/**
|
|
13
|
+
* Resolves the alias and keys of a belongsToMany association, creating the junction model
|
|
14
|
+
* when given by name and adding both foreign key attributes to it.
|
|
15
|
+
*
|
|
16
|
+
* @param source - Model the association is defined on.
|
|
17
|
+
* @param target - Associated model.
|
|
18
|
+
* @param options - Association options with `through`.
|
|
19
|
+
* @returns Alias forms and keys (including the junction).
|
|
20
|
+
*/
|
|
21
|
+
resolve(source: Model, target: Model, options: BelongsToManyOptions): TargetKeys;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { AnyModel, SaveOptions } from '../model/options.ts';
|
|
2
|
+
import { IncludeNode } from './include.ts';
|
|
3
|
+
import { IncludeResolver } from './include-resolver.ts';
|
|
4
|
+
import { InstanceCheck } from './nested-saver.ts';
|
|
5
|
+
export type { InstanceCheck } from './nested-saver.ts';
|
|
6
|
+
/**
|
|
7
|
+
* Nested creation (`Model.create(values, { include })`, Sequelize v6): builds nested instances
|
|
8
|
+
* from the values, saves belongsTo parents before the instance and hasOne / hasMany /
|
|
9
|
+
* belongsToMany children (with their junction rows) after it.
|
|
10
|
+
*/
|
|
11
|
+
export declare class NestedCreator {
|
|
12
|
+
#private;
|
|
13
|
+
/**
|
|
14
|
+
* @param resolver - Converts include nodes back to options for the nested builds.
|
|
15
|
+
* @param isInstance - Checks whether a value is a model instance.
|
|
16
|
+
*/
|
|
17
|
+
constructor(resolver: IncludeResolver, isInstance: InstanceCheck);
|
|
18
|
+
/**
|
|
19
|
+
* Builds the nested instance(s) of an include from the given values; instances are kept.
|
|
20
|
+
*
|
|
21
|
+
* @param node - Include node.
|
|
22
|
+
* @param value - Values (a list for multi associations), an instance, or `null`.
|
|
23
|
+
* @returns Nested instance(s), or `null`.
|
|
24
|
+
*/
|
|
25
|
+
build(node: IncludeNode, value: unknown): unknown;
|
|
26
|
+
/**
|
|
27
|
+
* Saves nested belongsTo parents and sets the foreign keys on the instance.
|
|
28
|
+
*
|
|
29
|
+
* @param instance - Instance being created.
|
|
30
|
+
* @param includes - Include tree of the instance.
|
|
31
|
+
* @param options - Save options (query options are passed on).
|
|
32
|
+
* @returns Resolves when the parents are saved.
|
|
33
|
+
*/
|
|
34
|
+
saveBelongsTo(instance: AnyModel, includes: readonly IncludeNode[], options: SaveOptions): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Saves nested hasOne / hasMany / belongsToMany children after the instance, one at a time.
|
|
37
|
+
*
|
|
38
|
+
* @param instance - Saved instance.
|
|
39
|
+
* @param includes - Include tree of the instance.
|
|
40
|
+
* @param options - Save options (query options are passed on).
|
|
41
|
+
* @returns Resolves when the children are saved.
|
|
42
|
+
*/
|
|
43
|
+
saveChildren(instance: AnyModel, includes: readonly IncludeNode[], options: SaveOptions): Promise<void>;
|
|
44
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AnyModel, SaveOptions } from '../model/options.ts';
|
|
2
|
+
import { IncludeNode } from './include.ts';
|
|
3
|
+
/** Tells model instances apart from plain values (injected to avoid importing `Model`). */
|
|
4
|
+
export type InstanceCheck = (value: unknown) => value is AnyModel;
|
|
5
|
+
/** Saves the nested instances of a nested creation, in the order Sequelize v6 does. */
|
|
6
|
+
export declare class NestedSaver {
|
|
7
|
+
#private;
|
|
8
|
+
/**
|
|
9
|
+
* @param isInstance - Checks whether a value is a model instance.
|
|
10
|
+
*/
|
|
11
|
+
constructor(isInstance: InstanceCheck);
|
|
12
|
+
/**
|
|
13
|
+
* Saves nested belongsTo parents and sets the foreign keys on the instance.
|
|
14
|
+
*
|
|
15
|
+
* @param instance - Instance being created.
|
|
16
|
+
* @param includes - Include tree of the instance.
|
|
17
|
+
* @param options - Save options (query options are passed on).
|
|
18
|
+
* @returns Resolves when the parents are saved.
|
|
19
|
+
*/
|
|
20
|
+
saveBelongsTo(instance: AnyModel, includes: readonly IncludeNode[], options: SaveOptions): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Saves nested hasOne / hasMany / belongsToMany children after the instance, one at a time.
|
|
23
|
+
*
|
|
24
|
+
* @param instance - Saved instance.
|
|
25
|
+
* @param includes - Include tree of the instance.
|
|
26
|
+
* @param options - Save options (query options are passed on).
|
|
27
|
+
* @returns Resolves when the children are saved.
|
|
28
|
+
*/
|
|
29
|
+
saveChildren(instance: AnyModel, includes: readonly IncludeNode[], options: SaveOptions): Promise<void>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AnyModel, ModelStatic } from '../model/options.ts';
|
|
2
|
+
import { AssociationKeys, TargetKeys } from './association-keys.ts';
|
|
3
|
+
import { AssociationOptions } from './types.ts';
|
|
4
|
+
type Model = ModelStatic<AnyModel>;
|
|
5
|
+
/** Resolves alias and keys of belongsTo / hasOne / hasMany and adds the foreign key attribute. */
|
|
6
|
+
export declare class OwnerKeys {
|
|
7
|
+
#private;
|
|
8
|
+
/**
|
|
9
|
+
* @param keys - Naming and foreign key attribute rules.
|
|
10
|
+
*/
|
|
11
|
+
constructor(keys: AssociationKeys);
|
|
12
|
+
/**
|
|
13
|
+
* Resolves the alias and keys of a belongsTo association and adds the foreign key attribute
|
|
14
|
+
* to the source.
|
|
15
|
+
*
|
|
16
|
+
* @param source - Model the association is defined on.
|
|
17
|
+
* @param target - Associated model.
|
|
18
|
+
* @param options - Association options.
|
|
19
|
+
* @returns Alias forms and keys.
|
|
20
|
+
*/
|
|
21
|
+
belongsTo(source: Model, target: Model, options: AssociationOptions): TargetKeys;
|
|
22
|
+
/**
|
|
23
|
+
* Resolves the alias and keys of a hasOne / hasMany association and adds the foreign key
|
|
24
|
+
* attribute to the target.
|
|
25
|
+
*
|
|
26
|
+
* @param multi - True for hasMany.
|
|
27
|
+
* @param source - Model the association is defined on.
|
|
28
|
+
* @param target - Associated model.
|
|
29
|
+
* @param options - Association options.
|
|
30
|
+
* @returns Alias forms and keys.
|
|
31
|
+
*/
|
|
32
|
+
hasOneOrMany(multi: boolean, source: Model, target: Model, options: AssociationOptions): TargetKeys;
|
|
33
|
+
}
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AnyModel } from '../model/options.ts';
|
|
2
|
+
import { IncludeNode } from './include.ts';
|
|
3
|
+
import { IncludeResolver } from './include-resolver.ts';
|
|
4
|
+
type Instance = AnyModel;
|
|
5
|
+
type FindOptions = Readonly<Record<string, unknown>>;
|
|
6
|
+
/** Loads `separate: true` includes with one extra query each. */
|
|
7
|
+
export declare class SeparateIncludeLoader {
|
|
8
|
+
#private;
|
|
9
|
+
/**
|
|
10
|
+
* @param resolver - Converts include nodes back to options for the separate queries.
|
|
11
|
+
*/
|
|
12
|
+
constructor(resolver: IncludeResolver);
|
|
13
|
+
/**
|
|
14
|
+
* Loads `separate: true` includes with one extra query each and attaches them, keeping at most
|
|
15
|
+
* `limit` rows per parent.
|
|
16
|
+
*
|
|
17
|
+
* @param parents - Instances the includes belong to.
|
|
18
|
+
* @param includes - Include tree.
|
|
19
|
+
* @param options - Find options (`transaction` is passed on).
|
|
20
|
+
* @returns Resolves when all separate includes are attached.
|
|
21
|
+
*/
|
|
22
|
+
load(parents: readonly Instance[], includes: readonly IncludeNode[], options: FindOptions): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { AnyModel, ModelStatic } from '../model/options.ts';
|
|
2
|
+
/** Kind of association (Sequelize v6 `associationType`). */
|
|
3
|
+
export type AssociationType = 'BelongsTo' | 'HasOne' | 'HasMany' | 'BelongsToMany';
|
|
4
|
+
/** Singular and plural names of an association alias. */
|
|
5
|
+
export type AssociationName = Readonly<{
|
|
6
|
+
/** Singular form, used by single-item accessors (`addPost`). */
|
|
7
|
+
singular: string;
|
|
8
|
+
/** Plural form, used by multi-item accessors (`getPosts`). */
|
|
9
|
+
plural: string;
|
|
10
|
+
}>;
|
|
11
|
+
/**
|
|
12
|
+
* Foreign key given as an object instead of a plain name.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const fk: ForeignKeyOptions = { name: 'authorId', field: 'author_id', allowNull: false };
|
|
17
|
+
* User.hasMany(Post, { foreignKey: fk });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export type ForeignKeyOptions = Readonly<{
|
|
21
|
+
/** Attribute name. */
|
|
22
|
+
name?: string;
|
|
23
|
+
/** Column name. */
|
|
24
|
+
field?: string;
|
|
25
|
+
/** Whether the key may be `NULL`. */
|
|
26
|
+
allowNull?: boolean;
|
|
27
|
+
}>;
|
|
28
|
+
/**
|
|
29
|
+
* Options shared by all association methods (Sequelize v6 `AssociationOptions`).
|
|
30
|
+
*
|
|
31
|
+
* Used by `hasOne`, `hasMany`, `belongsTo` and (extended) `belongsToMany`.
|
|
32
|
+
*
|
|
33
|
+
* @see {@link Model.hasMany}
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* const opts: AssociationOptions = {
|
|
38
|
+
* as: 'posts',
|
|
39
|
+
* foreignKey: { name: 'authorId', allowNull: false },
|
|
40
|
+
* onDelete: 'CASCADE',
|
|
41
|
+
* };
|
|
42
|
+
* User.hasMany(Post, opts);
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export type AssociationOptions = Readonly<{
|
|
46
|
+
/** Alias: string, or `{ singular, plural }` for multi associations. Default: the target model name. */
|
|
47
|
+
as?: string | AssociationName;
|
|
48
|
+
/** Foreign key attribute name or options. */
|
|
49
|
+
foreignKey?: string | ForeignKeyOptions;
|
|
50
|
+
/** Attribute of the source referenced by the foreign key (hasOne / hasMany / belongsToMany). */
|
|
51
|
+
sourceKey?: string;
|
|
52
|
+
/** Attribute of the target referenced by the foreign key (belongsTo / belongsToMany). */
|
|
53
|
+
targetKey?: string;
|
|
54
|
+
/** Attribute values applied to associated rows (filter on read, values on write). */
|
|
55
|
+
scope?: Readonly<Record<string, unknown>>;
|
|
56
|
+
/** Create foreign key constraints on `sync()`.
|
|
57
|
+
* @defaultValue true */
|
|
58
|
+
constraints?: boolean;
|
|
59
|
+
/** `ON DELETE` action of the foreign key constraint, e.g. `'CASCADE'`. */
|
|
60
|
+
onDelete?: string;
|
|
61
|
+
/** `ON UPDATE` action of the foreign key constraint, e.g. `'CASCADE'`. */
|
|
62
|
+
onUpdate?: string;
|
|
63
|
+
}>;
|
|
64
|
+
/**
|
|
65
|
+
* Junction table of a belongsToMany association given as an object.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* const through: ThroughOptions = { model: 'ProjectTask', scope: { kind: 'member' } };
|
|
70
|
+
* Project.belongsToMany(Task, { through });
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export type ThroughOptions = Readonly<{
|
|
74
|
+
/** Junction model, or the name of an implicit junction model to create. */
|
|
75
|
+
model: string | ModelStatic<AnyModel>;
|
|
76
|
+
/** Attribute values applied to junction rows. */
|
|
77
|
+
scope?: Readonly<Record<string, unknown>>;
|
|
78
|
+
}>;
|
|
79
|
+
/**
|
|
80
|
+
* Options of `belongsToMany`.
|
|
81
|
+
*
|
|
82
|
+
* Extends {@link AssociationOptions}; `foreignKey` is the junction column pointing at the source, `otherKey` the one pointing at the target.
|
|
83
|
+
*
|
|
84
|
+
* @see {@link Model.belongsToMany}
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* const opts: BelongsToManyOptions = { through: 'ProjectTask', foreignKey: 'projectId', otherKey: 'taskId' };
|
|
89
|
+
* Project.belongsToMany(Task, opts);
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export type BelongsToManyOptions = AssociationOptions & Readonly<{
|
|
93
|
+
/** Junction model, its name, or options. */
|
|
94
|
+
through: string | ModelStatic<AnyModel> | ThroughOptions;
|
|
95
|
+
/** Junction foreign key pointing at the target. Default: derived from the target model name. */
|
|
96
|
+
otherKey?: string | ForeignKeyOptions;
|
|
97
|
+
}>;
|
|
98
|
+
/** Resolved junction of a belongsToMany association. */
|
|
99
|
+
export type AssociationThrough = Readonly<{
|
|
100
|
+
/** Junction model. */
|
|
101
|
+
model: ModelStatic<AnyModel>;
|
|
102
|
+
/** Attribute values applied to junction rows. */
|
|
103
|
+
scope?: Readonly<Record<string, unknown>>;
|
|
104
|
+
}>;
|
|
105
|
+
/** Association between two models (Sequelize v6 association object). */
|
|
106
|
+
export type Association = Readonly<{
|
|
107
|
+
/** Kind of association. */
|
|
108
|
+
associationType: AssociationType;
|
|
109
|
+
/** Model the association is defined on. */
|
|
110
|
+
source: ModelStatic<AnyModel>;
|
|
111
|
+
/** Associated model. */
|
|
112
|
+
target: ModelStatic<AnyModel>;
|
|
113
|
+
/** Alias used in `include` and as the instance property. */
|
|
114
|
+
as: string;
|
|
115
|
+
/** Singular and plural alias forms. */
|
|
116
|
+
name: AssociationName;
|
|
117
|
+
/** Whether `as` was given explicitly. */
|
|
118
|
+
isAliased: boolean;
|
|
119
|
+
/** Foreign key attribute (on the source for belongsTo, on the target for hasOne/hasMany, on the junction for belongsToMany). */
|
|
120
|
+
foreignKey: string;
|
|
121
|
+
/** Column of the foreign key. */
|
|
122
|
+
identifierField: string;
|
|
123
|
+
/** Source attribute referenced by the foreign key. */
|
|
124
|
+
sourceKey: string;
|
|
125
|
+
/** Target attribute referenced by the foreign key (belongsTo) or by `otherKey` (belongsToMany). */
|
|
126
|
+
targetKey: string;
|
|
127
|
+
/** Junction foreign key pointing at the target (belongsToMany). */
|
|
128
|
+
otherKey: string | undefined;
|
|
129
|
+
/** Junction model (belongsToMany). */
|
|
130
|
+
through: AssociationThrough | undefined;
|
|
131
|
+
/** Association scope. */
|
|
132
|
+
scope: Readonly<Record<string, unknown>> | undefined;
|
|
133
|
+
/** True for belongsTo / hasOne. */
|
|
134
|
+
isSingleAssociation: boolean;
|
|
135
|
+
/** True for hasMany / belongsToMany. */
|
|
136
|
+
isMultiAssociation: boolean;
|
|
137
|
+
/** Names of the instance methods added to the source model. */
|
|
138
|
+
accessors: Readonly<Record<string, string>>;
|
|
139
|
+
}>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { PoolConfig } from 'pg';
|
|
2
|
+
import { ConnectionConfig as ConnectionSettings, SequelizeOptions } from './options.ts';
|
|
3
|
+
type ConstructorArgs = readonly [SequelizeOptions?] | readonly [string, SequelizeOptions?] | readonly [string, string | null | undefined, (string | null | undefined)?, SequelizeOptions?];
|
|
4
|
+
/**
|
|
5
|
+
* Connection configuration of a `Sequelize` instance: normalizes the overloaded Sequelize v6
|
|
6
|
+
* constructor arguments and derives the `pg` pool configurations (writer and read replicas).
|
|
7
|
+
*/
|
|
8
|
+
export declare class ConnectionConfig {
|
|
9
|
+
#private;
|
|
10
|
+
/** Normalized constructor options. */
|
|
11
|
+
readonly options: SequelizeOptions;
|
|
12
|
+
/**
|
|
13
|
+
* @param args - Arguments of the `Sequelize` constructor (URI, database / username / password, options).
|
|
14
|
+
* @throws Error for a non-postgres URI or dialect.
|
|
15
|
+
*/
|
|
16
|
+
constructor(args: ConstructorArgs);
|
|
17
|
+
/**
|
|
18
|
+
* Connection settings exposed as `sequelize.config`.
|
|
19
|
+
*
|
|
20
|
+
* @returns Database, user name, password, host and port.
|
|
21
|
+
*/
|
|
22
|
+
settings(): ConnectionSettings;
|
|
23
|
+
/**
|
|
24
|
+
* Pool configurations of the writer and the readers (no readers without `replication`).
|
|
25
|
+
*
|
|
26
|
+
* @returns Writer and reader `pg` pool configurations.
|
|
27
|
+
*/
|
|
28
|
+
replicationPoolConfigs(): Readonly<{
|
|
29
|
+
write: PoolConfig;
|
|
30
|
+
read: readonly PoolConfig[];
|
|
31
|
+
}>;
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Client as PgClient, PoolConfig } from 'pg';
|
|
2
|
+
import { Client, ExecuteOptions, QueryResult } from './connection-types.ts';
|
|
3
|
+
import { PgErrorMapper } from '../errors/map-pg-error.ts';
|
|
4
|
+
import { CompiledQuery } from '../sql/compile.ts';
|
|
5
|
+
import { QueryLogger } from './query-logger.ts';
|
|
6
|
+
import { StatementCacheOptions } from './options.ts';
|
|
7
|
+
export type { Client, ExecuteOptions, QueryResult } from './connection-types.ts';
|
|
8
|
+
/**
|
|
9
|
+
* Owner of the `pg` pools of a `Sequelize` instance: runs queries (mapping driver errors to Sequelize v6
|
|
10
|
+
* error classes), acquires clients for transactions, streams COPY data and closes the pools.
|
|
11
|
+
*/
|
|
12
|
+
export declare class ConnectionManager {
|
|
13
|
+
#private;
|
|
14
|
+
/**
|
|
15
|
+
* @param config - Writer pool configuration.
|
|
16
|
+
* @param readConfigs - Read replica pool configurations.
|
|
17
|
+
* @param logger - Logger of executed statements.
|
|
18
|
+
* @param errors - Driver error mapper.
|
|
19
|
+
* @param statementCache - Named prepared statement settings; unnamed statements when absent.
|
|
20
|
+
*/
|
|
21
|
+
constructor(config: PoolConfig, readConfigs: readonly PoolConfig[], logger: QueryLogger, errors: PgErrorMapper, statementCache?: boolean | StatementCacheOptions);
|
|
22
|
+
/**
|
|
23
|
+
* Runs a compiled query and maps driver errors to Sequelize v6 error classes.
|
|
24
|
+
*
|
|
25
|
+
* @param query - Query text and parameters.
|
|
26
|
+
* @param options - Client, route and logging settings.
|
|
27
|
+
* @returns Rows, row count and command.
|
|
28
|
+
*/
|
|
29
|
+
execute(query: CompiledQuery, options?: ExecuteOptions): Promise<QueryResult>;
|
|
30
|
+
/**
|
|
31
|
+
* Acquires a writer connection (e.g. for a transaction); release it when done.
|
|
32
|
+
*
|
|
33
|
+
* @returns Pooled client.
|
|
34
|
+
*/
|
|
35
|
+
acquire(): Promise<Client>;
|
|
36
|
+
/**
|
|
37
|
+
* Streams `lines` into `COPY ... FROM STDIN`.
|
|
38
|
+
*
|
|
39
|
+
* @param text - `COPY ... FROM STDIN` statement.
|
|
40
|
+
* @param lines - Encoded rows.
|
|
41
|
+
* @param options - Client and logging settings.
|
|
42
|
+
* @returns Copied row count.
|
|
43
|
+
*/
|
|
44
|
+
copyFrom(text: string, lines: AsyncIterable<string>, options?: ExecuteOptions): Promise<number>;
|
|
45
|
+
/**
|
|
46
|
+
* Runs `COPY ... TO STDOUT` and yields the output chunks.
|
|
47
|
+
*
|
|
48
|
+
* @param text - `COPY ... TO STDOUT` statement.
|
|
49
|
+
* @param options - Client and logging settings.
|
|
50
|
+
* @returns Async iterator of output chunks.
|
|
51
|
+
*/
|
|
52
|
+
copyTo(text: string, options?: ExecuteOptions): AsyncGenerator<Buffer, void, undefined>;
|
|
53
|
+
/**
|
|
54
|
+
* Opens a dedicated (non-pooled) client, e.g. for LISTEN.
|
|
55
|
+
*
|
|
56
|
+
* @returns Connected client.
|
|
57
|
+
*/
|
|
58
|
+
dedicated(): Promise<PgClient>;
|
|
59
|
+
/**
|
|
60
|
+
* Closes the writer and reader pools.
|
|
61
|
+
*
|
|
62
|
+
* @returns Resolves when all pools are closed.
|
|
63
|
+
*/
|
|
64
|
+
close(): Promise<void>;
|
|
65
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { PoolClient, QueryResultRow } from 'pg';
|
|
2
|
+
import { LoggingFunction } from './options.ts';
|
|
3
|
+
/** Result of one executed statement. */
|
|
4
|
+
export type QueryResult = Readonly<{
|
|
5
|
+
rows: readonly QueryResultRow[];
|
|
6
|
+
rowCount: number;
|
|
7
|
+
command: string;
|
|
8
|
+
}>;
|
|
9
|
+
/** Database client a query runs on: a pool connection held by a transaction. */
|
|
10
|
+
export type Client = Pick<PoolClient, 'query' | 'release'>;
|
|
11
|
+
/** Per-call execution settings. */
|
|
12
|
+
export type ExecuteOptions = Readonly<{
|
|
13
|
+
client?: Client;
|
|
14
|
+
/** Run on a read replica when one is configured (ignored when `client` is set). */
|
|
15
|
+
route?: 'read' | 'write';
|
|
16
|
+
logging?: LoggingFunction | false;
|
|
17
|
+
benchmark?: boolean;
|
|
18
|
+
/** `statement_timeout` in milliseconds for this query only (`0` disables it). */
|
|
19
|
+
statementTimeout?: number;
|
|
20
|
+
transactionId?: string;
|
|
21
|
+
}>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** Minimal view of the `pg` connection used by COPY. */
|
|
2
|
+
type CopyConnection = Readonly<{
|
|
3
|
+
query: (text: string) => void;
|
|
4
|
+
sendCopyFromChunk: (chunk: Buffer) => unknown;
|
|
5
|
+
endCopyFrom: () => void;
|
|
6
|
+
sendCopyFail: (message: string) => void;
|
|
7
|
+
stream?: Readonly<{
|
|
8
|
+
writableNeedDrain?: boolean;
|
|
9
|
+
once: (event: 'drain', listener: () => void) => unknown;
|
|
10
|
+
}>;
|
|
11
|
+
}>;
|
|
12
|
+
/**
|
|
13
|
+
* `pg` submittable running `COPY ... FROM STDIN` and streaming text lines produced by `lines`.
|
|
14
|
+
* Resolves with the number of copied rows.
|
|
15
|
+
*/
|
|
16
|
+
export declare class CopyFromStdin {
|
|
17
|
+
#private;
|
|
18
|
+
/** Completion callback set by `pg`. */
|
|
19
|
+
callback: ((error: Error | null, rowCount?: number) => void) | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* @param text - `COPY ... FROM STDIN` statement.
|
|
22
|
+
* @param lines - Encoded rows.
|
|
23
|
+
*/
|
|
24
|
+
constructor(text: string, lines: AsyncIterable<string>);
|
|
25
|
+
/** Promise resolving with the copied row count. */
|
|
26
|
+
done(): Promise<number>;
|
|
27
|
+
/** @internal Called by `pg` to start the query. */
|
|
28
|
+
submit(connection: CopyConnection): void;
|
|
29
|
+
/** Resolves when no more data will be written to the connection. */
|
|
30
|
+
settled(): Promise<void>;
|
|
31
|
+
/** @internal Server is ready to receive data. */
|
|
32
|
+
handleCopyInResponse(connection: CopyConnection): void;
|
|
33
|
+
/** @internal */
|
|
34
|
+
handleCommandComplete(message: Readonly<{
|
|
35
|
+
text?: string;
|
|
36
|
+
}>): void;
|
|
37
|
+
/** @internal `pg` detaches the query on error, so report it right away. */
|
|
38
|
+
handleError(error: Error): void;
|
|
39
|
+
/** @internal */
|
|
40
|
+
handleReadyForQuery(): void;
|
|
41
|
+
/** @internal */
|
|
42
|
+
handleRowDescription(): void;
|
|
43
|
+
/** @internal */
|
|
44
|
+
handleDataRow(): void;
|
|
45
|
+
/** @internal */
|
|
46
|
+
handleEmptyQuery(): void;
|
|
47
|
+
/** @internal */
|
|
48
|
+
handlePortalSuspended(): void;
|
|
49
|
+
/** @internal */
|
|
50
|
+
handleCopyData(): void;
|
|
51
|
+
}
|
|
52
|
+
export {};
|