Replies: 2 comments 2 replies
-
Just realised I can use the |
Beta Was this translation helpful? Give feedback.
0 replies
-
You should be able to access them as injectables: from typing import List
from dataclasses import asdict
from sanic import Sanic, Request, json
from sanic_ext import Extend
from mayim import Mayim
from mayim.executor import Executor
from mayim.extensions import SanicMayimExtension
class CityExecutor(Executor):
async def select_all_cities(
self, limit: int = 4, offset: int = 0
) -> List[City]:
...
app = Sanic(__name__)
Extend.register(
SanicMayimExtension(
executors=[CityExecutor], dsn="postgres://..."
)
)
@app.get("/")
async def handler(request: Request, executor: CityExecutor):
cities = await executor.select_all_cities()
return json({"cities": [asdict(city) for city in cities]}) Is this what you meant? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is there a way to have the executors injected in the
on_request
handlers? Would be useful for session handling.Beta Was this translation helpful? Give feedback.
All reactions