dbConf.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * Created by Macheng on 2021/04/26 .
  3. */
  4. import BaseModel from './baseModel'
  5. class DbConf extends BaseModel {
  6. id = 'default' // 数据库ID
  7. type = 0 // 数据库类型 1: Redis, 2: MySQL, 3: SQLite
  8. dbStatus = 0 // 运行状态 0: disconnect, 1: connect
  9. ip = '127.0.0.1' // IP
  10. port = 0 // Port
  11. user = '' // 用户名
  12. password = '' // 密码
  13. dbName = '' // 默认数据名称
  14. constructor(opts) {
  15. if (!opts) opts = {}
  16. super(opts)
  17. this.init(opts)
  18. }
  19. init(opts) {
  20. if (!opts) opts = {}
  21. super.init(opts)
  22. this.id = opts['id'] || this.id
  23. this.type = Number(opts['type']) || this.type
  24. this.dbStatus = Number(opts['dbStatus'])
  25. this.ip = opts['ip'] || this.ip
  26. this.port = Number(opts['port']) || this.port
  27. this.user = opts['user'] || this.user
  28. this.password = opts['password'] || this.password
  29. this.dbName = opts['dbName'] || this.dbName
  30. }
  31. toJson() {
  32. const obj1 = super.toJson()
  33. const obj2 = {
  34. id: this.id,
  35. type: this.type,
  36. dbStatus: this.dbStatus,
  37. ip: this.ip,
  38. port: this.port,
  39. user: this.user,
  40. password: this.password,
  41. dbName: this.dbName
  42. }
  43. return Object.assign({}, obj1, obj2)
  44. }
  45. }
  46. export default DbConf