Skip to content

Instantly share code, notes, and snippets.

@GGontijo
Created September 6, 2024 20:51
Show Gist options
  • Save GGontijo/ae518fb8522df0743ed3ac6401e764d8 to your computer and use it in GitHub Desktop.
Save GGontijo/ae518fb8522df0743ed3ac6401e764d8 to your computer and use it in GitHub Desktop.
Filtrar propriedades validas em tabela para uso no sqlalchemy
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