Channel model

This commit is contained in:
Felipe Martin 2020-11-04 16:51:24 +01:00
parent d238be7962
commit 78d943d530
Signed by: fmartingr
GPG Key ID: 716BC147715E716F
1 changed files with 23 additions and 0 deletions

View File

@ -51,3 +51,26 @@ class User(Model):
fields.update({"username": username})
return cls._table.update(fields, ["username"])
class Channel(Model):
_table = db["channels"]
@classmethod
def create(cls, provider, channel_id, enabled=False, channel_raw={}):
cls._table.insert({"provider": provider, "channel_id": channel_id, "enabled": enabled, "channel_raw": channel_raw})
@classmethod
def get(cls, username):
result = cls._table.find_one(username=username)
if not result:
raise cls.UserNotFound
return result
@classmethod
def delete(cls, username):
return cls._table.delete(username=username)
@classmethod
def update(cls, username, **fields):
fields.update({"username": username})
return cls._table.update(fields, ["username"])