xbackend/crud/crud_event_map.py
2021-06-01 09:49:03 +08:00

25 lines
761 B
Python

import pymongo
from bson import ObjectId
from motor.motor_asyncio import AsyncIOMotorDatabase
import schemas
from crud.base import CRUDBase
from schemas import *
__all__ = 'event_map',
class CRUDEventMap(CRUDBase):
async def edit_data_attr(self, db: AsyncIOMotorDatabase, game: str, data_id: schemas.EventMapEdit):
await self.update_one(db, {'game': game, 'cat': data_id.cat, 'name': data_id.name}, {'$set': data_id.dict()},
upsert=True)
async def create_index(self, db: AsyncIOMotorDatabase):
await db[self.coll_name].create_index(
[('game', pymongo.DESCENDING), ('cat', pymongo.DESCENDING), ('name', pymongo.DESCENDING)],
unique=True)
event_map = CRUDEventMap('event_map')