sequelize.js

Is there a shortcut in Sequelize for “user.setGroups()” when I have all the group ids?

╄→гoц情女王★ 提交于 2019-12-25 04:24:24
问题 In Sequelize, if I have a simple parent-child relationship I can set the foreignKey column without the whole object: Chapter.belongsTo(Book); // this works, but I had to query the DB for the 'book' object return Chapter.create({title: 'The Title'}).then(function(chapter) { return chapter.setBook(book); } The above generates two SQL statements, one to INSERT into the chapters table and one to UPDATE the foreignKey. // this also works, if I happen to know the book ID already return Chapter

Sequlize js / express js / node js how to change the date format

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-25 03:17:51
问题 When I see the dates stored in my database. This is normal . The date and the time that's all. But when I run a get request to get the data. THIS FORMAT IS NOT SAME AS THE FORMAT THAT STORED IN THE DATABASE . Why could this happen? 回答1: I think you can use moment.js for this kind of work on client or on server 回答2: You have selected a data type timestamp with timezone in database that's why it giving you time with timezone 回答3: THIS FORMAT IS NOT SAME AS THE FORMAT THAT STORED IN THE DATABASE

Node.js Sequelize findAll() column of included table model

萝らか妹 提交于 2019-12-25 02:21:35
问题 I'm trying to search for the following condition in a merged table between two tables. It should collect and return records that has the buyer 'alex' or seller 'alex' . The buyer exists in Chat table and seller exists in Market table which I have included as shown below. However, I am unable to get it to work. Any ideas are welcome. Chat.findAll({ where: { buyer: 'alex', seller: 'alex' }, include: [{ model: Market, required: true }] }) 回答1: The seller has to be inside Market Chat.findAll({

Requests can only be made in the LoggedIn state, not the Connecting state

99封情书 提交于 2019-12-25 01:53:20
问题 I am trying to connect to SQL Server (2016) using the "tedious" javascript library - I see a few of us had the same issue but not many of them had the question resolved - can you'll please let me know what I am doing wrong here? To give a background in short, I am spinning up my ApolloServer ( GraphQL - ) to build my schemas and have apollo server talk to my SQL Server and display it on my front end using apollo client. I am able to get my ApolloServer running - but when I try to connect to

Add transaction to sequelize create module

冷暖自知 提交于 2019-12-25 01:45:57
问题 I'm starting with sequelize to create an API and I'm facing an issue with transactions. My sequelize database configuration looks like this: var Sequelize = require('sequelize'); var sequelize = new Sequelize(CONFIG.database, env.user, env.password, { host: env.host, dialect: env.dialect, port: env.port, operatorsAliases: false }); var db = {}; fs.readdirSync(__dirname).filter(function (file) { return (file.indexOf('.') !== 0) && (file !== 'index.js'); }).forEach(function (file) { var model =

Change column name Sequilize

孤人 提交于 2019-12-25 01:40:37
问题 I want to change default column name in my final output which comes from Mysql database when i am accessing database using NodeJS and Sequelize connection. I am connecting using following code:- import Sequelize from "sequelize"; let dbConnection = new Sequelize('DB', 'abc', 'password', { host: '127.0.0.1', port: 4242, dialect: 'mysql', dialectOptions: { requestTimeout: 0, }, }); const Listing = dbConnection.define('TableName', { tour_title: { type: Sequelize.STRING, } }, { freezeTableName:

My database in not updating in Sequelize

送分小仙女□ 提交于 2019-12-25 01:18:31
问题 i am trying to use this code to update my values but when i res.json it gives me [0] any one who can help me with this problem. Thanks in advance. var condition={ where: {id:req.params.id} }; var values={ title:req.body.title, slug:req.body.slug, content:req.body.content }; options={multi:true}; var errors = req.validationErrors(); if (errors) { res.render('admin/edit_page', { errors: errors, title: title, slug: slug, content: content, id:id }); } else { // models.Page.find({ // where: { //

Node Sequelize - insert date “as is” without converting to UTC

僤鯓⒐⒋嵵緔 提交于 2019-12-25 00:33:15
问题 Im trying to run a simple query like Insert into table (somedate) values ('2018-06-11 23:59:00') but Sequelize executes it as Insert into table (somedate) values ('2018-06-12 02:59:00') Is there an option to set the date "as is" without converting or changing it in any way? 回答1: You can actually tell sequelize not to convert it to UTC while reading and you can also provide a time zone for while writing const sequelize = new Sequelize('db_name', 'postgres', 'postgres', { host: '127.0.0.1',

Using Sequelize with 1:M associations

非 Y 不嫁゛ 提交于 2019-12-24 20:56:45
问题 I'm developing a simple API using MySQL and Node for the backend and Sequelize to handle the database operations. The user has to be able to generate time intervals according to a template, which will specify the starting hour, the finishing hour and the duration of each interval in minutes. For that, I've created 2 tables: TEMPLATE and TEMPLATE_HOURS which have a 1:M relationship. Graphically: I'd like to avoid raw SQL queries as much as possible, and I'd like to know if there's a way to

sequelize Not unique table/alias

倾然丶 夕夏残阳落幕 提交于 2019-12-24 20:49:16
问题 Dears am getting a problem because included join a table throw another table then i include it immediately The (User) table should return provider name if i access the (User) table through (Provider) if included the (User) table imdditly that's mean getting the customer name but i get the below error ER_NONUNIQ_TABLE: Not unique table/alias: 'Provider.User' Code : models.Order.findOne({ where: { id: req.params.id },attributes: ['orderStatus','id','serviceId','providerId','orderDescription',