@@ -22,13 +22,11 @@ def __init__(self, col_name: str, file_handler: FileIO) -> None:
2222 self ._database = self ._get_database ()
2323
2424 # Initiating Collecting
25- self ._collection = self ._get_collection ()
25+ self ._collection : JsonArray = self ._get_collection ()
2626
2727 # Cursor
2828 self ._cursor : int = 0
2929
30-
31-
3230 def insert (self , document : Mapping ) -> str :
3331 """
3432 Inserts a single Document into the Database.
@@ -47,18 +45,17 @@ def insert(self, document: Mapping) -> str:
4745 if "_id_" in document .keys ():
4846 raise KeyError (f"You are not allowed to modify key `_id_`" )
4947
50-
5148 # getting Database
5249 _database = self ._get_database ()
5350
5451 # Create a Document
5552 _document = Document (document )
5653
5754 # ID of Document
58- _doc_id : str = _document .id
55+ _doc_id : str = str ( _document .id )
5956
6057 # check Document is already exist or not
61- if not self ._doc_is_exists (_document .id ):
58+ if not self ._doc_is_exists (str ( _document .id ) ):
6259
6360 # Append the document into the Collection
6461 self ._collection .append (_document )
@@ -74,7 +71,7 @@ def insert(self, document: Mapping) -> str:
7471 else :
7572 raise ValueError (f"Document id `{ _document .id } ` is already exists" )
7673
77- def insert_all (self , document_list : List [Mapping ]) -> JsonArray [ str ] :
74+ def insert_all (self , document_list : List [Mapping ]) -> JsonArray :
7875 """
7976 Inserts a single ``Document`` into the ``Database``.
8077
@@ -98,7 +95,7 @@ def insert_all(self, document_list: List[Mapping]) -> JsonArray[str]:
9895
9996 return JsonArray (_doc_id )
10097
101- def find (self , query = None , limit = None ) -> JsonArray [ Document ] :
98+ def find (self , query = None , limit = None ) -> JsonArray :
10299 """
103100 Finds all ``Document`` of ``Collection``.
104101
@@ -125,7 +122,7 @@ def find(self, query=None, limit=None) -> JsonArray[Document]:
125122 raise ValueError ('Document is not a Tuple' )
126123
127124 # if limit, Check everything ok
128- _limit_start = _limit_end = None
125+ _limit_start = _limit_end = 0
129126
130127 if limit and type (limit ) == type ((1 , 3 )):
131128 if len (limit ) == 2 :
@@ -192,7 +189,7 @@ def find(self, query=None, limit=None) -> JsonArray[Document]:
192189
193190 return JsonArray (_result )
194191
195- def delete (self , query = None ) -> JsonArray [ str ] :
192+ def delete (self , query = None ) -> JsonArray :
196193 """
197194 Delete single or multiple Document when meet the Conditions or ``query``.
198195
@@ -217,7 +214,7 @@ def delete(self, query=None) -> JsonArray[str]:
217214
218215 return JsonArray (_doc_id )
219216
220- def update (self , document : Mapping , query = None ) -> JsonArray [ str ] :
217+ def update (self , document : Mapping , query = None ) -> JsonArray :
221218 """
222219 Fetch all the Documents mathc the conditions and update them.
223220
@@ -267,7 +264,6 @@ def rename(self, new_name: str) -> int:
267264
268265 # Checking the collection is already exist or not
269266 if new_name not in self ._database .keys ():
270-
271267 # Creating new collection and
272268 # Putting old data into new collection
273269 self ._database [new_name ] = self ._collection
@@ -309,7 +305,6 @@ def drop(self) -> int:
309305
310306 return count
311307
312-
313308 # ----------------------------------------------------------------#
314309 def _get_database (self ) -> Document :
315310 """
@@ -338,10 +333,9 @@ def _get_collection(self) -> JsonArray:
338333 else :
339334 # Create new Collection
340335 self ._database [self ._col_name ] = JsonArray ([])
341- _collection : JsonArray = self ._database [self ._col_name ]
342-
343- return _collection
336+ _collection = self ._database [self ._col_name ]
344337
338+ return JsonArray (_collection )
345339
346340 def _reset_cursor (self ) -> None :
347341 """
@@ -350,7 +344,7 @@ def _reset_cursor(self) -> None:
350344 """
351345 self ._cursor = 0
352346
353- def _find_document_by_query (self , query : Mapping ) -> JsonArray [ Document ] :
347+ def _find_document_by_query (self , query : Mapping ) -> JsonArray | None :
354348 """
355349 Finds a single ``Document`` of ``Collection``.
356350
@@ -423,5 +417,3 @@ def _doc_is_exists(self, doc_id: str) -> bool:
423417 return True
424418
425419 return False
426-
427-
0 commit comments