Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for PG.OID in parameterized queries #1035

Merged
merged 5 commits into from Apr 8, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)