sequelize.js

sequelize for NodeJS: are these features supported?

风流意气都作罢 提交于 2019-12-05 10:59:53
Here are some questions about features supported by sequelize ( sequelize project site ) that I would like to clear up before deciding whether or not to use it: Chaining (efficiency): when chaining multiple queries, are these collected into one request to the database (as a batch of operations), or is each one sent separately? Chaining (success/error): when chaining multiple queries, when is the success event emitted and what happens on error? Is "success" emitted only if all operations succeeded? And if there was an error, does it rollback all operations (i.e. are the chained operations

How can I do a group by across 3 tables with Sequelize?

主宰稳场 提交于 2019-12-05 10:49:35
My models are: module.exports = function(sequelize, DataTypes) { var CommitFileStatistic; return CommitFileStatistic = sequelize.define('CommitFileStatistic', { additions: { type: DataTypes.INTEGER, allowNull: false }, deletions: { type: DataTypes.INTEGER, allowNull: false }, status: { type: DataTypes.STRING, allowNull: false }, fileSize: { type: DataTypes.INTEGER, allowNull: true }, levenshteinDelta: { type: DataTypes.INTEGER, allowNull: true }, fileHash: { type: DataTypes.STRING, allowNull: true } }, { classMethods: { associate: function(models) { CommitFileStatistic.belongsTo(models.Commit)

Sequelize findOrCreate giving me a SequelizeUniqueConstraintError: Validation error

不想你离开。 提交于 2019-12-05 09:46:28
so I am trying to chain multiple sequelize requests together - to check if a grant exists in our database. However when I'm using the sequelize findOrCreate method I get a SequelizeUniqueConstraintError: Validation error and I can't figure out why. This is my fund model. module.exports = function(sequelize, DataTypes) { var Fund = sequelize.define("funds", { id: { type: DataTypes.INTEGER, field: 'id', primaryKey: true, unique: true, autoIncrement: true, }, title: { type: DataTypes.TEXT, field: 'title' }, tags: { type: DataTypes.ARRAY(DataTypes.TEXT), field: 'tags' }, minimum_age: { type:

How to query many to many relation in sequelize

我的梦境 提交于 2019-12-05 09:39:41
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 works just fine, table is created and with include im getting users inside of event as participants.

Sequelize associations - please use promise-style instead

China☆狼群 提交于 2019-12-05 08:11:42
I'm trying to join 3 tables together Products , Suppliers and Categories and then get row with SupplierID = 13 . I have read How to implement many to many association in sequelize , there is explained how to associate 0:M . DB model: Code: var Sequelize = require('sequelize') var sequelize = new Sequelize('northwind', 'nodejs', 'nodejs', {dialect: 'mysql',}) var Project = require('sequelize-import')(__dirname + '/models', sequelize, { exclude: ['index.js'] }); Project.Suppliers.hasMany(Project.Products, {foreignKey: 'SupplierID'}); Project.Products.belongsTo(Project.Suppliers, {foreignKey:

Relations in sqlize / hasOne does not work

旧街凉风 提交于 2019-12-05 08:06:10
问题 I am trying to create 1:1 relation between table of shops and product. Each product should have an foreign key of shop table and each shop should have foreign key of product. i have defined those two tables. module.exports = function( sequelize , DataTypes ){ var shops = sequelize.define('shops',{ id: { type: DataTypes.INTEGER, allowNull:false, primaryKey:true, autoIncrement:true }, name:{ type:DataTypes.STRING, allowNull:false }, address:{ type: DataTypes.STRING, allowNull:false }, web:{

How to call a MSSQL Stored Procedure using Sequelize?

我的梦境 提交于 2019-12-05 07:54:58
I am struggling with calling a MS SQL Stored Proc using Sequelize. This is how i normally call the stored proc from SSMS USE [MYDB] GO DECLARE @return_value int EXEC @return_value = [dbo].[GetThings_ByLocation] @BeginDate = N'2016-06-23', @EndDate = N'2016-07-09', @LocationID = NULL SELECT 'Return Value' = @return_value GO How would i make this call using sequelize? Sequelize uses npm package Tedious ( https://www.npmjs.com/package/tedious ) to work with MS SQL. Connecting to the database is the same as others. You can use raw query to get results from stored procedures. sequelize.query(

Feathers.js / Sequelize -> Service with relations between two models

半城伤御伤魂 提交于 2019-12-05 05:49:45
I've got feathers.js functioning with mysql via sequelize. This is working, I can collect data from tables. Next step is to define 'joins' in the models. I have a table with a column 'status_id' and 'country_id'. These columns reference to an id in a metadata table. In SQL I would right: SELECT status.description, country.description, detail FROM details INNER JOIN metadata status ON (details.status_id = status.id AND status.type = 'status' INNER JOIN metadata country ON (details.country_id =country.id AND country.type = 'country') This metadata table won't be big in this case so hence this

NodeJS Sequelize and FindAll with Include and constraints

怎甘沉沦 提交于 2019-12-05 05:23:04
问题 I am trying to use the Include capabilities in the Find all to Eager load the data i need in a single query. My issue is that all the includes are LEFT OUTER JOIN ... which is good but i am not seeing a way to add additional constraints to that LEFT OUTER JOIN. My query would look something like: Matches.findAll( {where: ["match.isPublished = ?", true], include: [RoundMaps, Locations, {model: MemberMaps, as: "MemberMaps", where: ["memberMaps.memberUUID = ?", authenticatedUser.uuid]}]}) But

Sequelize hasMany through another table

巧了我就是萌 提交于 2019-12-05 04:28:50
Okay so i have the following three models Module: var Module = sequelize.define('module', { id: DataTypes.INTEGER, name: DataTypes.STRING, description: DataTypes.STRING, category_id: DataTypes.STRING, module_type_id: DataTypes.STRING, gives_score: DataTypes.INTEGER, duration: DataTypes.STRING, price: DataTypes.STRING }, { freezeTableName: true} ) Competence: Competence = sequelize.define('competence', { id: DataTypes.INTEGER, name: DataTypes.STRING, organization_id: DataTypes.INTEGER, competence_type_id: DataTypes.INTEGER },{freezeTableName:true}) Module_has_competence: Module_has_competence =