Skip to content

Commit 60826be

Browse files
Feature/sql server (#119)
* added sqlserver connector * added sqlserver docs
1 parent 2181716 commit 60826be

File tree

9 files changed

+525
-12
lines changed

9 files changed

+525
-12
lines changed

docsite/docs/connectors/implementing-a-connector.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 4
2+
sidebar_position: 5
33
---
44

55
# Implementing a Connector
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
sidebar_position: 4
3+
---
4+
5+
# SQL Server
6+
7+
The SQL Server adapter allows `intugle` to connect to Microsoft SQL Server and Azure SQL databases. It uses the modern [`mssql-python`](https://github.com/microsoft/mssql-python) driver, which connects directly to SQL Server without needing an external driver manager like ODBC.
8+
9+
## OS Dependencies
10+
11+
The `mssql-python` driver may require additional system-level libraries depending on your operating system (e.g., `libltdl` on Linux). Before proceeding, please ensure you have installed any necessary prerequisites for your OS.
12+
13+
For detailed, OS-specific installation instructions, please refer to the official **[Microsoft mssql-python documentation](httpshttps://learn.microsoft.com/en-us/sql/connect/python/mssql-python/python-sql-driver-mssql-python-quickstart?view=sql-server-ver17&tabs=windows%2Cazure-sql)**.
14+
15+
## Installation
16+
17+
To use this adapter, you must install the necessary dependencies as an extra:
18+
19+
```bash
20+
pip install "intugle[sqlserver]"
21+
```
22+
23+
## Profile Configuration
24+
25+
To configure the connection, add a `sqlserver` entry to your `profiles.yml` file.
26+
27+
**`profiles.yml`**
28+
```yaml
29+
sqlserver:
30+
name: my_sqlserver_source # A unique name for this source
31+
type: sqlserver
32+
host: "your_server_address"
33+
port: 1433
34+
user: "your_username"
35+
password: "your_password"
36+
database: "your_database_name"
37+
schema: "dbo" # Optional, defaults to 'dbo'
38+
encrypt: true # Optional, defaults to true
39+
```
40+
41+
| Key | Description | Required | Default |
42+
| ---------- | ------------------------------------------------------------------------------------------------------- | -------- | ------- |
43+
| `name` | A unique identifier for this data source connection. | Yes | |
44+
| `type` | The type of the adapter. Must be `sqlserver`. | Yes | |
45+
| `host` | The hostname or IP address of your SQL Server instance. | Yes | |
46+
| `port` | The port number for the connection. | No | `1433` |
47+
| `user` | The username for authentication. | Yes | |
48+
| `password` | The password for authentication. | Yes | |
49+
| `database` | The name of the database to connect to. | Yes | |
50+
| `schema` | The default schema to use for tables that are not fully qualified. | No | `dbo` |
51+
| `encrypt` | Whether to encrypt the connection. Recommended to keep this `true`. | No | `true` |
52+
53+
## Dataset Configuration
54+
55+
When defining datasets for the `SemanticModel`, use the `type: "sqlserver"` and provide the table name as the `identifier`.
56+
57+
```python
58+
from intugle import SemanticModel
59+
60+
datasets = {
61+
"customers": {
62+
"type": "sqlserver",
63+
"identifier": "Customers" # The name of the table in SQL Server
64+
},
65+
"orders": {
66+
"type": "sqlserver",
67+
"identifier": "Orders"
68+
},
69+
# ... other datasets
70+
}
71+
72+
# Build the semantic model
73+
sm = SemanticModel(datasets, domain="E-commerce")
74+
sm.build()
75+
```

pyproject.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,17 @@ snowflake = [
6161
]
6262
databricks = [
6363
"databricks-sql-connector>=4.1.3",
64-
"pyspark>=3.5.0",
64+
"pyspark>=3.5.0,<4.0.0",
6565
"sqlglot>=27.20.0",
6666
]
6767
postgres = [
6868
"asyncpg>=0.30.0",
6969
"sqlglot>=27.20.0",
7070
]
71+
sqlserver = [
72+
"mssql-python>=0.13.1",
73+
"sqlglot>=27.20.0",
74+
]
7175

7276
streamlit = [
7377
"streamlit==1.50.0",
@@ -101,8 +105,9 @@ dev = [
101105
"asyncpg>=0.30.0",
102106
"databricks-sql-connector>=4.1.3",
103107
"ipykernel>=6.30.1",
108+
"mssql-python>=0.13.1",
104109
"pysonar>=1.2.0.2419",
105-
"pyspark>=4.0.1",
110+
"pyspark>=3.5.0,<4.0.0",
106111
"pytest>=8.4.1",
107112
"pytest-asyncio>=1.1.0",
108113
"pytest-cov>=6.2.1",

src/intugle/adapters/factory.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def import_module(name: str) -> ModuleInterface:
2424
"intugle.adapters.types.snowflake.snowflake",
2525
"intugle.adapters.types.databricks.databricks",
2626
"intugle.adapters.types.postgres.postgres",
27+
"intugle.adapters.types.sqlserver.sqlserver",
2728
]
2829

2930

src/intugle/adapters/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ def get_dataset_data_type() -> type:
2323
from intugle.adapters.types.duckdb.models import DuckdbConfig
2424
from intugle.adapters.types.postgres.models import PostgresConfig
2525
from intugle.adapters.types.snowflake.models import SnowflakeConfig
26+
from intugle.adapters.types.sqlserver.models import SQLServerConfig
2627

27-
DataSetData = pd.DataFrame | DuckdbConfig | SnowflakeConfig | DatabricksConfig | PostgresConfig
28+
DataSetData = pd.DataFrame | DuckdbConfig | SnowflakeConfig | DatabricksConfig | PostgresConfig | SQLServerConfig
2829
else:
2930
# At runtime, this is dynamically determined
3031
DataSetData = Any

src/intugle/adapters/types/sqlserver/__init__.py

Whitespace-only changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from typing import Literal, Optional
2+
3+
from intugle.common.schema import SchemaBase
4+
5+
6+
class SQLServerConnectionConfig(SchemaBase):
7+
user: str
8+
password: str
9+
host: str
10+
port: int = 1433
11+
database: str
12+
schema: str = "dbo"
13+
encrypt: bool = True
14+
15+
16+
class SQLServerConfig(SchemaBase):
17+
identifier: str
18+
type: Literal["sqlserver"] = "sqlserver"

0 commit comments

Comments
 (0)