Skip to content

Commit

Permalink
Set test params for MS SQL docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
abitrolly committed Jan 19, 2020
1 parent 41f7953 commit 3a1bf8c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions dbconnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@

from secrets import Server, PWD, UID

Driver = "SQL+Server"
# Driver = "FreeTDS"


class DBConnector:
def __init__(self, db_name):
self.db_name = db_name
self.db_url = f"mssql+pyodbc://{UID}:{PWD}@{Server}/{db_name}?driver={Driver}&autocommit=True"

def __enter__(self):
self.engine = sqlalchemy.create_engine(
f"mssql+pyodbc://{UID}:{PWD}@{Server}/{self.db_name}?driver=SQL+Server&autocommit=True"
)
self.engine = sqlalchemy.create_engine(self.db_url)
self.conn = self.engine.raw_connection()
return self.conn

Expand All @@ -37,5 +38,8 @@ def __exit__(self, exc_type, exc_val, exc_tb):


if __name__ == "__main__":
with DBConnector("testdb") as conn:
Server = "127.0.0.1:1433"
PWD = "yourStrong(!)Password"
UID = "sa"
with DBConnector("master") as conn:
print(conn)

0 comments on commit 3a1bf8c

Please sign in to comment.