Create db_connection.py
Browse files- modules/db_connection.py +17 -0
modules/db_connection.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# modules/db_connection.py
|
| 2 |
+
import pymssql
|
| 3 |
+
from azure.identity import DefaultAzureCredential
|
| 4 |
+
|
| 5 |
+
def get_db_connection():
|
| 6 |
+
server = 'aideatexdb.database.windows.net'
|
| 7 |
+
database = 'textdb'
|
| 8 |
+
username = 'manuel.var.ale_aideatext.ai#EXT#@manuelvaraleaideatext.onmicrosoft.com'
|
| 9 |
+
|
| 10 |
+
credential = DefaultAzureCredential()
|
| 11 |
+
token = credential.get_token("https://database.windows.net/.default")
|
| 12 |
+
|
| 13 |
+
conn = pymssql.connect(server=server,
|
| 14 |
+
database=database,
|
| 15 |
+
user=username,
|
| 16 |
+
password=token.token)
|
| 17 |
+
return conn
|