postgrelize 0.0.0-stage → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (319) hide show
  1. package/CHANGELOG.md +289 -0
  2. package/LICENSE +21 -0
  3. package/README.md +131 -2
  4. package/dist/associations/alias-minifier.d.ts +43 -0
  5. package/dist/associations/association-accessors.d.ts +21 -0
  6. package/dist/associations/association-key-types.d.ts +44 -0
  7. package/dist/associations/association-keys.d.ts +98 -0
  8. package/dist/associations/association-lookup.d.ts +26 -0
  9. package/dist/associations/association-shape.d.ts +25 -0
  10. package/dist/associations/association.d.ts +95 -0
  11. package/dist/associations/belongs-to-many.d.ts +86 -0
  12. package/dist/associations/belongs-to.d.ts +45 -0
  13. package/dist/associations/has-many.d.ts +79 -0
  14. package/dist/associations/has-one.d.ts +44 -0
  15. package/dist/associations/include-assembler.d.ts +21 -0
  16. package/dist/associations/include-columns.d.ts +24 -0
  17. package/dist/associations/include-joins.d.ts +17 -0
  18. package/dist/associations/include-loader.d.ts +48 -0
  19. package/dist/associations/include-order.d.ts +22 -0
  20. package/dist/associations/include-query-builder.d.ts +54 -0
  21. package/dist/associations/include-resolver.d.ts +29 -0
  22. package/dist/associations/include-rows.d.ts +47 -0
  23. package/dist/associations/include-sub-query.d.ts +35 -0
  24. package/dist/associations/include.d.ts +112 -0
  25. package/dist/associations/junction-keys.d.ts +23 -0
  26. package/dist/associations/nested-creator.d.ts +44 -0
  27. package/dist/associations/nested-saver.d.ts +30 -0
  28. package/dist/associations/owner-keys.d.ts +34 -0
  29. package/dist/associations/separate-include-loader.d.ts +24 -0
  30. package/dist/associations/types.d.ts +139 -0
  31. package/dist/connection/after-connect-hook.d.ts +24 -0
  32. package/dist/connection/connect-hooks.d.ts +26 -0
  33. package/dist/connection/connection-config.d.ts +33 -0
  34. package/dist/connection/connection-manager.d.ts +65 -0
  35. package/dist/connection/connection-types.d.ts +21 -0
  36. package/dist/connection/copy-from-stdin.d.ts +52 -0
  37. package/dist/connection/copy-runner.d.ts +30 -0
  38. package/dist/connection/copy-to-stdout.d.ts +49 -0
  39. package/dist/connection/copy.d.ts +22 -0
  40. package/dist/connection/notifications.d.ts +28 -0
  41. package/dist/connection/options.d.ts +165 -0
  42. package/dist/connection/query-logger.d.ts +41 -0
  43. package/dist/connection/replica-router.d.ts +20 -0
  44. package/dist/connection/statement-cache.d.ts +36 -0
  45. package/dist/connection/statement-timeout.d.ts +22 -0
  46. package/dist/data-types/abstract-data-type.d.ts +58 -0
  47. package/dist/data-types/array-literal-parser.d.ts +17 -0
  48. package/dist/data-types/array-type.d.ts +18 -0
  49. package/dist/data-types/bit-type.d.ts +14 -0
  50. package/dist/data-types/blob-type.d.ts +12 -0
  51. package/dist/data-types/char-type.d.ts +12 -0
  52. package/dist/data-types/composite-fields.d.ts +26 -0
  53. package/dist/data-types/composite-type.d.ts +32 -0
  54. package/dist/data-types/data-types.d.ts +176 -0
  55. package/dist/data-types/date-type.d.ts +14 -0
  56. package/dist/data-types/decimal-type.d.ts +13 -0
  57. package/dist/data-types/default-value-generator.d.ts +15 -0
  58. package/dist/data-types/enum-type.d.ts +19 -0
  59. package/dist/data-types/ewkb-reader.d.ts +18 -0
  60. package/dist/data-types/ewkb-writer.d.ts +17 -0
  61. package/dist/data-types/float-type.d.ts +12 -0
  62. package/dist/data-types/geometric-text.d.ts +65 -0
  63. package/dist/data-types/geometric-type.d.ts +46 -0
  64. package/dist/data-types/hstore-type.d.ts +16 -0
  65. package/dist/data-types/integer-type.d.ts +24 -0
  66. package/dist/data-types/json-type.d.ts +16 -0
  67. package/dist/data-types/multirange-type.d.ts +19 -0
  68. package/dist/data-types/range-type.d.ts +28 -0
  69. package/dist/data-types/record-text.d.ts +29 -0
  70. package/dist/data-types/scalar-type.d.ts +13 -0
  71. package/dist/data-types/spatial-type.d.ts +20 -0
  72. package/dist/data-types/string-type.d.ts +12 -0
  73. package/dist/data-types/text-type.d.ts +12 -0
  74. package/dist/data-types/timestamp-type.d.ts +15 -0
  75. package/dist/data-types/virtual-type.d.ts +15 -0
  76. package/dist/data-types/wall-clock.d.ts +14 -0
  77. package/dist/ddl/column-ddl.d.ts +73 -0
  78. package/dist/ddl/constraint-ddl.d.ts +30 -0
  79. package/dist/ddl/ddl-generator.d.ts +181 -0
  80. package/dist/ddl/ddl-guards.d.ts +60 -0
  81. package/dist/ddl/ddl-types.d.ts +204 -0
  82. package/dist/ddl/enum-ddl.d.ts +42 -0
  83. package/dist/ddl/extension-ddl.d.ts +57 -0
  84. package/dist/ddl/function-ddl.d.ts +98 -0
  85. package/dist/ddl/index-ddl.d.ts +29 -0
  86. package/dist/ddl/index-element-ddl.d.ts +19 -0
  87. package/dist/ddl/partition-ddl.d.ts +88 -0
  88. package/dist/ddl/partition-types.d.ts +94 -0
  89. package/dist/ddl/policy-ddl.d.ts +137 -0
  90. package/dist/ddl/routine-guards.d.ts +63 -0
  91. package/dist/ddl/sequence-ddl.d.ts +103 -0
  92. package/dist/ddl/sql-literal.d.ts +61 -0
  93. package/dist/ddl/table-ddl.d.ts +35 -0
  94. package/dist/ddl/trigger-ddl.d.ts +81 -0
  95. package/dist/ddl/view-ddl.d.ts +122 -0
  96. package/dist/decorators/association-applier.d.ts +18 -0
  97. package/dist/decorators/association-decorators.d.ts +72 -0
  98. package/dist/decorators/column-decorators.d.ts +147 -0
  99. package/dist/decorators/decorator-factory.d.ts +45 -0
  100. package/dist/decorators/decorator-signature.d.ts +26 -0
  101. package/dist/decorators/decorator-types.d.ts +24 -0
  102. package/dist/decorators/foreign-key-decorator.d.ts +21 -0
  103. package/dist/decorators/hook-decorators.d.ts +393 -0
  104. package/dist/decorators/init-arguments.d.ts +29 -0
  105. package/dist/decorators/model-decorators.d.ts +18 -0
  106. package/dist/decorators/model-metadata.d.ts +70 -0
  107. package/dist/decorators/table-decorators.d.ts +43 -0
  108. package/dist/decorators/timestamp-decorators.d.ts +38 -0
  109. package/dist/errors/base-error.d.ts +40 -0
  110. package/dist/errors/connection-errors.d.ts +152 -0
  111. package/dist/errors/database-errors.d.ts +186 -0
  112. package/dist/errors/errors.d.ts +5 -0
  113. package/dist/errors/map-pg-error.d.ts +27 -0
  114. package/dist/errors/misc-errors.d.ts +232 -0
  115. package/dist/errors/validation-errors.d.ts +141 -0
  116. package/dist/exports-associations.d.ts +6 -0
  117. package/dist/exports-core.d.ts +95 -0
  118. package/dist/exports-decorators.d.ts +8 -0
  119. package/dist/exports-errors.d.ts +2 -0
  120. package/dist/exports-model.d.ts +21 -0
  121. package/dist/exports-schema.d.ts +19 -0
  122. package/dist/expressions/call-expressions.d.ts +54 -0
  123. package/dist/expressions/condition-expressions.d.ts +51 -0
  124. package/dist/expressions/expression.d.ts +52 -0
  125. package/dist/expressions/jsonpath-helpers.d.ts +37 -0
  126. package/dist/expressions/logic.d.ts +25 -0
  127. package/dist/expressions/methods.d.ts +188 -0
  128. package/dist/expressions/op.d.ts +182 -0
  129. package/dist/expressions/query-expressions.d.ts +110 -0
  130. package/dist/expressions/row-expressions.d.ts +35 -0
  131. package/dist/expressions/search-helpers.d.ts +138 -0
  132. package/dist/expressions/trigram-helpers.d.ts +40 -0
  133. package/dist/hooks/hooks.d.ts +125 -0
  134. package/dist/index.cjs +21864 -0
  135. package/dist/index.cjs.map +1 -0
  136. package/dist/index.d.ts +6 -0
  137. package/dist/index.js +21688 -0
  138. package/dist/index.js.map +1 -0
  139. package/dist/model/attribute-columns.d.ts +85 -0
  140. package/dist/model/attribute-normalizer.d.ts +42 -0
  141. package/dist/model/attribute-options.d.ts +121 -0
  142. package/dist/model/bulk-insert-builder.d.ts +24 -0
  143. package/dist/model/bulk-options.d.ts +173 -0
  144. package/dist/model/copy-options.d.ts +51 -0
  145. package/dist/model/cte-builder.d.ts +134 -0
  146. package/dist/model/definition-normalizer.d.ts +26 -0
  147. package/dist/model/delete-query-builder.d.ts +42 -0
  148. package/dist/model/find-options.d.ts +144 -0
  149. package/dist/model/find-query-builder.d.ts +38 -0
  150. package/dist/model/inflector.d.ts +28 -0
  151. package/dist/model/insert-query-builder.d.ts +41 -0
  152. package/dist/model/instance-destroyer.d.ts +44 -0
  153. package/dist/model/instance-lifecycle-services.d.ts +61 -0
  154. package/dist/model/instance-lifecycle.d.ts +128 -0
  155. package/dist/model/instance-saver.d.ts +25 -0
  156. package/dist/model/instance-state.d.ts +48 -0
  157. package/dist/model/instance-validation.d.ts +35 -0
  158. package/dist/model/instance-values.d.ts +88 -0
  159. package/dist/model/instance-writer.d.ts +59 -0
  160. package/dist/model/join-source-builder.d.ts +25 -0
  161. package/dist/model/lateral-keys-builder.d.ts +25 -0
  162. package/dist/model/merge-action-builder.d.ts +31 -0
  163. package/dist/model/merge-options.d.ts +72 -0
  164. package/dist/model/merge-query-builder.d.ts +29 -0
  165. package/dist/model/merge-source-builder.d.ts +22 -0
  166. package/dist/model/mixins/model-aggregates.d.ts +69 -0
  167. package/dist/model/mixins/model-associations.d.ts +113 -0
  168. package/dist/model/mixins/model-constructor.d.ts +7 -0
  169. package/dist/model/mixins/model-finders.d.ts +140 -0
  170. package/dist/model/mixins/model-hooks.d.ts +142 -0
  171. package/dist/model/mixins/model-postgres.d.ts +198 -0
  172. package/dist/model/mixins/model-schema-binding.d.ts +36 -0
  173. package/dist/model/mixins/model-schema.d.ts +100 -0
  174. package/dist/model/mixins/model-scopes.d.ts +57 -0
  175. package/dist/model/mixins/model-writers.d.ts +175 -0
  176. package/dist/model/mixins/named-hooks.d.ts +28 -0
  177. package/dist/model/model-accessors.d.ts +22 -0
  178. package/dist/model/model-base.d.ts +83 -0
  179. package/dist/model/model-definition.d.ts +130 -0
  180. package/dist/model/model-instance-persistence.d.ts +132 -0
  181. package/dist/model/model-instance-values.d.ts +197 -0
  182. package/dist/model/model-operations.d.ts +22 -0
  183. package/dist/model/model-registry.d.ts +152 -0
  184. package/dist/model/model-services.d.ts +46 -0
  185. package/dist/model/model-state.d.ts +68 -0
  186. package/dist/model/model-values.d.ts +86 -0
  187. package/dist/model/model.d.ts +629 -0
  188. package/dist/model/on-conflict-builder.d.ts +111 -0
  189. package/dist/model/operations/bulk-create-operation.d.ts +40 -0
  190. package/dist/model/operations/copy-from-source.d.ts +51 -0
  191. package/dist/model/operations/copy-operation.d.ts +54 -0
  192. package/dist/model/operations/count-operation.d.ts +52 -0
  193. package/dist/model/operations/create-operation.d.ts +31 -0
  194. package/dist/model/operations/destroy-operation.d.ts +65 -0
  195. package/dist/model/operations/find-cursor.d.ts +23 -0
  196. package/dist/model/operations/find-lookups.d.ts +99 -0
  197. package/dist/model/operations/find-operation.d.ts +47 -0
  198. package/dist/model/operations/increment-operation.d.ts +40 -0
  199. package/dist/model/operations/insert-operation.d.ts +71 -0
  200. package/dist/model/operations/merge-operation.d.ts +56 -0
  201. package/dist/model/operations/model-operation.d.ts +33 -0
  202. package/dist/model/operations/update-operation.d.ts +45 -0
  203. package/dist/model/operations/upsert-operation.d.ts +39 -0
  204. package/dist/model/options.d.ts +103 -0
  205. package/dist/model/returning-old.d.ts +52 -0
  206. package/dist/model/row-mapper.d.ts +78 -0
  207. package/dist/model/row-plan.d.ts +31 -0
  208. package/dist/model/runtime.d.ts +56 -0
  209. package/dist/model/scope-registry.d.ts +81 -0
  210. package/dist/model/select-aggregates.d.ts +37 -0
  211. package/dist/model/select-lock.d.ts +13 -0
  212. package/dist/model/select-options.d.ts +92 -0
  213. package/dist/model/select-query-builder.d.ts +73 -0
  214. package/dist/model/select-targets.d.ts +77 -0
  215. package/dist/model/source-option-builder.d.ts +23 -0
  216. package/dist/model/source-options.d.ts +108 -0
  217. package/dist/model/statement-builder.d.ts +77 -0
  218. package/dist/model/statement-services.d.ts +2 -0
  219. package/dist/model/sync-hooks.d.ts +18 -0
  220. package/dist/model/table-sample-builder.d.ts +13 -0
  221. package/dist/model/types.d.ts +85 -0
  222. package/dist/model/unnest-insert-builder.d.ts +24 -0
  223. package/dist/model/update-query-builder.d.ts +39 -0
  224. package/dist/model/v6-conflict-builder.d.ts +37 -0
  225. package/dist/model/value-cloner.d.ts +17 -0
  226. package/dist/model/values-writer.d.ts +12 -0
  227. package/dist/model/where-options.d.ts +164 -0
  228. package/dist/model/write-options.d.ts +160 -0
  229. package/dist/model/written-rows.d.ts +56 -0
  230. package/dist/package-version.d.ts +8 -0
  231. package/dist/query/query-result-shaper.d.ts +93 -0
  232. package/dist/query/raw-query.d.ts +27 -0
  233. package/dist/query-interface/alter-planner.d.ts +40 -0
  234. package/dist/query-interface/bulk-data.d.ts +44 -0
  235. package/dist/query-interface/column-commands.d.ts +52 -0
  236. package/dist/query-interface/column-describer.d.ts +17 -0
  237. package/dist/query-interface/enum-commands.d.ts +36 -0
  238. package/dist/query-interface/index-commands.d.ts +57 -0
  239. package/dist/query-interface/model-tables.d.ts +58 -0
  240. package/dist/query-interface/object-commands.d.ts +71 -0
  241. package/dist/query-interface/partition-commands.d.ts +43 -0
  242. package/dist/query-interface/policy-commands.d.ts +54 -0
  243. package/dist/query-interface/query-interface-catalog.d.ts +180 -0
  244. package/dist/query-interface/query-interface-objects.d.ts +108 -0
  245. package/dist/query-interface/query-interface-partitions.d.ts +66 -0
  246. package/dist/query-interface/query-interface-policies.d.ts +86 -0
  247. package/dist/query-interface/query-interface-routines.d.ts +120 -0
  248. package/dist/query-interface/query-interface-tables.d.ts +179 -0
  249. package/dist/query-interface/query-interface-types.d.ts +62 -0
  250. package/dist/query-interface/query-interface-views.d.ts +84 -0
  251. package/dist/query-interface/query-interface.d.ts +256 -0
  252. package/dist/query-interface/routine-commands.d.ts +71 -0
  253. package/dist/query-interface/schema-synchronizer.d.ts +110 -0
  254. package/dist/query-interface/statement-runner.d.ts +40 -0
  255. package/dist/query-interface/sync-planner.d.ts +26 -0
  256. package/dist/query-interface/table-commands.d.ts +63 -0
  257. package/dist/query-interface/table-introspector.d.ts +58 -0
  258. package/dist/query-interface/view-commands.d.ts +47 -0
  259. package/dist/sequelize/instance-hook-adders.d.ts +72 -0
  260. package/dist/sequelize/sequelize-base.d.ts +196 -0
  261. package/dist/sequelize/sequelize-constructor.d.ts +7 -0
  262. package/dist/sequelize/sequelize-helpers.d.ts +133 -0
  263. package/dist/sequelize/sequelize-hooks.d.ts +99 -0
  264. package/dist/sequelize/sequelize-internals.d.ts +87 -0
  265. package/dist/sequelize/sequelize-notifications.d.ts +66 -0
  266. package/dist/sequelize/sequelize-schema.d.ts +125 -0
  267. package/dist/sequelize/sequelize-transactions.d.ts +96 -0
  268. package/dist/sequelize.d.ts +1175 -0
  269. package/dist/sql/ast-clauses.d.ts +137 -0
  270. package/dist/sql/ast-expressions.d.ts +88 -0
  271. package/dist/sql/ast-statements.d.ts +80 -0
  272. package/dist/sql/ast.d.ts +21 -0
  273. package/dist/sql/compile.d.ts +21 -0
  274. package/dist/sql/dml-compiler.d.ts +54 -0
  275. package/dist/sql/expression-compiler.d.ts +56 -0
  276. package/dist/sql/from-compiler.d.ts +39 -0
  277. package/dist/sql/identifier-quoter.d.ts +15 -0
  278. package/dist/sql/merge-compiler.d.ts +20 -0
  279. package/dist/sql/order.d.ts +15 -0
  280. package/dist/sql/query-compiler.d.ts +45 -0
  281. package/dist/sql/sql-chunks.d.ts +50 -0
  282. package/dist/sql/with-compiler.d.ts +19 -0
  283. package/dist/transaction/advisory-locks.d.ts +28 -0
  284. package/dist/transaction/cls-namespace.d.ts +44 -0
  285. package/dist/transaction/transaction-constants.d.ts +35 -0
  286. package/dist/transaction/transaction-runner.d.ts +78 -0
  287. package/dist/transaction/transaction-starter.d.ts +25 -0
  288. package/dist/transaction/transaction-statements.d.ts +29 -0
  289. package/dist/transaction/transaction.d.ts +201 -0
  290. package/dist/validation/attribute-validators.d.ts +23 -0
  291. package/dist/validation/builtin-attribute-validator.d.ts +19 -0
  292. package/dist/validation/builtin-validators.d.ts +16 -0
  293. package/dist/validation/core-validator.d.ts +16 -0
  294. package/dist/validation/custom-validators.d.ts +13 -0
  295. package/dist/validation/instance-validator.d.ts +25 -0
  296. package/dist/validation/schema-items.d.ts +22 -0
  297. package/dist/validation/standard-schema-validator.d.ts +30 -0
  298. package/dist/validation/standard-schema.d.ts +39 -0
  299. package/dist/validation/types.d.ts +36 -0
  300. package/dist/validation/validation-target.d.ts +13 -0
  301. package/dist/where/comparison-compiler.d.ts +27 -0
  302. package/dist/where/condition-compiler.d.ts +18 -0
  303. package/dist/where/operand-resolver.d.ts +10 -0
  304. package/dist/where/operator-allowlist.d.ts +14 -0
  305. package/dist/where/where-support.d.ts +52 -0
  306. package/dist/where/where.d.ts +46 -0
  307. package/dist/where/window-compiler.d.ts +14 -0
  308. package/llm/USAGE.md +423 -0
  309. package/package.json +103 -4
  310. package/skills/postgrelize/SKILL.md +57 -0
  311. package/skills/postgrelize/reference/associations.md +108 -0
  312. package/skills/postgrelize/reference/errors.md +37 -0
  313. package/skills/postgrelize/reference/migrating-from-sequelize.md +15 -0
  314. package/skills/postgrelize/reference/postgresql-features.md +157 -0
  315. package/skills/postgrelize/reference/querying.md +111 -0
  316. package/skills/postgrelize/reference/schema.md +135 -0
  317. package/skills/postgrelize/reference/security.md +34 -0
  318. package/skills/postgrelize/reference/transactions-and-sessions.md +122 -0
  319. package/skills/postgrelize/reference/writing.md +198 -0
