From 253970094b5ffa2ac18dbd9c6aff3436a475ecf0 Mon Sep 17 00:00:00 2001 From: SouthFox Date: Mon, 11 Mar 2024 22:35:32 +0800 Subject: [PATCH] [feat] add select ap_type command --- app/hysql.hy | 12 ++++++++++++ tasks.py | 23 +++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 app/hysql.hy diff --git a/app/hysql.hy b/app/hysql.hy new file mode 100644 index 0000000..e618faa --- /dev/null +++ b/app/hysql.hy @@ -0,0 +1,12 @@ +#!/usr/bin/env hy +(import app [models]) +(import app.database [async_session]) +(import sqlalchemy [select]) +(import pprint [pprint]) + + +(defn/a selete_object + [db ap_type] + (.all (await (.scalars db + (.where (select models.InboxObject) + (= models.InboxObject.ap_type ap_type)))))) diff --git a/tasks.py b/tasks.py index 4890458..7b31d34 100644 --- a/tasks.py +++ b/tasks.py @@ -202,3 +202,26 @@ def send_note(ctx): print("Done!") asyncio.run(_dodo()) + + +@task +def get_object(ctx, ap_type): + import hy + from app.database import async_session + from app.hysql import selete_object + from pprint import pprint + + async def _dodo(): + async with async_session() as db_session: #type: ignore + + return await selete_object( + db_session, + ap_type + ) + + res = asyncio.run(_dodo()) + for ap_object in res: + print("=====") + print(ap_object.id ) + print(ap_object.ap_id) + pprint(ap_object.ap_object)