sequelize.js

sequelize-nodejs how do I fetch data from other fields of a table

[亡魂溺海] 提交于 2019-12-22 12:28:00
问题 Hi I'm developing a chat app and just want to know how do I fetch data from other fields of a table on mysqldatabase using sequelize because I'm totally new on this. Here is how I tried to do it: io.on('connection', function(socket){ // Send all previously sent messages for( i in messages ) { socket.emit('chat message', messages[i]); } socket.on('chat message', function(msg){ console.log('message: ' + msg); // Push the message into the in-memory array. messages.push(msg); // Storage the

Sequelize.js join table twice using hasMany

倾然丶 夕夏残阳落幕 提交于 2019-12-22 10:43:54
问题 I am using Sequelize.js to do a double join on the same table. I have a set of Team objects and a set of Game objects. A team hasMany Games, so it would have foreign keys in the game table, but there are two teams in every game so i need to join the table twice. What is the best way to do this using the sequelize ORM. Team = sequelize.define('teams',{ name : Sequelize.STRING, location : Sequelize.STRING, }); Game = sequelize.define('games',{ homeTeamId : Sequelize.INTEGER, awayTeamId :

Sequelize joining two tables which are not associated

倖福魔咒の 提交于 2019-12-22 08:36:28
问题 I am trying to retrieve data by joining two tables which are not "associated" using a relationship. These two tables are as below: mysql> desc partner_txns; +------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+-------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | txn_id | int(11) | NO | | NULL | | | user_id | int(11) | NO | MUL | NULL | | | txn_type | varchar(1)

How to query many to many relation in sequelize

女生的网名这么多〃 提交于 2019-12-22 07:05:30
问题 I've been using feathersjs/nodejs over postgres db via sequelize. In my db i have Users table and Events table. They are twice in relation: events.belongsTo(models.users, { foreignKey: { name: 'creatorId', allowNull: false }, onDelete: 'CASCADE', as: 'creator' }); events.belongsToMany(models.users, { through: 'event_participants', as: 'participants', foreignKey: 'eventId', otherKey: 'userId' }); models.users.belongsToMany(events, { through: 'event_participants', as: 'events' }); Everything

A Sequelize column that cannot be updated

假如想象 提交于 2019-12-22 04:12:08
问题 Is it possible to create a column on a MySQL table using Sequelize that can be initialized when creating a new row, but never updated? For example, a REST service allows a user to update his profile. He can change any field except his id . I can strip the id from the request on the API route, but that's a little redundant because there are a number of different models that behave similarly. Ideally, I'd like to be able to define a constraint in Sequelize that prevents the id column from being

How to create a new Sequelize dialect, for example DB2

喜夏-厌秋 提交于 2019-12-22 03:35:19
问题 Sequelize supports five flavours of DBMS. In my project, we have a legacy database located in an IBM DB2, which is not in that list. There exists a node driver for DB2, published by IBM. Is there a documentation on how to create such a new dialect for Sequelize? Is it encouraged? 回答1: According to latest for v4.0.0 It will throw an error if you use any thing other than five specified dialects, You can change the drivers but not the dialect. 1.So you cannot do it 2. It is not encouraged var

Node + Sequelize: How to check if item exists before adding? (async confusion)

限于喜欢 提交于 2019-12-22 02:49:10
问题 I am unfortunately new to node and running into some confusion regarding the asynchronous/synchronous execution of node. I am using node, sequelize with sqlite and async.js. I have a series of Articles , each of which has a number of Authors . For each Authors in each Article , I'd like to check if the Author exists. If not, create it. The problem is, on the initial run, duplicate authors are being created, I assume due to asynchronous functionality causing an issue with checking for

Promise.all(…).spread is not a function when running promises in parallel

匆匆过客 提交于 2019-12-22 02:21:18
问题 I'm trying to run 2 promises in paralel with sequelize, and then render the results in a .ejs template, but I'm receiving this error: Promise.all(...).spread is not a function This is my code: var environment_hash = req.session.passport.user.environment_hash; var Template = require('../models/index').Template; var List = require('../models/index').List; var values = { where: { environment_hash: environment_hash, is_deleted: 0 } }; template = Template.findAll(values); list = List.findAll

How to increase max_locks_per_transaction

北慕城南 提交于 2019-12-22 01:51:37
问题 I've been performing kind of intensive schema dropping and creating over a PostgreSQL server, ERROR: out of shared memory HINT: You might need to increase max_locks_per_transaction. I need to increase max_locks_per_transaction but how can i increase it in MAC OSX 回答1: you might find ../data/postgresql.conf file, then edit with notepad, set max_locks_per_transaction = 1024 if it looks like # max_locks_per_transaction... you must remove #. it must look like that: max_locks_per_transaction =

Check mysql connection in sequelize

不想你离开。 提交于 2019-12-22 01:25:44
问题 I have a very simple program in where I create a Sequelize instance and then I perform a raw query on a mysql database. The case is that when MySql is up and running there is no problem, I can perform the query with no problems. But when MySql is not running then the query doesn't emmit any error until the query timeout has reached and then it emmits a ETIMEOUT error. But that's not really what's happening. I expect the query to emit ENOTFOUND error or something like that if mysql is not