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,80 @@
1
+ import { ModelRegistry } from './model-registry.ts';
2
+ import { ModelValues } from './model-values.ts';
3
+ import { AnyModel, Values } from './options.ts';
4
+ /** Tells model instances apart from plain values (injected to avoid importing `Model`). */
5
+ export type InstanceCheck = (value: unknown) => value is AnyModel;
6
+ /** Options of `instance.get()`. */
7
+ export type GetOptions = Readonly<{
8
+ plain?: boolean;
9
+ raw?: boolean;
10
+ clone?: boolean;
11
+ }>;
12
+ /** Options of `instance.set()`. */
13
+ export type SetOptions = Readonly<{
14
+ raw?: boolean;
15
+ }>;
16
+ /**
17
+ * Attribute access of model instances (Sequelize v6 `get` / `set` / `setDataValue` / `changed` /
18
+ * `previous` / `equals`): custom getters and setters, plain conversion of nested instances and
19
+ * change tracking.
20
+ */
21
+ export declare class InstanceValues {
22
+ #private;
23
+ /**
24
+ * @param registry - Model definitions.
25
+ * @param values - Value equality.
26
+ * @param isInstance - Checks whether a value is a model instance.
27
+ */
28
+ constructor(registry: ModelRegistry, values: ModelValues, isInstance: InstanceCheck);
29
+ /**
30
+ * One attribute value (custom getter applied unless `raw`), or all values.
31
+ *
32
+ * @param instance - Model instance.
33
+ * @param keyOrOptions - Attribute name, or options for all values.
34
+ * @param options - `raw: true` skips the custom getter.
35
+ * @returns Attribute value or values object.
36
+ */
37
+ get(instance: AnyModel, keyOrOptions: string | number | symbol | GetOptions | undefined, options: SetOptions): unknown;
38
+ /**
39
+ * Sets one attribute (custom setter applied unless `raw`) or several.
40
+ *
41
+ * @param instance - Model instance.
42
+ * @param keyOrValues - Attribute name or values.
43
+ * @param valueOrOptions - Value, or options when setting several values.
44
+ * @param maybeOptions - Options when setting one value.
45
+ */
46
+ set(instance: AnyModel, keyOrValues: string | number | symbol | Values, valueOrOptions: unknown, maybeOptions: SetOptions | undefined): void;
47
+ /**
48
+ * Writes a value without custom setters, tracking the change.
49
+ *
50
+ * @param instance - Model instance.
51
+ * @param key - Attribute name.
52
+ * @param value - New value.
53
+ */
54
+ setDataValue(instance: AnyModel, key: string | number | symbol, value: unknown): void;
55
+ /**
56
+ * Lists changed attributes, checks one, or marks one as changed / unchanged.
57
+ *
58
+ * @param instance - Model instance.
59
+ * @param key - Attribute name.
60
+ * @param value - Changed flag.
61
+ * @returns Names (or `false`), a flag, or `undefined` when marking.
62
+ */
63
+ changed(instance: AnyModel, key: string | undefined, value: boolean | undefined): unknown;
64
+ /**
65
+ * Previous value of an attribute, or all previous values of changed attributes.
66
+ *
67
+ * @param instance - Model instance.
68
+ * @param key - Attribute name.
69
+ * @returns Previous value(s).
70
+ */
71
+ previous(instance: AnyModel, key: string | number | symbol | undefined): unknown;
72
+ /**
73
+ * Compares primary keys of two instances of the same model.
74
+ *
75
+ * @param instance - Model instance.
76
+ * @param other - Instance to compare with.
77
+ * @returns True when `other` is an instance of the model and all primary keys are equal.
78
+ */
79
+ equals(instance: AnyModel, other: AnyModel): boolean;
80
+ }
@@ -0,0 +1,59 @@
1
+ import { InstanceLifecycleServices } from './instance-lifecycle-services.ts';
2
+ import { InstanceLifecycle } from './instance-lifecycle.ts';
3
+ import { InstanceState } from './instance-state.ts';
4
+ import { ModelDefinition } from './model-definition.ts';
5
+ import { AnyModel, MutableOptions, SaveOptions } from './options.ts';
6
+ import { ModelRuntime } from './runtime.ts';
7
+ /** @internal State of one `save` call. */
8
+ export type SaveContext = Readonly<{
9
+ /** Model class. */
10
+ model: object;
11
+ /** Model definition. */
12
+ definition: ModelDefinition;
13
+ /** Runtime of the model. */
14
+ runtime: ModelRuntime;
15
+ /** Instance state. */
16
+ state: InstanceState;
17
+ /** Options passed to hooks (which may change them). */
18
+ opts: MutableOptions;
19
+ /** Options as given. */
20
+ options: SaveOptions;
21
+ /** Whether the instance is inserted. */
22
+ isNew: boolean;
23
+ /** `fields` option. */
24
+ explicitFields: readonly string[] | undefined;
25
+ }>;
26
+ /**
27
+ * SQL step of `instance.save()`: INSERT of a new instance (with nested associations) or UPDATE of
28
+ * changed attributes with optimistic locking, then the returned row is applied to the instance.
29
+ *
30
+ * @internal
31
+ */
32
+ export declare class InstanceWriter {
33
+ #private;
34
+ /**
35
+ * @param services - Collaborators.
36
+ * @param lifecycle - Row refresh.
37
+ */
38
+ constructor(services: InstanceLifecycleServices, lifecycle: InstanceLifecycle);
39
+ /**
40
+ * Inserts a new instance, saving `belongsTo` parents before and children after it.
41
+ *
42
+ * @param instance - Instance.
43
+ * @param context - Save state.
44
+ * @param now - Timestamp of the write.
45
+ * @returns Resolves when written.
46
+ */
47
+ insert(instance: AnyModel, context: SaveContext, now: Date): Promise<void>;
48
+ /**
49
+ * Updates the given attributes of a loaded instance (and its version).
50
+ *
51
+ * @param instance - Instance.
52
+ * @param context - Save state.
53
+ * @param fields - Attributes to write.
54
+ * @param now - Timestamp of the write.
55
+ * @returns Resolves when written.
56
+ * @throws OptimisticLockError when the version no longer matches.
57
+ */
58
+ update(instance: AnyModel, context: SaveContext, fields: readonly string[], now: Date): Promise<void>;
59
+ }
@@ -0,0 +1,25 @@
1
+ import { FromItem } from '../sql/ast.ts';
2
+ import { AttributeColumns } from './attribute-columns.ts';
3
+ import { ModelRegistry } from './model-registry.ts';
4
+ import { FromSourceOption } from './source-options.ts';
5
+ /**
6
+ * Extra relations for finders' `from`, `UPDATE ... FROM` and `DELETE ... USING`, keyed by alias.
7
+ * PostgreSQL extension.
8
+ */
9
+ export type JoinSources = Readonly<Record<string, FromSourceOption>>;
10
+ /** Converts `from` / `using` options (models, subqueries, relation names) into FROM items. */
11
+ export declare class JoinSourceBuilder {
12
+ #private;
13
+ /**
14
+ * @param registry - Model definitions.
15
+ * @param columns - Table references of models.
16
+ */
17
+ constructor(registry: ModelRegistry, columns: AttributeColumns);
18
+ /**
19
+ * Converts `from` / `using` options into FROM items.
20
+ *
21
+ * @param sources - Relations by alias.
22
+ * @returns FROM items (empty without sources).
23
+ */
24
+ build(sources: JoinSources | undefined): readonly FromItem[];
25
+ }
@@ -0,0 +1,25 @@
1
+ import { SelectNode } from '../sql/ast.ts';
2
+ import { ModelDefinition } from './model-definition.ts';
3
+ /** Parent keys of a top-N-per-parent read: child rows whose `attribute` equals one of `values`. */
4
+ export type LateralKeys = Readonly<{
5
+ attribute: string;
6
+ values: readonly unknown[];
7
+ }>;
8
+ /**
9
+ * Wraps the per-parent query in `FROM unnest(keys) JOIN LATERAL (query) ON TRUE`, so that `limit`
10
+ * and `order` of the query apply to each key separately.
11
+ */
12
+ export declare class LateralKeysBuilder {
13
+ #private;
14
+ /**
15
+ * Builds the outer SELECT.
16
+ *
17
+ * @param definition - Definition of the child model.
18
+ * @param inner - Per-parent SELECT (with `limit` and `order`) without the key condition.
19
+ * @param keys - Parent keys and the child attribute they match.
20
+ * @param alias - Alias of the child rows.
21
+ * @returns SELECT of every child row, grouped by key in key order.
22
+ * @throws Error when the key attribute is not a stored attribute.
23
+ */
24
+ build(definition: ModelDefinition, inner: SelectNode, keys: LateralKeys, alias: string): SelectNode;
25
+ }
@@ -0,0 +1,31 @@
1
+ import { ExprNode, MergeNode, MergeWhen } from '../sql/ast.ts';
2
+ import { AttributeColumns } from './attribute-columns.ts';
3
+ import { MergeOptions } from './merge-options.ts';
4
+ import { ModelDefinition } from './model-definition.ts';
5
+ /** Builds the join condition and the `WHEN [NOT] MATCHED [BY SOURCE]` clauses of `Model.merge`. */
6
+ export declare class MergeActionBuilder {
7
+ #private;
8
+ /**
9
+ * @param columns - Attribute to column mapping.
10
+ */
11
+ constructor(columns: AttributeColumns);
12
+ /**
13
+ * Join condition between target and source.
14
+ *
15
+ * @param definition - Model definition.
16
+ * @param where - `on` option.
17
+ * @returns Condition.
18
+ * @throws Error for a missing condition.
19
+ */
20
+ on(definition: ModelDefinition, where: unknown): ExprNode;
21
+ /**
22
+ * WHEN clauses in order: matched, not matched, not matched by source.
23
+ *
24
+ * @param definition - Model definition.
25
+ * @param options - Merge options.
26
+ * @param source - MERGE source.
27
+ * @returns WHEN clauses.
28
+ * @throws Error without any WHEN clause.
29
+ */
30
+ whens(definition: ModelDefinition, options: MergeOptions<unknown>, source: MergeNode['source']): readonly MergeWhen[];
31
+ }
@@ -0,0 +1,72 @@
1
+ import { Subquery } from '../expressions/methods.ts';
2
+ import { WhereOptions } from './types.ts';
3
+ /**
4
+ * One `WHEN MATCHED` / `WHEN NOT MATCHED BY SOURCE` action of `merge`.
5
+ *
6
+ * Set exactly one of `update`, `delete` or `nothing`.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const action: MergeMatchedAction<Product> = { where: { active: true }, update: { price: col('source.price') } };
11
+ * ```
12
+ */
13
+ export interface MergeMatchedAction<T> {
14
+ /** Extra condition (`WHEN MATCHED AND ...`). */
15
+ readonly where?: WhereOptions<T> | unknown;
16
+ /** Update the target row with these values / expressions (`col('source.attr')`). */
17
+ readonly update?: Partial<Record<keyof T & string, unknown>>;
18
+ /** Delete the target row. */
19
+ readonly delete?: true;
20
+ /** Do nothing. */
21
+ readonly nothing?: true;
22
+ }
23
+ /**
24
+ * `WHEN NOT MATCHED` action of `merge`.
25
+ *
26
+ * Set `insert` or `nothing`.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const action: MergeInsertAction<Product> = { insert: { sku: col('source.sku'), price: 0 } };
31
+ * ```
32
+ */
33
+ export interface MergeInsertAction<T> {
34
+ /** Extra condition (`WHEN NOT MATCHED AND ...`); may reference only source columns. */
35
+ readonly where?: unknown;
36
+ /** Values to insert: `true` copies same-named source columns, or a map of values / expressions. */
37
+ readonly insert?: true | Partial<Record<keyof T & string, unknown>>;
38
+ /** Do nothing. */
39
+ readonly nothing?: true;
40
+ }
41
+ /**
42
+ * Options of `Model.merge`, which runs a `MERGE` statement. PostgreSQL 15+ (RETURNING: 17+).
43
+ *
44
+ * Rows of the model table are the target; `source` rows or a subquery are the source.
45
+ *
46
+ * @see {@link Model.merge}
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * const opts: MergeOptions<Product> = {
51
+ * source: [{ sku: 'a1', price: 10 }],
52
+ * on: { sku: col('source.sku') },
53
+ * whenMatched: { update: { price: col('source.price') } },
54
+ * whenNotMatched: { insert: true },
55
+ * };
56
+ * ```
57
+ */
58
+ export interface MergeOptions<T> {
59
+ /** Source rows (plain objects) or a subquery. */
60
+ readonly source: readonly Readonly<Record<string, unknown>>[] | Subquery;
61
+ /** Alias of the source relation.
62
+ * @defaultValue 'source' */
63
+ readonly as?: string;
64
+ /** Join condition between target (model alias) and source (`col('source.attr')`). */
65
+ readonly on: WhereOptions<T> | unknown;
66
+ /** Actions for matched rows, applied in order. */
67
+ readonly whenMatched?: MergeMatchedAction<T> | readonly MergeMatchedAction<T>[];
68
+ /** Actions for source rows without a target row. */
69
+ readonly whenNotMatched?: MergeInsertAction<T> | readonly MergeInsertAction<T>[];
70
+ /** Actions for target rows without a source row (PostgreSQL 17+). */
71
+ readonly whenNotMatchedBySource?: MergeMatchedAction<T> | readonly MergeMatchedAction<T>[];
72
+ }
@@ -0,0 +1,29 @@
1
+ import { MergeNode } from '../sql/ast.ts';
2
+ import { AttributeColumns } from './attribute-columns.ts';
3
+ import { MergeOptions } from './merge-options.ts';
4
+ import { ModelDefinition } from './model-definition.ts';
5
+ export type { MergeInsertAction, MergeMatchedAction, MergeOptions } from './merge-options.ts';
6
+ /**
7
+ * Builds `MERGE INTO ... USING ...` statements of `Model.merge`: a VALUES or subquery source, the
8
+ * join condition, `WHEN [NOT] MATCHED [BY SOURCE]` actions with timestamps, and RETURNING with
9
+ * `merge_action()`.
10
+ */
11
+ export declare class MergeQueryBuilder {
12
+ #private;
13
+ /** Column carrying `merge_action()` in RETURNING. */
14
+ static readonly ACTION = "__pgz_merge_action";
15
+ /**
16
+ * @param columns - Attribute to column mapping.
17
+ */
18
+ constructor(columns: AttributeColumns);
19
+ /**
20
+ * Builds a MERGE statement for a model.
21
+ *
22
+ * @param definition - Model definition.
23
+ * @param options - Source, join condition and WHEN clauses.
24
+ * @param returning - Return written rows with the action taken.
25
+ * @returns MERGE node.
26
+ * @throws Error for empty sources, a missing `on` condition or no WHEN clause.
27
+ */
28
+ build(definition: ModelDefinition, options: MergeOptions<unknown>, returning: boolean): MergeNode;
29
+ }
@@ -0,0 +1,22 @@
1
+ import { MergeNode } from '../sql/ast.ts';
2
+ import { AttributeColumns } from './attribute-columns.ts';
3
+ import { MergeOptions } from './merge-options.ts';
4
+ import { ModelDefinition } from './model-definition.ts';
5
+ /** Builds the `USING` source of `Model.merge`: a subquery or typed `VALUES` rows. */
6
+ export declare class MergeSourceBuilder {
7
+ #private;
8
+ /**
9
+ * @param columns - Attribute to column mapping.
10
+ */
11
+ constructor(columns: AttributeColumns);
12
+ /**
13
+ * Builds the MERGE source.
14
+ *
15
+ * @param definition - Model definition.
16
+ * @param source - Source rows (plain objects) or a subquery.
17
+ * @param alias - Alias of the source.
18
+ * @returns MERGE source.
19
+ * @throws Error for empty source rows.
20
+ */
21
+ build(definition: ModelDefinition, source: MergeOptions<unknown>['source'], alias: string): MergeNode['source'];
22
+ }
@@ -0,0 +1,69 @@
1
+ import { AggregateOptions, AnyModel, Attributes, ModelStatic } from '../options.ts';
2
+ import { ModelConstructor } from './model-constructor.ts';
3
+ /**
4
+ * Aggregate statics of `Model`: `aggregate`, `max`, `min`, `sum`.
5
+ *
6
+ * @internal
7
+ */
8
+ export declare const ModelAggregates: <TBase extends ModelConstructor>(Base: TBase) => {
9
+ new (...args: any[]): {
10
+ get wasInserted(): boolean | undefined;
11
+ get oldValues(): Readonly<Record<string, unknown>> | null | undefined;
12
+ get sequelize(): import('../runtime.ts').RuntimeOwner;
13
+ };
14
+ /**
15
+ * Runs one SQL aggregate function over a column (`SELECT fn(col) ...`), applying the default scope
16
+ * and the paranoid filter. The function name is checked against a safe name pattern, never
17
+ * concatenated unchecked.
18
+ *
19
+ * @param this - The model class.
20
+ * @param field - Attribute name or `'*'`.
21
+ * @param aggregateFunction - SQL aggregate function name, e.g. `'max'`.
22
+ * @param options - Options (`where`, `distinct`, `group`, `plain: false` to get rows, query options).
23
+ * @returns Aggregated value: a number for `count` and numeric attributes, otherwise parsed like the attribute; rows with `plain: false`.
24
+ * @example
25
+ * ```ts
26
+ * const avgPrice = await Product.aggregate('price', 'avg', { where: { active: true } });
27
+ * ```
28
+ */
29
+ aggregate<M extends AnyModel, T = unknown>(this: ModelStatic<M>, field: keyof Attributes<M> | "*", aggregateFunction: string, options?: AggregateOptions<Attributes<M>>): Promise<T>;
30
+ /**
31
+ * Finds the largest value of an attribute with `max()`.
32
+ *
33
+ * @param this - The model class.
34
+ * @param field - Attribute name.
35
+ * @param options - Options, see {@link Model.aggregate}.
36
+ * @returns Maximum or `null` when there are no rows.
37
+ * @example
38
+ * ```ts
39
+ * const highest = await Product.max('price');
40
+ * ```
41
+ */
42
+ max<M extends AnyModel, T_1 = unknown>(this: ModelStatic<M>, field: keyof Attributes<M>, options?: AggregateOptions<Attributes<M>>): Promise<T_1>;
43
+ /**
44
+ * Finds the smallest value of an attribute with `min()`.
45
+ *
46
+ * @param this - The model class.
47
+ * @param field - Attribute name.
48
+ * @param options - Options, see {@link Model.aggregate}.
49
+ * @returns Minimum or `null` when there are no rows.
50
+ * @example
51
+ * ```ts
52
+ * const lowest = await Product.min('price', { where: { active: true } });
53
+ * ```
54
+ */
55
+ min<M extends AnyModel, T_2 = unknown>(this: ModelStatic<M>, field: keyof Attributes<M>, options?: AggregateOptions<Attributes<M>>): Promise<T_2>;
56
+ /**
57
+ * Adds up the values of an attribute with `sum()`.
58
+ *
59
+ * @param this - The model class.
60
+ * @param field - Attribute name.
61
+ * @param options - Options, see {@link Model.aggregate}.
62
+ * @returns Sum, or `null` when there are no rows (as returned by PostgreSQL).
63
+ * @example
64
+ * ```ts
65
+ * const total = await Invoice.sum('amount', { where: { paid: true } });
66
+ * ```
67
+ */
68
+ sum<M extends AnyModel>(this: ModelStatic<M>, field: keyof Attributes<M>, options?: AggregateOptions<Attributes<M>>): Promise<number>;
69
+ } & TBase;
@@ -0,0 +1,73 @@
1
+ import { Association, AssociationOptions, BelongsToManyOptions } from '../../associations/types.ts';
2
+ import { AnyModel, ModelStatic } from '../options.ts';
3
+ import { ModelConstructor } from './model-constructor.ts';
4
+ /**
5
+ * Association statics of `Model`: `associations`, `belongsTo`, `hasOne`, `hasMany`, `belongsToMany`.
6
+ *
7
+ * @internal
8
+ */
9
+ export declare const ModelAssociations: <TBase extends ModelConstructor>(Base: TBase) => {
10
+ new (...args: any[]): {
11
+ get wasInserted(): boolean | undefined;
12
+ get oldValues(): Readonly<Record<string, unknown>> | null | undefined;
13
+ get sequelize(): import('../runtime.ts').RuntimeOwner;
14
+ };
15
+ /** Associations of the model by alias (Sequelize v6 `Model.associations`). */
16
+ get associations(): Readonly<Record<string, Association>>;
17
+ /**
18
+ * Declares that each row of this model refers to one row of the target; the foreign key column
19
+ * lives on this model's table. Adds accessors such as `getX` / `setX` / `createX` to instances.
20
+ *
21
+ * @param this - The source model class.
22
+ * @param target - Associated model.
23
+ * @param options - Association options.
24
+ * @returns The association.
25
+ * @example
26
+ * ```ts
27
+ * Post.belongsTo(User, { foreignKey: 'authorId', as: 'author' });
28
+ * ```
29
+ * @see [Associations guide](/guide/associations)
30
+ */
31
+ belongsTo<M extends AnyModel, T extends AnyModel>(this: ModelStatic<M>, target: ModelStatic<T>, options?: AssociationOptions): Association;
32
+ /**
33
+ * Declares that each row of this model has at most one related target row; the foreign key column
34
+ * lives on the target's table.
35
+ *
36
+ * @param this - The source model class.
37
+ * @param target - Associated model.
38
+ * @param options - Association options.
39
+ * @returns The association.
40
+ * @example
41
+ * ```ts
42
+ * User.hasOne(Profile, { foreignKey: 'userId' });
43
+ * ```
44
+ */
45
+ hasOne<M extends AnyModel, T_1 extends AnyModel>(this: ModelStatic<M>, target: ModelStatic<T_1>, options?: AssociationOptions): Association;
46
+ /**
47
+ * Declares that each row of this model has many related target rows; the foreign key column
48
+ * lives on the target's table.
49
+ *
50
+ * @param this - The source model class.
51
+ * @param target - Associated model.
52
+ * @param options - Association options.
53
+ * @returns The association.
54
+ * @example
55
+ * ```ts
56
+ * User.hasMany(Post, { foreignKey: 'authorId', as: 'posts' });
57
+ * ```
58
+ */
59
+ hasMany<M extends AnyModel, T_2 extends AnyModel>(this: ModelStatic<M>, target: ModelStatic<T_2>, options?: AssociationOptions): Association;
60
+ /**
61
+ * Declares a many-to-many relation between this model and the target through a junction table.
62
+ *
63
+ * @param this - The source model class.
64
+ * @param target - Associated model.
65
+ * @param options - Association options with `through`.
66
+ * @returns The association.
67
+ * @example
68
+ * ```ts
69
+ * Project.belongsToMany(Task, { through: 'ProjectTasks' });
70
+ * ```
71
+ */
72
+ belongsToMany<M extends AnyModel, T_3 extends AnyModel>(this: ModelStatic<M>, target: ModelStatic<T_3>, options: BelongsToManyOptions): Association;
73
+ } & TBase;
@@ -0,0 +1,7 @@
1
+ import { ModelBase } from '../model-base.ts';
2
+ /**
3
+ * Constructor of `ModelBase` or a class derived from it; the base type of model mixins.
4
+ *
5
+ * @internal
6
+ */
7
+ export type ModelConstructor = new (...args: any[]) => ModelBase;
@@ -0,0 +1,124 @@
1
+ import { AnyModel, Attributes, CountOptions, FindAndCountResult, FindOptions, FindOrCreateOptions, ModelStatic } from '../options.ts';
2
+ import { ModelConstructor } from './model-constructor.ts';
3
+ /**
4
+ * Read statics of `Model`: `findAll`, `findOne`, `findByPk`, `count`, `findAndCountAll`, `findOrCreate`, `findOrBuild`.
5
+ *
6
+ * @internal
7
+ */
8
+ export declare const ModelFinders: <TBase extends ModelConstructor>(Base: TBase) => {
9
+ new (...args: any[]): {
10
+ get wasInserted(): boolean | undefined;
11
+ get oldValues(): Readonly<Record<string, unknown>> | null | undefined;
12
+ get sequelize(): import('../runtime.ts').RuntimeOwner;
13
+ };
14
+ /**
15
+ * Selects all rows matching the options, applying the default scope and, for paranoid models,
16
+ * hiding soft-deleted rows. Runs `beforeFind` and `afterFind` hooks unless `hooks: false`.
17
+ *
18
+ * @param this - The model class (or a scoped model class from {@link Model.scope}).
19
+ * @param options - Query options (`where`, `attributes`, `order`, `limit`, `include`, ...).
20
+ * @returns Instances, or plain objects with `raw: true`.
21
+ * @example
22
+ * ```ts
23
+ * const posts = await Post.findAll({
24
+ * where: { published: true },
25
+ * order: [['createdAt', 'DESC']],
26
+ * limit: 20,
27
+ * include: [User],
28
+ * });
29
+ * ```
30
+ * @see {@link Model.findEach} to stream large result sets.
31
+ */
32
+ findAll<M extends AnyModel>(this: ModelStatic<M>, options?: FindOptions<Attributes<M>>): Promise<M[]>;
33
+ /**
34
+ * Selects the first row matching the options and rejects when none is found.
35
+ *
36
+ * @param this - The model class (or a scoped model class from {@link Model.scope}).
37
+ * @param options - Query options with `rejectOnEmpty`.
38
+ * @returns Instance.
39
+ * @throws EmptyResultError (or the given error) when nothing is found.
40
+ * @example
41
+ * ```ts
42
+ * const user = await User.findOne({ where: { email: 'ada@example.com' }, rejectOnEmpty: true });
43
+ * ```
44
+ */
45
+ findOne<M extends AnyModel>(this: ModelStatic<M>, options: FindOptions<Attributes<M>> & Readonly<{
46
+ rejectOnEmpty: true | Error;
47
+ }>): Promise<M>;
48
+ /**
49
+ * Selects the first row matching the options (`LIMIT 1` unless `limit` is given).
50
+ *
51
+ * @param this - The model class (or a scoped model class from {@link Model.scope}).
52
+ * @param options - Query options.
53
+ * @returns Instance or `null`.
54
+ */
55
+ findOne<M extends AnyModel>(this: ModelStatic<M>, options?: FindOptions<Attributes<M>>): Promise<M | null>;
56
+ /**
57
+ * Selects the row with the given primary key.
58
+ *
59
+ * @param this - The model class (or a scoped model class from {@link Model.scope}).
60
+ * @param key - Primary key value.
61
+ * @param options - Query options other than `where`.
62
+ * @returns Instance or `null`.
63
+ * @example
64
+ * ```ts
65
+ * const user = await User.findByPk(42, { include: [Profile] });
66
+ * ```
67
+ */
68
+ findByPk<M extends AnyModel>(this: ModelStatic<M>, key: unknown, options?: Omit<FindOptions<Attributes<M>>, "where">): Promise<M | null>;
69
+ /**
70
+ * Counts rows, applying the default scope and the paranoid filter. Runs `beforeCount` hooks
71
+ * unless `hooks: false`.
72
+ *
73
+ * @param this - The model class (or a scoped model class from {@link Model.scope}).
74
+ * @param options - Count options (`where`, `col`, `distinct`, `group`, `include`).
75
+ * @returns The count. With `group` the runtime value is an array of `{ count, ...groupColumns }` objects, as in Sequelize v6.
76
+ * @example
77
+ * ```ts
78
+ * const active = await User.count({ where: { active: true } });
79
+ * ```
80
+ */
81
+ count<M extends AnyModel>(this: ModelStatic<M>, options?: CountOptions<Attributes<M>>): Promise<number>;
82
+ /**
83
+ * Runs {@link Model.findAll} and {@link Model.count} with the same filter, so `limit` / `offset`
84
+ * paginate the rows while `count` is the total.
85
+ *
86
+ * @param this - The model class (or a scoped model class from {@link Model.scope}).
87
+ * @param options - Query options.
88
+ * @returns Total count and the current page of rows.
89
+ * @example
90
+ * ```ts
91
+ * const { count, rows } = await Post.findAndCountAll({ where: { published: true }, limit: 10, offset: 20 });
92
+ * ```
93
+ */
94
+ findAndCountAll<M extends AnyModel>(this: ModelStatic<M>, options?: FindOptions<Attributes<M>>): Promise<FindAndCountResult<M>>;
95
+ /**
96
+ * Finds a row, or creates it when none matches. Creation runs inside a transaction (a nested
97
+ * one when `options.transaction` is given); when creation fails but the row exists after all
98
+ * (a concurrent insert won), that row is returned, otherwise the error is rethrown.
99
+ *
100
+ * @param this - The model class (or a scoped model class from {@link Model.scope}).
101
+ * @param options - `where` to search (its equality values also seed the new row), `defaults` to add on creation.
102
+ * @returns `[instance, created]`.
103
+ * @example
104
+ * ```ts
105
+ * const [tag, created] = await Tag.findOrCreate({ where: { name: 'news' }, defaults: { color: 'red' } });
106
+ * ```
107
+ */
108
+ findOrCreate<M extends AnyModel>(this: ModelStatic<M>, options: FindOrCreateOptions<Attributes<M>>): Promise<[M, boolean]>;
109
+ /**
110
+ * Finds a row, or builds a new unsaved instance when none matches; nothing is inserted.
111
+ *
112
+ * @param this - The model class (or a scoped model class from {@link Model.scope}).
113
+ * @param options - `where` to search (its equality values also seed the built instance), `defaults` to add when building.
114
+ * @returns `[instance, built]`.
115
+ * @example
116
+ * ```ts
117
+ * const [tag, built] = await Tag.findOrBuild({ where: { name: 'news' } });
118
+ * if (built) {
119
+ * await tag.save();
120
+ * }
121
+ * ```
122
+ */
123
+ findOrBuild<M extends AnyModel>(this: ModelStatic<M>, options: FindOrCreateOptions<Attributes<M>>): Promise<[M, boolean]>;
124
+ } & TBase;