-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Description
Table::class and DB::class has a bad design. They have a bunch of static methods for interacting with database.
It should be splitted respecting the following:
-
Table::classrenamed inTableEntity::class- it should have properties for every column;
- the child should still be able to define files;
- but it should use a new
WithFilestrait for that.
- but it should use a new
- it should not be available anymore to interact with the database;
- because it would represent only a blueprint of a Table.
-
DB::classsplitted inDbManager::classandDbConn::class-
they both are objects (no static methods anymore);
-
DbManager::classis stored byStaticHandler::class- its constructor gets database config and generate the
DbConn::classobjects- so it becomes a handler for all connections
- its constructor gets database config and generate the
-
DbConn::classis stored byDbManager::class- it gets the
TableEntity::classsubclass namespace and the query parameters - it returns the desired format (array, json, Entity object)
- it gets the
-
Probably we will create also an
DbQuery::class- this one would get the query params
- it should be executed manually with another method
-
Note: Small inspiration from Symfony 6.
Example
For framework usage:
use Arshwell\Monolith\StaticHandler;
use Arshwell\Monolith\Db\DbManager;
use Arshwell\Monolith\Db\DbConn;
use Arshwell\Monolith\Db\TableEntity;
StaticHandler::setDbManager(new DbManager(
// database config
));The new Entity class:
use Arshwell\Monolith\Db\TableEntity;
class User extens TableEntity
{
// const db table info
// const files
// properties for every table column
// getters and setters
}For user usage:
use Arshwell\Monolith\StaticHandler;
use Arshwell\Monolith\Db\DbConn;
use MyNamespace\TableEntity\User;
/** @var DbConn $dbConn **/
$dbConn = StaticHandler::getDbManager("main");
$dbConn->query(...)->result(User::class);
$dbConn->query(...)->result(User::class, TableEntity::RESULT_ENTITY);
$dbConn->query(...)->result(User::class, TableEntity::RESULT_ARRAY);
$dbConn->query(...)->result(User::class, TableEntity::RESULT_JSON);Arshwell Version
0.*
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels