@unique
Specifies the name of a FaunaDB index that enforces a uniqueness constraint.
Description
The @unique
directive marks a field as being unique. Unique fields
have an associated unique index within the database. The index
argument controls the name of the unique index. By default, the index
name uses this template: unique_<type name>_<field name>
.
Example
When the following GraphQL schema has been imported:
type User {
name: String! @unique(index: "unique_username")
}
The database contains the following index:
Get(Index("unique_username"))
{ ref: Index("unique_username"),
ts: 1560525943310000,
active: true,
partitions: 1,
name: 'unique_username',
source: Collection("User"),
data: { gql: { ts: Time("2019-06-14T15:25:43.226352Z") } },
terms: [ { field: [ 'data', 'name' ] } ],
unique: true }
Was this article helpful?
We're sorry to hear that.
Tell us how we can improve!
documentation@fauna.com
Thank you for your feedback!