Model.js 872 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. 'use strict';
  2. var MySql = require('../framework/lib/OujMySql.js');
  3. var TableHelper = require('../framework/lib/TableHelper.js');
  4. class Model {
  5. constructor(tableName, dbKey) {
  6. this.tableName = tableName;
  7. this.dbKey = dbKey || 'default';
  8. if (!tableName) {
  9. return;
  10. }
  11. /**
  12. * 数据库的表助手
  13. * @type {TableHelper}
  14. */
  15. this.objTable = new TableHelper(tableName, this.dbKey);
  16. /**
  17. * 数据库的操作类
  18. * @type {OujMySql}
  19. */
  20. this.objDb = new MySql(this.dbKey);
  21. }
  22. /**
  23. * 返回数据库操作对象
  24. * @param dbKey
  25. * @returns {OujMySql}
  26. */
  27. getObjDb(dbKey) {
  28. if (dbKey) {
  29. return new MySql(dbKey);
  30. } else {
  31. return this.objDb;
  32. }
  33. }
  34. }
  35. module.exports = Model;