Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect default values that are functions with parameters #589

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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