forked from ch3p4ll3/QBittorrentBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_management.py
41 lines (25 loc) · 885 Bytes
/
db_management.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
from pony.orm import Database, PrimaryKey, Required, \
db_session, ObjectNotFound
db = Database()
db.bind(provider='sqlite', filename='database.sqlite', create_db=True)
class Support(db.Entity):
id = PrimaryKey(int)
Action = Required(str, 255)
class CompletedTorrents(db.Entity):
hash = PrimaryKey(str)
db.generate_mapping(create_tables=True)
def read_support(chat_id):
with db_session:
return Support[chat_id].Action
def write_support(status, chat_id):
with db_session:
try:
Support[chat_id].Action = status
except ObjectNotFound:
Support(Action=status, id=chat_id)
def write_completed_torrents(torrent_hash):
with db_session:
CompletedTorrents(hash=torrent_hash)
def read_completed_torrents(torrent_hash):
with db_session:
return CompletedTorrents.get(hash=torrent_hash)