Created
September 6, 2024 20:51
-
-
Save GGontijo/ae518fb8522df0743ed3ac6401e764d8 to your computer and use it in GitHub Desktop.
Filtrar propriedades validas em tabela para uso no sqlalchemy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy import Table | |
from sqlalchemy.orm import class_mapper | |
def filtrar_colunas_validas(data, table): | |
valid_columns = set(table.columns.keys()) | |
return {key: value for key, value in data.items() if key in valid_columns} | |
# Exemplo de uso | |
filtered_data = filter_valid_columns(viagem.model_dump(), viagem_cif_table) | |
stmt_viagem = insert(viagem_cif_table).values(filtered_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment