Skip to content

Commit

Permalink
docs(dql):Add docs for unique directive (#644)
Browse files Browse the repository at this point in the history
  • Loading branch information
shivaji-dgraph committed Sep 22, 2023
1 parent 0a7daea commit af61674
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions content/dql/dql-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,28 @@ Query:
}
```

### Unique Directive


The unique constraint enables us to guarantee that all values of a predicate are distinct. To implement the @unique
directive for a predicate, you should define it in the schema and create an index on the predicate based on its type.
If a user does not add the proper index to the predicate, then Dgraph will return an error.

Dgraph will automatically include the @upsert directive for the predicate. To enforce this uniqueness constraint,
a predicate must have an index, as explained below. Currently, we only support the @unique directive on newly created
predicates with the data types string and integer.

| Data Type | Index |
| -------- | ------- |
| string | hash, exact |
| int | int |

This is how you define the unique directive for a predicate.

```
email: string @unique @index(exact) .
```

### Upsert directive


Expand Down

0 comments on commit af61674

Please sign in to comment.