-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(spanner): add PG.OID type support for parameterized queries (#6788)
* feat(spanner): add PG.OID type support for parameterized queries * test(spanner): add testing for PG.OID type * fix(spanner): fix typo * test(spanner): fix typo * test(spanner): add missing dependency * fix(spanner): fix typo --------- Co-authored-by: larkee <[email protected]> Co-authored-by: Saransh Dhingra <[email protected]>
- Loading branch information
1 parent
fcd0cfe
commit 273683d
Showing
10 changed files
with
239 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
/** | ||
* Copyright 2023 Google LLC | ||
* | ||
* 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 Google\Cloud\Spanner; | ||
|
||
use Google\Cloud\Spanner\V1\TypeAnnotationCode; | ||
|
||
/** | ||
* Represents a value with a data type of | ||
* [PG OID](https://cloud.google.com/spanner/docs/reference/postgresql/data-types) for the | ||
* Postgres Dialect database. | ||
* | ||
* Example: | ||
* ``` | ||
* use Google\Cloud\Spanner\SpannerClient; | ||
* | ||
* $spanner = new SpannerClient(); | ||
* $pgOid = $spanner->pgOid('123'); | ||
* ``` | ||
*/ | ||
class PgOid implements ValueInterface, TypeAnnotationInterface | ||
{ | ||
/** | ||
* @var string|null | ||
*/ | ||
private ?string $value; | ||
|
||
/** | ||
* @param string|null $value The OID value. | ||
*/ | ||
public function __construct(?string $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
/** | ||
* Get the underlying value. | ||
* | ||
* @return string|null | ||
*/ | ||
public function get(): ?string | ||
{ | ||
return $this->value; | ||
} | ||
|
||
/** | ||
* Get the type. | ||
* | ||
* @access private | ||
* @return int | ||
*/ | ||
public function type(): int | ||
{ | ||
return ValueMapper::TYPE_INT64; | ||
} | ||
|
||
/** | ||
* Get the type annotation code. | ||
* This is to be used along type, to differentiate the value from TypeCode::INT64. | ||
* | ||
* @access private | ||
* @return int | ||
*/ | ||
public function typeAnnotation(): int | ||
{ | ||
return TypeAnnotationCode::PG_OID; | ||
} | ||
|
||
/** | ||
* Format the value as a string. | ||
* | ||
* @return string | ||
*/ | ||
public function formatAsString(): ?string | ||
{ | ||
return (string) $this->value; | ||
} | ||
|
||
/** | ||
* Format the value as a string. | ||
* | ||
* @return string | ||
*/ | ||
public function __toString() | ||
{ | ||
return (string) $this->value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
/** | ||
* Copyright 2023 Google LLC | ||
* | ||
* 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 Google\Cloud\Spanner\Tests\Snippet; | ||
|
||
use Google\Cloud\Core\Testing\Snippet\SnippetTestCase; | ||
use Google\Cloud\Spanner\PgOid; | ||
|
||
/** | ||
* @group spanner | ||
*/ | ||
class PgOidTest extends SnippetTestCase | ||
{ | ||
public function testClass() | ||
{ | ||
$expected = new PgOid('123'); | ||
$snippet = $this->snippetFromClass(PgOid::class); | ||
$res = $snippet->invoke('pgOid'); | ||
|
||
$this->assertInstanceOf(PgOid::class, $res->returnVal()); | ||
$this->assertEquals($expected, $res->returnVal()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters