How to use delete operation with async orm?
See original GitHub issueWe used to use synchronous ORM
operations using code below:
obj = session.query(User).get(id)
session.delete(obj)
session.commit()
How should we use delete operation in asynchronous ORM
?
Versions:
- Python: 3.8.5
- SQLAlchemy: 1.4
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (9 by maintainers)
Top Results From Across the Web
Delete | SeaORM An async & dynamic ORM for Rust - SeaQL
Find a Model from the database, then delete the corresponding row from database. use sea_orm::entity::ModelTrait;
Read more >Asynchronous I/O (asyncio) - SQLAlchemy 1.4 Documentation
It's advisable to invoke the AsyncEngine.dispose() method using await when using the AsyncEngine object in a scope that will go out of context ......
Read more >python + SQLAlchemy: deleting with the Session object
In SQL Alchemy you are deleting Objects that you get with a query from the database. This you can do in 2 Ways:...
Read more >Basic Insert Update and Delete with Dapper | Dave Paquette
The SQL statement is a simple DELETE with a WHERE clause on the Id column. To execute the delete, call the ExecuteAsync method...
Read more >Asynchronous Programming - EF Core - Microsoft Learn
Asynchronous operations avoid blocking a thread while the query is executed in ... done by using the await keyword on each async operation....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I know it’s outdated, but I’ve met same problem and figured out, how to fix it.
@app.get("/db/del/{index}", response_model=list[Weather])
async def delete_row(index: int, session: AsyncSession = Depends(get_session)):
Inside function:
row = await session.execute(select(Weather).where(Weather.id == index))
row = row.scalar_one()
await session.delete(row)
await session.commit()
Idk if it is right, but it works, at least for me.
Hi,
The documentation is probably the best place to start: https://docs.sqlalchemy.org/en/14/orm/extensions/asyncio.html