This is an automated email from the ASF dual-hosted git repository.

lyndonb pushed a commit to branch 3.5-dev
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git


The following commit(s) were added to refs/heads/3.5-dev by this push:
     new 29600e361a gremlin-go aliasing examples in README and example.go
29600e361a is described below

commit 29600e361ae059b56bd2719b06fe4242e24cf0e5
Author: Valentyn Kahamlyk <vkagam...@users.noreply.github.com>
AuthorDate: Thu May 12 07:25:01 2022 -0700

    gremlin-go aliasing examples in README and example.go
    
    authored-by: valentynk <valent...@bitquilltech.com>
---
 docs/src/reference/gremlin-variants.asciidoc | 42 ++++++++++++++++++++++++++
 gremlin-go/README.md                         | 44 ++++++++++++++++++++++++++++
 gremlin-go/example/example.go                |  7 ++++-
 3 files changed, 92 insertions(+), 1 deletion(-)

diff --git a/docs/src/reference/gremlin-variants.asciidoc 
b/docs/src/reference/gremlin-variants.asciidoc
index 924974493e..bd3eab5016 100644
--- a/docs/src/reference/gremlin-variants.asciidoc
+++ b/docs/src/reference/gremlin-variants.asciidoc
@@ -1658,6 +1658,48 @@ capital letter in order to be public:
 
 *Tokens* - <<a-note-on-scopes,Scope.Global>>, <<a-note-on-scopes,Scope.Local>>
 
+[[gremlin-go-aliases]]
+=== Aliases
+To make the code more readable and close to the Gremlin query language), you 
can use aliases. These aliases can be named with capital letters to be 
consistent with non-aliased steps but will result in exported variables which 
could be problematic if not being used in a top-level program (i.e. not a 
redistributable package).
+[source,go]
+----
+       var __ = gremlingo.T__
+       var gt = gremlingo.P.Gt
+       var desc = gremlingo.Desc
+
+       results, err := g.V().HasLabel("person").Has("age", 
__.Is(gt(30))).Order().By("age", desc).ToList()
+----
+
+==== List of useful aliases
+[source,go]
+----
+       // common
+       var __ = gremlingo.T__
+       var TextP = gremlingo.TextP
+
+       // predicates
+       var between = gremlingo.P.Between
+       var eq = gremlingo.P.Eq
+       var gt = gremlingo.P.Gt
+       var gte = gremlingo.P.Gte
+       var inside = gremlingo.P.Inside
+       var lt = gremlingo.P.Lt
+       var lte = gremlingo.P.Lte
+       var neq = gremlingo.P.Neq
+       var not = gremlingo.P.Not
+       var outside = gremlingo.P.Outside
+       var test = gremlingo.P.Test
+       var within = gremlingo.P.Within
+       var without = gremlingo.P.Without
+       var and = gremlingo.P.And
+       var or = gremlingo.P.Or
+
+       // sorting
+       var shuffle = gremlingo.Shuffle
+       var asc = gremlingo.Asc
+       var desc = gremlingo.Desc
+----
+
 [[gremlin-go-limitations]]
 === Limitations
 
diff --git a/gremlin-go/README.md b/gremlin-go/README.md
index 5694cd09fd..e9f1bed9c8 100644
--- a/gremlin-go/README.md
+++ b/gremlin-go/README.md
@@ -136,6 +136,45 @@ Note: The exact import name as well as the module prefix 
for `NewDriverRemoteCon
                })
 ```
 
+## Aliases
+To make the code more readable and close to the Gremlin query language), you 
can use aliases. These aliases can be named with capital letters to be 
consistent with non-aliased steps but will result in exported variables which 
could be problematic if not being used in a top-level program (i.e. not a 
redistributable package).
+```go
+       var __ = gremlingo.T__
+       var gt = gremlingo.P.Gt
+       var desc = gremlingo.Desc
+
+       results, err := g.V().HasLabel("person").Has("age", 
__.Is(gt(30))).Order().By("age", desc).ToList()
+```
+
+### List of useful aliases
+```go
+       // common
+       var __ = gremlingo.T__
+       var TextP = gremlingo.TextP
+
+       // predicates
+       var between = gremlingo.P.Between
+       var eq = gremlingo.P.Eq
+       var gt = gremlingo.P.Gt
+       var gte = gremlingo.P.Gte
+       var inside = gremlingo.P.Inside
+       var lt = gremlingo.P.Lt
+       var lte = gremlingo.P.Lte
+       var neq = gremlingo.P.Neq
+       var not = gremlingo.P.Not
+       var outside = gremlingo.P.Outside
+       var test = gremlingo.P.Test
+       var within = gremlingo.P.Within
+       var without = gremlingo.P.Without
+       var and = gremlingo.P.And
+       var or = gremlingo.P.Or
+
+       // sorting
+       var shuffle = gremlingo.Shuffle
+       var asc = gremlingo.Asc
+       var desc = gremlingo.Desc
+```
+
 ## Troubleshooting
 
 ### Can't establish connection and get any result
@@ -313,6 +352,11 @@ if err != nil {
        results, err := g.V().HasLabel("person").Has("age", 
gremlingo.T__.Is(gremlingo.P.Gt(30))).Order().By("age", gremlingo.Desc).ToList()
 ```
 
+Or with aliases
+```go
+       results, err := g.V().HasLabel("person").Has("age", 
__.Is(gt(30))).Order().By("age", desc).ToList()
+```
+
 *List of all exports can be found at 
[pkg.go.dev](https://pkg.go.dev/github.com/apache/tinkerpop/gremlin-go/v3/driver)*
 
 ### Supported Data Types
diff --git a/gremlin-go/example/example.go b/gremlin-go/example/example.go
index 365565e566..561cde944a 100644
--- a/gremlin-go/example/example.go
+++ b/gremlin-go/example/example.go
@@ -24,6 +24,11 @@ import (
        "github.com/apache/tinkerpop/gremlin-go/v3/driver"
 )
 
+// syntactic sugar
+var __ = gremlingo.T__
+var gt = gremlingo.P.Gt
+var desc = gremlingo.Desc
+
 func main() {
        // Creating the connection to the server.
        driverRemoteConnection, err := 
gremlingo.NewDriverRemoteConnection("ws://localhost:8182/gremlin",
@@ -41,7 +46,7 @@ func main() {
        g := gremlingo.Traversal_().WithRemote(driverRemoteConnection)
 
        // Perform traversal
-       result, err := 
g.V().HasLabel("person").Order().By("age").Values("name").ToList()
+       result, err := g.V().HasLabel("person").Has("age", 
__.Is(gt(28))).Order().By("age", desc).Values("name").ToList()
        if err != nil {
                fmt.Println(err)
                return

Reply via email to