Skip to content

Commit c393002

Browse files
authored
feat: support mssql in databaseConnection plugin (#3674)
* feat: support mssql in databaseConnection plugin * feat: trust server certificate for mssql
1 parent 16629e3 commit c393002

File tree

4 files changed

+388
-23
lines changed

4 files changed

+388
-23
lines changed

packages/plugins/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"echarts": "5.4.1",
1111
"expr-eval": "^2.0.2",
1212
"lodash": "^4.17.21",
13+
"mssql": "^11.0.1",
1314
"mysql2": "^3.11.3",
1415
"json5": "^2.2.3",
1516
"pg": "^8.10.0",

packages/plugins/src/databaseConnection/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Client as PgClient } from 'pg'; // PostgreSQL 客户端
22
import mysql from 'mysql2/promise'; // MySQL 客户端
3+
import mssql from 'mssql'; // SQL Server 客户端
34

45
type Props = {
56
databaseType: string;
@@ -52,6 +53,20 @@ const main = async ({
5253
const [rows] = await connection.execute(sql);
5354
result = rows;
5455
await connection.end();
56+
} else if (databaseType === 'Microsoft SQL Server') {
57+
const pool = await mssql.connect({
58+
server: host,
59+
port: parseInt(port, 10),
60+
database: databaseName,
61+
user,
62+
password,
63+
options: {
64+
trustServerCertificate: true
65+
}
66+
});
67+
68+
result = await pool.query(sql);
69+
await pool.close();
5570
}
5671
return {
5772
result

packages/plugins/src/databaseConnection/template.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
{
4343
"label": "PostgreSQL",
4444
"value": "PostgreSQL"
45+
},
46+
{
47+
"label": "Microsoft SQL Server",
48+
"value": "Microsoft SQL Server"
4549
}
4650
],
4751
"required": true

0 commit comments

Comments
 (0)