简体   繁体   中英

How to select uuid version in entity typeorm?

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') #?

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM