You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In most applications one connection will be enough. So I have no intention to change the default use case. On the other it is a nice-to-have feature to be able handle multiple database connection.
Currently, connection information is obtained from $_ENV superglobal. To handle multiple connections, we would need to change the way it gets the connection information. I am thinking of abstracting $_ENV completely from connection class.
Currently Connection class implements Singleton. There is a static property named $instance. This connection can be considered as default. For other connections it would be a viable solution to extend this class. So the case would be something like this (combining the idea with issue #4 )
class MyDefaultConnection extends \BbOrm\Connection\Mysql
{
use \BbOrm\DefaultConnectionTrait();
// ... to be implemented
}
class MySecondaryConnection extends \BbOrm\Connection\SqLite
{
// ... to be implemented
}
On the other hand, In the models, it get connection from Connection::getInstance static method implemented in \BbOrm\Model. To use some models with non-default connection, in the model, override getConnection method in the Model class. Implementing an abstract parent class in-between \BbOrm\Model and \Project\SomeCustomModel would be an event better solution.
So the use case would be something like :
namespace \MyProject\Models\FirstDatabase;
abstract class Model extends \BbOrm\Model
{
public static function getInstance()
{
\BbOrm::Connection::getInstance('first_database_connection_key');
}
}
namespace \MyProject\Models\FirstDatabase;
class Post extends Model
{
public $id;
public $title;
public $created_at;
}
When it comes to an ORM, its nice to have multiple connection support.
The text was updated successfully, but these errors were encountered: