diff --git a/CHANGELOG.md b/CHANGELOG.md index e1ca59ce..6ca131a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ Changed - Path for auth and session pool files have moved from `storage/framework/cache/spanner` to `storage/framework/spanner/{auth|session}`. - Default Session Not Found Error Mode was changed from `MAINTAIN_SESSION_POOL` to `CLEAR_SESSION_POOL` (wasn't fully confident at the time, but I think it should be safe to assume it's working now). - Schema\Builder::getAllTables() now returns rows with `name` and `type` fields instead of list of strings (was implemented incorrectly). +- Exception previously thrown in `Query/Builder` for `sharedLock`, `lockForUpdate`, `insertGetId` was moved to `Query/Grammar`. +- Query/Builder::lock will now throw `BadMethodCallException` if called. Was ignored in previous versions. # v4.7.0 (Not released yet) diff --git a/src/Query/Builder.php b/src/Query/Builder.php index 93be201b..94637a25 100644 --- a/src/Query/Builder.php +++ b/src/Query/Builder.php @@ -17,7 +17,6 @@ namespace Colopl\Spanner\Query; -use Colopl\Spanner\Concerns\MarksAsNotSupported; use Colopl\Spanner\Connection; use Illuminate\Contracts\Support\Arrayable; use Illuminate\Database\Query\Builder as BaseBuilder; @@ -28,8 +27,7 @@ class Builder extends BaseBuilder use Concerns\AppliesForceIndex, Concerns\UsesMutations, Concerns\UsesPartitionedDml, - Concerns\UsesStaleReads, - MarksAsNotSupported; + Concerns\UsesStaleReads; /** * @var Connection @@ -44,14 +42,6 @@ public function insert(array $values) return parent::insert($this->prepareInsertForDml($values)); } - /** - * @inheritDoc - */ - public function insertGetId(array $values, $sequence = null) - { - $this->markAsNotSupported('insertGetId'); - } - /** * @inheritDoc */ @@ -76,22 +66,6 @@ public function truncate() } } - /** - * @inheritDoc - */ - public function sharedLock() - { - $this->markAsNotSupported('shared lock'); - } - - /** - * @inheritDoc - */ - public function lockForUpdate() - { - $this->markAsNotSupported('lock for update'); - } - /** * NOTE: We will attempt to bind column names included in UNNEST() here. * @see https://cloud.google.com/spanner/docs/lexical#query-parameters diff --git a/src/Query/Grammar.php b/src/Query/Grammar.php index 38d82bc4..09c8434e 100644 --- a/src/Query/Grammar.php +++ b/src/Query/Grammar.php @@ -17,6 +17,7 @@ namespace Colopl\Spanner\Query; +use Colopl\Spanner\Concerns\MarksAsNotSupported; use Colopl\Spanner\Concerns\SharedGrammarCalls; use Colopl\Spanner\Query\Builder as SpannerBuilder; use Illuminate\Database\Query\Builder; @@ -26,6 +27,7 @@ class Grammar extends BaseGrammar { + use MarksAsNotSupported; use SharedGrammarCalls; /** @@ -36,6 +38,22 @@ protected function compileFrom(Builder $query, $table) return parent::compileFrom($query, $table).$this->compileForceIndex($query); } + /** + * @inheritDoc + */ + public function compileInsertGetId(Builder $query, $values, $sequence) + { + $this->markAsNotSupported('insertGetId'); + } + + /** + * @inheritDoc + */ + protected function compileLock(Builder $query, $value) + { + $this->markAsNotSupported('explicit locking'); + } + /** * @inheritDoc */ diff --git a/tests/Query/BuilderTest.php b/tests/Query/BuilderTest.php index 6f75e05c..d7c6a392 100644 --- a/tests/Query/BuilderTest.php +++ b/tests/Query/BuilderTest.php @@ -17,6 +17,7 @@ namespace Colopl\Spanner\Tests\Query; +use BadMethodCallException; use Colopl\Spanner\Connection; use Colopl\Spanner\Query\Builder; use Colopl\Spanner\Tests\TestCase; @@ -826,4 +827,44 @@ public function testTruncate(): void $this->assertDatabaseCount($tableName, 0); } + + public function test_insertGetId(): void + { + $this->expectException(BadMethodCallException::class); + $this->expectExceptionMessage('Cloud Spanner does not support insertGetId'); + + $conn = $this->getDefaultConnection(); + $qb = $conn->table(self::TABLE_NAME_USER); + $qb->insertGetId(['userId' => $this->generateUuid(), 'name' => 'first']); + } + + public function test_lock(): void + { + $this->expectException(BadMethodCallException::class); + $this->expectExceptionMessage('Cloud Spanner does not support explicit locking'); + + $conn = $this->getDefaultConnection(); + $qb = $conn->table(self::TABLE_NAME_USER); + $qb->lock()->get(); + } + + public function test_lockForUpdate(): void + { + $this->expectException(BadMethodCallException::class); + $this->expectExceptionMessage('Cloud Spanner does not support explicit locking'); + + $conn = $this->getDefaultConnection(); + $qb = $conn->table(self::TABLE_NAME_USER); + $qb->lockForUpdate()->get(); + } + + public function test_sharedLock(): void + { + $this->expectException(BadMethodCallException::class); + $this->expectExceptionMessage('Cloud Spanner does not support explicit locking'); + + $conn = $this->getDefaultConnection(); + $qb = $conn->table(self::TABLE_NAME_USER); + $qb->sharedLock()->get(); + } }