Questions tagged [sequelize-hooks]

15 questions
9
votes
5 answers

why sequelize beforeUpdate hook doesn't work?

I have a simple user model with 2 hooks. User.beforeCreate(setSaltAndPass) User.beforeUpdate(setSaltAndPass) the first works perfectly but the beforeUpdate does not run, according to the documentation you should have no problem executing the…
3
votes
1 answer

In sequelize connection I am getting operation timeout error. How to fix this issue

I am using Sequelize ORM for connecting databases using NODE JS and PostgreSQL. When I request concurrently to the server it's throwing an error ConnectionAcquireTimeoutError [SequelizeConnectionAcquireTimeoutError]: Operation timeout. So, I search…
3
votes
1 answer

Sequelize afterCreate not firing

I am using Sequelize as an ORM with MySQL, Node and Express. When inserting a new item to 'ExpertiseField' table, I want to update a field in a different table. I'm having an issue with hooks in Sequelize, for some reason afterCreate appears to not…
JozeRi
  • 3,219
  • 6
  • 27
  • 45
2
votes
1 answer

Sequelize querying with encrypted fields using after* before* hooks

Hey there I have a question about the best way to store data encrypted in my database. I use Node.js, a MySQL database and sequelize 6.6.5 as ORM. Here's what I do: With beforeCreate and beforeUpdate hooks I'm encrypting my data before storing it…
db3000
  • 400
  • 5
  • 16
2
votes
1 answer

Sequelize hooks not triggering when updating records manually

I am new to sequelize and RDBMS, I have added sequelize hook as follows bills.afterBulkUpdate((instance, options) => { console.log(instance); }); I have questions here If I update any record in bills table manually(using DB script or query or…
Javed IN
  • 302
  • 1
  • 4
  • 12
1
vote
1 answer

Sequelize - how to get model from beforeBulkUpdate hook?

I was working on logging of the changes in my DB through sequelize hooks and I ran into an issue. You see, in instance hooks you are able to retrieve the model and its name through instance parameter like so : sequelize.beforeUpdate(instance,…
0
votes
1 answer

Sequelize - Update a date field automatically on an event

I've a login table which stores the user login details. Whenever a user changes the password, lastPasswordChange field should get updated with the date of the password change. Now I'm manually updateing the field with Date(). Is there any better way…
Sreesanth
  • 49
  • 1
  • 6
0
votes
0 answers

Sequelize async beforeCreate hook giving me an error while setting many to many association

I am using sequelize-typescript in this app and I have a model that currently is trying to hash a password before saving it account.model.ts @Table({ freezeTableName: true, tableName: 'accounts', }) export default class Account extends Model { …
0
votes
0 answers

Can i hide the Join Record using Sequelize's BelongsToMany Association's Mixin?

I am getting my Record with a normal findByPk() let paper = await models.Papers.findByPk(id, { include: [ { model: models.Users.scope('public'), // <- Just setting attributes as:…
0
votes
0 answers

Is there any way to hide some user attributes conditionally that are returned by sequelize query?

user profile table have a name, phoneNumber , isPrivate and additional attributes, If user check isPrivate to true, then if other users return any data related to this user the response shouldn't have the name and phoneNumber except the admin and…
0
votes
1 answer

How to listen for new records in database with Sequelize?

I have a PostgreSQL database with Sequelize ORM and I want to listen for new entries. How should I do? Should I use Sequelize afterCreate hook? Can someone help me?
FaFa
  • 358
  • 2
  • 16
0
votes
0 answers

Docker run for NestjS Microservice failing with error TS2307

I have hit an issue while building a docker image for a NestJS microservice. When I run npm start locally, this is response I see: 11:16:05 am - Starting compilation in watch mode... 11:16:12 am - Found 0 errors. Watching for file changes. [Nest]…
0
votes
1 answer

How to pass options to sequelize afterBulkUpdate

I'm updating user but then after i need to also update the user_profile table. The user table gets updated but in afterBulkUpdate hook the options is undefined and therefore cannot be destructured and throws an error. How can i pass options while…
K.Nehe
  • 424
  • 10
  • 22
0
votes
0 answers

how sequelize save items only after all models update

In my models I have One-To-Many relationships Team.hasMany(Player); Player.belongsTo(Team); const MyTeam = await Team.findOne({ where: { name: "chikago" }, include: Playes }); result in json like this MyTeam": { "id" : 5, "name" :…
ssdk86
  • 63
  • 2
  • 7
0
votes
1 answer

How can I automatically create a new record in a database when another one is created using Sequelize.js?

I am using Sequelize version 5 as my ORM with a User and Profile model defined. There is a one to one relationship between the two models, and I would like for a profile to be automatically created when a user is created. How can I accomplish this?…