Skip to content

Commit ea5efe4

Browse files
authored
feat: add support for PG.OID in parameterized queries (#1035)
* 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 <[email protected]>
1 parent 4da06a6 commit ea5efe4

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

google/cloud/spanner_v1/param_types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
JSON = Type(code=TypeCode.JSON)
3434
PG_NUMERIC = Type(code=TypeCode.NUMERIC, type_annotation=TypeAnnotationCode.PG_NUMERIC)
3535
PG_JSONB = Type(code=TypeCode.JSON, type_annotation=TypeAnnotationCode.PG_JSONB)
36+
PG_OID = Type(code=TypeCode.INT64, type_annotation=TypeAnnotationCode.PG_OID)
3637

3738

3839
def Array(element_type):

tests/system/test_session_api.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2348,6 +2348,18 @@ def test_execute_sql_w_jsonb_bindings(
23482348
)
23492349

23502350

2351+
def test_execute_sql_w_oid_bindings(
2352+
not_emulator, not_google_standard_sql, sessions_database, database_dialect
2353+
):
2354+
_bind_test_helper(
2355+
sessions_database,
2356+
database_dialect,
2357+
spanner_v1.param_types.PG_OID,
2358+
123,
2359+
[123, 456],
2360+
)
2361+
2362+
23512363
def test_execute_sql_w_query_param_struct(sessions_database, not_postgres):
23522364
name = "Phred"
23532365
count = 123

tests/unit/test_param_types.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,20 @@ def test_it(self):
7070
found = param_types.PG_JSONB
7171

7272
self.assertEqual(found, expected)
73+
74+
75+
class Test_OidParamType(unittest.TestCase):
76+
def test_it(self):
77+
from google.cloud.spanner_v1 import Type
78+
from google.cloud.spanner_v1 import TypeCode
79+
from google.cloud.spanner_v1 import TypeAnnotationCode
80+
from google.cloud.spanner_v1 import param_types
81+
82+
expected = Type(
83+
code=TypeCode.INT64,
84+
type_annotation=TypeAnnotationCode.PG_OID,
85+
)
86+
87+
found = param_types.PG_OID
88+
89+
self.assertEqual(found, expected)

0 commit comments

Comments
 (0)