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

UUID type hint #32

Merged
merged 2 commits into from
Oct 29, 2021
Merged
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
10 changes: 7 additions & 3 deletions aurora_data_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""
aurora-data-api - A Python DB-API 2.0 client for the AWS Aurora Serverless Data API
"""
import os, datetime, ipaddress, uuid, time, random, string, logging, itertools, reprlib
import os, datetime, ipaddress, time, random, string, logging, itertools, reprlib
from uuid import UUID
from decimal import Decimal
from collections import namedtuple
from .exceptions import (Warning, Error, InterfaceError, DatabaseError, DataError, OperationalError, IntegrityError,
Expand Down Expand Up @@ -116,7 +117,7 @@ class AuroraDataAPICursor:
"text": str,
"time": datetime.time,
"timestamp": datetime.datetime,
"uuid": uuid.uuid4,
"uuid": UUID,
"numeric": Decimal,
"decimal": Decimal
}
Expand All @@ -133,7 +134,8 @@ class AuroraDataAPICursor:
datetime.date: "DATE",
datetime.time: "TIME",
datetime.datetime: "TIMESTAMP",
Decimal: "DECIMAL"
Decimal: "DECIMAL",
UUID: "UUID"
}

def __init__(self, client=None, dbname=None, aurora_cluster_arn=None, secret_arn=None, transaction_id=None):
Expand Down Expand Up @@ -281,6 +283,8 @@ def _render_value(self, value, col_desc=None):
if col_desc and col_desc.type_code in self._data_api_type_hint_map:
if col_desc.type_code == Decimal:
scalar_value = Decimal(scalar_value)
elif col_desc.type_code == UUID:
scalar_value = UUID(scalar_value)
else:
try:
scalar_value = col_desc.type_code.fromisoformat(scalar_value)
Expand Down