@@ -113,8 +113,10 @@ def get(self, key: Union[str, List[str]], default=None) -> Union[Any, List[Any]]
113113 return _return_maybe (_type , values )
114114
115115 def update (self , mapping : Union [dict , tuple ] = (), ** kwargs ) -> None :
116+ """Note that this method overrides database itself.
117+ """
116118 self ._update_timestamp ()
117- return self .data .update (mapping , ** kwargs )
119+ self .data .update (mapping , ** kwargs )
118120
119121 def modify (
120122 self ,
@@ -146,6 +148,13 @@ def modify(
146148 return _return_maybe (type_id , values )
147149
148150 def add (self , item : Union [Any , List [Any ]]) -> Union [str , List [str ]]:
151+ """
152+ Args:
153+ item (Union[Any, List[Any]]): Object(s) to add to database
154+
155+ Returns:
156+ Union[str, List[str]]: Automatically generated ID of added item
157+ """
149158 _type , _items = _from_maybe_list (item )
150159
151160 ids = []
@@ -157,27 +166,58 @@ def add(self, item: Union[Any, List[Any]]) -> Union[str, List[str]]:
157166 self ._update_timestamp ()
158167 return _return_maybe (_type , ids )
159168
160- def remove (self , key : Union [str , List [str ]]) -> Union [str , List [str ]]:
169+ def remove (self , key : Union [str , List [str ]]) -> Union [Any , List [Any ]]:
170+ """
171+ Args:
172+ key (Union[str, List[str]]): ID(s) to remove from database
173+
174+ Returns:
175+ Union[Any, List[Any]]: removed items
176+ """
161177 _type , _keys = _from_maybe_list (key )
162178 popped = [self .data .pop (key ) for key in _keys ]
163179 self ._update_timestamp ()
164180 return _return_maybe (_type , popped )
165181
166182 def all (self ) -> List [Any ]:
183+ """Provide all items in database.
184+
185+ Returns:
186+ List[Any]: All items as list
187+ """
167188 return list (self .data .values ())
168189
169190 def clear (self ) -> None :
191+ """Clear all items. This method updates timestamp in metadata.
192+ """
170193 self .data .clear ()
171194 self ._update_timestamp ()
172195
173196 def find (self , func : Callable [..., bool ]) -> List [str ]:
197+ """Returns array of IDs that satisfies the provided testing function.
198+
199+ Args:
200+ func (Callable[..., bool]):
201+ A function to execute for each items in database.
202+
203+ Returns:
204+ List[str]: array with id of found items
205+ """
174206 ids = []
175207 for id , value in self .data .items ():
176208 if func (value ):
177209 ids .append (id )
178210 return ids
179211
180212 def has (self , key : Union [str , List [str ]]) -> Union [bool , List [bool ]]:
213+ """performs to determine whether has key
214+
215+ Args:
216+ key (Union[str, List[str]]): to find with string(s) as key
217+
218+ Returns:
219+ Union[bool, List[bool]]: boolean or array of boolean.
220+ """
181221 _type , _keys = _from_maybe_list (key )
182222 key_set = set (self .data .keys ())
183223 values = [k in key_set for k in _keys ]
@@ -202,9 +242,13 @@ def drop(self) -> int:
202242 return del_count
203243
204244 def commit (self ) -> None :
245+ """Save its states and all items at that time.
246+ """
205247 self .__memory__ = copy .deepcopy (self .__dict__ )
206248
207249 def rollback (self ) -> None :
250+ """Restore all states and items from latest commit.
251+ """
208252 self .__dict__ = copy .deepcopy (self .__memory__ )
209253
210254 def load (
0 commit comments