mm_sql 1.4.0 → 1.4.2

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.
@@ -0,0 +1,110 @@
1
+ const { mysqlAdmin } = require('../mm_mysql');
2
+
3
+ /**
4
+ * 测试mysqlAdmin的错误传播
5
+ */
6
+ async function testMysqlAdminErrorPropagation() {
7
+ console.log('=== 测试mysqlAdmin错误传播 ===');
8
+
9
+ try {
10
+ // 创建mysqlAdmin实例
11
+ const mysql = mysqlAdmin('test_scope', {
12
+ host: 'localhost',
13
+ port: 3306,
14
+ user: 'test_user',
15
+ password: 'test_password',
16
+ database: 'test_db'
17
+ });
18
+
19
+ console.log('✅ mysqlAdmin实例创建成功');
20
+
21
+ // 测试无效SQL - 应该抛出错误
22
+ try {
23
+ console.log('测试无效SQL...');
24
+ await mysql.run('SELECT * FROM non_existent_table_xyz');
25
+ console.log('❌ mysqlAdmin应该对无效SQL抛出错误,但没有抛出');
26
+ } catch (error) {
27
+ console.log('✅ mysqlAdmin正确抛出错误:', error.message);
28
+ }
29
+
30
+ // 测试无效参数 - 应该抛出TypeError
31
+ try {
32
+ console.log('测试无效参数...');
33
+ await mysql.run('SELECT * FROM test', 'invalid_param');
34
+ console.log('❌ mysqlAdmin应该对无效参数抛出TypeError,但没有抛出');
35
+ } catch (error) {
36
+ if (error instanceof TypeError) {
37
+ console.log('✅ mysqlAdmin正确抛出TypeError:', error.message);
38
+ } else {
39
+ console.log('❌ mysqlAdmin抛出错误但不是TypeError:', error.message);
40
+ }
41
+ }
42
+
43
+ } catch (error) {
44
+ console.log('❌ mysqlAdmin实例创建失败:', error.message);
45
+ }
46
+ }
47
+
48
+ /**
49
+ * 测试直接使用Mysql类的错误传播
50
+ */
51
+ async function testDirectMysqlErrorPropagation() {
52
+ console.log('\n=== 测试直接Mysql类错误传播 ===');
53
+
54
+ try {
55
+ const { Mysql } = require('../mm_mysql');
56
+
57
+ // 创建直接Mysql实例
58
+ const mysql = new Mysql({
59
+ host: 'localhost',
60
+ port: 3306,
61
+ user: 'test_user',
62
+ password: 'test_password',
63
+ database: 'test_db'
64
+ });
65
+
66
+ console.log('✅ 直接Mysql实例创建成功');
67
+
68
+ // 测试无效SQL - 应该抛出错误
69
+ try {
70
+ console.log('测试无效SQL...');
71
+ await mysql.run('SELECT * FROM non_existent_table_xyz');
72
+ console.log('❌ 直接Mysql应该对无效SQL抛出错误,但没有抛出');
73
+ } catch (error) {
74
+ console.log('✅ 直接Mysql正确抛出错误:', error.message);
75
+ }
76
+
77
+ // 测试无效参数 - 应该抛出TypeError
78
+ try {
79
+ console.log('测试无效参数...');
80
+ await mysql.run('SELECT * FROM test', 'invalid_param');
81
+ console.log('❌ 直接Mysql应该对无效参数抛出TypeError,但没有抛出');
82
+ } catch (error) {
83
+ if (error instanceof TypeError) {
84
+ console.log('✅ 直接Mysql正确抛出TypeError:', error.message);
85
+ } else {
86
+ console.log('❌ 直接Mysql抛出错误但不是TypeError:', error.message);
87
+ }
88
+ }
89
+
90
+ } catch (error) {
91
+ console.log('❌ 直接Mysql实例创建失败:', error.message);
92
+ }
93
+ }
94
+
95
+ /**
96
+ * 主测试函数
97
+ */
98
+ async function main() {
99
+ console.log('开始测试MySQL错误传播...\n');
100
+
101
+ await testMysqlAdminErrorPropagation();
102
+ await testDirectMysqlErrorPropagation();
103
+
104
+ console.log('\n测试完成');
105
+ }
106
+
107
+ // 运行测试
108
+ if (require.main === module) {
109
+ main().catch(console.error);
110
+ }
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "mm_sql",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "一个通用的SQL帮助类,支持通过切换db_type实现对不同数据库的操作,包括MySQL和SQLite等",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "start": "node test.js",
8
- "test": "node test.js"
8
+ "test": "node test.js",
9
+ "lint": "eslint . --config eslint.config.js",
10
+ "lint:fix": "eslint . --config eslint.config.js --fix",
11
+ "lint:check": "eslint . --config eslint.config.js --max-warnings 0"
9
12
  },
10
13
  "repository": {
11
14
  "type": "git",
@@ -41,7 +44,12 @@
41
44
  "node": ">=12.0.0"
42
45
  },
43
46
  "dependencies": {
44
- "mm_mysql": "^2.2.5",
45
- "mm_sqlite": "^1.2.2"
47
+ "mm_mysql": "^2.2.7",
48
+ "mm_sqlite": "^1.2.7"
49
+ },
50
+ "devDependencies": {
51
+ "eslint": "^9.39.2",
52
+ "eslint-plugin-jsdoc": "^61.5.0",
53
+ "mm_eslint": "^1.1.1"
46
54
  }
47
- }
55
+ }