def create_tables(): with open('pyuser/db/schema.sql', 'r') as file: tables_file = file.read() commands = tables_file.split(';') for command in commands: try: db_client.query(command) except OperationalError as e: print(f"Skipped command: {e.message}")
def register_to_db(self) -> Cursor: return db_client.query( "INSERT INTO users VALUES(:email, :first_n, :last_n, :lock_time, :log_attempts, :salt, :pwd)", { 'email': self.email, 'first_n': self.first_name, 'last_n': self.last_name, 'lock_time': self.lock_time, 'log_attempts': self.login_attempts, 'salt': self.salt, 'pwd': self.password, })
def remove_from_db(self) -> Cursor: return db_client.query("DELETE FROM users WHERE email = :email", {'email': self.email})
def get_user(email: str) -> Cursor: """ Searches for a user in the database. Takes the user's email address as an argument. """ return db_client.query("SELECT * FROM users WHERE email = :email", {"email": email})
def drop_tables(): tables_query = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;" tables = db_client.query(tables_query).fetchall() for table in tables: db_client.query(f"DROP TABLE {table[0]};")