-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb_config.py
53 lines (28 loc) · 1.08 KB
/
db_config.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
52
53
from tinydb import TinyDB, Query
from tinydb.operations import add
from helpers.helpers import remove_duplicates
db = TinyDB('db.json')
def create_user(user_id):
if not get_user(user_id):
db.insert({'user_id': user_id, 'presets': []})
def get_user(user_id):
User = Query()
return db.search(User.user_id == user_id)
def add_preset(user_id, preset):
User = Query()
get_current = get_presets(user_id)
get_current.append(preset)
remove_duplicate_entries = remove_duplicates(get_current)
db.update({'presets': remove_duplicate_entries}, User.user_id == user_id)
# db.update(add('presets', new_preset), User.user_id == user_id)
def get_presets(user_id):
User = Query()
return db.search(User.user_id == user_id)[0]['presets']
def delete_preset(user_id, preset):
User = Query()
presets = get_presets(user_id)
remove = [p for p in presets if p != preset]
db.update({'presets': remove}, User.user_id == user_id)
def delete_all_presets(user_id):
User = Query()
db.update({'presets': []}, User.user_id == user_id)