Skip to content

Commit

Permalink
Support json column types (#28)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrey Kislyuk <[email protected]>
  • Loading branch information
joyofhex and kislyuk authored Oct 29, 2021
1 parent 3d8fdf8 commit c178800
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions aurora_data_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
aurora-data-api - A Python DB-API 2.0 client for the AWS Aurora Serverless Data API
"""
import os, datetime, ipaddress, time, random, string, logging, itertools, reprlib
import os, datetime, ipaddress, time, random, string, logging, itertools, reprlib, json
from uuid import UUID
from decimal import Decimal
from collections import namedtuple
Expand Down Expand Up @@ -113,7 +113,7 @@ class AuroraDataAPICursor:
"cidr": ipaddress.ip_network,
"date": datetime.date,
"inet": ipaddress.ip_address,
"json": dict, # TODO
"json": "json",
"jsonb": dict, # TODO
"money": str, # TODO
"text": str,
Expand All @@ -137,6 +137,7 @@ class AuroraDataAPICursor:
datetime.time: "TIME",
datetime.datetime: "TIMESTAMP",
Decimal: "DECIMAL",
"json": "JSON",
UUID: "UUID"
}

Expand Down Expand Up @@ -288,6 +289,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 == "json":
scalar_value = json.loads(scalar_value)
elif col_desc.type_code == UUID:
scalar_value = UUID(scalar_value)
else:
Expand Down

0 comments on commit c178800

Please sign in to comment.