Skip to content

Comments

Detect default values that are functions with parameters#589

Open
edwardmcarl wants to merge 2 commits intosequelize:masterfrom
edwardmcarl:detect-database-functions
Open

Detect default values that are functions with parameters#589
edwardmcarl wants to merge 2 commits intosequelize:masterfrom
edwardmcarl:detect-database-functions

Conversation

@edwardmcarl
Copy link
Contributor

Hi. Thanks again for all your work on this.
It looks like the changes in 0.8.5 didn't quite resolve issue #548 :
We have a column with default value (EXTRACT( MICROSECOND FROM NOW(3)) / 1000). Sequelize-auto currently generates invalid JS/TS in its output (though much nicer than before):

<snip>
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: extract(microsecond from now(3)) \/ 1000,
<snip>

This stems from line 369 in auto-generator.js:

if (defaultVal.match(/\(\)/g)) {

which only matches parentheses with nothing between them. This PR just changes the regex to /\([\w ]*\)/g so that it matches on parentheses with alphanumeric characters and/or spaces between them, and an equivalent change on line 377.

It may be appropriate to use an even more permissive regex - for example, /\([\w ,]*\)/g would also match functions with multiple arguments. I'm not familiar enough with the functions of the different RDBMSs that Sequelize supports to devise the ideal regex, but this adjustment should add functionality without breaking anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant