diff --git a/src/masoniteorm/connections/ConnectionFactory.py b/src/masoniteorm/connections/ConnectionFactory.py index 9b924a3d..b36292dd 100644 --- a/src/masoniteorm/connections/ConnectionFactory.py +++ b/src/masoniteorm/connections/ConnectionFactory.py @@ -4,9 +4,10 @@ class ConnectionFactory: """Class for controlling the registration and creation of connection types.""" - _connections = { - # - } + _connections = {} + + def __init__(self, config_path=None): + self.config_path = config_path @classmethod def register(cls, key, connection): @@ -35,7 +36,7 @@ def make(self, key): masoniteorm.connection.BaseConnection -- Returns an instance of a BaseConnection class. """ - DB = load_config().DB + DB = load_config(config_path=self.config_path).DB connections = DB.get_connection_details() diff --git a/src/masoniteorm/connections/ConnectionResolver.py b/src/masoniteorm/connections/ConnectionResolver.py index f62eac30..f408c09c 100644 --- a/src/masoniteorm/connections/ConnectionResolver.py +++ b/src/masoniteorm/connections/ConnectionResolver.py @@ -6,7 +6,7 @@ class ConnectionResolver: _connections = {} _morph_map = {} - def __init__(self): + def __init__(self, config_path=None): from ..connections import ( SQLiteConnection, PostgresConnection, @@ -14,10 +14,10 @@ def __init__(self): MSSQLConnection, ) + self.config_path = config_path from ..connections import ConnectionFactory - self.connection_factory = ConnectionFactory() - + self.connection_factory = ConnectionFactory(config_path=config_path) self.register(SQLiteConnection) self.register(PostgresConnection) self.register(MySQLConnection) diff --git a/src/masoniteorm/query/QueryBuilder.py b/src/masoniteorm/query/QueryBuilder.py index fea2c674..5bd886ec 100644 --- a/src/masoniteorm/query/QueryBuilder.py +++ b/src/masoniteorm/query/QueryBuilder.py @@ -47,6 +47,7 @@ def __init__( scopes=None, schema=None, dry=False, + config_path=None ): """QueryBuilder initializer @@ -57,6 +58,7 @@ def __init__( connection {masoniteorm.connection.Connection} -- A connection class (default: {None}) table {str} -- the name of the table (default: {""}) """ + self.config_path = config_path self.grammar = grammar self.table(table) self.dry = dry @@ -103,7 +105,7 @@ def __init__( self.set_action("select") if not self._connection_details: - DB = load_config().DB + DB = load_config(config_path=self.config_path).DB self._connection_details = DB.get_connection_details() self.on(connection) @@ -382,7 +384,7 @@ def method(*args, **kwargs): ) def on(self, connection): - DB = load_config().DB + DB = load_config(self.config_path).DB if connection == "default": self.connection = self._connection_details.get("default") diff --git a/src/masoniteorm/schema/Schema.py b/src/masoniteorm/schema/Schema.py index 817872e9..6d49f886 100644 --- a/src/masoniteorm/schema/Schema.py +++ b/src/masoniteorm/schema/Schema.py @@ -57,6 +57,7 @@ def __init__( grammar=None, connection_details=None, schema=None, + config_path=None ): self._dry = dry self.connection = connection @@ -68,6 +69,7 @@ def __init__( self._blueprint = None self._sql = None self.schema = schema + self.config_path = config_path if not self.connection_class: self.on(self.connection) @@ -85,7 +87,7 @@ def on(self, connection_key): Returns: cls """ - DB = load_config().DB + DB = load_config(config_path=self.config_path).DB if connection_key == "default": self.connection = self.connection_details.get("default")