@rvoh/dream 1.4.2 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +66 -0
- package/dist/cjs/src/Dream.js +12 -16
- package/dist/cjs/src/bin/index.js +23 -7
- package/dist/cjs/src/cli/index.js +18 -3
- package/dist/cjs/src/db/ConnectedToDB.js +0 -8
- package/dist/cjs/src/db/DreamDbConnection.js +25 -36
- package/dist/cjs/src/db/helpers/dbTypesFilenameForConnection.js +6 -0
- package/dist/cjs/src/{bin/helpers/sync.js → db/helpers/syncDbTypesFiles.js} +8 -5
- package/dist/cjs/src/db/index.js +3 -2
- package/dist/cjs/src/decorators/field/sortable/helpers/setPosition.js +17 -2
- package/dist/cjs/src/dream/Query.js +9 -6
- package/dist/cjs/src/dream/QueryDriver/Base.js +111 -7
- package/dist/cjs/src/dream/QueryDriver/Kysely.js +213 -86
- package/dist/cjs/src/dream/QueryDriver/Postgres.js +162 -0
- package/dist/cjs/src/{helpers/db → dream/QueryDriver/helpers/kysely}/runMigration.js +20 -16
- package/dist/cjs/src/{helpers/db → dream/QueryDriver/helpers/pg}/createDb.js +5 -5
- package/dist/cjs/src/{helpers/db → dream/QueryDriver/helpers/pg}/dropDb.js +6 -6
- package/dist/cjs/src/{helpers/db → dream/QueryDriver/helpers/pg}/loadPgClient.js +5 -3
- package/dist/cjs/src/dream/internal/destroyDream.js +3 -10
- package/dist/cjs/src/dream/internal/saveDream.js +1 -1
- package/dist/cjs/src/dream/internal/similarity/SimilarityBuilder.js +9 -3
- package/dist/cjs/src/dream-app/index.js +47 -64
- package/dist/cjs/src/helpers/cli/SchemaBuilder.js +30 -42
- package/dist/cjs/src/helpers/cli/generateDream.js +2 -0
- package/dist/cjs/src/helpers/cli/generateDreamContent.js +5 -3
- package/dist/cjs/src/helpers/cli/generateFactoryContent.js +29 -0
- package/dist/cjs/src/helpers/cli/generateMigration.js +7 -5
- package/dist/cjs/src/helpers/cli/generateMigrationContent.js +48 -15
- package/dist/cjs/src/helpers/db/primaryKeyType.js +4 -22
- package/dist/cjs/src/helpers/sqlAttributes.js +4 -1
- package/dist/cjs/src/index.js +8 -2
- package/dist/esm/src/Dream.js +10 -14
- package/dist/esm/src/bin/index.js +23 -7
- package/dist/esm/src/cli/index.js +18 -3
- package/dist/esm/src/db/ConnectedToDB.js +0 -8
- package/dist/esm/src/db/DreamDbConnection.js +22 -34
- package/dist/esm/src/db/helpers/dbTypesFilenameForConnection.js +3 -0
- package/dist/esm/src/{bin/helpers/sync.js → db/helpers/syncDbTypesFiles.js} +7 -4
- package/dist/esm/src/db/index.js +3 -2
- package/dist/esm/src/decorators/field/sortable/helpers/setPosition.js +16 -2
- package/dist/esm/src/dream/Query.js +9 -6
- package/dist/esm/src/dream/QueryDriver/Base.js +111 -7
- package/dist/esm/src/dream/QueryDriver/Kysely.js +215 -88
- package/dist/esm/src/dream/QueryDriver/Postgres.js +162 -0
- package/dist/esm/src/{helpers/db → dream/QueryDriver/helpers/kysely}/runMigration.js +14 -10
- package/dist/esm/src/{helpers/db → dream/QueryDriver/helpers/pg}/createDb.js +5 -5
- package/dist/esm/src/{helpers/db → dream/QueryDriver/helpers/pg}/dropDb.js +6 -6
- package/dist/esm/src/{helpers/db → dream/QueryDriver/helpers/pg}/loadPgClient.js +5 -3
- package/dist/esm/src/dream/internal/destroyDream.js +3 -10
- package/dist/esm/src/dream/internal/saveDream.js +1 -1
- package/dist/esm/src/dream/internal/similarity/SimilarityBuilder.js +9 -3
- package/dist/esm/src/dream-app/index.js +44 -61
- package/dist/esm/src/helpers/cli/SchemaBuilder.js +24 -36
- package/dist/esm/src/helpers/cli/generateDream.js +2 -0
- package/dist/esm/src/helpers/cli/generateDreamContent.js +5 -3
- package/dist/esm/src/helpers/cli/generateFactoryContent.js +29 -0
- package/dist/esm/src/helpers/cli/generateMigration.js +7 -5
- package/dist/esm/src/helpers/cli/generateMigrationContent.js +48 -15
- package/dist/esm/src/helpers/db/primaryKeyType.js +4 -22
- package/dist/esm/src/helpers/sqlAttributes.js +4 -1
- package/dist/esm/src/index.js +3 -0
- package/dist/types/src/Dream.d.ts +5 -3
- package/dist/types/src/bin/index.d.ts +3 -1
- package/dist/types/src/db/ConnectedToDB.d.ts +0 -2
- package/dist/types/src/db/DreamDbConnection.d.ts +7 -3
- package/dist/types/src/db/helpers/dbTypesFilenameForConnection.d.ts +1 -0
- package/dist/types/src/db/helpers/syncDbTypesFiles.d.ts +1 -0
- package/dist/types/src/db/index.d.ts +2 -1
- package/dist/types/src/decorators/field/sortable/helpers/setPosition.d.ts +2 -0
- package/dist/types/src/dream/Query.d.ts +5 -20
- package/dist/types/src/dream/QueryDriver/Base.d.ts +74 -13
- package/dist/types/src/dream/QueryDriver/Kysely.d.ts +75 -9
- package/dist/types/src/dream/QueryDriver/Postgres.d.ts +32 -0
- package/dist/types/src/dream/QueryDriver/helpers/kysely/foreignKeyTypeFromPrimaryKey.d.ts +2 -0
- package/dist/types/src/dream/QueryDriver/helpers/kysely/runMigration.d.ts +9 -0
- package/dist/types/src/dream/QueryDriver/helpers/pg/createDb.d.ts +2 -0
- package/dist/types/src/dream/QueryDriver/helpers/pg/dropDb.d.ts +2 -0
- package/dist/types/src/dream/QueryDriver/helpers/pg/loadPgClient.d.ts +5 -0
- package/dist/types/src/dream/internal/destroyOptions.d.ts +3 -3
- package/dist/types/src/dream-app/index.d.ts +11 -6
- package/dist/types/src/helpers/cli/SchemaBuilder.d.ts +26 -0
- package/dist/types/src/helpers/cli/generateDream.d.ts +1 -0
- package/dist/types/src/helpers/cli/generateDreamContent.d.ts +2 -1
- package/dist/types/src/helpers/cli/generateMigration.d.ts +2 -1
- package/dist/types/src/helpers/cli/generateMigrationContent.d.ts +2 -1
- package/dist/types/src/helpers/db/primaryKeyType.d.ts +1 -1
- package/dist/types/src/index.d.ts +3 -0
- package/dist/types/src/types/dream.d.ts +4 -4
- package/dist/types/src/types/dream.ts +8 -9
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/Benchmark.html +2 -2
- package/docs/classes/CalendarDate.html +2 -2
- package/docs/classes/CheckConstraintViolation.html +3 -3
- package/docs/classes/CliFileWriter.html +2 -2
- package/docs/classes/CreateOrFindByFailedToCreateAndFind.html +3 -3
- package/docs/classes/DataTypeColumnTypeMismatch.html +3 -3
- package/docs/classes/Decorators.html +19 -19
- package/docs/classes/Dream.html +117 -115
- package/docs/classes/DreamApp.html +8 -5
- package/docs/classes/DreamBin.html +2 -2
- package/docs/classes/DreamCLI.html +4 -4
- package/docs/classes/DreamImporter.html +2 -2
- package/docs/classes/DreamLogos.html +2 -2
- package/docs/classes/DreamMigrationHelpers.html +7 -7
- package/docs/classes/DreamSerializerBuilder.html +8 -8
- package/docs/classes/DreamTransaction.html +2 -2
- package/docs/classes/Encrypt.html +2 -2
- package/docs/classes/Env.html +2 -2
- package/docs/classes/GlobalNameNotSet.html +3 -3
- package/docs/classes/KyselyQueryDriver.html +163 -0
- package/docs/classes/NonLoadedAssociation.html +3 -3
- package/docs/classes/NotNullViolation.html +3 -3
- package/docs/classes/ObjectSerializerBuilder.html +8 -8
- package/docs/classes/PostgresQueryDriver.html +165 -0
- package/docs/classes/Query.html +59 -87
- package/docs/classes/QueryDriverBase.html +156 -0
- package/docs/classes/Range.html +2 -2
- package/docs/classes/RecordNotFound.html +3 -3
- package/docs/classes/ValidationError.html +3 -3
- package/docs/functions/DreamSerializer.html +1 -1
- package/docs/functions/ObjectSerializer.html +1 -1
- package/docs/functions/ReplicaSafe.html +1 -1
- package/docs/functions/STI.html +1 -1
- package/docs/functions/SoftDelete.html +1 -1
- package/docs/functions/camelize.html +1 -1
- package/docs/functions/capitalize.html +1 -1
- package/docs/functions/cloneDeepSafe.html +1 -1
- package/docs/functions/closeAllDbConnections.html +1 -1
- package/docs/functions/compact.html +1 -1
- package/docs/functions/dreamDbConnections.html +1 -1
- package/docs/functions/dreamPath.html +1 -1
- package/docs/functions/expandStiClasses.html +1 -1
- package/docs/functions/generateDream.html +1 -1
- package/docs/functions/globalClassNameFromFullyQualifiedModelName.html +1 -1
- package/docs/functions/groupBy.html +1 -1
- package/docs/functions/hyphenize.html +1 -1
- package/docs/functions/inferSerializerFromDreamOrViewModel.html +1 -1
- package/docs/functions/inferSerializersFromDreamClassOrViewModelClass.html +1 -1
- package/docs/functions/intersection.html +1 -1
- package/docs/functions/isDreamSerializer.html +1 -1
- package/docs/functions/isEmpty.html +1 -1
- package/docs/functions/loadRepl.html +1 -1
- package/docs/functions/lookupClassByGlobalName.html +1 -1
- package/docs/functions/normalizeUnicode.html +1 -1
- package/docs/functions/pascalize.html +1 -1
- package/docs/functions/pgErrorType.html +1 -1
- package/docs/functions/range-1.html +1 -1
- package/docs/functions/relativeDreamPath.html +1 -1
- package/docs/functions/round.html +1 -1
- package/docs/functions/serializerNameFromFullyQualifiedModelName.html +1 -1
- package/docs/functions/sharedPathPrefix.html +1 -1
- package/docs/functions/snakeify.html +1 -1
- package/docs/functions/sort.html +1 -1
- package/docs/functions/sortBy.html +1 -1
- package/docs/functions/sortObjectByKey.html +1 -1
- package/docs/functions/sortObjectByValue.html +1 -1
- package/docs/functions/standardizeFullyQualifiedModelName.html +1 -1
- package/docs/functions/uncapitalize.html +1 -1
- package/docs/functions/uniq.html +1 -1
- package/docs/functions/untypedDb.html +1 -1
- package/docs/functions/validateColumn.html +1 -1
- package/docs/functions/validateTable.html +1 -1
- package/docs/hierarchy.html +1 -0
- package/docs/interfaces/BelongsToStatement.html +2 -2
- package/docs/interfaces/DecoratorContext.html +2 -2
- package/docs/interfaces/DreamAppInitOptions.html +2 -2
- package/docs/interfaces/DreamAppOpts.html +2 -2
- package/docs/interfaces/EncryptOptions.html +2 -2
- package/docs/interfaces/InternalAnyTypedSerializerRendersMany.html +2 -2
- package/docs/interfaces/InternalAnyTypedSerializerRendersOne.html +2 -2
- package/docs/interfaces/OpenapiDescription.html +2 -2
- package/docs/interfaces/OpenapiSchemaProperties.html +1 -1
- package/docs/interfaces/OpenapiSchemaPropertiesShorthand.html +1 -1
- package/docs/interfaces/OpenapiTypeFieldObject.html +1 -1
- package/docs/interfaces/SerializerRendererOpts.html +2 -2
- package/docs/modules.html +3 -0
- package/docs/types/Camelized.html +1 -1
- package/docs/types/CommonOpenapiSchemaObjectFields.html +1 -1
- package/docs/types/DateTime.html +1 -1
- package/docs/types/DbConnectionType.html +1 -1
- package/docs/types/DbTypes.html +1 -1
- package/docs/types/DreamAppAllowedPackageManagersEnum.html +1 -1
- package/docs/types/DreamAssociationMetadata.html +1 -1
- package/docs/types/DreamAttributes.html +1 -1
- package/docs/types/DreamClassAssociationAndStatement.html +1 -1
- package/docs/types/DreamClassColumn.html +1 -1
- package/docs/types/DreamColumn.html +1 -1
- package/docs/types/DreamColumnNames.html +1 -1
- package/docs/types/DreamLogLevel.html +1 -1
- package/docs/types/DreamLogger.html +1 -1
- package/docs/types/DreamModelSerializerType.html +1 -1
- package/docs/types/DreamOrViewModelClassSerializerKey.html +1 -1
- package/docs/types/DreamOrViewModelSerializerKey.html +1 -1
- package/docs/types/DreamParamSafeAttributes.html +1 -1
- package/docs/types/DreamParamSafeColumnNames.html +1 -1
- package/docs/types/DreamSerializable.html +1 -1
- package/docs/types/DreamSerializableArray.html +1 -1
- package/docs/types/DreamSerializerKey.html +1 -1
- package/docs/types/DreamSerializers.html +1 -1
- package/docs/types/DreamVirtualColumns.html +1 -1
- package/docs/types/EncryptAlgorithm.html +1 -1
- package/docs/types/HasManyStatement.html +1 -1
- package/docs/types/HasOneStatement.html +1 -1
- package/docs/types/Hyphenized.html +1 -1
- package/docs/types/OpenapiAllTypes.html +1 -1
- package/docs/types/OpenapiFormats.html +1 -1
- package/docs/types/OpenapiNumberFormats.html +1 -1
- package/docs/types/OpenapiPrimitiveBaseTypes.html +1 -1
- package/docs/types/OpenapiPrimitiveTypes.html +1 -1
- package/docs/types/OpenapiSchemaArray.html +1 -1
- package/docs/types/OpenapiSchemaArrayShorthand.html +1 -1
- package/docs/types/OpenapiSchemaBase.html +1 -1
- package/docs/types/OpenapiSchemaBody.html +1 -1
- package/docs/types/OpenapiSchemaBodyShorthand.html +1 -1
- package/docs/types/OpenapiSchemaCommonFields.html +1 -1
- package/docs/types/OpenapiSchemaExpressionAllOf.html +1 -1
- package/docs/types/OpenapiSchemaExpressionAnyOf.html +1 -1
- package/docs/types/OpenapiSchemaExpressionOneOf.html +1 -1
- package/docs/types/OpenapiSchemaExpressionRef.html +1 -1
- package/docs/types/OpenapiSchemaExpressionRefSchemaShorthand.html +1 -1
- package/docs/types/OpenapiSchemaInteger.html +1 -1
- package/docs/types/OpenapiSchemaNull.html +1 -1
- package/docs/types/OpenapiSchemaNumber.html +1 -1
- package/docs/types/OpenapiSchemaObject.html +1 -1
- package/docs/types/OpenapiSchemaObjectAllOf.html +1 -1
- package/docs/types/OpenapiSchemaObjectAllOfShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectAnyOf.html +1 -1
- package/docs/types/OpenapiSchemaObjectAnyOfShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectBase.html +1 -1
- package/docs/types/OpenapiSchemaObjectBaseShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectOneOf.html +1 -1
- package/docs/types/OpenapiSchemaObjectOneOfShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectShorthand.html +1 -1
- package/docs/types/OpenapiSchemaPrimitiveGeneric.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionAllOf.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionAnyOf.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionOneOf.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionSerializableRef.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionSerializerRef.html +1 -1
- package/docs/types/OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
- package/docs/types/OpenapiSchemaString.html +1 -1
- package/docs/types/OpenapiShorthandAllTypes.html +1 -1
- package/docs/types/OpenapiShorthandPrimitiveBaseTypes.html +1 -1
- package/docs/types/OpenapiShorthandPrimitiveTypes.html +1 -1
- package/docs/types/OpenapiTypeField.html +1 -1
- package/docs/types/Pascalized.html +1 -1
- package/docs/types/RoundingPrecision.html +1 -1
- package/docs/types/SerializerCasing.html +1 -1
- package/docs/types/SimpleObjectSerializerType.html +1 -1
- package/docs/types/Snakeified.html +1 -1
- package/docs/types/UpdateableAssociationProperties.html +1 -1
- package/docs/types/UpdateableProperties.html +1 -1
- package/docs/types/ValidationType.html +1 -1
- package/docs/types/ViewModel.html +1 -1
- package/docs/types/ViewModelClass.html +1 -1
- package/docs/types/WhereStatementForDream.html +1 -1
- package/docs/types/WhereStatementForDreamClass.html +1 -1
- package/docs/variables/DateTime-1.html +1 -1
- package/docs/variables/DreamAppAllowedPackageManagersEnumValues.html +1 -1
- package/docs/variables/DreamConst.html +1 -1
- package/docs/variables/TRIGRAM_OPERATORS.html +1 -1
- package/docs/variables/openapiPrimitiveTypes-1.html +1 -1
- package/docs/variables/openapiShorthandPrimitiveTypes-1.html +1 -1
- package/docs/variables/ops.html +1 -1
- package/docs/variables/primaryKeyTypes.html +1 -1
- package/package.json +3 -2
- package/dist/cjs/src/helpers/db/truncateDb.js +0 -27
- package/dist/esm/src/helpers/db/truncateDb.js +0 -24
- package/dist/types/src/bin/helpers/sync.d.ts +0 -1
- package/dist/types/src/helpers/db/createDb.d.ts +0 -2
- package/dist/types/src/helpers/db/dropDb.d.ts +0 -2
- package/dist/types/src/helpers/db/foreignKeyTypeFromPrimaryKey.d.ts +0 -2
- package/dist/types/src/helpers/db/loadPgClient.d.ts +0 -4
- package/dist/types/src/helpers/db/runMigration.d.ts +0 -6
- package/dist/types/src/helpers/db/truncateDb.d.ts +0 -1
- /package/dist/cjs/src/{helpers/db → dream/QueryDriver/helpers/kysely}/foreignKeyTypeFromPrimaryKey.js +0 -0
- /package/dist/esm/src/{helpers/db → dream/QueryDriver/helpers/kysely}/foreignKeyTypeFromPrimaryKey.js +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,69 @@
|
|
|
1
|
+
## 1.5.0
|
|
2
|
+
|
|
3
|
+
- add support for multiple database connections in a single dream application. To take advantage of this new feature, you can do the following:
|
|
4
|
+
|
|
5
|
+
1. Add a new connection configuration to your conf/dream.ts file, providing it an explicit alternate connection name as the second argument, like so:
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
dreamApp.set('db', 'myAlternateConnection', {
|
|
9
|
+
primary: {
|
|
10
|
+
user: AppEnv.string('DB_USER'),
|
|
11
|
+
password: AppEnv.string('DB_PASSWORD', { optional: !AppEnv.isProduction }),
|
|
12
|
+
host: AppEnv.string('DB_HOST', { optional: true }),
|
|
13
|
+
name: AppEnv.string('DB_NAME_2', { optional: true }),
|
|
14
|
+
port: AppEnv.integer('DB_PORT_2', { optional: true }),
|
|
15
|
+
useSsl: false,
|
|
16
|
+
},
|
|
17
|
+
})
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Be sure to add any new environment variables to your .env and .env.test files.
|
|
21
|
+
|
|
22
|
+
2. Run sync
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
yarn psy sync
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
3. add a new application model for your new connection, naming it the name of your connection, pascalized, with the string `ApplicationModel` at the end, like so:
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
// app/models/MyAlternateConnectionApplicationModel.ts
|
|
32
|
+
|
|
33
|
+
import Dream from '../../../src/Dream.js'
|
|
34
|
+
import { DBClass } from '../../types/db.alternateConnection.js'
|
|
35
|
+
import { connectionTypeConfig, schema } from '../../types/dream.alternateConnection.js'
|
|
36
|
+
import { globalTypeConfig } from '../../types/dream.globals.js'
|
|
37
|
+
|
|
38
|
+
export default class MyAlternateConnectionApplicationModel extends Dream {
|
|
39
|
+
declare public DB: DBClass
|
|
40
|
+
|
|
41
|
+
public override get connectionName() {
|
|
42
|
+
return 'alternateConnection' as const
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public override get schema(): any {
|
|
46
|
+
return schema
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public override get connectionTypeConfig() {
|
|
50
|
+
return connectionTypeConfig
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public override get globalTypeConfig() {
|
|
54
|
+
return globalTypeConfig
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
4. Now you can proceed to generate a model for your new connection, like so:
|
|
60
|
+
|
|
61
|
+
```sh
|
|
62
|
+
yarn psy g:model MyNewModel someField:text --connection-name=myAlternateConnection
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Dream will automatically read the connectionName and use it to derive the `MyAlternateConnectionApplicationModel` automatically, though if this isn't correct, you will need to manually adjust it.
|
|
66
|
+
|
|
1
67
|
## 1.4.2
|
|
2
68
|
|
|
3
69
|
- add ability to set custom import extension, which will be used when generating new files for your application
|
package/dist/cjs/src/Dream.js
CHANGED
|
@@ -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
|
|
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
|
|
112
|
-
|
|
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 =
|
|
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
|
|
1737
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default =
|
|
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
|
-
|
|
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
|
|
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
|
|
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',
|
package/dist/cjs/src/db/index.js
CHANGED
|
@@ -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
|
}
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = setPosition;
|
|
4
4
|
exports.applySortableScopesToQuery = applySortableScopesToQuery;
|
|
5
|
-
|
|
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
|
|
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
|
-
|
|
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
|
/**
|