mkeneqa / Pymysquery

Python database wrapper class for the pymysql module
MIT License
2 stars 1 forks source link

PySQuery Database Module

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.

Get Started

Option 1 - Clone The Repo:

Option 2 - Download the pymydb file :

Usage

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()