@rvoh/dream 0.35.1 → 0.35.2

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 (181) hide show
  1. package/dist/cjs/src/Dream.js +1 -12
  2. package/dist/cjs/src/bin/helpers/sync.js +2 -3
  3. package/dist/cjs/src/bin/index.js +17 -17
  4. package/dist/cjs/src/db/DreamDbConnection.js +10 -16
  5. package/dist/cjs/src/dream-application/index.js +22 -0
  6. package/dist/cjs/src/helpers/db/createDb.js +3 -3
  7. package/dist/cjs/src/helpers/db/dropDb.js +8 -5
  8. package/dist/esm/src/Dream.js +1 -12
  9. package/dist/esm/src/bin/helpers/sync.js +2 -3
  10. package/dist/esm/src/bin/index.js +17 -17
  11. package/dist/esm/src/db/DreamDbConnection.js +10 -16
  12. package/dist/esm/src/dream-application/index.js +22 -0
  13. package/dist/esm/src/helpers/db/createDb.js +3 -3
  14. package/dist/esm/src/helpers/db/dropDb.js +8 -5
  15. package/dist/types/src/Dream.d.ts +2 -2
  16. package/dist/types/src/db/DreamDbConnection.d.ts +1 -0
  17. package/dist/types/src/dream/Query.d.ts +2 -2
  18. package/dist/types/src/dream-application/index.d.ts +5 -0
  19. package/dist/types/src/types/query.d.ts +38 -0
  20. package/docs/assets/icons.js +1 -1
  21. package/docs/assets/icons.svg +1 -1
  22. package/docs/assets/main.js +1 -1
  23. package/docs/assets/navigation.js +1 -1
  24. package/docs/assets/search.js +1 -1
  25. package/docs/assets/style.css +66 -21
  26. package/docs/classes/Benchmark.html +2 -2
  27. package/docs/classes/CalendarDate.html +2 -2
  28. package/docs/classes/CreateOrFindByFailedToCreateAndFind.html +6 -5
  29. package/docs/classes/Decorators.html +19 -19
  30. package/docs/classes/Dream.html +132 -132
  31. package/docs/classes/DreamApplication.html +9 -5
  32. package/docs/classes/DreamBin.html +2 -2
  33. package/docs/classes/DreamCLI.html +4 -4
  34. package/docs/classes/DreamImporter.html +2 -2
  35. package/docs/classes/DreamLogos.html +2 -2
  36. package/docs/classes/DreamMigrationHelpers.html +7 -7
  37. package/docs/classes/DreamSerializer.html +2 -2
  38. package/docs/classes/DreamTransaction.html +2 -2
  39. package/docs/classes/Encrypt.html +2 -2
  40. package/docs/classes/Env.html +2 -2
  41. package/docs/classes/GlobalNameNotSet.html +6 -5
  42. package/docs/classes/NonLoadedAssociation.html +6 -5
  43. package/docs/classes/Query.html +51 -51
  44. package/docs/classes/Range.html +2 -2
  45. package/docs/classes/RecordNotFound.html +6 -5
  46. package/docs/classes/ValidationError.html +6 -5
  47. package/docs/functions/Attribute.html +1 -1
  48. package/docs/functions/RendersMany.html +1 -1
  49. package/docs/functions/RendersOne.html +1 -1
  50. package/docs/functions/ReplicaSafe.html +1 -1
  51. package/docs/functions/STI.html +1 -1
  52. package/docs/functions/SoftDelete.html +1 -1
  53. package/docs/functions/camelize.html +1 -1
  54. package/docs/functions/capitalize.html +1 -1
  55. package/docs/functions/closeAllDbConnections.html +1 -1
  56. package/docs/functions/compact.html +1 -1
  57. package/docs/functions/debug.html +1 -1
  58. package/docs/functions/dreamDbConnections.html +1 -1
  59. package/docs/functions/dreamPath.html +1 -1
  60. package/docs/functions/generateDream.html +1 -1
  61. package/docs/functions/globalClassNameFromFullyQualifiedModelName.html +1 -1
  62. package/docs/functions/hyphenize.html +1 -1
  63. package/docs/functions/inferSerializerFromDreamClassOrViewModelClass.html +1 -1
  64. package/docs/functions/inferSerializerFromDreamOrViewModel.html +1 -1
  65. package/docs/functions/isEmpty.html +1 -1
  66. package/docs/functions/loadRepl.html +1 -1
  67. package/docs/functions/lookupClassByGlobalName.html +1 -1
  68. package/docs/functions/pascalize.html +1 -1
  69. package/docs/functions/pgErrorType.html +1 -1
  70. package/docs/functions/range-1.html +1 -1
  71. package/docs/functions/relativeDreamPath.html +1 -1
  72. package/docs/functions/round.html +1 -1
  73. package/docs/functions/serializerNameFromFullyQualifiedModelName.html +1 -1
  74. package/docs/functions/sharedPathPrefix.html +1 -1
  75. package/docs/functions/snakeify.html +1 -1
  76. package/docs/functions/sort.html +1 -1
  77. package/docs/functions/sortBy.html +1 -1
  78. package/docs/functions/standardizeFullyQualifiedModelName.html +1 -1
  79. package/docs/functions/uncapitalize.html +1 -1
  80. package/docs/functions/uniq.html +1 -1
  81. package/docs/functions/untypedDb.html +1 -1
  82. package/docs/functions/validateColumn.html +1 -1
  83. package/docs/functions/validateTable.html +1 -1
  84. package/docs/index.html +7 -7
  85. package/docs/interfaces/AttributeStatement.html +2 -2
  86. package/docs/interfaces/DecoratorContext.html +2 -2
  87. package/docs/interfaces/DreamApplicationInitOptions.html +2 -2
  88. package/docs/interfaces/DreamApplicationOpts.html +2 -2
  89. package/docs/interfaces/DreamSerializerAssociationStatement.html +2 -2
  90. package/docs/interfaces/EncryptOptions.html +2 -2
  91. package/docs/interfaces/OpenapiSchemaProperties.html +1 -1
  92. package/docs/interfaces/OpenapiSchemaPropertiesShorthand.html +1 -1
  93. package/docs/interfaces/OpenapiTypeFieldObject.html +1 -1
  94. package/docs/modules.html +8 -8
  95. package/docs/types/Camelized.html +1 -1
  96. package/docs/types/CommonOpenapiSchemaObjectFields.html +1 -1
  97. package/docs/types/DateTime.html +1 -1
  98. package/docs/types/DbConnectionType.html +1 -1
  99. package/docs/types/DreamAssociationMetadata.html +1 -1
  100. package/docs/types/DreamAttributes.html +1 -1
  101. package/docs/types/DreamClassColumn.html +1 -1
  102. package/docs/types/DreamColumn.html +1 -1
  103. package/docs/types/DreamColumnNames.html +1 -1
  104. package/docs/types/DreamLogLevel.html +1 -1
  105. package/docs/types/DreamLogger.html +1 -1
  106. package/docs/types/DreamOrViewModelSerializerKey.html +1 -1
  107. package/docs/types/DreamParamSafeAttributes.html +1 -1
  108. package/docs/types/DreamParamSafeColumnNames.html +1 -1
  109. package/docs/types/DreamSerializerKey.html +1 -1
  110. package/docs/types/DreamSerializers.html +1 -1
  111. package/docs/types/DreamTableSchema.html +1 -1
  112. package/docs/types/DreamVirtualColumns.html +1 -1
  113. package/docs/types/EncryptAlgorithm.html +1 -1
  114. package/docs/types/Hyphenized.html +1 -1
  115. package/docs/types/IdType.html +1 -1
  116. package/docs/types/OpenapiAllTypes.html +1 -1
  117. package/docs/types/OpenapiFormats.html +1 -1
  118. package/docs/types/OpenapiNumberFormats.html +1 -1
  119. package/docs/types/OpenapiPrimitiveTypes.html +1 -1
  120. package/docs/types/OpenapiSchemaArray.html +1 -1
  121. package/docs/types/OpenapiSchemaArrayShorthand.html +1 -1
  122. package/docs/types/OpenapiSchemaBase.html +1 -1
  123. package/docs/types/OpenapiSchemaBody.html +1 -1
  124. package/docs/types/OpenapiSchemaBodyShorthand.html +1 -1
  125. package/docs/types/OpenapiSchemaCommonFields.html +1 -1
  126. package/docs/types/OpenapiSchemaExpressionAllOf.html +1 -1
  127. package/docs/types/OpenapiSchemaExpressionAnyOf.html +1 -1
  128. package/docs/types/OpenapiSchemaExpressionOneOf.html +1 -1
  129. package/docs/types/OpenapiSchemaExpressionRef.html +1 -1
  130. package/docs/types/OpenapiSchemaExpressionRefSchemaShorthand.html +1 -1
  131. package/docs/types/OpenapiSchemaInteger.html +1 -1
  132. package/docs/types/OpenapiSchemaNull.html +1 -1
  133. package/docs/types/OpenapiSchemaNumber.html +1 -1
  134. package/docs/types/OpenapiSchemaObject.html +1 -1
  135. package/docs/types/OpenapiSchemaObjectAllOf.html +1 -1
  136. package/docs/types/OpenapiSchemaObjectAllOfShorthand.html +1 -1
  137. package/docs/types/OpenapiSchemaObjectAnyOf.html +1 -1
  138. package/docs/types/OpenapiSchemaObjectAnyOfShorthand.html +1 -1
  139. package/docs/types/OpenapiSchemaObjectBase.html +1 -1
  140. package/docs/types/OpenapiSchemaObjectBaseShorthand.html +1 -1
  141. package/docs/types/OpenapiSchemaObjectOneOf.html +1 -1
  142. package/docs/types/OpenapiSchemaObjectOneOfShorthand.html +1 -1
  143. package/docs/types/OpenapiSchemaObjectShorthand.html +1 -1
  144. package/docs/types/OpenapiSchemaPartialSegment.html +1 -1
  145. package/docs/types/OpenapiSchemaPrimitiveGeneric.html +1 -1
  146. package/docs/types/OpenapiSchemaShorthandExpressionAllOf.html +1 -1
  147. package/docs/types/OpenapiSchemaShorthandExpressionAnyOf.html +1 -1
  148. package/docs/types/OpenapiSchemaShorthandExpressionOneOf.html +1 -1
  149. package/docs/types/OpenapiSchemaShorthandExpressionSerializableRef.html +1 -1
  150. package/docs/types/OpenapiSchemaShorthandExpressionSerializerRef.html +1 -1
  151. package/docs/types/OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
  152. package/docs/types/OpenapiSchemaString.html +1 -1
  153. package/docs/types/OpenapiShorthandAllTypes.html +1 -1
  154. package/docs/types/OpenapiShorthandPrimitiveTypes.html +1 -1
  155. package/docs/types/OpenapiTypeField.html +1 -1
  156. package/docs/types/Pascalized.html +1 -1
  157. package/docs/types/PrimaryKeyType.html +1 -1
  158. package/docs/types/RoundingPrecision.html +1 -1
  159. package/docs/types/SerializableClassOrSerializerCallback.html +1 -1
  160. package/docs/types/SerializableDreamClassOrViewModelClass.html +1 -1
  161. package/docs/types/SerializableDreamOrViewModel.html +1 -1
  162. package/docs/types/SerializableTypes.html +1 -1
  163. package/docs/types/Snakeified.html +1 -1
  164. package/docs/types/Timestamp.html +1 -1
  165. package/docs/types/UpdateableAssociationProperties.html +1 -1
  166. package/docs/types/UpdateableProperties.html +1 -1
  167. package/docs/types/ValidationType.html +1 -1
  168. package/docs/types/ViewModelSerializerKey.html +1 -1
  169. package/docs/types/WhereStatementForDream.html +1 -1
  170. package/docs/types/WhereStatementForDreamClass.html +1 -1
  171. package/docs/variables/DateTime-1.html +1 -1
  172. package/docs/variables/DreamConst.html +1 -1
  173. package/docs/variables/TRIGRAM_OPERATORS.html +1 -1
  174. package/docs/variables/openapiPrimitiveTypes-1.html +1 -1
  175. package/docs/variables/openapiShorthandPrimitiveTypes-1.html +1 -1
  176. package/docs/variables/ops.html +1 -1
  177. package/docs/variables/primaryKeyTypes.html +1 -1
  178. package/package.json +3 -3
  179. package/dist/cjs/src/db/ConnectionConfRetriever.js +0 -22
  180. package/dist/esm/src/db/ConnectionConfRetriever.js +0 -19
  181. package/dist/types/src/db/ConnectionConfRetriever.d.ts +0 -6
