sequelize.js

Unknown column 'getContent.movie_id' in 'field list

好久不见. 提交于 2019-12-13 03:55:03
问题 my whole schema const Films = new GraphQLObjectType({ name: 'films', interfaces: () => [MovieStream], fields: () => ({ movie_id: { type: GraphQLString, }, id:{ type: GraphQLID }, name: { type: GraphQLString, }, }) }) Films._typeConfig = { sqlTable: "films", uniqueKey: 'id', } const MovieStream = new GraphQLInterfaceType({ name: 'MovieStream', fields: () => ({ id: { type: GraphQLID, }, movie_id: { type: GraphQLString, }, }) }) MovieStream._typeConfig = { sqlTable: "movie_streams", uniqueKey:

Self referring foreign key in sequlize js

六眼飞鱼酱① 提交于 2019-12-13 03:48:08
问题 I have a model employee (id,first_name,last_name,manager_id) Here the manager_id is a self refering foreign key where it refers to the id column of the same table. How do I implement such a use case in sequelize. I tried this and this is not working employee.belongsTo(models.employee, { foreignKey: 'manager_id' }), 回答1: You can define association like : employee.belongsTo(employee, {as: "Manager"}); employee.hasMany(employee, { as: "Employee", foreignKey: "manager_id", useJunctionTable: false

How to read and store datetime as is from javascript to mysql

巧了我就是萌 提交于 2019-12-13 03:46:08
问题 I am building an application node.js where a user creates a record with a field named tour date and time. I am using daterangepicker plugin to show the date and time dropdown window. Once the user saves the record it is saved in the MySQL table as datetime field. Then I am using fullcalendar to display all the tour dates for a given month-year. But here is the problem. Lets say I select 28/11/2018 6:30 PM as the tour date and time. In the daterange picker it gets saved as 2018-11-28 18:30 $(

My Firebase cloud functions giving SequelizeConnectionError: connect ETIMEDOUT error whenever I query my MySql DB

老子叫甜甜 提交于 2019-12-13 03:41:50
问题 Problem Description: I am using Sequalize ORM and my Firebase cloud functions giving SequelizeConnectionError: connect ETIMEDOUT error whenever I query my MySql DB. It works fine when functions are running on localhost via Firebase cli. Below is the Sequalize connection method. Code Snippet var sequelize = new Sequelize('dbname, 'username', 'password', { host: "host", dialect: 'mysql', define: { paranoid: true }, pool: { max: 5, min: 0, acquire: 30000, idle: 1 }, operatorsAliases: false}) The

Sequelize mssql: order by primary key and limit

让人想犯罪 __ 提交于 2019-12-12 19:21:21
问题 I want to run a query with results sort using the primary key and also limit the number of return results. For example: return Things.findAll({ attributes: [ 'id', 'status', 'otherField' ], limit: 2, order: [['id', 'DESC']] }) when the query is build, it generate the following SQL statement: ... ORDER BY [Source].[id] DESC, [id] OFFSET 0 ROWS FETCH NEXT 2 ROWS ONLY Because id is the primary key and the sort parameter is also id I get the following error: 'A column has been specified more than

Unable to create child instance for one-to-many on Sequelize.js

痴心易碎 提交于 2019-12-12 19:16:40
问题 I am creating parent and child instance using sequlize, but it throws following error. Site.hasMany(Group,{as:'groups'}); Group.belongsTo(Site); //not working Site.create(siteData).then((site)=>{ site.addGroups(groupData).then(()=>{ //also tried addGroup next(); }); }); //this works Site.create(siteData).then((site)=>{ groupData.SiteId=site.id; Group.create(groupData).then(()=>{ next(); }); }); Error: Unhandled rejection TypeError: val.replace is not a function at Object.SqlString.escape (c:

sequelize : cannot seed association values in DB table

拈花ヽ惹草 提交于 2019-12-12 18:15:14
问题 I am trying to seed an association into my db using sequelize, the tables being: Users and Admins. For this I am relying on this answer on the forum. so here is my seed: 'use strict'; const bcrypt = require('bcryptjs') module.exports = { up: async (queryInterface, Sequelize) => { queryInterface.bulkInsert('Users', [{ firstName: 'someone', lastName: 'awesome', email: 'someone@somewhere.com', password: bcrypt.hashSync('helloWorld', 8), type: 'admin', createdAt: new Date(), updatedAt: new Date()

exporting a module in a callback function?

别来无恙 提交于 2019-12-12 16:26:52
问题 is there a way to export some variables that are inside a callback function? for example, if i need to use room.room_id in another file, what should i do? i tried module.exports.roomId = room.room_id but roomId in another file appeared to be undefined.thanks! var Room = require('../models/database').Room exports.create = function (req, res) { Room .create({ room_name: req.body.roomName }) .complete(function () { Room .find({where: {room_name: req.body.roomName}}) .success(function (room) { //

How to recreate database from old database using sequelize in node.js

限于喜欢 提交于 2019-12-12 13:19:47
问题 I am facing some problem with sequelize while i keep {force: true} . In this case old data dropped and new database is created and my saved data get lost. I want to create new database with old values. Can that possible with sequelize in node.js 回答1: When you have database with some data and want to make some changes in db you have two possibilities: as you said recreate db, but this will drop tables (erase your data). use migrations (you can read about it here) Migrations allow you to to don

Using replacements with a raw Sequelize query: avoiding single quotes?

可紊 提交于 2019-12-12 12:19:12
问题 This probably has a really easy answer but I'm not seeing it. I want to do a raw query using Sequelize: var sequelize = require('sequelize'); sequelize .query("LOAD DATA LOCAL INFILE :file INTO TABLE :table FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\n';", null, {raw:true}, {file: datasetPath, table: "dataset_" + datasetName}) The issue is that the replacement string includes single quotes for both the :file replacement (which is good because it's a path) and the :table