sequelize.js

Connect to a local SQL Server db with sequelize

柔情痞子 提交于 2019-12-30 13:19:52
问题 Having completed the SQL Server installer, the given connection string is Server=localhost\MSSQLSERVER01;Database=master;Trusted_Connection=True; , which seems like a strange format, and if I try to connect to the db with sequelize using that connection string: var sequelize = new Sequelize(process.env.DB_STRING); I get the error: TypeError: Cannot read property 'replace' of null at new Sequelize (C:\Users\George\Source\Repos\TestProj\node_modules\sequelize\lib\sequelize.js:132:40) at Object.

Sequelize - SQL Server - order by for association tables

拜拜、爱过 提交于 2019-12-30 10:37:21
问题 I have 3 tables such as user , userProfile and userProfileImages . User is mapping with userPrfoile as has many and userProfile is mapping with userProfileImages as has many. I need to write the order by query in userProfileImages , I tried as below, but no luck. User.findById(uID, { include: [ model: sequelize.models.userProfile as: userProfile, include: [ { model: sequelize.models.userProfileImages, as: 'profileImages', } ], order: [[sequelize.models.userProfileImages.id, "desc"]] // order:

How do plurals work in Sequelize?

…衆ロ難τιáo~ 提交于 2019-12-30 07:44:05
问题 While using Sequelize and reading the Sequelize docs, I observed that sometimes model names are used in singular and sometimes in plural. Some methods automatically added to models by associations have the singular form and some have the plural form. 1. How does Sequelize compute the plurals? Does it simply append an "s" to the string? 2. What if I want to use a noun with an irregular plural, such as "Person"? 3. When defining an instance, should I use the singular or the plural form? 4. When

Setting all queries to raw = true sequelize

泄露秘密 提交于 2019-12-30 03:19:22
问题 I really like using sequelize as my ORM for my node application, but right now, I am kind of irritated when they are passing DAO objects by default when you query. How can I set the raw option to true all the time? 回答1: According to the doc : If you do not provide other arguments than the SQL, raw will be assumed to the true, and sequelize will not try to do any formatting to the results of the query. That being said : The Sequelize object has a [options.query={}] optional parameter to set

Node.js 7 how to use sequelize transaction with async / await?

血红的双手。 提交于 2019-12-29 10:16:02
问题 Node.js 7 and up already support async/await syntax. How should I use async/await with sequelize transactions? 回答1: let transaction; try { // get transaction transaction = await sequelize.transaction(); // step 1 await Model.destroy({where: {id}, transaction}); // step 2 await Model.create({}, {transaction}); // step 3 await Model.update({}, {where: {id}, transaction }); // commit await transaction.commit(); } catch (err) { // Rollback transaction only if the transaction object is defined if

Node.js 7 how to use sequelize transaction with async / await?

拜拜、爱过 提交于 2019-12-29 10:15:25
问题 Node.js 7 and up already support async/await syntax. How should I use async/await with sequelize transactions? 回答1: let transaction; try { // get transaction transaction = await sequelize.transaction(); // step 1 await Model.destroy({where: {id}, transaction}); // step 2 await Model.create({}, {transaction}); // step 3 await Model.update({}, {where: {id}, transaction }); // commit await transaction.commit(); } catch (err) { // Rollback transaction only if the transaction object is defined if

Sequelize model error-tring to make model in sequelize and getting this error

放肆的年华 提交于 2019-12-25 09:33:28
问题 Error 471--cannot find module! This is the model I am tring to write.T have data is already in mysql. Tring to connect from sequilize. I deleted all node module and tried again,nothing is working.Please suggest something. module.exports = function(sequelize,dataTypes) { var calender = sequelize.define("calender",{ listing_id:DATATYPE.INTEGER, listdate:DATATYPE.DATE, available:DATATYPE.TEXT, price:DATATYPE.TEXT }); return calender; }; This is the code now this is the error module.js:471 throw

Sequelize - Associating 4 tables

ぐ巨炮叔叔 提交于 2019-12-25 09:17:13
问题 Am trying to associate 4 tables. Tasks, TaskQuestions, Questions and Options. My models are as follows Tasks model: var Sequelize = require('sequelize'); module.exports = function(sequelize, DataTypes) { var Task = sequelize.define('Task', { task_id: { type: Sequelize.STRING, primaryKey: true }, task_name: { type: Sequelize.STRING, allowNull: true }, task_description: { type: Sequelize.STRING, allowNull: true } },{ classMethods: { associate: function(models) { Task.belongsToMany(models

Webpack help - add hot loading and source mapping to a React / Node Project

不羁的心 提交于 2019-12-25 08:32:17
问题 I'm a webpack newbie. I'm trying to add React to a simple Node project but I've only ever used React with a pre set up webpack dev server and not with another server. Webpack runs it's own node server so this poses one problem for me. Here's what I need help with: How do I add hot loading and source mapping if I'm using Express? How can I add a global Bootstrap css from my public folder with webpack to this project (is there a way to do that kinda of how I did this with the js files and html

DateTime conversion failed with sequelise inserting a SQL Server record

人盡茶涼 提交于 2019-12-25 05:43:08
问题 When adding a new record into my database I get the error: Conversion failed when converting date and/or time from character string The datetime it tries to insert is: 2015-10-05 21:43:57.000 +00:00 It seems that Sequelise also inserts the timezone. I tried setting the "timezone" to an empty string but this didn't help. How can I insert a valid SQL Server DATETIME with sequelize? Model: RegDate : { type : Tedious.TYPES.DateTime, defaultValue: Sequelize.NOW } 回答1: Change the Column data type