Skip to content

Commit

Permalink
[breaking] feat: Query::insertGetId throws error now instead of retur…
Browse files Browse the repository at this point in the history
…n last value

this method is only called if `incrementing = true` which should never be true for Spanner databases
  • Loading branch information
taka-oyama committed Feb 14, 2022
1 parent 057ea35 commit db075c5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
6 changes: 0 additions & 6 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ parameters:
path: src/Colopl/Spanner/Connection.php
- message: '#^Cannot cast mixed to int\.$#'
path: src/Colopl/Spanner/Eloquent/Model.php
- message: '#^Return type \(string\) of method Colopl\\Spanner\\Query\\Builder::insertGetId\(\) should be compatible with return type \(int\) of method Illuminate\\Database\\Query\\Builder::insertGetId\(\)$#'
path: src/Colopl/Spanner/Query/Builder.php
- message: '#^Method Colopl\\Spanner\\Query\\Builder::insertGetId\(\) should return string but returns mixed\.$#'
path: src/Colopl/Spanner/Query/Builder.php
- message: '#^Cannot access offset string\|null on mixed\.$#'
path: src/Colopl/Spanner/Query/Builder.php
- message: '#^Method Colopl\\Spanner\\Schema\\Builder::createBlueprint\(\) should return Illuminate\\Database\\Schema\\Blueprint but returns mixed\.$#'
path: src/Colopl/Spanner/Schema/Builder.php
- message: '#^Property Illuminate\\Database\\Schema\\Builder::\$resolver \(Closure\) in isset\(\) is not nullable.$#'
Expand Down
14 changes: 5 additions & 9 deletions src/Colopl/Spanner/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,14 @@ public function insert(array $values)
* This will return the last value used since Spanner does not have the
* feature to return the last inserted ID.
*
* @param array $values
* @param string|null $sequence the name of primary key
* @return string
* @throws InvalidArgumentException
* @param array $values
* @param string|null $sequence the name of primary key
* @return int
*/
public function insertGetId(array $values, $sequence = null)
{
$values = $this->prepareInsertForDml($values);
$this->insert($values);

$lastValue = array_values(array_slice($values, -1))[0];
return $lastValue[$sequence] ?? null;
$this->markAsNotSupported('insertGetId');
return -1;
}

/**
Expand Down

0 comments on commit db075c5

Please sign in to comment.