gpt4 book ai didi

mysql - My SQL 数据库 Sequelize npm

转载 作者:行者123 更新时间:2023-11-29 18:18:22 27 4
gpt4 key购买 nike

听说我使用sequelize npm 连接mysql 数据库

    const Sequelize = require('sequelize');
var sequelize = new Sequelize('custom_crm', 'root', '', {
host: "localhost",
port: 3306,
dialect: 'mysql'
});
sequelize.authenticate().then(() => {
console.log('Connection has been established successfully.');
}).catch((err) => {
console.log('Unable to connect to the database:', err);
});

sequelize.query("SELECT id,name FROM `asd123`.`items` WHERE id = 5 LIMIT 1").spread((results, metadata) => {
console.log("results >>",results);
});

我想使用下面的 Sequelize 架构类型转换 asd123(数据库)查询。

website_videos = sequelize.define('website_video', {
id: { type: Sequelize.INTEGER, autoIncrement: true, primaryKey: true },
name : { type: Sequelize.CHAR}
});
website_videos.findAll({}).then((data) => {
console.log('data',data[0]['dataValues']);
}).catch((err) => {
console.log('Unable to connect to the database:', err);
});

最佳答案

试试这个:

website_videos.findAll(
{
where: {
id: user_id
},
limit: 1,
attributes:["id","name"],
}).then((data) => {
console.log('data', data[0]['dataValues']);
}).catch((err) => {
console.log('Unable to connect to the database:', err);
})

;

关于mysql - My SQL 数据库 Sequelize npm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46806894/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com