-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.py
More file actions
29 lines (22 loc) · 849 Bytes
/
db.py
File metadata and controls
29 lines (22 loc) · 849 Bytes
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
import sqlite3
class DB:
def __init__(self, db_name):
self.connection = sqlite3.connect(db_name)
self.cursor = self.get_cursor()
self.create_db()
def get_cursor(self):
return self.connection.cursor()
def close_db(self):
self.connection.close()
def create_db(self):
self.cursor.execute("CREATE TABLE IF NOT EXISTS users\
(key TEXT, expires_in INTEGER)")
self.connection.commit()
def insert_record(self, key, expire_in):
self.cursor.execute(
"INSERT INTO users VALUES (?, ?)", (key, expire_in))
self.connection.commit()
return self.cursor.lastrowid
def get_record_by_id(self, id_number):
self.cursor.execute("SELECT * FROM users WHERE rowid=?", (id_number, ))
return self.cursor.fetchone()