Ejemplo n.º 1
0
func deleteNode(db *neoism.Database, node *neoism.Node) {
	// need to remove all relationships before
	rels, err := node.Relationships()
	if err != nil {
		panic(err)
	}
	for _, rel := range rels {
		rel.Delete()
	}
	node.Delete()
}
Ejemplo n.º 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
}