Model.js 825 B

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