Module that helps you to save time and lines It runs all queries, fetches, connects, disconnects, commits etc. within itself :)
Just insert:
from db import DbHelper
db = DbHelper()
at the beginning of your script.
You can also use logs in your application by calling logging.getLogger()
and setting the log level you want:
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
SELECT example - 1 (clear query):
query = "SELECT * FROM table"
result = db.fetchone(query)
SELECT example - 2 (query with data):
query = "SELECT * FROM table WHERE some_column = %s"
data = "your param"
result = db.fetchone(query, data)
If you need to fetch some results from same query use this case on first query:
result = db.fetchone(query, data, open_cursor=True)
and this case on the next one:
result = db.fetchone(query, data, next_result=True)
don' forget to close_cursor after all
db.close_cursor()