I'm using a module called pymssql to connect to qa database. I use it a couple of places below to first create a connection (a part of this class), and then return a cursor. I'm going to be setting up and tearing down a lot of connections so I didn't want to use the scripty-looking examples here: https://code.google.com/p/pymssql/wiki/PymssqlExamples
Basically all my class does is pass in my connection credentials. Is this dumb?
class AlchemyConnection(object):
"""
Connection to database.
"""
def __init__(self):
self.createConnection()
def createConnection(self):
try:
self.con = pymssql.connect(dbconfig.host, dbconfig.user, dbconfig.password, dbconfig.database, as_dict=True)
print '[AlchemyConnection] Connection successful for user %s to database %s' % (dbconfig.user,
dbconfig.database)
except pymssql.DatabaseError as e:
pass
def close(self):
self.con.close()
def getCursor(self):
## TODO this feels shitty
self.cursor = self.con.cursor()
return self.cursor # returns pymmssql cursor object
def commit(self):
self.con.commit()
I'm using a module called pymssql to connect to qa database. I use it a couple of places below to first create a connection (a part of this class), and then return a cursor. I'm going to be setting up and tearing down a lot of connections so I didn't want to use the scripty-looking examples here: https://code.google.com/p/pymssql/wiki/PymssqlExamples
Basically all my class does is pass in my connection credentials. Is this dumb?