-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.py
40 lines (27 loc) · 894 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import sqlite3
from os import path, getcwd
db = path.join(getcwd(), 'database.db')
class Database:
def __init__(self):
self.connection = sqlite3.connect(db, check_same_thread=False)
def query(self, q, arg=()):
cursor = self.connection.cursor()
cursor.execute(q, arg)
results = cursor.fetchall()
cursor.close()
return results
def insert(self, q, arg=()):
cursor = self.connection.cursor()
cursor.execute(q, arg)
self.connection.commit()
result = cursor.lastrowid
cursor.close()
return result
def select(self, q, arg=()):
cursor = self.connection.cursor()
return cursor.execute(q, arg)
def delete(self, q, arg=()):
cursor = self.connection.cursor()
result = cursor.execute(q, arg)
self.connection.commit()
return result