Fix exploring datetime columns

This commit is contained in:
Tulir Asokan 2018-12-28 19:31:43 +02:00
parent 4cc605df76
commit 88107daa6f

View File

@ -14,6 +14,7 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from datetime import datetime
from aiohttp import web from aiohttp import web
from sqlalchemy import Table, Column, asc, desc 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}") @routes.get("/instance/{id}/database/{table}")
async def get_table(request: web.Request) -> web.Response: async def get_table(request: web.Request) -> web.Response:
instance_id = request.match_info.get("id", "") instance_id = request.match_info.get("id", "")
@ -73,5 +80,5 @@ async def get_table(request: web.Request) -> web.Response:
order = [] order = []
limit = int(request.query.get("limit", 100)) limit = int(request.query.get("limit", 100))
query = table.select().order_by(*order).limit(limit) 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) return web.json_response(data)