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
The database implementation has the query builder assignment hard coded in query function. For most cases this is OK or developers change replace the builder in Eloquent model class.
Use case
I'm programming a bi-temporal database layer for Laravel which need to modify and extend the query builder and schema builder. The Grammars keeps the same per driver as usual.
Just to change the model is too dangerous. If somebody updated a record with DB::table('xxx')->update(...) the bi-temporal table would be inconsistent.
That's why I want to ensure some functionality in the base layer which is done in both builders. I want to discuss two implementation possibilities. One needs to have a PR in Laravel Framework.
First variant (my favorite):
Add in config file database.php with a connection like:
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'options' => [
'querybuilderclass' => 'App\Builders\QueryBuilderNew.php'// per default not set
]
]
The query function in Connection.php could be like:
publicfunctionquery()
{
if(!empty($this->config['options']['querybuilderclass']) {
if(!is_subclass_of($this->config['options']['querybuilderclass'])::class, Connection::class) {
thrownewInvalidArgumentException('The configured query builder class "' .
$this->config['options']['querybuilderclass'] .'" is not inherited of Laravel\'s Connection class')
}
returnnew$this->config['options']['querybuilderclass'](
$this, $this->getQueryGrammar(), $this->getPostProcessor())
}
returnnewQueryBuilder(
$this, $this->getQueryGrammar(), $this->getPostProcessor()
);
}
I would change same for Schema Builder, QueryGrammar and SchemaGrammar.
variant 2
I build a kind virtual connection configured in database.php without a driver but with a baseConnectionName. The package Service Provider hooks the 'db' resolving event.
The callback function 'make' the configured base connection and extend the database manager with a new connection which bases on the original driver but with a new query builder.
The variant 2 is quiet complex and more difficult to undersatand, but it could work also.
Questions to the community:
-What do you think is the better solution?
-Has variant 1 a chance that a such a PR could be merged?
I am not so experienced with PR's and coding. So please correct me if there is a besser solution or style.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Issue
The database implementation has the query builder assignment hard coded in query function. For most cases this is OK or developers change replace the builder in Eloquent model class.
Use case
I'm programming a bi-temporal database layer for Laravel which need to modify and extend the query builder and schema builder. The Grammars keeps the same per driver as usual.
Just to change the model is too dangerous. If somebody updated a record with
DB::table('xxx')->update(...)
the bi-temporal table would be inconsistent.That's why I want to ensure some functionality in the base layer which is done in both builders. I want to discuss two implementation possibilities. One needs to have a PR in Laravel Framework.
First variant (my favorite):
Add in config file
database.php
with a connection like:The query function in
Connection.php
could be like:I would change same for Schema Builder, QueryGrammar and SchemaGrammar.
variant 2
I build a kind virtual connection configured in
database.php
without a driver but with abaseConnectionName
. The package Service Provider hooks the 'db' resolving event.The callback function 'make' the configured base connection and extend the database manager with a new connection which bases on the original driver but with a new query builder.
The variant 2 is quiet complex and more difficult to undersatand, but it could work also.
Questions to the community:
-What do you think is the better solution?
-Has variant 1 a chance that a such a PR could be merged?
I am not so experienced with PR's and coding. So please correct me if there is a besser solution or style.
Regards,
Enrica
Beta Was this translation helpful? Give feedback.
All reactions