-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql.py
More file actions
43 lines (36 loc) · 1.34 KB
/
sql.py
File metadata and controls
43 lines (36 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import pymysql
def establish_connection():
connection = pymysql.connect(
host='',
user='',
password='',
database='',
cursorclass=pymysql.cursors.DictCursor
)
return connection
def add_user(name,nickname,discordid,serverid):
connection = establish_connection()
with connection:
with connection.cursor() as cursor:
insert_query = "INSERT INTO `user` (name,nickname,discordid,serverid) VALUES (%s,%s,%s,%s)"
cursor.execute(insert_query, (name,nickname,discordid,serverid))
connection.commit()
def user_exist(discordid,serverid):
connection = establish_connection()
with connection:
with connection.cursor() as cursor:
select_query = "SELECT * FROM user WHERE discordid = %s AND serverid = %s"
cursor.execute(select_query, (discordid,serverid))
result = cursor.fetchone()
if result:
return True
else:
return False
def get_all_server_users(serverid):
connection = establish_connection()
with connection:
with connection.cursor() as cursor:
select_query = "SELECT * FROM user WHERE serverid = %s"
cursor.execute(select_query, (serverid))
result = cursor.fetchall()
return result