40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
import pymongo
|
|
from motor.motor_asyncio import AsyncIOMotorDatabase
|
|
|
|
from core.config import settings
|
|
from crud.base import CRUDBase
|
|
from schemas import *
|
|
from utils import *
|
|
|
|
__all__ = 'authority',
|
|
|
|
|
|
class CRUDAuthority(CRUDBase):
|
|
|
|
async def create(self, db: AsyncIOMotorDatabase, *args, **kwargs):
|
|
data = dict()
|
|
if len(args) > 0:
|
|
data['ptype'] = args[0]
|
|
if len(args) > 1:
|
|
data['v0'] = args[1]
|
|
if len(args) > 2:
|
|
data['v1'] = args[2]
|
|
if len(args) > 3:
|
|
data['v2'] = args[3]
|
|
if len(args) > 4:
|
|
data['v3'] = args[4]
|
|
if len(args) > 5:
|
|
data['v4'] = args[5]
|
|
|
|
data.update(kwargs)
|
|
await self.update_one(db, data, {'$set': data}, upsert=True)
|
|
|
|
async def create_index(self, db: AsyncIOMotorDatabase):
|
|
await db[self.coll_name].create_index(
|
|
[('ptype', pymongo.DESCENDING), ('v0', pymongo.DESCENDING), ('v1', pymongo.DESCENDING),
|
|
('v2', pymongo.DESCENDING), ('v3', pymongo.DESCENDING)],
|
|
unique=True)
|
|
|
|
|
|
authority = CRUDAuthority(settings.CASBIN_COLL)
|