20 lines
561 B
Python
20 lines
561 B
Python
from bson import ObjectId
|
|
|
|
|
|
class CRUDBase:
|
|
def __init__(self, coll_name):
|
|
self.coll_name = coll_name
|
|
|
|
async def get(self, coll, id: ObjectId):
|
|
return await coll.find_one({'_id': id})
|
|
|
|
async def read_have(self, coll, user_id: str, **kwargs):
|
|
where = {'members': user_id}
|
|
where.update(kwargs)
|
|
cursor = coll.find(where)
|
|
return await cursor.to_list(length=999)
|
|
|
|
async def find_many(self, db, **kwargs):
|
|
cursor = db[self.coll_name].find(kwargs)
|
|
return await cursor.to_list(length=999)
|