@@ 1,11 1,12 @@
from peewee import (
SqliteDatabase,
- Model,
- Charfield,
+ CharField,
DateTimeField,
IntegerField,
ForeignKeyField,
+ Model,
)
+from playhouse import migrate
# TODO: SUPPORT OTHER DBS THAN SQLITE
database = SqliteDatabase("mc.db")
@@ 19,9 20,9 @@ class BaseModel(Model):
class Users(BaseModel):
id = IntegerField(primary_key=True)
- username = Charfield(null=False)
- password = Charfield(null=True) # NULL TRUE = IN CASE OF SSO LOGIN/REGISTER
- uuid = Charfield(null=False)
+ username = CharField(null=False)
+ password = CharField(null=True) # NULL TRUE = IN CASE OF SSO LOGIN/REGISTER
+ uuid = CharField(null=False)
registered_on = DateTimeField(
null=False
) # USED MAINLY FOR NICE DATA STATS IN api/statusapi:status_order_stats()
@@ 29,6 30,13 @@ class Users(BaseModel):
class UsernameHistory(BaseModel):
id = IntegerField(primary_key=True)
- username = Charfield(null=False)
+ username = CharField(null=False)
changed_on = DateTimeField(null=False)
uuid = ForeignKeyField(Users, backref="uuid")
+
+
+def get_object(model, **kwargs):
+ try:
+ return model.get(**kwargs)
+ except model.DoesNotExist:
+ return None
@@ 0,0 1,7 @@
+from utils.db import get_object, Users
+
+
+def get_uuid_from_username(username: str):
+ user = get_object(Users, username=username)
+
+ return user.uuid if user else None