Skip to content

Instantly share code, notes, and snippets.

@wolftatsu
Created October 30, 2013 02:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolftatsu/7226137 to your computer and use it in GitHub Desktop.
Save wolftatsu/7226137 to your computer and use it in GitHub Desktop.
Python DB Access Wrapper
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