mirror of
https://github.com/grillazz/fastapi-sqlalchemy-asyncpg.git
synced 2025-08-26 16:40:40 +03:00
set postgresql dialect for compile_sql_or_scalar decorator
This commit is contained in:
parent
b938b0dee0
commit
042a56c8b5
@ -1,5 +1,6 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
from sqlalchemy.dialects import postgresql
|
||||||
from sqlalchemy import String, select, ForeignKey
|
from sqlalchemy import String, select, ForeignKey
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
@ -16,7 +17,7 @@ def compile_sql_or_scalar(func):
|
|||||||
async def wrapper(cls, db_session, name, compile_sql=False, *args, **kwargs):
|
async def wrapper(cls, db_session, name, compile_sql=False, *args, **kwargs):
|
||||||
stmt = await func(cls, db_session, name, *args, **kwargs)
|
stmt = await func(cls, db_session, name, *args, **kwargs)
|
||||||
if compile_sql:
|
if compile_sql:
|
||||||
return stmt.compile(compile_kwargs={"literal_binds": True})
|
return stmt.compile(dialect=postgresql.dialect(), compile_kwargs={"literal_binds": True})
|
||||||
result = await db_session.execute(stmt)
|
result = await db_session.execute(stmt)
|
||||||
return result.scalars().first()
|
return result.scalars().first()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user