dna*_*ion 5 node.js sequelize.js
从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();
Run Code Online (Sandbox Code Playgroud)
问题:
where对象中的模型属性?| 归档时间: |
|
| 查看次数: |
937 次 |
| 最近记录: |