@rvoh/dream 1.4.2 → 1.5.1

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 (281) hide show
  1. package/dist/cjs/src/Dream.js +12 -16
  2. package/dist/cjs/src/bin/index.js +23 -7
  3. package/dist/cjs/src/cli/index.js +18 -3
  4. package/dist/cjs/src/db/ConnectedToDB.js +0 -8
  5. package/dist/cjs/src/db/DreamDbConnection.js +25 -36
  6. package/dist/cjs/src/db/helpers/dbTypesFilenameForConnection.js +6 -0
  7. package/dist/cjs/src/{bin/helpers/sync.js → db/helpers/syncDbTypesFiles.js} +8 -5
  8. package/dist/cjs/src/db/index.js +3 -2
  9. package/dist/cjs/src/db/migration-helpers/DreamMigrationHelpers.js +36 -0
  10. package/dist/cjs/src/decorators/field/sortable/helpers/setPosition.js +17 -2
  11. package/dist/cjs/src/dream/Query.js +9 -6
  12. package/dist/cjs/src/dream/QueryDriver/Base.js +111 -7
  13. package/dist/cjs/src/dream/QueryDriver/Kysely.js +213 -86
  14. package/dist/cjs/src/dream/QueryDriver/Postgres.js +162 -0
  15. package/dist/cjs/src/{helpers/db → dream/QueryDriver/helpers/kysely}/runMigration.js +22 -17
  16. package/dist/cjs/src/{helpers/db → dream/QueryDriver/helpers/pg}/createDb.js +5 -5
  17. package/dist/cjs/src/{helpers/db → dream/QueryDriver/helpers/pg}/dropDb.js +6 -6
  18. package/dist/cjs/src/{helpers/db → dream/QueryDriver/helpers/pg}/loadPgClient.js +5 -3
  19. package/dist/cjs/src/dream/internal/destroyDream.js +3 -10
  20. package/dist/cjs/src/dream/internal/saveDream.js +1 -1
  21. package/dist/cjs/src/dream/internal/similarity/SimilarityBuilder.js +9 -3
  22. package/dist/cjs/src/dream-app/index.js +47 -64
  23. package/dist/cjs/src/helpers/cli/SchemaBuilder.js +30 -42
  24. package/dist/cjs/src/helpers/cli/generateDream.js +2 -0
  25. package/dist/cjs/src/helpers/cli/generateDreamContent.js +5 -3
  26. package/dist/cjs/src/helpers/cli/generateFactoryContent.js +29 -0
  27. package/dist/cjs/src/helpers/cli/generateMigration.js +7 -5
  28. package/dist/cjs/src/helpers/cli/generateMigrationContent.js +48 -15
  29. package/dist/cjs/src/helpers/db/primaryKeyType.js +4 -22
  30. package/dist/cjs/src/helpers/sqlAttributes.js +4 -1
  31. package/dist/cjs/src/index.js +8 -2
  32. package/dist/esm/src/Dream.js +10 -14
  33. package/dist/esm/src/bin/index.js +23 -7
  34. package/dist/esm/src/cli/index.js +18 -3
  35. package/dist/esm/src/db/ConnectedToDB.js +0 -8
  36. package/dist/esm/src/db/DreamDbConnection.js +22 -34
  37. package/dist/esm/src/db/helpers/dbTypesFilenameForConnection.js +3 -0
  38. package/dist/esm/src/{bin/helpers/sync.js → db/helpers/syncDbTypesFiles.js} +7 -4
  39. package/dist/esm/src/db/index.js +3 -2
  40. package/dist/esm/src/db/migration-helpers/DreamMigrationHelpers.js +36 -0
  41. package/dist/esm/src/decorators/field/sortable/helpers/setPosition.js +16 -2
  42. package/dist/esm/src/dream/Query.js +9 -6
  43. package/dist/esm/src/dream/QueryDriver/Base.js +111 -7
  44. package/dist/esm/src/dream/QueryDriver/Kysely.js +215 -88
  45. package/dist/esm/src/dream/QueryDriver/Postgres.js +162 -0
  46. package/dist/esm/src/{helpers/db → dream/QueryDriver/helpers/kysely}/runMigration.js +16 -11
  47. package/dist/esm/src/{helpers/db → dream/QueryDriver/helpers/pg}/createDb.js +5 -5
  48. package/dist/esm/src/{helpers/db → dream/QueryDriver/helpers/pg}/dropDb.js +6 -6
  49. package/dist/esm/src/{helpers/db → dream/QueryDriver/helpers/pg}/loadPgClient.js +5 -3
  50. package/dist/esm/src/dream/internal/destroyDream.js +3 -10
  51. package/dist/esm/src/dream/internal/saveDream.js +1 -1
  52. package/dist/esm/src/dream/internal/similarity/SimilarityBuilder.js +9 -3
  53. package/dist/esm/src/dream-app/index.js +44 -61
  54. package/dist/esm/src/helpers/cli/SchemaBuilder.js +24 -36
  55. package/dist/esm/src/helpers/cli/generateDream.js +2 -0
  56. package/dist/esm/src/helpers/cli/generateDreamContent.js +5 -3
  57. package/dist/esm/src/helpers/cli/generateFactoryContent.js +29 -0
  58. package/dist/esm/src/helpers/cli/generateMigration.js +7 -5
  59. package/dist/esm/src/helpers/cli/generateMigrationContent.js +48 -15
  60. package/dist/esm/src/helpers/db/primaryKeyType.js +4 -22
  61. package/dist/esm/src/helpers/sqlAttributes.js +4 -1
  62. package/dist/esm/src/index.js +3 -0
  63. package/dist/types/src/Dream.d.ts +5 -3
  64. package/dist/types/src/bin/index.d.ts +3 -1
  65. package/dist/types/src/db/ConnectedToDB.d.ts +0 -2
  66. package/dist/types/src/db/DreamDbConnection.d.ts +7 -3
  67. package/dist/types/src/db/helpers/dbTypesFilenameForConnection.d.ts +1 -0
  68. package/dist/types/src/db/helpers/syncDbTypesFiles.d.ts +1 -0
  69. package/dist/types/src/db/index.d.ts +2 -1
  70. package/dist/types/src/db/migration-helpers/DreamMigrationHelpers.d.ts +36 -0
  71. package/dist/types/src/decorators/field/sortable/helpers/setPosition.d.ts +2 -0
  72. package/dist/types/src/dream/Query.d.ts +5 -20
  73. package/dist/types/src/dream/QueryDriver/Base.d.ts +74 -13
  74. package/dist/types/src/dream/QueryDriver/Kysely.d.ts +75 -9
  75. package/dist/types/src/dream/QueryDriver/Postgres.d.ts +32 -0
  76. package/dist/types/src/dream/QueryDriver/helpers/kysely/foreignKeyTypeFromPrimaryKey.d.ts +2 -0
  77. package/dist/types/src/dream/QueryDriver/helpers/kysely/runMigration.d.ts +9 -0
  78. package/dist/types/src/dream/QueryDriver/helpers/pg/createDb.d.ts +2 -0
  79. package/dist/types/src/dream/QueryDriver/helpers/pg/dropDb.d.ts +2 -0
  80. package/dist/types/src/dream/QueryDriver/helpers/pg/loadPgClient.d.ts +5 -0
  81. package/dist/types/src/dream/internal/destroyOptions.d.ts +3 -3
  82. package/dist/types/src/dream-app/index.d.ts +11 -6
  83. package/dist/types/src/helpers/cli/SchemaBuilder.d.ts +26 -0
  84. package/dist/types/src/helpers/cli/generateDream.d.ts +1 -0
  85. package/dist/types/src/helpers/cli/generateDreamContent.d.ts +2 -1
  86. package/dist/types/src/helpers/cli/generateMigration.d.ts +2 -1
  87. package/dist/types/src/helpers/cli/generateMigrationContent.d.ts +2 -1
  88. package/dist/types/src/helpers/db/primaryKeyType.d.ts +1 -1
  89. package/dist/types/src/index.d.ts +3 -0
  90. package/dist/types/src/types/dream.d.ts +4 -4
  91. package/dist/types/src/types/dream.ts +8 -9
  92. package/docs/assets/navigation.js +1 -1
  93. package/docs/assets/search.js +1 -1
  94. package/docs/classes/Benchmark.html +2 -2
  95. package/docs/classes/CalendarDate.html +2 -2
  96. package/docs/classes/CheckConstraintViolation.html +3 -3
  97. package/docs/classes/CliFileWriter.html +2 -2
  98. package/docs/classes/CreateOrFindByFailedToCreateAndFind.html +3 -3
  99. package/docs/classes/DataTypeColumnTypeMismatch.html +3 -3
  100. package/docs/classes/Decorators.html +19 -19
  101. package/docs/classes/Dream.html +117 -115
  102. package/docs/classes/DreamApp.html +8 -5
  103. package/docs/classes/DreamBin.html +2 -2
  104. package/docs/classes/DreamCLI.html +4 -4
  105. package/docs/classes/DreamImporter.html +2 -2
  106. package/docs/classes/DreamLogos.html +2 -2
  107. package/docs/classes/DreamMigrationHelpers.html +19 -7
  108. package/docs/classes/DreamSerializerBuilder.html +8 -8
  109. package/docs/classes/DreamTransaction.html +2 -2
  110. package/docs/classes/Encrypt.html +2 -2
  111. package/docs/classes/Env.html +2 -2
  112. package/docs/classes/GlobalNameNotSet.html +3 -3
  113. package/docs/classes/KyselyQueryDriver.html +163 -0
  114. package/docs/classes/NonLoadedAssociation.html +3 -3
  115. package/docs/classes/NotNullViolation.html +3 -3
  116. package/docs/classes/ObjectSerializerBuilder.html +8 -8
  117. package/docs/classes/PostgresQueryDriver.html +165 -0
  118. package/docs/classes/Query.html +59 -87
  119. package/docs/classes/QueryDriverBase.html +156 -0
  120. package/docs/classes/Range.html +2 -2
  121. package/docs/classes/RecordNotFound.html +3 -3
  122. package/docs/classes/ValidationError.html +3 -3
  123. package/docs/functions/DreamSerializer.html +1 -1
  124. package/docs/functions/ObjectSerializer.html +1 -1
  125. package/docs/functions/ReplicaSafe.html +1 -1
  126. package/docs/functions/STI.html +1 -1
  127. package/docs/functions/SoftDelete.html +1 -1
  128. package/docs/functions/camelize.html +1 -1
  129. package/docs/functions/capitalize.html +1 -1
  130. package/docs/functions/cloneDeepSafe.html +1 -1
  131. package/docs/functions/closeAllDbConnections.html +1 -1
  132. package/docs/functions/compact.html +1 -1
  133. package/docs/functions/dreamDbConnections.html +1 -1
  134. package/docs/functions/dreamPath.html +1 -1
  135. package/docs/functions/expandStiClasses.html +1 -1
  136. package/docs/functions/generateDream.html +1 -1
  137. package/docs/functions/globalClassNameFromFullyQualifiedModelName.html +1 -1
  138. package/docs/functions/groupBy.html +1 -1
  139. package/docs/functions/hyphenize.html +1 -1
  140. package/docs/functions/inferSerializerFromDreamOrViewModel.html +1 -1
  141. package/docs/functions/inferSerializersFromDreamClassOrViewModelClass.html +1 -1
  142. package/docs/functions/intersection.html +1 -1
  143. package/docs/functions/isDreamSerializer.html +1 -1
  144. package/docs/functions/isEmpty.html +1 -1
  145. package/docs/functions/loadRepl.html +1 -1
  146. package/docs/functions/lookupClassByGlobalName.html +1 -1
  147. package/docs/functions/normalizeUnicode.html +1 -1
  148. package/docs/functions/pascalize.html +1 -1
  149. package/docs/functions/pgErrorType.html +1 -1
  150. package/docs/functions/range-1.html +1 -1
  151. package/docs/functions/relativeDreamPath.html +1 -1
  152. package/docs/functions/round.html +1 -1
  153. package/docs/functions/serializerNameFromFullyQualifiedModelName.html +1 -1
  154. package/docs/functions/sharedPathPrefix.html +1 -1
  155. package/docs/functions/snakeify.html +1 -1
  156. package/docs/functions/sort.html +1 -1
  157. package/docs/functions/sortBy.html +1 -1
  158. package/docs/functions/sortObjectByKey.html +1 -1
  159. package/docs/functions/sortObjectByValue.html +1 -1
  160. package/docs/functions/standardizeFullyQualifiedModelName.html +1 -1
  161. package/docs/functions/uncapitalize.html +1 -1
  162. package/docs/functions/uniq.html +1 -1
  163. package/docs/functions/untypedDb.html +1 -1
  164. package/docs/functions/validateColumn.html +1 -1
  165. package/docs/functions/validateTable.html +1 -1
  166. package/docs/hierarchy.html +1 -0
  167. package/docs/interfaces/BelongsToStatement.html +2 -2
  168. package/docs/interfaces/DecoratorContext.html +2 -2
  169. package/docs/interfaces/DreamAppInitOptions.html +2 -2
  170. package/docs/interfaces/DreamAppOpts.html +2 -2
  171. package/docs/interfaces/EncryptOptions.html +2 -2
  172. package/docs/interfaces/InternalAnyTypedSerializerRendersMany.html +2 -2
  173. package/docs/interfaces/InternalAnyTypedSerializerRendersOne.html +2 -2
  174. package/docs/interfaces/OpenapiDescription.html +2 -2
  175. package/docs/interfaces/OpenapiSchemaProperties.html +1 -1
  176. package/docs/interfaces/OpenapiSchemaPropertiesShorthand.html +1 -1
  177. package/docs/interfaces/OpenapiTypeFieldObject.html +1 -1
  178. package/docs/interfaces/SerializerRendererOpts.html +2 -2
  179. package/docs/modules.html +3 -0
  180. package/docs/types/Camelized.html +1 -1
  181. package/docs/types/CommonOpenapiSchemaObjectFields.html +1 -1
  182. package/docs/types/DateTime.html +1 -1
  183. package/docs/types/DbConnectionType.html +1 -1
  184. package/docs/types/DbTypes.html +1 -1
  185. package/docs/types/DreamAppAllowedPackageManagersEnum.html +1 -1
  186. package/docs/types/DreamAssociationMetadata.html +1 -1
  187. package/docs/types/DreamAttributes.html +1 -1
  188. package/docs/types/DreamClassAssociationAndStatement.html +1 -1
  189. package/docs/types/DreamClassColumn.html +1 -1
  190. package/docs/types/DreamColumn.html +1 -1
  191. package/docs/types/DreamColumnNames.html +1 -1
  192. package/docs/types/DreamLogLevel.html +1 -1
  193. package/docs/types/DreamLogger.html +1 -1
  194. package/docs/types/DreamModelSerializerType.html +1 -1
  195. package/docs/types/DreamOrViewModelClassSerializerKey.html +1 -1
  196. package/docs/types/DreamOrViewModelSerializerKey.html +1 -1
  197. package/docs/types/DreamParamSafeAttributes.html +1 -1
  198. package/docs/types/DreamParamSafeColumnNames.html +1 -1
  199. package/docs/types/DreamSerializable.html +1 -1
  200. package/docs/types/DreamSerializableArray.html +1 -1
  201. package/docs/types/DreamSerializerKey.html +1 -1
  202. package/docs/types/DreamSerializers.html +1 -1
  203. package/docs/types/DreamVirtualColumns.html +1 -1
  204. package/docs/types/EncryptAlgorithm.html +1 -1
  205. package/docs/types/HasManyStatement.html +1 -1
  206. package/docs/types/HasOneStatement.html +1 -1
  207. package/docs/types/Hyphenized.html +1 -1
  208. package/docs/types/OpenapiAllTypes.html +1 -1
  209. package/docs/types/OpenapiFormats.html +1 -1
  210. package/docs/types/OpenapiNumberFormats.html +1 -1
  211. package/docs/types/OpenapiPrimitiveBaseTypes.html +1 -1
  212. package/docs/types/OpenapiPrimitiveTypes.html +1 -1
  213. package/docs/types/OpenapiSchemaArray.html +1 -1
  214. package/docs/types/OpenapiSchemaArrayShorthand.html +1 -1
  215. package/docs/types/OpenapiSchemaBase.html +1 -1
  216. package/docs/types/OpenapiSchemaBody.html +1 -1
  217. package/docs/types/OpenapiSchemaBodyShorthand.html +1 -1
  218. package/docs/types/OpenapiSchemaCommonFields.html +1 -1
  219. package/docs/types/OpenapiSchemaExpressionAllOf.html +1 -1
  220. package/docs/types/OpenapiSchemaExpressionAnyOf.html +1 -1
  221. package/docs/types/OpenapiSchemaExpressionOneOf.html +1 -1
  222. package/docs/types/OpenapiSchemaExpressionRef.html +1 -1
  223. package/docs/types/OpenapiSchemaExpressionRefSchemaShorthand.html +1 -1
  224. package/docs/types/OpenapiSchemaInteger.html +1 -1
  225. package/docs/types/OpenapiSchemaNull.html +1 -1
  226. package/docs/types/OpenapiSchemaNumber.html +1 -1
  227. package/docs/types/OpenapiSchemaObject.html +1 -1
  228. package/docs/types/OpenapiSchemaObjectAllOf.html +1 -1
  229. package/docs/types/OpenapiSchemaObjectAllOfShorthand.html +1 -1
  230. package/docs/types/OpenapiSchemaObjectAnyOf.html +1 -1
  231. package/docs/types/OpenapiSchemaObjectAnyOfShorthand.html +1 -1
  232. package/docs/types/OpenapiSchemaObjectBase.html +1 -1
  233. package/docs/types/OpenapiSchemaObjectBaseShorthand.html +1 -1
  234. package/docs/types/OpenapiSchemaObjectOneOf.html +1 -1
  235. package/docs/types/OpenapiSchemaObjectOneOfShorthand.html +1 -1
  236. package/docs/types/OpenapiSchemaObjectShorthand.html +1 -1
  237. package/docs/types/OpenapiSchemaPrimitiveGeneric.html +1 -1
  238. package/docs/types/OpenapiSchemaShorthandExpressionAllOf.html +1 -1
  239. package/docs/types/OpenapiSchemaShorthandExpressionAnyOf.html +1 -1
  240. package/docs/types/OpenapiSchemaShorthandExpressionOneOf.html +1 -1
  241. package/docs/types/OpenapiSchemaShorthandExpressionSerializableRef.html +1 -1
  242. package/docs/types/OpenapiSchemaShorthandExpressionSerializerRef.html +1 -1
  243. package/docs/types/OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
  244. package/docs/types/OpenapiSchemaString.html +1 -1
  245. package/docs/types/OpenapiShorthandAllTypes.html +1 -1
  246. package/docs/types/OpenapiShorthandPrimitiveBaseTypes.html +1 -1
  247. package/docs/types/OpenapiShorthandPrimitiveTypes.html +1 -1
  248. package/docs/types/OpenapiTypeField.html +1 -1
  249. package/docs/types/Pascalized.html +1 -1
  250. package/docs/types/RoundingPrecision.html +1 -1
  251. package/docs/types/SerializerCasing.html +1 -1
  252. package/docs/types/SimpleObjectSerializerType.html +1 -1
  253. package/docs/types/Snakeified.html +1 -1
  254. package/docs/types/UpdateableAssociationProperties.html +1 -1
  255. package/docs/types/UpdateableProperties.html +1 -1
  256. package/docs/types/ValidationType.html +1 -1
  257. package/docs/types/ViewModel.html +1 -1
  258. package/docs/types/ViewModelClass.html +1 -1
  259. package/docs/types/WhereStatementForDream.html +1 -1
  260. package/docs/types/WhereStatementForDreamClass.html +1 -1
  261. package/docs/variables/DateTime-1.html +1 -1
  262. package/docs/variables/DreamAppAllowedPackageManagersEnumValues.html +1 -1
  263. package/docs/variables/DreamConst.html +1 -1
  264. package/docs/variables/TRIGRAM_OPERATORS.html +1 -1
  265. package/docs/variables/openapiPrimitiveTypes-1.html +1 -1
  266. package/docs/variables/openapiShorthandPrimitiveTypes-1.html +1 -1
  267. package/docs/variables/ops.html +1 -1
  268. package/docs/variables/primaryKeyTypes.html +1 -1
  269. package/package.json +4 -3
  270. package/CHANGELOG.md +0 -100
  271. package/dist/cjs/src/helpers/db/truncateDb.js +0 -27
  272. package/dist/esm/src/helpers/db/truncateDb.js +0 -24
  273. package/dist/types/src/bin/helpers/sync.d.ts +0 -1
  274. package/dist/types/src/helpers/db/createDb.d.ts +0 -2
  275. package/dist/types/src/helpers/db/dropDb.d.ts +0 -2
  276. package/dist/types/src/helpers/db/foreignKeyTypeFromPrimaryKey.d.ts +0 -2
  277. package/dist/types/src/helpers/db/loadPgClient.d.ts +0 -4
  278. package/dist/types/src/helpers/db/runMigration.d.ts +0 -6
  279. package/dist/types/src/helpers/db/truncateDb.d.ts +0 -1
  280. /package/dist/cjs/src/{helpers/db → dream/QueryDriver/helpers/kysely}/foreignKeyTypeFromPrimaryKey.js +0 -0
  281. /package/dist/esm/src/{helpers/db → dream/QueryDriver/helpers/kysely}/foreignKeyTypeFromPrimaryKey.js +0 -0
