func (kp *KPartite) AddNode(nodeType string, value interface{}) (bson.ObjectId, os.Error) { now := time.Nanoseconds() nd := &NodeDoc{ ID: chooseID(), Created: bson.Timestamp(now), Modified: bson.Timestamp(now), Value: value, } nt := kp.GetNodeType(nodeType) if nt == nil { return "", ErrArg } return nd.ID, nt.C.Insert(nd) }
func (kp *KPartite) UpdateEdge(edgeType string, edgeID bson.ObjectId, value interface{}) os.Error { et := kp.GetEdgeType(edgeType) if et == nil { return ErrArg } edge, err := kp.FindEdge(edgeType, bson.D{{"_id", edgeID}}) if err != nil { return err } now := bson.Timestamp(time.Nanoseconds()) edge.Modified = now edge.Value = value return et.C.Update(bson.D{{"_id", edgeID}}, edge) }
func (kp *KPartite) UpdateNode(nodeType string, nodeID bson.ObjectId, value interface{}) os.Error { nt := kp.GetNodeType(nodeType) if nt == nil { return ErrType } node, err := kp.FindNode(nodeType, bson.D{{"_id", nodeID}}) if err != nil { return err } now := bson.Timestamp(time.Nanoseconds()) node.Modified = now node.Value = value return nt.C.Update(bson.D{{"_id", nodeID}}, node) }
func (kp *KPartite) AddEdge(edgeType string, from, to bson.ObjectId, value interface{}) (bson.ObjectId, os.Error) { now := bson.Timestamp(time.Nanoseconds()) ed := &EdgeDoc{ ID: kp.makeEdgeID(from, to), Created: now, Modified: now, From: from, To: to, Value: value, } et := kp.GetEdgeType(edgeType) if et == nil { return "", ErrArg } return ed.ID, et.C.Insert(ed) }