1111 Union ,
1212)
1313
14- from sqlalchemy .engine import Connection
14+ from sqlalchemy .engine import URL , Connection
1515from sqlalchemy .ext .asyncio import (
1616 AsyncEngine ,
1717 async_scoped_session ,
@@ -51,7 +51,6 @@ def __init__(
5151 commit_on_exit: Whether to commit the session when the context manager or session generator exits.
5252 **session_options: The default `session` initialization parameters
5353 """
54-
5554 self .engine : AsyncEngine = engine
5655 """`sqlalchemy` Asynchronous Engine
5756
@@ -78,7 +77,7 @@ def __init__(
7877 f"_session_context_var_{ id (self )} " , default = None
7978 )
8079 self .scoped_session : async_scoped_session = async_scoped_session (self .session_maker , scopefunc = self ._session_scope .get )
81- super ().__init__ ()
80+ super ().__init__ (engine )
8281
8382 @property
8483 def session (self ) -> AsyncSession :
@@ -115,7 +114,7 @@ def __call__(self, scope: Any = None):
115114
116115 @classmethod
117116 def create (
118- cls , url : str , * , commit_on_exit : bool = True , session_options : Mapping [str , Any ] = None , ** kwargs
117+ cls , url : Union [ str , URL ] , * , commit_on_exit : bool = True , session_options : Mapping [str , Any ] = None , ** kwargs
119118 ) -> "AsyncDatabase" :
120119 """
121120 Initialize the client with a database connection string
@@ -207,7 +206,7 @@ def __init__(self, engine: Engine, commit_on_exit: bool = True, **session_option
207206 self ._session_scope : ContextVar [Union [str , Session , None ]] = ContextVar (f"_session_context_var_{ id (self )} " , default = None )
208207 self .scoped_session : scoped_session = scoped_session (self .session_maker , scopefunc = self ._session_scope .get )
209208 """Returns the Session local instance for the current context or current thread."""
210- super ().__init__ ()
209+ super ().__init__ (engine )
211210
212211 @property
213212 def session (self ) -> Session :
@@ -222,7 +221,7 @@ def __call__(self, scope: Any = None):
222221
223222 @classmethod
224223 def create (
225- cls , url : str , * , commit_on_exit : bool = True , session_options : Optional [Mapping [str , Any ]] = None , ** kwargs
224+ cls , url : Union [ str , URL ] , * , commit_on_exit : bool = True , session_options : Optional [Mapping [str , Any ]] = None , ** kwargs
226225 ) -> "Database" :
227226 kwargs .setdefault ("future" , True )
228227 engine = create_engine (url , ** kwargs )
0 commit comments