postgrelize 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (308) hide show
  1. package/CHANGELOG.md +269 -0
  2. package/LICENSE +21 -0
  3. package/README.md +131 -2
  4. package/dist/associations/association-accessors.d.ts +21 -0
  5. package/dist/associations/association-key-types.d.ts +44 -0
  6. package/dist/associations/association-keys.d.ts +98 -0
  7. package/dist/associations/association-lookup.d.ts +26 -0
  8. package/dist/associations/association-shape.d.ts +25 -0
  9. package/dist/associations/association.d.ts +95 -0
  10. package/dist/associations/belongs-to-many.d.ts +86 -0
  11. package/dist/associations/belongs-to.d.ts +45 -0
  12. package/dist/associations/has-many.d.ts +79 -0
  13. package/dist/associations/has-one.d.ts +44 -0
  14. package/dist/associations/include-assembler.d.ts +21 -0
  15. package/dist/associations/include-columns.d.ts +24 -0
  16. package/dist/associations/include-joins.d.ts +17 -0
  17. package/dist/associations/include-loader.d.ts +48 -0
  18. package/dist/associations/include-order.d.ts +22 -0
  19. package/dist/associations/include-query-builder.d.ts +54 -0
  20. package/dist/associations/include-resolver.d.ts +29 -0
  21. package/dist/associations/include-rows.d.ts +47 -0
  22. package/dist/associations/include-sub-query.d.ts +35 -0
  23. package/dist/associations/include.d.ts +112 -0
  24. package/dist/associations/junction-keys.d.ts +23 -0
  25. package/dist/associations/nested-creator.d.ts +44 -0
  26. package/dist/associations/nested-saver.d.ts +30 -0
  27. package/dist/associations/owner-keys.d.ts +34 -0
  28. package/dist/associations/separate-include-loader.d.ts +24 -0
  29. package/dist/associations/types.d.ts +139 -0
  30. package/dist/connection/connection-config.d.ts +33 -0
  31. package/dist/connection/connection-manager.d.ts +65 -0
  32. package/dist/connection/connection-types.d.ts +21 -0
  33. package/dist/connection/copy-from-stdin.d.ts +52 -0
  34. package/dist/connection/copy-runner.d.ts +30 -0
  35. package/dist/connection/copy-to-stdout.d.ts +49 -0
  36. package/dist/connection/copy.d.ts +22 -0
  37. package/dist/connection/notifications.d.ts +28 -0
  38. package/dist/connection/options.d.ts +158 -0
  39. package/dist/connection/query-logger.d.ts +41 -0
  40. package/dist/connection/replica-router.d.ts +20 -0
  41. package/dist/connection/statement-cache.d.ts +36 -0
  42. package/dist/connection/statement-timeout.d.ts +22 -0
  43. package/dist/data-types/abstract-data-type.d.ts +58 -0
  44. package/dist/data-types/array-literal-parser.d.ts +17 -0
  45. package/dist/data-types/array-type.d.ts +18 -0
  46. package/dist/data-types/bit-type.d.ts +14 -0
  47. package/dist/data-types/blob-type.d.ts +12 -0
  48. package/dist/data-types/char-type.d.ts +12 -0
  49. package/dist/data-types/composite-fields.d.ts +26 -0
  50. package/dist/data-types/composite-type.d.ts +32 -0
  51. package/dist/data-types/data-types.d.ts +172 -0
  52. package/dist/data-types/date-type.d.ts +14 -0
  53. package/dist/data-types/decimal-type.d.ts +13 -0
  54. package/dist/data-types/default-value-generator.d.ts +15 -0
  55. package/dist/data-types/enum-type.d.ts +19 -0
  56. package/dist/data-types/ewkb-reader.d.ts +18 -0
  57. package/dist/data-types/ewkb-writer.d.ts +17 -0
  58. package/dist/data-types/float-type.d.ts +12 -0
  59. package/dist/data-types/geometric-text.d.ts +65 -0
  60. package/dist/data-types/geometric-type.d.ts +46 -0
  61. package/dist/data-types/hstore-type.d.ts +16 -0
  62. package/dist/data-types/integer-type.d.ts +24 -0
  63. package/dist/data-types/json-type.d.ts +16 -0
  64. package/dist/data-types/multirange-type.d.ts +19 -0
  65. package/dist/data-types/range-type.d.ts +28 -0
  66. package/dist/data-types/record-text.d.ts +29 -0
  67. package/dist/data-types/scalar-type.d.ts +13 -0
  68. package/dist/data-types/spatial-type.d.ts +20 -0
  69. package/dist/data-types/string-type.d.ts +12 -0
  70. package/dist/data-types/text-type.d.ts +12 -0
  71. package/dist/data-types/timestamp-type.d.ts +15 -0
  72. package/dist/data-types/virtual-type.d.ts +15 -0
  73. package/dist/data-types/wall-clock.d.ts +14 -0
  74. package/dist/ddl/column-ddl.d.ts +73 -0
  75. package/dist/ddl/constraint-ddl.d.ts +30 -0
  76. package/dist/ddl/ddl-generator.d.ts +181 -0
  77. package/dist/ddl/ddl-guards.d.ts +60 -0
  78. package/dist/ddl/ddl-types.d.ts +193 -0
  79. package/dist/ddl/enum-ddl.d.ts +42 -0
  80. package/dist/ddl/extension-ddl.d.ts +57 -0
  81. package/dist/ddl/function-ddl.d.ts +98 -0
  82. package/dist/ddl/index-ddl.d.ts +29 -0
  83. package/dist/ddl/index-element-ddl.d.ts +19 -0
  84. package/dist/ddl/partition-ddl.d.ts +88 -0
  85. package/dist/ddl/partition-types.d.ts +94 -0
  86. package/dist/ddl/policy-ddl.d.ts +137 -0
  87. package/dist/ddl/routine-guards.d.ts +63 -0
  88. package/dist/ddl/sequence-ddl.d.ts +103 -0
  89. package/dist/ddl/sql-literal.d.ts +61 -0
  90. package/dist/ddl/table-ddl.d.ts +35 -0
  91. package/dist/ddl/trigger-ddl.d.ts +81 -0
  92. package/dist/ddl/view-ddl.d.ts +122 -0
  93. package/dist/decorators/association-applier.d.ts +18 -0
  94. package/dist/decorators/association-decorators.d.ts +72 -0
  95. package/dist/decorators/column-decorators.d.ts +147 -0
  96. package/dist/decorators/decorator-factory.d.ts +45 -0
  97. package/dist/decorators/decorator-signature.d.ts +26 -0
  98. package/dist/decorators/decorator-types.d.ts +24 -0
  99. package/dist/decorators/foreign-key-decorator.d.ts +21 -0
  100. package/dist/decorators/hook-decorators.d.ts +393 -0
  101. package/dist/decorators/init-arguments.d.ts +29 -0
  102. package/dist/decorators/model-decorators.d.ts +18 -0
  103. package/dist/decorators/model-metadata.d.ts +70 -0
  104. package/dist/decorators/table-decorators.d.ts +43 -0
  105. package/dist/decorators/timestamp-decorators.d.ts +38 -0
  106. package/dist/errors/base-error.d.ts +40 -0
  107. package/dist/errors/connection-errors.d.ts +152 -0
  108. package/dist/errors/database-errors.d.ts +152 -0
  109. package/dist/errors/errors.d.ts +5 -0
  110. package/dist/errors/map-pg-error.d.ts +27 -0
  111. package/dist/errors/misc-errors.d.ts +188 -0
  112. package/dist/errors/validation-errors.d.ts +117 -0
  113. package/dist/exports-core.d.ts +15 -0
  114. package/dist/exports-decorators.d.ts +8 -0
  115. package/dist/exports-errors.d.ts +2 -0
  116. package/dist/exports-model.d.ts +21 -0
  117. package/dist/exports-schema.d.ts +19 -0
  118. package/dist/expressions/call-expressions.d.ts +54 -0
  119. package/dist/expressions/condition-expressions.d.ts +51 -0
  120. package/dist/expressions/expression.d.ts +52 -0
  121. package/dist/expressions/jsonpath-helpers.d.ts +37 -0
  122. package/dist/expressions/methods.d.ts +188 -0
  123. package/dist/expressions/op.d.ts +182 -0
  124. package/dist/expressions/query-expressions.d.ts +110 -0
  125. package/dist/expressions/row-expressions.d.ts +35 -0
  126. package/dist/expressions/search-helpers.d.ts +138 -0
  127. package/dist/expressions/trigram-helpers.d.ts +40 -0
  128. package/dist/hooks/hooks.d.ts +125 -0
  129. package/dist/index.cjs +20461 -0
  130. package/dist/index.cjs.map +1 -0
  131. package/dist/index.d.ts +5 -0
  132. package/dist/index.js +20332 -0
  133. package/dist/index.js.map +1 -0
  134. package/dist/model/attribute-columns.d.ts +85 -0
  135. package/dist/model/attribute-normalizer.d.ts +42 -0
  136. package/dist/model/attribute-options.d.ts +121 -0
  137. package/dist/model/bulk-insert-builder.d.ts +24 -0
  138. package/dist/model/bulk-options.d.ts +173 -0
  139. package/dist/model/copy-options.d.ts +51 -0
  140. package/dist/model/cte-builder.d.ts +134 -0
  141. package/dist/model/definition-normalizer.d.ts +26 -0
  142. package/dist/model/delete-query-builder.d.ts +42 -0
  143. package/dist/model/find-options.d.ts +144 -0
  144. package/dist/model/find-query-builder.d.ts +38 -0
  145. package/dist/model/insert-query-builder.d.ts +41 -0
  146. package/dist/model/instance-destroyer.d.ts +44 -0
  147. package/dist/model/instance-lifecycle-services.d.ts +61 -0
  148. package/dist/model/instance-lifecycle.d.ts +128 -0
  149. package/dist/model/instance-saver.d.ts +25 -0
  150. package/dist/model/instance-state.d.ts +48 -0
  151. package/dist/model/instance-validation.d.ts +35 -0
  152. package/dist/model/instance-values.d.ts +80 -0
  153. package/dist/model/instance-writer.d.ts +59 -0
  154. package/dist/model/join-source-builder.d.ts +25 -0
  155. package/dist/model/lateral-keys-builder.d.ts +25 -0
  156. package/dist/model/merge-action-builder.d.ts +31 -0
  157. package/dist/model/merge-options.d.ts +72 -0
  158. package/dist/model/merge-query-builder.d.ts +29 -0
  159. package/dist/model/merge-source-builder.d.ts +22 -0
  160. package/dist/model/mixins/model-aggregates.d.ts +69 -0
  161. package/dist/model/mixins/model-associations.d.ts +73 -0
  162. package/dist/model/mixins/model-constructor.d.ts +7 -0
  163. package/dist/model/mixins/model-finders.d.ts +124 -0
  164. package/dist/model/mixins/model-hooks.d.ts +138 -0
  165. package/dist/model/mixins/model-postgres.d.ts +198 -0
  166. package/dist/model/mixins/model-schema-binding.d.ts +36 -0
  167. package/dist/model/mixins/model-schema.d.ts +55 -0
  168. package/dist/model/mixins/model-scopes.d.ts +57 -0
  169. package/dist/model/mixins/model-writers.d.ts +175 -0
  170. package/dist/model/mixins/named-hooks.d.ts +28 -0
  171. package/dist/model/model-accessors.d.ts +22 -0
  172. package/dist/model/model-base.d.ts +83 -0
  173. package/dist/model/model-definition.d.ts +130 -0
  174. package/dist/model/model-instance-persistence.d.ts +132 -0
  175. package/dist/model/model-instance-values.d.ts +154 -0
  176. package/dist/model/model-operations.d.ts +22 -0
  177. package/dist/model/model-registry.d.ts +139 -0
  178. package/dist/model/model-services.d.ts +46 -0
  179. package/dist/model/model-state.d.ts +60 -0
  180. package/dist/model/model-values.d.ts +86 -0
  181. package/dist/model/model.d.ts +560 -0
  182. package/dist/model/on-conflict-builder.d.ts +111 -0
  183. package/dist/model/operations/bulk-create-operation.d.ts +40 -0
  184. package/dist/model/operations/copy-from-source.d.ts +51 -0
  185. package/dist/model/operations/copy-operation.d.ts +54 -0
  186. package/dist/model/operations/count-operation.d.ts +52 -0
  187. package/dist/model/operations/create-operation.d.ts +31 -0
  188. package/dist/model/operations/destroy-operation.d.ts +65 -0
  189. package/dist/model/operations/find-cursor.d.ts +23 -0
  190. package/dist/model/operations/find-lookups.d.ts +89 -0
  191. package/dist/model/operations/find-operation.d.ts +47 -0
  192. package/dist/model/operations/increment-operation.d.ts +40 -0
  193. package/dist/model/operations/insert-operation.d.ts +71 -0
  194. package/dist/model/operations/merge-operation.d.ts +56 -0
  195. package/dist/model/operations/model-operation.d.ts +33 -0
  196. package/dist/model/operations/update-operation.d.ts +45 -0
  197. package/dist/model/operations/upsert-operation.d.ts +39 -0
  198. package/dist/model/options.d.ts +103 -0
  199. package/dist/model/returning-old.d.ts +52 -0
  200. package/dist/model/row-mapper.d.ts +78 -0
  201. package/dist/model/row-plan.d.ts +31 -0
  202. package/dist/model/runtime.d.ts +54 -0
  203. package/dist/model/scope-registry.d.ts +81 -0
  204. package/dist/model/select-aggregates.d.ts +37 -0
  205. package/dist/model/select-lock.d.ts +13 -0
  206. package/dist/model/select-options.d.ts +92 -0
  207. package/dist/model/select-query-builder.d.ts +73 -0
  208. package/dist/model/select-targets.d.ts +77 -0
  209. package/dist/model/source-option-builder.d.ts +23 -0
  210. package/dist/model/source-options.d.ts +108 -0
  211. package/dist/model/statement-builder.d.ts +77 -0
  212. package/dist/model/statement-services.d.ts +2 -0
  213. package/dist/model/sync-hooks.d.ts +18 -0
  214. package/dist/model/table-sample-builder.d.ts +13 -0
  215. package/dist/model/types.d.ts +85 -0
  216. package/dist/model/unnest-insert-builder.d.ts +24 -0
  217. package/dist/model/update-query-builder.d.ts +39 -0
  218. package/dist/model/v6-conflict-builder.d.ts +37 -0
  219. package/dist/model/value-cloner.d.ts +17 -0
  220. package/dist/model/values-writer.d.ts +12 -0
  221. package/dist/model/where-options.d.ts +164 -0
  222. package/dist/model/write-options.d.ts +160 -0
  223. package/dist/model/written-rows.d.ts +56 -0
  224. package/dist/query/query-result-shaper.d.ts +91 -0
  225. package/dist/query/raw-query.d.ts +27 -0
  226. package/dist/query-interface/alter-planner.d.ts +40 -0
  227. package/dist/query-interface/bulk-data.d.ts +44 -0
  228. package/dist/query-interface/column-commands.d.ts +52 -0
  229. package/dist/query-interface/column-describer.d.ts +17 -0
  230. package/dist/query-interface/enum-commands.d.ts +36 -0
  231. package/dist/query-interface/index-commands.d.ts +57 -0
  232. package/dist/query-interface/model-tables.d.ts +58 -0
  233. package/dist/query-interface/object-commands.d.ts +71 -0
  234. package/dist/query-interface/partition-commands.d.ts +43 -0
  235. package/dist/query-interface/policy-commands.d.ts +54 -0
  236. package/dist/query-interface/query-interface-objects.d.ts +108 -0
  237. package/dist/query-interface/query-interface-partitions.d.ts +66 -0
  238. package/dist/query-interface/query-interface-policies.d.ts +86 -0
  239. package/dist/query-interface/query-interface-routines.d.ts +120 -0
  240. package/dist/query-interface/query-interface-tables.d.ts +179 -0
  241. package/dist/query-interface/query-interface-types.d.ts +62 -0
  242. package/dist/query-interface/query-interface-views.d.ts +84 -0
  243. package/dist/query-interface/query-interface.d.ts +256 -0
  244. package/dist/query-interface/routine-commands.d.ts +71 -0
  245. package/dist/query-interface/schema-synchronizer.d.ts +99 -0
  246. package/dist/query-interface/statement-runner.d.ts +40 -0
  247. package/dist/query-interface/sync-planner.d.ts +26 -0
  248. package/dist/query-interface/table-commands.d.ts +63 -0
  249. package/dist/query-interface/table-introspector.d.ts +58 -0
  250. package/dist/query-interface/view-commands.d.ts +47 -0
  251. package/dist/sequelize/sequelize-base.d.ts +196 -0
  252. package/dist/sequelize/sequelize-constructor.d.ts +7 -0
  253. package/dist/sequelize/sequelize-hooks.d.ts +86 -0
  254. package/dist/sequelize/sequelize-internals.d.ts +87 -0
  255. package/dist/sequelize/sequelize-notifications.d.ts +66 -0
  256. package/dist/sequelize/sequelize-schema.d.ts +106 -0
  257. package/dist/sequelize/sequelize-transactions.d.ts +96 -0
  258. package/dist/sequelize.d.ts +790 -0
  259. package/dist/sql/ast-clauses.d.ts +137 -0
  260. package/dist/sql/ast-expressions.d.ts +88 -0
  261. package/dist/sql/ast-statements.d.ts +80 -0
  262. package/dist/sql/ast.d.ts +21 -0
  263. package/dist/sql/compile.d.ts +21 -0
  264. package/dist/sql/dml-compiler.d.ts +54 -0
  265. package/dist/sql/expression-compiler.d.ts +56 -0
  266. package/dist/sql/from-compiler.d.ts +39 -0
  267. package/dist/sql/identifier-quoter.d.ts +15 -0
  268. package/dist/sql/merge-compiler.d.ts +20 -0
  269. package/dist/sql/order.d.ts +15 -0
  270. package/dist/sql/query-compiler.d.ts +45 -0
  271. package/dist/sql/sql-chunks.d.ts +50 -0
  272. package/dist/sql/with-compiler.d.ts +19 -0
  273. package/dist/transaction/advisory-locks.d.ts +28 -0
  274. package/dist/transaction/transaction-constants.d.ts +35 -0
  275. package/dist/transaction/transaction-runner.d.ts +60 -0
  276. package/dist/transaction/transaction-starter.d.ts +25 -0
  277. package/dist/transaction/transaction-statements.d.ts +28 -0
  278. package/dist/transaction/transaction.d.ts +198 -0
  279. package/dist/validation/attribute-validators.d.ts +23 -0
  280. package/dist/validation/builtin-attribute-validator.d.ts +19 -0
  281. package/dist/validation/builtin-validators.d.ts +16 -0
  282. package/dist/validation/core-validator.d.ts +16 -0
  283. package/dist/validation/custom-validators.d.ts +13 -0
  284. package/dist/validation/instance-validator.d.ts +25 -0
  285. package/dist/validation/schema-items.d.ts +22 -0
  286. package/dist/validation/standard-schema-validator.d.ts +30 -0
  287. package/dist/validation/standard-schema.d.ts +39 -0
  288. package/dist/validation/types.d.ts +36 -0
  289. package/dist/validation/validation-target.d.ts +13 -0
  290. package/dist/where/comparison-compiler.d.ts +27 -0
  291. package/dist/where/condition-compiler.d.ts +18 -0
  292. package/dist/where/operand-resolver.d.ts +10 -0
  293. package/dist/where/operator-allowlist.d.ts +14 -0
  294. package/dist/where/where-support.d.ts +52 -0
  295. package/dist/where/where.d.ts +46 -0
  296. package/dist/where/window-compiler.d.ts +14 -0
  297. package/llm/USAGE.md +423 -0
  298. package/package.json +102 -4
  299. package/skills/postgrelize/SKILL.md +57 -0
  300. package/skills/postgrelize/reference/associations.md +108 -0
  301. package/skills/postgrelize/reference/errors.md +37 -0
  302. package/skills/postgrelize/reference/migrating-from-sequelize.md +15 -0
  303. package/skills/postgrelize/reference/postgresql-features.md +157 -0
  304. package/skills/postgrelize/reference/querying.md +111 -0
  305. package/skills/postgrelize/reference/schema.md +135 -0
  306. package/skills/postgrelize/reference/security.md +34 -0
  307. package/skills/postgrelize/reference/transactions-and-sessions.md +122 -0
  308. package/skills/postgrelize/reference/writing.md +198 -0
