WebAdminPanel/database.py

29 lines
628 B
Python
Raw Normal View History

2022-08-29 12:10:44 -04:00
from peewee import Model,CharField
2022-11-26 12:22:25 -05:00
from playhouse.db_url import connect
2022-08-29 12:10:44 -04:00
2022-11-26 12:22:25 -05:00
from config import db_url
db = connect(db_url)
2022-08-29 12:10:44 -04:00
class WebUser(Model):
username = CharField()
password_hash = CharField()
class Meta:
db_table = "webusers"
database = db
2022-09-01 09:24:40 -04:00
@staticmethod
def userExists(username) -> bool:
2022-08-29 12:10:44 -04:00
"""Check if the username exists in a database."""
query = WebUser.select().where(WebUser.username == username)
2022-09-01 09:24:40 -04:00
if (query):
if (query.exists()):
return True
2022-08-29 12:10:44 -04:00
2022-09-01 09:24:40 -04:00
return False
2022-08-29 12:10:44 -04:00
2022-11-26 12:22:25 -05:00
def build_database():
2022-08-29 12:10:44 -04:00
db.create_tables([WebUser])