def consultar_por_nome(nome): with closing(con()) as connection, closing(connection.cursor()) as cursor: cursor.execute(f"SELECT id, nome, rg FROM {model_name} WHERE nome = ?", (nome,)) row = cursor.fetchone() if row == None: return None return Professor.criar_com_id(row[0],row[1],row[2])
def listar(): with closing(con()) as connection, closing(connection.cursor()) as cursor: cursor.execute(f"SELECT id, nome, rg FROM {model_name}") rows = cursor.fetchall() registros = [] for (id, nome, rg) in rows: professor = Professor.criar_com_id(id, nome, rg) if professor != None: registros.append(professor) return registros