1 | <?php |
||
2 | |||
3 | namespace Staudenmeir\EloquentEagerLimitXLaravelCte\Eloquent; |
||
4 | |||
5 | use Illuminate\Database\Connection; |
||
6 | use RuntimeException; |
||
7 | use Staudenmeir\EloquentEagerLimit\Traits\HasEagerLimitRelationships; |
||
8 | use Staudenmeir\EloquentEagerLimitXLaravelCte\Query\Builder; |
||
9 | use Staudenmeir\EloquentEagerLimitXLaravelCte\Query\Grammars\MySqlGrammar; |
||
10 | use Staudenmeir\EloquentEagerLimitXLaravelCte\Query\Grammars\PostgresGrammar; |
||
11 | use Staudenmeir\EloquentEagerLimitXLaravelCte\Query\Grammars\SQLiteGrammar; |
||
12 | use Staudenmeir\EloquentEagerLimitXLaravelCte\Query\Grammars\SqlServerGrammar; |
||
13 | |||
14 | trait HasEagerLimitAndQueriesExpressions |
||
15 | { |
||
16 | use HasEagerLimitRelationships; |
||
17 | |||
18 | /** |
||
19 | * Get a new query builder instance for the connection. |
||
20 | * |
||
21 | * @return \Staudenmeir\EloquentEagerLimitXLaravelCte\Query\Builder |
||
22 | */ |
||
23 | 229 | protected function newBaseQueryBuilder() |
|
24 | { |
||
25 | 229 | $connection = $this->getConnection(); |
|
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
26 | |||
27 | 229 | $grammar = $connection->withTablePrefix( |
|
28 | 229 | $this->getQueryGrammar($connection) |
|
29 | 229 | ); |
|
30 | |||
31 | 229 | return new Builder($connection, $grammar); |
|
32 | } |
||
33 | |||
34 | /** |
||
35 | * Get the query grammar. |
||
36 | * |
||
37 | * @param \Illuminate\Database\Connection $connection |
||
38 | * @return \Illuminate\Database\Query\Grammars\Grammar |
||
39 | */ |
||
40 | 229 | protected function getQueryGrammar(Connection $connection) |
|
41 | { |
||
42 | 229 | $driver = $connection->getDriverName(); |
|
43 | |||
44 | switch ($driver) { |
||
45 | 229 | case 'mysql': |
|
46 | 89 | return new MySqlGrammar(); |
|
47 | 140 | case 'pgsql': |
|
48 | 48 | return new PostgresGrammar(); |
|
49 | 92 | case 'sqlite': |
|
50 | 47 | return new SQLiteGrammar(); |
|
51 | 45 | case 'sqlsrv': |
|
52 | 45 | return new SqlServerGrammar(); |
|
53 | } |
||
54 | |||
55 | throw new RuntimeException('This database is not supported.'); // @codeCoverageIgnore |
||
56 | } |
||
57 | } |
||
58 |