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

feat: mssql database support #346

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt

import frappe
import ibis


def get_mssql_connection(data_source):
if not frappe.conf.get("mssql_odbc_driver"):
frappe.throw(
"MSSQL ODBC driver path not configured. Please set it in common_site_config.json"
" under 'mssql_odbc_driver' key."
" Eg. 'mssql_odbc_driver': '/usr/local/lib/libtdsodbc.so' or 'FreeTDS'"
)

password = data_source.get_password(raise_exception=False)

return ibis.mssql.connect(
host=data_source.host,
port=int(data_source.port) or 1433,
user=data_source.username,
password=password,
database=data_source.database_name,
driver=frappe.conf.get("mssql_odbc_driver"),
)
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"fieldname": "database_type",
"fieldtype": "Select",
"label": "Database Type",
"options": "MariaDB\nPostgreSQL\nSQLite\nDuckDB\nBigQuery"
"options": "MariaDB\nPostgreSQL\nSQLite\nDuckDB\nBigQuery\nMSSQL"
},
{
"fieldname": "host",
Expand Down Expand Up @@ -120,7 +120,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-11-03 17:10:59.295243",
"modified": "2024-11-07 19:06:14.814805",
"modified_by": "Administrator",
"module": "Insights",
"name": "Insights Data Source v3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,14 @@
from frappe.model.document import Document
from ibis import BaseBackend

from insights.insights.doctype.insights_data_source_v3.connectors.bigquery import (
get_bigquery_connection,
)
from insights.insights.doctype.insights_data_source_v3.data_warehouse import (
WAREHOUSE_DB_NAME,
)
from insights.insights.doctype.insights_table_link_v3.insights_table_link_v3 import (
InsightsTableLinkv3,
)
from insights.insights.doctype.insights_table_v3.insights_table_v3 import (
InsightsTablev3,
)

from .connectors.bigquery import get_bigquery_connection
from .connectors.duckdb import get_duckdb_connection
from .connectors.frappe_db import (
get_frappedb_connection_string,
Expand All @@ -31,8 +26,10 @@
is_frappe_db,
)
from .connectors.mariadb import get_mariadb_connection_string
from .connectors.mssql import get_mssql_connection
from .connectors.postgresql import get_postgres_connection_string
from .connectors.sqlite import get_sqlite_connection_string
from .data_warehouse import WAREHOUSE_DB_NAME


class InsightsDataSourceDocument:
Expand Down Expand Up @@ -158,7 +155,7 @@ class InsightsDataSourcev3(InsightsDataSourceDocument, Document):
connection_string: DF.Text | None
database_name: DF.Data | None
database_type: DF.Literal[
"MariaDB", "PostgreSQL", "SQLite", "DuckDB", "BigQuery"
"MariaDB", "PostgreSQL", "SQLite", "DuckDB", "BigQuery", "MSSQL"
]
host: DF.Data | None
is_frappe_db: DF.Check
Expand Down Expand Up @@ -190,6 +187,8 @@ def _get_db_connection(self) -> BaseBackend:
return get_bigquery_connection(self)
if self.database_type == "DuckDB":
return get_duckdb_connection(self)
if self.database_type == "MSSQL":
return get_mssql_connection(self)

connection_string = self._get_connection_string()
return ibis.connect(connection_string)
Expand Down Expand Up @@ -224,6 +223,7 @@ def test_connection(self, raise_exception=False):
db.list_tables(database=self.get_quoted_db_name())
return True
except Exception as e:
frappe.msgprint(str(e), title="Error", indicator="red")
frappe.log_error("Testing Data Source connection failed", e)
if raise_exception:
raise e
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ dependencies = [
"ibis-framework==9.5.0",
"ibis-framework[duckdb]",
"ibis-framework[mysql]",
"ibis-framework[postgres]",
"ibis-framework[sqlite]",
"ibis-framework[mssql]",
# "ibis-framework[bigquery]",
]

Expand Down