denodb: UUID is not auto generated
Hi,
I have one issue that would like to ask here.
If I set the id to INTEGER it will be auto-generated, but if I use UUID it’s not. This is my model.
class User extends Model {
static table = 'users'
static timestamps = true
static fields = {
id: {
type: DataTypes.UUID,
primaryKey: true,
},
....
}
Do I miss anything to have this auto-generated?
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 1
- Comments: 16 (7 by maintainers)
Hi autsada,
For now, UUID fields are not auto-generated indeed.
I just found that Deno has a
uuidhelper in the standard library, so here’s how you can do it:Let me know if this works for you.
Keep in touch
I feel like I might have won an award for the weirdest bug I have ever see, consider the following user model:
On running I get a TS error:
If I flip the ID type to
DataTypes.STRING- it boots up fine, but then when a row is added to the DB the ID isIt’s evaling the string of the function…?
id: v4.generatewithDataTypes.String(id is uuid) works whileDataTypes.UUIDthrows error with1.0.37@eveningkid
Works! I still get errors from Typescript if i set the id in the model with
id: { primaryKey: true, type: DataTypes.UUID }the error is:but no error if I set it to string.
Doing so sets the default value as the immediate return value of
generate()which is a constant string. In his example @eveningkid gave a function: