dbRequest.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. const httpRequest_1 = __importDefault(require("./httpRequest"));
  7. /**
  8. * 数据库模块的通用请求方法
  9. *
  10. * @author haroldhu
  11. * @internal
  12. */
  13. class DBRequest {
  14. /**
  15. * 初始化
  16. *
  17. * @internal
  18. * @param config
  19. */
  20. constructor(config) {
  21. this.config = config;
  22. }
  23. /**
  24. * 发送请求
  25. *
  26. * @param dbParams - 数据库请求参数
  27. * @param opts - 可选配置项
  28. */
  29. async send(api, data, opts) {
  30. const params = Object.assign({}, data, { action: api });
  31. return httpRequest_1.default({
  32. config: this.config,
  33. params,
  34. method: 'post',
  35. opts,
  36. headers: {
  37. 'content-type': 'application/json'
  38. }
  39. });
  40. }
  41. }
  42. exports.DBRequest = DBRequest;