@@ -0,0 +1,140 @@
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; when none matches, inserts it and, if that fails with a unique violation (a concurrent
111
+ * insert won), reads the row again. Unlike `findOrCreate` the insert is not wrapped in a transaction, so it
112
+ * suits code that already handles the race itself. Inside a transaction the insert uses a savepoint, which
113
+ * fixes v6 returning an unsaved instance after a conflict.
114
+ *
115
+ * @param this - The model class (or a scoped model class from {@link Model.scope}).
116
+ * @param options - `where` to search (required; its equality values also seed the new row), `defaults` to add on creation.
117
+ * @returns `[instance, created]`.
118
+ * @throws Error when `where` is missing.
119
+ * @example
120
+ * ```ts
121
+ * const [tag, created] = await Tag.findCreateFind({ where: { name: 'news' }, defaults: { color: 'red' } });
122
+ * ```
123
+ */
124
+ findCreateFind<M extends AnyModel>(this: ModelStatic<M>, options: FindOrCreateOptions<Attributes<M>>): Promise<[M, boolean]>;
125
+ /**
126
+ * Finds a row, or builds a new unsaved instance when none matches; nothing is inserted.
127
+ *
128
+ * @param this - The model class (or a scoped model class from {@link Model.scope}).
129
+ * @param options - `where` to search (its equality values also seed the built instance), `defaults` to add when building.
130
+ * @returns `[instance, built]`.
131
+ * @example
132
+ * ```ts
133
+ * const [tag, built] = await Tag.findOrBuild({ where: { name: 'news' } });
134
+ * if (built) {
135
+ * await tag.save();
136
+ * }
137
+ * ```
138
+ */
139
+ findOrBuild<M extends AnyModel>(this: ModelStatic<M>, options: FindOrCreateOptions<Attributes<M>>): Promise<[M, boolean]>;
140
+ } & TBase;
@@ -0,0 +1,142 @@
1
+ import { HookFunction, HookType } from '../../hooks/hooks.ts';
2
+ import { AnyModel, ModelStatic } from '../options.ts';
3
+ import { NamedHookAdder } from './named-hooks.ts';
4
+ import { ModelConstructor } from './model-constructor.ts';
5
+ /**
6
+ * Hook statics of `Model`: `addHook`, `removeHook`, `hasHook(s)`, `runHooks` and the named adders (`Model.beforeCreate(fn)`, ...).
7
+ *
8
+ * @internal
9
+ */
10
+ export declare const ModelHooks: <TBase extends ModelConstructor>(Base: TBase) => {
11
+ new (...args: any[]): {
12
+ get wasInserted(): boolean | undefined;
13
+ get oldValues(): Readonly<Record<string, unknown>> | null | undefined;
14
+ get sequelize(): import('../runtime.ts').RuntimeOwner;
15
+ };
16
+ /** Adds a `beforeValidate` hook: `Model.beforeValidate(fn)` or `Model.beforeValidate(name, fn)`. */
17
+ beforeValidate: NamedHookAdder;
18
+ /** Adds a `afterValidate` hook: `Model.afterValidate(fn)` or `Model.afterValidate(name, fn)`. */
19
+ afterValidate: NamedHookAdder;
20
+ /** Adds a `validationFailed` hook: `Model.validationFailed(fn)` or `Model.validationFailed(name, fn)`. */
21
+ validationFailed: NamedHookAdder;
22
+ /** Adds a `beforeCreate` hook: `Model.beforeCreate(fn)` or `Model.beforeCreate(name, fn)`. */
23
+ beforeCreate: NamedHookAdder;
24
+ /** Adds a `afterCreate` hook: `Model.afterCreate(fn)` or `Model.afterCreate(name, fn)`. */
25
+ afterCreate: NamedHookAdder;
26
+ /** Adds a `beforeUpdate` hook: `Model.beforeUpdate(fn)` or `Model.beforeUpdate(name, fn)`. */
27
+ beforeUpdate: NamedHookAdder;
28
+ /** Adds a `afterUpdate` hook: `Model.afterUpdate(fn)` or `Model.afterUpdate(name, fn)`. */
29
+ afterUpdate: NamedHookAdder;
30
+ /** Adds a `beforeSave` hook: `Model.beforeSave(fn)` or `Model.beforeSave(name, fn)`. */
31
+ beforeSave: NamedHookAdder;
32
+ /** Adds a `afterSave` hook: `Model.afterSave(fn)` or `Model.afterSave(name, fn)`. */
33
+ afterSave: NamedHookAdder;
34
+ /** Adds a `beforeDestroy` hook: `Model.beforeDestroy(fn)` or `Model.beforeDestroy(name, fn)`. */
35
+ beforeDestroy: NamedHookAdder;
36
+ /** Adds a `afterDestroy` hook: `Model.afterDestroy(fn)` or `Model.afterDestroy(name, fn)`. */
37
+ afterDestroy: NamedHookAdder;
38
+ /** Adds a `beforeRestore` hook: `Model.beforeRestore(fn)` or `Model.beforeRestore(name, fn)`. */
39
+ beforeRestore: NamedHookAdder;
40
+ /** Adds a `afterRestore` hook: `Model.afterRestore(fn)` or `Model.afterRestore(name, fn)`. */
41
+ afterRestore: NamedHookAdder;
42
+ /** Adds a `beforeUpsert` hook: `Model.beforeUpsert(fn)` or `Model.beforeUpsert(name, fn)`. */
43
+ beforeUpsert: NamedHookAdder;
44
+ /** Adds a `afterUpsert` hook: `Model.afterUpsert(fn)` or `Model.afterUpsert(name, fn)`. */
45
+ afterUpsert: NamedHookAdder;
46
+ /** Adds a `beforeBulkCreate` hook: `Model.beforeBulkCreate(fn)` or `Model.beforeBulkCreate(name, fn)`. */
47
+ beforeBulkCreate: NamedHookAdder;
48
+ /** Adds a `afterBulkCreate` hook: `Model.afterBulkCreate(fn)` or `Model.afterBulkCreate(name, fn)`. */
49
+ afterBulkCreate: NamedHookAdder;
50
+ /** Adds a `beforeBulkUpdate` hook: `Model.beforeBulkUpdate(fn)` or `Model.beforeBulkUpdate(name, fn)`. */
51
+ beforeBulkUpdate: NamedHookAdder;
52
+ /** Adds a `afterBulkUpdate` hook: `Model.afterBulkUpdate(fn)` or `Model.afterBulkUpdate(name, fn)`. */
53
+ afterBulkUpdate: NamedHookAdder;
54
+ /** Adds a `beforeBulkDestroy` hook: `Model.beforeBulkDestroy(fn)` or `Model.beforeBulkDestroy(name, fn)`. */
55
+ beforeBulkDestroy: NamedHookAdder;
56
+ /** Adds a `afterBulkDestroy` hook: `Model.afterBulkDestroy(fn)` or `Model.afterBulkDestroy(name, fn)`. */
57
+ afterBulkDestroy: NamedHookAdder;
58
+ /** Adds a `beforeBulkRestore` hook: `Model.beforeBulkRestore(fn)` or `Model.beforeBulkRestore(name, fn)`. */
59
+ beforeBulkRestore: NamedHookAdder;
60
+ /** Adds a `afterBulkRestore` hook: `Model.afterBulkRestore(fn)` or `Model.afterBulkRestore(name, fn)`. */
61
+ afterBulkRestore: NamedHookAdder;
62
+ /** Adds a `beforeFind` hook: `Model.beforeFind(fn)` or `Model.beforeFind(name, fn)`. */
63
+ beforeFind: NamedHookAdder;
64
+ /** Adds a `beforeFindAfterExpandIncludeAll` hook: `Model.beforeFindAfterExpandIncludeAll(fn)` or `Model.beforeFindAfterExpandIncludeAll(name, fn)`. */
65
+ beforeFindAfterExpandIncludeAll: NamedHookAdder;
66
+ /** Adds a `beforeFindAfterOptions` hook: `Model.beforeFindAfterOptions(fn)` or `Model.beforeFindAfterOptions(name, fn)`. */
67
+ beforeFindAfterOptions: NamedHookAdder;
68
+ /** Adds a `afterFind` hook: `Model.afterFind(fn)` or `Model.afterFind(name, fn)`. */
69
+ afterFind: NamedHookAdder;
70
+ /** Adds a `beforeSync` hook: runs before `Model.sync()` and before this model's turn in `sequelize.sync()`. */
71
+ beforeSync: NamedHookAdder;
72
+ /** Adds an `afterSync` hook: runs after `Model.sync()` and after this model's turn in `sequelize.sync()`. */
73
+ afterSync: NamedHookAdder;
74
+ /** Adds a `beforeCount` hook: `Model.beforeCount(fn)` or `Model.beforeCount(name, fn)`. */
75
+ beforeCount: NamedHookAdder;
76
+ /**
77
+ * Registers a hook function for a lifecycle event of this model, same as the named adders such as
78
+ * `Model.beforeCreate(fn)`. Hooks of one type run in registration order.
79
+ *
80
+ * @param this - The model class.
81
+ * @param type - Hook type, e.g. `'beforeCreate'`.
82
+ * @param nameOrFn - Hook name (to remove it later) or the hook function.
83
+ * @param fn - Hook function when a name is given.
84
+ * @returns The model class.
85
+ * @example
86
+ * ```ts
87
+ * User.addHook('beforeCreate', 'normalizeEmail', async (instance: User) => {
88
+ * instance.set('email', String(instance.get('email')).toLowerCase());
89
+ * });
90
+ * ```
91
+ * @see [Hooks guide](/guide/hooks-validation)
92
+ */
93
+ addHook<MS extends ModelStatic<AnyModel>>(this: MS, type: HookType, nameOrFn: string | HookFunction, fn?: HookFunction): MS;
94
+ /**
95
+ * Removes hooks of a type from this model: one by name or function, or all of them.
96
+ *
97
+ * @param this - The model class.
98
+ * @param type - Hook type.
99
+ * @param nameOrFn - Hook name or function; all hooks of the type when omitted.
100
+ * @returns The model class.
101
+ * @example
102
+ * ```ts
103
+ * User.removeHook('beforeCreate', 'normalizeEmail');
104
+ * ```
105
+ */
106
+ removeHook<MS extends ModelStatic<AnyModel>>(this: MS, type: HookType, nameOrFn?: string | HookFunction): MS;
107
+ /**
108
+ * Checks whether hooks of the type are registered on the model.
109
+ *
110
+ * @param type - Hook type.
111
+ * @returns True when at least one hook exists, `false` after all were removed and
112
+ * `undefined` (typed `boolean`, like Sequelize v6) for a type that never had a hook.
113
+ * @example
114
+ * ```ts
115
+ * const registered = User.hasHook('beforeCreate');
116
+ * ```
117
+ */
118
+ hasHook(type: HookType): boolean;
119
+ /**
120
+ * Alias of {@link Model.hasHook}.
121
+ *
122
+ * @param type - Hook type.
123
+ * @returns Same as {@link Model.hasHook}.
124
+ * @example
125
+ * ```ts
126
+ * const registered = User.hasHooks('afterFind');
127
+ * ```
128
+ */
129
+ hasHooks(type: HookType): boolean;
130
+ /**
131
+ * Runs the hooks of a type with the given arguments (model hooks, then Sequelize-level hooks).
132
+ *
133
+ * @param type - Hook type.
134
+ * @param args - Hook arguments.
135
+ * @returns Resolves when all hooks finished.
136
+ * @example
137
+ * ```ts
138
+ * await User.runHooks('beforeCreate', user, {});
139
+ * ```
140
+ */
141
+ runHooks(type: HookType, ...args: readonly unknown[]): Promise<void>;
142
+ } & TBase;
@@ -0,0 +1,198 @@
1
+ import { Subquery, WriteStatement } from '../../expressions/methods.ts';
2
+ import { MergeOptions } from '../merge-query-builder.ts';
3
+ import { UpdateStatementOptions, WriteStatementOptions } from '../statement-builder.ts';
4
+ import { MergeResult } from '../operations/merge-operation.ts';
5
+ import { AnyModel, Attributes, CopyFromOptions, CopyToOptions, CreationAttributes, FindOptions, InsertFromOptions, InsertOptions, ModelStatic } from '../options.ts';
6
+ import { QueryOptionsBase } from '../runtime.ts';
7
+ import { ModelConstructor } from './model-constructor.ts';
8
+ /**
9
+ * PostgreSQL extension statics of `Model`: `insert`, `insertFrom`, `merge`, `subquery`, `updateStatement`, `deleteStatement`, `insertStatement`, `findEach`, `copyFrom`, `copyTo`.
10
+ *
11
+ * @internal
12
+ */
13
+ export declare const ModelPostgres: <TBase extends ModelConstructor>(Base: TBase) => {
14
+ new (...args: any[]): {
15
+ get wasInserted(): boolean | undefined;
16
+ get oldValues(): Readonly<Record<string, unknown>> | null | undefined;
17
+ get sequelize(): import('../runtime.ts').RuntimeOwner;
18
+ };
19
+ /**
20
+ * Inserts rows with `INSERT ... ON CONFLICT` and returns the inserted or updated rows. Unlike
21
+ * `bulkCreate`, rows skipped by `DO NOTHING` or by the `DO UPDATE ... WHERE` condition are not
22
+ * returned. Each instance has `wasInserted`. PostgreSQL extension.
23
+ *
24
+ * @param this - The model class.
25
+ * @param values - Attribute values of one row or several rows.
26
+ * @param options - Insert options (`onConflict`, `fields`, `hooks`, `validate`, `overriding`, `returningOld`, query options).
27
+ * @returns Instances of the rows written by the statement.
28
+ * @see {@link Model.bulkCreate} for the Sequelize v6 variant.
29
+ * @see [Bulk writes guide](/guide/bulk-writes)
30
+ * @example
31
+ * ```ts
32
+ * const items = [{ sku: 'a-1', qty: 5 }];
33
+ * const rows = await Product.insert(items, {
34
+ * onConflict: { target: ['sku'], action: { update: { qty: literal('"Product"."qty" + EXCLUDED."qty"') } } },
35
+ * });
36
+ * const inserted = rows.filter((row) => row.wasInserted);
37
+ * ```
38
+ */
39
+ insert<M extends AnyModel>(this: ModelStatic<M>, values: CreationAttributes<M> | readonly CreationAttributes<M>[], options?: InsertOptions<Attributes<M>>): Promise<M[]>;
40
+ /**
41
+ * `INSERT INTO ... SELECT`: inserts the rows produced by a subquery. Returns the inserted (or, with
42
+ * `onConflict`, updated) rows with `wasInserted`. PostgreSQL extension.
43
+ *
44
+ * @param this - The target model class.
45
+ * @param source - Subquery from `Model.subquery()`; its columns must match `options.columns`.
46
+ * @param options - Target columns, `onConflict` and query options.
47
+ * @returns Written rows.
48
+ * @example
49
+ * ```ts
50
+ * await Task.insertFrom(
51
+ * Post.subquery({ attributes: ['id', 'title'], where: { published: false } }),
52
+ * { columns: ['postId', 'title'] },
53
+ * );
54
+ * ```
55
+ */
56
+ insertFrom<M extends AnyModel>(this: ModelStatic<M>, source: Subquery, options: InsertFromOptions<Attributes<M>>): Promise<M[]>;
57
+ /**
58
+ * `MERGE INTO ... USING ...` (PostgreSQL 15+). With `returning: true` (PostgreSQL 17+) returns the
59
+ * written rows with the action taken. PostgreSQL extension.
60
+ *
61
+ * @param this - The model class.
62
+ * @param options - Source, join condition and WHEN clauses.
63
+ * @returns Affected row count and, with `returning`, `{ action, instance }` per row.
64
+ * @throws DatabaseError when the server rejects the statement (for example on PostgreSQL older than 15).
65
+ * @example
66
+ * ```ts
67
+ * await Product.merge({
68
+ * source: [{ sku: 'a', qty: 5 }],
69
+ * on: { sku: col('source.sku') },
70
+ * whenMatched: { update: { qty: literal('"Product"."qty" + "source"."qty"') } },
71
+ * whenNotMatched: { insert: true },
72
+ * });
73
+ * ```
74
+ */
75
+ merge<M extends AnyModel>(this: ModelStatic<M>, options: MergeOptions<Attributes<M>> & QueryOptionsBase & Readonly<{
76
+ /** Return written rows (PostgreSQL 17+). */
77
+ returning?: boolean;
78
+ /** With `returning`: expose pre-statement values as `instance.oldValues` (PostgreSQL 18+). */
79
+ returningOld?: boolean;
80
+ }>): Promise<MergeResult<M>>;
81
+ /**
82
+ * Builds a SELECT that can be embedded in another query: in `where` (`[Op.in]`, `=`, `exists()`),
83
+ * in `attributes` (scalar subquery) and as a source of `insertFrom` / `merge`. Default scope and
84
+ * paranoid filter apply; values stay bound parameters of the outer statement. PostgreSQL extension.
85
+ *
86
+ * @param this - The model class the subquery selects from.
87
+ * @param options - Find options (`attributes`, `where`, `order`, `limit`, `include`, ...) and `as` (table alias).
88
+ * @returns Subquery expression.
89
+ * @example
90
+ * ```ts
91
+ * await User.findAll({ where: { id: { [Op.in]: Post.subquery({ attributes: ['userId'], where: { published: true } }) } } });
92
+ * ```
93
+ */
94
+ subquery<M extends AnyModel>(this: ModelStatic<M>, options?: FindOptions<Attributes<M>> & Readonly<{
95
+ as?: string;
96
+ }>): Subquery;
97
+ /**
98
+ * Builds an `UPDATE` for a data-modifying CTE (`with`); nothing runs until the outer query does.
99
+ * No hooks or validation run; `updatedAt` is set unless `silent`. With `returning: true` the CTE
100
+ * can be read through `source`. Queries with such a CTE always use the writer. PostgreSQL extension.
101
+ *
102
+ * @param this - The model class.
103
+ * @param values - New attribute values.
104
+ * @param options - `where`, `returning`, `silent`.
105
+ * @returns Statement for the `with` option.
106
+ * @example
107
+ * ```ts
108
+ * const bumped = Task.updateStatement({ done: true }, { where: { id: 1 }, returning: true });
109
+ * const rows = await Task.findAll({ with: { bumped }, source: 'bumped' });
110
+ * ```
111
+ */
112
+ updateStatement<M extends AnyModel>(this: ModelStatic<M>, values: Partial<Attributes<M>>, options?: UpdateStatementOptions<Attributes<M>>): WriteStatement;
113
+ /**
114
+ * Builds a `DELETE` for a data-modifying CTE (`with`). It is a real delete, also for paranoid
115
+ * models, and ignores the paranoid filter. With `returning: true` the deleted rows can be read
116
+ * through `source`, e.g. to move them to another table. PostgreSQL extension.
117
+ *
118
+ * @param this - The model class.
119
+ * @param options - `where`, `returning`.
120
+ * @returns Statement for the `with` option.
121
+ * @example
122
+ * ```ts
123
+ * const done = Task.deleteStatement({ where: { done: true }, returning: true });
124
+ * const removed = await Task.findAll({ with: { done }, source: 'done' });
125
+ * ```
126
+ */
127
+ deleteStatement<M extends AnyModel>(this: ModelStatic<M>, options?: WriteStatementOptions<Attributes<M>>): WriteStatement;
128
+ /**
129
+ * Builds an `INSERT` of attribute-keyed rows for a data-modifying CTE (`with`). Defaults and
130
+ * timestamps are filled in; no hooks or validation run. PostgreSQL extension.
131
+ *
132
+ * @param this - The model class.
133
+ * @param rows - Rows to insert (at least one).
134
+ * @param options - `returning`.
135
+ * @returns Statement for the `with` option.
136
+ * @throws Error without rows.
137
+ * @example
138
+ * ```ts
139
+ * const added = Task.insertStatement([{ title: 'write docs' }], { returning: true });
140
+ * const rows = await Task.findAll({ with: { added }, source: 'added' });
141
+ * ```
142
+ */
143
+ insertStatement<M extends AnyModel>(this: ModelStatic<M>, rows: readonly CreationAttributes<M>[], options?: Pick<WriteStatementOptions<Attributes<M>>, "returning">): WriteStatement;
144
+ /**
145
+ * Streams rows with a server-side cursor (`DECLARE ... CURSOR` + `FETCH n`), so large result sets
146
+ * are not loaded at once. Runs inside `options.transaction` or its own transaction; the cursor is
147
+ * closed when iteration ends or is stopped early. Joined includes are not supported. PostgreSQL extension.
148
+ *
149
+ * @param this - The model class.
150
+ * @param options - Find options.
151
+ * @param cursor - `batchSize` (rows per FETCH, default 100).
152
+ * @returns Async iterator of instances.
153
+ * @example
154
+ * ```ts
155
+ * for await (const user of User.findEach({ where: { active: true } }, { batchSize: 500 })) {
156
+ * console.log(user.get('email'));
157
+ * }
158
+ * ```
159
+ */
160
+ findEach<M extends AnyModel>(this: ModelStatic<M>, options?: FindOptions<Attributes<M>>, cursor?: Readonly<{
161
+ batchSize?: number;
162
+ }>): AsyncGenerator<M, void, undefined>;
163
+ /**
164
+ * Bulk-loads rows with `COPY ... FROM STDIN` (text format) — much faster than INSERT for large
165
+ * volumes. No hooks or validation run; missing values are written as `NULL`. `createdAt` /
166
+ * `updatedAt` are filled when the model has timestamps. PostgreSQL extension.
167
+ *
168
+ * @param this - The model class.
169
+ * @param rows - Rows (array, iterable or async iterable of attribute values).
170
+ * @param options - `columns` (attribute names; default: keys of the first row of an array) and query options.
171
+ * @returns Number of copied rows.
172
+ * @example
173
+ * ```ts
174
+ * const copied = await Task.copyFrom(
175
+ * [{ title: 'first' }, { title: 'second' }],
176
+ * { columns: ['title'] },
177
+ * );
178
+ * ```
179
+ */
180
+ copyFrom<M extends AnyModel>(this: ModelStatic<M>, rows: Iterable<CreationAttributes<M>> | AsyncIterable<CreationAttributes<M>>, options?: CopyFromOptions<Attributes<M>>): Promise<number>;
181
+ /**
182
+ * Streams `COPY (SELECT ...) TO STDOUT` output — the fastest way to export rows (e.g. CSV). Default
183
+ * scope, paranoid filter, `with` / `source` and includes apply. Values of the query are inlined as
184
+ * escaped literals because COPY cannot take parameters (ADR-013). Stopping early drains the rest
185
+ * before the connection is released. PostgreSQL extension.
186
+ *
187
+ * @param this - The model class.
188
+ * @param options - Find options and output format (`format`, `header`, ...).
189
+ * @returns Async iterator of raw output chunks.
190
+ * @example
191
+ * ```ts
192
+ * for await (const chunk of User.copyTo({ attributes: ['id', 'email'], format: 'csv', header: true })) {
193
+ * process.stdout.write(chunk);
194
+ * }
195
+ * ```
196
+ */
197
+ copyTo<M extends AnyModel>(this: ModelStatic<M>, options?: CopyToOptions<Attributes<M>>): AsyncGenerator<Buffer, void, undefined>;
198
+ } & TBase;
@@ -0,0 +1,36 @@
1
+ import { AnyModel, ModelStatic } from '../options.ts';
2
+ import { ModelConstructor } from './model-constructor.ts';
3
+ /**
4
+ * Schema binding static of `Model`: `schema`.
5
+ *
6
+ * @internal
7
+ */
8
+ export declare const ModelSchemaBinding: <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
+ * Returns a model class whose queries target a PostgreSQL schema, like Sequelize v6.
16
+ *
17
+ * The copy has the attributes, hooks, scopes and associations of this model as they are at
18
+ * the time of the call and keeps the scope selection of this class. Changes made to the
19
+ * original afterwards are not seen by the copy.
20
+ *
21
+ * @param this - The model class being bound.
22
+ * @param schema - Schema name.
23
+ * @param options - Separator between schema and table reported by `getTableName` (a string,
24
+ * or `{ schemaDelimiter }`); PostgreSQL always qualifies with `.` in SQL. Defaults to `.`.
25
+ * @returns Schema-bound model class (instances are instances of this model).
26
+ * @example
27
+ * ```ts
28
+ * const TenantUser = User.schema('tenant_a');
29
+ * await TenantUser.findAll(); // SELECT ... FROM "tenant_a"."users"
30
+ * TenantUser.getTableName(); // { tableName: 'users', schema: 'tenant_a', delimiter: '.' }
31
+ * ```
32
+ */
33
+ schema<MS extends ModelStatic<AnyModel>>(this: MS, schema: string, options?: string | Readonly<{
34
+ schemaDelimiter?: string;
35
+ }>): MS;
36
+ } & TBase;
@@ -0,0 +1,100 @@
1
+ import { DropOptions, SyncOptions } from '../../query-interface/schema-synchronizer.ts';
2
+ import { QueryInterface } from '../../query-interface/query-interface.ts';
3
+ import { AnyModel, ModelStatic } from '../options.ts';
4
+ import { QueryOptionsBase } from '../runtime.ts';
5
+ import { ModelConstructor } from './model-constructor.ts';
6
+ /**
7
+ * Schema statics of `Model`: `sync`, `drop`, `truncate`.
8
+ *
9
+ * @internal
10
+ */
11
+ export declare const ModelSchema: <TBase extends ModelConstructor>(Base: TBase) => {
12
+ new (...args: any[]): {
13
+ get wasInserted(): boolean | undefined;
14
+ get oldValues(): Readonly<Record<string, unknown>> | null | undefined;
15
+ get sequelize(): import('../runtime.ts').RuntimeOwner;
16
+ };
17
+ /**
18
+ * Creates the table of this model and its indexes when missing. `force: true` drops it first
19
+ * (with `CASCADE`); `alter` changes an existing table to match the model.
20
+ *
21
+ * @param this - The model class.
22
+ * @param options - `force`, `alter`, `match`, `schema` and query options.
23
+ * @returns The model class.
24
+ * @example
25
+ * ```ts
26
+ * await User.sync({ alter: true });
27
+ * ```
28
+ * @see [Schema guide](/guide/schema)
29
+ */
30
+ sync<MS extends ModelStatic<AnyModel>>(this: MS, options?: SyncOptions): Promise<MS>;
31
+ /**
32
+ * Drops the table of this model and the enum types it owns.
33
+ *
34
+ * @param options - `cascade`, `schema` and query options.
35
+ * @returns Resolves when done.
36
+ * @example
37
+ * ```ts
38
+ * await Task.drop({ cascade: true });
39
+ * ```
40
+ */
41
+ drop(options?: DropOptions): Promise<void>;
42
+ /**
43
+ * Removes all rows with `TRUNCATE`, without running hooks.
44
+ *
45
+ * @param options - `cascade`, `restartIdentity` and query options.
46
+ * @returns Resolves when done.
47
+ * @example
48
+ * ```ts
49
+ * await Task.truncate({ restartIdentity: true, cascade: true });
50
+ * ```
51
+ */
52
+ truncate(options?: QueryOptionsBase & Readonly<{
53
+ cascade?: boolean;
54
+ restartIdentity?: boolean;
55
+ }>): Promise<void>;
56
+ /** Schema API of the owning `Sequelize` instance (Sequelize v6 `Model.queryInterface`). */
57
+ get queryInterface(): QueryInterface;
58
+ /**
59
+ * Describes the table of this model: its columns, types, nullability and defaults.
60
+ *
61
+ * @param schema - Schema to read; defaults to the model's schema, then `current_schema()`.
62
+ * @param options - Query options.
63
+ * @returns Column descriptions by column name.
64
+ * @example
65
+ * ```ts
66
+ * const columns = await User.describe();
67
+ * ```
68
+ */
69
+ describe(schema?: string, options?: QueryOptionsBase): ReturnType<QueryInterface["describeTable"]>;
70
+ /**
71
+ * Drops a schema with `DROP SCHEMA` (shortcut of `queryInterface.dropSchema`, Sequelize v6 `Model.dropSchema`).
72
+ *
73
+ * @param schema - Schema name.
74
+ * @returns Resolves when done.
75
+ * @example
76
+ * ```ts
77
+ * await User.dropSchema('tenant_1');
78
+ * ```
79
+ */
80
+ dropSchema(schema: string): Promise<void>;
81
+ /**
82
+ * Removes an attribute from the model definition, e.g. a column added by an association.
83
+ *
84
+ * @param attribute - Attribute name.
85
+ * @example
86
+ * ```ts
87
+ * User.removeAttribute('legacyFlag');
88
+ * ```
89
+ */
90
+ removeAttribute(attribute: string): void;
91
+ /**
92
+ * Rebuilds the normalized attribute definitions from the model's `init` input.
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * User.refreshAttributes();
97
+ * ```
98
+ */
99
+ refreshAttributes(): void;
100
+ } & TBase;
@@ -0,0 +1,57 @@
1
+ import { AnyModel, ModelStatic } from '../options.ts';
2
+ import { ScopeDefinition, ScopeSelector } from '../scope-registry.ts';
3
+ import { ModelConstructor } from './model-constructor.ts';
4
+ /**
5
+ * Scope statics of `Model`: `scope`, `unscoped`, `addScope`.
6
+ *
7
+ * @internal
8
+ */
9
+ export declare const ModelScopes: <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
+ /**
16
+ * Creates a model class that applies the given scopes to its queries instead of the default
17
+ * scope. The original class is not changed.
18
+ *
19
+ * @param this - The model class.
20
+ * @param selectors - Scope names, `{ method: [name, ...args] }`, inline options, `'defaultScope'`, or `null`.
21
+ * @returns Scoped model class (instances are instances of this model).
22
+ * @throws Error when a named scope does not exist.
23
+ * @example
24
+ * ```ts
25
+ * await User.scope('active', { method: ['olderThan', 18] }).findAll();
26
+ * ```
27
+ * @see [Querying guide](/guide/querying)
28
+ */
29
+ scope<MS extends ModelStatic<AnyModel>>(this: MS, ...selectors: readonly (ScopeSelector | readonly ScopeSelector[])[]): MS;
30
+ /**
31
+ * Creates a model class that applies no scope at all, not even the default scope.
32
+ *
33
+ * @param this - The model class.
34
+ * @returns Unscoped model class.
35
+ * @example
36
+ * ```ts
37
+ * const everyone = await User.unscoped().findAll();
38
+ * ```
39
+ */
40
+ unscoped<MS extends ModelStatic<AnyModel>>(this: MS): MS;
41
+ /**
42
+ * Adds a named scope (or replaces the default scope with name `'defaultScope'`).
43
+ *
44
+ * @param name - Scope name.
45
+ * @param scope - Options or a function returning options.
46
+ * @param options - `override: true` replaces an existing scope.
47
+ * @throws Error when the scope exists and `override` is not set.
48
+ * @example
49
+ * ```ts
50
+ * User.addScope('active', { where: { active: true } });
51
+ * User.addScope('olderThan', (age: number) => ({ where: { age: { [Op.gt]: age } } }));
52
+ * ```
53
+ */
54
+ addScope(name: string, scope: ScopeDefinition, options?: Readonly<{
55
+ override?: boolean;
56
+ }>): void;
57
+ } & TBase;