@@ -0,0 +1,111 @@
1
+ import { SqlExpression, Fn, Literal } from '../expressions/methods.ts';
2
+ import { ExprNode, OnConflictNode } from '../sql/ast.ts';
3
+ import { AttributeColumns } from './attribute-columns.ts';
4
+ import { ModelDefinition } from './model-definition.ts';
5
+ import { BulkCreateOptions, Values } from './options.ts';
6
+ import { WhereOptions } from './types.ts';
7
+ /** Columns or index expressions identifying the unique index, optionally a partial index. */
8
+ export type OnConflictColumnsTarget<T> = Readonly<{
9
+ /** Attribute names or index expressions (e.g. `fn('lower', col('email'))`, `literal('email COLLATE "C"')`). */
10
+ columns: readonly ((keyof T & string) | Literal | Fn)[];
11
+ /** Predicate of a partial unique index (`ON CONFLICT (...) WHERE ...`). */
12
+ where?: WhereOptions<T>;
13
+ }>;
14
+ /** Named constraint used as arbiter (`ON CONFLICT ON CONSTRAINT name`). */
15
+ export type OnConflictConstraintTarget = Readonly<{
16
+ /** Constraint name. */
17
+ constraint: string;
18
+ }>;
19
+ /** Conflict target of {@link OnConflictOptions}. */
20
+ export type OnConflictTarget<T> = readonly ((keyof T & string) | Literal | Fn)[] | OnConflictColumnsTarget<T> | OnConflictConstraintTarget;
21
+ /**
22
+ * Values assigned on conflict: a list of attributes (each set to `excluded(attribute)`) or a map
23
+ * of attribute to value or expression (`excluded()`, `col()`, `fn()`, `literal()`).
24
+ */
25
+ export type OnConflictUpdate<T> = readonly (keyof T & string)[] | Readonly<{
26
+ [K in keyof T]?: T[K] | SqlExpression;
27
+ }>;
28
+ /** `DO UPDATE` action of {@link OnConflictOptions}. */
29
+ export type OnConflictUpdateAction<T> = Readonly<{
30
+ /** Assignments. */
31
+ update: OnConflictUpdate<T>;
32
+ /** Only update rows matching this condition (`DO UPDATE ... WHERE`); others are left unchanged. */
33
+ where?: WhereOptions<T>;
34
+ }>;
35
+ /**
36
+ * Advanced `INSERT ... ON CONFLICT` specification. PostgreSQL extension.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * const rows = [{ tenantId: 1, key: 'views', hits: 1, version: 2 }];
41
+ * await Product.bulkCreate(rows, {
42
+ * onConflict: {
43
+ * target: ['tenantId', 'key'],
44
+ * action: {
45
+ * update: { hits: literal('"Product"."hits" + EXCLUDED."hits"'), updatedAt: fn('now') },
46
+ * where: { version: { [Op.lt]: excluded('version') } },
47
+ * },
48
+ * },
49
+ * });
50
+ * ```
51
+ */
52
+ export type OnConflictOptions<T> = Readonly<{
53
+ /** Unique index or constraint to arbitrate on. Required for `update`. */
54
+ target?: OnConflictTarget<T>;
55
+ /** `'nothing'` to skip conflicting rows, or an update. */
56
+ action: 'nothing' | OnConflictUpdateAction<T>;
57
+ }>;
58
+ /**
59
+ * Builds `INSERT ... ON CONFLICT` clauses: the `onConflict` option (PostgreSQL extension) and the
60
+ * Sequelize v6 rules of `bulkCreate` (`ignoreDuplicates`, `updateOnDuplicate`, `conflictAttributes`,
61
+ * `conflictWhere`) and `upsert` (conflict target from unique keys / indexes).
62
+ */
63
+ export declare class OnConflictBuilder {
64
+ #private;
65
+ /** Column added to `RETURNING` to tell inserted rows from updated ones. */
66
+ static readonly INSERTED_FLAG = "__pgz_inserted";
67
+ /** Sequelize v6 `bulkCreate` conflict options, not combinable with `onConflict`. */
68
+ static readonly V6_OPTIONS: readonly ["ignoreDuplicates", "updateOnDuplicate", "conflictAttributes", "conflictWhere"];
69
+ /**
70
+ * @param columns - Attribute to column mapping.
71
+ */
72
+ constructor(columns: AttributeColumns);
73
+ /**
74
+ * Validates `onConflict` and converts it into an AST node. The target table must be aliased with
75
+ * the model name so `col()` and `where` refer to the existing row.
76
+ *
77
+ * @param definition - Model definition.
78
+ * @param options - `onConflict` option.
79
+ * @returns ON CONFLICT node.
80
+ * @throws Error for unknown attributes, empty targets or an update without target.
81
+ */
82
+ build(definition: ModelDefinition, options: OnConflictOptions<unknown>): OnConflictNode;
83
+ /**
84
+ * `(xmax = 0) AS "__pgz_inserted"` — true for rows inserted by this statement.
85
+ *
86
+ * @returns RETURNING column.
87
+ */
88
+ insertedFlagColumn(): ExprNode;
89
+ /**
90
+ * ON CONFLICT clause of Sequelize v6 `bulkCreate` options.
91
+ *
92
+ * @param definition - Model definition.
93
+ * @param options - `updateOnDuplicate`, `conflictAttributes`, `conflictWhere`, `ignoreDuplicates`.
94
+ * @returns `{ onConflict }`, or `{}` without conflict handling.
95
+ * @throws Error for an empty `updateOnDuplicate`.
96
+ */
97
+ v6Bulk(definition: ModelDefinition, options: BulkCreateOptions): Readonly<{
98
+ onConflict?: OnConflictNode;
99
+ }>;
100
+ /**
101
+ * ON CONFLICT clause of Sequelize v6 `upsert`: the target is the first unique key (or unique
102
+ * index) containing an updated attribute, otherwise the primary key.
103
+ *
104
+ * @param definition - Model definition.
105
+ * @param insertValues - Inserted values.
106
+ * @param updatable - Attributes updated on conflict.
107
+ * @param conflictFields - `conflictFields` option (column names).
108
+ * @returns ON CONFLICT node.
109
+ */
110
+ v6Upsert(definition: ModelDefinition, insertValues: Values, updatable: readonly string[], conflictFields: readonly string[] | undefined): OnConflictNode;
111
+ }
@@ -0,0 +1,40 @@
1
+ import { BulkInsertBuilder } from '../bulk-insert-builder.ts';
2
+ import { ModelRegistry } from '../model-registry.ts';
3
+ import { ModelValues } from '../model-values.ts';
4
+ import { OnConflictBuilder } from '../on-conflict-builder.ts';
5
+ import { AnyModel, BulkCreateOptions, ModelStatic, Values } from '../options.ts';
6
+ import { WrittenRows } from '../written-rows.ts';
7
+ import { InsertOperation } from './insert-operation.ts';
8
+ import { ModelOperation, OperationServices } from './model-operation.ts';
9
+ /** Collaborators of {@link BulkCreateOperation}. */
10
+ export type BulkCreateOperationServices = OperationServices & Readonly<{
11
+ /** Model state. */
12
+ registry: ModelRegistry;
13
+ /** Value rules. */
14
+ values: ModelValues;
15
+ /** INSERT builder. */
16
+ bulkInserts: BulkInsertBuilder;
17
+ /** ON CONFLICT builder. */
18
+ conflicts: OnConflictBuilder;
19
+ /** Conflict-aware inserts. */
20
+ inserter: InsertOperation;
21
+ /** Alignment of `ignoreDuplicates` results. */
22
+ written: WrittenRows;
23
+ }>;
24
+ /**
25
+ * `Model.bulkCreate`: one multi-row INSERT (Sequelize v6 conflict options or `onConflict`), or
26
+ * one `save` per instance with `individualHooks` / nested includes.
27
+ */
28
+ export declare class BulkCreateOperation extends ModelOperation<BulkCreateOperationServices> {
29
+ #private;
30
+ /**
31
+ * `Model.bulkCreate`.
32
+ *
33
+ * @param model - Model class.
34
+ * @param records - Values per row.
35
+ * @param options - Bulk create options.
36
+ * @returns Instances with values returned by the database.
37
+ * @throws Error when `onConflict` is combined with Sequelize v6 conflict options.
38
+ */
39
+ bulkCreate<M extends AnyModel>(model: ModelStatic<M>, records: readonly Values[], options: BulkCreateOptions): Promise<M[]>;
40
+ }
@@ -0,0 +1,51 @@
1
+ import { CopyEncoder } from '../../connection/copy.ts';
2
+ import { AttributeDefinition, ModelDefinition } from '../model-definition.ts';
3
+ import { CopyFromOptions, Values } from '../options.ts';
4
+ type CopySource = Iterable<Values> | AsyncIterable<Values>;
5
+ /** Copied columns: attribute definitions in row order and the timestamps filled by `copyFrom`. */
6
+ export type CopyColumns = Readonly<{
7
+ /** Attributes in row order. */
8
+ attributes: readonly AttributeDefinition[];
9
+ /** Timestamp attributes filled with the current time. */
10
+ stamps: readonly string[];
11
+ }>;
12
+ /**
13
+ * Columns, statement text and encoded lines of `Model.copyFrom` (`COPY ... FROM STDIN`).
14
+ *
15
+ * @internal
16
+ */
17
+ export declare class CopyFromSource {
18
+ #private;
19
+ /**
20
+ * @param encoder - COPY text encoding of rows.
21
+ */
22
+ constructor(encoder: CopyEncoder);
23
+ /**
24
+ * Resolves the copied columns: listed (or first-row) attributes plus missing timestamps.
25
+ *
26
+ * @param definition - Model definition.
27
+ * @param rows - Row source.
28
+ * @param options - `columns`.
29
+ * @returns Attributes in row order and filled timestamps.
30
+ * @throws Error without columns or for unknown attributes.
31
+ */
32
+ columns(definition: ModelDefinition, rows: CopySource, options: CopyFromOptions): CopyColumns;
33
+ /**
34
+ * `COPY table (columns) FROM STDIN` text.
35
+ *
36
+ * @param definition - Model definition.
37
+ * @param attributes - Copied attributes.
38
+ * @returns Statement text.
39
+ */
40
+ sql(definition: ModelDefinition, attributes: readonly AttributeDefinition[]): string;
41
+ /**
42
+ * Encodes rows as COPY text lines, filling timestamps with `now`.
43
+ *
44
+ * @param rows - Row source.
45
+ * @param columns - Copied columns.
46
+ * @param now - Timestamp value.
47
+ * @returns Async iterator of encoded lines.
48
+ */
49
+ lines(rows: CopySource, { attributes, stamps }: CopyColumns, now: Date): AsyncGenerator<string>;
50
+ }
51
+ export {};
@@ -0,0 +1,54 @@
1
+ import { IncludeResolver } from '../../associations/include-resolver.ts';
2
+ import { CopyEncoder } from '../../connection/copy.ts';
3
+ import { SqlLiteral } from '../../ddl/sql-literal.ts';
4
+ import { SqlCompiler } from '../../sql/compile.ts';
5
+ import { AttributeColumns } from '../attribute-columns.ts';
6
+ import { FindQueryBuilder } from '../find-query-builder.ts';
7
+ import { ModelRegistry } from '../model-registry.ts';
8
+ import { AnyModel, CopyFromOptions, CopyToOptions, ModelStatic, Values } from '../options.ts';
9
+ /** Collaborators of {@link CopyOperation}. */
10
+ export type CopyOperationServices = Readonly<{
11
+ /** Model state and scopes. */
12
+ registry: ModelRegistry;
13
+ /** Paranoid filter. */
14
+ columns: AttributeColumns;
15
+ /** Finder SELECT builder. */
16
+ finds: FindQueryBuilder;
17
+ /** Include trees. */
18
+ includes: IncludeResolver;
19
+ /** COPY text encoding of rows. */
20
+ encoder: CopyEncoder;
21
+ /** Escaped literals (COPY takes no parameters). */
22
+ literals: SqlLiteral;
23
+ /** SQL compiler. */
24
+ compiler: SqlCompiler;
25
+ }>;
26
+ /** `Model.copyFrom` (`COPY ... FROM STDIN`) and `Model.copyTo` (`COPY (SELECT ...) TO STDOUT`). */
27
+ export declare class CopyOperation {
28
+ #private;
29
+ /**
30
+ * @param services - Collaborators.
31
+ */
32
+ constructor(services: CopyOperationServices);
33
+ /**
34
+ * `Model.copyFrom`: bulk-loads rows with `COPY ... FROM STDIN` (text format); timestamps are
35
+ * filled when the model has them.
36
+ *
37
+ * @param model - Model class.
38
+ * @param rows - Array, iterable or async iterable of attribute values.
39
+ * @param options - `columns` and query options.
40
+ * @returns Number of copied rows.
41
+ * @throws Error without columns or for unknown attributes.
42
+ */
43
+ copyFrom(model: ModelStatic<AnyModel>, rows: Iterable<Values> | AsyncIterable<Values>, options: CopyFromOptions): Promise<number>;
44
+ /**
45
+ * `Model.copyTo`: streams `COPY (SELECT ...) TO STDOUT` output; values of the query are inlined
46
+ * as escaped literals.
47
+ *
48
+ * @param model - Model class.
49
+ * @param options - Find options and output format.
50
+ * @returns Async iterator of raw output chunks.
51
+ * @throws Error for unsupported formats or multi-character delimiters / quotes.
52
+ */
53
+ copyTo(model: ModelStatic<AnyModel>, options: CopyToOptions): AsyncGenerator<Buffer, void, undefined>;
54
+ }
@@ -0,0 +1,52 @@
1
+ import { IncludeQueryBuilder } from '../../associations/include-query-builder.ts';
2
+ import { IncludeResolver } from '../../associations/include-resolver.ts';
3
+ import { SqlCompiler } from '../../sql/compile.ts';
4
+ import { AttributeColumns } from '../attribute-columns.ts';
5
+ import { CteBuilder } from '../cte-builder.ts';
6
+ import { ModelRegistry } from '../model-registry.ts';
7
+ import { AggregateOptions, AnyModel, CountOptions, ModelStatic } from '../options.ts';
8
+ import { RowMapper } from '../row-mapper.ts';
9
+ import { SelectQueryBuilder } from '../select-query-builder.ts';
10
+ import { ModelOperation, OperationServices } from './model-operation.ts';
11
+ /** Collaborators of {@link CountOperation}. */
12
+ export type CountOperationServices = OperationServices & Readonly<{
13
+ /** Model state and scopes. */
14
+ registry: ModelRegistry;
15
+ /** Paranoid filter. */
16
+ columns: AttributeColumns;
17
+ /** SELECT builder. */
18
+ selects: SelectQueryBuilder;
19
+ /** CTE options. */
20
+ cte: CteBuilder;
21
+ /** Row parsing. */
22
+ rows: RowMapper;
23
+ /** Include trees. */
24
+ includes: IncludeResolver;
25
+ /** Include count joins. */
26
+ includeQueries: IncludeQueryBuilder;
27
+ /** SQL compiler. */
28
+ compiler: SqlCompiler;
29
+ }>;
30
+ /** `Model.count` (with includes and `group`) and `Model.aggregate` (`max`, `min`, `sum`, ...). */
31
+ export declare class CountOperation extends ModelOperation<CountOperationServices> {
32
+ #private;
33
+ /**
34
+ * `Model.count` (default scope and paranoid filter applied).
35
+ *
36
+ * @param model - Model class.
37
+ * @param options - Count options.
38
+ * @returns Count, or `{ count, ...groups }[]` with `group`.
39
+ */
40
+ count(model: ModelStatic<AnyModel>, options: CountOptions): Promise<number>;
41
+ /**
42
+ * `Model.aggregate`: runs an aggregate function over a column.
43
+ *
44
+ * @param model - Model class.
45
+ * @param field - Attribute name or `'*'`.
46
+ * @param aggregateFunction - SQL aggregate function name, e.g. `'max'`.
47
+ * @param options - Options.
48
+ * @returns Aggregated value (the raw driver rows with `plain: false`, like v6: numeric results
49
+ * such as `sum` arrive as strings).
50
+ */
51
+ aggregate(model: ModelStatic<AnyModel>, field: string, aggregateFunction: string, options: AggregateOptions): Promise<unknown>;
52
+ }
@@ -0,0 +1,31 @@
1
+ import { ModelRegistry } from '../model-registry.ts';
2
+ import { ModelValues } from '../model-values.ts';
3
+ import { OnConflictBuilder } from '../on-conflict-builder.ts';
4
+ import { AnyModel, CreateOptions, ModelStatic, Values } from '../options.ts';
5
+ import { InsertOperation } from './insert-operation.ts';
6
+ import { ModelOperation, OperationServices } from './model-operation.ts';
7
+ /** Collaborators of {@link CreateOperation}. */
8
+ export type CreateOperationServices = OperationServices & Readonly<{
9
+ /** Model state. */
10
+ registry: ModelRegistry;
11
+ /** Value rules. */
12
+ values: ModelValues;
13
+ /** ON CONFLICT builder. */
14
+ conflicts: OnConflictBuilder;
15
+ /** Conflict-aware inserts. */
16
+ inserter: InsertOperation;
17
+ }>;
18
+ /** `Model.create`: builds and saves an instance, or inserts it with `onConflict`. */
19
+ export declare class CreateOperation extends ModelOperation<CreateOperationServices> {
20
+ #private;
21
+ /**
22
+ * `Model.create`.
23
+ *
24
+ * @param model - Model class.
25
+ * @param values - Attribute values.
26
+ * @param options - Create options.
27
+ * @returns Saved instance (with `onConflict`: the written row, or the unsaved instance with
28
+ * `wasInserted: false` when nothing was written).
29
+ */
30
+ create<M extends AnyModel>(model: ModelStatic<M>, values: Values | undefined, options: CreateOptions): Promise<M>;
31
+ }
@@ -0,0 +1,65 @@
1
+ import { SqlCompiler } from '../../sql/compile.ts';
2
+ import { AttributeColumns } from '../attribute-columns.ts';
3
+ import { DeleteQueryBuilder } from '../delete-query-builder.ts';
4
+ import { JoinSourceBuilder } from '../join-source-builder.ts';
5
+ import { ModelRegistry } from '../model-registry.ts';
6
+ import { ModelValues } from '../model-values.ts';
7
+ import { AnyModel, DestroyOptions, ModelStatic, RestoreOptions } from '../options.ts';
8
+ import { RowMapper } from '../row-mapper.ts';
9
+ import { QueryOptionsBase } from '../runtime.ts';
10
+ import { UpdateQueryBuilder } from '../update-query-builder.ts';
11
+ import { ModelOperation, OperationServices } from './model-operation.ts';
12
+ /** Collaborators of {@link DestroyOperation}. */
13
+ export type DestroyOperationServices = OperationServices & Readonly<{
14
+ /** Model state and scopes. */
15
+ registry: ModelRegistry;
16
+ /** Value rules. */
17
+ values: ModelValues;
18
+ /** SET items, paranoid filter. */
19
+ columns: AttributeColumns;
20
+ /** UPDATE builder (soft delete, restore). */
21
+ updates: UpdateQueryBuilder;
22
+ /** DELETE / TRUNCATE builder. */
23
+ deletes: DeleteQueryBuilder;
24
+ /** `using` relations. */
25
+ joins: JoinSourceBuilder;
26
+ /** Instances of returned rows. */
27
+ rows: RowMapper;
28
+ /** SQL compiler. */
29
+ compiler: SqlCompiler;
30
+ }>;
31
+ /**
32
+ * `Model.destroy` (DELETE, or soft delete of paranoid models), `Model.restore` and
33
+ * `Model.truncate`, with bulk and individual hooks.
34
+ */
35
+ export declare class DestroyOperation extends ModelOperation<DestroyOperationServices> {
36
+ #private;
37
+ /**
38
+ * `Model.destroy`.
39
+ *
40
+ * @param model - Model class.
41
+ * @param options - Destroy options.
42
+ * @returns Number of deleted rows, or deleted instances with `returning: true`.
43
+ */
44
+ destroy<M extends AnyModel>(model: ModelStatic<M>, options: DestroyOptions): Promise<number | M[]>;
45
+ /**
46
+ * `Model.restore`: sets `deletedAt = NULL` on matching rows of a paranoid model.
47
+ *
48
+ * @param model - Model class.
49
+ * @param options - Rows to restore and hook options.
50
+ * @returns Resolves when done.
51
+ * @throws Error when the model is not paranoid.
52
+ */
53
+ restore(model: ModelStatic<AnyModel>, options: RestoreOptions): Promise<void>;
54
+ /**
55
+ * `Model.truncate`.
56
+ *
57
+ * @param model - Model class.
58
+ * @param options - `cascade`, `restartIdentity` and query options.
59
+ * @returns Resolves when done.
60
+ */
61
+ truncate(model: object, options: QueryOptionsBase & Readonly<{
62
+ cascade?: boolean;
63
+ restartIdentity?: boolean;
64
+ }>): Promise<void>;
65
+ }
@@ -0,0 +1,23 @@
1
+ import { AnyModel, FindOptions, ModelStatic } from '../options.ts';
2
+ import { FindOperationServices } from './find-lookups.ts';
3
+ import { ModelOperation } from './model-operation.ts';
4
+ /**
5
+ * `Model.findEach`: streams rows with a server-side cursor.
6
+ *
7
+ * @internal
8
+ */
9
+ export declare class FindCursor extends ModelOperation<FindOperationServices> {
10
+ #private;
11
+ /**
12
+ * Streams instances of matching rows in batches.
13
+ *
14
+ * @param model - Model class.
15
+ * @param options - Find options.
16
+ * @param cursor - `batchSize` (rows per FETCH, default 100).
17
+ * @returns Async iterator of instances.
18
+ * @throws Error for joined includes or an invalid batch size.
19
+ */
20
+ each<M extends AnyModel>(model: ModelStatic<M>, options: FindOptions, cursor: Readonly<{
21
+ batchSize?: number;
22
+ }>): AsyncGenerator<M, void, undefined>;
23
+ }
@@ -0,0 +1,89 @@
1
+ import { IncludeLoader } from '../../associations/include-loader.ts';
2
+ import { IncludeResolver } from '../../associations/include-resolver.ts';
3
+ import { SqlCompiler } from '../../sql/compile.ts';
4
+ import { AttributeColumns } from '../attribute-columns.ts';
5
+ import { FindQueryBuilder } from '../find-query-builder.ts';
6
+ import { ModelRegistry } from '../model-registry.ts';
7
+ import { ModelValues } from '../model-values.ts';
8
+ import { AnyModel, FindOptions, FindOrCreateOptions, ModelStatic } from '../options.ts';
9
+ import { RowMapper } from '../row-mapper.ts';
10
+ import { SelectQueryBuilder } from '../select-query-builder.ts';
11
+ import { ModelOperation, OperationServices } from './model-operation.ts';
12
+ /** Collaborators of `FindOperation`. */
13
+ export type FindOperationServices = OperationServices & Readonly<{
14
+ /** Model state and scopes. */
15
+ registry: ModelRegistry;
16
+ /** Value rules. */
17
+ values: ModelValues;
18
+ /** Paranoid filter. */
19
+ columns: AttributeColumns;
20
+ /** Plain SELECT builder (`findEach`). */
21
+ selects: SelectQueryBuilder;
22
+ /** Finder SELECT builder. */
23
+ finds: FindQueryBuilder;
24
+ /** Row parsing. */
25
+ rows: RowMapper;
26
+ /** Include trees. */
27
+ includes: IncludeResolver;
28
+ /** Include row assembly and separate loading. */
29
+ loader: IncludeLoader;
30
+ /** SQL compiler. */
31
+ compiler: SqlCompiler;
32
+ }>;
33
+ /**
34
+ * Finders of `Model` built on `findAll` / `findOne` / `count`: `findOne`, `findByPk`,
35
+ * `findAndCountAll`, `findOrCreate` and `findOrBuild`.
36
+ *
37
+ * @internal
38
+ */
39
+ export declare abstract class FindLookups extends ModelOperation<FindOperationServices> {
40
+ #private;
41
+ /**
42
+ * `Model.findOne`: `findAll` with `limit: 1` (unless given), honouring `rejectOnEmpty`.
43
+ *
44
+ * @param model - Model class.
45
+ * @param options - Find options.
46
+ * @returns Instance or `null`.
47
+ * @throws EmptyResultError (or the given error) with `rejectOnEmpty`.
48
+ */
49
+ findOne<M extends AnyModel>(model: ModelStatic<M>, options: FindOptions & Readonly<{
50
+ rejectOnEmpty?: boolean | Error;
51
+ }>): Promise<M | null>;
52
+ /**
53
+ * `Model.findByPk`.
54
+ *
55
+ * @param model - Model class.
56
+ * @param key - Primary key value.
57
+ * @param options - Find options.
58
+ * @returns Instance or `null`.
59
+ */
60
+ findByPk<M extends AnyModel>(model: ModelStatic<M>, key: unknown, options: Omit<FindOptions, 'where'>): Promise<M | null>;
61
+ /**
62
+ * `Model.findAndCountAll`: `count` and `findAll` with the same filter, in parallel.
63
+ *
64
+ * @param model - Model class.
65
+ * @param options - Find options.
66
+ * @returns Total count and rows.
67
+ */
68
+ findAndCountAll<M extends AnyModel>(model: ModelStatic<M>, options: FindOptions): Promise<Readonly<{
69
+ count: number;
70
+ rows: M[];
71
+ }>>;
72
+ /**
73
+ * `Model.findOrCreate`: finds a row or creates it inside a transaction (re-reading it when a
74
+ * concurrent insert wins).
75
+ *
76
+ * @param model - Model class.
77
+ * @param options - `where` to search, `defaults` to add on creation.
78
+ * @returns `[instance, created]`.
79
+ */
80
+ findOrCreate<M extends AnyModel>(model: ModelStatic<M>, options: FindOrCreateOptions): Promise<[M, boolean]>;
81
+ /**
82
+ * `Model.findOrBuild`: finds a row or builds (without saving) a new instance.
83
+ *
84
+ * @param model - Model class.
85
+ * @param options - `where` to search, `defaults` to add when building.
86
+ * @returns `[instance, built]`.
87
+ */
88
+ findOrBuild<M extends AnyModel>(model: ModelStatic<M>, options: FindOrCreateOptions): Promise<[M, boolean]>;
89
+ }
@@ -0,0 +1,47 @@
1
+ import { Subquery } from '../../expressions/methods.ts';
2
+ import { AnyModel, FindOptions, ModelStatic } from '../options.ts';
3
+ import { FindLookups, FindOperationServices } from './find-lookups.ts';
4
+ export type { FindOperationServices } from './find-lookups.ts';
5
+ /**
6
+ * Finders of `Model`: `findAll` (scopes, paranoid filter, hooks, includes, raw / nested rows),
7
+ * `findOne`, `findByPk`, `findAndCountAll`, `findOrCreate`, `findOrBuild`, the cursor-based
8
+ * `findEach` and embeddable `subquery`.
9
+ */
10
+ export declare class FindOperation extends FindLookups {
11
+ #private;
12
+ /**
13
+ * @param services - Collaborators.
14
+ */
15
+ constructor(services: FindOperationServices);
16
+ /**
17
+ * `Model.findAll`.
18
+ *
19
+ * @param model - Model class.
20
+ * @param options - Find options.
21
+ * @returns Instances, or plain objects with `raw: true`.
22
+ */
23
+ findAll<M extends AnyModel>(model: ModelStatic<M>, options: FindOptions): Promise<M[]>;
24
+ /**
25
+ * `Model.findEach`: streams rows with a server-side cursor inside `options.transaction` or its
26
+ * own transaction; the cursor is closed when iteration ends or is stopped early.
27
+ *
28
+ * @param model - Model class.
29
+ * @param options - Find options.
30
+ * @param cursor - `batchSize` (rows per FETCH, default 100).
31
+ * @returns Async iterator of instances.
32
+ * @throws Error for joined includes or an invalid batch size.
33
+ */
34
+ findEach<M extends AnyModel>(model: ModelStatic<M>, options: FindOptions, cursor: Readonly<{
35
+ batchSize?: number;
36
+ }>): AsyncGenerator<M, void, undefined>;
37
+ /**
38
+ * `Model.subquery`: a SELECT embeddable in another query, built when the outer query compiles.
39
+ *
40
+ * @param model - Model class.
41
+ * @param options - Find options and `as` (table alias).
42
+ * @returns Subquery expression.
43
+ */
44
+ subquery(model: ModelStatic<AnyModel>, options: FindOptions & Readonly<{
45
+ as?: string;
46
+ }>): Subquery;
47
+ }
@@ -0,0 +1,40 @@
1
+ import { SqlCompiler } from '../../sql/compile.ts';
2
+ import { AttributeColumns } from '../attribute-columns.ts';
3
+ import { ModelRegistry } from '../model-registry.ts';
4
+ import { ModelValues } from '../model-values.ts';
5
+ import { AnyModel, AttributeAmounts, IncrementOptions, ModelStatic, Values } from '../options.ts';
6
+ import { RowMapper } from '../row-mapper.ts';
7
+ import { UpdateQueryBuilder } from '../update-query-builder.ts';
8
+ /** Collaborators of {@link IncrementOperation}. */
9
+ export type IncrementOperationServices = Readonly<{
10
+ /** Model state. */
11
+ registry: ModelRegistry;
12
+ /** Value rules. */
13
+ values: ModelValues;
14
+ /** SET items. */
15
+ columns: AttributeColumns;
16
+ /** UPDATE builder. */
17
+ updates: UpdateQueryBuilder;
18
+ /** Instances of returned rows. */
19
+ rows: RowMapper;
20
+ /** SQL compiler. */
21
+ compiler: SqlCompiler;
22
+ }>;
23
+ /** `Model.increment` / `Model.decrement`: `SET x = x ± by` (and `updatedAt`) on matching rows. */
24
+ export declare class IncrementOperation {
25
+ #private;
26
+ /**
27
+ * @param services - Collaborators.
28
+ */
29
+ constructor(services: IncrementOperationServices);
30
+ /**
31
+ * Increments (`sign` 1) or decrements (`sign` -1) attributes of matching rows.
32
+ *
33
+ * @param model - Model class.
34
+ * @param fields - Attribute name(s), or a map of attribute to amount.
35
+ * @param options - Increment options.
36
+ * @param sign - `1` or `-1`.
37
+ * @returns Updated instances and the affected row count.
38
+ */
39
+ change<M extends AnyModel>(model: ModelStatic<M>, fields: AttributeAmounts<Values>, options: IncrementOptions, sign: 1 | -1): Promise<[M[], number]>;
40
+ }