initial
This commit is contained in:
28
dbpool.py
Normal file
28
dbpool.py
Normal file
@ -0,0 +1,28 @@
|
||||
import mariadb
|
||||
import os
|
||||
|
||||
pool = None
|
||||
|
||||
def createConnectionPool():
|
||||
global pool
|
||||
|
||||
try:
|
||||
user = os.environ["DB_USER"]
|
||||
password = os.environ["DB_PASS"]
|
||||
host = os.environ["DB_HOST"]
|
||||
database = os.environ["DB_NAME"]
|
||||
except KeyError as err:
|
||||
raise Exception("Database configuration variable {} not available".format(err))
|
||||
|
||||
pool = mariadb.ConnectionPool(
|
||||
user = user,
|
||||
password = password,
|
||||
host = host,
|
||||
database = database,
|
||||
pool_name = 'hv-wep-app',
|
||||
pool_size = 5
|
||||
)
|
||||
|
||||
def getConnection():
|
||||
global pool
|
||||
return pool.get_connection()
|
Reference in New Issue
Block a user