anxiousmodernman / feedback

feedback tools testing
1 stars 1 forks source link

Okay to return random object inside my database connection class? #1

Closed anxiousmodernman closed 11 years ago

anxiousmodernman commented 11 years ago

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()
anxiousmodernman commented 11 years ago

fuck it