27 lines
738 B
Python
27 lines
738 B
Python
import pymongo
|
|
from motor.motor_asyncio import AsyncIOMotorDatabase
|
|
|
|
from crud.base import CRUDBase
|
|
from schemas import *
|
|
|
|
__all__ = 'data_auth',
|
|
|
|
|
|
class CRUDDataAuth(CRUDBase):
|
|
|
|
async def create(self, db: AsyncIOMotorDatabase, obj_in: DataAuthCreate, game):
|
|
data = obj_in.dict()
|
|
data['game'] = game
|
|
await self.update_one(db, data, {'$set': data}, upsert=True)
|
|
|
|
async def get_game_data_auth(self, db, game):
|
|
return await self.find_many(db, game=game)
|
|
|
|
async def create_index(self, db: AsyncIOMotorDatabase):
|
|
await db[self.coll_name].create_index(
|
|
[('game', pymongo.DESCENDING), ('name', pymongo.DESCENDING)],
|
|
unique=True)
|
|
|
|
|
|
data_auth = CRUDDataAuth('data_auth')
|