Stored Procedure API¶
Describes how to access the data available when executing as a stored procedure or trigger.
-
class
tgdb.storedproc.
TGGraphContext
¶ Acts as a combination of TGGraphObjectFactory and TGConnection. This is the class that is the primary interface between the stored procedure/trigger and the server. Since this code is executed on the server, the interface does not include any of the connection details required by the server. It also has access to all of the nodes and edges in this step in the query or across the whole database when a trigger??.
-
abstract
commit
()¶ Commits all changes scheduled in the changelist.
- Returns
Nothing
- Return type
-
abstract
createCompositeKey
(name: str) → tgdb.model.TGKey¶ Creates a composite key on the nodetype given by name. See stored procedure key.
- Parameters
name (str) – The nodetype name. Must be a valid nodetype.
- Returns
A new key to use for getting a particular node of a particular nodetype.
- Return type
-
abstract
createEdge
(fromnode: tgdb.model.TGNode, tonode: tgdb.model.TGNode, dirtype=<DirectionType.Directed: 1>, edgetype: str = None) → tgdb.model.TGEdge¶ Creates an edge from the given fromnode to the given tonode with the direction type and edgetype if provided. Does not insert the edge into the database. See stored procedure edge for potential restrictions.
- Parameters
fromnode (tgdb.model.TGNode) – The from node for this new edge.
tonode (tgdb.model.TGNode) – The to node for this new edge.
dirtype (tgdb.model.DirectionType) – The direction for the new edge. Should only set when edgetype is set to None.
edgetype (str) – The edgetype for the new node. If set to None, then uses the default edgetype for the direction type set. If set to a string, it must be a valid edgetype.
- Returns
The new edge.
- Return type
-
abstract
createNode
(nodetype: str) → tgdb.model.TGNode¶ Creates a new node with the given nodetype. Does not insert the node into the database. See stored procedure node for potential restrictions.
- Parameters
nodetype (str) – The nodetype for the new node. Must be a valid nodetype.
- Returns
The new node.
- Return type
-
abstract
deleteEntity
(entity: tgdb.model.TGEntity)¶ Deletes the entity. Will only be committed after the commit method is called.
- Parameters
entity (tgdb.model.TGEntity) – The entity to delete from the server on the next commit call.
- Returns
Nothing
- Return type
-
abstract
executeQuery
(query: str, option: tgdb.query.TGQueryOption = <tgdb.query.TGQueryOption object>) → tgdb.query.TGResultSet¶ Executes the query string with the query options specified.
- Parameters
query (str) – The query to run on the server.
option (tgdb.query.TGQueryOption) – The query options to use.
- Returns
The result of the query.
- Return type
-
abstract
getEdges
(edgetype: str = None) → Iterable[tgdb.model.TGEdge]¶ Gets all edges a part of this Graph Context. See stored procedure edge for potential restrictions.
- Parameters
edgetype (str) – The edgetype of the edges to get. If set to None, then gets all of the edges available. If it is a string, then it must be a valid edgetype name.
- Returns
An iterator of all of the edges that are of that edgetype or all that are available.
- Return type
-
abstract
getEntity
(key: tgdb.model.TGKey, option: tgdb.query.TGQueryOption = <tgdb.query.TGQueryOption object>) → tgdb.model.TGEntity¶ Gets the entity with the given key and query options specified.
- Parameters
key (tgdb.model.TGKey) – The key to use when looking up a particular entity in the database. Currently only supports looking up nodes.
option (tgdb.query.TGQueryOption) – The options for acquiring the entity requested.
- Returns
The entity requested.
- Return type
-
abstract
getNodes
(nodetype: str = None) → Iterable[tgdb.model.TGNode]¶ Gets all nodes a part of this Graph Context. See stored procedure node for potential restrictions.
- Parameters
nodetype (str) – The node type of the nodes to get. If set to None, then gets all of the nodes available. If it is a string, then it must be a valid nodetype name.
- Returns
An iterator of all of the nodes that are of that nodetype or all that are available.
- Return type
-
abstract
insertEntity
(entity: tgdb.model.TGEntity)¶ Inserts the entity. Will only be committed after the commit method is called.
- Parameters
entity (tgdb.model.TGEntity) – The entity to insert into the server on the next commit call.
- Returns
Nothing
- Return type
-
abstract
updateEntity
(entity: tgdb.model.TGEntity)¶ Updates the entity. Will only be committed after the commit method is called.
- Parameters
entity (tgdb.model.TGEntity) – The entity to update on the server on the next commit call.
- Returns
Nothing
- Return type
-
abstract
-
class
tgdb.storedproc.
TGTransactionChangelist
¶ Represents all of the entities that are about to be inserted, deleted, or changed on a transaction.
-
abstract
addEntity
(ent: tgdb.model.TGEntity, opcode: str)¶ Adds the entity to this transaction.
- Parameters
ent (tgdb.model.TGEntity) – The entity to add to a change list in the transaction.
opcode (str) – The operation code that determines whether to insert, change, or delete the entity. Must be one of “insert”, “update”, or “delete”
-
abstract
getDeletedEntities
() → Iterable[tgdb.model.TGEntity]¶ Get all removed entities for this transaction. See stored procedure entity for potential restrictions.
- Returns
All of the deleted entities for this transaction.
- Return type
-
abstract
getInsertedEntities
() → Iterable[tgdb.model.TGEntity]¶ Gets all newly inserted entities for this transaction. See stored procedure entity for potential restrictions.
- Returns
All of the newly inserted entities for this transaction.
- Return type
-
abstract
getModifiedEntities
() → Iterable[tgdb.model.TGEntity]¶ Get all modified entities for this transaction. See stored procedure entity for potential restrictions.
- Returns
All of the updated entities for this transaction.
- Return type
-
abstract
removeEntity
(ent: tgdb.model.TGEntity, opcode)¶ Remove the entity from this transaction.
- Parameters
ent (tgdb.model.TGEntity) – The entity to remove from a change list in the transaction.
opcode (str) – The operation code that determines whether to remove the entity from the insert, change, or delete changelist. Must be one of “insert”, “update”, or “delete”
-
abstract
-
tgdb.storedproc.
tgstoredproc
(fn)¶ This decorates a stored procedure and marks it so that the TIBCO Graph Database can execute it when called. The name of the function is what you should pass to the
execsp
Gremlin step.- Parameters
fn (typing.Callable[[TGGraphContext, ... ], typing.Any]) – A function that should be added to the stored procedures that a client may execute. Must have the first argument be annotated as a TGGraphContext. It must also have properly annotated return types that match up with the TGDB return language. The return type must match the annotated return type.
-
tgdb.storedproc.
tgstoredprocfull
(fn)¶ This function decorates a stored procedure and marks it so that the TIBCO Graph Database can execute it when called. The name of the function is what you should pass to the
execsp
Gremlin step. This function decorator is like tgstoredproc, but it also indicates that the results from the Gremlin steps preceding the execsp() step should be aggregated before calling the stored procedure.- Parameters
fn (typing.Callable[[TGGraphContext, ... ], typing.Any]) – A function that should be added to the stored procedures that a client may execute. Must have the first argument be annotated as a TGGraphContext. It must also have properly annotated return types that match up with the TGDB return language. The return type must match the annotated return type.
-
tgdb.storedproc.
tgtrigger
(fn)¶ This function decorates a trigger and marks it so that the TIBCO Graph Database can execute it when a transaction is committed.
- Parameters
fn (typing.Callable[[TGGraphContext, TGTransactionChangelist], None]) – A function that should be added to the triggers that execute on a transaction. Must have the first argument be annotated as a TGGraphContext. The second argument must be annotated as a TGTransactionChangeList.
Notes About Stored Procedures¶
Not necessarily all of the functionality/syntactical sugar provided by the client-facing API are allowed when executingthe server environment. Due to these restrictions, writing a stored procedure or trigger requires slightly moreverbose syntax. The below are the
-
class
tgdb.storedproc.
TGEntity
¶ Acts as a Python wrapper for a database entity.
- Canonical
tgdb.model.TGEntity
-
setAttribute
(attr_name: str, value: typing.Any) → None¶ Sets the attribute with attribute descriptor named by the
attr_name
parameter to the value described by theparametervalue
.- Parameters
attr_name (str) – The name of the attribute descriptor to set the value on this entity. Must be a validattribute descriptor name.
value (typing.Any) – The new value of the attribute on this entity. Must have a legal conversion from the Pythonobject to the attribute descriptor type.
- Returns
Nothing
- Return type
-
getAttribute
(attr_name: str) → typing.Any¶ Gets the attribute value specified by the
attr_name
parameter.- Parameters
attr_name (str) – The name of the attribute descriptor to get the value on this entity. Must be a valid attribute descriptor name.
- Returns
The value for the attribute. Will match up with the canonical type of the database in a Python environment (i.e. if the attribute descriptor is a
double
, then the returned type will be a Pythonfloat
).- Return type
typing.Any
-
getEntityKind
() → int¶ Gets the entity kind as an integer. Can use
fromKindId()
to get theTGEntityKind
.- Returns
The entity kind as an integer.
- Return type
-
class
tgdb.storedproc.
TGNode
¶ Acts as a Python wrapper for a database node. Will extend the Stored Procedure Entity. Supports the __hash__, __neq__, and __eq__ builtin Python methods which are useful for using this class as elements in a set or as the key elements in a dictionary.
- Canonical
tgdb.model.TGNode
-
getNodeType
() → str¶ Gets the node’s type’s name.
- Returns
The name of this node’s nodetype.
- Return type
-
getEdges
() → typing.Iterable[tgdb.model.TGEdge]¶ Gets the edges that are incident on this node.
- Returns
The edges incident on this node.
- Return type
-
addEdge
(toNode: TGNode, direction: tgdb.model.DirectionType = tgdb.model.DirectionType.Directed, edgetype: typing.Optional[str] = None) → TGEdge¶ Adds a new edge to this node (as the
from
node ifdirection
type isdirected
), with the other node set to thetoNode
parameter, and the edgetype of the new edge is set to the edgetype with the same name as theedgetype
parameter.- Parameters
toNode (tgdb.storedproc.TGNode) – The other node. Will be the
to
node if thedirection
parameter isdirected
.direction (tgdb.model.DirectionType) – The direction for this node. Only need to set when not setting the
edgetype
parameter.edgetype (typing.Optional[str]) – The edgetype of the new edge. Must be a valid edgetype name that is already registered in the database.
- Returns
The new edge.
- Return type
-
class
tgdb.storedproc.
TGEdge
¶ Acts as a Python wrapper for a database edge. Will extend the Stored Procedure Entity. Supports the __hash__, __neq__, and __eq__ builtin Python methods which are useful for using this class as elements in a set or as the key elements in a dictionary.
- Canonical
tgdb.model.TGEdge
-
getEdgeType
() → str¶ Gets the edge’s type’s name.
- Returns
The name of this edge’s edgetype.
- Return type
-
getVertices
() → typing.Tuple[tgdb.storedproc.TGNode, tgdb.storedproc.TGNode]¶ Gets this edge’s incident nodes.
- Returns
The edge’s incident nodes.
- Return type
typing.Tuple[tgdb.storedproc.TGNode, tgdb.storedproc.TGNode]
-
getDirection
() → int:¶ Gets the direction for this edge. Can be converted to a
DirectionType
by usingfromId()
.- Returns
The edge’s direction.
- Return type
-
class
tgdb.storedproc.
TGKey
¶ Acts as a Python wrapper for a database key. Will extend the Stored Procedure Entity. Supports the __setitem__ and __delitem__ builtin Python methods which are useful for using the bracket notation to set attribute values.
- Canonical
tgdb.model.TGKey