def set_username(self, id, username): """Set the username of the user.""" query = '''UPDATE users SET username = %s WHERE id = %s;''' database.commit(query, (username, id))
def set_allergy(self, id, name): """Set the name of an allergy.""" query = '''UPDATE allergies SET name = %s WHERE id = %s''' database.commit(query, (name, id))
def set_email(self, id, email): """Set the email adress of the user.""" query = '''UPDATE users SET email = %s WHERE id = %s;''' database.commit(query, (mail, id))
def set_ingredient(self, id, name): """Set the name of an ingredient.""" query = '''UPDATE ingredients SET name = %s WHERE id = %s''' database.commit(query, (name, id))
def set_roommate(self, id, first_name, middle_name, last_name): """Set the name of a roommate.""" query = '''UPDATE roommates SET first_name = %s, middle_name = %s, last_name = %s WHERE id = %s''' database.commit(query, (first_name, middle_name, last_name, id))
def set_password(self, id, password): """Set the user password.""" hash = self.generate_hash(password) query = '''UPDATE users SET hash = %s WHERE id = %s;''' database.commit(query, (hash, id))
def set_name(self, id, first_name, middle_name, last_name): """Set the name of the user.""" query = '''UPDATE users SET first_name = %s, middle_name = %s, last_name = %s WHERE id = %s;''' database.commit(query, (first_name, middle_name, last_name, id))
def add_user(self, username, email, first_name, middle_name, last_name, password): """Add a user to the database.""" hash = self.generate_hash(password) query = '''INSERT INTO users (username, email, first_name, middle_name, last_name, hash) VALUES (%s, %s, %s, %s, %s, %s)''' database.commit( query, (username, email, first_name, middle_name, last_name, hash))
def add_roommate(self, user_id, first_name, middle_name, last_name): """Add a roommate to the database.""" handle = self.get_handle(user_id) if not handle: handle = 1 query = '''INSERT INTO roommates (handle, user_id, first_name, middle_name, last_name) VALUES (%s, %s, %s, %s, %s)''' database.commit(query, (handle, user_id, first_name, middle_name, last_name))
def delete_roommate(self, id): """Delete a roomate from the database.""" query = '''DELETE FROM roommates WHERE id = %s''' database.commit(query, id)
def delete_allergy(self, id): """Delete an allergy from the database.""" query = '''DELETE FROM allergies WHERE id = %s''' database.commit(query, id)
def add_allergy(self, name): """Add an allergy to the database.""" query = '''INSERT INTO allergies (name) VALUES (%s)''' database.commit(query, name)
def delete_ingredient(self, id): """Delete an ingredient from the database.""" query = '''DELETE FROM ingredients WHERE id = %s''' database.commit(query, id)
def add_ingredient(self, name): """Add an ingredient to the database.""" query = '''INSERT INTO ingredients (name) VALUES (%s)''' database.commit(query, name)