postgrelize 0.0.0-stage → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +289 -0
- package/LICENSE +21 -0
- package/README.md +131 -2
- package/dist/associations/alias-minifier.d.ts +43 -0
- package/dist/associations/association-accessors.d.ts +21 -0
- package/dist/associations/association-key-types.d.ts +44 -0
- package/dist/associations/association-keys.d.ts +98 -0
- package/dist/associations/association-lookup.d.ts +26 -0
- package/dist/associations/association-shape.d.ts +25 -0
- package/dist/associations/association.d.ts +95 -0
- package/dist/associations/belongs-to-many.d.ts +86 -0
- package/dist/associations/belongs-to.d.ts +45 -0
- package/dist/associations/has-many.d.ts +79 -0
- package/dist/associations/has-one.d.ts +44 -0
- package/dist/associations/include-assembler.d.ts +21 -0
- package/dist/associations/include-columns.d.ts +24 -0
- package/dist/associations/include-joins.d.ts +17 -0
- package/dist/associations/include-loader.d.ts +48 -0
- package/dist/associations/include-order.d.ts +22 -0
- package/dist/associations/include-query-builder.d.ts +54 -0
- package/dist/associations/include-resolver.d.ts +29 -0
- package/dist/associations/include-rows.d.ts +47 -0
- package/dist/associations/include-sub-query.d.ts +35 -0
- package/dist/associations/include.d.ts +112 -0
- package/dist/associations/junction-keys.d.ts +23 -0
- package/dist/associations/nested-creator.d.ts +44 -0
- package/dist/associations/nested-saver.d.ts +30 -0
- package/dist/associations/owner-keys.d.ts +34 -0
- package/dist/associations/separate-include-loader.d.ts +24 -0
- package/dist/associations/types.d.ts +139 -0
- package/dist/connection/after-connect-hook.d.ts +24 -0
- package/dist/connection/connect-hooks.d.ts +26 -0
- package/dist/connection/connection-config.d.ts +33 -0
- package/dist/connection/connection-manager.d.ts +65 -0
- package/dist/connection/connection-types.d.ts +21 -0
- package/dist/connection/copy-from-stdin.d.ts +52 -0
- package/dist/connection/copy-runner.d.ts +30 -0
- package/dist/connection/copy-to-stdout.d.ts +49 -0
- package/dist/connection/copy.d.ts +22 -0
- package/dist/connection/notifications.d.ts +28 -0
- package/dist/connection/options.d.ts +165 -0
- package/dist/connection/query-logger.d.ts +41 -0
- package/dist/connection/replica-router.d.ts +20 -0
- package/dist/connection/statement-cache.d.ts +36 -0
- package/dist/connection/statement-timeout.d.ts +22 -0
- package/dist/data-types/abstract-data-type.d.ts +58 -0
- package/dist/data-types/array-literal-parser.d.ts +17 -0
- package/dist/data-types/array-type.d.ts +18 -0
- package/dist/data-types/bit-type.d.ts +14 -0
- package/dist/data-types/blob-type.d.ts +12 -0
- package/dist/data-types/char-type.d.ts +12 -0
- package/dist/data-types/composite-fields.d.ts +26 -0
- package/dist/data-types/composite-type.d.ts +32 -0
- package/dist/data-types/data-types.d.ts +176 -0
- package/dist/data-types/date-type.d.ts +14 -0
- package/dist/data-types/decimal-type.d.ts +13 -0
- package/dist/data-types/default-value-generator.d.ts +15 -0
- package/dist/data-types/enum-type.d.ts +19 -0
- package/dist/data-types/ewkb-reader.d.ts +18 -0
- package/dist/data-types/ewkb-writer.d.ts +17 -0
- package/dist/data-types/float-type.d.ts +12 -0
- package/dist/data-types/geometric-text.d.ts +65 -0
- package/dist/data-types/geometric-type.d.ts +46 -0
- package/dist/data-types/hstore-type.d.ts +16 -0
- package/dist/data-types/integer-type.d.ts +24 -0
- package/dist/data-types/json-type.d.ts +16 -0
- package/dist/data-types/multirange-type.d.ts +19 -0
- package/dist/data-types/range-type.d.ts +28 -0
- package/dist/data-types/record-text.d.ts +29 -0
- package/dist/data-types/scalar-type.d.ts +13 -0
- package/dist/data-types/spatial-type.d.ts +20 -0
- package/dist/data-types/string-type.d.ts +12 -0
- package/dist/data-types/text-type.d.ts +12 -0
- package/dist/data-types/timestamp-type.d.ts +15 -0
- package/dist/data-types/virtual-type.d.ts +15 -0
- package/dist/data-types/wall-clock.d.ts +14 -0
- package/dist/ddl/column-ddl.d.ts +73 -0
- package/dist/ddl/constraint-ddl.d.ts +30 -0
- package/dist/ddl/ddl-generator.d.ts +181 -0
- package/dist/ddl/ddl-guards.d.ts +60 -0
- package/dist/ddl/ddl-types.d.ts +204 -0
- package/dist/ddl/enum-ddl.d.ts +42 -0
- package/dist/ddl/extension-ddl.d.ts +57 -0
- package/dist/ddl/function-ddl.d.ts +98 -0
- package/dist/ddl/index-ddl.d.ts +29 -0
- package/dist/ddl/index-element-ddl.d.ts +19 -0
- package/dist/ddl/partition-ddl.d.ts +88 -0
- package/dist/ddl/partition-types.d.ts +94 -0
- package/dist/ddl/policy-ddl.d.ts +137 -0
- package/dist/ddl/routine-guards.d.ts +63 -0
- package/dist/ddl/sequence-ddl.d.ts +103 -0
- package/dist/ddl/sql-literal.d.ts +61 -0
- package/dist/ddl/table-ddl.d.ts +35 -0
- package/dist/ddl/trigger-ddl.d.ts +81 -0
- package/dist/ddl/view-ddl.d.ts +122 -0
- package/dist/decorators/association-applier.d.ts +18 -0
- package/dist/decorators/association-decorators.d.ts +72 -0
- package/dist/decorators/column-decorators.d.ts +147 -0
- package/dist/decorators/decorator-factory.d.ts +45 -0
- package/dist/decorators/decorator-signature.d.ts +26 -0
- package/dist/decorators/decorator-types.d.ts +24 -0
- package/dist/decorators/foreign-key-decorator.d.ts +21 -0
- package/dist/decorators/hook-decorators.d.ts +393 -0
- package/dist/decorators/init-arguments.d.ts +29 -0
- package/dist/decorators/model-decorators.d.ts +18 -0
- package/dist/decorators/model-metadata.d.ts +70 -0
- package/dist/decorators/table-decorators.d.ts +43 -0
- package/dist/decorators/timestamp-decorators.d.ts +38 -0
- package/dist/errors/base-error.d.ts +40 -0
- package/dist/errors/connection-errors.d.ts +152 -0
- package/dist/errors/database-errors.d.ts +186 -0
- package/dist/errors/errors.d.ts +5 -0
- package/dist/errors/map-pg-error.d.ts +27 -0
- package/dist/errors/misc-errors.d.ts +232 -0
- package/dist/errors/validation-errors.d.ts +141 -0
- package/dist/exports-associations.d.ts +6 -0
- package/dist/exports-core.d.ts +95 -0
- package/dist/exports-decorators.d.ts +8 -0
- package/dist/exports-errors.d.ts +2 -0
- package/dist/exports-model.d.ts +21 -0
- package/dist/exports-schema.d.ts +19 -0
- package/dist/expressions/call-expressions.d.ts +54 -0
- package/dist/expressions/condition-expressions.d.ts +51 -0
- package/dist/expressions/expression.d.ts +52 -0
- package/dist/expressions/jsonpath-helpers.d.ts +37 -0
- package/dist/expressions/logic.d.ts +25 -0
- package/dist/expressions/methods.d.ts +188 -0
- package/dist/expressions/op.d.ts +182 -0
- package/dist/expressions/query-expressions.d.ts +110 -0
- package/dist/expressions/row-expressions.d.ts +35 -0
- package/dist/expressions/search-helpers.d.ts +138 -0
- package/dist/expressions/trigram-helpers.d.ts +40 -0
- package/dist/hooks/hooks.d.ts +125 -0
- package/dist/index.cjs +21864 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +21688 -0
- package/dist/index.js.map +1 -0
- package/dist/model/attribute-columns.d.ts +85 -0
- package/dist/model/attribute-normalizer.d.ts +42 -0
- package/dist/model/attribute-options.d.ts +121 -0
- package/dist/model/bulk-insert-builder.d.ts +24 -0
- package/dist/model/bulk-options.d.ts +173 -0
- package/dist/model/copy-options.d.ts +51 -0
- package/dist/model/cte-builder.d.ts +134 -0
- package/dist/model/definition-normalizer.d.ts +26 -0
- package/dist/model/delete-query-builder.d.ts +42 -0
- package/dist/model/find-options.d.ts +144 -0
- package/dist/model/find-query-builder.d.ts +38 -0
- package/dist/model/inflector.d.ts +28 -0
- package/dist/model/insert-query-builder.d.ts +41 -0
- package/dist/model/instance-destroyer.d.ts +44 -0
- package/dist/model/instance-lifecycle-services.d.ts +61 -0
- package/dist/model/instance-lifecycle.d.ts +128 -0
- package/dist/model/instance-saver.d.ts +25 -0
- package/dist/model/instance-state.d.ts +48 -0
- package/dist/model/instance-validation.d.ts +35 -0
- package/dist/model/instance-values.d.ts +88 -0
- package/dist/model/instance-writer.d.ts +59 -0
- package/dist/model/join-source-builder.d.ts +25 -0
- package/dist/model/lateral-keys-builder.d.ts +25 -0
- package/dist/model/merge-action-builder.d.ts +31 -0
- package/dist/model/merge-options.d.ts +72 -0
- package/dist/model/merge-query-builder.d.ts +29 -0
- package/dist/model/merge-source-builder.d.ts +22 -0
- package/dist/model/mixins/model-aggregates.d.ts +69 -0
- package/dist/model/mixins/model-associations.d.ts +113 -0
- package/dist/model/mixins/model-constructor.d.ts +7 -0
- package/dist/model/mixins/model-finders.d.ts +140 -0
- package/dist/model/mixins/model-hooks.d.ts +142 -0
- package/dist/model/mixins/model-postgres.d.ts +198 -0
- package/dist/model/mixins/model-schema-binding.d.ts +36 -0
- package/dist/model/mixins/model-schema.d.ts +100 -0
- package/dist/model/mixins/model-scopes.d.ts +57 -0
- package/dist/model/mixins/model-writers.d.ts +175 -0
- package/dist/model/mixins/named-hooks.d.ts +28 -0
- package/dist/model/model-accessors.d.ts +22 -0
- package/dist/model/model-base.d.ts +83 -0
- package/dist/model/model-definition.d.ts +130 -0
- package/dist/model/model-instance-persistence.d.ts +132 -0
- package/dist/model/model-instance-values.d.ts +197 -0
- package/dist/model/model-operations.d.ts +22 -0
- package/dist/model/model-registry.d.ts +152 -0
- package/dist/model/model-services.d.ts +46 -0
- package/dist/model/model-state.d.ts +68 -0
- package/dist/model/model-values.d.ts +86 -0
- package/dist/model/model.d.ts +629 -0
- package/dist/model/on-conflict-builder.d.ts +111 -0
- package/dist/model/operations/bulk-create-operation.d.ts +40 -0
- package/dist/model/operations/copy-from-source.d.ts +51 -0
- package/dist/model/operations/copy-operation.d.ts +54 -0
- package/dist/model/operations/count-operation.d.ts +52 -0
- package/dist/model/operations/create-operation.d.ts +31 -0
- package/dist/model/operations/destroy-operation.d.ts +65 -0
- package/dist/model/operations/find-cursor.d.ts +23 -0
- package/dist/model/operations/find-lookups.d.ts +99 -0
- package/dist/model/operations/find-operation.d.ts +47 -0
- package/dist/model/operations/increment-operation.d.ts +40 -0
- package/dist/model/operations/insert-operation.d.ts +71 -0
- package/dist/model/operations/merge-operation.d.ts +56 -0
- package/dist/model/operations/model-operation.d.ts +33 -0
- package/dist/model/operations/update-operation.d.ts +45 -0
- package/dist/model/operations/upsert-operation.d.ts +39 -0
- package/dist/model/options.d.ts +103 -0
- package/dist/model/returning-old.d.ts +52 -0
- package/dist/model/row-mapper.d.ts +78 -0
- package/dist/model/row-plan.d.ts +31 -0
- package/dist/model/runtime.d.ts +56 -0
- package/dist/model/scope-registry.d.ts +81 -0
- package/dist/model/select-aggregates.d.ts +37 -0
- package/dist/model/select-lock.d.ts +13 -0
- package/dist/model/select-options.d.ts +92 -0
- package/dist/model/select-query-builder.d.ts +73 -0
- package/dist/model/select-targets.d.ts +77 -0
- package/dist/model/source-option-builder.d.ts +23 -0
- package/dist/model/source-options.d.ts +108 -0
- package/dist/model/statement-builder.d.ts +77 -0
- package/dist/model/statement-services.d.ts +2 -0
- package/dist/model/sync-hooks.d.ts +18 -0
- package/dist/model/table-sample-builder.d.ts +13 -0
- package/dist/model/types.d.ts +85 -0
- package/dist/model/unnest-insert-builder.d.ts +24 -0
- package/dist/model/update-query-builder.d.ts +39 -0
- package/dist/model/v6-conflict-builder.d.ts +37 -0
- package/dist/model/value-cloner.d.ts +17 -0
- package/dist/model/values-writer.d.ts +12 -0
- package/dist/model/where-options.d.ts +164 -0
- package/dist/model/write-options.d.ts +160 -0
- package/dist/model/written-rows.d.ts +56 -0
- package/dist/package-version.d.ts +8 -0
- package/dist/query/query-result-shaper.d.ts +93 -0
- package/dist/query/raw-query.d.ts +27 -0
- package/dist/query-interface/alter-planner.d.ts +40 -0
- package/dist/query-interface/bulk-data.d.ts +44 -0
- package/dist/query-interface/column-commands.d.ts +52 -0
- package/dist/query-interface/column-describer.d.ts +17 -0
- package/dist/query-interface/enum-commands.d.ts +36 -0
- package/dist/query-interface/index-commands.d.ts +57 -0
- package/dist/query-interface/model-tables.d.ts +58 -0
- package/dist/query-interface/object-commands.d.ts +71 -0
- package/dist/query-interface/partition-commands.d.ts +43 -0
- package/dist/query-interface/policy-commands.d.ts +54 -0
- package/dist/query-interface/query-interface-catalog.d.ts +180 -0
- package/dist/query-interface/query-interface-objects.d.ts +108 -0
- package/dist/query-interface/query-interface-partitions.d.ts +66 -0
- package/dist/query-interface/query-interface-policies.d.ts +86 -0
- package/dist/query-interface/query-interface-routines.d.ts +120 -0
- package/dist/query-interface/query-interface-tables.d.ts +179 -0
- package/dist/query-interface/query-interface-types.d.ts +62 -0
- package/dist/query-interface/query-interface-views.d.ts +84 -0
- package/dist/query-interface/query-interface.d.ts +256 -0
- package/dist/query-interface/routine-commands.d.ts +71 -0
- package/dist/query-interface/schema-synchronizer.d.ts +110 -0
- package/dist/query-interface/statement-runner.d.ts +40 -0
- package/dist/query-interface/sync-planner.d.ts +26 -0
- package/dist/query-interface/table-commands.d.ts +63 -0
- package/dist/query-interface/table-introspector.d.ts +58 -0
- package/dist/query-interface/view-commands.d.ts +47 -0
- package/dist/sequelize/instance-hook-adders.d.ts +72 -0
- package/dist/sequelize/sequelize-base.d.ts +196 -0
- package/dist/sequelize/sequelize-constructor.d.ts +7 -0
- package/dist/sequelize/sequelize-helpers.d.ts +133 -0
- package/dist/sequelize/sequelize-hooks.d.ts +99 -0
- package/dist/sequelize/sequelize-internals.d.ts +87 -0
- package/dist/sequelize/sequelize-notifications.d.ts +66 -0
- package/dist/sequelize/sequelize-schema.d.ts +125 -0
- package/dist/sequelize/sequelize-transactions.d.ts +96 -0
- package/dist/sequelize.d.ts +1175 -0
- package/dist/sql/ast-clauses.d.ts +137 -0
- package/dist/sql/ast-expressions.d.ts +88 -0
- package/dist/sql/ast-statements.d.ts +80 -0
- package/dist/sql/ast.d.ts +21 -0
- package/dist/sql/compile.d.ts +21 -0
- package/dist/sql/dml-compiler.d.ts +54 -0
- package/dist/sql/expression-compiler.d.ts +56 -0
- package/dist/sql/from-compiler.d.ts +39 -0
- package/dist/sql/identifier-quoter.d.ts +15 -0
- package/dist/sql/merge-compiler.d.ts +20 -0
- package/dist/sql/order.d.ts +15 -0
- package/dist/sql/query-compiler.d.ts +45 -0
- package/dist/sql/sql-chunks.d.ts +50 -0
- package/dist/sql/with-compiler.d.ts +19 -0
- package/dist/transaction/advisory-locks.d.ts +28 -0
- package/dist/transaction/cls-namespace.d.ts +44 -0
- package/dist/transaction/transaction-constants.d.ts +35 -0
- package/dist/transaction/transaction-runner.d.ts +78 -0
- package/dist/transaction/transaction-starter.d.ts +25 -0
- package/dist/transaction/transaction-statements.d.ts +29 -0
- package/dist/transaction/transaction.d.ts +201 -0
- package/dist/validation/attribute-validators.d.ts +23 -0
- package/dist/validation/builtin-attribute-validator.d.ts +19 -0
- package/dist/validation/builtin-validators.d.ts +16 -0
- package/dist/validation/core-validator.d.ts +16 -0
- package/dist/validation/custom-validators.d.ts +13 -0
- package/dist/validation/instance-validator.d.ts +25 -0
- package/dist/validation/schema-items.d.ts +22 -0
- package/dist/validation/standard-schema-validator.d.ts +30 -0
- package/dist/validation/standard-schema.d.ts +39 -0
- package/dist/validation/types.d.ts +36 -0
- package/dist/validation/validation-target.d.ts +13 -0
- package/dist/where/comparison-compiler.d.ts +27 -0
- package/dist/where/condition-compiler.d.ts +18 -0
- package/dist/where/operand-resolver.d.ts +10 -0
- package/dist/where/operator-allowlist.d.ts +14 -0
- package/dist/where/where-support.d.ts +52 -0
- package/dist/where/where.d.ts +46 -0
- package/dist/where/window-compiler.d.ts +14 -0
- package/llm/USAGE.md +423 -0
- package/package.json +103 -4
- package/skills/postgrelize/SKILL.md +57 -0
- package/skills/postgrelize/reference/associations.md +108 -0
- package/skills/postgrelize/reference/errors.md +37 -0
- package/skills/postgrelize/reference/migrating-from-sequelize.md +15 -0
- package/skills/postgrelize/reference/postgresql-features.md +157 -0
- package/skills/postgrelize/reference/querying.md +111 -0
- package/skills/postgrelize/reference/schema.md +135 -0
- package/skills/postgrelize/reference/security.md +34 -0
- package/skills/postgrelize/reference/transactions-and-sessions.md +122 -0
- package/skills/postgrelize/reference/writing.md +198 -0
|
@@ -0,0 +1,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 {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { PgErrorMapper } from '../errors/map-pg-error.ts';
|
|
2
|
+
import { Client, ExecuteOptions } from './connection-types.ts';
|
|
3
|
+
import { QueryLogger } from './query-logger.ts';
|
|
4
|
+
/** Runs `COPY ... FROM STDIN` and `COPY ... TO STDOUT` on a writer connection. */
|
|
5
|
+
export declare class CopyRunner {
|
|
6
|
+
#private;
|
|
7
|
+
/**
|
|
8
|
+
* @param acquire - Acquires a writer connection.
|
|
9
|
+
* @param logger - Logger of executed statements.
|
|
10
|
+
* @param errors - Driver error mapper.
|
|
11
|
+
*/
|
|
12
|
+
constructor(acquire: () => Promise<Client>, logger: QueryLogger, errors: PgErrorMapper);
|
|
13
|
+
/**
|
|
14
|
+
* Streams `lines` into `COPY ... FROM STDIN`.
|
|
15
|
+
*
|
|
16
|
+
* @param text - `COPY ... FROM STDIN` statement.
|
|
17
|
+
* @param lines - Encoded rows.
|
|
18
|
+
* @param options - Client and logging settings.
|
|
19
|
+
* @returns Copied row count.
|
|
20
|
+
*/
|
|
21
|
+
from(text: string, lines: AsyncIterable<string>, options: ExecuteOptions): Promise<number>;
|
|
22
|
+
/**
|
|
23
|
+
* Runs `COPY ... TO STDOUT` and yields the output chunks.
|
|
24
|
+
*
|
|
25
|
+
* @param text - `COPY ... TO STDOUT` statement.
|
|
26
|
+
* @param options - Client and logging settings.
|
|
27
|
+
* @returns Async iterator of output chunks.
|
|
28
|
+
*/
|
|
29
|
+
to(text: string, options: ExecuteOptions): AsyncGenerator<Buffer, void, undefined>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** Minimal view of the `pg` connection used by COPY TO. */
|
|
2
|
+
type CopyOutConnection = Readonly<{
|
|
3
|
+
query: (text: string) => void;
|
|
4
|
+
stream?: Readonly<{
|
|
5
|
+
pause: () => unknown;
|
|
6
|
+
resume: () => unknown;
|
|
7
|
+
}>;
|
|
8
|
+
}>;
|
|
9
|
+
/** `pg` submittable running `COPY ... TO STDOUT` and exposing the output as an async iterator of chunks. */
|
|
10
|
+
export declare class CopyToStdout {
|
|
11
|
+
#private;
|
|
12
|
+
/** Completion callback set by `pg`. */
|
|
13
|
+
callback: ((error: Error | null, rowCount?: number) => void) | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* @param text - `COPY ... TO STDOUT` statement.
|
|
16
|
+
*/
|
|
17
|
+
constructor(text: string);
|
|
18
|
+
/** Resolves with the copied row count when the server finished. */
|
|
19
|
+
done(): Promise<number>;
|
|
20
|
+
/** Output chunks in order; throws the server error, if any. */
|
|
21
|
+
chunks(): AsyncGenerator<Buffer, void, undefined>;
|
|
22
|
+
/** Stops delivering chunks and lets the remaining output drain. */
|
|
23
|
+
discard(): void;
|
|
24
|
+
/** @internal Called by `pg` to start the query. */
|
|
25
|
+
submit(connection: CopyOutConnection): void;
|
|
26
|
+
/** @internal */
|
|
27
|
+
handleCopyData(message: Readonly<{
|
|
28
|
+
chunk: Buffer;
|
|
29
|
+
}>): void;
|
|
30
|
+
/** @internal */
|
|
31
|
+
handleCommandComplete(message: Readonly<{
|
|
32
|
+
text?: string;
|
|
33
|
+
}>): void;
|
|
34
|
+
/** @internal `pg` detaches the query on error, so report it right away. */
|
|
35
|
+
handleError(error: Error): void;
|
|
36
|
+
/** @internal */
|
|
37
|
+
handleReadyForQuery(): void;
|
|
38
|
+
/** @internal */
|
|
39
|
+
handleCopyInResponse(): void;
|
|
40
|
+
/** @internal */
|
|
41
|
+
handleRowDescription(): void;
|
|
42
|
+
/** @internal */
|
|
43
|
+
handleDataRow(): void;
|
|
44
|
+
/** @internal */
|
|
45
|
+
handleEmptyQuery(): void;
|
|
46
|
+
/** @internal */
|
|
47
|
+
handlePortalSuspended(): void;
|
|
48
|
+
}
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Value accepted by the COPY text encoder. */
|
|
2
|
+
type CopyValue = unknown;
|
|
3
|
+
/** Encodes values and rows in PostgreSQL COPY text format. */
|
|
4
|
+
export declare class CopyEncoder {
|
|
5
|
+
#private;
|
|
6
|
+
/**
|
|
7
|
+
* Encodes one value in PostgreSQL COPY text format (`\N` for NULL).
|
|
8
|
+
*
|
|
9
|
+
* @param value - Value to encode.
|
|
10
|
+
* @returns Encoded field.
|
|
11
|
+
*/
|
|
12
|
+
encodeValue(value: CopyValue): string;
|
|
13
|
+
/**
|
|
14
|
+
* Encodes a row (already in column order) as one COPY text line.
|
|
15
|
+
*
|
|
16
|
+
* @param values - Values in column order.
|
|
17
|
+
* @returns Encoded line ending with a newline.
|
|
18
|
+
*/
|
|
19
|
+
encodeRow(values: readonly CopyValue[]): string;
|
|
20
|
+
}
|
|
21
|
+
export { CopyFromStdin } from './copy-from-stdin.ts';
|
|
22
|
+
export { CopyToStdout } from './copy-to-stdout.ts';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Client as PgClient } from 'pg';
|
|
2
|
+
/** Handler of `LISTEN` notifications. */
|
|
3
|
+
export type NotificationHandler = (payload: string | undefined, channel: string) => unknown;
|
|
4
|
+
/**
|
|
5
|
+
* Dedicated LISTEN connection shared by all subscriptions of a Sequelize instance: opened lazily and
|
|
6
|
+
* re-subscribed after connection loss.
|
|
7
|
+
*/
|
|
8
|
+
export declare class NotificationListener {
|
|
9
|
+
#private;
|
|
10
|
+
/**
|
|
11
|
+
* @param connect - Opens a dedicated client.
|
|
12
|
+
*/
|
|
13
|
+
constructor(connect: () => Promise<PgClient>);
|
|
14
|
+
/**
|
|
15
|
+
* Subscribes `handler` to a channel.
|
|
16
|
+
*
|
|
17
|
+
* @param channel - Channel name.
|
|
18
|
+
* @param handler - Called with the payload and the channel.
|
|
19
|
+
* @returns Function that unsubscribes the handler.
|
|
20
|
+
*/
|
|
21
|
+
listen(channel: string, handler: NotificationHandler): Promise<() => Promise<void>>;
|
|
22
|
+
/**
|
|
23
|
+
* Removes all subscriptions and closes the connection.
|
|
24
|
+
*
|
|
25
|
+
* @returns Resolves when closed.
|
|
26
|
+
*/
|
|
27
|
+
close(): Promise<void>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { PoolConfig } from 'pg';
|
|
2
|
+
import { HooksOption } from '../hooks/hooks.ts';
|
|
3
|
+
/** Function receiving executed SQL. With `benchmark: true` the second argument is the duration in ms. */
|
|
4
|
+
export type LoggingFunction = (sql: string, timingOrOptions?: unknown) => void;
|
|
5
|
+
/**
|
|
6
|
+
* Connection pool settings (Sequelize v6 `PoolOptions`), given as the `pool` option of {@link SequelizeOptions}.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const pool: PoolOptions = { max: 10, idle: 10_000, acquire: 30_000 };
|
|
11
|
+
* const db = new Sequelize('postgres://user:pass@localhost:5432/app', { pool });
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export type PoolOptions = Readonly<{
|
|
15
|
+
/** Maximum number of connections. Default 5. */
|
|
16
|
+
max?: number;
|
|
17
|
+
/** Minimum number of connections. Accepted for compatibility; `pg` does not keep idle minimums. */
|
|
18
|
+
min?: number;
|
|
19
|
+
/** Milliseconds a connection may be idle before release. Default 10000. */
|
|
20
|
+
idle?: number;
|
|
21
|
+
/** Milliseconds to wait for a connection before throwing `ConnectionAcquireTimeoutError`. Default 60000. */
|
|
22
|
+
acquire?: number;
|
|
23
|
+
/** Accepted for compatibility; eviction is handled by `idle`. */
|
|
24
|
+
evict?: number;
|
|
25
|
+
/** Maximum times a connection may be used before it is replaced (`pg` `maxUses`). */
|
|
26
|
+
maxUses?: number;
|
|
27
|
+
}>;
|
|
28
|
+
/**
|
|
29
|
+
* Named prepared statement cache settings, given as the `statementCache` option of {@link SequelizeOptions}.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const db = new Sequelize('postgres://user:pass@localhost:5432/app', { statementCache: { max: 50 } });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export type StatementCacheOptions = Readonly<{
|
|
37
|
+
/** Maximum named statements per connection. Default 100. Further statements run unnamed. */
|
|
38
|
+
max?: number;
|
|
39
|
+
}>;
|
|
40
|
+
/** Defaults applied to every model defined through this instance (Sequelize v6 `define` option). */
|
|
41
|
+
export type ModelDefaults = Readonly<{
|
|
42
|
+
/** Add `createdAt` / `updatedAt`. Default true. */
|
|
43
|
+
timestamps?: boolean;
|
|
44
|
+
/** Use snake_case column names for attributes and the table name. */
|
|
45
|
+
underscored?: boolean;
|
|
46
|
+
/** Use the model name as table name without pluralization. */
|
|
47
|
+
freezeTableName?: boolean;
|
|
48
|
+
/** PostgreSQL schema of the tables. */
|
|
49
|
+
schema?: string;
|
|
50
|
+
/** Soft-delete rows (`deletedAt`) instead of deleting them. */
|
|
51
|
+
paranoid?: boolean;
|
|
52
|
+
/** Hooks added to every model. */
|
|
53
|
+
hooks?: HooksOption;
|
|
54
|
+
}>;
|
|
55
|
+
/** Connection settings of one replication member. */
|
|
56
|
+
export type ReplicationMember = Readonly<{
|
|
57
|
+
/** Host. */
|
|
58
|
+
host?: string;
|
|
59
|
+
/** Port. */
|
|
60
|
+
port?: number;
|
|
61
|
+
/** User name. */
|
|
62
|
+
username?: string;
|
|
63
|
+
/** Password. */
|
|
64
|
+
password?: string;
|
|
65
|
+
/** Database name. */
|
|
66
|
+
database?: string;
|
|
67
|
+
}>;
|
|
68
|
+
/**
|
|
69
|
+
* The `replication` option: readers receive SELECTs outside transactions, the writer everything else.
|
|
70
|
+
*
|
|
71
|
+
* Members inherit missing connection settings from the top-level options. See {@link ReplicationMember}.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* const replication: ReplicationOptions = {
|
|
76
|
+
* read: [{ host: 'replica-1.internal' }, { host: 'replica-2.internal' }],
|
|
77
|
+
* write: { host: 'primary.internal' },
|
|
78
|
+
* };
|
|
79
|
+
* const db = new Sequelize('app', 'user', 'pass', { dialect: 'postgres', replication });
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export type ReplicationOptions = Readonly<{
|
|
83
|
+
/** Reader(s). */
|
|
84
|
+
read: ReplicationMember | readonly ReplicationMember[];
|
|
85
|
+
/** Writer; defaults to the top-level connection settings. */
|
|
86
|
+
write?: ReplicationMember;
|
|
87
|
+
}>;
|
|
88
|
+
/**
|
|
89
|
+
* Options of the {@link Sequelize} constructor (PostgreSQL subset of Sequelize v6 `Options`).
|
|
90
|
+
*
|
|
91
|
+
* All fields are optional; values given in a connection URL are overridden by these fields.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* const options: SequelizeOptions = {
|
|
96
|
+
* dialect: 'postgres',
|
|
97
|
+
* host: 'localhost',
|
|
98
|
+
* port: 5432,
|
|
99
|
+
* pool: { max: 10 },
|
|
100
|
+
* logging: false,
|
|
101
|
+
* define: { underscored: true },
|
|
102
|
+
* };
|
|
103
|
+
* const db = new Sequelize('app', 'user', 'pass', options);
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export type SequelizeOptions = Readonly<{
|
|
107
|
+
/** Must be `'postgres'` when given. */
|
|
108
|
+
dialect?: 'postgres';
|
|
109
|
+
/** Database name. */
|
|
110
|
+
database?: string;
|
|
111
|
+
/** User name. */
|
|
112
|
+
username?: string;
|
|
113
|
+
/** Password. */
|
|
114
|
+
password?: string;
|
|
115
|
+
/** Host. Default `'localhost'`. */
|
|
116
|
+
host?: string;
|
|
117
|
+
/** Port. Default 5432. */
|
|
118
|
+
port?: number;
|
|
119
|
+
/** SSL settings passed to `pg`. */
|
|
120
|
+
ssl?: PoolConfig['ssl'];
|
|
121
|
+
/** Extra options passed to the `pg` pool/client as is. */
|
|
122
|
+
dialectOptions?: Readonly<Omit<PoolConfig, 'types'>>;
|
|
123
|
+
/** Pool settings. */
|
|
124
|
+
pool?: PoolOptions;
|
|
125
|
+
/** SQL logger, or `false` to disable. Default `console.log`. */
|
|
126
|
+
logging?: LoggingFunction | false;
|
|
127
|
+
/** Pass query duration to the logger. */
|
|
128
|
+
benchmark?: boolean;
|
|
129
|
+
/** Session time zone. Default `'+00:00'`. */
|
|
130
|
+
timezone?: string;
|
|
131
|
+
/** Defaults for all models. */
|
|
132
|
+
define?: ModelDefaults;
|
|
133
|
+
/** Read replicas and writer (Sequelize v6 `replication`); entries inherit missing connection settings. */
|
|
134
|
+
replication?: ReplicationOptions;
|
|
135
|
+
/** Sequelize-level hooks run for every model (and `beforeConnect`). */
|
|
136
|
+
hooks?: HooksOption;
|
|
137
|
+
/**
|
|
138
|
+
* Shorten the aliases of included columns (`Posts.Comments.title` becomes `_0`) and of table aliases
|
|
139
|
+
* of 64 or more characters, as in Sequelize v6, so deep includes stay within PostgreSQL's 63-byte
|
|
140
|
+
* identifier limit. Without it PostgreSQL truncates longer aliases and columns can collide.
|
|
141
|
+
* Default `false`.
|
|
142
|
+
*/
|
|
143
|
+
minifyAliases?: boolean;
|
|
144
|
+
/** Minimum IN-list length compiled to `= ANY($n)`. Default 100. PostgreSQL extension. */
|
|
145
|
+
inAsAnyThreshold?: number;
|
|
146
|
+
/**
|
|
147
|
+
* Opt-in named prepared statements (PostgreSQL extension): repeated SELECT / INSERT / UPDATE / DELETE texts are
|
|
148
|
+
* parsed and planned once per connection. `true` uses the default bound of 100 statements per connection.
|
|
149
|
+
* Off by default; not for PgBouncer in transaction pooling mode; pair with a bounded `pool.max`.
|
|
150
|
+
*/
|
|
151
|
+
statementCache?: boolean | StatementCacheOptions;
|
|
152
|
+
}>;
|
|
153
|
+
/** Connection settings exposed as `sequelize.config` (Sequelize v6 shape). */
|
|
154
|
+
export type ConnectionConfig = Readonly<{
|
|
155
|
+
/** Database name. */
|
|
156
|
+
database: string | undefined;
|
|
157
|
+
/** User name. */
|
|
158
|
+
username: string | undefined;
|
|
159
|
+
/** Password. */
|
|
160
|
+
password: string | undefined;
|
|
161
|
+
/** Host. */
|
|
162
|
+
host: string;
|
|
163
|
+
/** Port. */
|
|
164
|
+
port: number;
|
|
165
|
+
}>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { CompiledQuery } from '../sql/compile.ts';
|
|
2
|
+
import { LoggingFunction } from './options.ts';
|
|
3
|
+
/** Logging settings: instance defaults or per-query overrides. */
|
|
4
|
+
export type QueryLogSettings = Readonly<{
|
|
5
|
+
/** SQL logger, or `false` to disable. */
|
|
6
|
+
logging?: LoggingFunction | false;
|
|
7
|
+
/** Pass the query duration to the logger. */
|
|
8
|
+
benchmark?: boolean;
|
|
9
|
+
/** Transaction id shown in the log line. */
|
|
10
|
+
transactionId?: string;
|
|
11
|
+
}>;
|
|
12
|
+
/** Writes executed SQL to the configured logger (Sequelize v6 `logging` / `benchmark` output). */
|
|
13
|
+
export declare class QueryLogger {
|
|
14
|
+
#private;
|
|
15
|
+
/**
|
|
16
|
+
* Logger for the `logging` / `benchmark` constructor options (`console.log` when `logging` is unset).
|
|
17
|
+
*
|
|
18
|
+
* @param options - Instance-level options.
|
|
19
|
+
* @returns Logger.
|
|
20
|
+
*/
|
|
21
|
+
static fromOptions(options: QueryLogSettings): QueryLogger;
|
|
22
|
+
/**
|
|
23
|
+
* @param defaults - Instance-level `logging` and `benchmark` settings.
|
|
24
|
+
*/
|
|
25
|
+
constructor(defaults: QueryLogSettings);
|
|
26
|
+
/**
|
|
27
|
+
* Whether a statement run with these settings is logged, so callers can skip timing it.
|
|
28
|
+
*
|
|
29
|
+
* @param options - Per-query settings overriding the defaults.
|
|
30
|
+
* @returns True when a logger is configured.
|
|
31
|
+
*/
|
|
32
|
+
enabled(options: QueryLogSettings): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Logs one executed statement.
|
|
35
|
+
*
|
|
36
|
+
* @param query - Executed query.
|
|
37
|
+
* @param options - Per-query settings overriding the defaults.
|
|
38
|
+
* @param elapsed - Duration in milliseconds.
|
|
39
|
+
*/
|
|
40
|
+
log(query: CompiledQuery, options: QueryLogSettings, elapsed: number): void;
|
|
41
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Chooses the pool a query runs on: the writer, or the next read replica in round-robin order. */
|
|
2
|
+
export declare class ReplicaRouter<P> {
|
|
3
|
+
#private;
|
|
4
|
+
/** Writer pool. */
|
|
5
|
+
readonly writer: P;
|
|
6
|
+
/** Read replica pools (may be empty). */
|
|
7
|
+
readonly readers: readonly P[];
|
|
8
|
+
/**
|
|
9
|
+
* @param writer - Writer pool.
|
|
10
|
+
* @param readers - Read replica pools.
|
|
11
|
+
*/
|
|
12
|
+
constructor(writer: P, readers: readonly P[]);
|
|
13
|
+
/**
|
|
14
|
+
* Pool for a query.
|
|
15
|
+
*
|
|
16
|
+
* @param route - `'read'` to use a replica when one is configured; anything else uses the writer.
|
|
17
|
+
* @returns Chosen pool.
|
|
18
|
+
*/
|
|
19
|
+
pool(route: 'read' | 'write' | undefined): P;
|
|
20
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { QueryResultRow } from 'pg';
|
|
2
|
+
import { CompiledQuery } from '../sql/compile.ts';
|
|
3
|
+
import { StatementCacheOptions } from './options.ts';
|
|
4
|
+
/** Minimal client surface the cache needs: the `pg` `query` overload with a config object. */
|
|
5
|
+
export type StatementClient = Readonly<{
|
|
6
|
+
query: (config: {
|
|
7
|
+
name?: string;
|
|
8
|
+
text: string;
|
|
9
|
+
values: unknown[];
|
|
10
|
+
}) => Promise<{
|
|
11
|
+
rows: QueryResultRow[];
|
|
12
|
+
rowCount: number | null;
|
|
13
|
+
command: string;
|
|
14
|
+
}>;
|
|
15
|
+
}>;
|
|
16
|
+
/**
|
|
17
|
+
* Opt-in named prepared statements (ADR-023): names eligible statements `pgz_<hash of the SQL text>` so
|
|
18
|
+
* PostgreSQL parses and plans them once per connection. Bounded per connection, never evicts.
|
|
19
|
+
*/
|
|
20
|
+
export declare class StatementCache {
|
|
21
|
+
#private;
|
|
22
|
+
/**
|
|
23
|
+
* @param options - `true` for defaults, or `{ max }` statements per connection.
|
|
24
|
+
* @throws Error when `max` is not a positive integer.
|
|
25
|
+
*/
|
|
26
|
+
constructor(options: true | StatementCacheOptions);
|
|
27
|
+
/**
|
|
28
|
+
* Runs a query on `client`, as a named statement when it is eligible.
|
|
29
|
+
*
|
|
30
|
+
* @param client - Connection to run on.
|
|
31
|
+
* @param query - Compiled query.
|
|
32
|
+
* @param retryable - Whether a stale-plan failure may be retried unnamed (false inside a transaction).
|
|
33
|
+
* @returns The driver result.
|
|
34
|
+
*/
|
|
35
|
+
run(client: StatementClient, query: CompiledQuery, retryable: boolean): ReturnType<StatementClient['query']>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Client } from './connection-types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Per-query `statement_timeout`: applied with `set_config(..., true)`, so the value is transaction-local
|
|
4
|
+
* and never reaches a pooled connection. The timeout value is a validated integer and is bound.
|
|
5
|
+
*/
|
|
6
|
+
export declare class StatementTimeout {
|
|
7
|
+
#private;
|
|
8
|
+
/**
|
|
9
|
+
* Runs `work` with `statement_timeout` set to `milliseconds`.
|
|
10
|
+
*
|
|
11
|
+
* Outside a transaction the work runs in its own `BEGIN … COMMIT` on the client. Inside one the previous
|
|
12
|
+
* value is restored afterwards, so later statements of the transaction keep their timeout.
|
|
13
|
+
*
|
|
14
|
+
* @param client - Connection the work runs on.
|
|
15
|
+
* @param inTransaction - Whether `client` already holds a transaction.
|
|
16
|
+
* @param milliseconds - Timeout; `0` disables it.
|
|
17
|
+
* @param work - The query to run.
|
|
18
|
+
* @returns The result of `work`.
|
|
19
|
+
* @throws Error when `milliseconds` is not a non-negative integer.
|
|
20
|
+
*/
|
|
21
|
+
run<T>(client: Pick<Client, 'query'>, inTransaction: boolean, milliseconds: number, work: () => Promise<T>): Promise<T>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Description of a column type: its SQL type and conversions between JavaScript values and the
|
|
3
|
+
* values sent to / received from PostgreSQL.
|
|
4
|
+
*/
|
|
5
|
+
export type DataType = Readonly<{
|
|
6
|
+
/** Sequelize v6 type key, e.g. `'STRING'`. */
|
|
7
|
+
key: string;
|
|
8
|
+
/** PostgreSQL column type, e.g. `'VARCHAR(255)'`. */
|
|
9
|
+
sqlType: string;
|
|
10
|
+
/** True for `JSON` and `JSONB`; enables nested JSON where conditions. */
|
|
11
|
+
isJson?: boolean;
|
|
12
|
+
/** True for `VIRTUAL`: the attribute is not stored in the database. */
|
|
13
|
+
isVirtual?: boolean;
|
|
14
|
+
/** Element type for `ARRAY` and `RANGE`. */
|
|
15
|
+
subtype?: DataType;
|
|
16
|
+
/** Allowed values for `ENUM`. */
|
|
17
|
+
values?: readonly string[];
|
|
18
|
+
/** SQL type that `where` parameters of this type are cast to (types PostgreSQL cannot infer from an untyped parameter). */
|
|
19
|
+
bindCast?: string;
|
|
20
|
+
/** Converts a value read from the driver into the attribute value. */
|
|
21
|
+
parse?: (value: unknown) => unknown;
|
|
22
|
+
/** Converts an attribute value into a driver parameter. */
|
|
23
|
+
serialize?: (value: unknown) => unknown;
|
|
24
|
+
}>;
|
|
25
|
+
/** A data type used as is (`DataTypes.INTEGER`) or after calling it (`DataTypes.STRING(64)`). */
|
|
26
|
+
export type DataTypeInput = DataType | ((...args: never[]) => DataType);
|
|
27
|
+
/**
|
|
28
|
+
* Base of the built-in data type classes. Conversions (`parse`, `serialize`) are own function
|
|
29
|
+
* properties, present only on types that convert values, so they can be read and called detached.
|
|
30
|
+
*
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
export declare abstract class AbstractDataType implements DataType {
|
|
34
|
+
/** Sequelize v6 type key, e.g. `'STRING'`. */
|
|
35
|
+
readonly key: string;
|
|
36
|
+
/** PostgreSQL column type, e.g. `'VARCHAR(255)'`. */
|
|
37
|
+
readonly sqlType: string;
|
|
38
|
+
/**
|
|
39
|
+
* @param key - Sequelize v6 type key.
|
|
40
|
+
* @param sqlType - PostgreSQL column type.
|
|
41
|
+
*/
|
|
42
|
+
constructor(key: string, sqlType: string);
|
|
43
|
+
/**
|
|
44
|
+
* Validates a numeric type parameter (length, precision, scale, srid) before it reaches SQL.
|
|
45
|
+
*
|
|
46
|
+
* @param name - Parameter name for the error message.
|
|
47
|
+
* @param value - Parameter value.
|
|
48
|
+
* @returns The value.
|
|
49
|
+
*/
|
|
50
|
+
protected static integer(name: string, value: number): number;
|
|
51
|
+
/**
|
|
52
|
+
* Resolves a data type given bare or called (`DataTypes.STRING` / `DataTypes.STRING(64)`).
|
|
53
|
+
*
|
|
54
|
+
* @param input - Data type or callable data type.
|
|
55
|
+
* @returns The data type; a callable type carries the properties of its default form.
|
|
56
|
+
*/
|
|
57
|
+
static from(input: DataTypeInput): DataType;
|
|
58
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
type Parsed = readonly (string | null | Parsed)[];
|
|
2
|
+
/**
|
|
3
|
+
* Parses PostgreSQL array literals (`{a,"b c",NULL}`, nested) into strings and nulls.
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export declare class ArrayLiteralParser {
|
|
8
|
+
#private;
|
|
9
|
+
/**
|
|
10
|
+
* Parses an array literal.
|
|
11
|
+
*
|
|
12
|
+
* @param text - Array literal as returned by the driver.
|
|
13
|
+
* @returns Elements (strings, `null`s and nested arrays); empty when `text` is not an array.
|
|
14
|
+
*/
|
|
15
|
+
parse(text: string): Parsed;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AbstractDataType, DataType, DataTypeInput } from './abstract-data-type.ts';
|
|
2
|
+
/**
|
|
3
|
+
* `type[]` (`DataTypes.ARRAY(DataTypes.TEXT)`).
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export declare class ArrayType extends AbstractDataType {
|
|
8
|
+
/** Element type. */
|
|
9
|
+
readonly subtype: DataType;
|
|
10
|
+
/** Converts a driver array literal into an array of strings. */
|
|
11
|
+
readonly parse: (value: unknown) => unknown;
|
|
12
|
+
/** Serializes every element; present only when the element type serializes values. */
|
|
13
|
+
readonly serialize?: (value: unknown) => unknown;
|
|
14
|
+
/**
|
|
15
|
+
* @param subtype - Element type.
|
|
16
|
+
*/
|
|
17
|
+
constructor(subtype: DataTypeInput);
|
|
18
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AbstractDataType } from './abstract-data-type.ts';
|
|
2
|
+
/**
|
|
3
|
+
* `BIT(length)` / `BIT VARYING(length)` (`DataTypes.BIT`, `DataTypes.VARBIT`); values are strings
|
|
4
|
+
* of `0` and `1`.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare class BitType extends AbstractDataType {
|
|
9
|
+
/**
|
|
10
|
+
* @param key - `'BIT'` or `'VARBIT'`.
|
|
11
|
+
* @param length - Number of bits; `BIT` defaults to 1, `VARBIT` to unlimited.
|
|
12
|
+
*/
|
|
13
|
+
constructor(key: 'BIT' | 'VARBIT', length?: number);
|
|
14
|
+
}
|