-
-
Notifications
You must be signed in to change notification settings - Fork 105
Database
Adek edited this page Dec 3, 2021
·
5 revisions
~Anjani
uses our own implementation of MongoDB to fit our need of asynchronous methods and annotation.
It's almost the same like Motor but some methods were built different and removed.
Get collection from the database.
Parameters:
-
name (
str
) - Collection name to fetch.
from typing import Any, MutableMapping
from anjani import command, plugin
class ExampleDB(plugin.Plugin):
name = "Example DB"
# It's recomended to load DataBase on on_load
# this method executed when the plugin is loaded
async def on_load(self) -> None:
self.db_collection = self.bot.get_collection("<COLLECTION_NAME>")
async def get_data(self, key: str, value: Any) -> MutableMapping[str, Any]:
return await self.db_collection.find_one({key: value})
async def cmd_fetchdb(self, ctx: command.Context) -> str:
data = await self.get_data("chat_id", ctx.chat.id)
self.log.info(data)
return "Fetched database complete"
Wiki of Anjani © Copyright 2021, UserBotIndo