I found this that will create or update a node/vertex https://docs.dgraph.io/howto/#upsert-procedure
I tried to search for documentation with sample queries but I am not getting any sample query.
Are there any better alternatives? to Upsert
I found this that will create or update a node/vertex https://docs.dgraph.io/howto/#upsert-procedure
I tried to search for documentation with sample queries but I am not getting any sample query.
Are there any better alternatives? to Upsert
p := Person{
Name: "Bob",
Age: 24,
}
txn := dg.NewTxn()
pb, err := json.Marshal(p)
if err != nil {
log.Fatal(err)
}
mu := &api.Mutation{
CommitNow: true,
SetJson: pb,
}
assigned, err := txn.Mutate(ctx, mu)
if err != nil {
log.Fatal(err)
}
bob := assigned.Uids["blank-0"]
p = Person{
Name: "Alice",
Age: 26,
Married: true,
Raw: []byte("raw_bytes"),
Friends: []Person{{
Uid: bob,
}, {
Name: "Charlie",
Age: 29,
}},
School: []School{{
Name: "Crown Public School",
}},
}
You can use this to create and update a node.