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

Method select

src/spaceandtime/sxtresource.py:469–510  ·  view source on GitHub ↗

-------------------- Issues a SELECT statement to the Space and Time network, and report back success and rows (or failure details). This is intended as a convenience feature, to quickly verify data structures or recently loaded data. While it can run more sophisticated SQ

(self, sql_text:str = '', columns:list = ['*'], user:SXTUser = None, biscuits:list = None, row_limit:int = 50)

Source from the content-addressed store, hash-verified

467
468
469 def select(self, sql_text:str = '', columns:list = ['*'], user:SXTUser = None, biscuits:list = None, row_limit:int = 50) -> tuple[bool, dict]:
470 """--------------------
471 Issues a SELECT statement to the Space and Time network, and report back success and rows (or failure details).
472
473 This is intended as a convenience feature, to quickly verify data structures or recently loaded data. While it can
474 run more sophisticated SQL, it is recommended to use the SXTUser object for more flexibility.
475
476 Args:
477 sql_text (str): Sql text to execute. If omitted, will defaults to "SELECT [columns] FROM [resource_name] LIMIT [row_limit]".
478 columns (list): List of columns to build the SELECT statement. Defaults to "*". If sql_text is supplied, this is ignored.
479 user (SXTUser): Authenticated user who will issue the command. If omitted, will use the default user, resource.user
480 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.
481 row_limit (int): Limits the number of rows returned. If set to -1 or None, no row limit is applied. Default 50.
482
483 Returns:
484 bool: Success flag, True if the object was dropped.
485 object: Row output of the SQL request, in JSON format, or if error, details returned from the request.
486
487 Examples:
488 >>> suzy = SXTUser('.env', authenticate=True)
489 >>> ethblocks = SXTTable(name='ETHEREUM.Blocks', default_user=suzy)
490 >>> success, rows = ethblocks.select (columns = 'BLOCK_NUMBER', row_limit = 10)
491 >>> len( rows )
492 10
493 >>> len(rows[0].keys())
494 11
495 """
496 self.logger.info(f'{"-"*15}\nSELECTing {self.resource_type.name} {self.resource_name}...')
497 user = self.get_first_valid_user(user)
498 if not biscuits: biscuits = list(self.biscuits)
499 if biscuits == []:
500 self.logger.warning('No biscuits found. While this may be OK, it can also cause errors.')
501 row_limit = '' if row_limit < 0 or not row_limit else f'LIMIT {row_limit}'
502 if sql_text == '': sql_text = f"SELECT { ','.join( columns ) } FROM {self.resource_name} {row_limit}"
503 self.logger.info(f'{self.resource_type.name} Query Started: {self.resource_name}:\n{sql_text}')
504 success, results = user.base_api.sql_dql(sql_text=sql_text, biscuits=biscuits, resources=self.resource_name, app_name=self.application_name)
505 if success:
506 self.logger.info(f'{self.resource_type.name} {self.resource_name} Finished: {len(results)} Rows Returned')
507 else:
508 self.logger.error(f'{self.resource_type.name} QUERY FAILED with user {user.user_id}:\n{results}\n{sql_text}')
509 self.__lasterr__ = None if success else self.SXTExceptions.SxTQueryError(results)
510 return success, results
511
512
513 def clear_all(self) -> None:

Callers 3

test_allFunction · 0.80

Calls 2

get_first_valid_userMethod · 0.95
sql_dqlMethod · 0.80

Tested by 2

test_allFunction · 0.64