Skip to content

Commit cc66531

Browse files
author
junjie.miao
committed
add support mssql
1 parent 0a7d239 commit cc66531

File tree

7 files changed

+28
-12
lines changed

7 files changed

+28
-12
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
### Demonstration
88

9+
Currently supported database types: mysql, oracle, postgresql, or mssql.
10+
11+
目前支持的数据库类型:mysql、oracle、postgresql、mssql。
12+
913
![db_query](db_query/_assets/db_query.png)
1014

1115
![db_query_sql_query](db_query/_assets/db_query_sql_query.png)

db_query/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ pandas==2.2.3
55
SQLAlchemy==2.0.35
66
PyMySQL==1.1.1
77
oracledb==2.2.1
8-
psycopg2-binary==2.9.10
8+
psycopg2-binary==2.9.10
9+
pymssql==2.3.4

db_query/tools/db_util.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ def get_driver_name(self):
3434
driver_name = 'oracle+oracledb'
3535
elif db_type == 'postgresql':
3636
driver_name = 'postgresql+psycopg2'
37+
elif db_type == 'mssql':
38+
driver_name = 'mssql+pymssql'
3739
return driver_name
3840

3941
def get_url(self):
@@ -76,10 +78,11 @@ def run_query(self, query_sql: str) -> list[dict]:
7678
return records
7779

7880
def test_sql(self):
79-
if self.db_type in {'mysql', 'postgresql'}:
80-
return "SELECT 1"
81-
elif self.db_type == 'oracle':
81+
db_type = self.db_type.lower()
82+
if db_type == 'oracle':
8283
return "SELECT 1 FROM DUAL"
84+
else:
85+
return "SELECT 1"
8386

8487
@staticmethod
8588
def is_not_empty(s: str):

db_query/tools/sql_query.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,17 @@ parameters:
2929
label:
3030
en_US: PostgreSQL
3131
zh_Hans: PostgreSQL
32+
- value: mssql
33+
label:
34+
en_US: Microsoft SQL Server
35+
zh_Hans: Microsoft SQL Server
3236
default: mysql
3337
label:
3438
en_US: Database type
3539
zh_Hans: 数据库类型
3640
human_description:
37-
en_US: Used for selecting the database type, mysql, oracle or postgresql.
38-
zh_Hans: 用于选择数据库类型,mysql、oracle或postgresql
41+
en_US: Used for selecting the database type, mysql, oracle, postgresql or mssql.
42+
zh_Hans: 用于选择数据库类型,mysql、oracle、postgresql或mssql
3943
form: llm
4044
- name: db_host
4145
type: string

db_query_pre_auth/provider/db_query.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ credentials_for_provider:
3838
en_US: Database type
3939
zh_Hans: 数据库类型
4040
help:
41-
en_US: Used for selecting the database type, mysql, oracle or postgresql.
42-
zh_Hans: 用于选择数据库类型,mysql、oracle或postgresql
41+
en_US: Used for selecting the database type, mysql, oracle, postgresql or mssql.
42+
zh_Hans: 用于选择数据库类型,mysql、oracle、postgresql或mssql
4343
db_host:
4444
type: text-input
4545
required: true

db_query_pre_auth/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ pandas==2.2.3
55
SQLAlchemy==2.0.35
66
PyMySQL==1.1.1
77
oracledb==2.2.1
8-
psycopg2-binary==2.9.10
8+
psycopg2-binary==2.9.10
9+
pymssql==2.3.4

db_query_pre_auth/tools/db_util.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ def get_driver_name(self):
3434
driver_name = 'oracle+oracledb'
3535
elif db_type == 'postgresql':
3636
driver_name = 'postgresql+psycopg2'
37+
elif db_type == 'mssql':
38+
driver_name = 'mssql+pymssql'
3739
return driver_name
3840

3941
def get_url(self):
@@ -76,10 +78,11 @@ def run_query(self, query_sql: str) -> list[dict]:
7678
return records
7779

7880
def test_sql(self):
79-
if self.db_type in {'mysql', 'postgresql'}:
80-
return "SELECT 1"
81-
elif self.db_type == 'oracle':
81+
db_type = self.db_type.lower()
82+
if db_type == 'oracle':
8283
return "SELECT 1 FROM DUAL"
84+
else:
85+
return "SELECT 1"
8386

8487
@staticmethod
8588
def is_not_empty(s: str):

0 commit comments

Comments
 (0)