sequelize.js

How can I set schema for all models at once at connection time for Sequelize Postgres?

孤街浪徒 提交于 2020-01-14 06:15:09
问题 I'm able to set schema for ad-hock queries with sequelize.query(` SET SCHEMA 'schema_for_client_name' `); I'm also able to set schema for individual models User.init( { userId: { type: DataTypes.INTEGER, autoIncrement: true, primaryKey: true, }, email: { type: DataTypes.STRING, allowNull: false, }, firstName: { type: DataTypes.STRING, allowNull: false, }, lastName: { type: DataTypes.STRING, allowNull: false, }, password: { type: DataTypes.STRING, allowNull: false, }, salt: { type: DataTypes

Problem coding a weak entity in sequelize

徘徊边缘 提交于 2020-01-14 06:00:51
问题 I am creating a cinema application. I have modeled the database on mySql but I am having trouble migrating it to Sequelize. I have followed the documentation but I am getting a lot of different errors. I have tried using associations and indexes (as it should be). This is the model I am trying to make. OCCUPIED_SEATS is composed of only two foreign keys and both make a unique index. OCCUPIED_SEATS : const SEATS = require("./Seats"); const SCREENING = require("./Screening"); const OCCUPIED

Sequelize belongsToMany additional attributes in join table

旧时模样 提交于 2020-01-14 03:23:24
问题 I'm having problem with an additional attribute in the join table of the belongsToMany relation. In the set or add method this attribute is not being passed to mysql. I'm following the documentation pass as "through" the attribute within the set method, but it is not working. Would anyone know what could be wrong since following the documentation is not working? Note: The registration and update of the join is correct, only the additional attribute that is not being passed to the table.

Sequelize: Parent with at least one children

一个人想着一个人 提交于 2020-01-13 16:25:37
问题 I have a relation which is roughly as follows: Parent: [id, name] Children1: [id, parent_id, name] Children2: [id, parent_id, name] Children3: [id, parent_id, name] Children4: [id, parent_id, name] Parent .hasMany -> Children1 .hasMany -> Children2 .hasMany -> Children3 .hasMany -> Children4 So, if I do: Parent->findOne({ include: [{model: Children1}, {model: Children2}] }) It will only bring Parent where there's children1 and children2 (ie, Inner join). If I do: Parent->findOne({ include: [

Sequelize Model Unit Test

孤人 提交于 2020-01-13 11:22:55
问题 I have a User sequelize model that has a beforeCreate hook that encrypts the password using bcrypyt . Bcrypyt is loaded as a dependency by the model using a require statement. Now, I'm writing my tests for my models and I want to write a test that ensures bcrypt is hashing the password on create. At the moment, I have added a setter onto the User model that sets the bcrypt object. In my tests, I can then create a spy using sinon and inject the spy using the setter and ensure it is called on

TypeError: Cannot read property 'findAll' of undefined (expressjs)

一笑奈何 提交于 2020-01-13 05:09:31
问题 TypeError: Cannot read property 'findAll' of undefined (expressjs). All functions (sequelize) are not working. All errors: Cannot read property 'sequelize method' ... module.exports = function (sequelize, DataTypes) { var User = sequelize.define('user', { email: {type: DataTypes.STRING(32), unique: true, allowNull: false}, }); return User; }; Controller: models = require('./../models'); exports.index = function (request, response, next) { models.User.findAll({attributes: ['id', 'username']});

Sequelize findAll is not a function

断了今生、忘了曾经 提交于 2020-01-12 07:51:07
问题 I'm making a project with Sequelize and I'm stucked in this step. The problem is that when I try to log in and the passport-local code is executed, when it reaches the User.findAll(...) it throws that findAll is not a function . If I make console.log(User) it shows [function]. My structure: /config/config.js /config/passport.js /models/index.js /models/nuke_users.js (generated by sequelize-auto) /index.js config.js: //Setting up the config var Sequelize = require('sequelize'); var sequelize =

Node.js: Defining Postgres Schemas in Sequelize

岁酱吖の 提交于 2020-01-12 06:16:51
问题 The Official Documentation doesn't explains clearly how define schemas for database by themselves. I'm assuming that Sequelize is more related to MySql than Postgres (where schemas are mandatory). If I've already created some schemas in Postgres, how I could sync them with Sequelize? 回答1: You can set the model with the schema using model.schema , something like: var City = sequelize.define('City', { id: { type: sequelize.Sequelize.INTEGER, primaryKey: true, autoIncrement: true, field: 'id' },

Node.js: Defining Postgres Schemas in Sequelize

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-12 06:15:46
问题 The Official Documentation doesn't explains clearly how define schemas for database by themselves. I'm assuming that Sequelize is more related to MySql than Postgres (where schemas are mandatory). If I've already created some schemas in Postgres, how I could sync them with Sequelize? 回答1: You can set the model with the schema using model.schema , something like: var City = sequelize.define('City', { id: { type: sequelize.Sequelize.INTEGER, primaryKey: true, autoIncrement: true, field: 'id' },

How to use findOrCreate in Sequelize

本小妞迷上赌 提交于 2020-01-12 03:21:28
问题 I am Sequelize beginner. I'd like to oAuth authenticate with Twitter or Facebook and want to save user information in the database. But if oAuth authentication is done on multiple sites, there is a problem that information such as userid registered in the database will duplicate with other site . In order to avoid this, I would like to do a process to update the database only when the specified userid does not already exist in the database. I knew that we could use sequelize's findOrCreate to