-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDB.py
45 lines (35 loc) · 1.29 KB
/
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
41
42
43
44
45
from all_imports import *
# DB class
class DB:
def __init__(self):
self.conn = db.connect('amzntrkr.db')
self.cursor = self.conn.cursor()
pass
def all(self, table=''):
q = 'SELECT * FROM ' + table
self.cursor.execute(q)
return self.cursor.fetchall()
def query(self, q):
self.cursor.execute(q)
def insert_tracking_table(self, pid='', name=''):
q = 'INSERT INTO tracking (id, productName) VALUES (?, ?)'
self.cursor.execute(q, [pid, name])
self.conn.commit()
def insert_price_table(
self, pid='', saleprice=0, dealprice=0, ourprice=0, bookprice=''):
q = 'INSERT INTO price (productId, saleprice, dealprice, ourprice, bookprice) VALUES (?, ?, ?, ?, ?)'
self.cursor.execute(
q,
[pid,
saleprice,
dealprice,
ourprice,
bookprice])
self.conn.commit()
def lastPriceEntries(self, n):
q = 'SELECT * FROM price JOIN tracking ON price.productId=tracking.id ORDER BY price.addedOn DESC LIMIT ?'
self.cursor.execute(q, [n])
return self.cursor.fetchall()
def delete(self, pid):
q = 'DELETE FROM tracking WHERE id = ' + pid
q = 'DELETE FROM price WHERE id = ' + pid