Skip to content

Commit ab9f8b5

Browse files
committed
New version.
1 parent cb36ac3 commit ab9f8b5

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

loaf/__init__.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import pymysql, datetime, socket
1+
import pymysql, psycopg2, datetime, socket
22

33
host_ = socket.gethostbyname(socket.gethostname())
44
port_ = 80 # Default XAMPP Apache server port.
@@ -7,21 +7,26 @@
77
db_ = None
88
creds_ = ""
99
cursor_ = "DEFAULT"
10+
mode_ = "MySQL"
1011

1112
# Make this differently, for the love of god!
12-
def bake(host=host_, port=port_, user=user_, pasw=pasw_, db=db_, creds=creds_, cursor=cursor_):
13-
global host_, port_, user_, pasw_, db_, creds_, cursor_
13+
def bake(host=host_, port=port_, user=user_, pasw=pasw_, db=db_, creds=creds_, cursor=cursor_, mode=mode_):
14+
global host_, port_, user_, pasw_, db_, creds_, cursor_, mode_
1415
if host != "": host_=host
1516
if port != "": port_=port
1617
if user != "": user_=user
1718
if pasw != "": pasw_=pasw
1819
if db != "": db_=db
1920
if creds != "": creds_=creds
2021
if cursor != "": cursor_=cursor
22+
if mode != "": mode_=mode
2123

2224
# A query.
2325
def query(query):
24-
conn = pymysql.connect(host=host_, port=port_, user=user_, passwd=pasw_, db=db_)
26+
if (mode_ == "MySQL"):
27+
conn = pymysql.connect(host=host_, port=port_, user=user_, passwd=pasw_, db=db_)
28+
elif (mode_ == "PostgreSQL"):
29+
conn = psycopg2.connect(host=host_, port=port_, user=user_, password=pasw_, database=db_)
2530
conn_object = conn.cursor(pymysql.cursors.DictCursor) if cursor_=="DICTIONARY" else conn.cursor()
2631
conn_object.execute(query)
2732
response = conn_object.fetchall()
@@ -30,6 +35,18 @@ def query(query):
3035
conn.close()
3136
return response
3237

38+
# Test your connection with your database.
39+
def test():
40+
try:
41+
if (mode_ == "MySQL"):
42+
conn = pymysql.connect(host=host_, port=port_, user=user_, passwd=pasw_, db=db_)
43+
elif (mode_ == "PostgreSQL"):
44+
conn = psycopg2.connect(host=host_, port=port_, user=user_, password=pasw_, database=db_)
45+
print(f"Successful connection at: {host_}")
46+
except Exception as ex:
47+
print(f"Connection error at: {host_}")
48+
print(ex)
49+
3350
# Call a stored procedure.
3451
def call(func, *args):
3552
call = "CALL " + func + "("

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from setuptools import setup, find_packages
22

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

0 commit comments

Comments
 (0)