vona-module-a-orm 5.0.85 → 5.0.86
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.
|
@@ -11,5 +11,4 @@ export declare class BeanDatabase extends BeanBase {
|
|
|
11
11
|
getDialect(client: keyof IDatabaseClientDialectRecord): BeanDatabaseDialectBase;
|
|
12
12
|
switchDbIsolate<RESULT>(fn: FunctionAsync<RESULT>, dbInfoOrClientName?: Partial<IDbInfo> | keyof IDatabaseClientRecord): Promise<RESULT>;
|
|
13
13
|
switchDb<RESULT>(fn: FunctionAsync<RESULT>, dbInfoOrClientName?: Partial<IDbInfo> | keyof IDatabaseClientRecord): Promise<RESULT>;
|
|
14
|
-
private _prepareClientConfig;
|
|
15
14
|
}
|
|
@@ -6,8 +6,9 @@ import type { IDatabaseDialectCapabilities, IFetchDatabasesResultItem, IFetchInd
|
|
|
6
6
|
import { BeanBase } from 'vona';
|
|
7
7
|
export declare class BeanDatabaseDialectBase extends BeanBase {
|
|
8
8
|
protected _capabilities?: IDatabaseDialectCapabilities;
|
|
9
|
+
protected _configBase?: Partial<ConfigDatabaseClient>;
|
|
9
10
|
get capabilities(): IDatabaseDialectCapabilities;
|
|
10
|
-
|
|
11
|
+
get configBase(): Partial<ConfigDatabaseClient> | undefined;
|
|
11
12
|
fetchDatabases(_schemaBuilder: Knex.SchemaBuilder, _databasePrefix: string): Promise<IFetchDatabasesResultItem[]>;
|
|
12
13
|
createDatabase(_schemaBuilder: Knex.SchemaBuilder, _databaseName: string): Promise<string>;
|
|
13
14
|
dropDatabase(_schemaBuilder: Knex.SchemaBuilder, _databaseName: string): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -190,20 +190,20 @@ let ServiceDatabase = (_dec$r = Service(), _dec2$r = BeanInfo({
|
|
|
190
190
|
get configDatabase() {
|
|
191
191
|
return this.app.config.database;
|
|
192
192
|
}
|
|
193
|
-
getClientConfig(clientName, original
|
|
193
|
+
getClientConfig(clientName, clientConfig, original) {
|
|
194
194
|
// clientConfig
|
|
195
|
-
|
|
196
|
-
|
|
195
|
+
if (!clientConfig) {
|
|
196
|
+
clientConfig = this.configDatabase.clients[clientName];
|
|
197
|
+
}
|
|
197
198
|
// check
|
|
198
199
|
if (!clientConfig) {
|
|
199
200
|
throw new Error(`database config not found: ${clientName}`);
|
|
200
201
|
}
|
|
202
|
+
if (original) return clientConfig;
|
|
201
203
|
// configBaseClient
|
|
202
204
|
const dialect = this.bean.database.getDialect(clientConfig.client);
|
|
203
|
-
const configBaseClient = dialect.getConfigBase();
|
|
204
205
|
// combine
|
|
205
|
-
|
|
206
|
-
clientConfig = deepExtend({}, configBase, configBaseClient, clientConfig);
|
|
206
|
+
clientConfig = deepExtend({}, this.configDatabase.base, dialect.configBase, clientConfig);
|
|
207
207
|
// ready
|
|
208
208
|
return clientConfig;
|
|
209
209
|
}
|
|
@@ -689,8 +689,9 @@ let ServiceDatabaseClient = (_dec$k = Service(), _dec2$k = BeanInfo({
|
|
|
689
689
|
}
|
|
690
690
|
}
|
|
691
691
|
async reload(clientConfig) {
|
|
692
|
+
const clientConfigReal = this.scope.service.database.getClientConfig(this.clientName, clientConfig);
|
|
692
693
|
await this.__close();
|
|
693
|
-
this.__load(this.clientNameSelector,
|
|
694
|
+
this.__load(this.clientNameSelector, clientConfigReal);
|
|
694
695
|
}
|
|
695
696
|
getDatabaseName() {
|
|
696
697
|
const connection = this.clientConfig.connection;
|
|
@@ -713,7 +714,7 @@ let ServiceDatabaseClient = (_dec$k = Service(), _dec2$k = BeanInfo({
|
|
|
713
714
|
const connDatabaseName = this._prepareDatabaseName(databaseName);
|
|
714
715
|
// set config
|
|
715
716
|
// * should not use this.clientConfig.connection, because password is hidden
|
|
716
|
-
const config = this.scope.service.database.getClientConfig(this.clientName, true);
|
|
717
|
+
const config = this.scope.service.database.getClientConfig(this.clientName, undefined, true);
|
|
717
718
|
config.connection = Object.assign({}, config.connection, connDatabaseName);
|
|
718
719
|
// only used by startup, so no consider that workers broadcast
|
|
719
720
|
this.configDatabase.clients[this.clientName] = config;
|
|
@@ -732,7 +733,7 @@ let BeanDatabase = (_dec$j = Bean(), _dec2$j = BeanInfo({
|
|
|
732
733
|
}
|
|
733
734
|
getClient(dbInfoOrClientName, clientConfig) {
|
|
734
735
|
const dbInfo = this.scope.service.database.prepareDbInfo(dbInfoOrClientName);
|
|
735
|
-
const clientConfigReal = this.
|
|
736
|
+
const clientConfigReal = this.scope.service.database.getClientConfig(dbInfo.clientName, clientConfig);
|
|
736
737
|
const selector = this.scope.service.database.prepareClientNameSelector(dbInfo, clientConfigReal.client);
|
|
737
738
|
return this.app.bean._getBeanSelector(ServiceDatabaseClient, selector, clientConfigReal);
|
|
738
739
|
}
|
|
@@ -766,11 +767,6 @@ let BeanDatabase = (_dec$j = Bean(), _dec2$j = BeanInfo({
|
|
|
766
767
|
return this.bean._getBean(ServiceTransactionAsyncLocalStorage).run(fn);
|
|
767
768
|
});
|
|
768
769
|
}
|
|
769
|
-
|
|
770
|
-
// only for bean.database.getClient
|
|
771
|
-
_prepareClientConfig(clientName, clientConfig) {
|
|
772
|
-
return clientConfig ? deepExtend({}, clientConfig) : this.scope.service.database.getClientConfig(clientName);
|
|
773
|
-
}
|
|
774
770
|
}) || _class$j) || _class$j);
|
|
775
771
|
|
|
776
772
|
var _dec$i, _dec2$i, _dec3$7, _class$i;
|
|
@@ -780,13 +776,14 @@ let BeanDatabaseDialectBase = (_dec$i = Bean(), _dec2$i = Virtual(), _dec3$7 = B
|
|
|
780
776
|
constructor(...args) {
|
|
781
777
|
super(...args);
|
|
782
778
|
this._capabilities = void 0;
|
|
779
|
+
this._configBase = void 0;
|
|
783
780
|
}
|
|
784
781
|
get capabilities() {
|
|
785
782
|
if (!this._capabilities) throw new Error('Should provide dialect capabilities');
|
|
786
783
|
return this._capabilities;
|
|
787
784
|
}
|
|
788
|
-
|
|
789
|
-
return
|
|
785
|
+
get configBase() {
|
|
786
|
+
return this._configBase;
|
|
790
787
|
}
|
|
791
788
|
async fetchDatabases(_schemaBuilder, _databasePrefix) {
|
|
792
789
|
throw new Error('Not Implemented');
|
|
@@ -4,7 +4,7 @@ import type { IDatabaseClientDialectRecord, IDatabaseClientRecord, IDbInfo } fro
|
|
|
4
4
|
import { BeanBase } from 'vona';
|
|
5
5
|
export declare class ServiceDatabase extends BeanBase {
|
|
6
6
|
get configDatabase(): import("../types/config.ts").ConfigDatabase;
|
|
7
|
-
getClientConfig(clientName: keyof IDatabaseClientRecord, original?: boolean): ConfigDatabaseClient;
|
|
7
|
+
getClientConfig(clientName: keyof IDatabaseClientRecord, clientConfig?: ConfigDatabaseClient, original?: boolean): ConfigDatabaseClient;
|
|
8
8
|
prepareDbInfo(dbInfoOrClientName?: Partial<IDbInfo> | keyof IDatabaseClientRecord): IDbInfo;
|
|
9
9
|
prepareClientNameSelector(dbInfo: IDbInfo, dialect: BeanDatabaseDialectBase | keyof IDatabaseClientDialectRecord): string;
|
|
10
10
|
parseClientNameSelector(clientNameSelector: string): IDbInfo;
|