@rvoh/dream 2.1.0 → 2.1.3

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 (237) hide show
  1. package/README.md +4 -4
  2. package/dist/cjs/src/Dream.js +35 -0
  3. package/dist/cjs/src/bin/index.js +1 -1
  4. package/dist/cjs/src/cli/index.js +1 -1
  5. package/dist/cjs/src/cli/logger/loggable/DreamCliLoggableText.js +1 -0
  6. package/dist/cjs/src/dream/DreamClassTransactionBuilder.js +30 -0
  7. package/dist/cjs/src/dream/Query.js +30 -0
  8. package/dist/cjs/src/dream/QueryDriver/Base.js +32 -0
  9. package/dist/cjs/src/dream/QueryDriver/Kysely.js +48 -0
  10. package/dist/cjs/src/dream/internal/printSerializerHierarchyLevel.js +2 -0
  11. package/dist/cjs/src/dream-app/helpers/DreamImporter.js +3 -1
  12. package/dist/cjs/src/dream-app/index.js +2 -1
  13. package/dist/cjs/src/helpers/Env.js +2 -0
  14. package/dist/cjs/src/helpers/cli/ASTConnectionBuilder.js +1 -1
  15. package/dist/cjs/src/helpers/cli/DBClassDeprecation.js +2 -0
  16. package/dist/cjs/src/helpers/cli/generateDream.js +2 -1
  17. package/dist/cjs/src/helpers/cli/generateDreamContent.js +5 -4
  18. package/dist/cjs/src/helpers/cli/generateFactory.js +2 -1
  19. package/dist/cjs/src/helpers/cli/generateFactoryContent.js +3 -2
  20. package/dist/cjs/src/helpers/cli/generateMigration.js +2 -1
  21. package/dist/cjs/src/helpers/cli/generateMigrationContent.js +7 -5
  22. package/dist/cjs/src/helpers/cli/generateSerializer.js +2 -1
  23. package/dist/cjs/src/helpers/cli/generateSerializerContent.js +1 -1
  24. package/dist/cjs/src/helpers/cli/generateUnitSpec.js +2 -1
  25. package/dist/cjs/src/helpers/getFiles.js +3 -1
  26. package/dist/cjs/src/helpers/sspawn.js +2 -0
  27. package/dist/esm/src/Dream.js +35 -0
  28. package/dist/esm/src/bin/index.js +1 -1
  29. package/dist/esm/src/cli/index.js +1 -1
  30. package/dist/esm/src/cli/logger/loggable/DreamCliLoggableText.js +1 -0
  31. package/dist/esm/src/dream/DreamClassTransactionBuilder.js +30 -0
  32. package/dist/esm/src/dream/Query.js +30 -0
  33. package/dist/esm/src/dream/QueryDriver/Base.js +32 -0
  34. package/dist/esm/src/dream/QueryDriver/Kysely.js +48 -0
  35. package/dist/esm/src/dream/internal/printSerializerHierarchyLevel.js +2 -0
  36. package/dist/esm/src/dream-app/helpers/DreamImporter.js +3 -1
  37. package/dist/esm/src/dream-app/index.js +2 -1
  38. package/dist/esm/src/helpers/Env.js +2 -0
  39. package/dist/esm/src/helpers/cli/ASTConnectionBuilder.js +1 -1
  40. package/dist/esm/src/helpers/cli/DBClassDeprecation.js +2 -0
  41. package/dist/esm/src/helpers/cli/generateDream.js +2 -1
  42. package/dist/esm/src/helpers/cli/generateDreamContent.js +5 -4
  43. package/dist/esm/src/helpers/cli/generateFactory.js +2 -1
  44. package/dist/esm/src/helpers/cli/generateFactoryContent.js +3 -2
  45. package/dist/esm/src/helpers/cli/generateMigration.js +2 -1
  46. package/dist/esm/src/helpers/cli/generateMigrationContent.js +7 -5
  47. package/dist/esm/src/helpers/cli/generateSerializer.js +2 -1
  48. package/dist/esm/src/helpers/cli/generateSerializerContent.js +1 -1
  49. package/dist/esm/src/helpers/cli/generateUnitSpec.js +2 -1
  50. package/dist/esm/src/helpers/getFiles.js +3 -1
  51. package/dist/esm/src/helpers/sspawn.js +2 -0
  52. package/dist/types/src/Dream.d.ts +28 -0
  53. package/dist/types/src/dream/DreamClassTransactionBuilder.d.ts +26 -0
  54. package/dist/types/src/dream/Query.d.ts +26 -0
  55. package/dist/types/src/dream/QueryDriver/Base.d.ts +26 -0
  56. package/dist/types/src/dream/QueryDriver/Kysely.d.ts +26 -0
  57. package/dist/types/src/dream-app/helpers/PackageManager.d.ts +1 -1
  58. package/dist/types/src/dream-app/index.d.ts +2 -2
  59. package/dist/types/src/types/associations/belongsTo.d.ts +1 -1
  60. package/dist/types/src/types/associations/belongsTo.ts +1 -1
  61. package/dist/types/src/types/serializer.ts +2 -2
  62. package/docs/assets/search.js +1 -1
  63. package/docs/classes/db.DreamMigrationHelpers.html +9 -9
  64. package/docs/classes/db.KyselyQueryDriver.html +47 -31
  65. package/docs/classes/db.PostgresQueryDriver.html +48 -32
  66. package/docs/classes/db.QueryDriverBase.html +46 -30
  67. package/docs/classes/errors.CheckConstraintViolation.html +4 -4
  68. package/docs/classes/errors.ColumnOverflow.html +4 -4
  69. package/docs/classes/errors.CreateOrFindByFailedToCreateAndFind.html +4 -4
  70. package/docs/classes/errors.DataIncompatibleWithDatabaseField.html +4 -4
  71. package/docs/classes/errors.DataTypeColumnTypeMismatch.html +4 -4
  72. package/docs/classes/errors.GlobalNameNotSet.html +4 -4
  73. package/docs/classes/errors.InvalidCalendarDate.html +4 -4
  74. package/docs/classes/errors.MissingSerializersDefinition.html +4 -4
  75. package/docs/classes/errors.NonLoadedAssociation.html +4 -4
  76. package/docs/classes/errors.NotNullViolation.html +4 -4
  77. package/docs/classes/errors.RecordNotFound.html +4 -4
  78. package/docs/classes/errors.ValidationError.html +4 -4
  79. package/docs/classes/index.CalendarDate.html +2 -2
  80. package/docs/classes/index.Decorators.html +19 -19
  81. package/docs/classes/index.Dream.html +210 -194
  82. package/docs/classes/index.DreamApp.html +5 -5
  83. package/docs/classes/index.DreamTransaction.html +2 -2
  84. package/docs/classes/index.Env.html +2 -2
  85. package/docs/classes/index.Query.html +91 -75
  86. package/docs/classes/system.CliFileWriter.html +2 -2
  87. package/docs/classes/system.DreamBin.html +2 -2
  88. package/docs/classes/system.DreamCLI.html +5 -5
  89. package/docs/classes/system.DreamImporter.html +2 -2
  90. package/docs/classes/system.DreamLogos.html +2 -2
  91. package/docs/classes/system.DreamSerializerBuilder.html +8 -8
  92. package/docs/classes/system.ObjectSerializerBuilder.html +8 -8
  93. package/docs/classes/utils.Encrypt.html +2 -2
  94. package/docs/classes/utils.Range.html +2 -2
  95. package/docs/functions/db.closeAllDbConnections.html +1 -1
  96. package/docs/functions/db.dreamDbConnections.html +1 -1
  97. package/docs/functions/db.untypedDb.html +1 -1
  98. package/docs/functions/db.validateColumn.html +1 -1
  99. package/docs/functions/db.validateTable.html +1 -1
  100. package/docs/functions/errors.pgErrorType.html +1 -1
  101. package/docs/functions/index.DreamSerializer.html +1 -1
  102. package/docs/functions/index.ObjectSerializer.html +1 -1
  103. package/docs/functions/index.ReplicaSafe.html +1 -1
  104. package/docs/functions/index.STI.html +1 -1
  105. package/docs/functions/index.SoftDelete.html +1 -1
  106. package/docs/functions/utils.camelize.html +1 -1
  107. package/docs/functions/utils.capitalize.html +1 -1
  108. package/docs/functions/utils.cloneDeepSafe.html +1 -1
  109. package/docs/functions/utils.compact.html +1 -1
  110. package/docs/functions/utils.groupBy.html +1 -1
  111. package/docs/functions/utils.hyphenize.html +1 -1
  112. package/docs/functions/utils.intersection.html +1 -1
  113. package/docs/functions/utils.isEmpty.html +1 -1
  114. package/docs/functions/utils.normalizeUnicode.html +1 -1
  115. package/docs/functions/utils.pascalize.html +1 -1
  116. package/docs/functions/utils.percent.html +1 -1
  117. package/docs/functions/utils.range-1.html +1 -1
  118. package/docs/functions/utils.round.html +1 -1
  119. package/docs/functions/utils.sanitizeString.html +1 -1
  120. package/docs/functions/utils.snakeify.html +1 -1
  121. package/docs/functions/utils.sort.html +1 -1
  122. package/docs/functions/utils.sortBy.html +1 -1
  123. package/docs/functions/utils.sortObjectByKey.html +1 -1
  124. package/docs/functions/utils.sortObjectByValue.html +1 -1
  125. package/docs/functions/utils.uncapitalize.html +1 -1
  126. package/docs/functions/utils.uniq.html +1 -1
  127. package/docs/index.html +4 -4
  128. package/docs/interfaces/openapi.OpenapiDescription.html +2 -2
  129. package/docs/interfaces/openapi.OpenapiSchemaProperties.html +1 -1
  130. package/docs/interfaces/openapi.OpenapiSchemaPropertiesShorthand.html +1 -1
  131. package/docs/interfaces/openapi.OpenapiTypeFieldObject.html +1 -1
  132. package/docs/interfaces/types.BelongsToStatement.html +2 -2
  133. package/docs/interfaces/types.DecoratorContext.html +2 -2
  134. package/docs/interfaces/types.DreamAppInitOptions.html +2 -2
  135. package/docs/interfaces/types.DreamAppOpts.html +2 -2
  136. package/docs/interfaces/types.EncryptOptions.html +2 -2
  137. package/docs/interfaces/types.InternalAnyTypedSerializerRendersMany.html +2 -2
  138. package/docs/interfaces/types.InternalAnyTypedSerializerRendersOne.html +2 -2
  139. package/docs/interfaces/types.SerializerRendererOpts.html +2 -2
  140. package/docs/modules/db.html +1 -1
  141. package/docs/modules/errors.html +1 -1
  142. package/docs/modules/index.html +1 -1
  143. package/docs/modules/openapi.html +1 -1
  144. package/docs/modules/system.html +1 -1
  145. package/docs/modules/types.html +1 -1
  146. package/docs/modules/utils.html +1 -1
  147. package/docs/types/index.DateTime.html +1 -1
  148. package/docs/types/openapi.CommonOpenapiSchemaObjectFields.html +1 -1
  149. package/docs/types/openapi.OpenapiAllTypes.html +1 -1
  150. package/docs/types/openapi.OpenapiFormats.html +1 -1
  151. package/docs/types/openapi.OpenapiNumberFormats.html +1 -1
  152. package/docs/types/openapi.OpenapiPrimitiveBaseTypes.html +1 -1
  153. package/docs/types/openapi.OpenapiPrimitiveTypes.html +1 -1
  154. package/docs/types/openapi.OpenapiSchemaArray.html +1 -1
  155. package/docs/types/openapi.OpenapiSchemaArrayShorthand.html +1 -1
  156. package/docs/types/openapi.OpenapiSchemaBase.html +1 -1
  157. package/docs/types/openapi.OpenapiSchemaBody.html +1 -1
  158. package/docs/types/openapi.OpenapiSchemaBodyShorthand.html +1 -1
  159. package/docs/types/openapi.OpenapiSchemaCommonFields.html +1 -1
  160. package/docs/types/openapi.OpenapiSchemaExpressionAllOf.html +1 -1
  161. package/docs/types/openapi.OpenapiSchemaExpressionAnyOf.html +1 -1
  162. package/docs/types/openapi.OpenapiSchemaExpressionOneOf.html +1 -1
  163. package/docs/types/openapi.OpenapiSchemaExpressionRef.html +1 -1
  164. package/docs/types/openapi.OpenapiSchemaExpressionRefSchemaShorthand.html +1 -1
  165. package/docs/types/openapi.OpenapiSchemaInteger.html +1 -1
  166. package/docs/types/openapi.OpenapiSchemaNull.html +1 -1
  167. package/docs/types/openapi.OpenapiSchemaNumber.html +1 -1
  168. package/docs/types/openapi.OpenapiSchemaObject.html +1 -1
  169. package/docs/types/openapi.OpenapiSchemaObjectAllOf.html +1 -1
  170. package/docs/types/openapi.OpenapiSchemaObjectAllOfShorthand.html +1 -1
  171. package/docs/types/openapi.OpenapiSchemaObjectAnyOf.html +1 -1
  172. package/docs/types/openapi.OpenapiSchemaObjectAnyOfShorthand.html +1 -1
  173. package/docs/types/openapi.OpenapiSchemaObjectBase.html +1 -1
  174. package/docs/types/openapi.OpenapiSchemaObjectBaseShorthand.html +1 -1
  175. package/docs/types/openapi.OpenapiSchemaObjectOneOf.html +1 -1
  176. package/docs/types/openapi.OpenapiSchemaObjectOneOfShorthand.html +1 -1
  177. package/docs/types/openapi.OpenapiSchemaObjectShorthand.html +1 -1
  178. package/docs/types/openapi.OpenapiSchemaPrimitiveGeneric.html +1 -1
  179. package/docs/types/openapi.OpenapiSchemaShorthandExpressionAllOf.html +1 -1
  180. package/docs/types/openapi.OpenapiSchemaShorthandExpressionAnyOf.html +1 -1
  181. package/docs/types/openapi.OpenapiSchemaShorthandExpressionOneOf.html +1 -1
  182. package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializableRef.html +1 -1
  183. package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializerRef.html +1 -1
  184. package/docs/types/openapi.OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
  185. package/docs/types/openapi.OpenapiSchemaString.html +1 -1
  186. package/docs/types/openapi.OpenapiShorthandAllTypes.html +1 -1
  187. package/docs/types/openapi.OpenapiShorthandPrimitiveBaseTypes.html +1 -1
  188. package/docs/types/openapi.OpenapiShorthandPrimitiveTypes.html +1 -1
  189. package/docs/types/openapi.OpenapiTypeField.html +1 -1
  190. package/docs/types/system.DreamAppAllowedPackageManagersEnum.html +1 -1
  191. package/docs/types/types.Camelized.html +1 -1
  192. package/docs/types/types.DbConnectionType.html +1 -1
  193. package/docs/types/types.DbTypes.html +1 -1
  194. package/docs/types/types.DreamAssociationMetadata.html +1 -1
  195. package/docs/types/types.DreamAttributes.html +1 -1
  196. package/docs/types/types.DreamClassAssociationAndStatement.html +1 -1
  197. package/docs/types/types.DreamClassColumn.html +1 -1
  198. package/docs/types/types.DreamColumn.html +1 -1
  199. package/docs/types/types.DreamColumnNames.html +1 -1
  200. package/docs/types/types.DreamLogLevel.html +1 -1
  201. package/docs/types/types.DreamLogger.html +1 -1
  202. package/docs/types/types.DreamModelSerializerType.html +1 -1
  203. package/docs/types/types.DreamOrViewModelClassSerializerKey.html +1 -1
  204. package/docs/types/types.DreamOrViewModelSerializerKey.html +1 -1
  205. package/docs/types/types.DreamParamSafeAttributes.html +1 -1
  206. package/docs/types/types.DreamParamSafeColumnNames.html +1 -1
  207. package/docs/types/types.DreamSerializable.html +1 -1
  208. package/docs/types/types.DreamSerializableArray.html +1 -1
  209. package/docs/types/types.DreamSerializerKey.html +1 -1
  210. package/docs/types/types.DreamSerializers.html +1 -1
  211. package/docs/types/types.DreamVirtualColumns.html +1 -1
  212. package/docs/types/types.EncryptAlgorithm.html +1 -1
  213. package/docs/types/types.HasManyStatement.html +1 -1
  214. package/docs/types/types.HasOneStatement.html +1 -1
  215. package/docs/types/types.Hyphenized.html +1 -1
  216. package/docs/types/types.Pascalized.html +1 -1
  217. package/docs/types/types.RoundingPrecision.html +1 -1
  218. package/docs/types/types.SerializerCasing.html +1 -1
  219. package/docs/types/types.SimpleObjectSerializerType.html +1 -1
  220. package/docs/types/types.Snakeified.html +1 -1
  221. package/docs/types/types.StrictInterface.html +1 -1
  222. package/docs/types/types.UpdateableAssociationProperties.html +1 -1
  223. package/docs/types/types.UpdateableProperties.html +1 -1
  224. package/docs/types/types.ValidationType.html +1 -1
  225. package/docs/types/types.ViewModel.html +1 -1
  226. package/docs/types/types.ViewModelClass.html +1 -1
  227. package/docs/types/types.WhereStatementForDream.html +1 -1
  228. package/docs/types/types.WhereStatementForDreamClass.html +1 -1
  229. package/docs/variables/index.DateTime-1.html +1 -1
  230. package/docs/variables/index.DreamConst.html +1 -1
  231. package/docs/variables/index.ops.html +1 -1
  232. package/docs/variables/openapi.openapiPrimitiveTypes-1.html +1 -1
  233. package/docs/variables/openapi.openapiShorthandPrimitiveTypes-1.html +1 -1
  234. package/docs/variables/system.DreamAppAllowedPackageManagersEnumValues.html +1 -1
  235. package/docs/variables/types.TRIGRAM_OPERATORS.html +1 -1
  236. package/docs/variables/types.primaryKeyTypes.html +1 -1
  237. package/package.json +21 -17
