Skip to content

Commit

Permalink
feat: add support for PG.OID in parameterized queries (#1035)
Browse files Browse the repository at this point in the history
* feat: add support for PG.OID in parameterized queries

* test: add tests for PG.OID bindings

* test: add test to check that the PG.OID param type is correct

* lint: fix lint

* test: correct new test name

---------

Co-authored-by: larkee <larkee@users.noreply.github.com>
  • Loading branch information
larkee and larkee committed Apr 8, 2024
1 parent 4da06a6 commit ea5efe4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions google/cloud/spanner_v1/param_types.py
Expand Up @@ -33,6 +33,7 @@
JSON = Type(code=TypeCode.JSON)
PG_NUMERIC = Type(code=TypeCode.NUMERIC, type_annotation=TypeAnnotationCode.PG_NUMERIC)
PG_JSONB = Type(code=TypeCode.JSON, type_annotation=TypeAnnotationCode.PG_JSONB)
PG_OID = Type(code=TypeCode.INT64, type_annotation=TypeAnnotationCode.PG_OID)


def Array(element_type):
Expand Down
12 changes: 12 additions & 0 deletions tests/system/test_session_api.py
Expand Up @@ -2348,6 +2348,18 @@ def test_execute_sql_w_jsonb_bindings(
)


def test_execute_sql_w_oid_bindings(
not_emulator, not_google_standard_sql, sessions_database, database_dialect
):
_bind_test_helper(
sessions_database,
database_dialect,
spanner_v1.param_types.PG_OID,
123,
[123, 456],
)


def test_execute_sql_w_query_param_struct(sessions_database, not_postgres):
name = "Phred"
count = 123
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/test_param_types.py
Expand Up @@ -70,3 +70,20 @@ def test_it(self):
found = param_types.PG_JSONB

self.assertEqual(found, expected)


class Test_OidParamType(unittest.TestCase):
def test_it(self):
from google.cloud.spanner_v1 import Type
from google.cloud.spanner_v1 import TypeCode
from google.cloud.spanner_v1 import TypeAnnotationCode
from google.cloud.spanner_v1 import param_types

expected = Type(
code=TypeCode.INT64,
type_annotation=TypeAnnotationCode.PG_OID,
)

found = param_types.PG_OID

self.assertEqual(found, expected)

0 comments on commit ea5efe4

Please sign in to comment.