Skip to content

Commit

Permalink
New version.
Browse files Browse the repository at this point in the history
  • Loading branch information
PoshoDev committed Apr 28, 2022
1 parent cb36ac3 commit ab9f8b5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
25 changes: 21 additions & 4 deletions loaf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pymysql, datetime, socket
import pymysql, psycopg2, datetime, socket

host_ = socket.gethostbyname(socket.gethostname())
port_ = 80 # Default XAMPP Apache server port.
Expand All @@ -7,21 +7,26 @@
db_ = None
creds_ = ""
cursor_ = "DEFAULT"
mode_ = "MySQL"

# Make this differently, for the love of god!
def bake(host=host_, port=port_, user=user_, pasw=pasw_, db=db_, creds=creds_, cursor=cursor_):
global host_, port_, user_, pasw_, db_, creds_, cursor_
def bake(host=host_, port=port_, user=user_, pasw=pasw_, db=db_, creds=creds_, cursor=cursor_, mode=mode_):
global host_, port_, user_, pasw_, db_, creds_, cursor_, mode_
if host != "": host_=host
if port != "": port_=port
if user != "": user_=user
if pasw != "": pasw_=pasw
if db != "": db_=db
if creds != "": creds_=creds
if cursor != "": cursor_=cursor
if mode != "": mode_=mode

# A query.
def query(query):
conn = pymysql.connect(host=host_, port=port_, user=user_, passwd=pasw_, db=db_)
if (mode_ == "MySQL"):
conn = pymysql.connect(host=host_, port=port_, user=user_, passwd=pasw_, db=db_)
elif (mode_ == "PostgreSQL"):
conn = psycopg2.connect(host=host_, port=port_, user=user_, password=pasw_, database=db_)
conn_object = conn.cursor(pymysql.cursors.DictCursor) if cursor_=="DICTIONARY" else conn.cursor()
conn_object.execute(query)
response = conn_object.fetchall()
Expand All @@ -30,6 +35,18 @@ def query(query):
conn.close()
return response

# Test your connection with your database.
def test():
try:
if (mode_ == "MySQL"):
conn = pymysql.connect(host=host_, port=port_, user=user_, passwd=pasw_, db=db_)
elif (mode_ == "PostgreSQL"):
conn = psycopg2.connect(host=host_, port=port_, user=user_, password=pasw_, database=db_)
print(f"Successful connection at: {host_}")
except Exception as ex:
print(f"Connection error at: {host_}")
print(ex)

# Call a stored procedure.
def call(func, *args):
call = "CALL " + func + "("
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages

VERSION = '0.1.11'
DESCRIPTION = 'Effortlessly access your MySQL server and procedures, plus some other utilities!'
VERSION = '0.1.12'
DESCRIPTION = 'Effortlessly access your SQL servers and procedures, plus some other utilities!'
with open('README.md', encoding="utf8") as f:
LONG_DESCRIPTION = f.read()

Expand Down

0 comments on commit ab9f8b5

Please sign in to comment.