#6 Digit unique number for the database schema

10 messages · Page 1 of 1 (latest)

sterile sable
#

Hello, Any Prisma Function that lets me generate a unique random 6 digit number? something like this
code String? @unique @default(cuid())

I am using mysql

viscid knoll
# sterile sable Hello, Any Prisma Function that lets me generate a unique random 6 digit number?...
MDN Web Docs

The Math.random() static method returns a floating-point, pseudo-random number that's greater than or equal to 0 and less than 1, with approximately uniform distribution over that range — which you can then scale to your desired range. The implementation selects the initial seed to the random number generation algorithm; it cannot be chosen or r...

sterile sable
#

Oh, Thank you, I ended up doing that, I was asking as I wanted to know if there is something built in, instead I used a recursive function that checks if the generated code is equal to an existing one and if not then reutrn that

viscid knoll
#

You have @unique that will not let two records have the same number with the same field

#

will throw an error

#

also if you only want to store numbers, then the appropriate type would be Int

#

not String, because you are storing numbers.