ts-prorm-orm 1.2.3 → 2.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 +331 -1
- package/README.md +32 -24
- package/dist/compliance/data-classifier.d.ts +6 -0
- package/dist/compliance/data-classifier.js +6 -0
- package/dist/compliance/data-lineage.d.ts +4 -0
- package/dist/compliance/data-lineage.js +4 -0
- package/dist/compliance/data-masker.d.ts +4 -0
- package/dist/compliance/data-masker.js +4 -0
- package/dist/compliance/index.d.ts +4 -0
- package/dist/compliance/index.js +15 -1
- package/dist/compliance/pseudonymization.d.ts +4 -0
- package/dist/compliance/pseudonymization.js +4 -0
- package/dist/compliance/query-firewall.d.ts +9 -9
- package/dist/compliance/query-firewall.js +9 -9
- package/dist/compliance/rate-limiter.d.ts +4 -0
- package/dist/compliance/rate-limiter.js +4 -0
- package/dist/compliance/row-level-security.d.ts +2 -0
- package/dist/compliance/row-level-security.js +2 -0
- package/dist/compliance/security-decorator.d.ts +8 -0
- package/dist/compliance/security-decorator.js +8 -0
- package/dist/compliance/session-isolation.d.ts +4 -0
- package/dist/compliance/session-isolation.js +4 -0
- package/dist/compliance/worm-storage.d.ts +4 -0
- package/dist/compliance/worm-storage.js +4 -0
- package/dist/connection-manager.js +13 -1
- package/dist/core/expressions.d.ts +58 -0
- package/dist/core/expressions.js +83 -0
- package/dist/core/hooks-manager.d.ts +179 -0
- package/dist/core/hooks-manager.js +291 -0
- package/dist/core/types.d.ts +235 -0
- package/dist/core/types.js +9 -0
- package/dist/decorators/audit.d.ts +3 -1
- package/dist/decorators/audit.js +3 -1
- package/dist/decorators/check.d.ts +15 -15
- package/dist/decorators/check.js +15 -15
- package/dist/decorators/collate.d.ts +16 -0
- package/dist/decorators/collate.js +16 -0
- package/dist/decorators/comment.d.ts +3 -1
- package/dist/decorators/comment.js +3 -1
- package/dist/decorators/database-settings.d.ts +6 -0
- package/dist/decorators/database-settings.js +6 -0
- package/dist/decorators/default.d.ts +2 -0
- package/dist/decorators/default.js +2 -0
- package/dist/decorators/encryption.d.ts +7 -1
- package/dist/decorators/encryption.js +7 -1
- package/dist/decorators/engine.d.ts +4 -0
- package/dist/decorators/engine.js +4 -0
- package/dist/decorators/fk-constraints.d.ts +32 -32
- package/dist/decorators/fk-constraints.js +32 -32
- package/dist/decorators/foreign-table.d.ts +1 -1
- package/dist/decorators/generated.d.ts +8 -0
- package/dist/decorators/generated.js +8 -0
- package/dist/decorators/hstore.d.ts +6 -0
- package/dist/decorators/hstore.js +6 -0
- package/dist/decorators/index.d.ts +2 -0
- package/dist/decorators/index.js +11 -1
- package/dist/decorators/json-column.d.ts +2 -0
- package/dist/decorators/json-column.js +2 -0
- package/dist/decorators/jsonb.d.ts +6 -0
- package/dist/decorators/jsonb.js +6 -0
- package/dist/decorators/permissions.d.ts +12 -0
- package/dist/decorators/permissions.js +12 -0
- package/dist/decorators/procedure.d.ts +4 -2
- package/dist/decorators/procedure.js +4 -2
- package/dist/decorators/query-options.d.ts +24 -0
- package/dist/decorators/query-options.js +24 -0
- package/dist/decorators/range.d.ts +8 -0
- package/dist/decorators/range.js +8 -0
- package/dist/decorators/set-column.d.ts +2 -0
- package/dist/decorators/set-column.js +2 -0
- package/dist/decorators/spatial.d.ts +2 -0
- package/dist/decorators/spatial.js +2 -0
- package/dist/decorators/storage.d.ts +24 -0
- package/dist/decorators/storage.js +24 -0
- package/dist/decorators/timezone.d.ts +7 -7
- package/dist/decorators/timezone.js +7 -7
- package/dist/decorators/trigger.d.ts +3 -1
- package/dist/decorators/trigger.js +3 -1
- package/dist/decorators/uuid.d.ts +6 -0
- package/dist/decorators/uuid.js +6 -0
- package/dist/decorators/view.d.ts +7 -1
- package/dist/decorators/view.js +7 -1
- package/dist/diagrams/chen-diagram.d.ts +15 -12
- package/dist/diagrams/chen-diagram.js +76 -85
- package/dist/diagrams/class-diagram.d.ts +9 -8
- package/dist/diagrams/class-diagram.js +60 -82
- package/dist/diagrams/core/index.d.ts +13 -0
- package/dist/diagrams/core/index.js +33 -0
- package/dist/diagrams/core/layout.d.ts +104 -0
- package/dist/diagrams/core/layout.js +223 -0
- package/dist/diagrams/{svg-dom.d.ts → core/svg.d.ts} +8 -20
- package/dist/diagrams/{svg-dom.js → core/svg.js} +21 -29
- package/dist/diagrams/core/theme.d.ts +84 -0
- package/dist/diagrams/core/theme.js +62 -0
- package/dist/diagrams/dependency-diagram.d.ts +15 -14
- package/dist/diagrams/dependency-diagram.js +71 -105
- package/dist/diagrams/er-diagram.d.ts +13 -26
- package/dist/diagrams/er-diagram.js +180 -259
- package/dist/diagrams/flow-diagram.d.ts +16 -11
- package/dist/diagrams/flow-diagram.js +96 -91
- package/dist/diagrams/gantt-diagram.d.ts +10 -5
- package/dist/diagrams/gantt-diagram.js +77 -103
- package/dist/diagrams/index-diagram.d.ts +10 -10
- package/dist/diagrams/index-diagram.js +106 -116
- package/dist/diagrams/index.d.ts +6 -9
- package/dist/diagrams/index.js +9 -24
- package/dist/diagrams/migration-diagram.d.ts +8 -4
- package/dist/diagrams/migration-diagram.js +189 -161
- package/dist/diagrams/model-diagram.d.ts +34 -34
- package/dist/diagrams/model-diagram.js +106 -485
- package/dist/diagrams/package-diagram.d.ts +9 -6
- package/dist/diagrams/package-diagram.js +64 -101
- package/dist/diagrams/relational-diagram.d.ts +12 -10
- package/dist/diagrams/relational-diagram.js +87 -114
- package/dist/diagrams/schemadoc-diagram.d.ts +8 -8
- package/dist/diagrams/schemadoc-diagram.js +71 -93
- package/dist/diagrams/sequence-diagram.d.ts +10 -10
- package/dist/diagrams/sequence-diagram.js +64 -89
- package/dist/diagrams/state-diagram.d.ts +10 -9
- package/dist/diagrams/state-diagram.js +69 -92
- package/dist/diagrams/tree-diagram.d.ts +11 -5
- package/dist/diagrams/tree-diagram.js +41 -65
- package/dist/dialects/clickhouse/index.js +15 -0
- package/dist/dialects/cockroachdb/index.d.ts +1 -1
- package/dist/dialects/cockroachdb/index.js +32 -63
- package/dist/dialects/db2/index.js +23 -8
- package/dist/dialects/dialect.d.ts +141 -5
- package/dist/dialects/duckdb/index.js +9 -2
- package/dist/dialects/hana/index.js +22 -5
- package/dist/dialects/lock-clause-helper.d.ts +167 -0
- package/dist/dialects/lock-clause-helper.js +316 -0
- package/dist/dialects/mariadb/index.d.ts +7 -4
- package/dist/dialects/mariadb/index.js +36 -60
- package/dist/dialects/mssql/index.js +34 -3
- package/dist/dialects/mysql/index.d.ts +1 -1
- package/dist/dialects/mysql/index.js +17 -45
- package/dist/dialects/oracle/index.d.ts +14 -3
- package/dist/dialects/oracle/index.js +66 -36
- package/dist/dialects/order-expression-helper.d.ts +72 -0
- package/dist/dialects/order-expression-helper.js +154 -0
- package/dist/dialects/partial-index.d.ts +52 -0
- package/dist/dialects/partial-index.js +251 -0
- package/dist/dialects/postgres/index.d.ts +1 -1
- package/dist/dialects/postgres/index.js +43 -68
- package/dist/dialects/redshift/index.js +9 -2
- package/dist/dialects/snowflake/index.js +17 -0
- package/dist/dialects/spanner/index.js +7 -2
- package/dist/dialects/sqlite/driver.d.ts +55 -0
- package/dist/dialects/sqlite/driver.js +102 -0
- package/dist/dialects/sqlite/index.d.ts +1 -1
- package/dist/dialects/sqlite/index.js +49 -27
- package/dist/external-fields/decorator.d.ts +2 -0
- package/dist/external-fields/decorator.js +2 -0
- package/dist/graph/base-graph-dialect.d.ts +24 -3
- package/dist/graph/base-graph-dialect.js +43 -2
- package/dist/graph/dgraph/index.js +6 -0
- package/dist/graph/gremlin/index.d.ts +6 -0
- package/dist/graph/gremlin/index.js +12 -1
- package/dist/graph/index.d.ts +1 -1
- package/dist/graph/neo4j/index.d.ts +2 -0
- package/dist/graph/neo4j/index.js +6 -1
- package/dist/graph/types.d.ts +12 -1
- package/dist/index.d.ts +12 -3
- package/dist/index.js +53 -7
- package/dist/logging/index.d.ts +10 -0
- package/dist/logging/index.js +23 -0
- package/dist/logging/query-logging.d.ts +82 -0
- package/dist/logging/query-logging.js +102 -0
- package/dist/models/associations.d.ts +38 -0
- package/dist/models/associations.js +16 -0
- package/dist/models/decorators.d.ts +55 -19
- package/dist/models/decorators.js +95 -19
- package/dist/models/eager-load.d.ts +99 -0
- package/dist/models/eager-load.js +348 -5
- package/dist/models/indexes.d.ts +3 -2
- package/dist/models/indexes.js +7 -1
- package/dist/models/model.js +69 -43
- package/dist/prorm.d.ts +175 -409
- package/dist/prorm.js +1132 -553
- package/dist/query-builders/order-limit-builder.js +12 -10
- package/dist/query-builders/sql-compiler.d.ts +10 -3
- package/dist/query-builders/sql-compiler.js +14 -43
- package/dist/query-interface.d.ts +2 -1
- package/dist/schema-objects.d.ts +42 -0
- package/dist/schema-objects.js +28 -0
- package/dist/sql-constants.d.ts +44 -0
- package/dist/sql-constants.js +138 -1
- package/dist/types/index.d.ts +387 -17
- package/dist/types/index.js +10 -15
- package/dist/types/query-types.d.ts +26 -0
- package/dist/types/query-types.js +30 -0
- package/package.json +39 -8
- package/dist/decorators/belongs-to-many.js +0 -115
- package/dist/decorators/belongs-to.js +0 -115
- package/dist/decorators/has-many.js +0 -127
- package/dist/decorators/has-one.js +0 -116
- package/dist/diagrams/palette.d.ts +0 -138
- package/dist/diagrams/palette.js +0 -194
- package/dist/hooks/hooks-manager.d.ts +0 -189
- package/dist/hooks/hooks-manager.js +0 -350
- package/dist/hooks/index.d.ts +0 -8
- package/dist/hooks/index.js +0 -37
- /package/dist/{logging.d.ts → logging/logger.d.ts} +0 -0
- /package/dist/{logging.js → logging/logger.js} +0 -0
package/dist/types/index.d.ts
CHANGED
|
@@ -520,6 +520,11 @@ export interface DropPolicyOptions {
|
|
|
520
520
|
/** Schema (for PostgreSQL) */
|
|
521
521
|
schema?: string;
|
|
522
522
|
}
|
|
523
|
+
/**
|
|
524
|
+
* Every SQL dialect prorm can target. The value chosen here decides which
|
|
525
|
+
* `Dialect` implementation compiles your `FindOptions` into SQL, so it governs
|
|
526
|
+
* identifier quoting, pagination syntax and which clauses are legal.
|
|
527
|
+
*/
|
|
523
528
|
export type Dialect = 'mysql' | 'postgres' | 'sqlite' | 'mssql' | 'mariadb' | 'oracle' | 'cockroachdb' | 'redshift' | 'db2' | 'snowflake' | 'clickhouse' | 'duckdb' | 'hana' | 'spanner' | 'turso' | 'tidb' | 'singlestore' | 'yugabytedb' | 'timescaledb' | 'greenplum' | 'vertica' | 'trino' | 'exasol' | 'questdb' | 'cratedb' | 'firebird' | 'databricks';
|
|
524
529
|
/**
|
|
525
530
|
* Query event data emitted when a query is executed
|
|
@@ -564,6 +569,11 @@ export interface PrormEvents {
|
|
|
564
569
|
/** Fired when there's an error */
|
|
565
570
|
error: (error: Error) => void;
|
|
566
571
|
}
|
|
572
|
+
/**
|
|
573
|
+
* Everything needed to construct a `Prorm` instance: which engine to
|
|
574
|
+
* talk to, how to reach it, and the cross-cutting behaviour (pooling, retries,
|
|
575
|
+
* logging, caching) that applies to every query it runs.
|
|
576
|
+
*/
|
|
567
577
|
export interface PrormOptions {
|
|
568
578
|
dialect: Dialect;
|
|
569
579
|
database?: string;
|
|
@@ -572,7 +582,23 @@ export interface PrormOptions {
|
|
|
572
582
|
host?: string;
|
|
573
583
|
port?: number;
|
|
574
584
|
storage?: string;
|
|
585
|
+
/**
|
|
586
|
+
* Query logging, following Sequelize's contract:
|
|
587
|
+
* `false` off, `true` console.log, or a function called as `(sql, timing)`.
|
|
588
|
+
* A per-query `logging` overrides this for that call.
|
|
589
|
+
*/
|
|
575
590
|
logging?: boolean | ((sql: string, timing?: number) => void);
|
|
591
|
+
/**
|
|
592
|
+
* Append the elapsed time to each logged query, and log even when `logging`
|
|
593
|
+
* was never set. Matches Sequelize's `benchmark`.
|
|
594
|
+
*/
|
|
595
|
+
benchmark?: boolean;
|
|
596
|
+
/**
|
|
597
|
+
* Append the values bound to each statement. Off by default: bound values
|
|
598
|
+
* routinely contain credentials and personal data, so this must be opted
|
|
599
|
+
* into deliberately.
|
|
600
|
+
*/
|
|
601
|
+
logQueryParameters?: boolean;
|
|
576
602
|
loggingLevel?: LoggingLevel | 'debug' | 'info' | 'warn' | 'error';
|
|
577
603
|
logSQL?: boolean;
|
|
578
604
|
logSlowQueries?: boolean;
|
|
@@ -640,6 +666,11 @@ export interface SlowQueryEvent extends QueryEvent {
|
|
|
640
666
|
/** The threshold that was exceeded (in ms) */
|
|
641
667
|
threshold: number;
|
|
642
668
|
}
|
|
669
|
+
/**
|
|
670
|
+
* Connection-pool sizing and lifecycle. A pooled connection is shared, so
|
|
671
|
+
* session state set on one query is not guaranteed to be visible to the next —
|
|
672
|
+
* use `onConnect` for settings that must apply to every connection.
|
|
673
|
+
*/
|
|
643
674
|
export interface PoolOptions {
|
|
644
675
|
/** Maximum number of connections in the pool */
|
|
645
676
|
max?: number;
|
|
@@ -662,6 +693,11 @@ export interface PoolOptions {
|
|
|
662
693
|
/** Log pool operations (acquire, release, etc.) */
|
|
663
694
|
logPoolOperations?: boolean;
|
|
664
695
|
}
|
|
696
|
+
/**
|
|
697
|
+
* Automatic retry policy for transient connection failures. `match` decides
|
|
698
|
+
* which errors are considered transient; anything unmatched fails immediately
|
|
699
|
+
* rather than being retried.
|
|
700
|
+
*/
|
|
665
701
|
export interface RetryOptions {
|
|
666
702
|
/** Maximum number of retry attempts (default: 3) */
|
|
667
703
|
max?: number;
|
|
@@ -676,6 +712,10 @@ export interface RetryOptions {
|
|
|
676
712
|
/** Maximum backoff time in ms (default: 10000) */
|
|
677
713
|
backoffMax?: number;
|
|
678
714
|
}
|
|
715
|
+
/**
|
|
716
|
+
* Per-model configuration: the table it maps to, whether timestamps and soft
|
|
717
|
+
* deletes are managed, and how attribute names are converted to column names.
|
|
718
|
+
*/
|
|
679
719
|
export interface ModelOptions {
|
|
680
720
|
tableName?: string;
|
|
681
721
|
/** Schema to use for this model (PostgreSQL) or database (MySQL) */
|
|
@@ -752,12 +792,20 @@ export declare enum SortDirection {
|
|
|
752
792
|
ASC = "ASC",
|
|
753
793
|
DESC = "DESC"
|
|
754
794
|
}
|
|
795
|
+
/**
|
|
796
|
+
* One column within an index, with the per-column modifiers (sort direction,
|
|
797
|
+
* collation, prefix length) that the engine supports.
|
|
798
|
+
*/
|
|
755
799
|
export interface IndexField {
|
|
756
800
|
name: string;
|
|
757
801
|
length?: number;
|
|
758
802
|
order?: SortDirection | 'ASC' | 'DESC';
|
|
759
803
|
collate?: string;
|
|
760
804
|
}
|
|
805
|
+
/**
|
|
806
|
+
* An index to create alongside the table. `where` produces a partial index,
|
|
807
|
+
* which several engines do not support — see the indexes guide for the matrix.
|
|
808
|
+
*/
|
|
761
809
|
export interface IndexOptions {
|
|
762
810
|
name?: string;
|
|
763
811
|
/** Single field name or array of field names for composite indexes */
|
|
@@ -765,7 +813,8 @@ export interface IndexOptions {
|
|
|
765
813
|
unique?: boolean;
|
|
766
814
|
type?: string;
|
|
767
815
|
using?: string;
|
|
768
|
-
where
|
|
816
|
+
/** Partial-index predicate; see `IndexOptions.where` in `src/dialects/dialect.ts`. */
|
|
817
|
+
where?: WhereOptions | string;
|
|
769
818
|
/** PostgreSQL: specify tablespace for the index */
|
|
770
819
|
tablespace?: string;
|
|
771
820
|
/** PostgreSQL: index storage parameters */
|
|
@@ -792,6 +841,10 @@ export interface IndexExpression {
|
|
|
792
841
|
/** Optional name for the expression */
|
|
793
842
|
name?: string;
|
|
794
843
|
}
|
|
844
|
+
/**
|
|
845
|
+
* A table constraint: primary key, unique, check, foreign key or exclusion.
|
|
846
|
+
* Composite constraints list every participating column in `fields`.
|
|
847
|
+
*/
|
|
795
848
|
export interface ConstraintOptions {
|
|
796
849
|
/** Custom constraint name (auto-generated if not provided) */
|
|
797
850
|
name?: string;
|
|
@@ -1004,6 +1057,10 @@ export interface InstanceValidateOptions {
|
|
|
1004
1057
|
/** Validate on update only (for instance validation) */
|
|
1005
1058
|
validateOnUpdate?: boolean;
|
|
1006
1059
|
}
|
|
1060
|
+
/**
|
|
1061
|
+
* A named, reusable fragment of `FindOptions` that a model can apply by name,
|
|
1062
|
+
* either always (the default scope) or on request.
|
|
1063
|
+
*/
|
|
1007
1064
|
export interface ScopeOptions {
|
|
1008
1065
|
attributes?: FindOptions['attributes'];
|
|
1009
1066
|
where?: WhereOptions;
|
|
@@ -1013,10 +1070,21 @@ export interface ScopeOptions {
|
|
|
1013
1070
|
offset?: number;
|
|
1014
1071
|
transaction?: Transaction;
|
|
1015
1072
|
}
|
|
1073
|
+
/**
|
|
1074
|
+
* Model-level validators, which run after per-attribute validation and can
|
|
1075
|
+
* therefore see the whole instance — the place for rules that span fields.
|
|
1076
|
+
*/
|
|
1016
1077
|
export interface ModelValidationOptions {
|
|
1017
1078
|
[key: string]: ValidationMethod | ValidationChain;
|
|
1018
1079
|
}
|
|
1080
|
+
/**
|
|
1081
|
+
* The name of a built-in validator, or a custom function.
|
|
1082
|
+
*/
|
|
1019
1083
|
export type ValidationMethod = (value: any) => boolean | string | Error;
|
|
1084
|
+
/**
|
|
1085
|
+
* An ordered list of validators applied to one attribute, evaluated until one
|
|
1086
|
+
* fails.
|
|
1087
|
+
*/
|
|
1020
1088
|
export interface ValidationChain {
|
|
1021
1089
|
is: [RegExp | string, string?];
|
|
1022
1090
|
not: [RegExp | string, string?];
|
|
@@ -1046,89 +1114,164 @@ export interface ValidationChain {
|
|
|
1046
1114
|
max: number;
|
|
1047
1115
|
min: number;
|
|
1048
1116
|
}
|
|
1117
|
+
/**
|
|
1118
|
+
* Any column type. The union covers the built-in `DataTypes` factories and the
|
|
1119
|
+
* dialect-specific types layered on top of them.
|
|
1120
|
+
*/
|
|
1049
1121
|
export type DataType = DataTypeString | DataTypeChar | DataTypeText | DataTypeNumber | DataTypeInteger | DataTypeBigInt | DataTypeFloat | DataTypeDouble | DataTypeDecimal | DataTypeBoolean | DataTypeDate | DataTypeDateOnly | DataTypeTime | DataTypeBlob | DataTypeEnum | DataTypeJSON | DataTypeJSONB | DataTypeUUID | DataTypeGeometry | DataTypeSET | DataTypeHStore | DataTypeRange | DataTypeInet | DataTypeCidr | DataTypeMacAddr | string;
|
|
1122
|
+
/**
|
|
1123
|
+
* The shape every data type shares: a `key` identifying it and a `toSql()`
|
|
1124
|
+
* that renders the engine-specific column type.
|
|
1125
|
+
*/
|
|
1050
1126
|
export interface DataTypeAbstract {
|
|
1051
1127
|
key: string;
|
|
1052
1128
|
toSql?: () => string;
|
|
1053
1129
|
}
|
|
1130
|
+
/**
|
|
1131
|
+
* Variable-length character data, `VARCHAR(n)` on most engines.
|
|
1132
|
+
*/
|
|
1054
1133
|
export interface DataTypeString extends DataTypeAbstract {
|
|
1055
1134
|
key: 'STRING';
|
|
1056
1135
|
length: number;
|
|
1057
1136
|
}
|
|
1137
|
+
/**
|
|
1138
|
+
* Fixed-length character data, `CHAR(n)`; shorter values are space-padded.
|
|
1139
|
+
*/
|
|
1058
1140
|
export interface DataTypeChar extends DataTypeAbstract {
|
|
1059
1141
|
key: 'CHAR';
|
|
1060
1142
|
length: number;
|
|
1061
1143
|
}
|
|
1144
|
+
/**
|
|
1145
|
+
* Unbounded character data. The size variants map to the engine's own
|
|
1146
|
+
* `TINYTEXT`/`MEDIUMTEXT`/`LONGTEXT` where those exist.
|
|
1147
|
+
*/
|
|
1062
1148
|
export interface DataTypeText extends DataTypeAbstract {
|
|
1063
1149
|
key: 'TEXT';
|
|
1064
1150
|
length?: number;
|
|
1065
1151
|
}
|
|
1152
|
+
/**
|
|
1153
|
+
* Shared options for the numeric types: precision, scale, sign and zero-fill.
|
|
1154
|
+
*/
|
|
1066
1155
|
export interface DataTypeNumber extends DataTypeAbstract {
|
|
1067
1156
|
key: 'NUMBER';
|
|
1068
1157
|
precision: number;
|
|
1069
1158
|
scale: number;
|
|
1070
1159
|
}
|
|
1160
|
+
/**
|
|
1161
|
+
* A 32-bit integer.
|
|
1162
|
+
*/
|
|
1071
1163
|
export interface DataTypeInteger extends DataTypeAbstract {
|
|
1072
1164
|
key: 'INTEGER';
|
|
1073
1165
|
length?: number;
|
|
1074
1166
|
unsigned?: boolean;
|
|
1075
1167
|
zerofill?: boolean;
|
|
1076
1168
|
}
|
|
1169
|
+
/**
|
|
1170
|
+
* A 64-bit integer. Values beyond `Number.MAX_SAFE_INTEGER` are returned as
|
|
1171
|
+
* strings by most drivers, so treat the result as a string when the range
|
|
1172
|
+
* matters.
|
|
1173
|
+
*/
|
|
1077
1174
|
export interface DataTypeBigInt extends DataTypeAbstract {
|
|
1078
1175
|
key: 'BIGINT';
|
|
1079
1176
|
length?: number;
|
|
1080
1177
|
unsigned?: boolean;
|
|
1081
1178
|
}
|
|
1179
|
+
/**
|
|
1180
|
+
* Single-precision floating point. Inexact — do not use for money.
|
|
1181
|
+
*/
|
|
1082
1182
|
export interface DataTypeFloat extends DataTypeAbstract {
|
|
1083
1183
|
key: 'FLOAT';
|
|
1084
1184
|
length?: number;
|
|
1085
1185
|
decimals?: number;
|
|
1086
1186
|
unsigned?: boolean;
|
|
1087
1187
|
}
|
|
1188
|
+
/**
|
|
1189
|
+
* Double-precision floating point. Inexact — do not use for money.
|
|
1190
|
+
*/
|
|
1088
1191
|
export interface DataTypeDouble extends DataTypeAbstract {
|
|
1089
1192
|
key: 'DOUBLE';
|
|
1090
1193
|
length?: number;
|
|
1091
1194
|
decimals?: number;
|
|
1092
1195
|
unsigned?: boolean;
|
|
1093
1196
|
}
|
|
1197
|
+
/**
|
|
1198
|
+
* Exact fixed-point numeric with the given precision and scale. The type to
|
|
1199
|
+
* use for money.
|
|
1200
|
+
*/
|
|
1094
1201
|
export interface DataTypeDecimal extends DataTypeAbstract {
|
|
1095
1202
|
key: 'DECIMAL';
|
|
1096
1203
|
precision: number;
|
|
1097
1204
|
scale: number;
|
|
1098
1205
|
unsigned?: boolean;
|
|
1099
1206
|
}
|
|
1207
|
+
/**
|
|
1208
|
+
* A boolean. Engines without a native boolean store it as a small integer or
|
|
1209
|
+
* a single character; the dialect handles the conversion.
|
|
1210
|
+
*/
|
|
1100
1211
|
export interface DataTypeBoolean extends DataTypeAbstract {
|
|
1101
1212
|
key: 'BOOLEAN';
|
|
1102
1213
|
}
|
|
1214
|
+
/**
|
|
1215
|
+
* A timestamp, with time zone where the engine supports one.
|
|
1216
|
+
*/
|
|
1103
1217
|
export interface DataTypeDate extends DataTypeAbstract {
|
|
1104
1218
|
key: 'DATE';
|
|
1105
1219
|
precision?: number;
|
|
1106
1220
|
timezone?: boolean;
|
|
1107
1221
|
}
|
|
1222
|
+
/**
|
|
1223
|
+
* A calendar date with no time component.
|
|
1224
|
+
*/
|
|
1108
1225
|
export interface DataTypeDateOnly extends DataTypeAbstract {
|
|
1109
1226
|
key: 'DATEONLY';
|
|
1110
1227
|
}
|
|
1228
|
+
/**
|
|
1229
|
+
* A time of day with no date component.
|
|
1230
|
+
*/
|
|
1111
1231
|
export interface DataTypeTime extends DataTypeAbstract {
|
|
1112
1232
|
key: 'TIME';
|
|
1113
1233
|
precision?: number;
|
|
1114
1234
|
}
|
|
1235
|
+
/**
|
|
1236
|
+
* Binary data. The size variants map to the engine's own blob types.
|
|
1237
|
+
*/
|
|
1115
1238
|
export interface DataTypeBlob extends DataTypeAbstract {
|
|
1116
1239
|
key: 'BLOB';
|
|
1117
1240
|
length?: 'tiny' | 'medium' | 'long';
|
|
1118
1241
|
}
|
|
1242
|
+
/**
|
|
1243
|
+
* A column restricted to a fixed set of string values. Engines without native
|
|
1244
|
+
* enums emit a check constraint instead.
|
|
1245
|
+
*/
|
|
1119
1246
|
export interface DataTypeEnum extends DataTypeAbstract {
|
|
1120
1247
|
key: 'ENUM';
|
|
1121
1248
|
values: string[];
|
|
1122
1249
|
}
|
|
1250
|
+
/**
|
|
1251
|
+
* A JSON document. Values round-trip as parsed JavaScript values on every
|
|
1252
|
+
* dialect — the write side encodes and the read side parses, so a string is
|
|
1253
|
+
* returned as the string it was stored as.
|
|
1254
|
+
*/
|
|
1123
1255
|
export interface DataTypeJSON extends DataTypeAbstract {
|
|
1124
1256
|
key: 'JSON';
|
|
1125
1257
|
}
|
|
1258
|
+
/**
|
|
1259
|
+
* PostgreSQL's binary JSON: indexable and faster to query than {@link
|
|
1260
|
+
* DataTypeJSON}, at the cost of not preserving key order or whitespace.
|
|
1261
|
+
*/
|
|
1126
1262
|
export interface DataTypeJSONB extends DataTypeAbstract {
|
|
1127
1263
|
key: 'JSONB';
|
|
1128
1264
|
}
|
|
1265
|
+
/**
|
|
1266
|
+
* A UUID, stored natively where the engine has the type and as a 36-character
|
|
1267
|
+
* string where it does not.
|
|
1268
|
+
*/
|
|
1129
1269
|
export interface DataTypeUUID extends DataTypeAbstract {
|
|
1130
1270
|
key: 'UUID';
|
|
1131
1271
|
}
|
|
1272
|
+
/**
|
|
1273
|
+
* A spatial value (point, polygon and so on), with an optional SRID.
|
|
1274
|
+
*/
|
|
1132
1275
|
export interface DataTypeGeometry extends DataTypeAbstract {
|
|
1133
1276
|
key: 'GEOMETRY';
|
|
1134
1277
|
type: string;
|
|
@@ -1158,6 +1301,10 @@ export interface SetColumnOptions {
|
|
|
1158
1301
|
/** Optional name for the SET type (useful for custom types) */
|
|
1159
1302
|
name?: string;
|
|
1160
1303
|
}
|
|
1304
|
+
/**
|
|
1305
|
+
* A computed attribute that exists on the instance but has no column. Declare
|
|
1306
|
+
* the fields it reads so a query that selects it also selects its inputs.
|
|
1307
|
+
*/
|
|
1161
1308
|
export interface DataTypeVirtual extends DataTypeAbstract {
|
|
1162
1309
|
key: 'VIRTUAL';
|
|
1163
1310
|
returnType?: DataType;
|
|
@@ -1206,6 +1353,10 @@ export interface DataTypeHStore extends DataTypeAbstract {
|
|
|
1206
1353
|
* - daterange: Range of date
|
|
1207
1354
|
*/
|
|
1208
1355
|
export type RangeSubtype = 'int4range' | 'int8range' | 'numrange' | 'tsrange' | 'tstzrange' | 'daterange';
|
|
1356
|
+
/**
|
|
1357
|
+
* A PostgreSQL range type over another type, such as `int4range` or
|
|
1358
|
+
* `tstzrange`.
|
|
1359
|
+
*/
|
|
1209
1360
|
export interface DataTypeRange extends DataTypeAbstract {
|
|
1210
1361
|
key: 'RANGE';
|
|
1211
1362
|
subtype: RangeSubtype;
|
|
@@ -1304,6 +1455,10 @@ export interface ArrayOperatorOptions {
|
|
|
1304
1455
|
/** Array ALL operator */
|
|
1305
1456
|
$arrayAll?: any;
|
|
1306
1457
|
}
|
|
1458
|
+
/**
|
|
1459
|
+
* One column of a model: its type, nullability, default, key membership and
|
|
1460
|
+
* the name it maps to in the database.
|
|
1461
|
+
*/
|
|
1307
1462
|
export interface AttributeOptions {
|
|
1308
1463
|
type: DataType;
|
|
1309
1464
|
allowNull?: boolean;
|
|
@@ -1335,6 +1490,10 @@ export interface AttributeOptions {
|
|
|
1335
1490
|
hidden?: boolean;
|
|
1336
1491
|
virtual?: boolean;
|
|
1337
1492
|
}
|
|
1493
|
+
/**
|
|
1494
|
+
* The target of a foreign key — which table and column it points at, and what
|
|
1495
|
+
* happens on update or delete.
|
|
1496
|
+
*/
|
|
1338
1497
|
export interface ReferenceOptions {
|
|
1339
1498
|
model: string | ModelStatic<any>;
|
|
1340
1499
|
key?: string;
|
|
@@ -1342,6 +1501,11 @@ export interface ReferenceOptions {
|
|
|
1342
1501
|
onDelete?: ReferentialAction | 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'NO ACTION' | 'SET DEFAULT';
|
|
1343
1502
|
onUpdate?: ReferentialAction | 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'NO ACTION' | 'SET DEFAULT';
|
|
1344
1503
|
}
|
|
1504
|
+
/**
|
|
1505
|
+
* The lifecycle callbacks a model can declare. `beforeSave`/`afterSave` wrap
|
|
1506
|
+
* both create and update, so shared logic belongs there rather than duplicated
|
|
1507
|
+
* across the pair.
|
|
1508
|
+
*/
|
|
1345
1509
|
export interface ModelHooks {
|
|
1346
1510
|
beforeValidate?: HookHandler;
|
|
1347
1511
|
afterValidate?: HookHandler;
|
|
@@ -1362,10 +1526,25 @@ export interface ModelHooks {
|
|
|
1362
1526
|
beforeFind?: FindHookHandler;
|
|
1363
1527
|
afterFind?: AfterFindHookHandler;
|
|
1364
1528
|
}
|
|
1529
|
+
/**
|
|
1530
|
+
* A hook that runs before a read, and may modify the options in place.
|
|
1531
|
+
*/
|
|
1365
1532
|
export type FindHookHandler = (options: FindOptions, model: ModelStatic<any>) => Promise<void> | void;
|
|
1533
|
+
/**
|
|
1534
|
+
* A hook that runs after a read, receiving the instances it produced.
|
|
1535
|
+
*/
|
|
1366
1536
|
export type AfterFindHookHandler = (instances: Model[], options: FindOptions, model: ModelStatic<any>) => Promise<void> | void;
|
|
1537
|
+
/**
|
|
1538
|
+
* A hook receiving a single instance and the options for the operation.
|
|
1539
|
+
*/
|
|
1367
1540
|
export type HookHandler = (instance: Model, options?: HookOptions) => Promise<void> | void;
|
|
1541
|
+
/**
|
|
1542
|
+
* A hook receiving every instance in a bulk operation at once.
|
|
1543
|
+
*/
|
|
1368
1544
|
export type BulkHookHandler = (instances?: Model[], options?: HookOptions) => Promise<void> | void;
|
|
1545
|
+
/**
|
|
1546
|
+
* Controls whether hooks run for an operation, and which ones.
|
|
1547
|
+
*/
|
|
1369
1548
|
export interface HookOptions {
|
|
1370
1549
|
transaction?: Transaction;
|
|
1371
1550
|
hooks?: boolean;
|
|
@@ -1377,9 +1556,16 @@ export interface HookOptions {
|
|
|
1377
1556
|
model?: any;
|
|
1378
1557
|
instances?: Model[];
|
|
1379
1558
|
}
|
|
1559
|
+
/**
|
|
1560
|
+
* A `WHERE` clause: attribute/value pairs, operator objects, or nested
|
|
1561
|
+
* `and`/`or`/`not` groups.
|
|
1562
|
+
*/
|
|
1380
1563
|
export type WhereOptions<T = any> = {
|
|
1381
1564
|
[key: string]: any;
|
|
1382
1565
|
} | WhereLogical<T>;
|
|
1566
|
+
/**
|
|
1567
|
+
* The logical combinators available inside a `WHERE` clause.
|
|
1568
|
+
*/
|
|
1383
1569
|
export interface WhereLogical<T> {
|
|
1384
1570
|
$and?: WhereOptions<T>[];
|
|
1385
1571
|
$or?: WhereOptions<T>[];
|
|
@@ -1451,6 +1637,10 @@ export interface SubqueryOptions {
|
|
|
1451
1637
|
export type HavingOptions<T = any> = {
|
|
1452
1638
|
[key: string]: any;
|
|
1453
1639
|
} | HavingLogical<T>;
|
|
1640
|
+
/**
|
|
1641
|
+
* The logical combinators available inside a `HAVING` clause, applied after
|
|
1642
|
+
* grouping rather than before it.
|
|
1643
|
+
*/
|
|
1454
1644
|
export interface HavingLogical<T> {
|
|
1455
1645
|
$and?: HavingOptions<T>[];
|
|
1456
1646
|
$or?: HavingOptions<T>[];
|
|
@@ -1465,6 +1655,9 @@ export interface HavingLogical<T> {
|
|
|
1465
1655
|
* - Literal SQL with alias: [['COUNT(*)', 'count']]
|
|
1466
1656
|
*/
|
|
1467
1657
|
export type AttributeValue = string | [any, string] | [any, any, string];
|
|
1658
|
+
/**
|
|
1659
|
+
* Which columns to select — a list, or an include/exclude pair.
|
|
1660
|
+
*/
|
|
1468
1661
|
export type AttributesOptions = string[] | {
|
|
1469
1662
|
include?: string[];
|
|
1470
1663
|
exclude?: string[];
|
|
@@ -1516,9 +1709,28 @@ export interface UnpivotOptions {
|
|
|
1516
1709
|
/** Name for the column name column in the result */
|
|
1517
1710
|
nameColumn: string;
|
|
1518
1711
|
}
|
|
1712
|
+
/**
|
|
1713
|
+
* The single options object every finder compiles into SQL. `where`,
|
|
1714
|
+
* `include`, `order`, `limit`, locking and the rest behave identically
|
|
1715
|
+
* whichever finder you call.
|
|
1716
|
+
*/
|
|
1519
1717
|
export interface FindOptions {
|
|
1520
1718
|
where?: WhereOptions;
|
|
1521
1719
|
attributes?: AttributesOptions;
|
|
1720
|
+
/**
|
|
1721
|
+
* Association aliases to count without loading their rows. Each sets
|
|
1722
|
+
* `<alias>Count` on every returned row.
|
|
1723
|
+
*
|
|
1724
|
+
* ```typescript
|
|
1725
|
+
* const users = await User.findAll({ withCount: ['posts'] });
|
|
1726
|
+
* users[0].postsCount; // number
|
|
1727
|
+
* ```
|
|
1728
|
+
*
|
|
1729
|
+
* Resolved with one grouped query per association, so the statement count
|
|
1730
|
+
* does not grow with the number of parent rows. Prefer this over a full
|
|
1731
|
+
* `include` when you only need the size.
|
|
1732
|
+
*/
|
|
1733
|
+
withCount?: string[];
|
|
1522
1734
|
/** Schema to use for the main table */
|
|
1523
1735
|
schema?: string;
|
|
1524
1736
|
/**
|
|
@@ -1703,6 +1915,10 @@ export interface FindOptions {
|
|
|
1703
1915
|
*/
|
|
1704
1916
|
streamHighWatermark?: number;
|
|
1705
1917
|
}
|
|
1918
|
+
/**
|
|
1919
|
+
* Options for `findOrCreate`: the search criteria plus the `defaults` used
|
|
1920
|
+
* only when nothing matched.
|
|
1921
|
+
*/
|
|
1706
1922
|
export interface FindOrCreateOptions<T = any> extends FindOptions {
|
|
1707
1923
|
/** Default values to use when creating a new record if not found */
|
|
1708
1924
|
defaults?: Partial<T>;
|
|
@@ -1711,6 +1927,10 @@ export interface FindOrCreateOptions<T = any> extends FindOptions {
|
|
|
1711
1927
|
/** Whether to validate the model before creation (default: true) */
|
|
1712
1928
|
validate?: boolean;
|
|
1713
1929
|
}
|
|
1930
|
+
/**
|
|
1931
|
+
* An `ORDER BY` clause. Use the array-of-arrays form — a bare string is not
|
|
1932
|
+
* parsed into column and direction.
|
|
1933
|
+
*/
|
|
1714
1934
|
export type Order = OrderItem[] | string | [string, string][] | import('../operators').OrderExpression[];
|
|
1715
1935
|
/**
|
|
1716
1936
|
* Options for JSON path extraction
|
|
@@ -1823,27 +2043,35 @@ export interface DWithinOptions {
|
|
|
1823
2043
|
* GROUP BY clause format
|
|
1824
2044
|
*/
|
|
1825
2045
|
export type GroupBy = string | string[] | GroupByItem[];
|
|
2046
|
+
/**
|
|
2047
|
+
* One `GROUP BY` term: a column, a literal, or a function call.
|
|
2048
|
+
*/
|
|
1826
2049
|
export interface GroupByItem {
|
|
1827
2050
|
model?: ModelStatic<any>;
|
|
1828
2051
|
as?: string;
|
|
1829
2052
|
}
|
|
1830
2053
|
/**
|
|
1831
2054
|
* Lock types for row-level locking
|
|
1832
|
-
* - 'UPDATE': FOR UPDATE (PostgreSQL/MySQL) - prevents other transactions from modifying the rows
|
|
1833
|
-
* - 'SHARE': FOR SHARE (PostgreSQL) / LOCK IN SHARE MODE (MySQL) - allows other transactions to read but not modify
|
|
1834
|
-
* - 'KEY SHARE': FOR KEY SHARE (PostgreSQL only) - prevents key updates but allows row updates
|
|
2055
|
+
* - 'UPDATE': FOR UPDATE (PostgreSQL/MySQL/MariaDB/Oracle/Db2/HANA, UPDLOCK on SQL Server) - prevents other transactions from modifying the rows
|
|
2056
|
+
* - 'SHARE': FOR SHARE (PostgreSQL) / LOCK IN SHARE MODE (MySQL/MariaDB, or FOR SHARE when a modifier is used) / HOLDLOCK (SQL Server) - allows other transactions to read but not modify
|
|
2057
|
+
* - 'KEY SHARE': FOR KEY SHARE (PostgreSQL/CockroachDB only) - prevents key updates but allows row updates
|
|
2058
|
+
* - 'NO KEY UPDATE': FOR NO KEY UPDATE (PostgreSQL/CockroachDB only) - like UPDATE but does not block KEY SHARE lockers
|
|
2059
|
+
*
|
|
2060
|
+
* A dialect that cannot express the requested level throws when the query is
|
|
2061
|
+
* built, rather than silently falling back to a weaker lock (or to none).
|
|
1835
2062
|
*/
|
|
1836
2063
|
export declare enum LockLevel {
|
|
1837
2064
|
Share = "SHARE",
|
|
1838
2065
|
Update = "UPDATE",
|
|
1839
|
-
KeyShare = "KEY SHARE"
|
|
2066
|
+
KeyShare = "KEY SHARE",
|
|
2067
|
+
NoKeyUpdate = "NO KEY UPDATE"
|
|
1840
2068
|
}
|
|
1841
2069
|
/**
|
|
1842
2070
|
* Lock types for row-level locking
|
|
1843
2071
|
*
|
|
1844
2072
|
* Accepts either the raw string literals or the equivalent {@link LockLevel} enum member.
|
|
1845
2073
|
*/
|
|
1846
|
-
export type LockType = 'SHARE' | 'UPDATE' | 'KEY SHARE' | LockLevel;
|
|
2074
|
+
export type LockType = 'SHARE' | 'UPDATE' | 'KEY SHARE' | 'NO KEY UPDATE' | LockLevel;
|
|
1847
2075
|
/**
|
|
1848
2076
|
* Lock options for row-level locking
|
|
1849
2077
|
* @example
|
|
@@ -1861,6 +2089,15 @@ export type LockType = 'SHARE' | 'UPDATE' | 'KEY SHARE' | LockLevel;
|
|
|
1861
2089
|
*
|
|
1862
2090
|
* // SKIP LOCKED - skip locked rows (PostgreSQL/MySQL 8.0+)
|
|
1863
2091
|
* User.findAll({ lock: { level: 'UPDATE', skipLocked: true } })
|
|
2092
|
+
*
|
|
2093
|
+
* // Modifiers on their own imply FOR UPDATE
|
|
2094
|
+
* User.findAll({ lock: { skipLocked: true } })
|
|
2095
|
+
*
|
|
2096
|
+
* @remarks
|
|
2097
|
+
* `nowait` and `skipLocked` are mutually exclusive - setting both throws.
|
|
2098
|
+
* Dialects with no row-level locking (SQLite and friends) ignore `lock`
|
|
2099
|
+
* entirely; dialects that have locking but cannot express the exact request
|
|
2100
|
+
* (e.g. `SHARE` on Oracle, `SKIP LOCKED` on Db2) throw when the query is built.
|
|
1864
2101
|
*/
|
|
1865
2102
|
export type LockOptions = LockType | boolean | {
|
|
1866
2103
|
of: ModelStatic<any>;
|
|
@@ -1884,6 +2121,10 @@ export interface NowaitOptions {
|
|
|
1884
2121
|
export interface SkipLockedOptions {
|
|
1885
2122
|
skipLocked: true;
|
|
1886
2123
|
}
|
|
2124
|
+
/**
|
|
2125
|
+
* An association to eager-load, given as the model, its alias, or a full
|
|
2126
|
+
* {@link IncludeOptions}.
|
|
2127
|
+
*/
|
|
1887
2128
|
export interface Includeable {
|
|
1888
2129
|
/** The model to include */
|
|
1889
2130
|
model: ModelStatic<any>;
|
|
@@ -1909,6 +2150,10 @@ export interface Includeable {
|
|
|
1909
2150
|
*/
|
|
1910
2151
|
as?: string;
|
|
1911
2152
|
}
|
|
2153
|
+
/**
|
|
2154
|
+
* A single eager-loaded association: which one, what to select from it,
|
|
2155
|
+
* whether it filters the parent (`required`), and any nesting beneath it.
|
|
2156
|
+
*/
|
|
1912
2157
|
export interface IncludeOptions extends Includeable {
|
|
1913
2158
|
where?: WhereOptions;
|
|
1914
2159
|
attributes?: string[] | {
|
|
@@ -2091,6 +2336,10 @@ export interface AntiJoinOptions {
|
|
|
2091
2336
|
*/
|
|
2092
2337
|
type?: 'notExists' | 'notIn' | 'leftJoinIsNull';
|
|
2093
2338
|
}
|
|
2339
|
+
/**
|
|
2340
|
+
* Options for inserting one row: which fields to write, whether to validate,
|
|
2341
|
+
* and the transaction to run inside.
|
|
2342
|
+
*/
|
|
2094
2343
|
export interface CreateOptions extends SaveOptions {
|
|
2095
2344
|
include?: Includeable[] | IncludeOptions[];
|
|
2096
2345
|
ignoreDuplicates?: boolean;
|
|
@@ -2105,6 +2354,10 @@ export interface CreateOptions extends SaveOptions {
|
|
|
2105
2354
|
*/
|
|
2106
2355
|
using?: string;
|
|
2107
2356
|
}
|
|
2357
|
+
/**
|
|
2358
|
+
* Options for updating rows: the `where` that selects them, which fields may
|
|
2359
|
+
* be written, and whether hooks run per row.
|
|
2360
|
+
*/
|
|
2108
2361
|
export interface UpdateOptions extends SaveOptions {
|
|
2109
2362
|
where: WhereOptions;
|
|
2110
2363
|
limit?: number;
|
|
@@ -2123,6 +2376,10 @@ export interface UpdateOptions extends SaveOptions {
|
|
|
2123
2376
|
*/
|
|
2124
2377
|
using?: string;
|
|
2125
2378
|
}
|
|
2379
|
+
/**
|
|
2380
|
+
* Options for deleting rows. On a paranoid model this soft-deletes unless
|
|
2381
|
+
* `force` is set.
|
|
2382
|
+
*/
|
|
2126
2383
|
export interface DestroyOptions extends HookOptions {
|
|
2127
2384
|
where: WhereOptions;
|
|
2128
2385
|
limit?: number;
|
|
@@ -2145,6 +2402,9 @@ export interface DestroyOptions extends HookOptions {
|
|
|
2145
2402
|
*/
|
|
2146
2403
|
using?: string;
|
|
2147
2404
|
}
|
|
2405
|
+
/**
|
|
2406
|
+
* Options for persisting an instance, whether that is an insert or an update.
|
|
2407
|
+
*/
|
|
2148
2408
|
export interface SaveOptions {
|
|
2149
2409
|
transaction?: Transaction;
|
|
2150
2410
|
hooks?: boolean;
|
|
@@ -2154,6 +2414,9 @@ export interface SaveOptions {
|
|
|
2154
2414
|
logging?: boolean | ((sql: string, time?: number) => void);
|
|
2155
2415
|
benchmark?: boolean;
|
|
2156
2416
|
}
|
|
2417
|
+
/**
|
|
2418
|
+
* Options for refetching an instance's current database state.
|
|
2419
|
+
*/
|
|
2157
2420
|
export interface ReloadOptions extends FindOptions {
|
|
2158
2421
|
/**
|
|
2159
2422
|
* Specify attributes to select when reloading from the database.
|
|
@@ -2165,6 +2428,10 @@ export interface ReloadOptions extends FindOptions {
|
|
|
2165
2428
|
*/
|
|
2166
2429
|
hooks?: boolean;
|
|
2167
2430
|
}
|
|
2431
|
+
/**
|
|
2432
|
+
* Shared options for every association: the alias it is exposed under, the
|
|
2433
|
+
* foreign key, and what happens to children when the parent goes.
|
|
2434
|
+
*/
|
|
2168
2435
|
export interface AssociationOptions {
|
|
2169
2436
|
as?: string;
|
|
2170
2437
|
/**
|
|
@@ -2208,6 +2475,10 @@ export interface AssociationOptions {
|
|
|
2208
2475
|
through?: string | ThroughOptions;
|
|
2209
2476
|
scope?: AssociationScope;
|
|
2210
2477
|
}
|
|
2478
|
+
/**
|
|
2479
|
+
* Foreign-key specifics for an association, when the defaults derived from
|
|
2480
|
+
* the model names are not what you want.
|
|
2481
|
+
*/
|
|
2211
2482
|
export interface AssociationForeignKeyOptions {
|
|
2212
2483
|
/** Custom name for the foreign key constraint */
|
|
2213
2484
|
name?: string;
|
|
@@ -2225,6 +2496,10 @@ export interface AssociationForeignKeyOptions {
|
|
|
2225
2496
|
/** Custom constraint name for the foreign key (alternative to 'name') */
|
|
2226
2497
|
constraintName?: string;
|
|
2227
2498
|
}
|
|
2499
|
+
/**
|
|
2500
|
+
* The join table of a many-to-many association, and any extra attributes
|
|
2501
|
+
* carried on it.
|
|
2502
|
+
*/
|
|
2228
2503
|
export interface ThroughOptions {
|
|
2229
2504
|
model: string | ModelStatic<any>;
|
|
2230
2505
|
as?: string;
|
|
@@ -2233,6 +2508,10 @@ export interface ThroughOptions {
|
|
|
2233
2508
|
scope?: AssociationScope;
|
|
2234
2509
|
timestamps?: boolean;
|
|
2235
2510
|
}
|
|
2511
|
+
/**
|
|
2512
|
+
* A filter applied to every query through an association — the mechanism
|
|
2513
|
+
* behind polymorphic associations.
|
|
2514
|
+
*/
|
|
2236
2515
|
export interface AssociationScope {
|
|
2237
2516
|
[key: string]: any;
|
|
2238
2517
|
}
|
|
@@ -2249,6 +2528,10 @@ export declare class Transaction {
|
|
|
2249
2528
|
commit(): Promise<void>;
|
|
2250
2529
|
rollback(): Promise<void>;
|
|
2251
2530
|
}
|
|
2531
|
+
/**
|
|
2532
|
+
* Options for a transaction: isolation level, type, and whether it nests as a
|
|
2533
|
+
* savepoint inside an outer transaction.
|
|
2534
|
+
*/
|
|
2252
2535
|
export interface TransactionOptions {
|
|
2253
2536
|
autocommit?: boolean;
|
|
2254
2537
|
/**
|
|
@@ -2302,6 +2585,10 @@ export declare enum IsolationLevel {
|
|
|
2302
2585
|
RepeatableRead = "REPEATABLE READ",
|
|
2303
2586
|
Serializable = "SERIALIZABLE"
|
|
2304
2587
|
}
|
|
2588
|
+
/**
|
|
2589
|
+
* The static side of a model class — the finders, writers and association
|
|
2590
|
+
* declarations, as opposed to an instance of it.
|
|
2591
|
+
*/
|
|
2305
2592
|
export interface ModelStatic<T extends Model> {
|
|
2306
2593
|
name: string;
|
|
2307
2594
|
tableName: string;
|
|
@@ -2697,6 +2984,10 @@ export interface ToJSONOptions {
|
|
|
2697
2984
|
*/
|
|
2698
2985
|
clone?: boolean;
|
|
2699
2986
|
}
|
|
2987
|
+
/**
|
|
2988
|
+
* The instance side of a model: the attribute accessors plus `save`,
|
|
2989
|
+
* `update`, `destroy`, `reload` and the association helpers.
|
|
2990
|
+
*/
|
|
2700
2991
|
export interface Model {
|
|
2701
2992
|
getDataValue(key: string): any;
|
|
2702
2993
|
setDataValue(key: string, value: any): void;
|
|
@@ -2720,6 +3011,10 @@ export interface Model {
|
|
|
2720
3011
|
reload(options?: FindOptions): Promise<this>;
|
|
2721
3012
|
toJSON(options?: ToJSONOptions): Record<string, any>;
|
|
2722
3013
|
}
|
|
3014
|
+
/**
|
|
3015
|
+
* A declared relationship between two models, and the metadata the query
|
|
3016
|
+
* builder needs to join them.
|
|
3017
|
+
*/
|
|
2723
3018
|
export interface Association {
|
|
2724
3019
|
source: ModelStatic<any>;
|
|
2725
3020
|
target: ModelStatic<any>;
|
|
@@ -2730,6 +3025,10 @@ export interface Association {
|
|
|
2730
3025
|
targetKey?: string | string[];
|
|
2731
3026
|
sourceKey?: string | string[];
|
|
2732
3027
|
}
|
|
3028
|
+
/**
|
|
3029
|
+
* Options for inserting many rows in one statement, including upsert
|
|
3030
|
+
* behaviour and whether each row is validated.
|
|
3031
|
+
*/
|
|
2733
3032
|
export interface BulkCreateOptions extends CreateOptions {
|
|
2734
3033
|
ignoreDuplicates?: boolean;
|
|
2735
3034
|
validate?: boolean;
|
|
@@ -2744,10 +3043,17 @@ export interface BulkCreateOptions extends CreateOptions {
|
|
|
2744
3043
|
/** Fields to update on conflict in upsert */
|
|
2745
3044
|
updateOnDuplicate?: string[];
|
|
2746
3045
|
}
|
|
3046
|
+
/**
|
|
3047
|
+
* Options for `count`, including `distinct` and the `where`/`include` that
|
|
3048
|
+
* narrow what is counted.
|
|
3049
|
+
*/
|
|
2747
3050
|
export interface CountOptions extends FindOptions {
|
|
2748
3051
|
distinct?: boolean;
|
|
2749
3052
|
col?: string;
|
|
2750
3053
|
}
|
|
3054
|
+
/**
|
|
3055
|
+
* Options for `sum`, `min`, `max` and friends.
|
|
3056
|
+
*/
|
|
2751
3057
|
export interface AggregateOptions extends FindOptions {
|
|
2752
3058
|
plain?: boolean;
|
|
2753
3059
|
}
|
|
@@ -2779,6 +3085,10 @@ export interface WindowFunctionOptions {
|
|
|
2779
3085
|
/** Default value for LAG/LEAD functions when the offset goes beyond the partition */
|
|
2780
3086
|
defaultValue?: any;
|
|
2781
3087
|
}
|
|
3088
|
+
/**
|
|
3089
|
+
* Options for an insert-or-update, including which columns decide whether a
|
|
3090
|
+
* row already exists.
|
|
3091
|
+
*/
|
|
2782
3092
|
export interface UpsertOptions extends Omit<UpdateOptions, 'where'>, CreateOptions {
|
|
2783
3093
|
/** Fields to use for conflict resolution (ON CONFLICT for PostgreSQL/SQLite, ON DUPLICATE KEY for MySQL) */
|
|
2784
3094
|
conflictFields?: string[];
|
|
@@ -2801,22 +3111,38 @@ export interface UpsertOptions extends Omit<UpdateOptions, 'where'>, CreateOptio
|
|
|
2801
3111
|
/** Whether to use paranoid mode when fetching the instance after upsert */
|
|
2802
3112
|
paranoid?: boolean;
|
|
2803
3113
|
}
|
|
3114
|
+
/**
|
|
3115
|
+
* Options for emptying a table, including whether to cascade to dependents
|
|
3116
|
+
* and restart identity sequences.
|
|
3117
|
+
*/
|
|
2804
3118
|
export interface TruncateOptions extends HookOptions {
|
|
2805
3119
|
cascade?: boolean;
|
|
2806
3120
|
restartIdentity?: boolean;
|
|
2807
3121
|
}
|
|
3122
|
+
/**
|
|
3123
|
+
* Options for dropping a table.
|
|
3124
|
+
*/
|
|
2808
3125
|
export interface DropOptions extends HookOptions {
|
|
2809
3126
|
cascade?: boolean;
|
|
2810
3127
|
}
|
|
3128
|
+
/**
|
|
3129
|
+
* Which validations to run, and whether to stop at the first failure.
|
|
3130
|
+
*/
|
|
2811
3131
|
export interface ValidationOptions {
|
|
2812
3132
|
fields?: string[];
|
|
2813
3133
|
validate?: boolean;
|
|
2814
3134
|
hooks?: boolean;
|
|
2815
3135
|
}
|
|
3136
|
+
/**
|
|
3137
|
+
* Options for undoing a soft delete on a paranoid model.
|
|
3138
|
+
*/
|
|
2816
3139
|
export interface RestoreOptions extends HookOptions {
|
|
2817
3140
|
where?: WhereOptions;
|
|
2818
3141
|
limit?: number;
|
|
2819
3142
|
}
|
|
3143
|
+
/**
|
|
3144
|
+
* Shared options for atomic increment and decrement.
|
|
3145
|
+
*/
|
|
2820
3146
|
export interface IncrementDecrementOptions extends HookOptions {
|
|
2821
3147
|
/** Amount to increment/decrement by (default: 1) */
|
|
2822
3148
|
by?: number;
|
|
@@ -2825,21 +3151,39 @@ export interface IncrementDecrementOptions extends HookOptions {
|
|
|
2825
3151
|
/** Whether to reload the instance after the operation (default: true) */
|
|
2826
3152
|
reload?: boolean;
|
|
2827
3153
|
}
|
|
3154
|
+
/**
|
|
3155
|
+
* Options for atomically adding to numeric columns, done in SQL so concurrent
|
|
3156
|
+
* writers do not lose updates.
|
|
3157
|
+
*/
|
|
2828
3158
|
export interface IncrementOptions extends IncrementDecrementOptions {
|
|
2829
3159
|
}
|
|
3160
|
+
/**
|
|
3161
|
+
* Options for atomically subtracting from numeric columns.
|
|
3162
|
+
*/
|
|
2830
3163
|
export interface DecrementOptions extends IncrementDecrementOptions {
|
|
2831
3164
|
}
|
|
3165
|
+
/**
|
|
3166
|
+
* Raised when one or more validators reject an instance; `errors` holds one
|
|
3167
|
+
* entry per failure.
|
|
3168
|
+
*/
|
|
2832
3169
|
export interface ValidationError extends Error {
|
|
2833
3170
|
name: string;
|
|
2834
3171
|
message: string;
|
|
2835
3172
|
errors: ValidationErrorItem[];
|
|
2836
3173
|
}
|
|
3174
|
+
/**
|
|
3175
|
+
* A single validation failure: which attribute, which validator, and the
|
|
3176
|
+
* message it produced.
|
|
3177
|
+
*/
|
|
2837
3178
|
export interface ValidationErrorItem {
|
|
2838
3179
|
message: string;
|
|
2839
3180
|
type: string;
|
|
2840
3181
|
path: string;
|
|
2841
3182
|
value: any;
|
|
2842
3183
|
}
|
|
3184
|
+
/**
|
|
3185
|
+
* The rows and metadata returned by a query.
|
|
3186
|
+
*/
|
|
2843
3187
|
export interface QueryResult {
|
|
2844
3188
|
rows: any[];
|
|
2845
3189
|
rowCount: number;
|
|
@@ -2859,6 +3203,9 @@ export interface QueryResult {
|
|
|
2859
3203
|
*/
|
|
2860
3204
|
resultSets?: any[][];
|
|
2861
3205
|
}
|
|
3206
|
+
/**
|
|
3207
|
+
* Column metadata a driver reports for a result set.
|
|
3208
|
+
*/
|
|
2862
3209
|
export interface FieldInfo {
|
|
2863
3210
|
name: string;
|
|
2864
3211
|
type: string;
|
|
@@ -2869,6 +3216,10 @@ export interface FieldInfo {
|
|
|
2869
3216
|
isEnum: boolean;
|
|
2870
3217
|
isPrimaryKey: boolean;
|
|
2871
3218
|
}
|
|
3219
|
+
/**
|
|
3220
|
+
* The result of `query()`, whose shape depends on the statement and the
|
|
3221
|
+
* `type` given in {@link QueryOptions}.
|
|
3222
|
+
*/
|
|
2872
3223
|
export interface RawQueryResult {
|
|
2873
3224
|
rows: any[];
|
|
2874
3225
|
count: number;
|
|
@@ -2880,17 +3231,12 @@ export interface RawQueryResult {
|
|
|
2880
3231
|
* prorm.query('SELECT * FROM users', { type: QueryTypes.SELECT })
|
|
2881
3232
|
* prorm.query('INSERT INTO users VALUES(...)', { type: QueryTypes.INSERT })
|
|
2882
3233
|
*/
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
BULKUPDATE = "BULKUPDATE",
|
|
2890
|
-
BULKDELETE = "BULKDELETE",
|
|
2891
|
-
RAW = "RAW",
|
|
2892
|
-
CALL = "CALL"
|
|
2893
|
-
}
|
|
3234
|
+
import { QueryTypes } from './query-types';
|
|
3235
|
+
export { QueryTypes };
|
|
3236
|
+
/**
|
|
3237
|
+
* Options for a raw query: how to interpret the result, what to bind, and
|
|
3238
|
+
* whether to map rows onto a model.
|
|
3239
|
+
*/
|
|
2894
3240
|
export interface QueryOptions {
|
|
2895
3241
|
plain?: boolean;
|
|
2896
3242
|
raw?: boolean;
|
|
@@ -2968,12 +3314,20 @@ export interface StreamOptions {
|
|
|
2968
3314
|
*/
|
|
2969
3315
|
logging?: boolean | ((sql: string, time?: number) => void);
|
|
2970
3316
|
}
|
|
3317
|
+
/**
|
|
3318
|
+
* Raised when the database rejects a statement; carries the driver's own
|
|
3319
|
+
* error alongside the SQL that produced it.
|
|
3320
|
+
*/
|
|
2971
3321
|
export interface QueryError extends Error {
|
|
2972
3322
|
parent?: Error;
|
|
2973
3323
|
original?: Error;
|
|
2974
3324
|
sql?: string;
|
|
2975
3325
|
parameters?: any[];
|
|
2976
3326
|
}
|
|
3327
|
+
/**
|
|
3328
|
+
* Options for `sync()`. `force` drops and recreates; `alter` tries to migrate
|
|
3329
|
+
* an existing table in place.
|
|
3330
|
+
*/
|
|
2977
3331
|
export interface SyncOptions {
|
|
2978
3332
|
/**
|
|
2979
3333
|
* If true, drop all tables first before recreating them.
|
|
@@ -3096,16 +3450,28 @@ export interface ReplicationOptions {
|
|
|
3096
3450
|
/** Whether to automatically fail over to master on all replicas unhealthy */
|
|
3097
3451
|
autoFailover?: boolean;
|
|
3098
3452
|
}
|
|
3453
|
+
/**
|
|
3454
|
+
* A row materialised as an object, with its attributes and instance methods.
|
|
3455
|
+
*/
|
|
3099
3456
|
export type ModelInstance<T = any> = any;
|
|
3457
|
+
/**
|
|
3458
|
+
* One node of a Redis cluster used as a cache backend.
|
|
3459
|
+
*/
|
|
3100
3460
|
export interface RedisClusterNode {
|
|
3101
3461
|
host: string;
|
|
3102
3462
|
port: number;
|
|
3103
3463
|
tls?: boolean;
|
|
3104
3464
|
}
|
|
3465
|
+
/**
|
|
3466
|
+
* The in-process first-level cache that sits in front of a shared cache.
|
|
3467
|
+
*/
|
|
3105
3468
|
export interface L1CacheOptions {
|
|
3106
3469
|
maxItems: number;
|
|
3107
3470
|
ttl: number;
|
|
3108
3471
|
}
|
|
3472
|
+
/**
|
|
3473
|
+
* Configuration for using a Redis cluster as the shared cache.
|
|
3474
|
+
*/
|
|
3109
3475
|
export interface RedisClusterCacheOptions {
|
|
3110
3476
|
nodes: RedisClusterNode[];
|
|
3111
3477
|
maxRedirects?: number;
|
|
@@ -3116,6 +3482,10 @@ export interface RedisClusterCacheOptions {
|
|
|
3116
3482
|
lazyConnect?: boolean;
|
|
3117
3483
|
l1?: L1CacheOptions;
|
|
3118
3484
|
}
|
|
3485
|
+
/**
|
|
3486
|
+
* How query results are cached: which backend, for how long, and how entries
|
|
3487
|
+
* are invalidated when a write touches the same table.
|
|
3488
|
+
*/
|
|
3119
3489
|
export interface CacheManagerOptions {
|
|
3120
3490
|
keyPrefix?: string;
|
|
3121
3491
|
defaultTtl?: number;
|