vmoo-mcp-database-server 1.2.1 → 1.2.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.
- package/package.json +1 -1
- package/shared/database-utils.js +22 -1
package/package.json
CHANGED
package/shared/database-utils.js
CHANGED
|
@@ -1,14 +1,34 @@
|
|
|
1
1
|
// VMOO数据库工具函数
|
|
2
2
|
import mysql from 'mysql2/promise';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* 替换配置中的环境变量
|
|
6
|
+
* @param {Object} config 配置对象
|
|
7
|
+
* @returns {Object} 替换后的配置对象
|
|
8
|
+
*/
|
|
9
|
+
function replaceEnvVariables(config) {
|
|
10
|
+
const configStr = JSON.stringify(config);
|
|
11
|
+
const replacedStr = configStr.replace(/\$\{([^}]+)\}/g, (_, envVar) => {
|
|
12
|
+
const value = process.env[envVar];
|
|
13
|
+
if (value === undefined) {
|
|
14
|
+
throw new Error(`环境变量 ${envVar} 未设置`);
|
|
15
|
+
}
|
|
16
|
+
return value;
|
|
17
|
+
});
|
|
18
|
+
return JSON.parse(replacedStr);
|
|
19
|
+
}
|
|
20
|
+
|
|
4
21
|
/**
|
|
5
22
|
* 创建数据库连接池
|
|
6
23
|
* @param {Object} config 数据库配置
|
|
7
24
|
* @returns {Object} 连接池
|
|
8
25
|
*/
|
|
9
26
|
function createConnectionPool(config) {
|
|
27
|
+
// 替换环境变量
|
|
28
|
+
const processedConfig = replaceEnvVariables(config);
|
|
29
|
+
|
|
10
30
|
return mysql.createPool({
|
|
11
|
-
...
|
|
31
|
+
...processedConfig,
|
|
12
32
|
waitForConnections: true,
|
|
13
33
|
connectionLimit: 10,
|
|
14
34
|
queueLimit: 0
|
|
@@ -92,6 +112,7 @@ async function listTables(pool, pattern = null) {
|
|
|
92
112
|
}
|
|
93
113
|
|
|
94
114
|
export {
|
|
115
|
+
replaceEnvVariables,
|
|
95
116
|
createConnectionPool,
|
|
96
117
|
normalizeTableName,
|
|
97
118
|
executeQuery,
|