Skip to content

Commit

Permalink
Add Oracle support (#50)
Browse files Browse the repository at this point in the history
* Support Oracle

* Fix static analysis

* Refactoring

* Add tests

* Update README

* Test Scrutinizer fix

* Remove tests

* Fix static analysis

* Fix code coverage

* Fix static analysis

* Fix code coverage

* Improve static analysis

* Fix static analysis
  • Loading branch information
staudenmeir authored Sep 1, 2023
1 parent 50924b8 commit 87f4447
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ jobs:
- uses: shivammathur/setup-php@v2
with:
php-version: 8.2
- run: composer update --no-interaction --no-progress --prefer-dist
- run: |
composer require --dev --ignore-platform-req=ext-oci8 yajra/laravel-oci8
composer update --no-interaction --no-progress --prefer-dist --ignore-platform-req=ext-oci8
- run: vendor/bin/phpstan analyse --error-format=github
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Supports Laravel 5.5+.
- PostgreSQL 9.4+
- SQLite 3.8.3+
- SQL Server 2008+
- Oracle 9.2+
- SingleStore 8.1+

## Installation
Expand Down
22 changes: 22 additions & 0 deletions src/Connections/OracleConnection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Staudenmeir\LaravelCte\Connections;

use Staudenmeir\LaravelCte\Query\OracleBuilder;
use Yajra\Oci8\Oci8Connection;

/**
* @codeCoverageIgnore
*/
class OracleConnection extends Oci8Connection
{
/**
* Get a new query builder instance.
*
* @return \Illuminate\Database\Query\Builder
*/
public function query()
{
return new OracleBuilder($this);
}
}
3 changes: 3 additions & 0 deletions src/Connectors/ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Database\Connectors\ConnectionFactory as Base;
use InvalidArgumentException;
use Staudenmeir\LaravelCte\Connections\MySqlConnection;
use Staudenmeir\LaravelCte\Connections\OracleConnection;
use Staudenmeir\LaravelCte\Connections\PostgresConnection;
use Staudenmeir\LaravelCte\Connections\SQLiteConnection;
use Staudenmeir\LaravelCte\Connections\SingleStoreConnection;
Expand Down Expand Up @@ -40,6 +41,8 @@ protected function createConnection($driver, $connection, $database, $prefix = '
return new SQLiteConnection($connection, $database, $prefix, $config);
case 'sqlsrv':
return new SqlServerConnection($connection, $database, $prefix, $config);
case 'oracle':
return new OracleConnection($connection, $database, $prefix, $config); // @codeCoverageIgnore
case 'singlestore':
return new SingleStoreConnection($connection, $database, $prefix, $config);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Eloquent/QueriesExpressions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
namespace Staudenmeir\LaravelCte\Eloquent;

use Staudenmeir\LaravelCte\Query\Builder;
use Staudenmeir\LaravelCte\Query\OracleBuilder;
use Staudenmeir\LaravelCte\Query\SingleStoreBuilder;

trait QueriesExpressions
{
/**
* Get a new query builder instance for the connection.
*
* @return \Staudenmeir\LaravelCte\Query\Builder
* @return \Illuminate\Database\Query\Builder
*/
protected function newBaseQueryBuilder()
{
$connection = $this->getConnection();

return match ($connection->getDriverName()) {
'oracle' => new OracleBuilder($connection),
'singlestore' => new SingleStoreBuilder($connection),
default => new Builder($connection),
};
Expand Down
11 changes: 11 additions & 0 deletions src/Query/Grammars/OracleGrammar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Staudenmeir\LaravelCte\Query\Grammars;

use Staudenmeir\LaravelCte\Query\Grammars\Traits\CompilesOracleExpressions;
use Yajra\Oci8\Query\Grammars\OracleGrammar as Base;

class OracleGrammar extends Base
{
use CompilesOracleExpressions;
}
22 changes: 22 additions & 0 deletions src/Query/Grammars/Traits/CompilesOracleExpressions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Staudenmeir\LaravelCte\Query\Grammars\Traits;

/**
* @codeCoverageIgnore
*/
trait CompilesOracleExpressions
{
use CompilesExpressions;

/**
* Get the "recursive" keyword.
*
* @param array $expressions
* @return string
*/
protected function recursiveKeyword(array $expressions)
{
return '';
}
}
11 changes: 11 additions & 0 deletions src/Query/OracleBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Staudenmeir\LaravelCte\Query;

use Staudenmeir\LaravelCte\Query\Traits\BuildsExpressionQueries;
use Yajra\Oci8\Query\OracleBuilder as Base;

class OracleBuilder extends Base
{
use BuildsExpressionQueries;
}
2 changes: 2 additions & 0 deletions src/Query/Traits/BuildsExpressionQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Database\Query\Processors\Processor;
use RuntimeException;
use Staudenmeir\LaravelCte\Query\Grammars\MySqlGrammar;
use Staudenmeir\LaravelCte\Query\Grammars\OracleGrammar;
use Staudenmeir\LaravelCte\Query\Grammars\PostgresGrammar;
use Staudenmeir\LaravelCte\Query\Grammars\SingleStoreGrammar;
use Staudenmeir\LaravelCte\Query\Grammars\SQLiteGrammar;
Expand Down Expand Up @@ -75,6 +76,7 @@ protected function getQueryGrammar(Connection $connection)
'pgsql' => new PostgresGrammar(),
'sqlite' => new SQLiteGrammar(),
'sqlsrv' => new SqlServerGrammar(),
'oracle' => new OracleGrammar(),
'singlestore' => new SingleStoreGrammar(),
default => throw new RuntimeException('This database is not supported.'), // @codeCoverageIgnore
};
Expand Down

0 comments on commit 87f4447

Please sign in to comment.