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,37 @@
1
+ import { ExprNode } from '../sql/ast.ts';
2
+ import { AttributeColumns } from './attribute-columns.ts';
3
+ import { ModelDefinition } from './model-definition.ts';
4
+ import { SelectOptions } from './select-options.ts';
5
+ import { SelectTargets } from './select-targets.ts';
6
+ /** Selected columns of `count()` and `aggregate()`: the grouped columns and the aggregate. */
7
+ export declare class SelectAggregates {
8
+ #private;
9
+ /**
10
+ * @param columns - Attribute to column mapping.
11
+ * @param targets - Converts attribute names and expressions.
12
+ */
13
+ constructor(columns: AttributeColumns, targets: SelectTargets);
14
+ /**
15
+ * Columns of `SELECT count(...) AS "count"`.
16
+ *
17
+ * @param definition - Model definition.
18
+ * @param options - Select options with `col` / `distinct`.
19
+ * @returns Group columns followed by the count.
20
+ */
21
+ count(definition: ModelDefinition, options: SelectOptions & Readonly<{
22
+ col?: string;
23
+ distinct?: boolean;
24
+ }>): readonly ExprNode[];
25
+ /**
26
+ * Columns of `SELECT fn(field) AS "fn"`.
27
+ *
28
+ * @param definition - Model definition.
29
+ * @param field - Attribute name or `'*'`.
30
+ * @param aggregateFunction - Aggregate function name.
31
+ * @param options - Select options with `distinct`.
32
+ * @returns Group columns followed by the aggregate.
33
+ */
34
+ aggregate(definition: ModelDefinition, field: string, aggregateFunction: string, options: SelectOptions & Readonly<{
35
+ distinct?: boolean;
36
+ }>): readonly ExprNode[];
37
+ }
@@ -0,0 +1,13 @@
1
+ import { LockNode } from '../sql/ast.ts';
2
+ import { SelectOptions } from './select-options.ts';
3
+ /** Resolves the `lock`, `skipLocked` and `noWait` options into a row-lock clause. */
4
+ export declare class SelectLock {
5
+ /**
6
+ * Row-lock clause of the options.
7
+ *
8
+ * @param options - Select options.
9
+ * @returns Lock node, or `undefined` without a lock.
10
+ * @throws Error when `skipLocked` and `noWait` are both set.
11
+ */
12
+ of(options: SelectOptions): LockNode | undefined;
13
+ }
@@ -0,0 +1,92 @@
1
+ import { LateralKeys } from './lateral-keys-builder.ts';
2
+ import { TableSampleOptions } from './source-options.ts';
3
+ import { FromItem, LockNode, QueryNode, WithClause } from '../sql/ast.ts';
4
+ /**
5
+ * Selected attributes: a list of names or `[expression, alias]` pairs, or an `{ include, exclude }` spec.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * const list: FindAttributeOptions = ['id', 'name', [fn('count', col('id')), 'total']];
10
+ * const spec: FindAttributeOptions = { include: [[literal('1'), 'one']], exclude: ['password'] };
11
+ * ```
12
+ */
13
+ export type FindAttributeOptions = readonly (string | readonly [unknown, string])[] | AttributeSpec;
14
+ /** The `attributes: { include, exclude }` form: all attributes plus/minus some. */
15
+ export type AttributeSpec = Readonly<{
16
+ /** Extra columns added to all attributes. */
17
+ include?: readonly (string | readonly [unknown, string])[];
18
+ /** Attributes left out. */
19
+ exclude?: readonly string[];
20
+ }>;
21
+ /** One `order` item: attribute name, `[attribute, direction]`, `[expression, direction]` or an expression. */
22
+ export type OrderItem = string | unknown | readonly [unknown, string?];
23
+ /** `order` option of finders: a single expression or a list of {@link OrderItem}. */
24
+ export type Order = unknown | readonly OrderItem[];
25
+ /** Model whose rows are locked by `lock.of`. */
26
+ export type LockTarget = Readonly<{
27
+ /** Model name, which is the table alias in the query. */
28
+ name: string;
29
+ }>;
30
+ /** `lock` option of finders: `true` (`FOR UPDATE`), a lock strength, or `{ level, of }`. */
31
+ export type LockOption = boolean | LockNode['strength'] | Readonly<{
32
+ /** Lock strength. */
33
+ level: LockNode['strength'];
34
+ /** Model whose rows are locked (`FOR UPDATE OF`). */
35
+ of?: LockTarget;
36
+ }>;
37
+ /**
38
+ * Options that shape a SELECT statement, shared by finders and `copyTo`.
39
+ *
40
+ * Finders extend this with flags such as `raw` and `include` ({@link FindOptions}).
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * const opts: SelectOptions = {
45
+ * attributes: ['status', [fn('count', col('id')), 'n']],
46
+ * group: ['status'],
47
+ * having: { n: { [Op.gt]: 1 } },
48
+ * order: [['status', 'DESC']],
49
+ * limit: 20,
50
+ * offset: 40,
51
+ * };
52
+ * ```
53
+ */
54
+ export type SelectOptions = Readonly<{
55
+ /** Filter; finders type this as {@link WhereOptions}. */
56
+ where?: unknown;
57
+ /** Selected attributes. All attributes when omitted. */
58
+ attributes?: FindAttributeOptions;
59
+ /** Sort order: attribute names, `[attribute, 'ASC' | 'DESC']` pairs or expressions. */
60
+ order?: Order;
61
+ /** `GROUP BY` attributes or expressions. */
62
+ group?: unknown;
63
+ /** `HAVING` condition. */
64
+ having?: unknown;
65
+ /** Maximum number of rows; `null` or `undefined` for no limit. */
66
+ limit?: number | null;
67
+ /** Number of rows to skip; `null` or `undefined` to skip none. */
68
+ offset?: number | null;
69
+ /** Row lock (`FOR UPDATE` etc.); requires a transaction. */
70
+ lock?: LockOption;
71
+ /** Add `SKIP LOCKED` to the row lock; only with `lock`. */
72
+ skipLocked?: boolean;
73
+ /** Add `NOWAIT` to the row lock so the query fails instead of waiting; only with `lock`. PostgreSQL extension. */
74
+ noWait?: boolean;
75
+ /** `SELECT DISTINCT ON (...)`: attributes or expressions. PostgreSQL extension. */
76
+ distinctOn?: readonly unknown[];
77
+ /**
78
+ * `FETCH FIRST limit ROWS WITH TIES` instead of `LIMIT`: also returns the rows that tie with the
79
+ * last one on the `order` columns. Needs `limit` and `order`. PostgreSQL extension.
80
+ */
81
+ withTies?: boolean;
82
+ /** Read only a random sample of the model table (`TABLESAMPLE`). PostgreSQL extension. */
83
+ sample?: TableSampleOptions;
84
+ /** @internal Top-N-per-parent read of a lateral include. */
85
+ lateralKeys?: LateralKeys;
86
+ /** @internal Resolved `source` subquery: rows come from it instead of the model table. */
87
+ fromQuery?: QueryNode;
88
+ /** @internal Resolved `WITH` clause. */
89
+ withClause?: WithClause;
90
+ /** @internal Resolved extra FROM relations. */
91
+ extraFrom?: readonly FromItem[];
92
+ }>;
@@ -0,0 +1,73 @@
1
+ import { ExprNode, OrderNode, SelectNode } from '../sql/ast.ts';
2
+ import { WhereCompiler } from '../where/where.ts';
3
+ import { AttributeColumns } from './attribute-columns.ts';
4
+ import { ModelDefinition } from './model-definition.ts';
5
+ import { FindAttributeOptions, SelectOptions } from './select-options.ts';
6
+ export type { AttributeSpec, FindAttributeOptions, LockOption, LockTarget, Order, OrderItem, SelectOptions, } from './select-options.ts';
7
+ /**
8
+ * Builds SELECT statements of finders: columns from `attributes`, `where` / `having`, `order`,
9
+ * `group`, `distinctOn`, `limit` / `offset`, row locks, and the `count()` / `aggregate()` forms.
10
+ */
11
+ export declare class SelectQueryBuilder {
12
+ #private;
13
+ /**
14
+ * @param columns - Attribute to column mapping.
15
+ */
16
+ constructor(columns: AttributeColumns);
17
+ /**
18
+ * Builds a SELECT for `findAll`-style options.
19
+ *
20
+ * @param definition - Model definition.
21
+ * @param options - Select options.
22
+ * @param inAsAnyThreshold - Lists at least this long compile to `= ANY($n)`.
23
+ * @param columnsOverride - Selected columns instead of `attributes`.
24
+ * @param aliasOverride - Table alias instead of the model name.
25
+ * @returns SELECT node.
26
+ */
27
+ build(definition: ModelDefinition, options: SelectOptions, inAsAnyThreshold?: number, columnsOverride?: readonly ExprNode[], aliasOverride?: string): SelectNode;
28
+ /**
29
+ * Builds `SELECT count(...) AS "count"` for `count()`.
30
+ *
31
+ * @param definition - Model definition.
32
+ * @param options - Select options with `col` / `distinct`.
33
+ * @param inAsAnyThreshold - Lists at least this long compile to `= ANY($n)`.
34
+ * @returns SELECT node.
35
+ */
36
+ count(definition: ModelDefinition, options: SelectOptions & Readonly<{
37
+ col?: string;
38
+ distinct?: boolean;
39
+ }>, inAsAnyThreshold?: number): SelectNode;
40
+ /**
41
+ * Builds `SELECT fn(field) AS "fn"` for `aggregate()`.
42
+ *
43
+ * @param definition - Model definition.
44
+ * @param field - Attribute name or `'*'`.
45
+ * @param aggregateFunction - Aggregate function name.
46
+ * @param options - Select options with `distinct`.
47
+ * @param inAsAnyThreshold - Lists at least this long compile to `= ANY($n)`.
48
+ * @returns SELECT node.
49
+ */
50
+ aggregate(definition: ModelDefinition, field: string, aggregateFunction: string, options: SelectOptions & Readonly<{
51
+ distinct?: boolean;
52
+ }>, inAsAnyThreshold?: number): SelectNode;
53
+ /**
54
+ * Selected columns for the `attributes` option.
55
+ *
56
+ * @param definition - Model definition.
57
+ * @param alias - Table alias.
58
+ * @param ctx - Where compiler of the model.
59
+ * @param attributes - `attributes` option.
60
+ * @returns Column expressions.
61
+ */
62
+ columns(definition: ModelDefinition, alias: string, ctx: WhereCompiler, attributes: FindAttributeOptions | undefined): readonly ExprNode[];
63
+ /**
64
+ * One `order` item.
65
+ *
66
+ * @param definition - Model definition.
67
+ * @param alias - Table alias.
68
+ * @param ctx - Where compiler of the model.
69
+ * @param item - Attribute name, `[target, direction]` or expression.
70
+ * @returns Order node.
71
+ */
72
+ orderItem(definition: ModelDefinition, alias: string, ctx: WhereCompiler, item: unknown): OrderNode;
73
+ }
@@ -0,0 +1,77 @@
1
+ import { ExprNode, OrderNode } from '../sql/ast.ts';
2
+ import { WhereCompiler } from '../where/where.ts';
3
+ import { AttributeColumns } from './attribute-columns.ts';
4
+ import { ModelDefinition } from './model-definition.ts';
5
+ import { FindAttributeOptions, Order } from './select-options.ts';
6
+ /**
7
+ * Converts the attribute and expression lists of finders into SELECT expressions: `attributes`,
8
+ * `order`, `group` and `distinctOn` items, including `'jsonAttr.a.b'` paths.
9
+ */
10
+ export declare class SelectTargets {
11
+ #private;
12
+ /**
13
+ * @param columns - Attribute to column mapping.
14
+ */
15
+ constructor(columns: AttributeColumns);
16
+ /**
17
+ * Selected columns for the `attributes` option.
18
+ *
19
+ * @param definition - Model definition.
20
+ * @param alias - Table alias.
21
+ * @param ctx - Where compiler of the model.
22
+ * @param attributes - `attributes` option.
23
+ * @returns Column expressions.
24
+ */
25
+ columns(definition: ModelDefinition, alias: string, ctx: WhereCompiler, attributes: FindAttributeOptions | undefined): readonly ExprNode[];
26
+ /**
27
+ * One `order` item.
28
+ *
29
+ * @param definition - Model definition.
30
+ * @param alias - Table alias.
31
+ * @param ctx - Where compiler of the model.
32
+ * @param item - Attribute name, `[target, direction]` or expression.
33
+ * @returns Order node.
34
+ */
35
+ orderItem(definition: ModelDefinition, alias: string, ctx: WhereCompiler, item: unknown): OrderNode;
36
+ /**
37
+ * Expression of an attribute name, `'jsonAttr.a.b'` path, `'table.column'` or expression.
38
+ *
39
+ * @param definition - Model definition.
40
+ * @param alias - Table alias.
41
+ * @param ctx - Where compiler of the model.
42
+ * @param target - Attribute name or expression.
43
+ * @returns Expression.
44
+ */
45
+ target(definition: ModelDefinition, alias: string, ctx: WhereCompiler, target: unknown): ExprNode;
46
+ /**
47
+ * `ORDER BY` items of the `order` option.
48
+ *
49
+ * @param definition - Model definition.
50
+ * @param alias - Table alias.
51
+ * @param ctx - Where compiler of the model.
52
+ * @param order - `order` option.
53
+ * @returns Order nodes.
54
+ * @throws Error for an order that is neither a list nor an expression.
55
+ */
56
+ orderBy(definition: ModelDefinition, alias: string, ctx: WhereCompiler, order: Order): readonly OrderNode[];
57
+ /**
58
+ * Expressions of a `group` or `distinctOn` option (one item or a list).
59
+ *
60
+ * @param definition - Model definition.
61
+ * @param alias - Table alias.
62
+ * @param ctx - Where compiler of the model.
63
+ * @param items - Attribute names or expressions.
64
+ * @returns Expressions.
65
+ */
66
+ list(definition: ModelDefinition, alias: string, ctx: WhereCompiler, items: unknown): readonly ExprNode[];
67
+ /**
68
+ * Expressions of the `distinctOn` option.
69
+ *
70
+ * @param definition - Model definition.
71
+ * @param alias - Table alias.
72
+ * @param ctx - Where compiler of the model.
73
+ * @param items - Attribute names or expressions.
74
+ * @returns Expressions.
75
+ */
76
+ distinctOn(definition: ModelDefinition, alias: string, ctx: WhereCompiler, items: readonly unknown[] | undefined): readonly ExprNode[];
77
+ }
@@ -0,0 +1,23 @@
1
+ import { FromItem } from '../sql/ast.ts';
2
+ import { AttributeColumns } from './attribute-columns.ts';
3
+ import { ModelRegistry } from './model-registry.ts';
4
+ type Plain = Readonly<Record<string, unknown>>;
5
+ /** Converts the object forms of a `from` entry (`values`, `function`, `jsonTable`, `lateral`, `model` + `sample`). */
6
+ export declare class SourceOptionBuilder {
7
+ #private;
8
+ /**
9
+ * @param registry - Model definitions.
10
+ * @param columns - Table references of models.
11
+ */
12
+ constructor(registry: ModelRegistry, columns: AttributeColumns);
13
+ /**
14
+ * Builds the FROM item of an object-form source.
15
+ *
16
+ * @param alias - Alias of the relation.
17
+ * @param source - Source option.
18
+ * @returns FROM item.
19
+ * @throws Error for inconsistent options.
20
+ */
21
+ build(alias: string, source: Plain): FromItem;
22
+ }
23
+ export {};
@@ -0,0 +1,108 @@
1
+ import { Subquery } from '../expressions/methods.ts';
2
+ import { AnyModel, ModelStatic } from './options.ts';
3
+ /**
4
+ * `TABLESAMPLE` of a table. PostgreSQL extension.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * const sample: TableSampleOptions = { method: 'BERNOULLI', percent: 10, seed: 42 };
9
+ * const rows = await Post.findAll({ sample });
10
+ * ```
11
+ */
12
+ export type TableSampleOptions = Readonly<{
13
+ /** Sampling method: `BERNOULLI` (row by row) or `SYSTEM` (block by block, faster). */
14
+ method: 'BERNOULLI' | 'SYSTEM';
15
+ /** Percentage of the table to read, from 0 to 100. Bound as a parameter. */
16
+ percent: number;
17
+ /** `REPEATABLE` seed: the same seed returns the same sample while the data does not change. */
18
+ seed?: number;
19
+ }>;
20
+ /**
21
+ * One column of a {@link JsonTableOptions}.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * const columns: JsonTableColumnOptions[] = [
26
+ * { name: 'position', ordinality: true },
27
+ * { name: 'qty', type: 'integer', path: '$.quantity' },
28
+ * { name: 'hasNote', exists: true, path: '$.note' },
29
+ * ];
30
+ * ```
31
+ */
32
+ export type JsonTableColumnOptions = Readonly<{
33
+ /** Output column name. */
34
+ name: string;
35
+ /** Number the rows (`FOR ORDINALITY`); no `type` or `path`. */
36
+ ordinality?: boolean;
37
+ /** Column type: one of the cast types (`integer`, `text`, `jsonb`, `timestamptz`, …). */
38
+ type?: string;
39
+ /** jsonpath of the value, relative to the row; defaults to the column name. */
40
+ path?: string;
41
+ /** Return whether the path matches (`EXISTS`); `type` defaults to `boolean`. */
42
+ exists?: boolean;
43
+ }>;
44
+ /**
45
+ * `JSON_TABLE` source: turns a JSON document into rows. Needs PostgreSQL 17.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * const source: JsonTableOptions = {
50
+ * doc: { items: [{ sku: 'a', qty: 2 }] },
51
+ * path: '$.items[*]',
52
+ * columns: [{ name: 'sku', type: 'text' }, { name: 'qty', type: 'integer' }],
53
+ * };
54
+ * ```
55
+ */
56
+ export type JsonTableOptions = Readonly<{
57
+ /** Document: a JSON value (bound as `jsonb`) or an expression such as `col('Order.data')`. */
58
+ doc: unknown;
59
+ /** jsonpath that selects the rows; rendered as an escaped string literal. */
60
+ path: string;
61
+ /** Output columns. */
62
+ columns: readonly JsonTableColumnOptions[];
63
+ }>;
64
+ /**
65
+ * Relation of a `from` entry: a model, a subquery, a relation name, or one of the source forms.
66
+ * PostgreSQL extension.
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * const from: FromSourceOption[] = [
71
+ * Post,
72
+ * 'audit_log',
73
+ * { values: { columns: ['id', 'label'], rows: [[1, 'a'], [2, 'b']] } },
74
+ * { function: 'generate_series', args: [cast(1, 'integer'), cast(3, 'integer')], columns: ['n'] },
75
+ * { lateral: Post.subquery({ limit: 3 }) },
76
+ * { model: Post, sample: { method: 'SYSTEM', percent: 5 } },
77
+ * ];
78
+ * ```
79
+ */
80
+ export type FromSourceOption = ModelStatic<AnyModel> | Subquery | string | Readonly<{
81
+ /** `(VALUES …) AS alias(columns)`: bound rows. */
82
+ values: Readonly<{
83
+ /** Column names. */
84
+ columns: readonly string[];
85
+ /** Rows: one cell per column, bound as parameters. */
86
+ rows: readonly (readonly unknown[])[];
87
+ }>;
88
+ }> | Readonly<{
89
+ /** Set-returning function (`generate_series`, `unnest`, …), optionally schema-qualified. */
90
+ function: string;
91
+ /** Arguments, bound as parameters unless expressions. Wrap values in `cast()` when the type is ambiguous. */
92
+ args?: readonly unknown[];
93
+ /** Column aliases. */
94
+ columns?: readonly string[];
95
+ /** `WITH ORDINALITY`: name of the row-number column, appended to `columns`. */
96
+ ordinality?: string;
97
+ }> | Readonly<{
98
+ /** `JSON_TABLE(...)`. PostgreSQL 17+. */
99
+ jsonTable: JsonTableOptions;
100
+ }> | Readonly<{
101
+ /** `LATERAL (subquery)`: may reference relations to its left. */
102
+ lateral: Subquery;
103
+ }> | Readonly<{
104
+ /** Table of the model read with `TABLESAMPLE`. */
105
+ model: ModelStatic<AnyModel>;
106
+ /** Sampling. */
107
+ sample: TableSampleOptions;
108
+ }>;
@@ -0,0 +1,77 @@
1
+ import { WriteStatement } from '../expressions/methods.ts';
2
+ import { AttributeColumns } from './attribute-columns.ts';
3
+ import { DeleteQueryBuilder } from './delete-query-builder.ts';
4
+ import { InsertQueryBuilder } from './insert-query-builder.ts';
5
+ import { ModelRegistry } from './model-registry.ts';
6
+ import { ModelValues } from './model-values.ts';
7
+ import { AnyModel, ModelStatic, Values } from './options.ts';
8
+ import { UpdateQueryBuilder } from './update-query-builder.ts';
9
+ import { WhereOptions } from './types.ts';
10
+ /**
11
+ * Options of `Model.deleteStatement()` and `Model.updateStatement()`.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const options: WriteStatementOptions<Task> = { where: { done: true }, returning: true };
16
+ * ```
17
+ */
18
+ export type WriteStatementOptions<T = Values> = Readonly<{
19
+ /** Rows to change; all rows when omitted. The default scope applies. */
20
+ where?: WhereOptions<T>;
21
+ /** Add `RETURNING` with all columns, so that the CTE can be read. */
22
+ returning?: boolean;
23
+ }>;
24
+ /**
25
+ * Options of `Model.updateStatement()`.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * const options: UpdateStatementOptions<Task> = { where: { id: 1 }, returning: true, silent: true };
30
+ * ```
31
+ */
32
+ export type UpdateStatementOptions<T = Values> = WriteStatementOptions<T> & Readonly<{
33
+ /** Leave `updatedAt` unchanged. */
34
+ silent?: boolean;
35
+ }>;
36
+ /** Builds the INSERT / UPDATE / DELETE statements of data-modifying CTEs. No hooks or validation run. */
37
+ export declare class StatementBuilder {
38
+ #private;
39
+ /**
40
+ * @param services - Model state, value rules and statement builders.
41
+ */
42
+ constructor(services: Readonly<{
43
+ registry: ModelRegistry;
44
+ values: ModelValues;
45
+ columns: AttributeColumns;
46
+ updates: UpdateQueryBuilder;
47
+ deletes: DeleteQueryBuilder;
48
+ inserts: InsertQueryBuilder;
49
+ }>);
50
+ /**
51
+ * An UPDATE statement.
52
+ *
53
+ * @param model - Model class.
54
+ * @param values - New attribute values.
55
+ * @param options - Condition, RETURNING, `silent`.
56
+ * @returns Statement for a CTE.
57
+ */
58
+ update(model: ModelStatic<AnyModel>, values: Values, options: UpdateStatementOptions): WriteStatement;
59
+ /**
60
+ * A DELETE statement (a real delete, also for paranoid models).
61
+ *
62
+ * @param model - Model class.
63
+ * @param options - Condition and RETURNING.
64
+ * @returns Statement for a CTE.
65
+ */
66
+ delete(model: ModelStatic<AnyModel>, options: WriteStatementOptions): WriteStatement;
67
+ /**
68
+ * An INSERT statement of attribute-keyed rows (defaults and timestamps are filled in).
69
+ *
70
+ * @param model - Model class.
71
+ * @param rows - Rows to insert.
72
+ * @param options - RETURNING.
73
+ * @returns Statement for a CTE.
74
+ * @throws Error without rows.
75
+ */
76
+ insert(model: ModelStatic<AnyModel>, rows: readonly Values[], options: Pick<WriteStatementOptions, 'returning'>): WriteStatement;
77
+ }
@@ -0,0 +1,2 @@
1
+ import { StatementBuilder } from './statement-builder.ts';
2
+ export declare const statements: StatementBuilder;
@@ -0,0 +1,18 @@
1
+ import { SyncOptions } from '../query-interface/schema-synchronizer.ts';
2
+ import { InstanceLifecycle } from './instance-lifecycle.ts';
3
+ /** Runs the `beforeSync` / `afterSync` hooks of a model around its table sync. */
4
+ export declare class SyncHooks {
5
+ #private;
6
+ /**
7
+ * @param lifecycle - Hook runner (model hooks, then Sequelize-level hooks).
8
+ */
9
+ constructor(lifecycle: InstanceLifecycle);
10
+ /**
11
+ * Runs `run` between the model's sync hooks unless `options.hooks` is `false`.
12
+ *
13
+ * @param model - Model class.
14
+ * @param options - Sync options passed to the hooks.
15
+ * @param run - The table sync.
16
+ */
17
+ around(model: object, options: SyncOptions, run: () => Promise<void>): Promise<void>;
18
+ }
@@ -0,0 +1,13 @@
1
+ import { TableSample } from '../sql/ast.ts';
2
+ import { TableSampleOptions } from './source-options.ts';
3
+ /** Validates `sample` options and converts them to a `TABLESAMPLE` clause. */
4
+ export declare class TableSampleBuilder {
5
+ /**
6
+ * Builds the sampling clause.
7
+ *
8
+ * @param sample - Sample options.
9
+ * @returns `TABLESAMPLE` node with bound percent and seed.
10
+ * @throws Error for an unknown method, a percent outside 0–100, or a non-finite seed.
11
+ */
12
+ build(sample: TableSampleOptions): TableSample;
13
+ }
@@ -0,0 +1,85 @@
1
+ import { SqlExpression } from '../expressions/methods.ts';
2
+ export type { AnyAll, SqlValue, ValuesList, WhereAttributeHash, WhereAttributeValue, WhereLogic, WhereOperators, WhereOptions, } from './where-options.ts';
3
+ declare const CreationAttributeBrand: unique symbol;
4
+ declare const NonAttributeBrand: unique symbol;
5
+ declare const ForeignKeyBrand: unique symbol;
6
+ /**
7
+ * Marks an attribute as optional on creation (e.g. auto-increment ids, defaults).
8
+ * Same semantics as Sequelize v6 `CreationOptional`.
9
+ */
10
+ export type CreationOptional<T> = T extends null | undefined ? T : T & CreationOptionalBrand;
11
+ /** Marks a class property as not being a model attribute (Sequelize v6 `NonAttribute`). */
12
+ export type NonAttribute<T> = T extends null | undefined ? T : T & NonAttributeBrandType;
13
+ /** Marks an attribute as a foreign key (Sequelize v6 `ForeignKey`). */
14
+ export type ForeignKey<T> = T extends null | undefined ? T : T & ForeignKeyBrandType;
15
+ /** Type brand of {@link CreationOptional}. */
16
+ export type CreationOptionalBrand = {
17
+ /** Brand marker. */
18
+ [CreationAttributeBrand]?: true;
19
+ };
20
+ /** Type brand of {@link NonAttribute}. */
21
+ export type NonAttributeBrandType = {
22
+ /** Brand marker. */
23
+ [NonAttributeBrand]?: true;
24
+ };
25
+ /** Type brand of {@link ForeignKey}. */
26
+ export type ForeignKeyBrandType = {
27
+ /** Brand marker. */
28
+ [ForeignKeyBrand]?: true;
29
+ };
30
+ type IsBranded<T, Brand extends symbol> = [Extract<keyof NonNullable<T>, Brand>] extends [never] ? false : true;
31
+ type AnyFunction = (...args: any[]) => unknown;
32
+ /**
33
+ * Options of {@link InferAttributes}.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * type UserAttributes = InferAttributes<User, { omit: 'posts' }>;
38
+ * ```
39
+ */
40
+ export type InferAttributesOptions<OmittedKeys> = Readonly<{
41
+ /** Attribute names to leave out. */
42
+ omit?: OmittedKeys;
43
+ }>;
44
+ type AttributeKey<M, K extends keyof M, OmittedKeys> = K extends keyof ModelBase ? never : K extends OmittedKeys ? never : M[K] extends AnyFunction ? never : IsBranded<M[K], typeof NonAttributeBrand> extends true ? never : K;
45
+ /** Base instance members that are never attributes. */
46
+ export type ModelBase = Readonly<{
47
+ /** Current values. */
48
+ dataValues: unknown;
49
+ /** Values as of the last load/save. */
50
+ _previousDataValues: unknown;
51
+ /** Phantom attribute type. */
52
+ _attributes: unknown;
53
+ /** Phantom creation attribute type. */
54
+ _creationAttributes: unknown;
55
+ /** Model class. */
56
+ _model: unknown;
57
+ /** Unsaved flag. */
58
+ isNewRecord: unknown;
59
+ /** Owning `Sequelize` instance. */
60
+ sequelize: unknown;
61
+ /** Insert/update flag of `onConflict` results. */
62
+ wasInserted: unknown;
63
+ /** Pre-statement values of `returningOld` results. */
64
+ oldValues: unknown;
65
+ }>;
66
+ /** Infers attribute types from a model class declaration (Sequelize v6 `InferAttributes`). */
67
+ export type InferAttributes<M, Options extends InferAttributesOptions<keyof M | never> = InferAttributesOptions<never>> = {
68
+ [K in keyof M as AttributeKey<M, K, Options['omit']>]: M[K];
69
+ };
70
+ /** Infers creation attribute types; `CreationOptional` attributes may be `undefined` (Sequelize v6 `InferCreationAttributes`). */
71
+ export type InferCreationAttributes<M, Options extends InferAttributesOptions<keyof M | never> = InferAttributesOptions<never>> = {
72
+ [K in keyof M as AttributeKey<M, K, Options['omit']>]: IsBranded<M[K], typeof CreationAttributeBrand> extends true ? M[K] | undefined : M[K];
73
+ };
74
+ /** Makes the given keys of `T` optional (Sequelize v6 `Optional`). */
75
+ export type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
76
+ /** Makes nullable attributes optional (Sequelize v6 `MakeNullishOptional`). */
77
+ export type MakeNullishOptional<T> = {
78
+ [K in keyof T as null extends T[K] ? never : undefined extends T[K] ? never : K]: T[K];
79
+ } & {
80
+ [K in keyof T as null extends T[K] ? K : undefined extends T[K] ? K : never]?: T[K];
81
+ };
82
+ /** A value or an array of values. */
83
+ export type AllowArray<T> = T | readonly T[];
84
+ /** Any expression builder value. */
85
+ export type Expression = SqlExpression;
@@ -0,0 +1,24 @@
1
+ import { CompiledQuery, SqlCompiler } from '../sql/compile.ts';
2
+ import { InsertQueryBuilder } from './insert-query-builder.ts';
3
+ import { ModelDefinition } from './model-definition.ts';
4
+ import { BulkCreateOptions } from './options.ts';
5
+ /**
6
+ * Builds `INSERT INTO t (cols) SELECT * FROM unnest($1::type[], …)` for `bulkCreate({ unnest: true })`:
7
+ * one array parameter per column, so the 65535-parameter limit does not cap the batch size.
8
+ */
9
+ export declare class UnnestInsertBuilder {
10
+ #private;
11
+ /**
12
+ * @param inserts - VALUES INSERT builder, reused for columns, table and RETURNING.
13
+ * @param compiler - SQL compiler.
14
+ */
15
+ constructor(inserts: InsertQueryBuilder, compiler: SqlCompiler);
16
+ /**
17
+ * @param definition - Model definition.
18
+ * @param rows - Values by attribute name.
19
+ * @param options - `returning` and `overriding` of the bulk create.
20
+ * @returns The compiled INSERT; its values are the column arrays.
21
+ * @throws Error for conflict options, `ARRAY` columns, or rows that leave a column to its default.
22
+ */
23
+ build(definition: ModelDefinition, rows: readonly Readonly<Record<string, unknown>>[], options: BulkCreateOptions): CompiledQuery;
24
+ }