mm_sqlite 1.0.7 → 1.0.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.
package/db/mm.db CHANGED
Binary file
package/db.js CHANGED
@@ -18,7 +18,9 @@ class DB extends Sql {
18
18
 
19
19
  // 事务SQL
20
20
  this.task_sql = "";
21
-
21
+ // 表名
22
+ this.table = "";
23
+
22
24
  /**
23
25
  * 获取上级
24
26
  * @return {Object} 返回上级管理器
@@ -437,8 +439,26 @@ DB.prototype.addTable = async function(table, field, type = 'int', auto = true,
437
439
  if (!field) {
438
440
  field = "id";
439
441
  }
440
- var sql = "CREATE TABLE IF NOT EXISTS `{0}` (`{1}` {2})".replace('{0}', table).replace(
441
- '{1}', field).replace('{2}', this.setType(field, type, null, true, auto) + ' PRIMARY KEY');
442
+ // SQLite的自增主键要求字段类型必须是INTEGER(大写且不带长度)
443
+ let fieldType;
444
+ if (auto) {
445
+ // 自增字段使用简单的INTEGER类型,由后面的PRIMARY KEY AUTOINCREMENT决定自增行为
446
+ fieldType = "INTEGER";
447
+ } else {
448
+ // 非自增字段使用正常的类型设置
449
+ fieldType = this.setType(field, type, null, true, auto);
450
+ }
451
+ // 根据是否自增来构造不同的SQL语句
452
+ let sqlTemplate;
453
+ if (auto) {
454
+ // 自增字段:使用INTEGER PRIMARY KEY AUTOINCREMENT语法
455
+ sqlTemplate = "CREATE TABLE IF NOT EXISTS `{0}` (`{1}` {2} PRIMARY KEY AUTOINCREMENT)";
456
+ } else {
457
+ // 非自增字段:使用正常的字段类型和主键定义
458
+ sqlTemplate = "CREATE TABLE IF NOT EXISTS `{0}` (`{1}` {2} PRIMARY KEY)";
459
+ }
460
+ var sql = sqlTemplate.replace('{0}', table).replace(
461
+ '{1}', field).replace('{2}', fieldType);
442
462
  if (commit) {
443
463
  sql += " COMMENT = '" + commit + "';"
444
464
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_sqlite",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "高性能SQLite数据库操作模块,提供与mm_mysql完全兼容的API接口,支持异步操作、事务处理和批量操作",
5
5
  "main": "index.js",
6
6
  "scripts": {
Binary file
Binary file
Binary file
package/db/test.db DELETED
Binary file