mm_sqlite 1.3.4 → 1.3.5

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.
package/db.js CHANGED
@@ -265,7 +265,7 @@ DB.prototype.fields = async function (table, field_name, timeout = 15000) {
265
265
  var len = list.length;
266
266
  for (var i = 0; i < len; i++) {
267
267
  list[i].pk = list[i].pk ? true : false;
268
- list[i].notnull = list[i].notnull ? true : false;
268
+ list[i].not_null = list[i].not_null ? true : false;
269
269
  }
270
270
 
271
271
  // 如果指定了字段名,过滤结果
@@ -273,7 +273,16 @@ DB.prototype.fields = async function (table, field_name, timeout = 15000) {
273
273
  list = list.filter(field => field.name === field_name);
274
274
  }
275
275
 
276
- return list;
276
+ return list.map(item => ({
277
+ name: item.name,
278
+ cid: item.cid,
279
+ default_value: item.dflt_value,
280
+ not_null: item.notnull,
281
+ type: item.type,
282
+ pk: item.pk,
283
+ auto: item.auto,
284
+ note: item.note
285
+ }));
277
286
  } catch (err) {
278
287
  this.log('error', '获取字段信息失败', err);
279
288
  return [];
@@ -611,22 +620,22 @@ DB.prototype.delField = async function (table, field, timeout = 15000) {
611
620
  DB.prototype.sqlField = function (fd) {
612
621
  var sql = '`{0}`'.replace('{0}', fd.name);
613
622
  sql += ' ' + fd.type;
614
- if (fd.notnull) {
623
+ if (fd.not_null) {
615
624
  sql += ' NOT NULL';
616
625
  }
617
626
  if (fd.auto) {
618
- if (fd.dflt_value) {
619
- if (fd.dflt_value === '0000-00-00 00:00:00') {
620
- fd.dflt_value = 'CURRENT_TIMESTAMP';
627
+ if (fd.default_value) {
628
+ if (fd.default_value === '0000-00-00 00:00:00') {
629
+ fd.default_value = 'CURRENT_TIMESTAMP';
621
630
  }
622
- sql += ' DEFAULT ' + fd.dflt_value;
631
+ sql += ' DEFAULT ' + fd.default_value;
623
632
  }
624
633
  sql += ' ' + fd.auto;
625
- } else if (fd.dflt_value) {
626
- if (fd.dflt_value === '0000-00-00 00:00:00') {
627
- fd.dflt_value = '1970-01-01 00:00:00';
634
+ } else if (fd.default_value) {
635
+ if (fd.default_value === '0000-00-00 00:00:00') {
636
+ fd.default_value = '1970-01-01 00:00:00';
628
637
  }
629
- sql += ' DEFAULT ' + fd.dflt_value;
638
+ sql += ' DEFAULT ' + fd.default_value;
630
639
  }
631
640
  if (fd.note) {
632
641
  sql += " COMMENT '" + fd.note + "'";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_sqlite",
3
- "version": "1.3.4",
3
+ "version": "1.3.5",
4
4
  "description": "高性能SQLite数据库操作模块,提供与mm_mysql完全兼容的API接口,支持异步操作、事务处理和批量操作",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/sql.js CHANGED
@@ -1110,13 +1110,13 @@ Sql.prototype.addList = async function (list, batch_size = 100, timeout = 60000)
1110
1110
 
1111
1111
  // 分批处理大数据量
1112
1112
  const total = Math.ceil(list.length / batch_size);
1113
- $.log.info(`开始分批添加数据,共${total}批,每批${batch_size}条`);
1113
+ this.log('info', `开始分批添加数据,共${total}批,每批${batch_size}条`);
1114
1114
 
1115
1115
  // 分批执行,每批一个单独的批量插入语句
1116
1116
  let final_res = null;
1117
1117
  for (let i = 0; i < total; i++) {
1118
1118
  const batch = list.slice(i * batch_size, (i + 1) * batch_size);
1119
- $.log.debug(`处理第${i + 1}/${total}批数据,${batch.length}条`);
1119
+ this.log('debug', `处理第${i + 1}/${total}批数据,${batch.length}条`);
1120
1120
 
1121
1121
  // 生成批量插入SQL
1122
1122
  const batch_sql = this.toBatchAddSql(batch);
@@ -1131,7 +1131,7 @@ Sql.prototype.addList = async function (list, batch_size = 100, timeout = 60000)
1131
1131
  ]);
1132
1132
  }
1133
1133
 
1134
- $.log.success(`批量添加数据完成,共${list.length}条`);
1134
+ this.log('success', `批量添加数据完成,共${list.length}条`);
1135
1135
  return final_res;
1136
1136
  })(),
1137
1137
  timeout_promise
@@ -1216,7 +1216,7 @@ Sql.prototype.delList = async function (list, like, batch_size = 100, timeout =
1216
1216
 
1217
1217
  // 分批处理大数据量
1218
1218
  const total = Math.ceil(list.length / batch_size);
1219
- $.log.info(`开始分批删除数据,共${total}批,每批${batch_size}条`);
1219
+ this.log('info', `开始分批删除数据,共${total}批,每批${batch_size}条`);
1220
1220
 
1221
1221
  // 使用事务包装整个操作以保证原子性
1222
1222
  let final_res = null;
@@ -1227,7 +1227,7 @@ Sql.prototype.delList = async function (list, like, batch_size = 100, timeout =
1227
1227
  // 分批处理
1228
1228
  for (let i = 0; i < total; i++) {
1229
1229
  const batch = list.slice(i * batch_size, (i + 1) * batch_size);
1230
- $.log.debug(`处理第${i + 1}/${total}批数据,${batch.length}条`);
1230
+ this.log('debug', `处理第${i + 1}/${total}批数据,${batch.length}条`);
1231
1231
 
1232
1232
  let batch_sql = '';
1233
1233
  for (const item of batch) {
@@ -1257,7 +1257,7 @@ Sql.prototype.delList = async function (list, like, batch_size = 100, timeout =
1257
1257
  this.log('error', 'SQL语句执行失败', error);
1258
1258
  }
1259
1259
 
1260
- $.log.success(`批量删除数据完成,共${list.length}条`);
1260
+ this.log('success', `批量删除数据完成,共${list.length}条`);
1261
1261
  return final_res;
1262
1262
  })(),
1263
1263
  timeout_promise
@@ -1300,7 +1300,7 @@ Sql.prototype.setList = async function (list, like = false, batch_size = 100, ti
1300
1300
 
1301
1301
  // 分批处理大数据量
1302
1302
  const total = Math.ceil(list.length / batch_size);
1303
- $.log.info(`开始分批更新数据,共${total}批,每批${batch_size}条`);
1303
+ this.log('info', `开始分批更新数据,共${total}批,每批${batch_size}条`);
1304
1304
 
1305
1305
  // 使用事务包装整个操作以保证原子性
1306
1306
  let final_res = null;
@@ -1311,7 +1311,7 @@ Sql.prototype.setList = async function (list, like = false, batch_size = 100, ti
1311
1311
  // 分批处理
1312
1312
  for (let i = 0; i < total; i++) {
1313
1313
  const batch = list.slice(i * batch_size, (i + 1) * batch_size);
1314
- $.log.debug(`处理第${i + 1}/${total}批数据,${batch.length}条`);
1314
+ this.log('debug', `处理第${i + 1}/${total}批数据,${batch.length}条`);
1315
1315
 
1316
1316
  let batch_sql = '';
1317
1317
  for (const item of batch) {
@@ -1339,7 +1339,7 @@ Sql.prototype.setList = async function (list, like = false, batch_size = 100, ti
1339
1339
  }
1340
1340
  }
1341
1341
 
1342
- $.log.success(`批量更新数据完成,共${list.length}条`);
1342
+ this.log('success', `批量更新数据完成,共${list.length}条`);
1343
1343
  return final_res;
1344
1344
  })(),
1345
1345
  timeout_promise
Binary file
Binary file