Jump to content
  • Quick Start Guide


    Table of Contents

    Basics

    • Stored procedures are written in Python files.
    • Each python file may have multiple stored procedures and helper functions.
    • The python files must import from the tgdb.storedproc module.

    Configuration

    • All of the files with stored procedures for a database should be stored in a directory together. Any non-python files in this directory are ignored by the stored procedure engine.
    • The database configuration file points to this stored procedure directory. 
    • Each database in the server can point to different (or the same) stored procedure directories.
    • The database configuration file must include a [storedproc] section:
     [storedproc][/code]  			
     dir = /Users/john/workspace/storedproc[/code]  			
     pythonpath = [/code]  			
     autorefresh = true[/code]  			
     refreshinterval = 60[/code] 			
      • dir field is required. Point to the stored procedure directory in this field
      • optional fields include:
        • pythonpath, which points to an optional 3rd party python library
        • autorefresh, a boolean value, which indicates whether the stored procedure engine should refresh the contents of the stored procedure automatically
        • refreshinterval, an int value, which indicates the interval (in seconds) that the directory is refreshed. This field is ignored if 'autorefresh' is set to false.

    Definition

     @tgstoredproc[/code]  			
     def createEdge(gc: TGGraphContext, year: int): -> "[E]"[/code]  			
         ...[/code] 			
    Function Signature
    • @tgstoredproc function decorator
    • The first parameter must be of type TGGraphContext.
    • Type hints for each parameter, e.g.: <parameter name>: <parameter type>. Valid parameter types include:
      • TGGraphContext (only valid for the first parameter)
      • int
      • bool
      • str
      • float
    • Return Type Annotation for the return type. Custom return types are defined for stored procedures here: Function Return Type Annotations If there's no annotation defined in the function definition, or if the annotation is an empty string (""), then the SP is considered a void function, and returning a result from a void function will return an error.
    • variable length *args and **kwargs parameters are also allowed. They also must include type hints.
    • default values for parameters are also allowed
    • general function definition rules regarding ordering of positional, keyword, and default parameters follow Python function definition syntax. See Parameter Ordering and Required Syntax
    Function Definition
    • The return value must be of the same type that is indicated in the return type annotation:
     @tgstoredproc[/code]  			
     def returnString(gc: TGGraphContext, name: str): -> "s"[/code]  			
         return "hello " + s[/code] 			

     

     

     

    Invocation

    • Stored procedures are invoked via gremlin query, using the custom "execsp" step:
       $ g.execsp('returnString', 'Hello World!');

    • Gremlin queries (and thus, stored procedures) can be executed via the admin console, or through client APIs.
    • The leading TGGraphContext parameter from the stored procedure definition guidelines, is not included in the invocation arguments. This argument is built from the output of the gremlin query steps leading up to the execsp step.
    • execsp() arguments, then, include:
      • the function name, wrapped in single quotes, as the first argument
      • arguments to the stored procedure
        • str arguments must be wrapped in single quotes
        • bool arguments not represented as 1 or 0 (i.e., 'False' or 'True') must be wrapped in single quotes
        • int and float arguments do not need to be wrapped in quotes.
    • See Stored Procedure Invocation for more details.

    Useful Admin Commands

    • show procedures
    • describe <procedure>
    • refresh procedures
    • set server storedproc.dir=<DIR>

    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...