예제 #1
0
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}")
예제 #2
0
파일: user.py 프로젝트: lseab/pyusers
 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,
         })
예제 #3
0
파일: user.py 프로젝트: lseab/pyusers
 def remove_from_db(self) -> Cursor:
     return db_client.query("DELETE FROM users WHERE email = :email",
                            {'email': self.email})
예제 #4
0
파일: user.py 프로젝트: lseab/pyusers
 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})
예제 #5
0
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]};")