Support for Microsoft SQL Server NEWSEQUENTIALID() #11387
Labels
status: awaiting response
For issues and PRs. OP must respond (or change something, if it is a PR). Maintainers have no action
type: feature
For issues and PRs. For new features. Never breaking changes.
Issue Description
When working with an MSSQL database you can have sequential UUID using NEWSEQUENTIALID() as default value. This doesn't seem to work with create() in sequelize. The table is generated successfully using:
But when I try to insert using sequelize create method the generate SQL is:
It results in an error, because newsequentialid() is only supposed to be used in a default constraint:
SequelizeDatabaseError: The newsequentialid() built-in function can only be used in a DEFAULT expression for a column of type 'uniqueidentifier' in a CREATE TABLE or ALTER TABLE statement. It cannot be combined with other operators to form a complex scalar expression.
If I work with an existing database and remove the field defaultValue the create works. The id is generated as it should if I look in the database, but sequelize seems to ignore it in the output from the insert statement.
Is your feature request related to a problem? Please describe.
We have an existing database with all id columns as sequential UUID. With sequelize we couldn't insert data and get the generated ID back. This made me look in the the table generation. Both of these problem makes it hard for us to use sequelize in our project.
Describe the solution you'd like
Support to not use the defaultValue in the insert statement, but only in the table creation and not for every insert statement. Also don't remove output from insert statements for the id.
Perhaps a field option
generated: true
to tell sequelize that the field shouldn't be used in the insert statement and should always be taken from the output after the insert.Why should this be in Sequelize
When the default value is added as a part of the table definition it shouldn't be necessary to send it with every insert statement.
Describe alternatives/workarounds you've considered
Considered, but not reasonable solutions are:
Additional context
Add any other context or screenshots about the feature request here.
Issue Template Checklist
Is this issue dialect-specific?
Would you be willing to resolve this issue by submitting a Pull Request?
The text was updated successfully, but these errors were encountered: