From 1e7063021febf9db7e47d8ea602f582b00d55da6 Mon Sep 17 00:00:00 2001 From: Jonas Staudenmeir Date: Sat, 9 Mar 2024 11:11:57 +0100 Subject: [PATCH] Support Laravel 11 --- .github/workflows/ci.yml | 4 ++-- .github/workflows/static-analysis.yml | 2 +- README.md | 6 ------ composer.json | 10 ++++------ docker-compose.ci.yml | 8 -------- docker-compose.yml | 8 -------- src/Connections/MariaDbConnection.php | 10 ++++++++++ src/Connectors/ConnectionFactory.php | 2 ++ src/Query/Grammars/MariaDbGrammar.php | 11 +++++++++++ .../Grammars/Traits/CompilesSqlServerExpressions.php | 12 ------------ src/Query/Traits/BuildsExpressionQueries.php | 9 +++------ tests/TestCase.php | 1 + tests/config/database.php | 2 +- 13 files changed, 35 insertions(+), 50 deletions(-) create mode 100644 src/Connections/MariaDbConnection.php create mode 100644 src/Query/Grammars/MariaDbGrammar.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e4cf585..f237e0f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,8 +8,8 @@ jobs: strategy: matrix: - php: [ 8.3, 8.2, 8.1 ] - database: [ mysql, mariadb, pgsql, sqlite, sqlsrv, singlestore, firebird ] + php: [ 8.3, 8.2 ] + database: [ mysql, mariadb, pgsql, sqlite, sqlsrv ] # TODO[L11]: singlestore, firebird release: [ stable, lowest ] include: - php: 8.3 diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 5a484fc..4533305 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -1,6 +1,6 @@ name: Static Analysis -on: [ push, pull_request ] +on: workflow_dispatch # TODO[L11]: [ push, pull_request ] jobs: phpstan: diff --git a/README.md b/README.md index 7a26a02..bfccdf9 100644 --- a/README.md +++ b/README.md @@ -199,12 +199,6 @@ $tree = User::from('tree') If you want to implement recursive relationships, you can use this package: [staudenmeir/laravel-adjacency-list](https://github.com/staudenmeir/laravel-adjacency-list) -### Package Conflicts - -- `staudenmeir/eloquent-eager-limit`: Replace both packages - with [staudenmeir/eloquent-eager-limit-x-laravel-cte](https://github.com/staudenmeir/eloquent-eager-limit-x-laravel-cte) - to use them on the same model. - ### Lumen If you are using Lumen, you have to instantiate the query builder manually: diff --git a/composer.json b/composer.json index b96a4db..e3d161a 100644 --- a/composer.json +++ b/composer.json @@ -9,15 +9,13 @@ } ], "require": { - "php": "^8.1", - "illuminate/database": "^10.0" + "php": "^8.2", + "illuminate/database": "^11.0" }, "require-dev": { - "harrygulliford/laravel-firebird": "^3.2", - "orchestra/testbench": "^8.0", + "orchestra/testbench": "^9.0", "phpstan/phpstan": "^1.10", - "phpunit/phpunit": "^10.1", - "singlestoredb/singlestoredb-laravel": "^1.5.1" + "phpunit/phpunit": "^10.5" }, "autoload": { "psr-4": { diff --git a/docker-compose.ci.yml b/docker-compose.ci.yml index 2fdbe12..c0b3df9 100644 --- a/docker-compose.ci.yml +++ b/docker-compose.ci.yml @@ -1,14 +1,6 @@ version: '3.8' services: - php8.1: - image: ghcr.io/staudenmeir/php:8.1 - working_dir: /var/www/html - networks: - - test - volumes: - - .:/var/www/html:delegated - - ~/.cache/composer/files:/root/.composer/cache/files php8.2: image: ghcr.io/staudenmeir/php:8.2 working_dir: /var/www/html diff --git a/docker-compose.yml b/docker-compose.yml index b498c2e..0eb88d4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,14 +1,6 @@ version: '3.8' services: - php8.1: - image: ghcr.io/staudenmeir/php:8.1 - working_dir: /var/www/html - networks: - - test - volumes: - - .:/var/www/html:delegated - - .docker/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini php8.2: image: ghcr.io/staudenmeir/php:8.2 working_dir: /var/www/html diff --git a/src/Connections/MariaDbConnection.php b/src/Connections/MariaDbConnection.php new file mode 100644 index 0000000..1bb89a5 --- /dev/null +++ b/src/Connections/MariaDbConnection.php @@ -0,0 +1,10 @@ + new MySqlConnection($connection, $database, $prefix, $config), + 'mariadb' => new MariaDbConnection($connection, $database, $prefix, $config), 'pgsql' => new PostgresConnection($connection, $database, $prefix, $config), 'sqlite' => new SQLiteConnection($connection, $database, $prefix, $config), 'sqlsrv' => new SqlServerConnection($connection, $database, $prefix, $config), diff --git a/src/Query/Grammars/MariaDbGrammar.php b/src/Query/Grammars/MariaDbGrammar.php new file mode 100644 index 0000000..aa028dc --- /dev/null +++ b/src/Query/Grammars/MariaDbGrammar.php @@ -0,0 +1,11 @@ +compileSelectParent($query); } - /** - * Compile a common table expression for a query. TODO[L11] - * - * @param string $sql - * @param \Illuminate\Database\Query\Builder $query - * @return string - */ - protected function compileTableExpression($sql, $query) - { - return $this->compileExpressions($query, $query->expressions).' '.parent::compileTableExpression($sql, $query); - } - /** * Get the "recursive" keyword. * diff --git a/src/Query/Traits/BuildsExpressionQueries.php b/src/Query/Traits/BuildsExpressionQueries.php index 87fcd87..9114bc3 100644 --- a/src/Query/Traits/BuildsExpressionQueries.php +++ b/src/Query/Traits/BuildsExpressionQueries.php @@ -7,6 +7,7 @@ use Illuminate\Database\Query\Processors\Processor; use RuntimeException; use Staudenmeir\LaravelCte\Query\Grammars\FirebirdGrammar; +use Staudenmeir\LaravelCte\Query\Grammars\MariaDbGrammar; use Staudenmeir\LaravelCte\Query\Grammars\MySqlGrammar; use Staudenmeir\LaravelCte\Query\Grammars\OracleGrammar; use Staudenmeir\LaravelCte\Query\Grammars\PostgresGrammar; @@ -74,6 +75,7 @@ protected function getQueryGrammar(Connection $connection) $grammar = match ($driver) { 'mysql' => new MySqlGrammar(), + 'mariadb' => new MariaDbGrammar(), 'pgsql' => new PostgresGrammar(), 'sqlite' => new SQLiteGrammar(), 'sqlsrv' => new SqlServerGrammar(), @@ -83,12 +85,7 @@ protected function getQueryGrammar(Connection $connection) default => throw new RuntimeException('This database is not supported.'), // @codeCoverageIgnore }; - // TODO[L11] - if (method_exists($grammar, 'setConnection')) { - $grammar->setConnection($connection); - } - - return $grammar; + return $grammar->setConnection($connection); } /** diff --git a/tests/TestCase.php b/tests/TestCase.php index 7116f8f..700c833 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -77,6 +77,7 @@ protected function getEnvironmentSetUp($app) protected function getPackageProviders($app) { + return []; // TODO[L11] return [SingleStoreProvider::class, FirebirdServiceProvider::class]; } } diff --git a/tests/config/database.php b/tests/config/database.php index d826709..effcbce 100644 --- a/tests/config/database.php +++ b/tests/config/database.php @@ -16,7 +16,7 @@ 'engine' => null, ], 'mariadb' => [ - 'driver' => 'mysql', + 'driver' => 'mariadb', 'host' => 'mariadb', 'port' => '3306', 'database' => 'test',