From 88107daa6f3c8dd64b2b0f376b3c8bcf5718733b Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 28 Dec 2018 19:31:43 +0200 Subject: [PATCH] Fix exploring datetime columns --- maubot/management/api/instance_database.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/maubot/management/api/instance_database.py b/maubot/management/api/instance_database.py index 767b465..9830728 100644 --- a/maubot/management/api/instance_database.py +++ b/maubot/management/api/instance_database.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . from typing import TYPE_CHECKING +from datetime import datetime from aiohttp import web from sqlalchemy import Table, Column, asc, desc @@ -50,6 +51,12 @@ async def get_database(request: web.Request) -> web.Response: }) +def check_type(val): + if isinstance(val, datetime): + return val.isoformat() + return val + + @routes.get("/instance/{id}/database/{table}") async def get_table(request: web.Request) -> web.Response: instance_id = request.match_info.get("id", "") @@ -73,5 +80,5 @@ async def get_table(request: web.Request) -> web.Response: order = [] limit = int(request.query.get("limit", 100)) query = table.select().order_by(*order).limit(limit) - data = [[*row] for row in db.execute(query)] + data = [[check_type(value) for value in row] for row in db.execute(query)] return web.json_response(data)