MCPcopy
hub / github.com/spaceandtimefdn/SxT-Python-SDK / delete

Method delete

src/spaceandtime/sxtresource.py:1186–1212  ·  view source on GitHub ↗

-------------------- Deletes records from the table, with a required WHERE statement. Note, some tables in the space and time network are immutable and cannot be changed. Args: sql_text (str): If set, the sql_text is simply passed thru to the network directly a

(self, sql_text:str = None, where:str = '0=1', user:SXTUser = None, biscuits:list = None)

Source from the content-addressed store, hash-verified

1184
1185
1186 def delete(self, sql_text:str = None, where:str = '0=1', user:SXTUser = None, biscuits:list = None) -> tuple[bool, dict]:
1187 """--------------------
1188 Deletes records from the table, with a required WHERE statement.
1189
1190 Note, some tables in the space and time network are immutable and cannot be changed.
1191
1192 Args:
1193 sql_text (str): If set, the sql_text is simply passed thru to the network directly as a DML request.
1194 where (str): A WHERE statement to limit rows deleted. This defaults to a zero-delete statement, so must be overridden to execute a meaningful delete.
1195 user (SXTUser): User who will execute the request. Defaults to the default user.
1196 biscuits (list): List of biscuits required to authorize this request.
1197
1198 Returns:
1199 bool: Success flag, True if the data was fully inserted, False if any of the records failed.
1200 object: Row output of the SQL request, as dict, or if error, details returned from the request.
1201 """
1202 user = self.get_first_valid_user(user)
1203 if not biscuits: biscuits = list(self.biscuits)
1204 if biscuits == []:
1205 raise SxTArgumentError('A biscuit with DELETE permissions must be included.', logger=self.logger)
1206 if len(where) >0 and not str(where).strip().startswith('where'): where = f' WHERE {where} '
1207 if not sql_text: sql_text = f"DELETE FROM {self.table_name} {where}"
1208 self.logger.info(f'DELETING: {sql_text}')
1209 success, results = user.base_api.sql_dml(sql_text=sql_text, biscuits=biscuits, app_name=self.application_name, resources=[self.table_name])
1210 time.sleep(1)
1211 if not success: self.__lasterr__ = self.SXTExceptions.SxTQueryError(results)
1212 return success, results
1213
1214
1215

Callers 3

call_apiMethod · 0.80

Calls 3

SxTArgumentErrorClass · 0.90
get_first_valid_userMethod · 0.80
sql_dmlMethod · 0.80

Tested by 1