sequelize.js

MySql - Sequalize - Cannot add foreign key constraint

为君一笑 提交于 2019-12-14 00:48:31
问题 I am trying to using Nodejs sequelize to create database. The commands being invoked are CREATE TABLE IF NOT EXISTS `wheel` (`id` INTEGER NOT NULL auto_increment , `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, `shopId` VARCHAR(255), PRIMARY KEY (`id`), FOREIGN KEY (`shopId`) REFERENCES `shop` (`id`) ON DELETE SET NULL ON UPDATE CASCADE) ENGINE=InnoDB; CREATE TABLE IF NOT EXISTS `segments` (`segmentID` VARCHAR(255) NOT NULL , `heading` VARCHAR(255) NOT NULL, `subHeading`

What does 'symbol-keyed' mean in 'JSON.stringify'

喜欢而已 提交于 2019-12-13 18:06:57
问题 There is a Object generated by NodeJS, it looks like this when I use console.log: { dataValues: { a: 1, b: 2 }, fn1: function(){}, fn2: function(){} } when I use JSON.stringify, it return this string: {"a":1,"b":1} I checked the mozilla developer center and found this: All symbol-keyed properties will be completely ignored, even when using the replacer function. I think the 'dataValues' must be the 'symbol-keyed' property, but what does 'symbol-keyed' mean? btw, I use the sequelizejs ORM lib

How to build model with sequelize for belong to many association

僤鯓⒐⒋嵵緔 提交于 2019-12-13 17:30:03
问题 This is what I wrote in Country.js (exactly the same as User.js except datatypes) : module.exports = function(sequelize, DataTypes) { const Country = sequelize.define('country', { id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true }, code: { type: DataTypes.INTEGER }, alpha2: { type: DataTypes.STRING }, alpha3: { type: DataTypes.STRING }, name_en: { type: DataTypes.STRING }, name_fr: { type: DataTypes.STRING } }, { freezeTableName: true, timestamps: false }); Country

How to add context to a Sequelize hook?

▼魔方 西西 提交于 2019-12-13 15:23:11
问题 I want to use a hook to perform access control on a row so that users can only access rows they own. The hook would add an additional where clause to ensure that the user is the owner of the row (ex: WHERE ownerId=user.id). The problem is, how do I pass the user id to Sequelize so that the hook has it when the hook fires? I've looked through the documentation and it's not obvious to me if this is possible. Thanks reference: http://sequelize.readthedocs.org/en/latest/docs/hooks/ 回答1: To add

Query was empty Nodejs Sequlize

假装没事ソ 提交于 2019-12-13 12:53:38
问题 I'm trying to update data in a nodejs application. I tested it with postman. My developing steps was was: Getting data with id: 10 from DB (MySQL) to update >> Unhandled rejection SequelizeDatabaseError: Query was empty I recognised, I use wrong id, so I changed to a correct one:50 >> Some other error Okay, I fix this some other error related to my inaccurate work, and use good id: 50 >> Unhandled rejection SequelizeDatabaseError: Unhandled rejection SequelizeDatabaseError: Query was empty

Insert/Update PostGis Geometry with Sequelize ORM

牧云@^-^@ 提交于 2019-12-13 12:08:36
问题 I have extracted models of some PostGis layers with sequelize-auto, giving: module.exports = function(sequelize, DataTypes) { return sequelize.define('table', { id: { type: DataTypes.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true }, geom: { type: DataTypes.GEOMETRY('POINT', 4326), allowNull: true, }, ... On GET sequelize sends the geom to the client as GeoJSON: { "type":"Point", "coordinates":[11.92164103734465,57.67219297300486] } When I try to save this back PosGis errors

How to write sql for this?

泪湿孤枕 提交于 2019-12-13 08:23:54
问题 I've tables like this Customer -ID -name -address Business -ID -name -type Discount -ID -amount -BusinessID -position UsedDiscounts -CustomerID -DiscountID Business has many discounts. User has used many discounts, record of which is in UsedDiscounts. User can only use discount in order, defined by position. Discount 1, then Discount 2. So even if business has 10 discounts out, the one Customer qualifies for is Position of used discount by that business + 1. Goal: get all discounts user

Associations not working for Sequelize

落爺英雄遲暮 提交于 2019-12-13 06:16:10
问题 I run the below mutation first, creates the fish, I also created a river all ready. Why are rivers and fishes empty? Graphql: query { fishes { name species rivers { name } } river(id: 1) { name fishes { name} } } # mutation { # createFish (name: "Orange-Vall Smallmouth Yellowfish", species: "Labeobarbus aeneus", riverId: 1) { # name # rivers { # name # } # } # } The results are below: { "data": { "fishes": [ { "name": "Orange-Vall Smallmouth Yellowfish", "species": "Labeobarbus aeneus",

Use multiple datastore connections with Sequelize

一世执手 提交于 2019-12-13 06:12:50
问题 I've defined 2 connections in the /config/connections.js file: monolithMysql: { user: 'store_app', database: 'store', dialect: 'mysql', options: { dialect: 'mysql', host: 'dockerhost', port: 3306, logging: console.log } }, postgres: { user: 'user_app', database: 'user_authentication', dialect: 'postgres', options: { dialect: 'postgres', host: 'dockerhost', port: 8201, logging: console.log } } and in the different models I've put the property connection , so that they're distinguished, as

TypeError: object is not a function when defining models in NodeJs using Sequelize

耗尽温柔 提交于 2019-12-13 05:12:52
问题 This is my managedb.js var Sequelize = require('sequelize-postgres').sequelize; var postgres = require('sequelize-postgres').postgres; var pg = require('pg'); var db = new Sequelize('tesf3', 'postgres', 'postgres', { dialect: 'postgres', port: '5432', omitNull: true }); module.exports.db = db; var Link = db.import(__dirname + '/lib/link/models').Link; var LinkUser = db.import(__dirname + '/lib/link/models').LinkUser; module.exports.Link = Link; module.exports.LinkUser = LinkUser; This is my