@@ -1234,18 +1234,7 @@ class Dream {
1234
1234
  * @returns A Kysely query. Depending on the type passed, it will return either a SelectQueryBuilder, DeleteQueryBuilder, UpdateQueryBuilder, or an InsertQueryBuilder
1235
1235
  */
1236
1236
  static toKysely(type) {
1237
- switch (type) {
1238
- case 'select':
1239
- return this.query().dbFor('select').selectFrom(this.table);
1240
- case 'delete':
1241
- return this.query().dbFor('delete').deleteFrom(this.table);
1242
- case 'update':
1243
- return this.query().dbFor('update').updateTable(this.table);
1244
- case 'insert':
1245
- return this.query().dbFor('insert').insertInto(this.table);
1246
- default:
1247
- throw new Error('never');
1248
- }
1237
+ return this.query().toKysely(type);
1249
1238
  }
1250
1239
  /**
1251
1240
  * Applies transaction to a new Query scoped
@@ -5,17 +5,16 @@ const fs = require("fs/promises");
5
5
  const path = require("path");
6
6
  const index_js_1 = require("../../cli/index.js");
7
7
  const colorize_js_1 = require("../../cli/logger/loggable/colorize.js");
8
- const ConnectionConfRetriever_js_1 = require("../../db/ConnectionConfRetriever.js");
9
8
  const index_js_2 = require("../../dream-application/index.js");
9
+ const autoGeneratedFileDisclaimer_js_1 = require("../../helpers/cli/autoGeneratedFileDisclaimer.js");
10
10
  const compact_js_1 = require("../../helpers/compact.js");
11
11
  const EnvInternal_js_1 = require("../../helpers/EnvInternal.js");
12
12
  const dreamPath_js_1 = require("../../helpers/path/dreamPath.js");
13
13
  const snakeify_js_1 = require("../../helpers/snakeify.js");
14
14
  const sspawn_js_1 = require("../../helpers/sspawn.js");
15
- const autoGeneratedFileDisclaimer_js_1 = require("../../helpers/cli/autoGeneratedFileDisclaimer.js");
16
15
  async function writeSyncFile() {
17
- const dbConf = new ConnectionConfRetriever_js_1.default().getConnectionConf('primary');
18
16
  const dreamApp = index_js_2.default.getOrFail();
17
+ const dbConf = dreamApp.dbConnectionConfig('primary');
19
18
  const dbSyncFilePath = path.join((0, dreamPath_js_1.default)('types'), 'db.ts');
20
19
  const absoluteDbSyncPath = path.join(dreamApp.projectRoot, dbSyncFilePath);
21
20
  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}`, {
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const index_js_1 = require("../cli/index.js");
4
- const ConnectionConfRetriever_js_1 = require("../db/ConnectionConfRetriever.js");
5
4
  const index_js_2 = require("../dream-application/index.js");
6
5
  const EnvInternal_js_1 = require("../helpers/EnvInternal.js");
7
6
  const SchemaBuilder_js_1 = require("../helpers/cli/SchemaBuilder.js");
@@ -29,8 +28,8 @@ class DreamBin {
29
28
  await new SchemaBuilder_js_1.default().build();
30
29
  }
31
30
  static async dbCreate() {
32
- const connectionRetriever = new ConnectionConfRetriever_js_1.default();
33
- const primaryDbConf = connectionRetriever.getConnectionConf('primary');
31
+ const dreamApp = index_js_2.default.getOrFail();
32
+ const primaryDbConf = dreamApp.dbConnectionConfig('primary');
34
33
  index_js_1.default.logger.logStartProgress(`creating ${primaryDbConf.name}...`);
35
34
  await (0, createDb_js_1.default)('primary');
36
35
  index_js_1.default.logger.logEndProgress();
@@ -44,8 +43,8 @@ class DreamBin {
44
43
  // }
45
44
  }
46
45
  static async dbDrop() {
47
- const connectionRetriever = new ConnectionConfRetriever_js_1.default();
48
- const primaryDbConf = connectionRetriever.getConnectionConf('primary');
46
+ const dreamApp = index_js_2.default.getOrFail();
47
+ const primaryDbConf = dreamApp.dbConnectionConfig('primary');
49
48
  index_js_1.default.logger.logStartProgress(`dropping ${primaryDbConf.name}...`);
50
49
  await (0, dropDb_js_1.default)('primary');
51
50
  index_js_1.default.logger.logEndProgress();
@@ -59,24 +58,24 @@ class DreamBin {
59
58
  // }
60
59
  }
61
60
  static async dbMigrate() {
62
- const connectionRetriever = new ConnectionConfRetriever_js_1.default();
63
- const primaryDbConf = connectionRetriever.getConnectionConf('primary');
61
+ const dreamApp = index_js_2.default.getOrFail();
62
+ const primaryDbConf = dreamApp.dbConnectionConfig('primary');
64
63
  index_js_1.default.logger.logStartProgress(`migrating ${primaryDbConf.name}...`);
65
64
  await (0, runMigration_js_1.default)({ mode: 'migrate' });
66
- await this.duplicateDatabase();
67
65
  index_js_1.default.logger.logEndProgress();
66
+ await this.duplicateDatabase();
68
67
  }
69
68
  static async dbRollback(opts) {
70
- const connectionRetriever = new ConnectionConfRetriever_js_1.default();
71
- const primaryDbConf = connectionRetriever.getConnectionConf('primary');
69
+ const dreamApp = index_js_2.default.getOrFail();
70
+ const primaryDbConf = dreamApp.dbConnectionConfig('primary');
72
71
  index_js_1.default.logger.logStartProgress(`rolling back ${primaryDbConf.name}...`);
73
72
  let step = opts.steps;
74
73
  while (step > 0) {
75
74
  await (0, runMigration_js_1.default)({ mode: 'rollback' });
76
75
  step -= 1;
77
76
  }
78
- await this.duplicateDatabase();
79
77
  index_js_1.default.logger.logEndProgress();
78
+ await this.duplicateDatabase();
80
79
  }
81
80
  static async generateDream(fullyQualifiedModelName, columnsWithTypes, options) {
82
81
  await (0, generateDream_js_1.default)({ fullyQualifiedModelName, columnsWithTypes, options });
@@ -96,26 +95,27 @@ class DreamBin {
96
95
  index_js_1.default.logger.logEndProgress();
97
96
  }
98
97
  static async duplicateDatabase() {
99
- const parallelTests = index_js_2.default.getOrFail().parallelTests;
98
+ const dreamApp = index_js_2.default.getOrFail();
99
+ const parallelTests = dreamApp.parallelTests;
100
100
  if (!parallelTests)
101
101
  return;
102
- const connectionRetriever = new ConnectionConfRetriever_js_1.default();
103
- const dbConf = connectionRetriever.getConnectionConf('primary');
102
+ index_js_1.default.logger.logStartProgress(`duplicating db for parallel tests...`);
103
+ const dbConf = dreamApp.dbConnectionConfig('primary');
104
104
  const client = await (0, loadPgClient_js_1.default)({ useSystemDb: true });
105
105
  if (EnvInternal_js_1.default.boolean('DREAM_CORE_DEVELOPMENT')) {
106
106
  const replicaTestWorkerDatabaseName = `replica_test_${dbConf.name}`;
107
- index_js_1.default.logger.logContinueProgress(`creating fake replica test database ${replicaTestWorkerDatabaseName}...`);
107
+ index_js_1.default.logger.logContinueProgress(`creating fake replica test database ${replicaTestWorkerDatabaseName}...`, { logPrefix: ' ├ [db]', logPrefixColor: 'cyan' });
108
108
  await client.query(`DROP DATABASE IF EXISTS ${replicaTestWorkerDatabaseName};`);
109
109
  await client.query(`CREATE DATABASE ${replicaTestWorkerDatabaseName} TEMPLATE ${dbConf.name};`);
110
110
  }
111
111
  for (let i = 2; i <= parallelTests; i++) {
112
112
  const workerDatabaseName = `${dbConf.name}_${i}`;
113
- console.log(`creating duplicate test database ${workerDatabaseName} for concurrent tests`);
114
- index_js_1.default.logger.logContinueProgress(`creating duplicate test database ${workerDatabaseName} for concurrent tests...`);
113
+ index_js_1.default.logger.logContinueProgress(`creating duplicate test database ${workerDatabaseName} for concurrent tests...`, { logPrefix: ' ├ [db]', logPrefixColor: 'cyan' });
115
114
  await client.query(`DROP DATABASE IF EXISTS ${workerDatabaseName};`);
116
115
  await client.query(`CREATE DATABASE ${workerDatabaseName} TEMPLATE ${dbConf.name};`);
117
116
  }
118
117
  await client.end();
118
+ index_js_1.default.logger.logEndProgress();
119
119
  }
120
120
  }
121
121
  exports.default = DreamBin;
@@ -13,16 +13,16 @@ exports.closeAllDbConnections = closeAllDbConnections;
13
13
  const pg_1 = require("pg");
14
14
  const kysely_1 = require("kysely");
15
15
  const index_js_1 = require("../dream-application/index.js");
16
- const ConnectionConfRetriever_js_1 = require("./ConnectionConfRetriever.js");
17
16
  let connections = {};
18
17
  class DreamDbConnection {
19
18
  static getConnection(connectionType) {
20
- const connectionName = getConnectionTypeName(connectionType);
19
+ const dreamApp = index_js_1.default.getOrFail();
20
+ const connectionName = this.getConnectionTypeName(connectionType);
21
21
  const connection = connections[connectionName];
22
22
  if (connection) {
23
23
  return connection;
24
24
  }
25
- const connectionConf = new ConnectionConfRetriever_js_1.default().getConnectionConf(connectionType);
25
+ const connectionConf = dreamApp.dbConnectionConfig(connectionType);
26
26
  const dbConn = new kysely_1.Kysely({
27
27
  log(event) {
28
28
  const dreamApp = index_js_1.default.getOrFail();
@@ -34,7 +34,7 @@ class DreamDbConnection {
34
34
  pool: new pg_1.default.Pool({
35
35
  user: connectionConf.user || '',
36
36
  password: connectionConf.password || '',
37
- database: getDatabaseName(connectionConf.name),
37
+ database: dreamApp.dbName(connectionType),
38
38
  host: connectionConf.host || 'localhost',
39
39
  port: connectionConf.port || 5432,
40
40
  ssl: connectionConf.useSsl ? sslConfig(connectionConf) : false,
@@ -42,7 +42,7 @@ class DreamDbConnection {
42
42
  }),
43
43
  plugins: [new kysely_1.CamelCasePlugin({ underscoreBetweenUppercaseLetters: true })],
44
44
  });
45
- connections[getConnectionTypeName(connectionType)] = dbConn;
45
+ connections[this.getConnectionTypeName(connectionType)] = dbConn;
46
46
  return dbConn;
47
47
  }
48
48
  static async dropAllConnections() {
@@ -51,19 +51,13 @@ class DreamDbConnection {
51
51
  delete connections[key];
52
52
  }
53
53
  }
54
+ static getConnectionTypeName(connectionType) {
55
+ return index_js_1.default.getOrFail().parallelDatabasesEnabled
56
+ ? `${connectionType}_${process.env.VITEST_POOL_ID}`
57
+ : connectionType;
58
+ }
54
59
  }
55
60
  exports.default = DreamDbConnection;
56
- function getConnectionTypeName(connectionType) {
57
- return parallelDatabasesEnabled() ? `${connectionType}_${process.env.JEST_WORKER_ID}` : connectionType;
58
- }
59
- function getDatabaseName(dbName) {
60
- return parallelDatabasesEnabled() ? `${dbName}_${process.env.JEST_WORKER_ID}` : dbName;
61
- }
62
- function parallelDatabasesEnabled() {
63
- return (!!index_js_1.default.getOrFail().parallelTests &&
64
- !Number.isNaN(Number(process.env.JEST_WORKER_ID)) &&
65
- Number(process.env.JEST_WORKER_ID) > 1);
66
- }
67
61
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
68
62
  function sslConfig(connectionConf) {
69
63
  // TODO: properly configure (https://rvohealth.atlassian.net/browse/PDTC-2914)
@@ -228,6 +228,28 @@ Try setting it to something valid, like:
228
228
  get serializers() {
229
229
  return (0, importSerializers_js_1.getSerializersOrFail)();
230
230
  }
231
+ dbName(connection) {
232
+ const conf = this.dbConnectionConfig(connection);
233
+ return this.parallelDatabasesEnabled ? `${conf.name}_${process.env.VITEST_POOL_ID}` : conf.name;
234
+ }
235
+ dbConnectionConfig(connection) {
236
+ const conf = this.dbCredentials?.[connection] || this.dbCredentials?.primary;
237
+ if (!conf)
238
+ throw new Error(`
239
+ Cannot find a connection config given the following connection and node environment:
240
+ connection: ${connection}
241
+ NODE_ENV: ${EnvInternal_js_1.default.nodeEnv}
242
+ `);
243
+ return conf;
244
+ }
245
+ get hasReplicaConfig() {
246
+ return !!this.dbCredentials.replica;
247
+ }
248
+ get parallelDatabasesEnabled() {
249
+ return (!!this.parallelTests &&
250
+ !Number.isNaN(Number(process.env.VITEST_POOL_ID)) &&
251
+ Number(process.env.VITEST_POOL_ID) > 1);
252
+ }
231
253
  async load(resourceType, resourcePath, importCb) {
232
254
  switch (resourceType) {
233
255
  case 'models':
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = createDb;
4
- const ConnectionConfRetriever_js_1 = require("../../db/ConnectionConfRetriever.js");
4
+ const index_js_1 = require("../../dream-application/index.js");
5
5
  const EnvInternal_js_1 = require("../EnvInternal.js");
6
6
  const loadPgClient_js_1 = require("./loadPgClient.js");
7
7
  async function createDb(connection, dbName) {
@@ -9,8 +9,8 @@ async function createDb(connection, dbName) {
9
9
  // so there is no way to drop in production
10
10
  if (EnvInternal_js_1.default.isProduction)
11
11
  return false;
12
- const connectionRetriever = new ConnectionConfRetriever_js_1.default();
13
- const dbConf = connectionRetriever.getConnectionConf(connection);
12
+ const dreamApp = index_js_1.default.getOrFail();
13
+ const dbConf = dreamApp.dbConnectionConfig(connection);
14
14
  dbName ||= dbConf.name || null;
15
15
  if (!dbName)
16
16
  throw new Error('Must either pass a dbName to the create function, or else ensure that DB_NAME is set in the env');
@@ -1,17 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = dropDb;
4
- const ConnectionConfRetriever_js_1 = require("../../db/ConnectionConfRetriever.js");
5
4
  const index_js_1 = require("../../dream-application/index.js");
6
5
  const EnvInternal_js_1 = require("../EnvInternal.js");
7
6
  const loadPgClient_js_1 = require("./loadPgClient.js");
7
+ const index_js_2 = require("../../cli/index.js");
8
8
  async function dropDb(connection, dbName) {
9
9
  // this was only ever written to clear the db between tests or in development,
10
10
  // so there is no way to drop in production
11
11
  if (EnvInternal_js_1.default.isProduction)
12
12
  return false;
13
- const connectionRetriever = new ConnectionConfRetriever_js_1.default();
14
- const dbConf = connectionRetriever.getConnectionConf(connection);
13
+ const dreamApp = index_js_1.default.getOrFail();
14
+ const dbConf = dreamApp.dbConnectionConfig(connection);
15
15
  dbName ||= dbConf.name || null;
16
16
  if (!dbName)
17
17
  throw new Error('Must either pass a dbName to the drop function, or else ensure that DB_NAME is set in the env');
@@ -25,12 +25,15 @@ async function maybeDropDuplicateDatabases(client, dbName) {
25
25
  return;
26
26
  if (EnvInternal_js_1.default.boolean('DREAM_CORE_DEVELOPMENT')) {
27
27
  const replicaTestWorkerDatabaseName = `replica_test_${dbName}`;
28
- console.log(`dropping fake replica test database ${replicaTestWorkerDatabaseName}`);
28
+ index_js_2.default.logger.logContinueProgress(`dropping fake replica test database ${replicaTestWorkerDatabaseName}`, { logPrefix: ' ├ [db]', logPrefixColor: 'cyan' });
29
29
  await client.query(`DROP DATABASE IF EXISTS ${replicaTestWorkerDatabaseName};`);
30
30
  }
31
31
  for (let i = 2; i <= parallelTests; i++) {
32
32
  const workerDatabaseName = `${dbName}_${i}`;
33
- console.log(`dropping duplicate test database ${workerDatabaseName}`);
33
+ index_js_2.default.logger.logContinueProgress(`dropping duplicate test database ${workerDatabaseName}`, {
34
+ logPrefix: ' ├ [db]',
35
+ logPrefixColor: 'cyan',
36
+ });
34
37
  await client.query(`DROP DATABASE IF EXISTS ${workerDatabaseName};`);
35
38
  }
36
39
  }
@@ -1232,18 +1232,7 @@ export default class Dream {
1232
1232
  * @returns A Kysely query. Depending on the type passed, it will return either a SelectQueryBuilder, DeleteQueryBuilder, UpdateQueryBuilder, or an InsertQueryBuilder
1233
1233
  */
1234
1234
  static toKysely(type) {
1235
- switch (type) {
1236
- case 'select':
1237
- return this.query().dbFor('select').selectFrom(this.table);
1238
- case 'delete':
1239
- return this.query().dbFor('delete').deleteFrom(this.table);
1240
- case 'update':
1241
- return this.query().dbFor('update').updateTable(this.table);
1242
- case 'insert':
1243
- return this.query().dbFor('insert').insertInto(this.table);
1244
- default:
1245
- throw new Error('never');
1246
- }
1235
+ return this.query().toKysely(type);
1247
1236
  }
1248
1237
  /**
1249
1238
  * Applies transaction to a new Query scoped
@@ -2,17 +2,16 @@ import * as fs from 'fs/promises';
2
2
  import * as path from 'path';
3
3
  import DreamCLI from '../../cli/index.js';
4
4
  import colorize from '../../cli/logger/loggable/colorize.js';
5
- import ConnectionConfRetriever from '../../db/ConnectionConfRetriever.js';
6
5
  import DreamApplication from '../../dream-application/index.js';
6
+ import autogeneratedFileDisclaimer from '../../helpers/cli/autoGeneratedFileDisclaimer.js';
7
7
  import compact from '../../helpers/compact.js';
8
8
  import EnvInternal from '../../helpers/EnvInternal.js';
9
9
  import dreamPath from '../../helpers/path/dreamPath.js';
10
10
  import snakeify from '../../helpers/snakeify.js';
11
11
  import sspawn from '../../helpers/sspawn.js';
12
- import autogeneratedFileDisclaimer from '../../helpers/cli/autoGeneratedFileDisclaimer.js';
13
12
  export default async function writeSyncFile() {
14
- const dbConf = new ConnectionConfRetriever().getConnectionConf('primary');
15
13
  const dreamApp = DreamApplication.getOrFail();
14
+ const dbConf = dreamApp.dbConnectionConfig('primary');
16
15
  const dbSyncFilePath = path.join(dreamPath('types'), 'db.ts');
17
16
  const absoluteDbSyncPath = path.join(dreamApp.projectRoot, dbSyncFilePath);
18
17
  await sspawn(`kysely-codegen --dialect=postgres --url=postgres://${dbConf.user}:${dbConf.password}@${dbConf.host}:${dbConf.port}/${dbConf.name} --out-file=${absoluteDbSyncPath}`, {
@@ -1,5 +1,4 @@
1
1
  import DreamCLI from '../cli/index.js';
2
- import ConnectionConfRetriever from '../db/ConnectionConfRetriever.js';
3
2
  import DreamApplication from '../dream-application/index.js';
4
3
  import EnvInternal from '../helpers/EnvInternal.js';
5
4
  import SchemaBuilder from '../helpers/cli/SchemaBuilder.js';
@@ -27,8 +26,8 @@ export default class DreamBin {
27
26
  await new SchemaBuilder().build();
28
27
  }
29
28
  static async dbCreate() {
30
- const connectionRetriever = new ConnectionConfRetriever();
31
- const primaryDbConf = connectionRetriever.getConnectionConf('primary');
29
+ const dreamApp = DreamApplication.getOrFail();
30
+ const primaryDbConf = dreamApp.dbConnectionConfig('primary');
32
31
  DreamCLI.logger.logStartProgress(`creating ${primaryDbConf.name}...`);
33
32
  await createDb('primary');
34
33
  DreamCLI.logger.logEndProgress();
@@ -42,8 +41,8 @@ export default class DreamBin {
42
41
  // }
43
42
  }
44
43
  static async dbDrop() {
45
- const connectionRetriever = new ConnectionConfRetriever();
46
- const primaryDbConf = connectionRetriever.getConnectionConf('primary');
44
+ const dreamApp = DreamApplication.getOrFail();
45
+ const primaryDbConf = dreamApp.dbConnectionConfig('primary');
47
46
  DreamCLI.logger.logStartProgress(`dropping ${primaryDbConf.name}...`);
48
47
  await _dropDb('primary');
49
48
  DreamCLI.logger.logEndProgress();
@@ -57,24 +56,24 @@ export default class DreamBin {
57
56
  // }
58
57
  }
59
58
  static async dbMigrate() {
60
- const connectionRetriever = new ConnectionConfRetriever();
61
- const primaryDbConf = connectionRetriever.getConnectionConf('primary');
59
+ const dreamApp = DreamApplication.getOrFail();
60
+ const primaryDbConf = dreamApp.dbConnectionConfig('primary');
62
61
  DreamCLI.logger.logStartProgress(`migrating ${primaryDbConf.name}...`);
63
62
  await runMigration({ mode: 'migrate' });
64
- await this.duplicateDatabase();
65
63
  DreamCLI.logger.logEndProgress();
64
+ await this.duplicateDatabase();
66
65
  }
67
66
  static async dbRollback(opts) {
68
- const connectionRetriever = new ConnectionConfRetriever();
69
- const primaryDbConf = connectionRetriever.getConnectionConf('primary');
67
+ const dreamApp = DreamApplication.getOrFail();
68
+ const primaryDbConf = dreamApp.dbConnectionConfig('primary');
70
69
  DreamCLI.logger.logStartProgress(`rolling back ${primaryDbConf.name}...`);
71
70
  let step = opts.steps;
72
71
  while (step > 0) {
73
72
  await runMigration({ mode: 'rollback' });
74
73
  step -= 1;
75
74
  }
76
- await this.duplicateDatabase();
77
75
  DreamCLI.logger.logEndProgress();
76
+ await this.duplicateDatabase();
78
77
  }
79
78
  static async generateDream(fullyQualifiedModelName, columnsWithTypes, options) {
80
79
  await generateDream({ fullyQualifiedModelName, columnsWithTypes, options });
@@ -94,25 +93,26 @@ export default class DreamBin {
94
93
  DreamCLI.logger.logEndProgress();
95
94
  }
96
95
  static async duplicateDatabase() {
97
- const parallelTests = DreamApplication.getOrFail().parallelTests;
96
+ const dreamApp = DreamApplication.getOrFail();
97
+ const parallelTests = dreamApp.parallelTests;
98
98
  if (!parallelTests)
99
99
  return;
100
- const connectionRetriever = new ConnectionConfRetriever();
101
- const dbConf = connectionRetriever.getConnectionConf('primary');
100
+ DreamCLI.logger.logStartProgress(`duplicating db for parallel tests...`);
101
+ const dbConf = dreamApp.dbConnectionConfig('primary');
102
102
  const client = await loadPgClient({ useSystemDb: true });
103
103
  if (EnvInternal.boolean('DREAM_CORE_DEVELOPMENT')) {
104
104
  const replicaTestWorkerDatabaseName = `replica_test_${dbConf.name}`;
105
- DreamCLI.logger.logContinueProgress(`creating fake replica test database ${replicaTestWorkerDatabaseName}...`);
105
+ DreamCLI.logger.logContinueProgress(`creating fake replica test database ${replicaTestWorkerDatabaseName}...`, { logPrefix: ' ├ [db]', logPrefixColor: 'cyan' });
106
106
  await client.query(`DROP DATABASE IF EXISTS ${replicaTestWorkerDatabaseName};`);
107
107
  await client.query(`CREATE DATABASE ${replicaTestWorkerDatabaseName} TEMPLATE ${dbConf.name};`);
108
108
  }
109
109
  for (let i = 2; i <= parallelTests; i++) {
110
110
  const workerDatabaseName = `${dbConf.name}_${i}`;
111
- console.log(`creating duplicate test database ${workerDatabaseName} for concurrent tests`);
112
- DreamCLI.logger.logContinueProgress(`creating duplicate test database ${workerDatabaseName} for concurrent tests...`);
111
+ DreamCLI.logger.logContinueProgress(`creating duplicate test database ${workerDatabaseName} for concurrent tests...`, { logPrefix: ' ├ [db]', logPrefixColor: 'cyan' });
113
112
  await client.query(`DROP DATABASE IF EXISTS ${workerDatabaseName};`);
114
113
  await client.query(`CREATE DATABASE ${workerDatabaseName} TEMPLATE ${dbConf.name};`);
115
114
  }
116
115
  await client.end();
116
+ DreamCLI.logger.logEndProgress();
117
117
  }
118
118
  }
@@ -9,16 +9,16 @@
9
9
  import pg from 'pg';
10
10
  import { CamelCasePlugin, Kysely, PostgresDialect } from 'kysely';
11
11
  import DreamApplication from '../dream-application/index.js';
12
- import ConnectionConfRetriever from './ConnectionConfRetriever.js';
13
12
  let connections = {};
14
13
  export default class DreamDbConnection {
15
14
  static getConnection(connectionType) {
16
- const connectionName = getConnectionTypeName(connectionType);
15
+ const dreamApp = DreamApplication.getOrFail();
16
+ const connectionName = this.getConnectionTypeName(connectionType);
17
17
  const connection = connections[connectionName];
18
18
  if (connection) {
19
19
  return connection;
20
20
  }
21
- const connectionConf = new ConnectionConfRetriever().getConnectionConf(connectionType);
21
+ const connectionConf = dreamApp.dbConnectionConfig(connectionType);
22
22
  const dbConn = new Kysely({
23
23
  log(event) {
24
24
  const dreamApp = DreamApplication.getOrFail();
@@ -30,7 +30,7 @@ export default class DreamDbConnection {
30
30
  pool: new pg.Pool({
31
31
  user: connectionConf.user || '',
32
32
  password: connectionConf.password || '',
33
- database: getDatabaseName(connectionConf.name),
33
+ database: dreamApp.dbName(connectionType),
34
34
  host: connectionConf.host || 'localhost',
35
35
  port: connectionConf.port || 5432,
36
36
  ssl: connectionConf.useSsl ? sslConfig(connectionConf) : false,
@@ -38,7 +38,7 @@ export default class DreamDbConnection {
38
38
  }),
39
39
  plugins: [new CamelCasePlugin({ underscoreBetweenUppercaseLetters: true })],
40
40
  });
41
- connections[getConnectionTypeName(connectionType)] = dbConn;
41
+ connections[this.getConnectionTypeName(connectionType)] = dbConn;
42
42
  return dbConn;
43
43
  }
44
44
  static async dropAllConnections() {
@@ -47,17 +47,11 @@ export default class DreamDbConnection {
47
47
  delete connections[key];
48
48
  }
49
49
  }
50
- }
51
- function getConnectionTypeName(connectionType) {
52
- return parallelDatabasesEnabled() ? `${connectionType}_${process.env.JEST_WORKER_ID}` : connectionType;
53
- }
54
- function getDatabaseName(dbName) {
55
- return parallelDatabasesEnabled() ? `${dbName}_${process.env.JEST_WORKER_ID}` : dbName;
56
- }
57
- function parallelDatabasesEnabled() {
58
- return (!!DreamApplication.getOrFail().parallelTests &&
59
- !Number.isNaN(Number(process.env.JEST_WORKER_ID)) &&
60
- Number(process.env.JEST_WORKER_ID) > 1);
50
+ static getConnectionTypeName(connectionType) {
51
+ return DreamApplication.getOrFail().parallelDatabasesEnabled
52
+ ? `${connectionType}_${process.env.VITEST_POOL_ID}`
53
+ : connectionType;
54
+ }
61
55
  }
62
56
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
63
57
  function sslConfig(connectionConf) {
@@ -226,6 +226,28 @@ Try setting it to something valid, like:
226
226
  get serializers() {
227
227
  return getSerializersOrFail();
228
228
  }
229
+ dbName(connection) {
230
+ const conf = this.dbConnectionConfig(connection);
231
+ return this.parallelDatabasesEnabled ? `${conf.name}_${process.env.VITEST_POOL_ID}` : conf.name;
232
+ }
233
+ dbConnectionConfig(connection) {
234
+ const conf = this.dbCredentials?.[connection] || this.dbCredentials?.primary;
235
+ if (!conf)
236
+ throw new Error(`
237
+ Cannot find a connection config given the following connection and node environment:
238
+ connection: ${connection}
239
+ NODE_ENV: ${EnvInternal.nodeEnv}
240
+ `);
241
+ return conf;
242
+ }
243
+ get hasReplicaConfig() {
244
+ return !!this.dbCredentials.replica;
245
+ }
246
+ get parallelDatabasesEnabled() {
247
+ return (!!this.parallelTests &&
248
+ !Number.isNaN(Number(process.env.VITEST_POOL_ID)) &&
249
+ Number(process.env.VITEST_POOL_ID) > 1);
250
+ }
229
251
  async load(resourceType, resourcePath, importCb) {
230
252
  switch (resourceType) {
231
253
  case 'models':
@@ -1,4 +1,4 @@
1
- import ConnectionConfRetriever from '../../db/ConnectionConfRetriever.js';
1
+ import DreamApplication from '../../dream-application/index.js';
2
2
  import EnvInternal from '../EnvInternal.js';
3
3
  import loadPgClient from './loadPgClient.js';
4
4
  export default async function createDb(connection, dbName) {
@@ -6,8 +6,8 @@ export default async function createDb(connection, dbName) {
6
6
  // so there is no way to drop in production
7
7
  if (EnvInternal.isProduction)
8
8
  return false;
9
- const connectionRetriever = new ConnectionConfRetriever();
10
- const dbConf = connectionRetriever.getConnectionConf(connection);
9
+ const dreamApp = DreamApplication.getOrFail();
10
+ const dbConf = dreamApp.dbConnectionConfig(connection);
11
11
  dbName ||= dbConf.name || null;
12
12
  if (!dbName)
13
13
  throw new Error('Must either pass a dbName to the create function, or else ensure that DB_NAME is set in the env');
@@ -1,14 +1,14 @@
1
- import ConnectionConfRetriever from '../../db/ConnectionConfRetriever.js';
2
1
  import DreamApplication from '../../dream-application/index.js';
3
2
  import EnvInternal from '../EnvInternal.js';
4
3
  import loadPgClient from './loadPgClient.js';
4
+ import DreamCLI from '../../cli/index.js';
5
5
  export default async function dropDb(connection, dbName) {
6
6
  // this was only ever written to clear the db between tests or in development,
7
7
  // so there is no way to drop in production
8
8
  if (EnvInternal.isProduction)
9
9
  return false;
10
- const connectionRetriever = new ConnectionConfRetriever();
11
- const dbConf = connectionRetriever.getConnectionConf(connection);
10
+ const dreamApp = DreamApplication.getOrFail();
11
+ const dbConf = dreamApp.dbConnectionConfig(connection);
12
12
  dbName ||= dbConf.name || null;
13
13
  if (!dbName)
14
14
  throw new Error('Must either pass a dbName to the drop function, or else ensure that DB_NAME is set in the env');
@@ -22,12 +22,15 @@ async function maybeDropDuplicateDatabases(client, dbName) {
22
22
  return;
23
23
  if (EnvInternal.boolean('DREAM_CORE_DEVELOPMENT')) {
24
24
  const replicaTestWorkerDatabaseName = `replica_test_${dbName}`;
25
- console.log(`dropping fake replica test database ${replicaTestWorkerDatabaseName}`);
25
+ DreamCLI.logger.logContinueProgress(`dropping fake replica test database ${replicaTestWorkerDatabaseName}`, { logPrefix: ' ├ [db]', logPrefixColor: 'cyan' });
26
26
  await client.query(`DROP DATABASE IF EXISTS ${replicaTestWorkerDatabaseName};`);
27
27
  }
28
28
  for (let i = 2; i <= parallelTests; i++) {
29
29
  const workerDatabaseName = `${dbName}_${i}`;
30
- console.log(`dropping duplicate test database ${workerDatabaseName}`);
30
+ DreamCLI.logger.logContinueProgress(`dropping duplicate test database ${workerDatabaseName}`, {
31
+ logPrefix: ' ├ [db]',
32
+ logPrefixColor: 'cyan',
33
+ });
31
34
  await client.query(`DROP DATABASE IF EXISTS ${workerDatabaseName};`);
32
35
  }
33
36
  }
@@ -1,4 +1,4 @@
1
- import { CompiledQuery, DeleteQueryBuilder, InsertQueryBuilder, SelectQueryBuilder, Updateable, UpdateQueryBuilder } from 'kysely';
1
+ import { CompiledQuery, Updateable } from 'kysely';
2
2
  import { VirtualAttributeStatement } from './decorators/field-or-getter/Virtual.js';
3
3
  import { SortableFieldConfig } from './decorators/field/sortable/Sortable.js';
4
4
  import { ScopeStatement } from './decorators/static-method/Scope.js';
@@ -1011,7 +1011,7 @@ export default class Dream {
1011
1011
  * @param type - The type of Kysely query builder instance you would like to obtain
1012
1012
  * @returns A Kysely query. Depending on the type passed, it will return either a SelectQueryBuilder, DeleteQueryBuilder, UpdateQueryBuilder, or an InsertQueryBuilder
1013
1013
  */
1014
- static toKysely<T extends typeof Dream, QueryType extends 'select' | 'delete' | 'update' | 'insert', ToKyselyReturnType = QueryType extends 'select' ? SelectQueryBuilder<InstanceType<T>['DB'], InstanceType<T>['table'], unknown> : QueryType extends 'delete' ? DeleteQueryBuilder<InstanceType<T>['DB'], InstanceType<T>['table'], unknown> : QueryType extends 'update' ? UpdateQueryBuilder<InstanceType<T>['DB'], InstanceType<T>['table'], InstanceType<T>['table'], unknown> : QueryType extends 'insert' ? InsertQueryBuilder<InstanceType<T>['DB'], InstanceType<T>['table'], unknown> : never>(this: T, type: QueryType): ToKyselyReturnType;
1014
+ static toKysely<T extends typeof Dream, QueryType extends 'select' | 'delete' | 'update'>(this: T, type: QueryType): QueryType extends "select" ? import("kysely").SelectQueryBuilder<InstanceType<T>["DB"], InstanceType<T>["table"] & keyof InstanceType<T>["DB"], unknown> : QueryType extends "delete" ? import("kysely").DeleteQueryBuilder<InstanceType<T>["DB"], InstanceType<T>["table"] & keyof InstanceType<T>["DB"], unknown> : QueryType extends "update" ? import("kysely").UpdateQueryBuilder<InstanceType<T>["DB"], InstanceType<T>["table"] & keyof InstanceType<T>["DB"], InstanceType<T>["table"] & keyof InstanceType<T>["DB"], unknown> : never;
1015
1015
  /**
1016
1016
  * Applies transaction to a new Query scoped
1017
1017
  * to this model
@@ -3,6 +3,7 @@ import { DbConnectionType } from '../types/db.js';
3
3
  export default class DreamDbConnection {
4
4
  static getConnection<DB>(connectionType: DbConnectionType): Kysely<DB>;
5
5
  static dropAllConnections(): Promise<void>;
6
+ private static getConnectionTypeName;
6
7
  }
7
8
  export declare function dreamDbConnections(): {
8
9
  [key: string]: Kysely<any>;
@@ -4,7 +4,7 @@ import Dream from '../Dream.js';
4
4
  import { ColumnNamesAccountingForJoinedAssociations, LimitStatement, OffsetStatement, OrderQueryStatement, PassthroughOnClause, WhereStatement, WhereStatementForJoinedAssociation } from '../types/associations/shared.js';
5
5
  import { DbConnectionType } from '../types/db.js';
6
6
  import { AllDefaultScopeNames, DefaultScopeName, DreamColumnNames, DreamTableSchema, OrderDir, PassthroughColumnNames, PluckEachArgs, PrimaryKeyForFind, RelaxedJoinOnStatement, RelaxedJoinStatement, RelaxedPreloadOnStatement, RelaxedPreloadStatement, TableColumnNames, TableOrAssociationName } from '../types/dream.js';
7
- import { DefaultQueryTypeOptions, ExtendQueryType, NamespacedOrBaseModelColumnTypes } from '../types/query.js';
7
+ import { DefaultQueryTypeOptions, ExtendQueryType, NamespacedOrBaseModelColumnTypes, QueryToKyselyDBType, QueryToKyselyTableNamesType } from '../types/query.js';
8
8
  import { JoinedAssociation, JoinedAssociationsTypeFromAssociations, QueryTypeOptions, VariadicJoinsArgs, VariadicLeftJoinLoadArgs, VariadicLoadArgs } from '../types/variadic.js';
9
9
  import DreamTransaction from './DreamTransaction.js';
10
10
  export default class Query<DreamInstance extends Dream, QueryTypeOpts extends Readonly<QueryTypeOptions> = DefaultQueryTypeOptions<DreamInstance>> extends ConnectedToDB<DreamInstance> {
@@ -635,7 +635,7 @@ export default class Query<DreamInstance extends Dream, QueryTypeOpts extends Re
635
635
  * @param type - the type of Kysely query builder instance you would like to obtain
636
636
  * @returns A Kysely query. Depending on the type passed, it will return either a SelectQueryBuilder, DeleteQueryBuilder, or an UpdateQueryBuilder
637
637
  */
638
- toKysely<QueryType extends 'select' | 'delete' | 'update', ToKyselyReturnType = QueryType extends 'select' ? SelectQueryBuilder<DreamInstance['DB'], DreamInstance['table'], unknown> : QueryType extends 'delete' ? DeleteQueryBuilder<DreamInstance['DB'], DreamInstance['table'], unknown> : QueryType extends 'update' ? UpdateQueryBuilder<DreamInstance['DB'], DreamInstance['table'], DreamInstance['table'], unknown> : never>(type: QueryType): ToKyselyReturnType;
638
+ toKysely<QueryType extends 'select' | 'delete' | 'update', DbType = QueryToKyselyDBType<typeof this>, TableNames = QueryToKyselyTableNamesType<typeof this>, ToKyselyReturnType = QueryType extends 'select' ? SelectQueryBuilder<DbType, TableNames & keyof DbType, unknown> : QueryType extends 'delete' ? DeleteQueryBuilder<DbType, TableNames & keyof DbType, unknown> : QueryType extends 'update' ? UpdateQueryBuilder<DbType, TableNames & keyof DbType, TableNames & keyof DbType, unknown> : never>(type: QueryType): ToKyselyReturnType;
639
639
  /**
640
640
  * Applies transaction to the Query instance
641
641
  *