-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimporting_job_table.py
51 lines (45 loc) · 1.79 KB
/
importing_job_table.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
46
47
48
49
50
51
from db import get_db
class Importing_job_table():
def __init__(self, user_id, token_info):
self.user_id = user_id
self.token_info = token_info
@staticmethod
def get_row(user_id, object_name):
db = get_db()
row = db.execute(
"SELECT id, user_id, object_name, start_date, last_date, active FROM importing_job_table WHERE user_id = ? and object_name = ?", (user_id, object_name)
).fetchone()
return row
@staticmethod
def get_jobs(db):
row = db.execute(
"SELECT user_id, object_name, last_date FROM importing_job_table WHERE active = 1 and last_date < date('now')"
).fetchall()
return row
@staticmethod
def update_row(user_id, object_name, start_date, active = 1):
last_date = start_date
db = get_db()
cur = db.execute(
"UPDATE importing_job_table SET start_date = ?, last_date = ?, active = ? WHERE user_id = ? and object_name = ?", (start_date, last_date, active, user_id, object_name)
)
db.commit()
return cur.lastrowid
@staticmethod
def update_last_date(db, user_id, object_name, last_date):
cur = db.execute(
"UPDATE importing_job_table SET last_date = ? WHERE user_id = ? and object_name = ?", (last_date, user_id, object_name)
)
db.commit()
return cur.lastrowid
@staticmethod
def create(user_id, object_name, start_date, active = 1):
last_date = start_date
db = get_db()
cur = db.execute(
"INSERT INTO importing_job_table (user_id, object_name, start_date, last_date, active)"
" VALUES (?, ?, ?, ?, ?)",
(user_id, object_name, start_date, last_date, active),
)
db.commit()
return cur.lastrowid