Query API

Describes how to access the results from a query.

class tgdb.query.TGQuery

Used for parameterized queries.

abstract close()

Close the query and clean up the compiled query on the server side.

Returns

Nothing

Return type

None

abstract execute()tgdb.query.TGResultSet

Execute this query with the current parameter list.

Returns

The results from executing this query with the given parameters.

Return type

tgdb.query.TGResultSet

abstract property option

Gets the query options for this query.

Returns

The options for this query.

Return type

tgdb.query.TGQueryOption

class tgdb.query.TGQueryCommand(value)

The query commands that the server recognizes.

classmethod fromId(id: int)

Converts a query command identifier into a query execution type.

Parameters

id (int) – An integer identifier to get the query command.

Returns

The query command.

Return type

tgdb.query.TGQueryCommand

class tgdb.query.TGQueryErrorStatus(value)

This class converts a query result from an integer to the meaning behind it.

property errorMsg

The message for the user.

Returns

The error message.

Return type

str

classmethod fromId(id: int)

Converts an integer identifier to a TGQueryErrorStatus.

Parameters

id (int) – The integer identifier that the server has for a given result.

Returns

The error status in a more readable and supportable manner.

Return type

tgdb.query.TGQueryErrorStatus

property result

The integer representation of the query result. Must correspond to a result on the server.

Returns

The result.

Return type

int

exception tgdb.query.TGQueryException(result: int, msg: Optional[str])

Represents an exception occurring in the execution of a query.

property errStatus

Gets the error status.

Returns

The error status

Return type

tgdb.query.TGQueryErrorStatus

class tgdb.query.TGQueryOption(*args, **kwds)

Stores information about the query.

prefetchsize
Type

int

traversalDepth
Type

int

edgeLimit
Type

int

queryExpr
Type

str

edgeExpr
Type

str

sortAttrName: str
The attribute to sort the results (only used when usign TGQL, not Gremlin).
sortOrderDesc: bool
Whether to sort on the attribute descending or ascending, with True for sort descending and False for ascending (only used when usign TGQL, not Gremlin).
sortResultLimit: int
The maximum number of objects to return in the result (only used when usign TGQL, not Gremlin).
property batchSize
Returns

Whether the sort should be descending.

Return type

int

property edgeExpr

Gets the expression to traverse an edge to another node (only used when usign TGQL, not Gremlin).

Returns

The expression to traverse an edge to another node (only used when usign TGQL, not Gremlin).

Return type

str

property edgeLimit

Represents the maximum number of edges for the server to respond with (only used when using TGQL, not Gremlin).

Returns

The maximum number of edges from the server.

Return type

int

property endExpr
Returns

Whether the sort should be descending.

Return type

int

property prefetchSize

Represents the maximum number of objects to fetch during a single request/response to the server.

Returns

The number of bytes to prefetch.

Return type

int

property queryExpr

Gets the query string.

Returns

The query string.

Return type

str

property sortAttrName
Returns

Whether the sort should be descending.

Return type

int

property sortOrderDesc
Returns

Whether the sort should be descending.

Return type

int

property sortResultLimit
Returns

The sort result limit.

Return type

int

property traversalDepth

Represents the maximum depth of recursion for the query (only used when using TGQL, not Gremlin).

Returns

Maximum traversal depth

Return type

int

property traverseExpr
Returns

Whether the sort should be descending.

Return type

int

writeExternal(os: tgdb.pdu.TGOutputStream, writeSort: bool = False, writeQueryStr: bool = False)

Handles communicating the query options with the server.

Parameters
  • os – The stream to write this to.

  • writeSort – Whether to write the sort information.

  • writeQueryStr – Whether to write the query string options.

class tgdb.query.TGQueryResultDataType(value)

Data type used to describe the metadata of the resulting type of a gremlin query.

classmethod getTypeForChar(char: str)

Converts a character into the appropriate query result data type.

Parameters

char (str) – A single character.

Returns

The query result data type.

Return type

tgdb.query.TGQueryResultDataType

class tgdb.query.TGResultDataDescriptor

The resulting set’s data descriptor.

abstract property attributeType

Gets the attribute type (if this descriptor has type attribute).

Returns

The attribute type.

Return type

tgdb.model.TGAttributeType

abstract property containedDataSize

Gets the number of descriptors in this descriptor (should only not be None when this is of type list or path).

Returns

The number of data types that are sub-types.

Return type

int

abstract property containedDescriptors

Gets the descriptors contained by this descriptor. Should only be defined when this is of type list or path.

Returns

The contained descriptors.

Return type

typing.List[tgdb.query.TGResultDataDescriptor]

abstract property dataType

Gets the data type for this data descriptor.

Returns

The result data type.

Return type

tgdb.query.TGQueryResultDataType

abstract property hasConcreteType

Whether this attribute has a concrete type (should be False if this is a composite type, like a list or a map).

Returns

Whether this descriptor represents a concrete type.

Return type

bool

abstract property isArray

Whether this descriptor represents an array.

Returns

Whether this descriptor represents an array.

Return type

bool

abstract property isMap

Whether this descriptor represents a map.

Returns

Whether this descriptor represents a map.

Return type

bool

abstract property keyDescriptor

Gets the descriptor used as the key for this descriptor. Should only be defined when this corresponds to a map.

Returns

The descriptor for the key.

Return type

tgdb.query.TGResultDataDescriptor

abstract property sysobj

The corresponding system object (if this is of type object).

Returns

The corresponding system object.

Return type

tgdb.model.TGSystemObject

abstract property valueDescriptor

Gets the descriptor used as the value for this descriptor. Should only be defined when this corresponds to a map.

Returns

The descriptor for the value.

Return type

tgdb.query.TGResultDataDescriptor

class tgdb.query.TGResultSet

This represents a single query response from the server

It will in the future handle acting like a cursor.

abstract property exceptions

Returns what the server’s exceptions are.

To be either Null or an empty List if there are no exceptions.

Returns

A list of the exceptions that occurred during recovery of the data requested by the query.

Return type

typing.List[Exception]

abstract property hasExceptions

Returns whether the server responded with any exceptions.

Returns

Whether the query caused any exceptions.

Return type

bool

abstract property metadata

Returns the metadata for this query result set.

Returns

This queries metadata.

Return type

tgdb.query.TGResultSetMetaData

abstract property position

The current position of this cursor.

Returns

The current position.

Return type

int

abstract property size

Gets the number of objects returned as an integer.

Returns

The number of objects in this query.

Return type

int

abstract skip(count)

Skips the objects

Parameters

count (int) – The number of objects to skip past.

Returns

Nothing

Return type

None

abstract toCollection() → List

Gets all of the objects as a list

Note: Do not use when the number of objects returned could be large. Would recommend iterating through because of the penalty that Python has with deserializing objects.

Returns

A list of all of the query results. The types should match up with those described by the metadata.

Return type

typing.List

class tgdb.query.TGResultSetMetaData

The resulting set’s metadata descriptor.

abstract property annotation

Gets the result type of this result set’s metadata.

Returns

The annotation for this result. Can be used to determine the language.

Return type

str

abstract property resultDataDescriptor

Gets the data descriptor for this result set’s metadata.

Returns

The result set’s data descriptor.

Return type

tgdb.query.TGResultDataDescriptor

abstract property resultType

Gets the result type of this result set’s metadata.

Returns

The top level result data type for this result.

Return type

tgdb.query.TGQueryResultDataType