コード例 #1
0
ファイル: presentation.go プロジェクト: zombor/neoism
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
0
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
}