本文整理匯總了Golang中github.com/jmcvetta/neoism.Database.CreateNode方法的典型用法代碼示例。如果您正苦於以下問題:Golang Database.CreateNode方法的具體用法?Golang Database.CreateNode怎麽用?Golang Database.CreateNode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/jmcvetta/neoism.Database
的用法示例。
在下文中一共展示了Database.CreateNode方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: create
func create(db *neoism.Database) {
kirk, err := db.CreateNode(neoism.Props{"name": "Kirk", "shirt": "yellow"})
if err != nil {
log.Fatal(err)
}
fmt.Println(kirk.Properties()) // map[shirt:yellow name:Kirk] <nil>
// Ignoring subsequent errors for brevity
spock, _ := db.CreateNode(neoism.Props{"name": "Spock", "shirt": "blue"})
mccoy, _ := db.CreateNode(neoism.Props{"name": "McCoy", "shirt": "blue"})
r, _ := kirk.Relate("outranks", spock.Id(), nil) // No properties on this relationship
start, _ := r.Start()
fmt.Println(start.Properties()) // map[name:Kirk shirt:yellow] <nil>
kirk.Relate("outranks", mccoy.Id(), nil)
spock.Relate("outranks", mccoy.Id(), nil)
}
示例2: getOrCreateNode
func getOrCreateNode(db *neoism.Database, label string, key string, value string, props neoism.Props) *neoism.Node {
res := []struct {
// `json:` tags matches column names in query
N neoism.Node
}{}
//MATCH (n:Tag { name: 'deporte' }) RETURN n
st := "MATCH (n:" + label + " { " + key + ": '" + value + "' }) RETURN n"
println(st)
cq0 := neoism.CypherQuery{
// Use backticks for long statements - Cypher is whitespace indifferent
Statement: st,
Parameters: neoism.Props{},
Result: &res,
}
db.Cypher(&cq0)
// println("largo")
// println(len(res))
// tagName, err := n1.Property("name")
// println(tagName)
// println(err)
var node *neoism.Node
if len(res) > 0 { // existe el tag
println("si")
node = &res[0].N
node.Db = db
} else {
println("no")
node, _ = db.CreateNode(props)
node.AddLabel(label)
}
return node
}