GitHub: https://github.com/tmdag/dbconnector
This python script is using official MySQL python connector from MySQL connector website. While official python module is using 'low level' MySQL querries, this dbmanager wraps them around to more pythonic functions.
$ pip install git+https://github.com/tmdag/dbconnector
dbconnector expects configuration file with your database details. Example of such config: config.ini
[mysql]
user = myusername
password = MySectetPassword
host = myServer
database = myDatabase
You can pass config location to the class as an argument.
Each connection with database is made by creating class instance and requires database closure with 'close_connection()' method.
- Support for single file DB
- more sophisticated calls
- implement as_dict / as_list
from dbconnector import dbmanager
db_config = 'config/config.ini'
dbconnect = dbmanager.Connect(cfg=db_config)
db_tables = dbconnect.show_tables()
my_column_names = dbconnect.get_column_names("myTable")
primary_key_of_table = dbconnect.get_primary_key("myTable")
id_of_specific_entry = dbconnect.get_value_id("cameras", "cameraName", "GoPro")
raw_mysql_call = dbconnect.raw_call("SELECT shots.shotName FROM shots INNER JOIN shows ON shows.showID = shots.shows_showID WHERE shows.showName = 'MYSHOT'")
dbconnect.save() # save (commit) if there were any changes made in the database.
dbconnect.close_connection()