Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
28 changes: 1 addition & 27 deletions src/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,8 +27,7 @@ class Builder extends BaseBuilder
use Concerns\AppliesForceIndex,
Concerns\UsesMutations,
Concerns\UsesPartitionedDml,
Concerns\UsesStaleReads,
MarksAsNotSupported;
Concerns\UsesStaleReads;

/**
* @var Connection
Expand All @@ -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
*/
Expand All @@ -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
Expand Down
18 changes: 18 additions & 0 deletions src/Query/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +27,7 @@

class Grammar extends BaseGrammar
{
use MarksAsNotSupported;
use SharedGrammarCalls;

/**
Expand All @@ -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
*/
Expand Down
41 changes: 41 additions & 0 deletions tests/Query/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}