# Predicate in a Go struct and uid is now string?

**URL:** <https://discuss.dgraph.io/t/predicate-in-a-go-struct-and-uid-is-now-string/1988>\
**Category:** Users\
**Created:** [November 28, 2017, 3:37pm UTC](https://discuss.dgraph.io/t/predicate-in-a-go-struct-and-uid-is-now-string/1988 "2017-11-28T15:37:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dalu](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/dalu/32/806_2.png) [@dalu](https://discuss.dgraph.io/u/dalu)\
**Post date:** [November 28, 2017, 3:37pm UTC](https://discuss.dgraph.io/t/predicate-in-a-go-struct-and-uid-is-now-string/1988/1 "2017-11-28T15:37:02Z")

</div>

What would a predicate in a Go struct be?  
Because  
[https://docs.dgraph.io/howto/#giving-nodes-a-type](https://docs.dgraph.io/howto/#giving-nodes-a-type)

I’m not a native English speaker and I never had to learn a different language using those words.

For a

```auto
type Community struct {
}

```

would the predicate be

```auto
type Community struct {
IsCommunity bool `json:"-"`
}

```

?  
Oh and do I have to index it?

And from your client example with SetObject  
[https://godoc.org/github.com/dgraph-io/dgraph/client#ex-package--SetObject](https://godoc.org/github.com/dgraph-io/dgraph/client#ex-package--SetObject)

You have `uid string`  
Did the native type of uid change from int64 to string?  
Do I have to set the value of uid when I insert a new … object?

---

<div class="post-metadata">

**Author:** ![pawan](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/pawan/32/1946_2.png) [@pawan](https://discuss.dgraph.io/u/pawan)\
**Post date:** [November 28, 2017, 11:25pm UTC](https://discuss.dgraph.io/t/predicate-in-a-go-struct-and-uid-is-now-string/1988/2 "2017-11-28T23:25:13Z")

</div>

Hey @dalu

From the SetObject example

```auto
type Person struct {
    Uid string `json:"uid,omitempty"`
    Name string `json:"name,omitempty"`
    Age int `json:"age,omitempty"`
    Dob *time.Time `json:"dob,omitempty"`
    Married bool `json:"married,omitempty"`
}

```

The predicates would be `name`, `age`, `dob`, `married`. They are analogous to column names in a SQL DB.

For your example, you should have something like below in which case `is_community` would be a predicate.

```auto
type Community struct {
  IsCommunity bool `json:"is_community"`
}

```

> [@dalu](#):
>
> Oh and do I have to index it?

That depends on the kind of queries you want to perform. If you just wanted to retrieve them then you don’t need any indexes, on the other hand if you wanted to perform an `eq` query then you would need some index.

> [@dalu](#):
>
> Did the native type of uid change from int64 to string?

Internally, `uid` is stored as a `uint64` but for the user its a `string`. You give us a string and we return a string.

> [@dalu](#):
>
> Do I have to set the value of uid when I insert a new … object?

No, you only set the value of `uid` when you want to update something. In other words, if the marshalled object has a `uid` field, we assume its an update otherwise we create a new node.

---

<div class="post-metadata">

**Author:** ![dalu](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/dalu/32/806_2.png) [@dalu](https://discuss.dgraph.io/u/dalu)\
**Post date:** [December 13, 2017, 12:04pm UTC](https://discuss.dgraph.io/t/predicate-in-a-go-struct-and-uid-is-now-string/1988/3 "2017-12-13T12:04:46Z")

</div>

> [@pawan](#):
>
> That depends on the kind of queries you want to perform. If you just wanted to retrieve them then you don’t need any indexes, on the other hand if you wanted to perform an eq query then you would need some index.

Late reply, busy sorry and computer died etc.  
Anyhow,  
In the context of the question (giving nodes a type, see OP) I’d filter by “has predicate is\_community”  
Would I need to index this predicate in this use case?

And I know it’s hard to predict the future, however maybe you have a plan.  
Do you expect the way inserts, updates, queries and deletes are done to change?  
aka. if I wrote a http api with dgraph as storage how likely is it that I’d have to rewrite both the app and the way I do CRUD once 1.0 is out?

Regarding uint64 id, if I understood correctly,  
When I do

```auto
p := new(Person)
p.Uid = bson.NewObjectId().Hex()

```

this would be the unique identifier and not an uint64 value.  
An uint64 value would only be assigned when .pUid == “” and then this value would be converted to string when querying.  
I’m still concerned about the value overflowing.  
uint64 maybe large but it’s not that large when every transaction, every query receive their own uint64 id( that seems to be serial).  
Imagine a semi busy social network/dating site with 10k members all uploading fotos and sending messages and doing queries and searches

---

<div class="post-metadata">

**Author:** ![peter](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/peter/32/574_2.png) [@peter](https://discuss.dgraph.io/u/peter)\
**Post date:** [December 15, 2017, 6:02am UTC](https://discuss.dgraph.io/t/predicate-in-a-go-struct-and-uid-is-now-string/1988/4 "2017-12-15T06:02:43Z")

</div>

> I’d filter by “has predicate is\_community”. Would I need to index this predicate in this use case?

An index isn’t needed in this case (it used to be a few versions back, but isn’t needed any more).

> Do you expect the way inserts, updates, queries and deletes are done to change?  
> aka. if I wrote a http api with dgraph as storage how likely is it that I’d have to rewrite both the app and the way I do CRUD once 1.0 is out?

We expect this to remain stable from now on (we plan to release 1.0 very soon).

> I’m still concerned about the value overflowing.

Don’t worry, uint64s are pretty big. If you were to continually assign 1 million UIDs per second (which is absolutely crazy!), then the range of a uint64 will still last you for almost 60,000 years.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex007/uploads/dgraph/original/2X/2/2b38fdece2abe5814f2e51bee69d1e67fc304b0a.png) [@system](https://discuss.dgraph.io/u/system)\
**Post date:** [January 14, 2018, 6:02am UTC](https://discuss.dgraph.io/t/predicate-in-a-go-struct-and-uid-is-now-string/1988/5 "2018-01-14T06:02:48Z")

</div>

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