@@ -2,15 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const yoctocolors_1 = require("yoctocolors");
4
4
  const errors_js_1 = require("./db/errors.js");
5
- const index_js_1 = require("./db/index.js");
6
5
  const associationToGetterSetterProp_js_1 = require("./decorators/field/association/associationToGetterSetterProp.js");
7
6
  const shared_js_1 = require("./decorators/field/association/shared.js");
8
7
  const shared_js_2 = require("./decorators/field/lifecycle/shared.js");
9
8
  const resortAllRecords_js_1 = require("./decorators/field/sortable/helpers/resortAllRecords.js");
10
- const index_js_2 = require("./dream-app/index.js");
9
+ const index_js_1 = require("./dream-app/index.js");
11
10
  const DreamClassTransactionBuilder_js_1 = require("./dream/DreamClassTransactionBuilder.js");
12
11
  const DreamInstanceTransactionBuilder_js_1 = require("./dream/DreamInstanceTransactionBuilder.js");
13
- const DreamTransaction_js_1 = require("./dream/DreamTransaction.js");
14
12
  const associationQuery_js_1 = require("./dream/internal/associations/associationQuery.js");
15
13
  const associationUpdateQuery_js_1 = require("./dream/internal/associations/associationUpdateQuery.js");
16
14
  const createAssociation_js_1 = require("./dream/internal/associations/createAssociation.js");
