Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mssql support #3985

Merged
merged 32 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
121bd0d
add mssql
isthaison Dec 11, 2024
d18e1fd
add mssql on api test
isthaison Dec 11, 2024
2099b34
add drive msodb
isthaison Dec 11, 2024
3b924b4
Merge remote-tracking branch 'upstream/main' into sqlserverexecsql
isthaison Dec 11, 2024
efbfa18
update add packages microsoft
isthaison Dec 11, 2024
89b18a7
test ci
isthaison Dec 11, 2024
bbc154e
test ci
isthaison Dec 11, 2024
adfae5c
test ci
isthaison Dec 11, 2024
4d46829
skip confirm yes/no
isthaison Dec 11, 2024
e14457d
test ci
isthaison Dec 11, 2024
02b749a
tesst ci
isthaison Dec 11, 2024
5723a85
tesst ci
isthaison Dec 11, 2024
78a94fa
Merge branch 'main' into sqlserverexecsql
KevinHuSh Dec 12, 2024
d073b9e
test ci
isthaison Dec 12, 2024
b0ac9c2
Merge branch 'sqlserverexecsql' of https://github.com/isthaison/ragfl…
isthaison Dec 12, 2024
df3e546
Merge branch 'main' into sqlserverexecsql
isthaison Dec 12, 2024
8f3469e
test ci
isthaison Dec 12, 2024
97f120b
Merge branch 'sqlserverexecsql' of https://github.com/isthaison/ragfl…
isthaison Dec 12, 2024
1e997e7
get new code
isthaison Dec 12, 2024
f9a8ec7
get new code
isthaison Dec 12, 2024
051ec64
get new code
isthaison Dec 12, 2024
55a6252
Merge remote-tracking branch 'upstream/main' into sqlserverexecsql
isthaison Dec 12, 2024
98ca32a
add package
isthaison Dec 12, 2024
698dddf
lock poe
isthaison Dec 12, 2024
da0c20a
lock
isthaison Dec 12, 2024
be9b262
Merge remote-tracking branch 'upstream/main' into sqlserverexecsql
isthaison Dec 12, 2024
ff44c0c
update poe
isthaison Dec 12, 2024
06cccd9
Update api/apps/canvas_app.py
KevinHuSh Dec 12, 2024
98e5330
Update api/apps/canvas_app.py
KevinHuSh Dec 12, 2024
3353e9e
Update api/apps/canvas_app.py
isthaison Dec 12, 2024
5690b4c
Update canvas_app.py
KevinHuSh Dec 12, 2024
0752b96
Merge branch 'main' into sqlserverexecsql
KevinHuSh Dec 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ RUN --mount=type=cache,id=ragflow_apt,target=/var/cache/apt,sharing=locked \
apt autoremove && \
apt update && \
apt install -y nodejs cargo

# Add sql17
RUN --mount=type=cache,id=ragflow_apt,target=/var/cache/apt,sharing=locked \
curl -sSL -O https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb && \
dpkg -i packages-microsoft-prod.deb && \
rm packages-microsoft-prod.deb && \
apt update
RUN --mount=type=cache,id=ragflow_apt,target=/var/cache/apt,sharing=locked \
apt install -y unixodbc-dev
RUN --mount=type=cache,id=ragflow_apt,target=/var/cache/apt,sharing=locked \
apt install -y msodbcsql17


# Add dependencies of selenium
RUN --mount=type=bind,from=infiniflow/ragflow_deps:latest,source=/chrome-linux64-121-0-6167-85,target=/chrome-linux64.zip \
Expand Down Expand Up @@ -170,5 +182,4 @@ RUN chmod +x ./entrypoint.sh
COPY --from=builder /ragflow/web/dist /ragflow/web/dist

COPY --from=builder /ragflow/VERSION /ragflow/VERSION

ENTRYPOINT ["./entrypoint.sh"]
13 changes: 11 additions & 2 deletions agent/component/exesql.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import pymysql
import psycopg2
from agent.component.base import ComponentBase, ComponentParamBase
import pyodbc


class ExeSQLParam(ComponentParamBase):
Expand All @@ -38,7 +39,7 @@ def __init__(self):
self.top_n = 30

def check(self):
self.check_valid_value(self.db_type, "Choose DB type", ['mysql', 'postgresql', 'mariadb'])
self.check_valid_value(self.db_type, "Choose DB type", ['mysql', 'postgresql', 'mariadb', 'mssql'])
self.check_empty(self.database, "Database name")
self.check_empty(self.username, "database username")
self.check_empty(self.host, "IP Address")
Expand Down Expand Up @@ -77,7 +78,15 @@ def _run(self, history, **kwargs):
elif self._param.db_type == 'postgresql':
db = psycopg2.connect(dbname=self._param.database, user=self._param.username, host=self._param.host,
port=self._param.port, password=self._param.password)

elif self._param.db_type == 'mssql':
conn_str = (
r'DRIVER={ODBC Driver 17 for SQL Server};'
r'SERVER=' + self._param.host + ',' + str(self._param.port) + ';'
r'DATABASE=' + self._param.database + ';'
r'UID=' + self._param.username + ';'
r'PWD=' + self._param.password
)
db = pyodbc.connect(conn_str)
try:
cursor = db.cursor()
except Exception as e:
Expand Down
26 changes: 24 additions & 2 deletions api/apps/canvas_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from api.utils.api_utils import get_json_result, server_error_response, validate_request, get_data_error_result
from agent.canvas import Canvas
from peewee import MySQLDatabase, PostgresqlDatabase
import pyodbc
KevinHuSh marked this conversation as resolved.
Show resolved Hide resolved


@manager.route('/templates', methods=['GET']) # noqa: F821
Expand Down Expand Up @@ -242,8 +243,29 @@ def test_db_connect():
elif req["db_type"] == 'postgresql':
db = PostgresqlDatabase(req["database"], user=req["username"], host=req["host"], port=req["port"],
password=req["password"])
db.connect()
db.close()
elif req["db_type"] == 'mssql':
isthaison marked this conversation as resolved.
Show resolved Hide resolved
connection_string = (
f"DRIVER={{ODBC Driver 17 for SQL Server}};"
f"SERVER={req['host']},{req['port']};"
f"DATABASE={req['database']};"
f"UID={req['username']};"
f"PWD={req['password']};"
)
db = pyodbc.connect(connection_string)
else:
return server_error_response("Unsupported database type.")

# Test the connection
if req["db_type"] == "mssql":
cursor = db.cursor()
cursor.execute("SELECT 1")
cursor.close()
db.close()
else:
db.connect()
db.close()

return get_json_result(data="Database Connection Successful!")
except Exception as e:
return server_error_response(e)

10 changes: 6 additions & 4 deletions web/src/pages/flow/constant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2855,10 +2855,12 @@ export const QWeatherTimePeriodOptions = [
'30d',
];

export const ExeSQLOptions = ['mysql', 'postgresql', 'mariadb'].map((x) => ({
label: upperFirst(x),
value: x,
}));
export const ExeSQLOptions = ['mysql', 'postgresql', 'mariadb', 'mssql'].map(
(x) => ({
label: upperFirst(x),
value: x,
}),
);

export const SwitchElseTo = 'end_cpn_id';

Expand Down
Loading