mm_sql 1.4.1 → 1.4.3

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,136 @@
1
+ const { mysqlAdmin } = require('../mm_mysql');
2
+
3
+ /**
4
+ * 测试mysqlAdmin的错误传播
5
+ */
6
+ async function testMysqlAdminError() {
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
+ await sql(mysql);
22
+ await param(mysql);
23
+
24
+ } catch (error) {
25
+ console.log('❌ mysqlAdmin实例创建失败:', error.message);
26
+ }
27
+ }
28
+
29
+ /**
30
+ * 测试无效SQL
31
+ * @param {object} mysql - mysql实例
32
+ */
33
+ async function sql(mysql) {
34
+ try {
35
+ console.log('测试无效SQL...');
36
+ await mysql.run('SELECT * FROM non_existent_table_xyz');
37
+ console.log('❌ mysqlAdmin应该对无效SQL抛出错误,但没有抛出');
38
+ } catch (error) {
39
+ console.log('✅ mysqlAdmin正确抛出错误:', error.message);
40
+ }
41
+ }
42
+
43
+ /**
44
+ * 测试无效参数
45
+ * @param {object} mysql - mysql实例
46
+ */
47
+ async function param(mysql) {
48
+ try {
49
+ console.log('测试无效参数...');
50
+ await mysql.run('SELECT * FROM test', 'invalid_param');
51
+ console.log('❌ mysqlAdmin应该对无效参数抛出TypeError,但没有抛出');
52
+ } catch (error) {
53
+ if (error instanceof TypeError) {
54
+ console.log('✅ mysqlAdmin正确抛出TypeError:', error.message);
55
+ } else {
56
+ console.log('❌ mysqlAdmin抛出错误但不是TypeError:', error.message);
57
+ }
58
+ }
59
+ }
60
+
61
+ /**
62
+ * 测试直接使用Mysql类的错误传播
63
+ */
64
+ async function testDirectMysqlError() {
65
+ console.log('\n=== 测试直接Mysql类错误传播 ===');
66
+
67
+ try {
68
+ const { Mysql } = require('../mm_mysql');
69
+
70
+ // 创建直接Mysql实例
71
+ const mysql = new Mysql({
72
+ host: 'localhost',
73
+ port: 3306,
74
+ user: 'test_user',
75
+ password: 'test_password',
76
+ database: 'test_db'
77
+ });
78
+
79
+ console.log('✅ 直接Mysql实例创建成功');
80
+
81
+ await directSql(mysql);
82
+ await direct(mysql);
83
+
84
+ } catch (error) {
85
+ console.log('❌ 直接Mysql实例创建失败:', error.message);
86
+ }
87
+ }
88
+
89
+ /**
90
+ * 测试直接Mysql实例的无效SQL
91
+ * @param {object} mysql - mysql实例
92
+ */
93
+ async function directSql(mysql) {
94
+ try {
95
+ console.log('测试无效SQL...');
96
+ await mysql.run('SELECT * FROM non_existent_table_xyz');
97
+ console.log('❌ 直接Mysql应该对无效SQL抛出错误,但没有抛出');
98
+ } catch (error) {
99
+ console.log('✅ 直接Mysql正确抛出错误:', error.message);
100
+ }
101
+ }
102
+
103
+ /**
104
+ * 测试直接Mysql实例的无效参数
105
+ * @param {object} mysql - mysql实例
106
+ */
107
+ async function direct(mysql) {
108
+ try {
109
+ console.log('测试无效参数...');
110
+ await mysql.run('SELECT * FROM test', 'invalid_param');
111
+ console.log('❌ 直接Mysql应该对无效参数抛出TypeError,但没有抛出');
112
+ } catch (error) {
113
+ if (error instanceof TypeError) {
114
+ console.log('✅ 直接Mysql正确抛出TypeError:', error.message);
115
+ } else {
116
+ console.log('❌ 直接Mysql抛出错误但不是TypeError:', error.message);
117
+ }
118
+ }
119
+ }
120
+
121
+ /**
122
+ * 主测试函数
123
+ */
124
+ async function main() {
125
+ console.log('开始测试MySQL错误传播...\n');
126
+
127
+ await testMysqlAdminError();
128
+ await testDirectMysqlError();
129
+
130
+ console.log('\n测试完成');
131
+ }
132
+
133
+ // 运行测试
134
+ if (require.main === module) {
135
+ main().catch(console.error);
136
+ }
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "mm_sql",
3
- "version": "1.4.1",
3
+ "version": "1.4.3",
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
+ }