mirror of
https://github.com/maubot/maubot.git
synced 2024-10-01 01:06:10 -04:00
Fix exploring datetime columns
This commit is contained in:
parent
4cc605df76
commit
88107daa6f
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user