Prisma - differences between id, unique, and index
Hey 👋,
Could someone explain the difference between
@id
, @unique
, and @index
?15 Replies
Id is they way to say to prima that the field is the
table primary key
Unique is saying that the column value will be unique for the entire table
Index is saying to prisma to create a indexI see, so
@id
will make it the field the primary key, @unique
, will just mean that postgres won't create that new row unless that value is unique within that column, and @index
just creates an index? 👀Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Also that
Yes
You also have new variations of find unique, but it's more related to prisma
In general, adding index randomly isn't good
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Adding indexes can make faster queries
But too much indexes can slow down overall the queries
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Database indexes are a beast on its own
Uniques are fine
It's more of a constraint
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Find unique searchs for index values, such as IDs and unique fields
As they are easily to index and such
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Find first is just a general purpose single row search
Depends on the schema and such
Adding indexes without some info about the acess
It's no good
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
@index
just creates a general index for faster lookups by that field.
@unique
creates a unique index that not only does faster lookups, but also enforces that two rows cannot have the same value for that fieldUnknown User•2y ago
Message Not Public
Sign In & Join Server To View