node.js - Sequelize 模型的自动完成属性
问题描述
以 sequelize 文档中的这个简单示例为例。
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();
问题:
- 有没有办法让 VSCode 智能自动完成
where
对象中的模型属性? - 另外,如何让模型实例的属性自动完成?(请阅读上面代码片段中对 main 函数的注释)
解决方案
推荐阅读
- reactjs - 是否可以下载 create-react-app 应用程序的源文件/代码?
- javascript - 为什么会出现此错误:无法提供安全连接
- python - 强制关闭应用程序浏览器 Django ConnectionResetError:[WinError 10054] 远程主机强制关闭现有连接
- python - Blogger API v3 添加搜索说明
- javascript - 反应窗口的问题不会显示结果
- typescript - 如何使用 WebView API 在 VS Code 中打开第 3 方网站?
- laravel - 在 laravel 中使用波斯字符作为 slug
- reactjs - 如何每 10 分钟使用反应钩子获取异步数据
- c - C 程序打印出错误的值
- node.js - 如何处理 mogodb+Nodejs 中的断言错误?