37 lines
1.3 KiB
Python
37 lines
1.3 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
|
||
# 查找一条数据,不返回_id
|
||
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
|
||
|
||
async def get_one(self, db: AsyncIOMotorDatabase, game: str, screen: str):
|
||
where = {'game': game, 'attr_name': screen}
|
||
res = await self.find_one(db, where, {'_id': 0})
|
||
return res.get('map_')
|
||
|
||
|
||
select_map = CRUDSelectMap('select_map')
|