@@ -213,7 +213,7 @@ ${INDENT} to extend the Coach model in src/app/models/Health/Coach: Health/Co
213
213
  .description('Seeds the database using the file located in db/seed.ts.')
214
214
  .action(async () => {
215
215
  if (process.env.NODE_ENV === 'test' && process.env.DREAM_SEED_DB_IN_TEST !== '1') {
216
- console.log('skipping db seed for test env. To really seed for test, add DREAM_SEED_DB_IN_TEST=1');
216
+ DreamApp.log('skipping db seed for test env. To really seed for test, add DREAM_SEED_DB_IN_TEST=1');
217
217
  return;
218
218
  }
219
219
  await initializeDreamApp();
@@ -13,6 +13,7 @@ export default class DreamCliLoggableText extends DreamCliLoggable {
13
13
  this.logPrefixBgColor = logPrefixBgColor;
14
14
  }
15
15
  render() {
16
+ // eslint-disable-next-line no-console
16
17
  console.log(`${this.colorizedLogPrefix} ${colorize(this.text, { color: this.color, bgColor: this.bgColor })}`);
17
18
  }
18
19
  }
@@ -124,6 +124,36 @@ export default class DreamClassTransactionBuilder {
124
124
  async min(columnName) {
125
125
  return this.queryInstance().min(columnName);
126
126
  }
127
+ /**
128
+ * Retrieves the sum value of the specified column
129
+ * for this Query
130
+ *
131
+ * ```ts
132
+ * await Game.txn(txn).sum('score')
133
+ * // 1
134
+ * ```
135
+ *
136
+ * @param columnName - a column name on the model
137
+ * @returns the sum of the values of the specified column for this Query
138
+ */
139
+ async sum(columnName) {
140
+ return this.queryInstance().sum(columnName);
141
+ }
142
+ /**
143
+ * Retrieves the average value of the specified column
144
+ * for this Query
145
+ *
146
+ * ```ts
147
+ * await Game.txn(txn).avg('score')
148
+ * // 1
149
+ * ```
150
+ *
151
+ * @param columnName - a column name on the model
152
+ * @returns the average of the values of the specified column for this Query
153
+ */
154
+ async avg(columnName) {
155
+ return this.queryInstance().avg(columnName);
156
+ }
127
157
  /**
128
158
  * Persists a new record, setting the provided attributes.
129
159
  * Automatically sets createdAt and updatedAt timestamps.
@@ -1043,6 +1043,36 @@ export default class Query {
1043
1043
  async min(columnName) {
1044
1044
  return await this.dbDriverInstance().min(columnName);
1045
1045
  }
1046
+ /**
1047
+ * Retrieves the sum value of the specified column
1048
+ * for this Query
1049
+ *
1050
+ * ```ts
1051
+ * await Game.query().sum('score')
1052
+ * // 1
1053
+ * ```
1054
+ *
1055
+ * @param columnName - a column name on the model
1056
+ * @returns the sum of the values of the specified column for this Query
1057
+ */
1058
+ async sum(columnName) {
1059
+ return await this.dbDriverInstance().sum(columnName);
1060
+ }
1061
+ /**
1062
+ * Retrieves the average value of the specified column
1063
+ * for this Query
1064
+ *
1065
+ * ```ts
1066
+ * await Game.query().avg('score')
1067
+ * // 1
1068
+ * ```
1069
+ *
1070
+ * @param columnName - a column name on the model
1071
+ * @returns the average of the values of the specified column for this Query
1072
+ */
1073
+ async avg(columnName) {
1074
+ return await this.dbDriverInstance().avg(columnName);
1075
+ }
1046
1076
  /**
1047
1077
  * Plucks the provided fields from the given dream class table
1048
1078
  *
@@ -273,6 +273,38 @@ export default class QueryDriverBase {
273
273
  async min(columnName) {
274
274
  throw new Error('implement min in child class');
275
275
  }
276
+ /**
277
+ * Retrieves the sum value of the specified column
278
+ * for this Query
279
+ *
280
+ * ```ts
281
+ * await Game.query().sum('score')
282
+ * // 1
283
+ * ```
284
+ *
285
+ * @param columnName - a column name on the model
286
+ * @returns the sum of the values of the specified column for this Query
287
+ */
288
+ // eslint-disable-next-line @typescript-eslint/require-await, @typescript-eslint/no-unused-vars
289
+ async sum(columnName) {
290
+ throw new Error('implement sum in child class');
291
+ }
292
+ /**
293
+ * Retrieves the average value of the specified column
294
+ * for this Query
295
+ *
296
+ * ```ts
297
+ * await Game.query().avg('score')
298
+ * // 1
299
+ * ```
300
+ *
301
+ * @param columnName - a column name on the model
302
+ * @returns the average of the values of the specified column for this Query
303
+ */
304
+ // eslint-disable-next-line @typescript-eslint/require-await, @typescript-eslint/no-unused-vars
305
+ async avg(columnName) {
306
+ throw new Error('implement avg in child class');
307
+ }
276
308
  /**
277
309
  * Retrieves the number of records in the database
278
310
  *
@@ -194,6 +194,7 @@ export default class KyselyQueryDriver extends QueryDriverBase {
194
194
  }
195
195
  }
196
196
  catch (error) {
197
+ // eslint-disable-next-line no-console
197
198
  console.error(error);
198
199
  await DreamCLI.logger.logProgress('[dream] sync failed, reverting file contents...', async () => {
199
200
  await CliFileWriter.revert();
@@ -452,6 +453,52 @@ export default class KyselyQueryDriver extends QueryDriverBase {
452
453
  const data = await executeDatabaseQuery(kyselyQuery, 'executeTakeFirstOrThrow');
453
454
  return data.min;
454
455
  }
456
+ /**
457
+ * Retrieves the sum value of the specified column
458
+ * for this Query
459
+ *
460
+ * ```ts
461
+ * await Game.query().sum('score')
462
+ * // 1
463
+ * ```
464
+ *
465
+ * @param columnName - a column name on the model
466
+ * @returns the sum of the values of the specified column for this Query
467
+ */
468
+ async sum(columnName) {
469
+ // eslint-disable-next-line @typescript-eslint/unbound-method
470
+ const { sum } = this.dbFor('select').fn;
471
+ let kyselyQuery = new this.constructor(this.query).buildSelect({
472
+ bypassSelectAll: true,
473
+ bypassOrder: true,
474
+ });
475
+ kyselyQuery = kyselyQuery.select(sum(columnName));
476
+ const data = await executeDatabaseQuery(kyselyQuery, 'executeTakeFirstOrThrow');
477
+ return data.sum === null ? null : parseFloat(data.sum);
478
+ }
479
+ /**
480
+ * Retrieves the average value of the specified column
481
+ * for this Query
482
+ *
483
+ * ```ts
484
+ * await Game.query().avg('score')
485
+ * // 1
486
+ * ```
487
+ *
488
+ * @param columnName - a column name on the model
489
+ * @returns the average of the values of the specified column for this Query
490
+ */
491
+ async avg(columnName) {
492
+ // eslint-disable-next-line @typescript-eslint/unbound-method
493
+ const { avg } = this.dbFor('select').fn;
494
+ let kyselyQuery = new this.constructor(this.query).buildSelect({
495
+ bypassSelectAll: true,
496
+ bypassOrder: true,
497
+ });
498
+ kyselyQuery = kyselyQuery.select(avg(columnName));
499
+ const data = await executeDatabaseQuery(kyselyQuery, 'executeTakeFirstOrThrow');
500
+ return data.avg;
501
+ }
455
502
  /**
456
503
  * Retrieves the number of records in the database
457
504
  *
@@ -893,6 +940,7 @@ export default class KyselyQueryDriver extends QueryDriverBase {
893
940
  const hasMany = association.type === 'HasMany';
894
941
  // initialize by trying to access the association, which throws an exception if not yet initialized
895
942
  try {
943
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
896
944
  ;
897
945
  dream[association.as];
898
946
  }
@@ -7,7 +7,9 @@ export default function printSerializerHierarchyLevel({ serializerAssociationTyp
7
7
  });
8
8
  const prefix = `${hierarchyLine} `;
9
9
  const nestedAssociationDisplay = indentation + `${prefix}${serializerAssociationType} ${yoctocolors.cyan(serializerAssociationName)}`;
10
+ // eslint-disable-next-line no-console
10
11
  console.log(nestedAssociationDisplay);
12
+ // eslint-disable-next-line no-console
11
13
  console.log(yoctocolors.gray(indentation +
12
14
  indent(prefix.length, { tabWidth: 1 }) +
13
15
  associationSerializer.globalName));
@@ -4,7 +4,9 @@ export default class DreamImporter {
4
4
  static async ls(dir) {
5
5
  try {
6
6
  const dirents = await fs.readdir(dir, { withFileTypes: true });
7
- const files = await Promise.all(dirents
7
+ const files = await Promise.all(
8
+ // eslint-disable-next-line @typescript-eslint/await-thenable
9
+ dirents
8
10
  .map(dirent => {
9
11
  const res = path.resolve(dir, dirent.name);
10
12
  return dirent.isDirectory()
@@ -137,6 +137,7 @@ export default class DreamApp {
137
137
  }
138
138
  static checkKey(encryptionIdentifier, key, algorithm) {
139
139
  if (!Encrypt.validateKey(key, algorithm))
140
+ // eslint-disable-next-line no-console
140
141
  console.warn(`
141
142
  Your current key value for ${encryptionIdentifier} encryption is invalid.
142
143
  Try setting it to something valid, like:
@@ -410,7 +411,7 @@ function argToString(arg) {
410
411
  return arg.toISO();
411
412
  return util.inspect(arg, { depth: 3 });
412
413
  }
413
- export const DreamAppAllowedPackageManagersEnumValues = ['yarn', 'npm', 'pnpm'];
414
+ export const DreamAppAllowedPackageManagersEnumValues = ['pnpm', 'yarn', 'npm'];
414
415
  // GeneratorImportStyles are used by CLI generators to determine how
415
416
  // to style import suffixes. When integrating with other apps, this
416
417
  // suffix style can change, and may need to be configured.
@@ -38,12 +38,14 @@ export default class Env {
38
38
  return this.optional(env) === '1';
39
39
  }
40
40
  setString(env, val) {
41
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
41
42
  val === undefined ? delete process.env[env] : (process.env[env] = val);
42
43
  }
43
44
  unsetString(env) {
44
45
  delete process.env[env];
45
46
  }
46
47
  setInteger(env, val) {
48
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
47
49
  val === undefined ? delete process.env[env] : (process.env[env] = Math.floor(val).toString());
48
50
  }
49
51
  unsetInteger(env) {
@@ -179,7 +179,7 @@ export default class ASTConnectionBuilder extends ASTBuilder {
179
179
  foreignKey = _foreignKey;
180
180
  }
181
181
  }
182
- catch (err) {
182
+ catch {
183
183
  this.hasForeignKeyError = true;
184
184
  }
185
185
  try {
@@ -37,7 +37,9 @@ export default class DBClassDeprecation {
37
37
  }
38
38
  }
39
39
  catch (err) {
40
+ // eslint-disable-next-line no-console
40
41
  console.error(err);
42
+ // eslint-disable-next-line no-console
41
43
  console.log(`
42
44
  ATTENTION:
43
45
 
@@ -1,4 +1,5 @@
1
1
  import * as fs from 'node:fs/promises';
2
+ import DreamCLI from '../../cli/index.js';
2
3
  import dreamFileAndDirPaths from '../path/dreamFileAndDirPaths.js';
3
4
  import dreamPath from '../path/dreamPath.js';
4
5
  import standardizeFullyQualifiedModelName from '../standardizeFullyQualifiedModelName.js';
@@ -11,7 +12,7 @@ export default async function generateDream({ fullyQualifiedModelName, columnsWi
11
12
  fullyQualifiedModelName = standardizeFullyQualifiedModelName(fullyQualifiedModelName);
12
13
  const { relFilePath, absDirPath, absFilePath } = dreamFileAndDirPaths(dreamPath('models'), `${fullyQualifiedModelName}.ts`);
13
14
  try {
14
- console.log(`generating dream: ${relFilePath}`);
15
+ DreamCLI.logger.log(`[dream] generating dream: ${relFilePath}`);
15
16
  await fs.mkdir(absDirPath, { recursive: true });
16
17
  await fs.writeFile(absFilePath, generateDreamContent({
17
18
  fullyQualifiedModelName,
@@ -94,11 +94,12 @@ export function processAttribute(attribute, modelClassName) {
94
94
  if (!attributeType) {
95
95
  throw new Error(`must pass a column type for ${attributeName} (i.e. ${attributeName}:string)`);
96
96
  }
97
- switch (attributeType) {
98
- case 'belongs_to':
97
+ const processedAttrType = camelize(attributeType).toLowerCase();
98
+ switch (processedAttrType) {
99
+ case 'belongsto':
99
100
  return createBelongsToAttribute(attributeName, descriptors, modelClassName);
100
- case 'has_one':
101
- case 'has_many':
101
+ case 'hasone':
102
+ case 'hasmany':
102
103
  return { content: '', imports: [] };
103
104
  case 'encrypted':
104
105
  return createEncryptedAttribute(attributeName, attribute, modelClassName);
@@ -3,11 +3,12 @@ import dreamFileAndDirPaths from '../path/dreamFileAndDirPaths.js';
3
3
  import dreamPath from '../path/dreamPath.js';
4
4
  import standardizeFullyQualifiedModelName from '../standardizeFullyQualifiedModelName.js';
5
5
  import generateFactoryContent from './generateFactoryContent.js';
6
+ import DreamCLI from '../../cli/index.js';
6
7
  export default async function generateFactory({ fullyQualifiedModelName, columnsWithTypes, }) {
7
8
  fullyQualifiedModelName = standardizeFullyQualifiedModelName(fullyQualifiedModelName);
8
9
  const { relFilePath, absDirPath, absFilePath } = dreamFileAndDirPaths(dreamPath('factories'), `${fullyQualifiedModelName}Factory.ts`);
9
10
  try {
10
- console.log(`generating factory: ${relFilePath}`);
11
+ DreamCLI.logger.log(`[dream] generating factory: ${relFilePath}`);
11
12
  await fs.mkdir(absDirPath, { recursive: true });
12
13
  await fs.writeFile(absFilePath, generateFactoryContent({ fullyQualifiedModelName, columnsWithTypes }));
13
14
  }
@@ -30,8 +30,9 @@ export default function generateFactoryContent({ fullyQualifiedModelName, column
30
30
  continue;
31
31
  if (!attributeType)
32
32
  throw new Error(`Must pass a column type for ${attributeName} (i.e. ${attributeName}:string)`);
33
- switch (attributeType) {
34
- case 'belongs_to': {
33
+ const safeAttributeType = camelize(attributeType)?.toLowerCase();
34
+ switch (safeAttributeType) {
35
+ case 'belongsto': {
35
36
  const attributeVariable = camelize(attributeName.split('/').pop());
36
37
  const fullyQualifiedAssociatedModelName = standardizeFullyQualifiedModelName(attributeName);
37
38
  const associationModelName = globalClassNameFromFullyQualifiedModelName(fullyQualifiedAssociatedModelName);
@@ -10,6 +10,7 @@ import dreamFileAndDirPaths from '../path/dreamFileAndDirPaths.js';
10
10
  import dreamPath from '../path/dreamPath.js';
11
11
  import snakeify from '../snakeify.js';
12
12
  import generateStiMigrationContent from './generateStiMigrationContent.js';
13
+ import DreamCLI from '../../cli/index.js';
13
14
  export default async function generateMigration({ migrationName, columnsWithTypes, connectionName, fullyQualifiedModelName, fullyQualifiedParentName, }) {
14
15
  const { relFilePath, absFilePath } = connectionName === 'default'
15
16
  ? dreamFileAndDirPaths(path.join(dreamPath('db'), 'migrations'), `${migrationVersion()}-${hyphenize(migrationName).replace(/\//g, '-')}.ts`)
@@ -41,7 +42,7 @@ export default async function generateMigration({ migrationName, columnsWithType
41
42
  });
42
43
  }
43
44
  try {
44
- console.log(`generating migration: ${relFilePath}`);
45
+ DreamCLI.logger.log(`[dream] generating migration: ${relFilePath}`);
45
46
  await fs.writeFile(absFilePath, finalContent);
46
47
  }
47
48
  catch (error) {
@@ -3,6 +3,7 @@ import Query from '../../dream/Query.js';
3
3
  import InvalidDecimalFieldPassedToGenerator from '../../errors/InvalidDecimalFieldPassedToGenerator.js';
4
4
  import compact from '../compact.js';
5
5
  import snakeify from '../snakeify.js';
6
+ import camelize from '../camelize.js';
6
7
  const STI_TYPE_COLUMN_NAME = 'type';
7
8
  const COLUMNS_TO_INDEX = [STI_TYPE_COLUMN_NAME];
8
9
  export default function generateMigrationContent({ connectionName = 'default', table, columnsWithTypes = [], primaryKeyType = 'bigserial', createOrAlter = 'create', stiChildClassName, } = {}) {
@@ -17,11 +18,12 @@ export default function generateMigrationContent({ connectionName = 'default', t
17
18
  * email address are the same email address
18
19
  */
19
20
  const attributeType = nonStandardAttributeName === 'email' ? 'citext' : _attributeType;
21
+ const processedAttrType = camelize(attributeType)?.toLowerCase();
20
22
  const userWantsThisOptional = optionalFromDescriptors(descriptors);
21
23
  // when creating a migration for an STI child, we don't want to include notNull;
22
24
  // instead, we'll add a check constraint that uses the STI child class name
23
25
  const sqlAttributeType = getAttributeType(attributeType, descriptors);
24
- if (attributeType === undefined || ['has_one', 'has_many'].includes(attributeType))
26
+ if (attributeType === undefined || ['hasone', 'hasmany'].includes(processedAttrType))
25
27
  return acc;
26
28
  if (attributeType === 'citext')
27
29
  requireCitextExtension = true;
@@ -30,8 +32,8 @@ export default function generateMigrationContent({ connectionName = 'default', t
30
32
  if (nonStandardAttributeName === undefined)
31
33
  return acc;
32
34
  let attributeName = snakeify(nonStandardAttributeName);
33
- switch (attributeType) {
34
- case 'belongs_to':
35
+ switch (processedAttrType) {
36
+ case 'belongsto':
35
37
  columnDefs.push(generateBelongsToStr(connectionName, attributeName, {
36
38
  primaryKeyType,
37
39
  omitInlineNonNull,
@@ -82,7 +84,7 @@ export default function generateMigrationContent({ connectionName = 'default', t
82
84
  break;
83
85
  }
84
86
  columnDrops.push(`.dropColumn('${attributeName}')`);
85
- if (attributeType === 'belongs_to' || COLUMNS_TO_INDEX.includes(attributeName)) {
87
+ if (processedAttrType === 'belongsto' || COLUMNS_TO_INDEX.includes(attributeName)) {
86
88
  const indexName = `${table}_${attributeName}`;
87
89
  indexDefs.push(`await db.schema
88
90
  .createIndex('${indexName}')
@@ -247,7 +249,7 @@ function generateColumnStr(attributeName, attributeType, descriptors, { omitInli
247
249
  if (attributeName === STI_TYPE_COLUMN_NAME)
248
250
  returnStr = `// CONSIDER: when using type for STI, always use an enum
249
251
  // Try using the enum syntax in your generator, e.g.:
250
- // yarn psy g:model Balloon type:enum:balloon_type:latex,mylar
252
+ // pnpm psy g:model Balloon type:enum:balloon_type:latex,mylar
251
253
  ${returnStr}`;
252
254
  return returnStr;
253
255
  }
@@ -3,11 +3,12 @@ import dreamFileAndDirPaths from '../path/dreamFileAndDirPaths.js';
3
3
  import dreamPath from '../path/dreamPath.js';
4
4
  import standardizeFullyQualifiedModelName from '../standardizeFullyQualifiedModelName.js';
5
5
  import generateSerializerContent from './generateSerializerContent.js';
6
+ import DreamCLI from '../../cli/index.js';
6
7
  export default async function generateSerializer({ fullyQualifiedModelName, columnsWithTypes, fullyQualifiedParentName, stiBaseSerializer, includeAdminSerializers, }) {
7
8
  fullyQualifiedModelName = standardizeFullyQualifiedModelName(fullyQualifiedModelName);
8
9
  const { relFilePath, absDirPath, absFilePath } = dreamFileAndDirPaths(dreamPath('serializers'), `${fullyQualifiedModelName}Serializer.ts`);
9
10
  try {
10
- console.log(`generating serializer: ${relFilePath}`);
11
+ DreamCLI.logger.log(`[dream] generating serializer: ${relFilePath}`);
11
12
  await fs.mkdir(absDirPath, { recursive: true });
12
13
  await fs.writeFile(absFilePath, generateSerializerContent({
13
14
  fullyQualifiedModelName,
@@ -49,7 +49,7 @@ export default function generateSerializerContent({ fullyQualifiedModelName, col
49
49
  const [name, type] = attr.split(':');
50
50
  if (name === undefined)
51
51
  return '';
52
- if (['belongs_to', 'has_one', 'has_many'].includes(type))
52
+ if (['belongsto', 'hasone', 'hasmany'].includes(camelize(type)?.toLowerCase()))
53
53
  return '';
54
54
  return `\n ${attribute(modelClassName, name, type, attr, stiBaseSerializer)}`;
55
55
  })
@@ -1,4 +1,5 @@
1
1
  import * as fs from 'node:fs/promises';
2
+ import DreamCLI from '../../cli/index.js';
2
3
  import dreamFileAndDirPaths from '../path/dreamFileAndDirPaths.js';
3
4
  import dreamPath from '../path/dreamPath.js';
4
5
  import standardizeFullyQualifiedModelName from '../standardizeFullyQualifiedModelName.js';
@@ -7,7 +8,7 @@ export default async function generateUnitSpec({ fullyQualifiedModelName, }) {
7
8
  fullyQualifiedModelName = standardizeFullyQualifiedModelName(fullyQualifiedModelName);
8
9
  const { relFilePath, absDirPath, absFilePath } = dreamFileAndDirPaths(dreamPath('modelSpecs'), `${fullyQualifiedModelName}.spec.ts`);
9
10
  try {
10
- console.log(`generating spec: ${relFilePath}`);
11
+ DreamCLI.logger.log(`[dream] generating spec: ${relFilePath}`);
11
12
  await fs.mkdir(absDirPath, { recursive: true });
12
13
  await fs.writeFile(absFilePath, generateUnitSpecContent({ fullyQualifiedModelName }));
13
14
  }
@@ -3,7 +3,9 @@ import * as path from 'node:path';
3
3
  export default async function getFiles(dir) {
4
4
  try {
5
5
  const dirents = await fs.readdir(dir, { withFileTypes: true });
6
- const files = await Promise.all(dirents.map(dirent => {
6
+ const files = await Promise.all(
7
+ // eslint-disable-next-line @typescript-eslint/await-thenable
8
+ dirents.map(dirent => {
7
9
  const res = path.resolve(dir, dirent.name);
8
10
  return dirent.isDirectory() ? getFiles(res) : res.replace(/\.ts$/, '.js');
9
11
  }));
@@ -28,6 +28,7 @@ export function ssspawn(command, opts = {}) {
28
28
  opts?.onStdout?.(txt);
29
29
  }
30
30
  else {
31
+ // eslint-disable-next-line no-console
31
32
  console.log(txt);
32
33
  }
33
34
  });
@@ -38,5 +39,6 @@ export function ssspawn(command, opts = {}) {
38
39
  return proc;
39
40
  }
40
41
  function handleSpawnError(err) {
42
+ // eslint-disable-next-line no-console
41
43
  console.error(err?.toString());
42
44
  }
@@ -707,6 +707,34 @@ export default class Dream {
707
707
  * @returns the min value of the specified column for this model's records
708
708
  */
709
709
  static min<T extends typeof Dream, ColumnName extends DreamColumnNames<InstanceType<T>>>(this: T, columnName: ColumnName): Promise<InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]["columns" & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]][ColumnName & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]["columns" & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]]]["coercedType" & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]["columns" & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]][ColumnName & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]["columns" & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]]]]>;
710
+ /**
711
+ * Retrieves the sum for all values of the specified column
712
+ * for this model's records.
713
+ *
714
+ *
715
+ * ```ts
716
+ * await Game.sum('score')
717
+ * // 100
718
+ * ```
719
+ *
720
+ * @param columnName - a column name on the model
721
+ * @returns the sum for all values of the specified column for this model's records
722
+ */
723
+ static sum<T extends typeof Dream, ColumnName extends DreamColumnNames<InstanceType<T>>>(this: T, columnName: ColumnName): Promise<InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]["columns" & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]][ColumnName & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]["columns" & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]]]["coercedType" & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]["columns" & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]][ColumnName & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]["columns" & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]]]]>;
724
+ /**
725
+ * Retrieves the average for all values of the specified column
726
+ * for this model's records.
727
+ *
728
+ *
729
+ * ```ts
730
+ * await Game.avg('score')
731
+ * // 100
732
+ * ```
733
+ *
734
+ * @param columnName - a column name on the model
735
+ * @returns the average for all values of the specified column for this model's records
736
+ */
737
+ static avg<T extends typeof Dream, ColumnName extends DreamColumnNames<InstanceType<T>>>(this: T, columnName: ColumnName): Promise<InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]["columns" & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]][ColumnName & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]["columns" & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]]]["coercedType" & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]["columns" & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]][ColumnName & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]["columns" & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]]]]>;
710
738
  /**
711
739
  * Persists a new record, setting the provided attributes.
712
740
  * Automatically sets createdAt and updatedAt timestamps.
@@ -115,6 +115,32 @@ export default class DreamClassTransactionBuilder<DreamClass extends typeof Drea
115
115
  * @returns The min value of the specified column for this model's records
116
116
  */
117
117
  min<I extends DreamClassTransactionBuilder<DreamClass, DreamInstance>, T extends DreamColumnNames<DreamInstance>>(this: I, columnName: T): Promise<DreamInstance["schema"][DreamInstance["table"] & keyof DreamInstance["schema"]]["columns" & keyof DreamInstance["schema"][DreamInstance["table"] & keyof DreamInstance["schema"]]][T & keyof DreamInstance["schema"][DreamInstance["table"] & keyof DreamInstance["schema"]]["columns" & keyof DreamInstance["schema"][DreamInstance["table"] & keyof DreamInstance["schema"]]]]["coercedType" & keyof DreamInstance["schema"][DreamInstance["table"] & keyof DreamInstance["schema"]]["columns" & keyof DreamInstance["schema"][DreamInstance["table"] & keyof DreamInstance["schema"]]][T & keyof DreamInstance["schema"][DreamInstance["table"] & keyof DreamInstance["schema"]]["columns" & keyof DreamInstance["schema"][DreamInstance["table"] & keyof DreamInstance["schema"]]]]]>;
118
+ /**
119
+ * Retrieves the sum value of the specified column
120
+ * for this Query
121
+ *
122
+ * ```ts
123
+ * await Game.txn(txn).sum('score')
124
+ * // 1
125
+ * ```
126
+ *
127
+ * @param columnName - a column name on the model
128
+ * @returns the sum of the values of the specified column for this Query
129
+ */
130
+ sum<I extends DreamClassTransactionBuilder<DreamClass, DreamInstance>, T extends DreamColumnNames<DreamInstance>>(this: I, columnName: T): Promise<DreamInstance["schema"][DreamInstance["table"] & keyof DreamInstance["schema"]]["columns" & keyof DreamInstance["schema"][DreamInstance["table"] & keyof DreamInstance["schema"]]][T & keyof DreamInstance["schema"][DreamInstance["table"] & keyof DreamInstance["schema"]]["columns" & keyof DreamInstance["schema"][DreamInstance["table"] & keyof DreamInstance["schema"]]]]["coercedType" & keyof DreamInstance["schema"][DreamInstance["table"] & keyof DreamInstance["schema"]]["columns" & keyof DreamInstance["schema"][DreamInstance["table"] & keyof DreamInstance["schema"]]][T & keyof DreamInstance["schema"][DreamInstance["table"] & keyof DreamInstance["schema"]]["columns" & keyof DreamInstance["schema"][DreamInstance["table"] & keyof DreamInstance["schema"]]]]]>;
131
+ /**
132
+ * Retrieves the average value of the specified column
133
+ * for this Query
134
+ *
135
+ * ```ts
136
+ * await Game.txn(txn).avg('score')
137
+ * // 1
138
+ * ```
139
+ *
140
+ * @param columnName - a column name on the model
141
+ * @returns the average of the values of the specified column for this Query
142
+ */
143
+ avg<I extends DreamClassTransactionBuilder<DreamClass, DreamInstance>, T extends DreamColumnNames<DreamInstance>>(this: I, columnName: T): Promise<DreamInstance["schema"][DreamInstance["table"] & keyof DreamInstance["schema"]]["columns" & keyof DreamInstance["schema"][DreamInstance["table"] & keyof DreamInstance["schema"]]][T & keyof DreamInstance["schema"][DreamInstance["table"] & keyof DreamInstance["schema"]]["columns" & keyof DreamInstance["schema"][DreamInstance["table"] & keyof DreamInstance["schema"]]]]["coercedType" & keyof DreamInstance["schema"][DreamInstance["table"] & keyof DreamInstance["schema"]]["columns" & keyof DreamInstance["schema"][DreamInstance["table"] & keyof DreamInstance["schema"]]][T & keyof DreamInstance["schema"][DreamInstance["table"] & keyof DreamInstance["schema"]]["columns" & keyof DreamInstance["schema"][DreamInstance["table"] & keyof DreamInstance["schema"]]]]]>;
118
144
  /**
119
145
  * Persists a new record, setting the provided attributes.
120
146
  * Automatically sets createdAt and updatedAt timestamps.
@@ -752,6 +752,32 @@ export default class Query<DreamInstance extends Dream, QueryTypeOpts extends Re
752
752
  * @returns the min value of the specified column for this Query
753
753
  */
754
754
  min<Q extends Query<DreamInstance, QueryTypeOpts>, DB extends DreamInstance['DB'], ColumnName extends ColumnNamesAccountingForJoinedAssociations<Q['queryTypeOpts']['joinedAssociations'], DB, QueryTypeOpts['rootTableName'], QueryTypeOpts['rootTableAlias']>, ReturnType extends NamespacedOrBaseModelColumnTypes<[ColumnName], Q, DreamInstance>[0]>(columnName: ColumnName): Promise<ReturnType>;
755
+ /**
756
+ * Retrieves the sum value of the specified column
757
+ * for this Query
758
+ *
759
+ * ```ts
760
+ * await Game.query().sum('score')
761
+ * // 1
762
+ * ```
763
+ *
764
+ * @param columnName - a column name on the model
765
+ * @returns the sum of the values of the specified column for this Query
766
+ */
767
+ sum<Q extends Query<DreamInstance, QueryTypeOpts>, DB extends DreamInstance['DB'], ColumnName extends ColumnNamesAccountingForJoinedAssociations<Q['queryTypeOpts']['joinedAssociations'], DB, QueryTypeOpts['rootTableName'], QueryTypeOpts['rootTableAlias']>, ReturnType extends NamespacedOrBaseModelColumnTypes<[ColumnName], Q, DreamInstance>[0]>(columnName: ColumnName): Promise<ReturnType>;
768
+ /**
769
+ * Retrieves the average value of the specified column
770
+ * for this Query
771
+ *
772
+ * ```ts
773
+ * await Game.query().avg('score')
774
+ * // 1
775
+ * ```
776
+ *
777
+ * @param columnName - a column name on the model
778
+ * @returns the average of the values of the specified column for this Query
779
+ */
780
+ avg<Q extends Query<DreamInstance, QueryTypeOpts>, DB extends DreamInstance['DB'], ColumnName extends ColumnNamesAccountingForJoinedAssociations<Q['queryTypeOpts']['joinedAssociations'], DB, QueryTypeOpts['rootTableName'], QueryTypeOpts['rootTableAlias']>, ReturnType extends NamespacedOrBaseModelColumnTypes<[ColumnName], Q, DreamInstance>[0]>(columnName: ColumnName): Promise<ReturnType>;
755
781
  /**
756
782
  * Plucks the provided fields from the given dream class table
757
783
  *
@@ -195,6 +195,32 @@ export default class QueryDriverBase<DreamInstance extends Dream> {
195
195
  * @returns the min value of the specified column for this Query
196
196
  */
197
197
  min(columnName: string): Promise<any>;
198
+ /**
199
+ * Retrieves the sum value of the specified column
200
+ * for this Query
201
+ *
202
+ * ```ts
203
+ * await Game.query().sum('score')
204
+ * // 1
205
+ * ```
206
+ *
207
+ * @param columnName - a column name on the model
208
+ * @returns the sum of the values of the specified column for this Query
209
+ */
210
+ sum(columnName: string): Promise<any>;
211
+ /**
212
+ * Retrieves the average value of the specified column
213
+ * for this Query
214
+ *
215
+ * ```ts
216
+ * await Game.query().avg('score')
217
+ * // 1
218
+ * ```
219
+ *
220
+ * @param columnName - a column name on the model
221
+ * @returns the average of the values of the specified column for this Query
222
+ */
223
+ avg(columnName: string): Promise<any>;
198
224
  /**
199
225
  * Retrieves the number of records in the database
200
226
  *