From c178800baf9e8372ef1f13cf911cf99d0ede4b8e Mon Sep 17 00:00:00 2001 From: David Bruce Date: Fri, 29 Oct 2021 22:46:01 +0200 Subject: [PATCH] Support json column types (#28) Co-authored-by: Andrey Kislyuk --- aurora_data_api/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/aurora_data_api/__init__.py b/aurora_data_api/__init__.py index 25c2b52..93cb958 100644 --- a/aurora_data_api/__init__.py +++ b/aurora_data_api/__init__.py @@ -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 @@ -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, @@ -137,6 +137,7 @@ class AuroraDataAPICursor: datetime.time: "TIME", datetime.datetime: "TIMESTAMP", Decimal: "DECIMAL", + "json": "JSON", UUID: "UUID" } @@ -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: