Last active
June 17, 2019 23:41
-
-
Save motionrus/82dd62fb7024f65a6bb61b0e916da9f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy import pool as alchemy_pool | |
import configparser, pymssql | |
PATH_TO_CONFIG = 'config_local.ini' | |
def get_db_config(): | |
config = configparser.ConfigParser() | |
config.read(PATH_TO_CONFIG) | |
return config['DB.CONFIG'] | |
def getconn(): | |
db = get_db_config() | |
return pymssql.connect( | |
host=db['db.host'] + ':' + db['db.port'], | |
user=db['db.user'], | |
password=db['db.password'], | |
database=db['db.database'], | |
as_dict=True | |
) | |
pool = alchemy_pool.QueuePool(getconn, pool_size=30) | |
conn = pool.connect() | |
curs = conn.cursor() | |
# example usage | |
# curs.execute(query, params) | |
# conn.commit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment