MagicStack / MagicStack/asyncpg
Feature Request: Middleware
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 8.1k
- 分支
- 468
- PR 合併指標
- 30 天內沒有已合併 PR
描述
As discussed in #128, it might be a cool idea to have a "middleware" layer in asyncpg where people can register their own code to be ran pre or post query.
One usecase is asyncpgsa, which is a project to allow sqlalchemy objects to be passed to asyncpg connection methods. If there was a middleware layer, asyncpgsa could simply be a middleware that would run right before asyncpg prepared the query to convert the sqlalchemy object into a string. This would make asyncpgsa stupid simple, and just be a conversion layer, allowing it to get out of the way, and let asyncpg be the source of truth for everything else.
Another use case is metrics. My org is starting to track metrics per endpoint and per database query. If asyncpg had middleware support, we could simply inject a middleware that tracked the query and the time it took, and send that information into our metric platform. This could be done today by wrapping asyncpg and adding a method around it that tracks the metrics. It would be amazing if instead asyncpg could be used directly, and the middleware handles that portion for me.
Middlewares could potentially be "added" when the pool is created. (they can only exist on a pool maybe?)
Anyways, I am happy to try to implement this if you would like, but first wanted to get a general discussion going on the topic.
貢獻指南
這個儲存庫沒有索引到貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
先閱讀 issue #128,接著檢查 pool 建立與連線方法,以判斷可以在哪裡註冊和呼叫 pre- 與 post-query middleware。比較 asyncpgsa 轉換與 metrics 的使用情境,並在實作之前定義所需的 API、範圍、順序、async 行為與測試。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- postgresql, python
- 領域
- backend, databases
- Issue 類型
- 功能
- 難度
- 5/5
- 預估耗時
- 一週以上
- 活躍度
- 停滯
- 描述清晰度
- 需要釐清
- 新手友好度
- 25/100