MagicStack / MagicStack/asyncpg

Feature Request: Middleware

Aperta
#152 3 commenti 5 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

enhancement
Lingua principale
Python
Stelle
8.1k
Fork
468
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Leggi prima l’issue #128, poi esamina la creazione del pool e i metodi di connessione per determinare dove potrebbero essere registrati e invocati i middleware pre- e post-query. Confronta i casi d’uso della conversione di asyncpgsa e delle metriche, quindi definisci l’API, l’ambito, l’ordine, il comportamento async e i test necessari prima dell’implementazione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
postgresql, python
Ambito
backend, databases
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.