sequelize.js

Sequelize - Get all data with custom where

*爱你&永不变心* 提交于 2020-07-23 06:33:19
问题 How can I get data with custom where conditions? In this question Sequelize - function on column in a where clause, I have a similar problem, but this one I believe uses MySQL built-in functions and it fetches data within a radius. I have several models. House Address Task Each house HAS MANY tasks . and each house HAS ONE address . When calling /getTasks , I need to get all the mission BUT with a constraint of: house address straight distance must be N-Kilometers away from request's lat-long

Sequelize - Get all data with custom where

三世轮回 提交于 2020-07-23 06:31:10
问题 How can I get data with custom where conditions? In this question Sequelize - function on column in a where clause, I have a similar problem, but this one I believe uses MySQL built-in functions and it fetches data within a radius. I have several models. House Address Task Each house HAS MANY tasks . and each house HAS ONE address . When calling /getTasks , I need to get all the mission BUT with a constraint of: house address straight distance must be N-Kilometers away from request's lat-long

Sequelize migration doesnot read dotenv variable if I don't run it from root directory. why?

被刻印的时光 ゝ 提交于 2020-07-23 06:22:12
问题 This is what I did require('dotenv').config() in the config file set .sequelizerc in the root directory like below set .sequelie file to point config, migrations, models, seeds directory from root directory ran npx seuqlie-cli db:migrate form root directory. It work! ran npx seuqlie-cli db:migrate form sequelize directory. It doesn't read dotenv variable and come with connect ECONNREFUSED 127.0.0.1:3306 and I want to know what is differences between 4 and 5..? this is my directory looks like

Sequelize migration doesnot read dotenv variable if I don't run it from root directory. why?

本小妞迷上赌 提交于 2020-07-23 06:21:21
问题 This is what I did require('dotenv').config() in the config file set .sequelizerc in the root directory like below set .sequelie file to point config, migrations, models, seeds directory from root directory ran npx seuqlie-cli db:migrate form root directory. It work! ran npx seuqlie-cli db:migrate form sequelize directory. It doesn't read dotenv variable and come with connect ECONNREFUSED 127.0.0.1:3306 and I want to know what is differences between 4 and 5..? this is my directory looks like

Updating instance with multiple associations in Sequelize

纵然是瞬间 提交于 2020-07-23 06:15:06
问题 I am able to create records in my MySQL DB with sequelize and NodeJS. But now I am trying to update records in my Database. I have NodeJS as backend and my DB is MySql. Sequelize is my ORM. In Sequelize 5, I have a couple of classes: WorkOder, User (mechanic), Customer, Client and ExpertiseOffice. My datamodel is not complex, there are only 1:1 relations. A WorkOrder has one customer, one Client and one ExpertiseOffice. I use Postman to test my api's. With creating a WorkOrder with some

Updating instance with multiple associations in Sequelize

给你一囗甜甜゛ 提交于 2020-07-23 06:15:05
问题 I am able to create records in my MySQL DB with sequelize and NodeJS. But now I am trying to update records in my Database. I have NodeJS as backend and my DB is MySql. Sequelize is my ORM. In Sequelize 5, I have a couple of classes: WorkOder, User (mechanic), Customer, Client and ExpertiseOffice. My datamodel is not complex, there are only 1:1 relations. A WorkOrder has one customer, one Client and one ExpertiseOffice. I use Postman to test my api's. With creating a WorkOrder with some

Updating instance with multiple associations in Sequelize

点点圈 提交于 2020-07-23 06:13:18
问题 I am able to create records in my MySQL DB with sequelize and NodeJS. But now I am trying to update records in my Database. I have NodeJS as backend and my DB is MySql. Sequelize is my ORM. In Sequelize 5, I have a couple of classes: WorkOder, User (mechanic), Customer, Client and ExpertiseOffice. My datamodel is not complex, there are only 1:1 relations. A WorkOrder has one customer, one Client and one ExpertiseOffice. I use Postman to test my api's. With creating a WorkOrder with some

Sequelize - function on column in a where clause

心不动则不痛 提交于 2020-07-18 11:55:08
问题 I have a Restaurant model with a property 'location' of the type GEOMETRY("Point"). I'm trying to write a query with sequelize that will give me all the restaurants in a certain radius: models.Restaurant.findAll({ attributes: ["*", [models.sequelize.fn("ST_Distance_Sphere", models.sequelize.fn("ST_MakePoint", latitude, longitude), models.sequelize.col("location")), "distance"]], where: { xxx: { $lte: radius } } }).then(function(dishes) { res.status(200).json({dishes: dishes}) }); I have no

Sequelize upsert() never updates and only inserts

故事扮演 提交于 2020-07-09 03:04:54
问题 So I'm trying to use the model.upsert() of sequelize and all i receive is inserts , no matter what i change in the query. I have a Transaction model that has some fields, with the default generated id. reading the sequelize's upsert documentation i noticed this: An update will be executed if a row which matches the supplied values on either the primary key or a unique key is found. Note that the unique index must be defined in your sequelize model and not just in the table. So i was guessing

Sequelize upsert() never updates and only inserts

依然范特西╮ 提交于 2020-07-09 03:01:24
问题 So I'm trying to use the model.upsert() of sequelize and all i receive is inserts , no matter what i change in the query. I have a Transaction model that has some fields, with the default generated id. reading the sequelize's upsert documentation i noticed this: An update will be executed if a row which matches the supplied values on either the primary key or a unique key is found. Note that the unique index must be defined in your sequelize model and not just in the table. So i was guessing