-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepository.py
More file actions
44 lines (32 loc) · 1.1 KB
/
Copy pathrepository.py
File metadata and controls
44 lines (32 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from model import Book
from config import database
import uuid
class BookRepo():
@staticmethod
async def retrieve():
_book=[]
collection = database.get_collection('book').find()
async for book in collection:
_book.append(book)
return _book
@staticmethod
async def insert(book : Book):
id = str(uuid.uuid4())
_book= {
"id":id,
"title" : book.title,
"description" : book.description,
}
await database.get_collection('book').insert_one(_book)
@staticmethod
async def update(id:str,book : Book):
_book = await database.get_collection('book').find_one({"_id":id})
_book["title"] = book.title
_book["description"] = book.description
await database.get_collection("book").update_one({"_id":id,"$set":_book})
@staticmethod
async def retrieve_id(id:str):
return await database.get_collection('book').find_one({"_id":id})
@staticmethod
async def delete(id:str):
await database.delete_collection('book').delete_one({"_id":id})