spinlud / sequelize-typescript-generator

70 stars 25 forks source link

MySQL Tinyint as boolean // default values not working #25

Closed schealex closed 2 years ago

schealex commented 3 years ago

Hi there,

first of all great project, will save so much time. But i've got two major problems with it.

1) for mysql tinyint(1) fields should be considered as boolean (thats what mysql uses as boolean type) 2) if i use a default value for my primary keys like "(uuid())" which tells mysql to autogenerate the uuid for me (mysql >= 8) then the generator does not add any default value and therefore makes the field required in attributes. How are you supposed to handle this?

Regards Alex

spinlud commented 3 years ago

Hi!

  1. The library does not make assumptions about what type a column should be mapped to, it uses the type mapped by the node.js driver for that specific database. In this case mysql driver maps MySQL tinyint to a number in javascript. If you want to cast it to a boolean is very simple in javascript, just use !!your_column.
  2. Could you try the latest version? I've added specific default mappings in MySQL for uuid() and now() functions.