- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.py
More file actions
Latest commit
29 lines (22 loc) · 849 Bytes
/
Copy pathdb.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
importsqlite3
classDB:
def__init__(self, db_name):
self.connection=sqlite3.connect(db_name)
self.cursor=self.get_cursor()
self.create_db()
defget_cursor(self):
returnself.connection.cursor()
defclose_db(self):
self.connection.close()
defcreate_db(self):
self.cursor.execute("CREATE TABLE IF NOT EXISTS users\
(key TEXT, expires_in INTEGER)")
self.connection.commit()
definsert_record(self, key, expire_in):
self.cursor.execute(
"INSERT INTO users VALUES (?, ?)", (key, expire_in))
self.connection.commit()
returnself.cursor.lastrowid
defget_record_by_id(self, id_number):
self.cursor.execute("SELECT * FROM users WHERE rowid=?", (id_number, ))
returnself.cursor.fetchone()