5

in my data model, as the type of id, I want to generate a default value that will start with the user.

so the id will bed something like this user..rear33422qeqr

type User {

  myId: String! @default (`user${2+2}`)
  name: String!
  email: String! @unique

}

is it possible to call a javascript function or using string interpolation (user${2+2})

Ashik
  • 2,888
  • 8
  • 28
  • 53
  • Frankly, I didn't understand what you want to do, do you want to generate a random string and append it to your user? – SMAKSS May 04 '20 at 04:50
  • 1
    I want to customize the auto generated prisma id. by default all id starts with ck... for example this is a valid prisma id , which is auto generated. `ck9rni8rv001507190wwmatgy` but I want to customize this. so that all user's id will be `user--randomDigit/randomString` and all post's id will be `posts--randomDigit/randomString` – Ashik May 04 '20 at 05:00
  • There is an open issue on Prisma's GitHub to support custom ID patterns. Somebody proposed a [solution](https://github.com/prisma/prisma/issues/6719#issuecomment-1178211695) based on the possibility to register [middlewares](https://www.prisma.io/docs/concepts/components/prisma-client/middleware). It may not be perfect but it's working. – alexanderdavide Jul 23 '22 at 09:35
  • I don't think this is possible, since prisma only uses sql queries. So you would need to write an sql function (`CREATE SEQUENCE`) for this, and push it to the database via a migration. – Coli Jul 23 '22 at 09:36

0 Answers0