@@ -218,30 +218,60 @@ def call(self, func_name, *args, **kwargs):
218218 default_type = default_type )
219219 return response
220220
221+ def _insert (self , space_name , values , flags ):
222+ assert isinstance (values , tuple )
223+ assert (flags & (BOX_RETURN_TUPLE | BOX_ADD | BOX_REPLACE )) == flags
221224
222- def insert (self , space_name , values , return_tuple = False , not_presented = False , presented = False ):
223- '''\
224- Execute INSERT request.
225- Insert single record into a space `space_name`.
225+ request = RequestInsert (self , space_name , values , flags )
226+ return self ._send_request (request , space_name )
227+
228+ def replace (self , space_name , values , return_tuple ):
229+ '''
230+ Execute REPLACE request.
231+ It will throw error if there's no tuple with this PK exists
226232
227233 :param int space_name: space id to insert a record
228234 :type space_name: int or str
229235 :param values: record to be inserted. The tuple must contain only scalar (integer or strings) values
230236 :type values: tuple
237+ :param return_tuple: True indicates that it is required to return the inserted tuple back
238+ :type return_tuple: bool
231239
240+ :rtype: `Response` instance
241+ '''
242+ self ._insert (space_name , values , (BOX_REPLACE_TUPLE if return_tuple else 0 ) | BOX_REPLACE )
243+
244+ def store (self , space_name , values , return_tuple ):
245+ '''
246+ Execute STORE request.
247+ It will overwrite tuple with the same PK, if it exists, or inserts if not
248+
249+ :param int space_name: space id to insert a record
250+ :type space_name: int or str
251+ :param values: record to be inserted. The tuple must contain only scalar (integer or strings) values
252+ :type values: tuple
232253 :param return_tuple: True indicates that it is required to return the inserted tuple back
233254 :type return_tuple: bool
234- :param not_presented: True indicates that there's must be no tuple with same primary key
235- :type not_presented: bool
236- :param presented: True indicates that there's must be tuple with same primary key
237- :type presented: bool
238-
255+
239256 :rtype: `Response` instance
240257 '''
241- assert isinstance ( values , tuple )
258+ self . _insert ( space_name , values , ( BOX_REPLACE_TUPLE if return_tuple else 0 ))
242259
243- request = RequestInsert (self , space_name , values , return_tuple , not_presented , presented )
244- return self ._send_request (request , space_name )
260+ def insert (self , space_name , values , return_tuple ):
261+ '''
262+ Execute INSERT request.
263+ It will throw error if there's tuple with same PK exists.
264+
265+ :param int space_name: space id to insert a record
266+ :type space_name: int or str
267+ :param values: record to be inserted. The tuple must contain only scalar (integer or strings) values
268+ :type values: tuple
269+ :param return_tuple: True indicates that it is required to return the inserted tuple back
270+ :type return_tuple: bool
271+
272+ :rtype: `Response` instance
273+ '''
274+ self ._insert (space_name , values , (BOX_REPLACE_TUPLE if return_tuple else 0 ) | BOX_ADD )
245275
246276
247277 def delete (self , space_name , key , return_tuple = False ):
0 commit comments