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

Method create

src/spaceandtime/sxtresource.py:409–438  ·  view source on GitHub ↗

-------------------- Issues the supplied (parameterized) CREATE statement to the Space and Time network, and report back success and details. Args: sql_text (str): Parameterized CREATE statement. If omitted, will use the resource.create_ddl class property. Both will re

(self, sql_text:str = None, user:SXTUser = None, biscuits:list = None)

Source from the content-addressed store, hash-verified

407
408
409 def create(self, sql_text:str = None, user:SXTUser = None, biscuits:list = None):
410 """--------------------
411 Issues the supplied (parameterized) CREATE statement to the Space and Time network, and report back success and details.
412
413 Args:
414 sql_text (str): Parameterized CREATE statement. If omitted, will use the resource.create_ddl class property. Both will replace {placeholders} with real values before submission.
415 user (SXTUser): Authenticated user who will issue the command. If omitted, will use the default user, resource.user
416 biscuits (list): List of biscuits to include with the request, either as string biscuit tokens or as SXTBiscuit objects. If omitted, will use the class.biscuits list. Must contain CREATE permissions.
417
418 Returns:
419 bool: Success flag, True if the object was created.
420 object: other details supplied during the request, including API messaging. Typically a dict.
421 """
422 user = self.get_first_valid_user(user)
423 if not sql_text:
424 if self.create_ddl_template == '':
425 raise SxTArgumentError('Must set the create_ddl before trying to create the table.', logger=self.logger)
426 sql_text = self.create_ddl
427 if self.private_key == '':
428 raise SxTArgumentError('Must create or set a keypair before trying to create the table. Try running new_keypair().', logger=self.logger)
429 if not biscuits: biscuits = self.biscuits if type(self.biscuits)==list else [self.biscuits]
430 if biscuits == []:
431 self.logger.warning('No biscuits found. While this may be OK, it can also cause errors.')
432 success, results = user.base_api.sql_ddl(sql_text=sql_text.strip(), biscuits=biscuits, app_name=self.application_name)
433 if success:
434 self.logger.info(f'{self.resource_type.name} Created: {self.resource_name}:\n{sql_text}')
435 else:
436 self.logger.error(f'{self.resource_type.name} FAILED TO CREATE with user {user.user_id}:\n{results}\n{sql_text}\n\nBiscuits: {biscuits}')
437 self.__lasterr__ = None if success else self.SXTExceptions.SxTQueryError(results)
438 return success, results
439
440
441 def drop(self, user:SXTUser = None, biscuits:list = None):

Callers 3

test_allFunction · 0.80

Calls 3

get_first_valid_userMethod · 0.95
SxTArgumentErrorClass · 0.90
sql_ddlMethod · 0.80

Tested by 2

test_allFunction · 0.64