@@ -93,6 +93,8 @@ def match_path(self, dsn):
9393
9494
9595class Connect :
96+ """Provides methods for connecting to a supported database using a URL or connection dict."""
97+
9698 def __init__ (self , database_by_scheme : Dict [str , Database ]):
9799 self .database_by_scheme = database_by_scheme
98100 self .match_uri_path = {
@@ -172,9 +174,11 @@ def connect_to_uri(self, db_uri: str, thread_count: Optional[int] = 1) -> Databa
172174 kw = {k : v for k , v in kw .items () if v is not None }
173175
174176 if issubclass (cls , ThreadedDatabase ):
175- return cls (thread_count = thread_count , ** kw )
177+ db = cls (thread_count = thread_count , ** kw )
178+ else :
179+ db = cls (** kw )
176180
177- return cls ( ** kw )
181+ return self . _connection_created ( db )
178182
179183 def connect_with_dict (self , d , thread_count ):
180184 d = dict (d )
@@ -186,9 +190,15 @@ def connect_with_dict(self, d, thread_count):
186190
187191 cls = matcher .database_cls
188192 if issubclass (cls , ThreadedDatabase ):
189- return cls (thread_count = thread_count , ** d )
193+ db = cls (thread_count = thread_count , ** d )
194+ else :
195+ db = cls (** d )
196+
197+ return self ._connection_created (db )
190198
191- return cls (** d )
199+ def _connection_created (self , db ):
200+ "Nop function to be overridden by subclasses."
201+ return db
192202
193203 def __call__ (self , db_conf : Union [str , dict ], thread_count : Optional [int ] = 1 ) -> Database :
194204 """Connect to a database using the given database configuration.
0 commit comments