7 Star 11 Fork 0

Apache/TinkerPop

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
.github
bin
data
docker
docs
gremlin-annotations
gremlin-console
gremlin-core
gremlin-dotnet
gremlin-driver
gremlin-go
build
driver
examples
LICENSE
NOTICE
README.md
design.md
docker-compose.yml
go.mod
go.sum
pom.xml
run.sh
gremlin-groovy
gremlin-javascript
gremlin-language
gremlin-python
gremlin-server
gremlin-shaded
gremlin-test
gremlin-tools
gremlin-util
gremlint
hadoop-gremlin
licenses
neo4j-gremlin
spark-gremlin
sparql-gremlin
tinkergraph-gremlin
.asf.yaml
.dockerignore
.gitignore
.mailmap
.travis.install-maven.sh
CHANGELOG.asciidoc
CONTRIBUTING.asciidoc
LICENSE
NOTICE
README.asciidoc
pom.xml
source-release.xml
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

NOTE that versions suffixed with "-rc" are considered release candidates (i.e. pre-alpha, alpha, beta, etc.) and thus for early testing purposes only.

codecov

Go Gremlin Language Variant

Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) and graph analytic systems (OLAP). Gremlin is the graph traversal language of TinkerPop. It can be described as a functional, data-flow language that enables users to succinctly express complex traversals on (or queries of) their application's property graph.

Gremlin-Go implements Gremlin within the Go language and can be used on any Go runtime greater than v1.22. One important difference between Go and Java is that the functions are capitalized, as is required to export functions is Go.

Gremlin-Go is designed to connect to a "server" that is hosting a TinkerPop-enabled graph system. That "server" could be Gremlin Server or a remote Gremlin provider that exposes protocols by which Gremlin-Go can connect.

Once "g" has been created using a connection, it is then possible to start writing Gremlin traversals to query the remote graph:

package main

import (
	"fmt"
	"github.com/apache/tinkerpop/gremlin-go/v3/driver"
)

func main() {
	// Creating the connection to the server with default settings.
	driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection("http://localhost:8182/gremlin")
	// Handle error
	if err != nil {
		fmt.Println(err)
		return
	}
	// Cleanup
	defer driverRemoteConnection.Close()

	// Create an anonymous traversal source with remote
	g := gremlingo.Traversal_().With(driverRemoteConnection)

	// Add a vertex with properties to the graph with the terminal step Iterate()
	promise := g.AddV("gremlin").Property("language", "go").Iterate()

	// The returned promised is a go channel to wait for all submitted steps to finish execution and return error.
	err = <-promise
	if err != nil {
		fmt.Println(err)
		return
	}

	// Get the value of the property
	result, err := g.V().HasLabel("gremlin").Values("language").ToList()
	if err != nil {
		fmt.Println(err)
		return
	}
	// Print the result
	for _, r := range result {
		fmt.Println(r.GetString())
	}
}

Sample Traversals

The Gremlin language allows users to write highly expressive graph traversals and has a broad list of functions that cover a wide body of features. Traversal in Go is very similar to other GLV, with the exception that all step functions are capitalized.

Anonymous traversal __ replaced with T__ due to Go limitations.

Anything in the package when referenced needs the prefix gremlingo like gremlingo.Desc.

Create Vertex

Adding a vertex with properties.

promise := g.AddV("gremlin").Property("language", "go").Iterate()
// Wait for all steps to finish execution and check for error.
err := <-promise
if err != nil {
    fmt.Println(err)
    return
}

Find Vertices

Getting the property value associated with the added vertex. We currently only support ToList() for submitting the remote traversal. Support for Next() will be implemented in the subsequent milestones.

result, err := g.V().HasLabel("gremlin").Values("language").ToList()
// Handle error
if err != nil {
    fmt.Println(err)
    return
}
// Print result
for _, r := range result {
    fmt.Println(r.GetString())
}

Update Vertex

Updating vertex by adding another property to it.

promise := g.AddV("gremlin").Property("language", "go").Iterate()
// Wait for all steps to finish execution and check for error.
err := <-promise
if err != nil {
    fmt.Println(err)
    return
}

Filtering and sorting

results, err := g.V().HasLabel("person").Has("age", gremlingo.T__.Is(gremlingo.P.Gt(30))).Order().By("age", gremlingo.Order.Desc).ToList()

Or with aliases

results, err := g.V().HasLabel("person").Has("age", __.Is(gt(30))).Order().By("age", order.Desc).ToList()

List of all exports can be found at pkg.go.dev

Supported Data Types

The Go driver supports all of the core GraphBinary data types.

More

For information on Installation, Connection Usage, Developer Documentation and more, visit the driver docs

马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/apache/tinkerpop.git
git@gitee.com:apache/tinkerpop.git
apache
tinkerpop
TinkerPop
master

搜索帮助