SQLAlchemy Updating ORM model after inserting it
async def upsert_record(record: Record) -> Record: async with async_session() as session: stmt = insert(Record).values( record.to_dict() ).on_conflict_do_update( index_elements=[‘id’], set_={ # Just updating the values, nothing important … } ) result = await session.execute(stmt) await session.commit() record = await get_record(result.inserted_primary_key[0]) return record I created the following function to upsert records into the sqlite database. Once the record […]
SQLAlchemy Updating ORM model after inserting it
async def upsert_record(record: Record) -> Record: async with async_session() as session: stmt = insert(Record).values( record.to_dict() ).on_conflict_do_update( index_elements=[‘id’], set_={ # Just updating the values, nothing important … } ) result = await session.execute(stmt) await session.commit() record = await get_record(result.inserted_primary_key[0]) return record I created the following function to upsert records into the sqlite database. Once the record […]