-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.py
26 lines (22 loc) · 899 Bytes
/
db.py
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
import sqlite3
class Database:
def __init__(self):
self.connection = sqlite3.connect('data.db')
self.cursor = self.connection.cursor()
def create_database(self):
'''Creating database'''
with self.connection:
return self.cursor.execute("""CREATE TABLE IF NOT EXISTS data (
token TEXT,
ownerid TEXT,
userid TEXT,
username TEXT
)""")
def populate_data(self, token, owner_id, user_id, username):
'''Populating data in database'''
with self.connection:
return self.cursor.execute(f"INSERT INTO data VALUES (?, ?, ?, ?)", (token, owner_id, user_id, username))
def takes_all_data(self):
'''Takes all data'''
with self.connection:
return self.cursor.execute("SELECT * FROM data").fetchone()