I'm use typeorm and nestJs
I have an entity in which I am using the decorator @PrimaryGeneratedColumn('uuid') can I somehow specify a specific version of the uuid?
@PrimaryGeneratedColumn('uuid')
uuid: string;
can it be done like this?
@PrimaryGeneratedColumn('uuid:4') #?
CodePudding user response:
From here:
TypeORM uses RFC4122 compliant UUID v4 function for drivers which do not have a built-in uuid function
So depending on the driver, you're already getting V4 UUID's.
If you need a different UUID implementation, then you can use something like the following to manually set the ID. I've used this quite a lot for short ID's, and it works fine.
import { v4 as uuidv4 } from 'uuid';
@PrimaryColumn()
uuid: string = uuidv4()