Skip to content

Instantly share code, notes, and snippets.

@meepoSenpai
Created March 11, 2021 17:34
Show Gist options
  • Save meepoSenpai/4515b634120812d9b959223b2b27ef41 to your computer and use it in GitHub Desktop.
Save meepoSenpai/4515b634120812d9b959223b2b27ef41 to your computer and use it in GitHub Desktop.
User Stuff
class User(DB.Entity):
id = PrimaryKey(int, auto=True)
name = Required(str)
mail = Required(str)
passhash = Required(str)
@db_session
def create(username: str, email: str, passhash: str):
if username == None or passhash == None or email == None:
raise ValueError("Username, E-Mail or Password can't be None")
user = User(name=username, mail=email, passhash=passhash)
commit()
return user
@db_session
def find_by_id(id: int):
return User[id]
@db_session
def find_by_name(name: str):
return select(user for user in User if user.name == name)[:]
@db_session
def remove_from_db(id: int, password: str):
if password != User[id].passhash:
raise ValueError("Incorrect Password")
User[id].delete()
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment