Prisma - differences between id, unique, and index

Hey 👋, Could someone explain the difference between @id, @unique, and @index?
15 Replies
Neto
Neto•2y ago
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 index
domi?
domi?OP•2y ago
I 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
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Neto
Neto•2y ago
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
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Neto
Neto•2y ago
Adding indexes can make faster queries But too much indexes can slow down overall the queries
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Neto
Neto•2y ago
Database indexes are a beast on its own Uniques are fine It's more of a constraint
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Neto
Neto•2y ago
Find unique searchs for index values, such as IDs and unique fields As they are easily to index and such
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Neto
Neto•2y ago
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
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Brendonovich
Brendonovich•2y ago
@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 field
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server