25 lines
761 B
Python
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__ = 'data_attr',
|
|
|
|
|
|
class CRUDDataAttr(CRUDBase):
|
|
|
|
async def edit_data_attr(self, db: AsyncIOMotorDatabase, game: str, data_id: schemas.DataAttrEdit):
|
|
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)
|
|
|
|
|
|
data_attr = CRUDDataAttr('data_attr')
|