You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am working on odmantic quart extension and I have tried to wrap the AIOEngine like Quart-Motor does with the MotorDatabase. For example of what I am talking about. Here is an example.
from odmantic import AIOEngine as _AIOEngine, Model
from motor import motor_asyncio
from quart import abort
class AIOEngine(_AIOEngine):
"""
Wrapper for :class:`~AIOEngine`.
"""
async def find_one_or_404(self, model: Model, *args, **kwargs):
"""
Find a single document or raise a 404.
This is like :meth:`~AIOEngine.find_one`, but rather than returning
``None``, cause a 404 Not Found HTTP status on the request.
.. code-block:: python
@app.route("/user/<username>")
async def user_profile(username):
user = await odmantic.db..find_one_or_404(model, {"_id": username})
return await render_template("user.html",
user=user)
"""
found = await self.find_one(model, *args, **kwargs)
if found is None:
return abort(404)
return found
class AIOMotorClient(motor_asyncio.AsyncIOMotorClient):
"""Wrapper for :class:`AsyncIOMotorClient.MongoClient`.
Returns instances of Quart-Motor
:class:`~quart_motor.wrappers.Database` instead of native motor
:class:`~AsyncIOMotorDatabase` when accessed with dot notation.
"""
def __getitem__(self, name) -> AIOEngine:
"""__getitem__."""
return AIOEngine(self, name)
This would be used as follows:
client = AIOMotorClient(*args, **kwargs)
db = AIOMotorClient['someDatabase']
When I try to do this I get all sort of errors. Does anyone know why that is?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am working on odmantic quart extension and I have tried to wrap the AIOEngine like Quart-Motor does with the MotorDatabase. For example of what I am talking about. Here is an example.
This would be used as follows:
When I try to do this I get all sort of errors. Does anyone know why that is?
Thank you in advance,
Chris
Beta Was this translation helpful? Give feedback.
All reactions