sequelize-auto
sequelize-auto copied to clipboard
DataTypes.UUID with mysql
Hey guys,
i've got my tables all having a varchar(36) as primary key containing the UUID of the object. The defaultValue is "(UUID())" which commands mysql to generate the uuid on creation.
Now when i try to auto generate using this package i'll get:
id: {
type: DataTypes.STRING(36),
allowNull: false,
defaultValue: Sequelize.Sequelize.fn('uuid'),
primaryKey: true
},
what i would like would be that sequilize-auto used the DataTypes.UUID as type. I looked at the source and it seems like the only way to get the UUID type is if the field is of type uuid | uniqueidentifier, both of which do not exist in mysql.
Am i being dumb or blind?
So the if the column's default value is "(UUID())" then make the type DataTypes.UUID. That makes sense.
What should the Sequelize model's defaultValue be?
Well now it depends, you could see it as an indicator that sequelize should take care of it and generate the uuid otherwise like in my above example it should call the function. I don't actually now if that works though, I've not tested this! But it would be awesome if we could make this integration quickly as my whole application depends on this. If I can support in any way, let me know. Thanks
Perhaps you could manually code a model class or two and test it different ways, and let me know what works. Then I can put those changes into sequelize-auto.
Should we have something like this?
if (dialect == 'mysql' && fieldType == 'varchar(36)' && defaultValue.includes('uuid')) {
dataType = DataTypes.UUID;
}
Hey guys,
i've got my tables all having a varchar(36) as primary key containing the UUID of the object. The defaultValue is "(UUID())" which commands mysql to generate the uuid on creation.
Now when i try to auto generate using this package i'll get:
id: { type: DataTypes.STRING(36), allowNull: false, defaultValue: Sequelize.Sequelize.fn('uuid'), primaryKey: true },what i would like would be that sequilize-auto used the DataTypes.UUID as type. I looked at the source and it seems like the only way to get the UUID type is if the field is of type uuid | uniqueidentifier, both of which do not exist in mysql.
Am i being dumb or blind?
I just want to konw : How to set mysql table default value, then I can run generate script to get " defaultValue:DataTypes.UUIDV4" like left code
I have try set "(UUID())" to field default , but generate "Sequelize.Sequelize.fn("uuid")", but not work
not work mean : When I use /graphql api don't run successful for addTodo