Created
October 30, 2013 02:07
-
-
Save wolftatsu/7226137 to your computer and use it in GitHub Desktop.
Python DB Access Wrapper
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
import sys | |
import mysql.connector | |
def exec_sql(fn): | |
def wrapper(*args, **kw): | |
_self = args[0] | |
_self.con = mysql.connector.connect(**_self.rds_config) | |
ret = None | |
try: | |
ret = fn(*args, **kw) | |
finally: | |
_self.con.close() | |
_self.con = None | |
return ret | |
return wrapper | |
class DbBase(object): | |
def __init__(self, config): | |
self.rds_config = config | |
self.con = None | |
class DataAccessClass: | |
@exec_sql | |
def some_sql_(self): | |
cur = self.con.cursor() | |
query ="" | |
cur.execute(query) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment