All Questions
13 questions
1
vote
1
answer
73
views
How to create a single table at run time with SQLAlchemy asyncio
In my program I have several classes defined which may or may not be instantiated in a given run time. Therefore I don't want to define the tables in the class and have them all populated together ...
1
vote
1
answer
392
views
How do you establish a self-referencing foreign key in SQLAlchemy 2.0?
Here is my model:
class MyModel(Base):
__tablename__ = 'model'
id : Mapped[int] = mapped_column(primary_key=True)
given_id : Mapped[str] = mapped_column(String(50),...
0
votes
1
answer
959
views
Tortoise-orm with FastApi Fetching data from db is blocking/Sync instead of asynchronous/non-blocking
Using fastapi with tortoise-orm==0.19.3. There're like 25,000 records of the table Server.
I'm fetching all of them with the endpoint /servers/ like this.
@server_router.get("/servers")
...
2
votes
1
answer
10k
views
How to use FastApi and SqlAlchemy for asynchronous operations
I'm using translation software, there may be some mistakes in expression, please understand
I have checked the tutorials on the internet and followed the corresponding ideas, but I have encountered a ...
5
votes
2
answers
8k
views
How to get a session from async_session() generator FastApi Sqlalchemy
I see in many places an approach for getting SqlAlchemy session just like this one below:
async def get_session() -> AsyncSession:
async with async_session() as session:
yield session
...
3
votes
1
answer
2k
views
How to return data on WebSocket when new database entry is made FastAPI
I am trying to write a simple API that collects measurements, and then streams them live to clients over a websocket with FastAPI. There are plenty of tutorials on how to send messages when triggered ...
61
votes
3
answers
108k
views
ObjectNotExecutableError when executing any SQL query using AsyncEngine
I'm using async_engine. When I try to execute anything:
async with self.async_engine.connect() as con:
query = "SELECT id, name FROM item LIMIT 50;"
result = await con.execute(f"...
38
votes
2
answers
77k
views
SqlAlchemy asyncio orm: How to query the database
In SqlAlchemy async orm engine how do I query a table and get a value or all?
I know from the non async methods that I can just do
SESSION.query(TableClass).get(x)
but trying this with the async ...
2
votes
0
answers
4k
views
Async SQLAlchemy Session: Commit using AsyncSession() or AsyncSession?
I am starting to use AsyncSession from sqlalchemy in a asyncio app. However, when assigning an AsyncSession object to a class like Foo (based on official docs) and Bar below, is there any difference ...
14
votes
1
answer
27k
views
SQLAlchemy AttributeError: 'AsyncEngine' object has no attribute '_run_ddl_visitor'
I am trying to use the async version of SQLAlchemy in an asyncio app. However, when trying to create the tables using Metadata().create_all(), the following error occurs
AttributeError: 'AsyncEngine' ...
1
vote
1
answer
1k
views
"meta" in Async SQLAlchemy Example
In the official SQLALchemy docs on using an async version of the traditional Engine API, we are provided with the example code
import asyncio
from sqlalchemy.ext.asyncio import create_async_engine
...
0
votes
1
answer
939
views
aiomysql and sqlalchemy basic example produces syntax error on python 3.6
I am trying to integrate sqlalchemy with aiomysql on python 3.6, using their official example on github here is my full code
import sqlalchemy as sa
import asyncio
from aiomysql.sa import ...
3
votes
2
answers
8k
views
Correct usage of sqlalchemy scoped_session with python asyncio
I'm building an app using asyncio. I will be using sqlalchemy as the orm.
From what i understand scoped_session associates a session with a thread so they don't with each other's operations.
Now since ...