File tree 2 files changed +9
-3
lines changed
advanced_alchemy/extensions/flask
2 files changed +9
-3
lines changed Original file line number Diff line number Diff line change 12
12
from advanced_alchemy .exceptions import ImproperConfigurationError
13
13
from advanced_alchemy .extensions .flask .cli import database_group
14
14
from advanced_alchemy .extensions .flask .config import SQLAlchemyAsyncConfig , SQLAlchemySyncConfig
15
- from advanced_alchemy .utils .portals import PortalProvider
15
+ from advanced_alchemy .utils .portals import Portal , PortalProvider
16
16
17
17
if TYPE_CHECKING :
18
18
from flask import Flask
@@ -44,6 +44,11 @@ def __init__(
44
44
if app is not None :
45
45
self .init_app (app )
46
46
47
+ @property
48
+ def portal (self ) -> "Portal" :
49
+ """Get the portal."""
50
+ return self .portal_provider .portal
51
+
47
52
@property
48
53
def config (self ) -> "Sequence[Union[SQLAlchemyAsyncConfig, SQLAlchemySyncConfig]]" :
49
54
"""Get the SQLAlchemy configuration(s)."""
Original file line number Diff line number Diff line change @@ -86,6 +86,7 @@ Advanced Alchemy supports async SQLAlchemy with Flask:
86
86
87
87
You can also safely use an AsyncSession in your routes within a sync context.
88
88
89
+
89
90
.. warning ::
90
91
91
92
This is experimental and may change in the future.
@@ -94,8 +95,8 @@ You can also safely use an AsyncSession in your routes within a sync context.
94
95
95
96
@app.route (" /users" )
96
97
def list_users ():
97
- session = alchemy.get_sync_session ()
98
- users = session.execute( select(User))
98
+ session = alchemy.get_async_session ()
99
+ users = alchemy.portal.call( session.execute, select(User))
99
100
return {" users" : [user.dict() for user in users.scalars()]}
100
101
101
102
Configuration
You can’t perform that action at this time.
0 commit comments