@cloudbase/manager-node 5.3.0 → 5.4.0-beta.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.
package/jest.config.js CHANGED
@@ -10,7 +10,10 @@ module.exports = {
10
10
  },
11
11
  transformIgnorePatterns: ['node_modules'],
12
12
  testEnvironment: 'node',
13
- forceExit: true,
13
+ testPathIgnorePatterns: [
14
+ // PG 集成测试 / smoke 测试需要 PostgreSQL 环境,流水线默认跳过
15
+ '/pg-storage-integration\\.test\\.ts$/'
16
+ ],
14
17
  // https://github.com/facebook/jest/issues/5164
15
18
  globalSetup: './test/global-setup-hook.ts',
16
19
  // globalTeardown: './test/global-teardown-hook.js',
@@ -281,6 +281,39 @@ class DatabaseService {
281
281
  let { Tag } = this.getDatabaseConfig();
282
282
  return this.dbOpService.request('RunCommands', Object.assign({ MgoCommands: options.MgoCommands, Tag: options.Tag || Tag, EnvId: options.EnvId || this.envId }, (options.MongoConnector ? { MongoConnector: options.MongoConnector } : {})));
283
283
  }
284
+ /**
285
+ * 在 PostgreSQL 数据库上执行 SQL 语句
286
+ *
287
+ * @param options 执行参数
288
+ * @param options.Sql 要执行的 SQL 语句
289
+ * @param options.Role 指定 role 执行 SQL(可选)
290
+ * @param options.EnvId 环境 ID(可选,不传则自动使用当前环境 ID)
291
+ * @returns 执行结果,包含影响行数、字段列表、数据行及执行耗时
292
+ *
293
+ * @example
294
+ * // 创建表
295
+ * const res = await database.executePGSql({
296
+ * Sql: 'CREATE TABLE users (id SERIAL PRIMARY KEY, name TEXT NOT NULL)'
297
+ * })
298
+ *
299
+ * @example
300
+ * // 查询数据
301
+ * const res = await database.executePGSql({
302
+ * Sql: "SELECT * FROM users WHERE id = 1"
303
+ * })
304
+ * console.log(res.Columns) // ['id', 'name']
305
+ * console.log(res.Rows) // ['["1","Alice"]']
306
+ */
307
+ async executePGSql(options) {
308
+ const params = {
309
+ EnvId: options.EnvId || this.envId,
310
+ Sql: options.Sql
311
+ };
312
+ if (options.Role) {
313
+ params.Role = options.Role;
314
+ }
315
+ return this.dbOpService.request('ExecutePGSql', params);
316
+ }
284
317
  }
285
318
  exports.DatabaseService = DatabaseService;
286
319
  DatabaseService.tcbServiceVersion = {
@@ -321,3 +354,6 @@ __decorate([
321
354
  __decorate([
322
355
  preLazy()
323
356
  ], DatabaseService.prototype, "runCommands", null);
357
+ __decorate([
358
+ preLazy()
359
+ ], DatabaseService.prototype, "executePGSql", null);