Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: laravel 11 support #200

Merged
merged 8 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# v8.0.0 (2024-03-15)

Added
- Laravel 11 Support (#200)
- The following deprecated methods have been removed
- `Schema\Builder::getAllTables()`
- `Schema\Builder::getIndexListing()`
- `Schema\Grammar::compileTableExists()`
- `Schema\Grammar::compileGetAllTables()`
- `Schema\Grammar::compileColumnListing()`
- `Schema\Grammar::compileIndexListing()`
- `Query\Processor::processColumnListing()`
- `Query\Processor::processIndexListing()`
- `Blueprint::decimal()` can no longer specify `unsigned` flag.

# v7.1.0 (2024-03-11)

Changed
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:8.1-cli-alpine
FROM php:8.2-cli-alpine

COPY --from=composer:2 /usr/bin/composer /usr/bin/composer

Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
"php": "^8.1",
taka-oyama marked this conversation as resolved.
Show resolved Hide resolved
"ext-grpc": "*",
"ext-json": "*",
"laravel/framework": "^10.37.0",
"laravel/framework": "^11",
"google/cloud-spanner": "^1.58.4",
"grpc/grpc": "^1.42",
"symfony/cache": "~6",
"symfony/cache": "~7",
"symfony/deprecation-contracts": "~2",
"symfony/lock": "~6"
"symfony/lock": "~7"
},
"require-dev": {
"orchestra/testbench": "~8",
"phpunit/phpunit": "~10.0",
"orchestra/testbench": "~9",
"phpunit/phpunit": "~11.0",
"phpstan/phpstan": "^1"
},
"autoload": {
Expand Down
30 changes: 30 additions & 0 deletions src/Query/ArrayValue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Copyright 2019 Colopl Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Colopl\Spanner\Query;

/**
* Just a temp object wrapper so UPDATE statements can handle array types
*/
final readonly class ArrayValue
halnique marked this conversation as resolved.
Show resolved Hide resolved
{
public function __construct(
public array $value
)
{
}
}
15 changes: 15 additions & 0 deletions src/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Colopl\Spanner\Connection;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Database\Query\Builder as BaseBuilder;
use Illuminate\Database\Query\Expression;
use Illuminate\Support\Arr;
use LogicException;

Expand All @@ -43,6 +44,20 @@ public function insert(array $values)
return parent::insert($this->prepareInsertForDml($values));
}

/**
* @inheritDoc
*/
public function update(array $values)
{
foreach ($values as $key => $value) {
if (is_array($value)) {
$values[$key] = new ArrayValue($value);
}
}

return parent::update($values);
}

/**
* @inheritDoc
*/
Expand Down
14 changes: 10 additions & 4 deletions src/Query/Concerns/UsesMutations.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ trait UsesMutations
*/
public function insertUsingMutation(array $values)
{
$this->connection->insertUsingMutation($this->from, $values);
$this->connection->insertUsingMutation($this->getTableName(), $values);
}

/**
Expand All @@ -40,7 +40,7 @@ public function insertUsingMutation(array $values)
*/
public function updateUsingMutation(array $values)
{
$this->connection->updateUsingMutation($this->from, $values);
$this->connection->updateUsingMutation($this->getTableName(), $values);
}

/**
Expand All @@ -49,7 +49,7 @@ public function updateUsingMutation(array $values)
*/
public function insertOrUpdateUsingMutation(array $values)
{
$this->connection->insertOrUpdateUsingMutation($this->from, $values);
$this->connection->insertOrUpdateUsingMutation($this->getTableName(), $values);
}

/**
Expand All @@ -58,6 +58,12 @@ public function insertOrUpdateUsingMutation(array $values)
*/
public function deleteUsingMutation($keys)
{
$this->connection->deleteUsingMutation($this->from, $keys);
$this->connection->deleteUsingMutation($this->getTableName(), $keys);
}

protected function getTableName(): string
{
assert(is_string($this->from));
return $this->from;
}
}
15 changes: 15 additions & 0 deletions src/Query/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Illuminate\Database\Query\Builder;
use Illuminate\Contracts\Database\Query\Expression;
use Illuminate\Database\Query\Grammars\Grammar as BaseGrammar;
use Illuminate\Support\Arr;
use RuntimeException;

class Grammar extends BaseGrammar
Expand All @@ -45,6 +46,20 @@ protected function compileLock(Builder $query, $value)
return '';
}

