Autocomplete attributes for Sequelize Models

Viewed 499

Take this simple example from the sequelize documentation.

const { Sequelize, DataTypes, Model } = require('sequelize');

const sequelize = new Sequelize('sqlite::memory');

class User extends Model {}

User.init(
  {
    // Model attributes are defined here
    firstName: {
      type: DataTypes.STRING,
      allowNull: false,
    },
    lastName: {
      type: DataTypes.STRING,
      // allowNull defaults to true
    },
  },
  {
    // Other model options go here
    sequelize, // We need to pass the connection instance
    modelName: 'User', // We need to choose the model name
  },
);

async function main() {
  await User.sync();

  await User.create({
    firstName: 'Ruby',
    lastName: 'Gem',
  });

  const ruby = await User.findOne({
    where: {
      firstName: 'Ruby', // how to get auto complete for Model attributes? example: firstName
    },
  });

  const rubyFirstName = ruby.firstName; // how to get auto complete for the Model instance?

  console.log(rubyFirstName);
  console.log(ruby);
}

main();

Question:

  • Is there a way to get VSCode intellisence to auto complete the Model attributes in where object?
  • Also, how to get auto complete to work for attributes for the Model instance? (please read the comments on the main function in the above snippet)
0 Answers
Related