Repository navigation
Replies: 2 comments 2 replies
|
Just realised I can use the |
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? |
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Is there a way to have the executors injected in the
on_requesthandlers? Would be useful for session handling.All reactions