@@ -108,8 +106,14 @@ class Dream {
108
106
  get schema() {
109
107
  throw new DreamMissingRequiredOverride_js_1.default(this.constructor, 'schema');
110
108
  }
111
- get globalSchema() {
112
- throw new DreamMissingRequiredOverride_js_1.default(this.constructor, 'globalSchema');
109
+ get connectionName() {
110
+ return 'default';
111
+ }
112
+ get connectionTypeConfig() {
113
+ throw new DreamMissingRequiredOverride_js_1.default(this.constructor, 'connectionTypeConfig');
114
+ }
115
+ get globalTypeConfig() {
116
+ throw new DreamMissingRequiredOverride_js_1.default(this.constructor, 'globalTypeConfig');
113
117
  }
114
118
  /**
115
119
  * Determines if the provided Dream class is the same as or a subclass of this Dream class.
@@ -842,7 +846,7 @@ class Dream {
842
846
  * @returns the found model or serializer, depending on what you are looking for
843
847
  */
844
848
  static lookup(lookupName) {
845
- const dreamApp = index_js_2.default.getOrFail();
849
+ const dreamApp = index_js_1.default.getOrFail();
846
850
  const models = dreamApp.models;
847
851
  const serializers = dreamApp.serializers;
848
852
  return models[lookupName] || serializers[lookupName];
@@ -1733,16 +1737,8 @@ class Dream {
1733
1737
  * @returns void
1734
1738
  */
1735
1739
  static async transaction(callback) {
1736
- const dreamTransaction = new DreamTransaction_js_1.default();
1737
- let callbackResponse = undefined;
1738
- await (0, index_js_1.default)('primary')
1739
- .transaction()
1740
- .execute(async (kyselyTransaction) => {
1741
- dreamTransaction.kyselyTransaction = kyselyTransaction;
1742
- callbackResponse = (await callback(dreamTransaction));
1743
- });
1744
- await dreamTransaction.runAfterCommitHooks(dreamTransaction);
1745
- return callbackResponse;
1740
+ const dbDriverClass = Query_js_1.default.dbDriverClass(this.prototype.connectionName);
1741
+ return (await dbDriverClass.transaction(this.prototype, callback));
1746
1742
  }
1747
1743
  /**
1748
1744
  * Sends data through for use as passthrough data
@@ -1,24 +1,40 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const index_js_1 = require("../cli/index.js");
4
+ const index_js_2 = require("../dream-app/index.js");
4
5
  const Query_js_1 = require("../dream/Query.js");
5
6
  const generateDream_js_1 = require("../helpers/cli/generateDream.js");
6
7
  const sspawn_js_1 = require("../helpers/sspawn.js");
7
8
  class DreamBin {
8
9
  static async sync(onSync, options) {
9
- await Query_js_1.default.dbDriverClass().sync(onSync, options);
10
+ const dreamApp = index_js_2.default.getOrFail();
11
+ for (const connectionName of Object.keys(dreamApp.dbCredentials)) {
12
+ await Query_js_1.default.dbDriverClass(connectionName).sync(connectionName, onSync, options);
13
+ }
10
14
  }
11
15
  static async dbCreate() {
12
- await Query_js_1.default.dbDriverClass().dbCreate();
16
+ const dreamApp = index_js_2.default.getOrFail();
17
+ for (const connectionName of Object.keys(dreamApp.dbCredentials)) {
18
+ await Query_js_1.default.dbDriverClass(connectionName).dbCreate(connectionName);
19
+ }
13
20
  }
14
21
  static async dbDrop() {
15
- await Query_js_1.default.dbDriverClass().dbDrop();
22
+ const dreamApp = index_js_2.default.getOrFail();
23
+ for (const connectionName of Object.keys(dreamApp.dbCredentials)) {
24
+ await Query_js_1.default.dbDriverClass(connectionName).dbDrop(connectionName);
25
+ }
16
26
  }
17
27
  static async dbMigrate() {
18
- await Query_js_1.default.dbDriverClass().migrate();
28
+ const dreamApp = index_js_2.default.getOrFail();
29
+ for (const connectionName of Object.keys(dreamApp.dbCredentials)) {
30
+ await Query_js_1.default.dbDriverClass(connectionName).migrate(connectionName);
31
+ }
19
32
  }
20
33
  static async dbRollback(opts) {
21
- await Query_js_1.default.dbDriverClass().rollback(opts);
34
+ const dreamApp = index_js_2.default.getOrFail();
35
+ for (const connectionName of Object.keys(dreamApp.dbCredentials)) {
36
+ await Query_js_1.default.dbDriverClass(connectionName).rollback({ ...opts, connectionName });
37
+ }
22
38
  }
23
39
  static async generateDream(fullyQualifiedModelName, columnsWithTypes, options) {
24
40
  await (0, generateDream_js_1.default)({
@@ -35,8 +51,8 @@ class DreamBin {
35
51
  fullyQualifiedParentName,
36
52
  });
37
53
  }
38
- static async generateMigration(migrationName, columnsWithTypes) {
39
- await Query_js_1.default.dbDriverClass().generateMigration(migrationName, columnsWithTypes);
54
+ static async generateMigration(migrationName, columnsWithTypes, connectionName) {
55
+ await Query_js_1.default.dbDriverClass(connectionName).generateMigration(connectionName, migrationName, columnsWithTypes);
40
56
  }
41
57
  // though this is a private method, it is still used internally.
42
58
  // It is only made private so that people don't mistakenly try
@@ -15,25 +15,37 @@ ${INDENT} subtitle:string:optional
15
15
  ${INDENT}
16
16
  ${INDENT}supported types:
17
17
  ${INDENT} - citext:
18
+ ${INDENT} - citext[]:
18
19
  ${INDENT} case insensitive text (indexes and queries are automatically case insensitive)
19
20
  ${INDENT}
20
21
  ${INDENT} - string:
22
+ ${INDENT} - string[]:
21
23
  ${INDENT} varchar; allowed length defaults to 255, but may be customized, e.g.: subtitle:string:128 or subtitle:string:128:optional
22
24
  ${INDENT}
23
25
  ${INDENT} - text
26
+ ${INDENT} - text[]
24
27
  ${INDENT} - date
28
+ ${INDENT} - date[]
25
29
  ${INDENT} - datetime
30
+ ${INDENT} - datetime[]
26
31
  ${INDENT} - integer
32
+ ${INDENT} - integer[]
27
33
  ${INDENT}
28
34
  ${INDENT} - decimal:
35
+ ${INDENT} - decimal[]:
29
36
  ${INDENT} scale,precision is required, e.g.: volume:decimal:3,2 or volume:decimal:3,2:optional
37
+ ${INDENT}
38
+ ${INDENT} leveraging arrays, add the "[]" suffix, e.g.: volume:decimal[]:3,2
30
39
  ${INDENT}
31
40
  ${INDENT} - enum:
41
+ ${INDENT} - enum[]:
32
42
  ${INDENT} include the enum name to automatically create the enum:
33
43
  ${INDENT} type:enum:room_types:bathroom,kitchen,bedroom or type:enum:room_types:bathroom,kitchen,bedroom:optional
34
44
  ${INDENT}
35
45
  ${INDENT} omit the enum values to leverage an existing enum (omits the enum type creation):
36
- ${INDENT} type:enum:room_types or type:enum:room_types:optional`;
46
+ ${INDENT} type:enum:room_types or type:enum:room_types:optional
47
+ ${INDENT}
48
+ ${INDENT} leveraging arrays, add the "[]" suffix, e.g.: type:enum[]:room_types:bathroom,kitchen,bedroom`;
37
49
  const columnsWithTypesDescription = baseColumnsWithTypesDescription +
38
50
  `
39
51
  ${INDENT}
@@ -80,10 +92,11 @@ class DreamCLI {
80
92
  .alias('g:migration')
81
93
  .description('create a new migration')
82
94
  .argument('<migrationName>', 'end with -to-table-name to prepopulate with an alterTable command')
95
+ .option('--connection-name <connectionName>', 'the connection name you wish to use for your migration')
83
96
  .argument('[columnsWithTypes...]', columnsWithTypesDescriptionForMigration)
84
- .action(async (migrationName, columnsWithTypes) => {
97
+ .action(async (migrationName, columnsWithTypes, options) => {
85
98
  await initializeDreamApp();
86
- await index_js_1.default.generateMigration(migrationName, columnsWithTypes);
99
+ await index_js_1.default.generateMigration(migrationName, columnsWithTypes, options.connectionName || 'default');
87
100
  process.exit();
88
101
  });
89
102
  program
@@ -92,6 +105,7 @@ class DreamCLI {
92
105
  .alias('generate:dream')
93
106
  .alias('g:dream')
94
107
  .option('--no-serializer')
108
+ .option('--connection-name <connectionName>', 'the db connection you want this attached to (defaults to the default db connection)', 'default')
95
109
  .option('--sti-base-serializer')
96
110
  .description('create a new Dream model')
97
111
  .argument('<modelName>', 'the name of the model to create, e.g. Post or Settings/CommunicationPreferences')
@@ -106,6 +120,7 @@ class DreamCLI {
106
120
  .alias('g:sti-child')
107
121
  .description('create a new Dream model that extends another Dream model, leveraging STI (single table inheritance)')
108
122
  .option('--no-serializer')
123
+ .option('--connection-name', 'the db connection you want this model attached to (defaults to the default connection)', 'default')
109
124
  .argument('<childModelName>', 'the name of the model to create, e.g. Post or Settings/CommunicationPreferences')
110
125
  .argument('<extends>', 'just the word "extends"')
111
126
  .argument('<parentModelName>', `fully qualified name of the parent model, e.g.:
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const index_js_1 = require("../db/index.js");
4
3
  class ConnectedToDB {
5
4
  dreamInstance;
6
5
  dreamClass;
@@ -29,13 +28,6 @@ class ConnectedToDB {
29
28
  return 'primary';
30
29
  }
31
30
  }
32
- // ATTENTION FRED
33
- // stop trying to make this async. You never learn...
34
- dbFor(sqlCommandType) {
35
- if (this.dreamTransaction?.kyselyTransaction)
36
- return this.dreamTransaction?.kyselyTransaction;
37
- return (0, index_js_1.default)(this.dbConnectionType(sqlCommandType));
38
- }
39
31
  isReplicaSafe() {
40
32
  return this.innerJoinDreamClasses.reduce((accumulator, dreamClass) => accumulator && dreamClass['replicaSafe'], this.dreamClass['replicaSafe']);
41
33
  }
@@ -1,7 +1,4 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dreamDbConnections = dreamDbConnections;
4
- exports.closeAllDbConnections = closeAllDbConnections;
5
2
  // after building for esm, importing pg using the following:
6
3
  //
7
4
  // import * as pg from 'pg'
@@ -10,19 +7,23 @@ exports.closeAllDbConnections = closeAllDbConnections;
10
7
  // when being imported from our esm build.
11
8
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
12
9
  // @ts-ignore
13
- const pg_1 = require("pg");
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.dreamDbConnections = dreamDbConnections;
12
+ exports.closeAllDbConnections = closeAllDbConnections;
13
+ exports.closeAllConnectionsForConnectionName = closeAllConnectionsForConnectionName;
14
14
  const kysely_1 = require("kysely");
15
15
  const index_js_1 = require("../dream-app/index.js");
16
+ const protectAgainstPollutingAssignment_js_1 = require("../helpers/protectAgainstPollutingAssignment.js");
16
17
  let connections = {};
17
18
  class DreamDbConnection {
18
- static getConnection(connectionType) {
19
+ static getConnection(connectionName, connectionType, dialectProvider) {
19
20
  const dreamApp = index_js_1.default.getOrFail();
20
- const connectionName = this.getConnectionTypeName(connectionType);
21
- const connection = connections[connectionName];
21
+ const connectionTypeName = this.getConnectionTypeName(connectionType);
22
+ const connection = connections[connectionName]?.[connectionTypeName];
22
23
  if (connection) {
23
24
  return connection;
24
25
  }
25
- const connectionConf = dreamApp.dbConnectionConfig(connectionType);
26
+ const connectionConf = dreamApp.dbConnectionConfig(connectionName, connectionType);
26
27
  const dbConn = new kysely_1.Kysely({
27
28
  log(event) {
28
29
  const dreamApp = index_js_1.default.getOrFail();
@@ -30,27 +31,14 @@ class DreamDbConnection {
30
31
  fn(event);
31
32
  });
32
33
  },
33
- dialect: new kysely_1.PostgresDialect({
34
- pool: new pg_1.default.Pool({
35
- user: connectionConf.user || '',
36
- password: connectionConf.password || '',
37
- database: dreamApp.dbName(connectionType),
38
- host: connectionConf.host || 'localhost',
39
- port: connectionConf.port || 5432,
40
- ssl: connectionConf.useSsl ? sslConfig(connectionConf) : false,
41
- }),
42
- }),
34
+ dialect: dialectProvider(connectionConf),
43
35
  plugins: [new kysely_1.CamelCasePlugin({ underscoreBetweenUppercaseLetters: true })],
44
36
  });
45
- connections[this.getConnectionTypeName(connectionType)] = dbConn;
37
+ const protectedName = (0, protectAgainstPollutingAssignment_js_1.default)(connectionName);
38
+ connections[protectedName] ||= {};
39
+ connections[protectedName][this.getConnectionTypeName(connectionType)] = dbConn;
46
40
  return dbConn;
47
41
  }
48
- static async dropAllConnections() {
49
- for (const key of Object.keys(connections)) {
50
- await connections[key]?.destroy();
51
- delete connections[key];
52
- }
53
- }
54
42
  static getConnectionTypeName(connectionType) {
55
43
  return index_js_1.default.getOrFail().parallelDatabasesEnabled
56
44
  ? `${connectionType}_${process.env.VITEST_POOL_ID}`
@@ -58,20 +46,21 @@ class DreamDbConnection {
58
46
  }
59
47
  }
60
48
  exports.default = DreamDbConnection;
61
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
62
- function sslConfig(connectionConf) {
63
- // TODO: properly configure (https://rvohealth.atlassian.net/browse/PDTC-2914)
64
- return {
65
- rejectUnauthorized: false,
66
- // ca: fs.readFileSync('/path/to/server-certificates/root.crt').toString(),
67
- // key: fs.readFileSync('/path/to/client-key/postgresql.key').toString(),
68
- // cert: fs.readFileSync('/path/to/client-certificates/postgresql.crt').toString(),
69
- };
70
- }
71
49
  function dreamDbConnections() {
72
50
  return connections;
73
51
  }
74
52
  async function closeAllDbConnections() {
75
- await Promise.all(Object.values(connections).map(conn => conn.destroy()));
53
+ const connectionNames = Object.keys(connections);
54
+ for (const connectionName of connectionNames) {
55
+ await closeAllConnectionsForConnectionName(connectionName);
56
+ }
76
57
  connections = {};
77
58
  }
59
+ async function closeAllConnectionsForConnectionName(connectionName) {
60
+ const protectedName = (0, protectAgainstPollutingAssignment_js_1.default)(connectionName);
61
+ return await Promise.allSettled(Object.keys(connections[protectedName]).map(async (key) => {
62
+ const conn = connections[protectedName][key];
63
+ await conn.destroy();
64
+ delete connections[protectedName][key];
65
+ }));
66
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = dbTypesFilenameForConnection;
4
+ function dbTypesFilenameForConnection(connectionName) {
5
+ return connectionName === 'default' ? 'db.ts' : `db.${connectionName}.ts`;
6
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = writeSyncFile;
3
+ exports.default = syncDbTypesFiles;
4
4
  const fs = require("node:fs/promises");
5
5
  const path = require("node:path");
6
6
  const CliFileWriter_js_1 = require("../../cli/CliFileWriter.js");
@@ -13,13 +13,16 @@ const EnvInternal_js_1 = require("../../helpers/EnvInternal.js");
13
13
  const dreamPath_js_1 = require("../../helpers/path/dreamPath.js");
14
14
  const snakeify_js_1 = require("../../helpers/snakeify.js");
15
15
  const sspawn_js_1 = require("../../helpers/sspawn.js");
16
- async function writeSyncFile() {
16
+ const dbTypesFilenameForConnection_js_1 = require("./dbTypesFilenameForConnection.js");
17
+ async function syncDbTypesFiles(connectionName) {
17
18
  const dreamApp = index_js_2.default.getOrFail();
18
- const dbConf = dreamApp.dbConnectionConfig('primary');
19
- const dbSyncFilePath = path.join((0, dreamPath_js_1.default)('types'), 'db.ts');
19
+ const dbConf = dreamApp.dbConnectionConfig(connectionName, 'primary');
20
+ const driverClass = dreamApp.dbConnectionQueryDriverClass(connectionName);
21
+ const dbFilename = (0, dbTypesFilenameForConnection_js_1.default)(connectionName);
22
+ const dbSyncFilePath = path.join((0, dreamPath_js_1.default)('types'), dbFilename);
20
23
  const absoluteDbSyncPath = path.join(dreamApp.projectRoot, dbSyncFilePath);
21
24
  await CliFileWriter_js_1.CliFileWriter.cache(absoluteDbSyncPath);
22
- await (0, sspawn_js_1.default)(`kysely-codegen --dialect=postgres --url=postgres://${dbConf.user}:${dbConf.password}@${dbConf.host}:${dbConf.port}/${dbConf.name} --out-file=${absoluteDbSyncPath}`, {
25
+ await (0, sspawn_js_1.default)(`kysely-codegen --dialect=${driverClass.syncDialect} --url=${driverClass.syncDialect}://${dbConf.user}:${dbConf.password}@${dbConf.host}:${dbConf.port}/${dbConf.name} --out-file=${absoluteDbSyncPath}`, {
23
26
  onStdout: message => {
24
27
  index_js_1.default.logger.logContinueProgress((0, colorize_js_1.default)(`[db]`, { color: 'cyan' }) + ' ' + message, {
25
28
  logPrefixColor: 'cyan',
@@ -4,8 +4,9 @@ exports.default = db;
4
4
  const DateTime_js_1 = require("../helpers/DateTime.js");
5
5
  const EnvInternal_js_1 = require("../helpers/EnvInternal.js");
6
6
  const DreamDbConnection_js_1 = require("./DreamDbConnection.js");
7
+ const Postgres_js_1 = require("../dream/QueryDriver/Postgres.js");
7
8
  if (EnvInternal_js_1.default.string('TZ', { optional: true }))
8
9
  DateTime_js_1.Settings.defaultZone = EnvInternal_js_1.default.string('TZ');
9
- function db(connectionType = 'primary') {
10
- return DreamDbConnection_js_1.default.getConnection(connectionType);
10
+ function db(connectionName = 'default', connectionType = 'primary', dialectProvider = Postgres_js_1.default.dialectProvider(connectionName, connectionType)) {
11
+ return DreamDbConnection_js_1.default.getConnection(connectionName, connectionType, dialectProvider);
11
12
  }
@@ -94,6 +94,42 @@ class DreamMigrationHelpers {
94
94
  ALTER TABLE ${kysely_1.sql.table(table)} DROP CONSTRAINT IF EXISTS ${kysely_1.sql.table(constraintName)};
95
95
  `.execute(db);
96
96
  }
97
+ /**
98
+ * Forces a new transaction boundary in migration execution.
99
+ *
100
+ * When called in a migration file, this method ensures that any existing transaction
101
+ * is committed before this migration runs, and a new transaction is started before the
102
+ * migration in this file. This is essential for migrations that depend on previously
103
+ * committed changes.
104
+ *
105
+ * Some database operations require that dependent changes be committed before they can
106
+ * be executed. For example, check constraints that reference enum values require those
107
+ * enum values to be committed to the database first.
108
+ *
109
+ * ```ts
110
+ * // first migration file: Add enum value
111
+ * export async function up(db: Kysely<any>): Promise<void> {
112
+ * await DreamMigrationHelpers.addEnumValue(db, {
113
+ * enumName: 'user_status',
114
+ * value: 'premium'
115
+ * })
116
+ * }
117
+ *
118
+ * // second migration file: Add check constraint that depends on the enum value
119
+ * export async function up(db: Kysely<any>): Promise<void> {
120
+ * DreamMigrationHelpers.newTransaction() // Ensure enum value is committed first
121
+ *
122
+ * await db.schema
123
+ * .alterTable('users')
124
+ * .addCheckConstraint(
125
+ * 'check_premium_users',
126
+ * sql`status = 'premium' OR credits < 100`
127
+ * )
128
+ * .execute()
129
+ * }
130
+ * ```
131
+ */
132
+ static newTransaction() { }
97
133
  /**
98
134
  * Drop a value from an enum and replace it (or optionally remove it from array columns)
99
135
  *
@@ -2,7 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = setPosition;
4
4
  exports.applySortableScopesToQuery = applySortableScopesToQuery;
5
- const index_js_1 = require("../../../../db/index.js");
5
+ exports.getPostgresQueryDriver = getPostgresQueryDriver;
6
+ const index_js_1 = require("../../../../dream-app/index.js");
7
+ const Postgres_js_1 = require("../../../../dream/QueryDriver/Postgres.js");
6
8
  const range_js_1 = require("../../../../helpers/range.js");
7
9
  const getColumnForSortableScope_js_1 = require("./getColumnForSortableScope.js");
8
10
  const scopeArray_js_1 = require("./scopeArray.js");
@@ -79,7 +81,10 @@ async function applyUpdates({ position, previousPosition, dream, positionField,
79
81
  }
80
82
  async function setNewPosition({ dream, positionField, query, scope, previousPosition, txn, }) {
81
83
  const newPosition = (await (0, sortableQueryExcludingDream_js_1.default)(dream, query, scope).max(positionField)) + 1;
82
- const dbOrTxn = txn ? txn.kyselyTransaction : (0, index_js_1.default)('primary');
84
+ const queryDriverClass = getPostgresQueryDriver(dream.connectionName || 'default');
85
+ const dbOrTxn = txn
86
+ ? txn.kyselyTransaction
87
+ : queryDriverClass.dbFor(dream.connectionName || 'default', 'primary');
83
88
  await dbOrTxn
84
89
  .updateTable(dream.table)
85
90
  .where(dream['_primaryKey'], '=', dream.primaryKeyValue())
@@ -156,3 +161,13 @@ async function updatePositionForRecord(txn, dream, positionField, position) {
156
161
  })
157
162
  .execute();
158
163
  }
164
+ function getPostgresQueryDriver(connectionName) {
165
+ const queryDriverClass = index_js_1.default.getOrFail().dbConnectionQueryDriverClass(connectionName);
166
+ if (!(queryDriverClass === Postgres_js_1.default)) {
167
+ throw new Error(`
168
+ ${queryDriverClass.name} is not an instance of PostgresQueryDriver.
169
+ You must be using the PostgresQueryDriver when leveraging the Sortable decorator
170
+ `);
171
+ }
172
+ return queryDriverClass;
173
+ }
@@ -20,7 +20,6 @@ const index_js_2 = require("../ops/index.js");
20
20
  const computedPaginatePage_js_1 = require("./internal/computedPaginatePage.js");
21
21
  const convertDreamClassAndAssociationNameTupleArrayToPreloadArgs_js_1 = require("./internal/convertDreamClassAndAssociationNameTupleArrayToPreloadArgs.js");
22
22
  const extractNestedPaths_js_1 = require("./internal/extractNestedPaths.js");
23
- const Postgres_js_1 = require("./QueryDriver/Postgres.js");
24
23
  class Query {
25
24
  /**
26
25
  * @internal
@@ -1170,13 +1169,17 @@ class Query {
1170
1169
  async all(options = {}) {
1171
1170
  return await this.dbDriverInstance().takeAll(options);
1172
1171
  }
1173
- static dbDriverClass() {
1174
- return Postgres_js_1.default;
1172
+ static dbDriverClass(connectionName) {
1173
+ const dreamApp = index_js_1.default.getOrFail();
1174
+ return dreamApp.dbConnectionQueryDriverClass(connectionName);
1175
1175
  }
1176
1176
  dbDriverInstance(query = this) {
1177
- const driverClass = Query.dbDriverClass();
1177
+ const driverClass = Query.dbDriverClass(this.connectionName);
1178
1178
  return new driverClass(query);
1179
1179
  }
1180
+ get connectionName() {
1181
+ return this.dreamInstance.connectionName || 'default';
1182
+ }
1180
1183
  /**
1181
1184
  * Paginates the results of your query, accepting a pageSize and page argument,
1182
1185
  * which it uses to segment your query into pages, leveraging limit and offset
@@ -1281,7 +1284,7 @@ class Query {
1281
1284
  const query = this.orderStatements.length
1282
1285
  ? this
1283
1286
  : this.order({ [this.namespacedPrimaryKey]: 'asc' });
1284
- const dbDriverClass = Query.dbDriverClass();
1287
+ const dbDriverClass = Query.dbDriverClass(this.connectionName);
1285
1288
  return await new dbDriverClass(query).takeOne();
1286
1289
  }
1287
1290
  /**
@@ -1321,7 +1324,7 @@ class Query {
1321
1324
  const query = this.orderStatements.length
1322
1325
  ? this.invertOrder()
1323
1326
  : this.order({ [this.namespacedPrimaryKey]: 'desc' });
1324
- const dbDriverClass = Query.dbDriverClass();
1327
+ const dbDriverClass = Query.dbDriverClass(this.connectionName);
1325
1328
  return await new dbDriverClass(query).takeOne();
1326
1329
  }
1327
1330
  /**
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const CalendarDate_js_1 = require("../../helpers/CalendarDate.js");
4
+ const DateTime_js_1 = require("../../helpers/DateTime.js");
3
5
  class QueryDriverBase {
4
6
  query;
5
7
  dreamClass;
@@ -24,7 +26,9 @@ class QueryDriverBase {
24
26
  * migrate the database. Must respond to the NODE_ENV value.
25
27
  */
26
28
  // eslint-disable-next-line @typescript-eslint/require-await
27
- static async migrate() {
29
+ static async migrate(
30
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
31
+ connectionName) {
28
32
  throw new Error('override migrate in child class');
29
33
  }
30
34
  /**
@@ -38,14 +42,18 @@ class QueryDriverBase {
38
42
  * create the database. Must respond to the NODE_ENV value.
39
43
  */
40
44
  // eslint-disable-next-line @typescript-eslint/require-await
41
- static async dbCreate() {
45
+ static async dbCreate(
46
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
47
+ connectionName) {
42
48
  throw new Error('override dbCreate on child class');
43
49
  }
44
50
  /**
45
51
  * delete the database. Must respond to the NODE_ENV value.
46
52
  */
47
53
  // eslint-disable-next-line @typescript-eslint/require-await
48
- static async dbDrop() {
54
+ static async dbDrop(
55
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
56
+ connectionName) {
49
57
  throw new Error('override dbDrop on child class');
50
58
  }
51
59
  /**
@@ -56,8 +64,14 @@ class QueryDriverBase {
56
64
  * is sorted by date in the file tree, and, more importantly, so
57
65
  * they can be run in order by your migration runner.
58
66
  */
59
- // eslint-disable-next-line @typescript-eslint/require-await, @typescript-eslint/no-unused-vars
60
- static async generateMigration(migrationName, columnsWithTypes) {
67
+ // eslint-disable-next-line @typescript-eslint/require-await
68
+ static async generateMigration(
69
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
70
+ connectionName,
71
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
72
+ migrationName,
73
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
74
+ columnsWithTypes) {
61
75
  throw new Error('override generateMigration in child class');
62
76
  }
63
77
  /**
@@ -76,8 +90,10 @@ class QueryDriverBase {
76
90
  * but this will likely need to be overridden to tailor to your custom
77
91
  * database engine.
78
92
  */
79
- // eslint-disable-next-line @typescript-eslint/require-await, @typescript-eslint/no-unused-vars
80
- static async sync(_) {
93
+ // eslint-disable-next-line @typescript-eslint/require-await
94
+ static async sync(connectionName, _,
95
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
96
+ options = {}) {
81
97
  throw new Error('override sync on child class');
82
98
  }
83
99
  /**
@@ -94,6 +110,79 @@ class QueryDriverBase {
94
110
  toKysely(type) {
95
111
  throw new Error('implement toKysely in child class (if it makes sense)');
96
112
  }
113
+ /**
114
+ * Builds a new DreamTransaction instance, provides
115
+ * the instance to the provided callback.
116
+ *
117
+ * ```ts
118
+ * await ApplicationModel.transaction(async txn => {
119
+ * const user = await User.txn(txn).create({ email: 'how@yadoin' })
120
+ * await Pet.txn(txn).create({ user })
121
+ * })
122
+ * ```
123
+ *
124
+ * @param callback - A callback function to call. The transaction provided to the callback can be passed to subsequent database calls within the transaction callback
125
+ * @returns void
126
+ */
127
+ // eslint-disable-next-line @typescript-eslint/require-await
128
+ static async transaction(dreamInstance, callback) {
129
+ throw new Error('implement transaction in child class');
130
+ }
131
+ /**
132
+ * @internal
133
+ *
134
+ * returns the foreign key type based on the primary key received.
135
+ * gives the driver the opportunity to switch i.e. bigserial to bigint.
136
+ */
137
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
138
+ static foreignKeyTypeFromPrimaryKey(primaryKey) {
139
+ throw new Error('implement foreignKeyTypeFromPrimaryKey in child class');
140
+ }
141
+ /**
142
+ * @internal
143
+ *
144
+ * used to return the computed primary key type based
145
+ * on the primaryKeyType set in the DreamApp class.
146
+ */
147
+ static primaryKeyType() {
148
+ throw new Error('implement primaryKeyType in child class');
149
+ }
150
+ /**
151
+ * @internal
152
+ *
153
+ * this method is called when dream is initializing, and is used
154
+ * to configure the database to utilize custom type parsers for
155
+ * a variety of data types.
156
+ *
157
+ * @param connectionName - the name of the connection you are doing this for
158
+ * @returns void
159
+ */
160
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
161
+ static async setDatabaseTypeParsers(connectionName) { }
162
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
163
+ static async duplicateDatabase(connectionName) { }
164
+ // eslint-disable-next-line @typescript-eslint/require-await
165
+ static async getColumnData(
166
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
167
+ connectionName,
168
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
169
+ tableName,
170
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
171
+ associationData) {
172
+ throw new Error('implement getColumnData in child class');
173
+ }
174
+ static serializeDbType(type, val) {
175
+ switch (type) {
176
+ case 'datetime':
177
+ case 'date':
178
+ if (val instanceof DateTime_js_1.DateTime || val instanceof CalendarDate_js_1.default) {
179
+ return val.toSQL();
180
+ }
181
+ throw new Error(`unrecognized value found when trying to serialize for date/datetime: ${val}`);
182
+ default:
183
+ return val;
184
+ }
185
+ }
97
186
  /**
98
187
  * @internal
99
188
  *
@@ -249,6 +338,21 @@ class QueryDriverBase {
249
338
  static async saveDream(dream, txn = null) {
250
339
  throw new Error('implement saveDream in child class');
251
340
  }
341
+ /**
342
+ * destroys a dream, possibly implementing soft delete if reallyDestroy is false
343
+ * and the record being deleted implements soft delete.
344
+ *
345
+ * @param dream - the dream instance you wish to destroy
346
+ * @param txn - a transaction to encapsulate, consistently provided by underlying dream mechanisms
347
+ * @param reallyDestroy - whether or not to reallyDestroy. If false, soft delete will be attempted when relevant
348
+ */
349
+ // eslint-disable-next-line @typescript-eslint/require-await, @typescript-eslint/no-unused-vars
350
+ static async destroyDream(dream, txn, reallyDestroy) {
351
+ throw new Error('implement destroyDream in child class');
352
+ }
353
+ static get syncDialect() {
354
+ return 'postgres';
355
+ }
252
356
  /**
253
357
  * Returns the sql that would be executed by this Query
254
358
  *