voice state - also there was no git history here so im just force pushing
This commit is contained in:
commit
9c41144985
9 changed files with 207 additions and 0 deletions
52
cef_3M/sql.py
Normal file
52
cef_3M/sql.py
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import pymysql
|
||||
import config
|
||||
from typing import Tuple
|
||||
|
||||
pymysql.install_as_MySQLdb()
|
||||
|
||||
import MySQLdb as maraidb
|
||||
|
||||
DB: pymysql = maraidb.connect(user=config.MARIADB_USER, password=config.MARIADB_PASSWORD, db=config.MARIADB_DB, autocommit=True)
|
||||
DB.autocommit(True)
|
||||
|
||||
def reconnect(f):
|
||||
def wrap(*args, **kwargs):
|
||||
DB.ping()
|
||||
return f(*args, **kwargs)
|
||||
return wrap
|
||||
|
||||
@reconnect
|
||||
def SqlExecute(query, *args):
|
||||
cursor = DB.cursor(pymysql.cursors.DictCursor)
|
||||
cursor.execute(query, args)
|
||||
cursor.close()
|
||||
return cursor.lastrowid
|
||||
|
||||
@reconnect
|
||||
def SqlExecuteFetchOne(query, *args):
|
||||
cursor = DB.cursor(pymysql.cursors.DictCursor)
|
||||
cursor.execute(query, args)
|
||||
row = cursor.fetchone()
|
||||
cursor.close()
|
||||
return row
|
||||
|
||||
@reconnect
|
||||
def MultipleSqlExecuteFetchOne(*queries: Tuple[str, tuple]):
|
||||
cursor = DB.cursor(pymysql.cursors.DictCursor)
|
||||
ret = []
|
||||
for query, args in queries:
|
||||
cursor.execute(query, args)
|
||||
ret.append(cursor.fetchone())
|
||||
cursor.close()
|
||||
return ret
|
||||
|
||||
@reconnect
|
||||
def SqlExecuteFetchAll(query, *args):
|
||||
cursor = DB.cursor(pymysql.cursors.DictCursor)
|
||||
cursor.execute(query, args)
|
||||
rows = cursor.fetchall()
|
||||
cursor.close()
|
||||
return rows
|
||||
|
||||
|
||||
CACHE = {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue