mm_mysql 2.3.7 → 2.3.8

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.
Files changed (2) hide show
  1. package/db.js +11 -11
  2. package/package.json +1 -1
package/db.js CHANGED
@@ -62,12 +62,12 @@ DB.prototype.database = function () {
62
62
  * @param {string} key 键名
63
63
  * @returns {object} 返回管理器
64
64
  */
65
- DB.prototype.new = function (table, key) {
65
+ DB.prototype.new = function (table = '', key = '') {
66
66
  const db = this.getParent().db();
67
67
  db.table = table;
68
68
  if (key) {
69
69
  db.key = key;
70
- } else {
70
+ } else if (table) {
71
71
  const arr = table.split('_');
72
72
  db.key = arr[arr.length - 1] + '_id';
73
73
  }
@@ -78,7 +78,7 @@ DB.prototype.new = function (table, key) {
78
78
  * 获取数据库连接
79
79
  * @returns {Promise<object>}
80
80
  */
81
- DB.prototype.getConn = async function() {
81
+ DB.prototype.getConn = async function () {
82
82
  try {
83
83
  return await this.getParent().getConn();
84
84
  } catch (error) {
@@ -92,7 +92,7 @@ DB.prototype.getConn = async function() {
92
92
  * 开始事务
93
93
  * @returns {Promise<object>}
94
94
  */
95
- DB.prototype.start = async function() {
95
+ DB.prototype.start = async function () {
96
96
  try {
97
97
  return await this.getParent().beginTransaction();
98
98
  } catch (error) {
@@ -108,12 +108,12 @@ DB.prototype.start = async function() {
108
108
  * @returns {Promise<void>}
109
109
  * @throws {TypeError} 当transaction参数无效时
110
110
  */
111
- DB.prototype.commit = async function(transaction) {
111
+ DB.prototype.commit = async function (transaction) {
112
112
  // 参数校验
113
113
  if (!transaction || typeof transaction !== 'object') {
114
114
  throw new TypeError('transaction must be object');
115
115
  }
116
-
116
+
117
117
  try {
118
118
  await transaction.commit();
119
119
  } catch (error) {
@@ -127,12 +127,12 @@ DB.prototype.commit = async function(transaction) {
127
127
  * @returns {Promise<void>}
128
128
  * @throws {TypeError} 当transaction参数无效时
129
129
  */
130
- DB.prototype.back = async function(transaction) {
130
+ DB.prototype.back = async function (transaction) {
131
131
  // 参数校验
132
132
  if (!transaction || typeof transaction !== 'object') {
133
133
  throw new TypeError('transaction must be object');
134
134
  }
135
-
135
+
136
136
  try {
137
137
  await transaction.rollback();
138
138
  } catch (error) {
@@ -146,12 +146,12 @@ DB.prototype.back = async function(transaction) {
146
146
  * @returns {Promise<*>}
147
147
  * @throws {TypeError} 当callback参数无效时
148
148
  */
149
- DB.prototype.transaction = async function(callback) {
149
+ DB.prototype.transaction = async function (callback) {
150
150
  // 参数校验
151
151
  if (typeof callback !== 'function') {
152
152
  throw new TypeError('callback must be function');
153
153
  }
154
-
154
+
155
155
  try {
156
156
  return await this.getParent().transaction(callback);
157
157
  } catch (error) {
@@ -205,7 +205,7 @@ DB.prototype.fields = async function (table, field_name, timeout = 15000) {
205
205
  }
206
206
  const field = 'COLUMN_NAME as `name`,ORDINAL_POSITION as `cid`,COLUMN_DEFAULT as `default_value`,IS_NULLABLE as `not_null`,COLUMN_TYPE as `type`,COLUMN_KEY as `pk`,EXTRA as `auto`,COLUMN_COMMENT as `note`';
207
207
  let sql = 'select ' + field + " from information_schema.COLUMNS where `table_name` = '" + targetTable +
208
- "' and `table_schema` = '" + this.database() + "'";
208
+ "' and `table_schema` = '" + this.database() + "'";
209
209
  if (field_name) {
210
210
  sql += " AND COLUMN_NAME='" + field_name + "'";
211
211
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_mysql",
3
- "version": "2.3.7",
3
+ "version": "2.3.8",
4
4
  "description": "这是超级美眉mysql帮助函数模块,用于便捷操作mysql,使用await方式,可以避免嵌套函数",
5
5
  "main": "index.js",
6
6
  "dependencies": {