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,39 @@
1
+ import { FromItem, SetItem, UpdateNode } from '../sql/ast.ts';
2
+ import { AttributeColumns } from './attribute-columns.ts';
3
+ import { ModelDefinition } from './model-definition.ts';
4
+ /** Options of {@link UpdateQueryBuilder.build}. */
5
+ export type UpdateBuildOptions = Readonly<{
6
+ /** Return all stored columns. */
7
+ returning?: boolean;
8
+ /** Lists at least this long compile to `= ANY($n)`. */
9
+ inAsAnyThreshold?: number;
10
+ /** Extra relations (`UPDATE ... FROM`); the table is then aliased with the model name. */
11
+ from?: readonly FromItem[];
12
+ }>;
13
+ /** Builds UPDATE statements and the SET items of `increment` / `decrement`. */
14
+ export declare class UpdateQueryBuilder {
15
+ #private;
16
+ /**
17
+ * @param columns - Attribute to column mapping.
18
+ */
19
+ constructor(columns: AttributeColumns);
20
+ /**
21
+ * Builds an UPDATE.
22
+ *
23
+ * @param definition - Model definition.
24
+ * @param set - SET items.
25
+ * @param where - Condition.
26
+ * @param options - RETURNING, `= ANY` threshold, FROM relations.
27
+ * @returns UPDATE node.
28
+ */
29
+ build(definition: ModelDefinition, set: readonly SetItem[], where: unknown, options?: UpdateBuildOptions): UpdateNode;
30
+ /**
31
+ * SET items `field = field + by` (or `- by`) for increment / decrement.
32
+ *
33
+ * @param definition - Model definition.
34
+ * @param by - Amount per attribute.
35
+ * @param sign - `1` to increment, `-1` to decrement.
36
+ * @returns SET items.
37
+ */
38
+ increment(definition: ModelDefinition, by: Readonly<Record<string, number>>, sign: 1 | -1): readonly SetItem[];
39
+ }
@@ -0,0 +1,37 @@
1
+ import { OnConflictNode } from '../sql/ast.ts';
2
+ import { AttributeColumns } from './attribute-columns.ts';
3
+ import { ModelDefinition } from './model-definition.ts';
4
+ import { BulkCreateOptions, Values } from './options.ts';
5
+ /**
6
+ * Translates the Sequelize v6 conflict rules into ON CONFLICT clauses: `bulkCreate`
7
+ * (`ignoreDuplicates`, `updateOnDuplicate`, `conflictAttributes`, `conflictWhere`) and `upsert`
8
+ * (conflict target from unique keys / indexes).
9
+ */
10
+ export declare class V6ConflictBuilder {
11
+ #private;
12
+ /**
13
+ * @param columns - Attribute to column mapping.
14
+ */
15
+ constructor(columns: AttributeColumns);
16
+ /**
17
+ * ON CONFLICT clause of Sequelize v6 `bulkCreate` options.
18
+ *
19
+ * @param definition - Model definition.
20
+ * @param options - `updateOnDuplicate`, `conflictAttributes`, `conflictWhere`, `ignoreDuplicates`.
21
+ * @returns `{ onConflict }`, or `{}` without conflict handling.
22
+ * @throws Error for an empty `updateOnDuplicate`.
23
+ */
24
+ bulk(definition: ModelDefinition, options: BulkCreateOptions): Readonly<{
25
+ onConflict?: OnConflictNode;
26
+ }>;
27
+ /**
28
+ * ON CONFLICT clause of Sequelize v6 `upsert`.
29
+ *
30
+ * @param definition - Model definition.
31
+ * @param insertValues - Inserted values.
32
+ * @param updatable - Attributes updated on conflict.
33
+ * @param conflictFields - `conflictFields` option (column names).
34
+ * @returns ON CONFLICT node.
35
+ */
36
+ upsert(definition: ModelDefinition, insertValues: Values, updatable: readonly string[], conflictFields: readonly string[] | undefined): OnConflictNode;
37
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Deep copy of attribute values for `toJSON`. Rows hold primitives, dates, arrays and plain JSON
3
+ * objects, which are copied directly; `structuredClone` is the slow general path, so it is used
4
+ * for the whole value as soon as something else shows up (functions, symbols, class instances,
5
+ * typed arrays, `Map`, cycles or an object reachable twice), which keeps its exact semantics.
6
+ */
7
+ export declare class ValueCloner {
8
+ #private;
9
+ /**
10
+ * Copies a value like `structuredClone` does.
11
+ *
12
+ * @param value - Value to copy.
13
+ * @returns The copy.
14
+ * @throws DataCloneError for values `structuredClone` rejects (functions, symbols).
15
+ */
16
+ clone<T>(value: T): T;
17
+ }
@@ -0,0 +1,12 @@
1
+ /** Writes attribute values into plain objects built from driver rows. */
2
+ export declare class ValuesWriter {
3
+ /**
4
+ * Sets a value as an own property. A column called `__proto__` stays an own property, like it
5
+ * does with `Object.fromEntries`, instead of replacing the object's prototype.
6
+ *
7
+ * @param values - Target object.
8
+ * @param name - Property name.
9
+ * @param value - Property value.
10
+ */
11
+ set(values: Record<string, unknown>, name: string, value: unknown): void;
12
+ }
@@ -0,0 +1,164 @@
1
+ import { Cast, Col, Excluded, Exists, Fn, Json, Literal, Subquery, Tuple, Where } from '../expressions/methods.ts';
2
+ import { Op } from '../expressions/op.ts';
3
+ import { AllowArray } from './types.ts';
4
+ /** Expressions accepted in place of a value (`Excluded` only inside `onConflict`). */
5
+ export type SqlValue = Literal | Fn | Col | Cast | Excluded | Subquery | Tuple;
6
+ type Comparable<V> = V | SqlValue;
7
+ /** Operators applicable to an attribute of type `V`. */
8
+ export type WhereOperators<V = unknown> = {
9
+ /** `= value`; `IS NULL` when the value is `null`. */
10
+ [Op.eq]?: Comparable<V> | null;
11
+ /** `<> value`; `IS NOT NULL` when the value is `null`. */
12
+ [Op.ne]?: Comparable<V> | null;
13
+ /** `IS value`, for `null`, `true` or `false`. */
14
+ [Op.is]?: boolean | null;
15
+ /** `IS NOT value` for `null`/booleans, otherwise negates a nested condition. */
16
+ [Op.not]?: Comparable<V> | boolean | null | WhereOperators<V>;
17
+ /** `> value`. */
18
+ [Op.gt]?: Comparable<V> | AnyAll<V>;
19
+ /** `>= value`. */
20
+ [Op.gte]?: Comparable<V> | AnyAll<V>;
21
+ /** `< value`. */
22
+ [Op.lt]?: Comparable<V> | AnyAll<V>;
23
+ /** `<= value`. */
24
+ [Op.lte]?: Comparable<V> | AnyAll<V>;
25
+ /** `IN (...)`; long lists compile to `= ANY($n)`. */
26
+ [Op.in]?: readonly V[] | Literal | Subquery;
27
+ /** `NOT IN (...)`; long lists compile to `<> ALL($n)`. */
28
+ [Op.notIn]?: readonly V[] | Literal | Subquery;
29
+ /** `BETWEEN a AND b`, value is `[a, b]`. */
30
+ [Op.between]?: readonly [Comparable<V>, Comparable<V>];
31
+ /** `NOT BETWEEN a AND b`, value is `[a, b]`. */
32
+ [Op.notBetween]?: readonly [Comparable<V>, Comparable<V>];
33
+ /** `LIKE pattern`. */
34
+ [Op.like]?: string | SqlValue | AnyAll<string>;
35
+ /** `NOT LIKE pattern`. */
36
+ [Op.notLike]?: string | SqlValue | AnyAll<string>;
37
+ /** `ILIKE pattern`. */
38
+ [Op.iLike]?: string | SqlValue | AnyAll<string>;
39
+ /** `NOT ILIKE pattern`. */
40
+ [Op.notILike]?: string | SqlValue | AnyAll<string>;
41
+ /** `LIKE 'value%'`. */
42
+ [Op.startsWith]?: string | SqlValue;
43
+ /** `LIKE '%value'`. */
44
+ [Op.endsWith]?: string | SqlValue;
45
+ /** `LIKE '%value%'`. */
46
+ [Op.substring]?: string | SqlValue;
47
+ /** `~ pattern` (POSIX regular expression). */
48
+ [Op.regexp]?: string | SqlValue;
49
+ /** `!~ pattern`. */
50
+ [Op.notRegexp]?: string | SqlValue;
51
+ /** `~* pattern` (case-insensitive regular expression). */
52
+ [Op.iRegexp]?: string | SqlValue;
53
+ /** `!~* pattern`. */
54
+ [Op.notIRegexp]?: string | SqlValue;
55
+ /** `&&` — arrays or ranges overlap. */
56
+ [Op.overlap]?: unknown;
57
+ /** `@>` — array, range or jsonb contains the value. */
58
+ [Op.contains]?: unknown;
59
+ /** `<@` — array, range or jsonb is contained by the value. */
60
+ [Op.contained]?: unknown;
61
+ /** `-|-` — ranges are adjacent. */
62
+ [Op.adjacent]?: unknown;
63
+ /** `<<` — range is strictly left of the value. */
64
+ [Op.strictLeft]?: unknown;
65
+ /** `>>` — range is strictly right of the value. */
66
+ [Op.strictRight]?: unknown;
67
+ /** `&>` — range does not extend to the left of the value. */
68
+ [Op.noExtendLeft]?: unknown;
69
+ /** `&<` — range does not extend to the right of the value. */
70
+ [Op.noExtendRight]?: unknown;
71
+ /** `@@` — tsvector matches tsquery. */
72
+ [Op.match]?: SqlValue;
73
+ /** Compares with another column, value is a column reference such as `'user.id'`. */
74
+ [Op.col]?: string;
75
+ /** Logical AND of nested conditions. */
76
+ [Op.and]?: AllowArray<Comparable<V> | WhereOperators<V>>;
77
+ /** Logical OR of nested conditions. */
78
+ [Op.or]?: AllowArray<Comparable<V> | WhereOperators<V>>;
79
+ /** `ANY (ARRAY[...])`, combined with a comparison operator. */
80
+ [Op.any]?: readonly V[] | Literal;
81
+ /** `ALL (ARRAY[...])`, combined with a comparison operator. */
82
+ [Op.all]?: readonly V[] | Literal;
83
+ /** `IS DISTINCT FROM value` (null-safe `<>`). PostgreSQL extension. */
84
+ [Op.isDistinctFrom]?: Comparable<V> | null;
85
+ /** `IS NOT DISTINCT FROM value` (null-safe `=`). PostgreSQL extension. */
86
+ [Op.isNotDistinctFrom]?: Comparable<V> | null;
87
+ /** jsonb `?` — top-level key exists. PostgreSQL extension. */
88
+ [Op.hasKey]?: string;
89
+ /** jsonb `?|` — any of the keys exist. PostgreSQL extension. */
90
+ [Op.hasAnyKeys]?: readonly string[];
91
+ /** jsonb `?&` — all of the keys exist. PostgreSQL extension. */
92
+ [Op.hasAllKeys]?: readonly string[];
93
+ /** `SIMILAR TO pattern` (SQL regular expression). PostgreSQL extension. */
94
+ [Op.similarTo]?: string | SqlValue;
95
+ /** `NOT SIMILAR TO pattern`. PostgreSQL extension. */
96
+ [Op.notSimilarTo]?: string | SqlValue;
97
+ /** jsonb `@?` — the jsonpath returns any item; the value is a jsonpath string. PostgreSQL extension. */
98
+ [Op.jsonPathExists]?: string | SqlValue;
99
+ /** `<<=` — inet/cidr subnet is contained within or equals the value. PostgreSQL extension. */
100
+ [Op.containedOrEqual]?: unknown;
101
+ /** `>>=` — inet/cidr subnet contains or equals the value. PostgreSQL extension. */
102
+ [Op.containsOrEqual]?: unknown;
103
+ /** `%` — `pg_trgm` trigram similarity above `pg_trgm.similarity_threshold`. PostgreSQL extension. */
104
+ [Op.trigramSimilar]?: string | SqlValue;
105
+ /** `<%` — `pg_trgm`: the column is similar to a part of the value. PostgreSQL extension. */
106
+ [Op.trigramWordSimilar]?: string | SqlValue;
107
+ /** `<<%` — `pg_trgm`: the column is strictly similar to a word of the value. PostgreSQL extension. */
108
+ [Op.trigramStrictWordSimilar]?: string | SqlValue;
109
+ /** `%>` — `pg_trgm`: the column has a part similar to the value. PostgreSQL extension. */
110
+ [Op.trigramHasSimilarWord]?: string | SqlValue;
111
+ /** `%>>` — `pg_trgm`: the column has a strictly similar word of the value. PostgreSQL extension. */
112
+ [Op.trigramHasSimilarStrictWord]?: string | SqlValue;
113
+ };
114
+ /** `{ [Op.any]: values }` / `{ [Op.all]: values }` used with comparison operators. */
115
+ export type AnyAll<V> = {
116
+ /** `ANY (...)`. */
117
+ [Op.any]: readonly V[] | ValuesList<V>;
118
+ } | {
119
+ /** `ALL (...)`. */
120
+ [Op.all]: readonly V[] | ValuesList<V>;
121
+ };
122
+ /** `{ [Op.values]: [...] }` — `VALUES (...)` list for `Op.any` / `Op.all`. */
123
+ export type ValuesList<V> = {
124
+ /** Values. */
125
+ [Op.values]: readonly V[];
126
+ };
127
+ /** Condition for one attribute: a value, a list of values (`IN`), operators, or an expression. */
128
+ export type WhereAttributeValue<V> = Comparable<V> | null | readonly V[] | WhereOperators<V> | (V extends object ? Readonly<Record<string, unknown>> : never);
129
+ /** Logical combinators allowed at any level of a where object. */
130
+ export type WhereLogic<T> = {
131
+ /** Logical AND of nested conditions. */
132
+ [Op.and]?: AllowArray<WhereOptions<T>>;
133
+ /** Logical OR of nested conditions. */
134
+ [Op.or]?: AllowArray<WhereOptions<T>>;
135
+ /** `IS NOT value` for `null`/booleans, otherwise negates a nested condition. */
136
+ [Op.not]?: WhereOptions<T>;
137
+ };
138
+ /** Where object keyed by attribute names, nested JSON paths (`'meta.a'`), casts (`'id::text'`) or included columns (`'$posts.title$'`). */
139
+ export type WhereAttributeHash<T> = {
140
+ [K in keyof T]?: WhereAttributeValue<T[K]>;
141
+ } & {
142
+ [key: `$${string}$` | `${string}.${string}` | `${string}::${string}`]: unknown;
143
+ } & WhereLogic<T>;
144
+ /**
145
+ * `where` option of queries (Sequelize v6 `WhereOptions`).
146
+ *
147
+ * A condition is an object keyed by attribute (equality, `IN` for arrays, or operators), a list of conditions (`OR`), or an expression (`where()`, `literal()`, `fn()`, ...). Values are always bound parameters.
148
+ *
149
+ * @see {@link Op}
150
+ *
151
+ * @example
152
+ * ```ts
153
+ * const w: WhereOptions<User> = {
154
+ * active: true,
155
+ * age: { [Op.between]: [18, 65] },
156
+ * role: ['admin', 'editor'],
157
+ * [Op.or]: [{ name: { [Op.iLike]: 'a%' } }, { email: { [Op.endsWith]: '@example.com' } }],
158
+ * '$posts.title$': 'Hello',
159
+ * };
160
+ * const rows = await User.findAll({ where: w, include: [Post] });
161
+ * ```
162
+ */
163
+ export type WhereOptions<T = Record<string, unknown>> = WhereAttributeHash<T> | readonly WhereOptions<T>[] | Where | Literal | Fn | Json | Exists;
164
+ export {};
@@ -0,0 +1,160 @@
1
+ import { IncludeOption } from '../associations/include.ts';
2
+ import { OnConflictOptions } from './on-conflict-builder.ts';
3
+ import { Values } from './options.ts';
4
+ import { QueryOptionsBase } from './runtime.ts';
5
+ import { WhereOptions } from './types.ts';
6
+ /**
7
+ * Options of `create` and instance `save`.
8
+ *
9
+ * Runs `beforeSave` / `beforeCreate` / `beforeUpdate` hooks (and their `after` counterparts) unless `hooks` is `false`.
10
+ *
11
+ * @see {@link Model.create}
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const opts: SaveOptions<User> = { fields: ['name', 'email'], validate: true, transaction };
16
+ * await user.save(opts);
17
+ * ```
18
+ */
19
+ export type SaveOptions<T = Values> = QueryOptionsBase & Readonly<{
20
+ /** Attributes to save; others are ignored. Default: all changed attributes. */
21
+ fields?: readonly (keyof T & string)[];
22
+ /** Do not update `updatedAt`.
23
+ * @defaultValue false */
24
+ silent?: boolean;
25
+ /** Return all columns after insert/update; PostgreSQL always uses `RETURNING`, so this is accepted for v6 compatibility.
26
+ * @defaultValue true */
27
+ returning?: boolean;
28
+ /** Run lifecycle hooks.
29
+ * @defaultValue true */
30
+ hooks?: boolean;
31
+ /** Run validations.
32
+ * @defaultValue true (`false` for `bulkCreate`) */
33
+ validate?: boolean;
34
+ /** `OVERRIDING SYSTEM VALUE` / `OVERRIDING USER VALUE` for identity columns. PostgreSQL extension. */
35
+ overriding?: 'system' | 'user';
36
+ }>;
37
+ /**
38
+ * Options of `create`.
39
+ *
40
+ * Extends {@link SaveOptions}.
41
+ *
42
+ * @see {@link Model.create}
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * const post = await Post.create(
47
+ * { title: 'Hello', author: { name: 'Ann' } },
48
+ * { include: [{ association: 'author' }], transaction },
49
+ * );
50
+ * ```
51
+ */
52
+ export type CreateOptions<T = Values> = SaveOptions<T> & Readonly<{
53
+ /** Advanced `ON CONFLICT` handling. PostgreSQL extension. */
54
+ onConflict?: OnConflictOptions<T>;
55
+ /** Create associated rows from nested values (Sequelize v6). */
56
+ include?: IncludeOption;
57
+ }>;
58
+ /**
59
+ * Options of `upsert`.
60
+ *
61
+ * Extends {@link SaveOptions}. With `onConflict` the result of `upsert` becomes `[instance, created]`.
62
+ *
63
+ * @see {@link Model.upsert}
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * const [user] = await User.upsert(
68
+ * { email: 'a@example.com', name: 'Ann' },
69
+ * { conflictFields: ['email'] },
70
+ * );
71
+ * ```
72
+ */
73
+ export type UpsertOptions<T = Values> = SaveOptions<T> & Readonly<{
74
+ /** Conflict target columns. Default: unique key containing a given attribute, else the primary key. */
75
+ conflictFields?: readonly string[];
76
+ /** Advanced `ON CONFLICT` handling; the result becomes `[instance, created]`. PostgreSQL extension. */
77
+ onConflict?: OnConflictOptions<T>;
78
+ /** `OVERRIDING SYSTEM VALUE` / `OVERRIDING USER VALUE` for identity columns. */
79
+ overriding?: 'system' | 'user';
80
+ }>;
81
+ /**
82
+ * Options of `Model.insert`. PostgreSQL extension.
83
+ *
84
+ * Rows are inserted with a single `INSERT` and no per-row save hooks; only the bulk-create hooks run.
85
+ *
86
+ * @see {@link Model.insert}
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * const opts: InsertOptions<User> = {
91
+ * onConflict: { target: ['email'], action: 'nothing' },
92
+ * hooks: false,
93
+ * };
94
+ * const rows = await User.insert([{ email: 'a@example.com' }], opts);
95
+ * ```
96
+ */
97
+ export type InsertOptions<T = Values> = QueryOptionsBase & Readonly<{
98
+ /** Attributes to insert; others are ignored. Default: all given attributes. */
99
+ fields?: readonly (keyof T & string)[];
100
+ /** Advanced `ON CONFLICT` handling. */
101
+ onConflict?: OnConflictOptions<T>;
102
+ /** Run `beforeBulkCreate` / `afterBulkCreate` hooks.
103
+ * @defaultValue true */
104
+ hooks?: boolean;
105
+ /** Validate rows before inserting.
106
+ * @defaultValue false */
107
+ validate?: boolean;
108
+ /** `OVERRIDING SYSTEM VALUE` / `OVERRIDING USER VALUE` for identity columns. */
109
+ overriding?: 'system' | 'user';
110
+ /** Return the pre-statement row values as `instance.oldValues`. PostgreSQL 18+. */
111
+ returningOld?: boolean;
112
+ }>;
113
+ /**
114
+ * Options of `Model.insertFrom`, which inserts the result of a subquery (`INSERT ... SELECT`). PostgreSQL extension.
115
+ *
116
+ * @see {@link Model.insertFrom}
117
+ *
118
+ * @example
119
+ * ```ts
120
+ * const opts: InsertFromOptions<Task> = {
121
+ * columns: ['title', 'projectId'],
122
+ * onConflict: { action: 'nothing' },
123
+ * };
124
+ * ```
125
+ */
126
+ export type InsertFromOptions<T = Values> = QueryOptionsBase & Readonly<{
127
+ /** Target attributes, in the order of the subquery columns. */
128
+ columns: readonly (keyof T & string)[];
129
+ /** Advanced `ON CONFLICT` handling. */
130
+ onConflict?: OnConflictOptions<T>;
131
+ /** Return the pre-statement row values as `instance.oldValues`. PostgreSQL 18+. */
132
+ returningOld?: boolean;
133
+ }>;
134
+ /**
135
+ * Options of `increment` and `decrement`.
136
+ *
137
+ * Runs one `UPDATE ... SET col = col + n` and updates `updatedAt` unless `silent`.
138
+ *
139
+ * @see {@link Model.increment}
140
+ *
141
+ * @example
142
+ * ```ts
143
+ * await Product.increment('stock', { by: 5, where: { id: 1 } });
144
+ * const opts: IncrementOptions<Product> = { by: 2, silent: true, transaction };
145
+ * const product = await Product.findByPk(1);
146
+ * await product!.decrement('stock', opts);
147
+ * ```
148
+ */
149
+ export type IncrementOptions<T = Values> = QueryOptionsBase & Readonly<{
150
+ /** Rows to change; required for the static form, ignored on instances. */
151
+ where?: WhereOptions<T>;
152
+ /** Amount to add (`increment`) or subtract (`decrement`).
153
+ * @defaultValue 1 */
154
+ by?: number;
155
+ /** Do not update `updatedAt`.
156
+ * @defaultValue false */
157
+ silent?: boolean;
158
+ }>;
159
+ /** Attribute name(s) or a map of attribute name to amount for `increment` / `decrement`. */
160
+ export type AttributeAmounts<T> = (keyof T & string) | readonly (keyof T & string)[] | Partial<Record<keyof T & string, number>>;
@@ -0,0 +1,56 @@
1
+ import { ModelDefinition } from './model-definition.ts';
2
+ import { ModelRegistry } from './model-registry.ts';
3
+ import { AnyModel, ModelStatic, Values } from './options.ts';
4
+ import { ReturningOld } from './returning-old.ts';
5
+ import { RowMapper } from './row-mapper.ts';
6
+ type Row = Readonly<Record<string, unknown>>;
7
+ /**
8
+ * Turns rows returned by writes into instances: strips the marker columns (inserted flag, merge
9
+ * action, pre-statement values), records `wasInserted` / `oldValues`, and aligns `DO NOTHING`
10
+ * results with the input rows.
11
+ */
12
+ export declare class WrittenRows {
13
+ #private;
14
+ /**
15
+ * @param registry - Model definitions.
16
+ * @param rows - Builds instances from rows.
17
+ * @param returningOld - Reads pre-statement values.
18
+ */
19
+ constructor(registry: ModelRegistry, rows: RowMapper, returningOld: ReturningOld);
20
+ /**
21
+ * Row without the marker columns added to RETURNING.
22
+ *
23
+ * @param row - Returned row.
24
+ * @returns Row of model columns.
25
+ */
26
+ withoutMarkers(row: Row): Row;
27
+ /**
28
+ * Instance of a returned row; with `old`, its pre-statement values become `oldValues`.
29
+ *
30
+ * @param model - Model class.
31
+ * @param row - Returned row.
32
+ * @param old - Whether RETURNING included the pre-statement row.
33
+ * @returns Instance.
34
+ */
35
+ instance<M extends AnyModel>(model: ModelStatic<M>, row: Row, old: boolean): M;
36
+ /**
37
+ * Instance of a row returned by an INSERT with the inserted flag column; sets `wasInserted`.
38
+ *
39
+ * @param model - Model class.
40
+ * @param row - Returned row.
41
+ * @param old - Whether RETURNING included the pre-statement row.
42
+ * @returns Instance.
43
+ */
44
+ inserted<M extends AnyModel>(model: ModelStatic<M>, row: Row, old: boolean): M;
45
+ /**
46
+ * With `ON CONFLICT DO NOTHING` RETURNING has rows only for inserted records (in VALUES order).
47
+ * Aligns them with the input rows; skipped records get `undefined`.
48
+ *
49
+ * @param definition - Model definition.
50
+ * @param inputs - Inserted values.
51
+ * @param returned - Returned rows.
52
+ * @returns One returned row (or `undefined`) per input.
53
+ */
54
+ aligned(definition: ModelDefinition, inputs: readonly Values[], returned: readonly Row[]): readonly (Row | undefined)[];
55
+ }
56
+ export {};
@@ -0,0 +1,8 @@
1
+ /** Reads the version of the installed package (`Sequelize.version`). */
2
+ export declare class PackageVersion {
3
+ #private;
4
+ /**
5
+ * @returns The `version` field of postgrelize's `package.json`.
6
+ */
7
+ read(): string;
8
+ }
@@ -0,0 +1,93 @@
1
+ import { QueryResult } from '../connection/connection-manager.ts';
2
+ import { AnyModel, ModelStatic } from '../model/options.ts';
3
+ import { RowMapper } from '../model/row-mapper.ts';
4
+ import { QueryOptionsBase } from '../model/runtime.ts';
5
+ import { BindParameters, Replacements } from './raw-query.ts';
6
+ /** Query types of `sequelize.query` (Sequelize v6 `QueryTypes`). */
7
+ export declare const QueryTypes: {
8
+ /** Returns rows. */
9
+ readonly SELECT: "SELECT";
10
+ /** Returns `[rows, rowCount]`. */
11
+ readonly INSERT: "INSERT";
12
+ /** Returns `[rows, rowCount]`. */
13
+ readonly UPDATE: "UPDATE";
14
+ /** Returns `[undefined, null]` like v6 on PostgreSQL (the statement runs; its rows are not returned). */
15
+ readonly UPSERT: "UPSERT";
16
+ /** Returns the rows of the statement (`[]` without `RETURNING`). */
17
+ readonly DELETE: "DELETE";
18
+ /** Returns the number of affected rows. */
19
+ readonly BULKUPDATE: "BULKUPDATE";
20
+ /** Returns the number of affected rows. */
21
+ readonly BULKDELETE: "BULKDELETE";
22
+ /** Returns `[rows, result]` (default). */
23
+ readonly RAW: "RAW";
24
+ /** Returns `[rows, result]`. */
25
+ readonly SHOWTABLES: "SHOWTABLES";
26
+ /** Returns `[rows, result]`. */
27
+ readonly DESCRIBE: "DESCRIBE";
28
+ /** Returns `[rows, result]`. */
29
+ readonly VERSION: "VERSION";
30
+ /** Returns `[rows, result]`. */
31
+ readonly FOREIGNKEYS: "FOREIGNKEYS";
32
+ /** Returns `[rows, result]`. */
33
+ readonly SHOWINDEXES: "SHOWINDEXES";
34
+ /** Returns `[rows, result]`. */
35
+ readonly SHOWCONSTRAINTS: "SHOWCONSTRAINTS";
36
+ };
37
+ /** One of {@link QueryTypes}. */
38
+ export type QueryType = (typeof QueryTypes)[keyof typeof QueryTypes];
39
+ /**
40
+ * Options of `sequelize.query`, in addition to the common query options such as `transaction` and `logging`.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * const rows = await sequelize.query('SELECT * FROM users WHERE id = :id', {
45
+ * type: QueryTypes.SELECT,
46
+ * replacements: { id: 1 },
47
+ * model: User,
48
+ * mapToModel: true,
49
+ * });
50
+ * ```
51
+ */
52
+ export type QueryOptions = QueryOptionsBase & Readonly<{
53
+ /** Shapes the result; default `RAW`. */
54
+ type?: QueryType;
55
+ /** Values for `?` / `:name` placeholders; bound as parameters. */
56
+ replacements?: Replacements;
57
+ /** Values for `$1` / `$name` placeholders. */
58
+ bind?: BindParameters;
59
+ /** Return only the first row (or `null`). */
60
+ plain?: boolean;
61
+ /** Build instances of this model from SELECT rows. */
62
+ model?: ModelStatic<AnyModel>;
63
+ /** Map column names to attribute names of `model`. */
64
+ mapToModel?: boolean;
65
+ /** Return plain rows even with `model`. */
66
+ raw?: boolean;
67
+ }>;
68
+ /**
69
+ * Shapes the result of `sequelize.query` like Sequelize v6: rows (optionally as model instances),
70
+ * `[rows, rowCount]`, a row count or `[rows, result]` depending on the query type.
71
+ */
72
+ export declare class QueryResultShaper {
73
+ #private;
74
+ /**
75
+ * @param rows - Maps columns to attributes for `mapToModel`.
76
+ */
77
+ constructor(rows: RowMapper);
78
+ /**
79
+ * Query type in effect: the `type` option, or `SELECT` with `model` / `plain`.
80
+ *
81
+ * @param options - Query options.
82
+ * @returns Query type, or `undefined` for RAW.
83
+ */
84
+ type(options: QueryOptions): QueryType | undefined;
85
+ /**
86
+ * Shapes a driver result according to the query options.
87
+ *
88
+ * @param result - Driver result.
89
+ * @param options - Query options.
90
+ * @returns Shaped result.
91
+ */
92
+ shape(result: QueryResult, options: QueryOptions): unknown;
93
+ }
@@ -0,0 +1,27 @@
1
+ import { CompiledQuery } from '../sql/compile.ts';
2
+ /** Values substituted into raw SQL: `?` for arrays, `:name` for objects. */
3
+ export type Replacements = readonly unknown[] | Readonly<Record<string, unknown>>;
4
+ /** Bind parameters for raw SQL: `$1` for arrays, `$name` for objects. */
5
+ export type BindParameters = readonly unknown[] | Readonly<Record<string, unknown>>;
6
+ /**
7
+ * Converts raw SQL with Sequelize v6 `replacements` and `bind` into a parameterized query.
8
+ * Replacement values are bound as parameters instead of being inlined; string literals,
9
+ * quoted identifiers, comments, dollar-quoted strings and `::` casts are left untouched.
10
+ *
11
+ * @internal
12
+ */
13
+ export declare class RawQuery {
14
+ #private;
15
+ /**
16
+ * Prepares raw SQL for execution.
17
+ *
18
+ * @param sql - SQL text with `?` / `:name` replacements and `$1` / `$name` bind parameters.
19
+ * @param options - Replacements and bind parameters.
20
+ * @returns Query text with `$n` placeholders and its values.
21
+ * @throws Error for a missing replacement or bind parameter.
22
+ */
23
+ prepare(sql: string, options?: Readonly<{
24
+ replacements?: Replacements;
25
+ bind?: BindParameters;
26
+ }>): CompiledQuery;
27
+ }
@@ -0,0 +1,40 @@
1
+ import { TableName } from '../ddl/sql-literal.ts';
2
+ import { ModelDefinition } from '../model/model-definition.ts';
3
+ import { QueryOptionsBase } from '../model/runtime.ts';
4
+ import { ModelTables } from './model-tables.ts';
5
+ import { QueryInterface } from './query-interface.ts';
6
+ /**
7
+ * Diffs a model against its existing table for `sync({ alter })`: added, changed, referencing and
8
+ * dropped columns, in that order.
9
+ *
10
+ * @internal
11
+ */
12
+ export declare class AlterPlanner {
13
+ #private;
14
+ /**
15
+ * @param queryInterface - Query interface used to inspect the table.
16
+ * @param tables - Model table DDL.
17
+ */
18
+ constructor(queryInterface: QueryInterface, tables: ModelTables);
19
+ /**
20
+ * Statements that bring the existing table in line with the model.
21
+ *
22
+ * @param definition - Model definition.
23
+ * @param alter - `alter` option; `{ drop: false }` keeps extra columns.
24
+ * @param options - `schema` and query options.
25
+ * @returns Statements.
26
+ */
27
+ statements(definition: ModelDefinition, alter: boolean | Readonly<{
28
+ drop?: boolean;
29
+ }>, options: QueryOptionsBase & Readonly<{
30
+ schema?: string;
31
+ }>): Promise<readonly string[]>;
32
+ /**
33
+ * Columns of the table that already have a foreign key.
34
+ *
35
+ * @param table - Table name or `{ tableName, schema }`.
36
+ * @param options - Query options.
37
+ * @returns Column names.
38
+ */
39
+ foreignKeyColumns(table: TableName, options: QueryOptionsBase): Promise<ReadonlySet<string>>;
40
+ }