Hey! When using `uuid` with postgres, should I alw...
# orm-help
m
Hey! When using
uuid
with postgres, should I always define the db type as
String
+
@db.Uuid
? I only have
String
currently and I'm not sure if prisma stores the uuid as native uuid by default?
n
Hey Marvin 👋 You should mark them as
@id
as mentioned here in reference Your model could look something like this:
Copy code
model User {
  id        String   @id @default(uuid())
}
m
Ah sorry, my bad! I already have that. Does that mean it automatically uses the native UUID type of postgres already?
n
No that won’t use the native UUID of PostgreSQL, this
uuid()
function is implemented by prisma - UUID schema reference You would need to use
dbgenerated()
to use native UUID of PostgreSQL, here is an example of using it.
m
Okay and for what is
@db.Uuid
? I thought that's the part where the column type is specified?
n
That’s true,
@db.Uuid
would map the column type, in this case, it would be typed to native uuid, In the above example
@db.uuid
and
dbgenerated
both are used.
@default(dbgenerated("gen_random_uuid()"))
this would automatically add a PostgreSQL supported native uuid when a record is inserted.
@db.Uuid
would map the column type as native uuid.
m
Got it! Thanks a lot for your help! 🙂
🙌 1