/**
* @inheritDoc
*/
public function prepareBindingsForUpdate(array $bindings, array $values)
{
$bindings = parent::prepareBindingsForUpdate($bindings, $values);
foreach ($bindings as $key => $value) {
if ($value instanceof ArrayValue) {
$bindings[$key] = $value->value;
}
}
return $bindings;
}

/**
* @inheritDoc
*/
Expand Down
20 changes: 0 additions & 20 deletions src/Query/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,6 @@ protected function processColumn(mixed $value): mixed
return $value;
}

/**
* @inheritDoc
*/
public function processColumnListing($results)
{
return array_map(function ($result) {
return ((object) $result)->column_name;
}, $results);
}

/**
* Process the results of a columns query.
*
Expand All @@ -94,16 +84,6 @@ public function processColumns($results)
}, $results);
}

/**
* @deprecated Use processIndexes($results) instead.
* @param array $results
* @return array
*/
public function processIndexListing($results)
{
return self::processIndexes($results);
}

/**
* @param array $results
* @return array
Expand Down
11 changes: 3 additions & 8 deletions src/Schema/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function uuid($column = 'uuid')
* @param int|null $length
* @return ColumnDefinition
*/
public function binary($column, $length = null)
public function binary($column, $length = null, $fixed = false)
halnique marked this conversation as resolved.
Show resolved Hide resolved
{
$length = $length ?: Builder::$defaultBinaryLength;

Expand All @@ -138,10 +138,9 @@ public function binary($column, $length = null)
* @param string $column
* @param int $total
* @param int $places
* @param bool $unsigned
* @return ColumnDefinition
*/
public function decimal($column, $total = 38, $places = 9, $unsigned = false)
public function decimal($column, $total = 38, $places = 9)
{
if ($total !== 38) {
$this->markAsNotSupported('decimal with precision other than 38');
Expand All @@ -151,11 +150,7 @@ public function decimal($column, $total = 38, $places = 9, $unsigned = false)
$this->markAsNotSupported('decimal with scale other than 9');
}

if ($unsigned) {
$this->markAsNotSupported('unsigned decimal');
}

return parent::decimal($column, $total, $places, $unsigned);
return parent::decimal($column, $total, $places);
}

/**
Expand Down
23 changes: 0 additions & 23 deletions src/Schema/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,6 @@ class Builder extends BaseBuilder
*/
public static $defaultMorphKeyType = 'uuid';

/**
* @deprecated Will be removed in a future Laravel version.
*
* @return list<array{ name: string, type: string }>
*/
public function getAllTables()
{
return $this->connection->select(
$this->grammar->compileGetAllTables()
);
}

/**
* @inheritDoc Adds a parent key, for tracking interleaving
*
Expand All @@ -64,17 +52,6 @@ public function getTables()
);
}

/**
* @deprecated Use getIndexes($table) instead
*
* @param string $table
* @return string[]
*/
public function getIndexListing($table)
{
return parent::getIndexes($table);
}

/**
* @param string $table
* @param string $name
Expand Down
46 changes: 0 additions & 46 deletions src/Schema/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,6 @@ class Grammar extends BaseGrammar
*/
protected $modifiers = ['Nullable', 'Default', 'UseSequence'];

/**
* Compile the query to determine if a table exists.
*
* @deprecated Will be removed in a future Laravel version.
*
* @return string
*/
public function compileTableExists()
{
return 'select * from information_schema.tables where table_schema = \'\' and table_name = ?';
}

/**
* Compile the query to determine the tables.
*
Expand All @@ -62,40 +50,6 @@ public function compileTables()
return 'select `table_name` as name, `table_type` as type, `parent_table_name` as parent from information_schema.tables where table_schema = \'\' and table_type = \'BASE TABLE\'';
}

/**
* @deprecated Will be removed in a future Laravel version.
*
* @return string
*/
public function compileGetAllTables()
{
return 'select `table_name` as name, `table_type` as type from information_schema.tables where table_schema = \'\' and table_type = \'BASE TABLE\'';
}

/**
* Compile the query to determine the list of columns.
*
* @deprecated Will be removed in a future Laravel version.
*
* @return string
*/
public function compileColumnListing()
{
return 'select column_name as `column_name` from information_schema.columns where table_schema = \'\' and table_name = ?';
}

/**
* Compile the query to determine the list of indexes.
*
* @deprecated Use compileIndexes($table) instead.
*
* @return string
*/
public function compileIndexListing()
{
return 'select index_name as `index_name` from information_schema.indexes where table_schema = \'\' and table_name = ?';
}

/**
* Compile the query to determine the list of indexes.
*
Expand Down
Loading
Loading