31 lines
1.0 KiB
Python
31 lines
1.0 KiB
Python
from motor.motor_asyncio import AsyncIOMotorDatabase
|
|
|
|
import schemas
|
|
from crud.base import CRUDBase
|
|
|
|
__all__ = 'select_map',
|
|
|
|
|
|
class CRUDSelectMap(CRUDBase):
|
|
async def save(self, db: AsyncIOMotorDatabase, data_in: schemas.SelectMap):
|
|
where = {'attr_name': data_in.attr_name, 'game': data_in.game}
|
|
return await self.update_one(db, where, {'$set': data_in.dict(skip_defaults=True)}, upsert=True)
|
|
|
|
# async def read(self, db: AsyncIOMotorDatabase, data_in: schemas.SelectMap):
|
|
# where = data_in.dict(skip_defaults=True)
|
|
# res = await self.find_many(db, where)
|
|
# return res
|
|
#
|
|
async def get_list(self, db: AsyncIOMotorDatabase, game: str):
|
|
where = {'game': game}
|
|
res = await self.find_many(db, where, {'_id': 0})
|
|
return res
|
|
|
|
async def get_select(self, db: AsyncIOMotorDatabase, data_in: schemas.SelectAttr, game: str):
|
|
where = {'game': game, **data_in.dict()}
|
|
res = await self.find_one(db, where, {'_id': 0})
|
|
return res
|
|
|
|
|
|
select_map = CRUDSelectMap('select_map')
|