upload
This commit is contained in:
BIN
libs/__pycache__/lib_checks.cpython-39.pyc
Normal file
BIN
libs/__pycache__/lib_checks.cpython-39.pyc
Normal file
Binary file not shown.
BIN
libs/__pycache__/lib_mysql.cpython-39.pyc
Normal file
BIN
libs/__pycache__/lib_mysql.cpython-39.pyc
Normal file
Binary file not shown.
6
libs/lib_checks.py
Normal file
6
libs/lib_checks.py
Normal file
@@ -0,0 +1,6 @@
|
||||
def has_role(user_roles, searched_role):
|
||||
found = False
|
||||
for i in user_roles:
|
||||
if i.name == searched_role:
|
||||
found = True
|
||||
return found
|
||||
44
libs/lib_mysql.py
Normal file
44
libs/lib_mysql.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import os
|
||||
import mysql.connector
|
||||
|
||||
|
||||
class MariaDB():
|
||||
username = None
|
||||
password = None
|
||||
site_url = None
|
||||
|
||||
def __init__(self, mysql_host, mysql_user, mysql_databse, mysql_password):
|
||||
self.mysql_host = mysql_host
|
||||
self.mysql_user = mysql_user
|
||||
self.mysql_password = mysql_password
|
||||
self.mysql_databse = mysql_databse
|
||||
|
||||
def connect(self):
|
||||
mydb = mysql.connector.connect(
|
||||
host=self.mysql_host,
|
||||
user=self.mysql_user,
|
||||
password=self.mysql_password,
|
||||
database=self.mysql_databse
|
||||
)
|
||||
self.mydb = mydb
|
||||
self.mycursor = mydb.cursor(buffered=True, dictionary=True)
|
||||
|
||||
def insert(self, sql, val):
|
||||
self.mycursor.execute(sql, val)
|
||||
self.mydb.commit()
|
||||
|
||||
print(f"MySQL-Connection: {self.mycursor.rowcount} record inserted")
|
||||
|
||||
def select(self, sql, val):
|
||||
if len(val) == 0:
|
||||
self.mycursor.execute(sql)
|
||||
else:
|
||||
self.mycursor.execute(sql, val)
|
||||
|
||||
myresult = self.mycursor.fetchall()
|
||||
return myresult
|
||||
|
||||
|
||||
|
||||
def disconnect(self):
|
||||
self.mydb.disconnect()
|
||||
Reference in New Issue
Block a user