xbackend/crud/select_map.py
2022-11-11 10:37:46 +08:00

37 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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')