11import json
22from typing import Mapping , List
33
4- from .document import Document
4+ from .document import Document , JsonArray
55from .fileio import FileIO
66
77
@@ -75,7 +75,7 @@ def insert(self, document: Mapping) -> str:
7575 else :
7676 raise ValueError (f"Document id `{ _document .id } ` is already exists" )
7777
78- def insert_all (self , document_list : List [Mapping ]) -> List [str ]:
78+ def insert_all (self , document_list : List [Mapping ]) -> JsonArray [str ]:
7979 """
8080 Inserts a single ``Document`` into the ``Database``.
8181
@@ -97,7 +97,7 @@ def insert_all(self, document_list: List[Mapping]) -> List[str]:
9797 # insert every single document in Database & increment ``doc_count``.
9898 _doc_id .append (self .insert (document ))
9999
100- return _doc_id
100+ return JsonArray ( _doc_id )
101101
102102 def __find_one (self , query : Mapping = None ) -> Document | None : # Not works, right nom
103103 """
@@ -132,7 +132,7 @@ def __find_one(self, query: Mapping = None) -> Document | None: # Not wo
132132
133133 return _result
134134
135- def find (self , query = None , limit = None ) -> List [Document ]:
135+ def find (self , query = None , limit = None ) -> JsonArray [Document ]:
136136 """
137137 Finds all ``Document`` of ``Collection``.
138138
@@ -188,7 +188,7 @@ def find(self, query=None, limit=None) -> List[Document]:
188188 else :
189189 _result = self ._collection
190190
191- return _result
191+ return JsonArray ( _result )
192192
193193 elif query is not None and type (query ) == type ({}):
194194 if limit :
@@ -224,9 +224,9 @@ def find(self, query=None, limit=None) -> List[Document]:
224224
225225 self ._reset_cursor ()
226226
227- return _result
227+ return JsonArray ( _result )
228228
229- def delete (self , query = None ) -> List [str ]:
229+ def delete (self , query = None ) -> JsonArray [str ]:
230230 """
231231 Delete single or multiple Document when meet the Conditions or ``query``.
232232
@@ -249,9 +249,9 @@ def delete(self, query=None) -> List[str]:
249249
250250 self ._file_handler .write (self ._database )
251251
252- return _doc_id
252+ return JsonArray ( _doc_id )
253253
254- def update (self , document : Mapping , query = None ) -> List [str ]:
254+ def update (self , document : Mapping , query = None ) -> JsonArray [str ]:
255255 """
256256 Fetch all the Documents mathc the conditions and update them.
257257
@@ -285,7 +285,7 @@ def update(self, document: Mapping, query=None) -> List[str]:
285285 # Write current state of Database
286286 self ._file_handler .write (self ._database )
287287
288- return _doc_id
288+ return JsonArray ( _doc_id )
289289
290290 def count (self , query = None , limit : tuple = None ) -> int :
291291 """
@@ -315,7 +315,7 @@ def _reset_cursor(self) -> None:
315315 """
316316 self ._cursor = 0
317317
318- def _find_document_by_query (self , query : Mapping ) -> List :
318+ def _find_document_by_query (self , query : Mapping ) -> JsonArray [ Document ] :
319319 """
320320 Finds a single ``Document`` of ``Collection``.
321321
@@ -379,20 +379,6 @@ def _find_document_by_query(self, query: Mapping) -> List:
379379 else :
380380 return None
381381
382- return result
383-
384- # ======================== #
385- def _doc_is_exists (self , doc_id : str ) -> bool :
386- # Iterate over all Documents of Collection
387- for doc in self ._collection :
388- if doc ["_id_" ] == doc_id :
389- return True
382+ return JsonArray (result )
390383
391- return False
392384
393- def _find_document_by_id (self , doc_id ) -> Document :
394- for doc in self ._collection :
395- if doc ["_id_" ] == doc_id :
396- return doc
397- else :
398- return None
0 commit comments