@cloudbase/manager-node 5.5.2 → 5.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/database/index.js +25 -13
- package/package.json +1 -1
- package/types/database/index.d.ts +2 -1
package/lib/database/index.js
CHANGED
|
@@ -46,6 +46,14 @@ class DatabaseService {
|
|
|
46
46
|
Tag: Databases[0].InstanceId
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
+
getMongoConnector() {
|
|
50
|
+
const currEnv = this.environment;
|
|
51
|
+
const { Databases } = currEnv.lazyEnvironmentConfig;
|
|
52
|
+
return {
|
|
53
|
+
DatabaseName: Databases[0].InstanceId,
|
|
54
|
+
InstanceId: 'flexdb'
|
|
55
|
+
};
|
|
56
|
+
}
|
|
49
57
|
async checkCollectionExists(collectionName) {
|
|
50
58
|
try {
|
|
51
59
|
const result = await this.describeCollection(collectionName);
|
|
@@ -63,10 +71,10 @@ class DatabaseService {
|
|
|
63
71
|
}
|
|
64
72
|
}
|
|
65
73
|
async createCollection(collectionName) {
|
|
66
|
-
|
|
74
|
+
const MongoConnector = this.getMongoConnector();
|
|
67
75
|
const res = await this.dbOpService.request('CreateTable', {
|
|
68
76
|
EnvId: this.envId,
|
|
69
|
-
|
|
77
|
+
MongoConnector,
|
|
70
78
|
TableName: collectionName
|
|
71
79
|
});
|
|
72
80
|
return res;
|
|
@@ -75,10 +83,10 @@ class DatabaseService {
|
|
|
75
83
|
// 先检查当前集合是否存在
|
|
76
84
|
const existRes = await this.checkCollectionExists(collectionName);
|
|
77
85
|
if (existRes.Exists) {
|
|
78
|
-
|
|
86
|
+
const MongoConnector = this.getMongoConnector();
|
|
79
87
|
const res = await this.dbOpService.request('DeleteTable', {
|
|
80
88
|
EnvId: this.envId,
|
|
81
|
-
|
|
89
|
+
MongoConnector,
|
|
82
90
|
TableName: collectionName
|
|
83
91
|
});
|
|
84
92
|
return res;
|
|
@@ -88,15 +96,15 @@ class DatabaseService {
|
|
|
88
96
|
}
|
|
89
97
|
}
|
|
90
98
|
async updateCollection(collectionName, indexiesInfo) {
|
|
91
|
-
|
|
92
|
-
const res = await this.dbOpService.request('UpdateTable', Object.assign({ EnvId: this.envId,
|
|
99
|
+
const MongoConnector = this.getMongoConnector();
|
|
100
|
+
const res = await this.dbOpService.request('UpdateTable', Object.assign({ EnvId: this.envId, MongoConnector, TableName: collectionName }, indexiesInfo));
|
|
93
101
|
return res;
|
|
94
102
|
}
|
|
95
103
|
async describeCollection(collectionName) {
|
|
96
|
-
|
|
104
|
+
const MongoConnector = this.getMongoConnector();
|
|
97
105
|
return this.dbOpService.request('DescribeTable', {
|
|
98
106
|
EnvId: this.envId,
|
|
99
|
-
|
|
107
|
+
MongoConnector,
|
|
100
108
|
TableName: collectionName
|
|
101
109
|
});
|
|
102
110
|
}
|
|
@@ -105,14 +113,14 @@ class DatabaseService {
|
|
|
105
113
|
MgoLimit: this.DEFAULT_MGO_LIMIT,
|
|
106
114
|
MgoOffset: this.DEFAULT_MGO_OFFSET
|
|
107
115
|
}) {
|
|
108
|
-
|
|
116
|
+
const MongoConnector = this.getMongoConnector();
|
|
109
117
|
if (options.MgoLimit === undefined) {
|
|
110
118
|
options.MgoLimit = this.DEFAULT_MGO_LIMIT;
|
|
111
119
|
}
|
|
112
120
|
if (options.MgoOffset === undefined) {
|
|
113
121
|
options.MgoOffset = this.DEFAULT_MGO_OFFSET;
|
|
114
122
|
}
|
|
115
|
-
const res = await this.dbOpService.request('ListTables', Object.assign({ EnvId: this.envId,
|
|
123
|
+
const res = await this.dbOpService.request('ListTables', Object.assign({ EnvId: this.envId, MongoConnector }, options));
|
|
116
124
|
if (res.Tables === null) {
|
|
117
125
|
// 无集合
|
|
118
126
|
res.Collections = [];
|
|
@@ -277,12 +285,16 @@ class DatabaseService {
|
|
|
277
285
|
}
|
|
278
286
|
/**
|
|
279
287
|
* 执行文档型数据库命令
|
|
280
|
-
* @param options 命令参数(命令列表、可选的
|
|
288
|
+
* @param options 命令参数(命令列表、可选的 EnvId/MongoConnector)
|
|
281
289
|
* @returns 执行结果,Data 为 JSON 字符串数组
|
|
282
290
|
*/
|
|
283
291
|
async runCommands(options) {
|
|
284
|
-
|
|
285
|
-
return this.dbOpService.request('RunCommands',
|
|
292
|
+
const MongoConnector = options.MongoConnector || this.getMongoConnector();
|
|
293
|
+
return this.dbOpService.request('RunCommands', {
|
|
294
|
+
MgoCommands: options.MgoCommands,
|
|
295
|
+
MongoConnector,
|
|
296
|
+
EnvId: options.EnvId || this.envId,
|
|
297
|
+
});
|
|
286
298
|
}
|
|
287
299
|
/**
|
|
288
300
|
* 在 PostgreSQL 数据库上执行 SQL 语句
|
package/package.json
CHANGED
|
@@ -155,6 +155,7 @@ export declare class DatabaseService {
|
|
|
155
155
|
constructor(environment: Environment);
|
|
156
156
|
getCurrEnvironment(): Environment;
|
|
157
157
|
getDatabaseConfig(): IDatabaseConfig;
|
|
158
|
+
getMongoConnector(): IMongoConnector;
|
|
158
159
|
checkCollectionExists(collectionName: string): Promise<IExistsRes>;
|
|
159
160
|
createCollection(collectionName: string): Promise<any>;
|
|
160
161
|
deleteCollection(collectionName: string): Promise<any>;
|
|
@@ -197,7 +198,7 @@ export declare class DatabaseService {
|
|
|
197
198
|
restoreTables(time: string, modifyTableNamesInfo: IModifyTableNamesInfo[], instanceId?: string): Promise<IRestoreTCBTablesResult>;
|
|
198
199
|
/**
|
|
199
200
|
* 执行文档型数据库命令
|
|
200
|
-
* @param options 命令参数(命令列表、可选的
|
|
201
|
+
* @param options 命令参数(命令列表、可选的 EnvId/MongoConnector)
|
|
201
202
|
* @returns 执行结果,Data 为 JSON 字符串数组
|
|
202
203
|
*/
|
|
203
204
|
runCommands(options: IRunCommandsOptions): Promise<IRunCommandsResult>;
|