-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.py
More file actions
36 lines (30 loc) · 1.49 KB
/
db.py
File metadata and controls
36 lines (30 loc) · 1.49 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
import sqlite3
class Database:
def __init__(self, db_file):
self.connection = sqlite3.connect(db_file)
self.cursor = self.connection.cursor()
def add_user(self, user_id):
with self.connection:
return self.cursor.execute("INSERT INTO `users` (`user_id`) VALUES (?)", (user_id,))
def user_exists(self, user_id):
with self.connection:
result = self.cursor.execute("SELECT * FROM `users` WHERE `user_id` =?", (user_id,)).fetchall()
return bool(len(result))
def set_nickname(self, user_id, nickname):
with self.connection:
return self.cursor.execute("UPDATE `users` SET `nickname` = ? WHERE `user_id` = ?", (nickname, user_id))
def get_sign_up(self, user_id):
with self.connection:
result = self.cursor.execute("SELECT `sign_up` FROM `users` WHERE `user_id` =?", (user_id,)).fetchall()
for row in result:
sign_up = str(row[0])
return sign_up
def set_sign_up(self, user_id, sign_up):
with self.connection:
return self.cursor.execute("UPDATE `users` SET `sign_up` = ? WHERE `user_id` =?", (sign_up, user_id))
def get_nickname(self, user_id):
with self.connection:
result = self.cursor.execute("SELECT `nickname` FROM `users` WHERE `user_id` =?", (user_id,)).fetchall()
for row in result:
nickname = str(row[0])
return nickname