sequelize.js

Unhandled Promise Rejection Error in node js

微笑、不失礼 提交于 2020-12-15 06:08:57
问题 am getting error while executing combined queries Am using, sequelize and mysql Here is my code: const makeAuthenticate = async (req, res) => { const newOtp = Math.floor(100000 + Math.random() * 900000); try { const {phone} = req.body; const [user, created] = await db.User.findOrCreate({ where: { phone: phone }, }) .then(e => { db.User.update({ otp: newOtp }, { where: { phone: phone }}) .then(f => res.status(200).json({ otp: newOtp })) .catch(err => res.status(500).json({error: err})) //

Node js Sequelize repository pattern (node:2944) UnhandledPromiseRejectionWarning: TypeError: is not a function

假装没事ソ 提交于 2020-12-15 03:47:23
问题 I recently got aware of repository pattern. I am quite new to this pattern and tried to shift my code in this patter. I am using Node js and Sequelize ORM with Sqlite database. Following route is working router.get('/listquestions',(req,res)=>{ Question.findAll({ attributes: ['id','title'], include: [{ model:Lecture, attributes: ['id','videoname','coursecode'], }] }).then((questions) => { if(questions){ console.log(JSON.stringify(questions)); res.render('pages/questionslist', {data:questions}

using map to create a new plain object in Sequelize

此生再无相见时 提交于 2020-12-15 03:45:50
问题 i am trying to map my conversation array to create a new object with url and thumbnail url instead of the image file name. router.get('/', auth, async (req, res) => { const conversations = await Conversation.findAll({ include: [ // { // model: Message, // where: { // [Op.or]: [ // { senderId: req.user.id }, // { receiverId: req.user.id }, // ], // }, // required: true, // RIGHT JOIN // }, { Post, attributes:["id","title","userId"], include: [ { model: User, attributes: ["id", "name", "email"]

Node js Sequelize repository pattern (node:2944) UnhandledPromiseRejectionWarning: TypeError: is not a function

﹥>﹥吖頭↗ 提交于 2020-12-15 03:45:10
问题 I recently got aware of repository pattern. I am quite new to this pattern and tried to shift my code in this patter. I am using Node js and Sequelize ORM with Sqlite database. Following route is working router.get('/listquestions',(req,res)=>{ Question.findAll({ attributes: ['id','title'], include: [{ model:Lecture, attributes: ['id','videoname','coursecode'], }] }).then((questions) => { if(questions){ console.log(JSON.stringify(questions)); res.render('pages/questionslist', {data:questions}

How to pass a seed value to random order function in Sequelize

ぃ、小莉子 提交于 2020-12-15 03:43:45
问题 In SQL dialects you can sort by random and you can pass a seed to the random function in order to get a repeatable random order of rows. In MySQL you'd do it like this: SELECT * FROM `users` ORDER BY RAND("192.168.1.1") I'm aware of how to use the RAND function when querying with Sequelize: users.findAll({ order: [sequelize.random()], }); I can't seem to figure out how to pass a seed to the random function. I've looked at the docs: https://sequelize.org/master/class/lib/sequelize.js~Sequelize

nodejs, postgres, sequelize - instead of getting the filename, trying to get full path

*爱你&永不变心* 提交于 2020-12-13 03:39:44
问题 After storing my images separately as strings in postgres. when i go to the route, images looks like this (the response i am currently getting) "images":"image1.png-2020-11-11T13:15:55.692Z" i am trying to get it like this "images":["url":"image1.png-2020-11-11T13:15:55.692Z_full","thumbnailUrl":"image1.png-2020- 11-11T13:15:55.692Z_thumb"] Here is my get request router.get("/", (req, res) => Post.findAll({ order: [["createdAt", "DESC"]], include: { model: Post_Image, attributes: ["id",

nodejs, postgres, sequelize - instead of getting the filename, trying to get full path

 ̄綄美尐妖づ 提交于 2020-12-13 03:38:56
问题 After storing my images separately as strings in postgres. when i go to the route, images looks like this (the response i am currently getting) "images":"image1.png-2020-11-11T13:15:55.692Z" i am trying to get it like this "images":["url":"image1.png-2020-11-11T13:15:55.692Z_full","thumbnailUrl":"image1.png-2020- 11-11T13:15:55.692Z_thumb"] Here is my get request router.get("/", (req, res) => Post.findAll({ order: [["createdAt", "DESC"]], include: { model: Post_Image, attributes: ["id",

How can users like each others post using sequelize postgres nodejs?

寵の児 提交于 2020-12-13 03:14:18
问题 I am trying to implement that users can like each others post. Here is my Likes model: const Likes = db.define("Likes", { id: { allowNull: false, autoIncrement: true, primaryKey: true, type: Sequelize.INTEGER, }, PostId: { type: Sequelize.INTEGER, references: { model: "Post", key: "id", }, onUpdate: "cascade", onDelete: "cascade", }, userId: { type: Sequelize.INTEGER, references: { model: "User", key: "id", }, onUpdate: "cascade", onDelete: "cascade", }, createdAt: { allowNull: false, type:

How can users like each others post using sequelize postgres nodejs?

狂风中的少年 提交于 2020-12-13 03:11:51
问题 I am trying to implement that users can like each others post. Here is my Likes model: const Likes = db.define("Likes", { id: { allowNull: false, autoIncrement: true, primaryKey: true, type: Sequelize.INTEGER, }, PostId: { type: Sequelize.INTEGER, references: { model: "Post", key: "id", }, onUpdate: "cascade", onDelete: "cascade", }, userId: { type: Sequelize.INTEGER, references: { model: "User", key: "id", }, onUpdate: "cascade", onDelete: "cascade", }, createdAt: { allowNull: false, type:

Sequelize how to structure the chat part of the app?

六月ゝ 毕业季﹏ 提交于 2020-12-07 16:41:02
问题 I currently have an app where users can log in and make posts. Next to each post, there is button that if pressed, the current user can send a message to the user who created the post. I have a posts model and a user model. Each user can post as many posts as they want, but each post only belongs to one user. const User = db.define( "User", { id: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true, }, name: { type: Sequelize.STRING, }, email: { type: Sequelize.STRING, }, password