@@ -39,21 +39,7 @@ export class DriverFactory {
3939 }
4040
4141 static fabricate ( conName : string , runtimeConfig : any = { } ) : DriverContract {
42- if ( conName === 'default' ) conName = Config . get ( 'database.default' )
43-
44- const conConfig = Config . get ( `database.connections.${ conName } ` )
45-
46- if ( ! conConfig ) {
47- throw new NotImplementedException (
48- `Connection ${ conName } is not configured inside database.connections object from config/database file` ,
49- )
50- }
51-
52- if ( ! this . drivers . has ( conConfig . driver ) ) {
53- throw new NotImplementedException (
54- `Driver ${ conConfig . driver } does not exist, use Database.build method to create a new driver` ,
55- )
56- }
42+ const conConfig = this . getConnectionConfig ( conName )
5743
5844 const { Driver, clientConnection } = this . drivers . get ( conConfig . driver )
5945
@@ -143,4 +129,39 @@ export class DriverFactory {
143129
144130 return client
145131 }
132+
133+ static async generateConnectionClient (
134+ conName ?: string ,
135+ configs : any = { } ,
136+ saveOnDriver = true ,
137+ ) {
138+ const conConfig = this . getConnectionConfig ( conName )
139+
140+ await this . generateDriverClient (
141+ conConfig . driver ,
142+ conName ,
143+ configs ,
144+ saveOnDriver ,
145+ )
146+ }
147+
148+ private static getConnectionConfig ( conName : string ) {
149+ if ( conName === 'default' ) conName = Config . get ( 'database.default' )
150+
151+ const conConfig = Config . get ( `database.connections.${ conName } ` )
152+
153+ if ( ! conConfig ) {
154+ throw new NotImplementedException (
155+ `Connection ${ conName } is not configured inside database.connections object from config/database file` ,
156+ )
157+ }
158+
159+ if ( ! this . drivers . has ( conConfig . driver ) ) {
160+ throw new NotImplementedException (
161+ `Driver ${ conConfig . driver } does not exist, use Database.build method to create a new driver` ,
162+ )
163+ }
164+
165+ return conConfig
166+ }
146167}
0 commit comments