Generating/auto-assigning UID

The clients might need to get a valid uid in order to create new entities in the Dgraph DB. So, we have to expose some way in which the client can request the server for a UID (Which the server would generate, store and return)

We need a query format which could help doing this. One way is:

mutation {
  get
}

which would generate a uid, store it in posting-list and return
{
 uid: 0x12
}

This uid can be used by the client to associate other atributes to this entity by further mutations.

We could also extend this to

mutation {
  get 10
}

To get 10 uids
{
 uid: [12, 2334, 453, ...]
}

This would help reduce the number of calls made to the server in cases when we want to create a given number of entities at a time.

What do you think of this approach? Any suggestions/comments are welcome. @minions,

It would increase the back and forth required. How about sending mutations like this:

mutation {
  set {
    <_uid_:0x0a> <pred.rel> <_new_:x> .
    <_new_:x> <pred.val> "value" .
    <_new_:x> <pred.rel> <_new_:y> .
    <_new_:y> <pred.val> "value2" .
  }
}

And then we internally automatically generate the UIDs, assign them to the RDFs and store them. We can also return the value of x and y back to the client in the response. This means each call to the server has a good chunk of mutations, avoiding back and forth to generate ids.

2 Likes

This sounds good as well! Will send out a PR around it.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.