Skip to content

String lengths for mssql #219

Closed
Closed

Description

@Benjathing

Testing sequelize-auto with a model -> database -> auto:

export default function(sequelize, DataTypes) {
    return sequelize.define('test', {
        title: DataTypes.STRING(1000),
  });
}

generated a table with:
title (nvarchar(1000), null)

However, on running sequelize-auto against this database, it genereated only:

module.exports = function(sequelize, DataTypes) {
  return sequelize.define('test', {
    title: {
      type: DataTypes.STRING,
      allowNull: true
    }
}

What happened to the string length?

Activity

  1. irwin-r commented on Jun 4, 2018

    @irwin-r

    Hello,

    I'm still very new to Sequelize and figuring it out myself, so I can't advise on how to best fix this issue, but I was able to apply a change to the isDescribeQuery portion of Sequelize's lib\dialects\mssql\query.js to fix this issue.:

        data.forEach(function(_result) {
          if (_result.Default) {
            _result.Default = _result.Default.replace("('",'').replace("')",'').replace(/'/g,''); /* jshint ignore: line */
          }
    
          result[_result.Name] = {
            type: _result.Type.toUpperCase(),
            allowNull: (_result.IsNull === 'YES' ? true : false),
            defaultValue: _result.Default,
            primaryKey: _result.Constraint === 'PRIMARY KEY'
          };
    
          // ADDITION:
          // Sequelize wasn't adding column length when specified.
          if (result.Length !== null) 
            result[_result.Name].type += `(${_result.Length})`;
        });

    Hope this helps :)

    On a somewhat unrelated note, SMALLDATETIME and MONEY aren't currently acknowledged by Sequelize. I've currently just routed them to DATE/DECIMAL respectively, but I think that recognising/adding these types would be a welcome addition.

  2. steveschmitt commented on Jul 6, 2020

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions