Skip to content
This repository was archived by the owner on Sep 2, 2024. It is now read-only.

added 2 db functions #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions staticbackend/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ def create_document(self, repo: str, data: Dict[str, Any]) -> Dict[str, Any]:
resp: Any = self._request(f"/db/{repo}", body=data)
return resp # type: ignore

def bulk_create_documents(
self, repo: str, data: List[Dict[str, Any]]
) -> Dict[str, Any]:
"""Create documents in bulk."""
resp: Any = self._request(f"/db/{repo}?bulk=1", body=data)
return resp # type: ignore

def list_documents(
self, repo: str, page: int = 1, size: int = 25, desc: bool = False
) -> DocumentResults:
Expand Down Expand Up @@ -62,3 +69,8 @@ def update_document(
def delete_document(self, repo: str, doc_id: str) -> int:
resp: Any = self._request(f"/db/{repo}/{doc_id}", method="delete")
return int(resp)

def increment(self, repo: str, doc_id: str, field: str, range: int) -> Any:
data = {"field": field, "range": range}
resp: Any = self._request(f"/inc/{repo}/{doc_id}", body=data)
return resp