Formerly known as MyPyDb Database Class
A Python3 Object Oriented Database wrapper class for the PyMySQL module.
This is a compilation of commonly used database functions I've used over the years when using the PyMySQL module for querying Maria/MySQL databases.
Some Benefits of Using this class:
DISCLAIMER: This is a WIP and requires testing and better documentation.
git clone https://github.com/mkeneqa/mypydb.git
python3 -m venv venv
(unix) or py -m venv venv
(win)source venv/bin/activate
.\venv\Scripts\activate
python -m pip install --upgrade pip
python -m pip install PyMySQL
python -m pip install pandas
pymydb
file :mypydb.py
file and place it in your project
python -m pip install PyMySQL
python -m pip install pandas
Initialize Database Connection
import pymydb
host_ip = '192.168.10.10'
db_name = 'my_db'
pymydb.Database.DBUSR = 'db_user'
pymydb.Database.DBPSWD = 'db_pswd'
_db = pymydb.Database(host_ip,db_name)
_db.Connect()
Truncate Table
_db.TruncateTable('users')
Fetch All
# returns a list of coloumn names as Tuples
rows = _db.FetchAll("SELECT * FROM users")
for row in rows:
rid,first_name,last_name,is_active = row
# do something ...
Fetch One
_db.FetchOne("SELECT `id` FROM users LIMIT 1")
Close Connection
_db.CloseConn()