forked from dcai/airnotifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dao.py
29 lines (21 loc) · 858 Bytes
/
dao.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
from typing import Dict
import logging
class Dao:
def __init__(self, mongodb, options):
self.mongodb = mongodb
self.masterdb = mongodb[options.masterdb]
self.options = options
def set_current_app(self, name):
dbname = self.options.appprefix + name
self.db = self.mongodb[dbname]
def get_version(self):
return "2.0.0"
def find_app_by_name(self, name):
return self.masterdb.applications.find_one({"shortname": name})
def update_app_by_name(self, name: str, app: Dict[str, str]):
self.masterdb.applications.update({"shortname": name}, app)
def find_token(self, token):
logging.info("find token: %s" % token)
return self.db.tokens.find_one({"token": token})
def add_token(self, token: Dict[str, str]):
return self.db.tokens.insert(token)