Recently, I've been working on writing unit tests for Sequelize with a Postgres database and using Jest for testing. While trying to get the following code to work: test('email field only takes valid emails', () => { expect.assertions( ...
I have a scenario where I need to add multiple users in my database by uploading a CSV file. The CSV file contains three columns: first_name, last_name, email. How can I achieve this using my existing user model and controller? Model.js const User = sequ ...
Currently, I am utilizing Sequelize for an express project that is in progress. I have encountered a situation where I need to retrieve a concatenated result of two columns in a single query. For example: SELECT first_name || ' ' || last_name ...
I'm having trouble deploying my Node.js express app to vercel. I keep encountering this error message: "This serverless function has crashed." I can't seem to pinpoint the issue. In my root project folder, I have an index.js file where I initialize the ap ...
Recently, I encountered a server error issue while requesting data from the server using my React client. Unfortunately, the server failed to respond properly and I traced the problem back to my Sequelize Database. exports.createMemeber = (req, res) => ...
Currently, I am working on a project that allows users to ask and answer questions. However, I am facing an issue with the comments field. The comments table displays data correctly and can delete entries, but I need to find a way to count the total number ...
I've been working on a feature in my Express router that updates data in a MySQL schema for 'members' of clubs. The members table has various columns like member_id, forename, surname, address, etc. I've successfully created an Express route using Sequeliz ...
I am struggling to access the findById function of CRUDService in ItemService. While I am able to get a response from the readAll function, I am facing issues with the findById function. It seems that the dao object being passed to CRUDService from ItemSer ...
As a beginner in javascript, I wanted to confirm if my code is appropriate. I am currently using JavaScript to handle a PUT request. My main goal is to return the updated Sequelize model as a response and then redirect the user back to the local /. Can I ...
When attempting to run the setup, I encountered the following error: npm run setup **Sequelize CLI [Node: 12.14.1, CLI: 5.5.1, ORM: 5.21.6] Loaded configuration file "src\config\database.json". Using environment "development" ...
I have a table containing 20 elements. Is there a more concise way to input data into Sequelize without listing each element individually like this: Sequelize.create({ elem1: req.body.eleme1, elem2: req.body.eleme2, elem3: req.body.eleme3, elem4: ...
I have successfully implemented 3 SQL tables with Sequalize, and here are the schemas: Loans id: DataTypes.INTEGER, book_id: DataTypes.INTEGER, patron_id: DataTypes.INTEGER, loaned_on: DataTypes.DATE, return_by: DataTypes.DATE, returned_on: DataTypes.DA ...
My experience with Typescript is relatively new, and I am completely unfamiliar with Sequelize. Currently, I have only made changes to the postgres config in the .config/config file to add the dev db configuration: export const config = { "dev" ...
Having an issue with the update method in MySQL ORM. User.update({ ResetPasswordToken : resetPasswordToken },{ where: { UserName: 'testuser' } }) Receive this Sequelize Log: Running query: UPDATE Users SET ResetPasswordToken=?,updatedAt=? WHE ...
I encountered some issues while trying to utilize the eager loading feature for M:N relations. The relationship in the user model: User.belongsToMany(models.rol, { through: { model: models['usuario_rol'] }, as: { plural: ...
Below is the stored procedure I have written: CREATE OR REPLACE FUNCTION GetAllEmployee() RETURNS setof "Employees" AS $BODY$ BEGIN RETURN QUERY select * from "Employees"; END; $BODY$ LANGUAGE plpgsql; I am attempting to execute this stored procedure fro ...
I'm having some trouble with a piece of code. Here's my signup function : exports.signup = (req, res) => { // Adding User to Database console.log("Processing func -> SignUp"); User.create({ name: req.body.name, username: req.body.username, ...
I am attempting to establish a 1:1 relationship between two tables. The RefreshToken table will contain two foreign keys connected to the Users table, which can be seen in this image: https://i.stack.imgur.com/B2fcU.png To generate my sequelize models, I ...
After successfully creating a user with sequelize, I encountered an issue where querying any user resulted in an "Invalid value" error. The Sequelize User model is defined as follows: import DataTypes from "sequelize"; import bcrypt from "b ...
I am currently working on a Node.js/Express application that communicates with a MySQL server using Sequelize. I want to make sure that a particular database is created before the app starts running when using npm start. I think I need to create a one-ti ...
When attempting to access an object, I am encountering an issue where it is returning as undefined, despite having created the object earlier in the statement and successfully accessing it from a separate then statement. Here is a breakdown of the logic b ...
Embarking on my first experience with Sequelize and MySQL, I am seeking guidance on inserting data into two tables with a foreign key relationship. Let's delve into the structure of the entities - bookingDescription and bookingSummary. //bookingSummary mo ...
I am currently in the process of developing a discord bot, which includes 2 slash commands. One command is called /setup, used for adding the guildId and an adminChannel to a database. The other command is named /onduty, which is used for adding the user, ...
My attempt to conceal my database password using a .env file is failing. The compiler seems unable to locate the password. You can observe the environmental variable, PWD, designated for the database password in the .env file. PWD = 0000 SECRET = mySecre ...
I have a simple table set up like this: const Sequelize = require('sequelize'); const sequelize = require('../../util/database'); const Speed = sequelize.define('speed', { id: {type: Sequelize.INTEGER, autoIncrement: true ...
Currently, I'm retrieving data from a MYSQL database by executing the following SQL command: SELECT GROUP_CONCAT(MemberMemberId SEPARATOR ',') AS MemberMemberId FROM member_events WHERE event_date = "2000-01-01" AND EventEventId= 1; ...
In my NodeJS/Express/Angular7 application with Sequelize 5 and MySQL, I have a table of images connected to a table of keywords through a join table in a bidirectional hasMany relationship. My goal is to retrieve all images that contain keyword IDs within ...
The Sequelize version is 6.6.2 Mysql2 version: 2.2.5 I have constructed my Model in the following manner and defined methods as shown: interface IUserAttributes { user_id: number; logon_name: string; user_password: string; full_name: string; di ...
Seeking guidance on selecting the appropriate ON clause for a join. I am working with two tables - packages and users. The package table contains two fields/columns (owner_id, helper_id) that serve as foreign keys to the same users table. My goal is to per ...
One of the tasks involves checking if the date entered by the user falls within the range specified in the start_Date and end_Date columns in a MySQL database. This needs to be implemented using NodeJS. ...
So I have been working on developing a NodeJs application on my Windows machine. Recently, I decided to deploy it on Azure cloud and set up a SQL Server instance. During the testing phase, where the node app was running locally and the SQL Server was conn ...
Having two tables in my database, Users and Profile_Education. The Users data is obtained from an auth0/login form, while the Profile_Education is fetched from a node.js/express API. I am looking to establish a foreign key in Profile_Education to link it w ...
Currently, I am integrating passportjs for authenticating my express app. Even though I have followed a tutorial closely, I keep encountering issues with session authentication. In my primary workflow, I authenticate users using the local strategy. passp ...
After successfully connecting to my AWS RDS PostgreSQL using the initial code, I decided to switch to Sequelize. Here is the new code that I tried: import "dotenv/config.js"; import Sequelize from "sequelize"; const dbConfig = { HOST ...
Within my express application, I utilize Sequelize for database management. Below is the bootstrap code that I use: db.sequelize .sync({ force: true}) .complete(function(err) { if (err) { throw err[0]; } else { //seed requi ...
I am working with the Sequelize ORM within a Node/Express environment. My database has two tables: one for Users and another for Items. The Item table includes a foreign key that is linked to the UserId in the User table. Whenever I attempt to create an ...
I have three models that extend Sequelize.Model and I have generated migrations for them. The associations are set up as follows: Cat Cat.belongsToMany(Treat, { as: 'treats', through: 'CatTreat', foreignKey: 'cat_id', } ...
I have a nodejs express app where I am utilizing a library that operates on a typical callback interface for executing functions. However, my persistence layer is set up using a promise-based approach. The following code snippet is causing me some concern: ...
I am working with Sequelize dependency I need to retrieve data from the parent table. In my database, there is a table called tblroute which has an association with routedetails. The foreign key in routedetails corresponds to the id of tblroute. router.g ...
I've come across this issue several times on various forums but haven't been able to resolve it yet. My setup involves Express and PostgreSQL with Sequelize ORM. The problem lies in the one-to-one relationship between two models: Campus and Acad ...
Despite poring through the sequelize documentation and conducting extensive searches online, I have yet to come across a satisfactory answer: Why is BuildOptions necessary and what impact does it have on the created model? import { Sequelize, Model, Data ...
As someone who is just starting out with automated testing, I've been thinking about the best approach to write tests for my database. The project I'm currently involved in utilizes PostgreSQL with Sequelize as the ORM on a Node.JS platform. Additionally ...
I'm currently using the node sequelize library to handle data insertion in a postgress database. Below is the user model defined in the Users.ts file: export class User extends Sequelize.Model { public id!: number; public name: string; public ...
Hey there! I'm currently working on an ExpressJS RESTapi project that uses SequlizeJS as its ORM for a MySQL database. I need to figure out how to create a backup of the database and store it locally. Any suggestions on how to accomplish this within E ...
Currently, I am attempting to execute the TIMESTAMPDIFF() function on a column in a joined table. My current implementation looks like this: Project .findAll({ include: [Note, Link], attributes: [ [sequelize.fn('TIMESTAMPDIFF', ...
I've set up a database table to store information about people and their relationships, allowing for self-association of parents, children, cousins, etc. const People = sequelize.define('People', { gender: Sequelize.STRING, name: Sequelize.STRING, a ...
Currently, I am developing an application using Node.js, specifically Express server-side and Vue client-side, with SQLite + Sequelize for managing the database. One of the features of this app is that a user can create a post. While this functionality ex ...
I have a React front end with Node backend and I'm using sequelize for mySQL. Within my database, there is a table called "company" with a column named "logo" where images are stored. How can I dynamically generate a URL for the img tag in order to di ...
I have a question about adding multiple foreign keys to an object. Specifically, I have a scenario with Complaints that involve 2 Transports. One is used to track goods being sent back, and the other is used for goods being resent to the customer. @Table({ ...
I currently have a table with a unique constraint on a field along with paranoid enabled. For example, in the scenario presented below, the brand name serves as the unique value. class Brand extends Model { static init(sequelize) { retu ...
select reservation_datetime from LectureReservation Inner Join Lecture On LectureReservation.lecture_id = Lecture.id Where Lecture.mentor_id = 1 This is my initial query and now I am attempting to convert it into a sequelize format like: if (req.params ...
I'm currently working with Nodejs and I have a query that retrieves a count. I need to check if the count > 0 in order to return true, otherwise false. However, I am facing difficulties handling this in Nodejs. Below is the code snippet I am struggling ...
I'm facing a challenge while attempting to run my web app on a Windows Azure App Service. The back-end of my app is developed in Node.js/Express using TypeScript (compiled with tsc, not Webpack) and integrates Sequelize to connect to a SQLite 3 database s ...
I've been working on a project using React, Node, Sequelize, and Redux for a while now, and everything was running smoothly. However, the other day I decided to update some of my Node packages, as I usually do, but after running npm update --save/--sa ...
For the past few years, I have been developing an ExpressJS server application for internal use at my workplace. This application serves as a clinical decision support tool utilized in various hospitals. As the application has grown significantly in size, ...
I am in the process of developing an application that involves updating posts from the past. A dedicated page has been created for this purpose along with a corresponding route. app.post("/posts/:id/update", function(req, res){ Post.findAll({ ...
I am facing a task where I have an array of items that need to be created in the database. My approach is to check each insertion for success. If successful, I will add the item with a flag indicating success as true in a new array (results) in JSON forma ...
I need to efficiently store data across multiple separate tables in Postgres within a single API call. While I can make individual calls for each table, I am seeking advice on the best way to handle this. Any tips or suggestions would be greatly appreciate ...
I am attempting to add a new record to a MYSQL table using sequelize. After installing sequelize and mysql, I ran the following commands: npm install --save sequelize npm install --save mysql In my app.js file, I included the following: var Sequelize ...
Unexpectedly, our mocha tests come to a halt and display the following message on the console: Cannot find module `pg-native` No stack trace is provided, and mocha fails to render the usual test output. The test abruptly terminates. If I deactivate the ...
One interesting aspect of my project is the menus table, which features a one-to-many self-association. The structure looks something like this: ---Menu | '--submenu | '--submenu ---secondMenu | '--submenu ...
Using Sequelize ORM in my NODE JS and PostgreSQL setup has been great, but recently I encountered an issue. When multiple requests are made to the server concurrently, an error is thrown: ConnectionAcquireTimeoutError [SequelizeConnectionAcquireTimeoutErro ...
Is there a way to retrieve multiple results from Sequelize and store them in an array? For example, I want to fetch all the values in the name field from the test table and display them in the console. This is what I tried: test.findAll().them(function(re ...
Can someone help me with a query that will retrieve a specific column from the database and return it in this format: [ { "tenantName": "H&M" }, { "tenantName": "McDonalds" } ] I would like to transform ...
Consider a scenario where we have a "shirt" table and a "john" table. When using Sequelize, if we define db.john.hasMany(db.shirt), a foreign key is created in the "shirt" table. Similarly, when we use db.shirt.belongsTo(db.john), a foreign key for "joh ...
How can I append a value to the variable in Sequelize? let where = { [Sequelize.Op.or]:[ { category: { [Sequelize.Op.like]: '%some text%' } }, { category: { ...
I am working on a basic REST API using Typescript, Koa, and Sequelize. If the client sends an invalid PUT request with empty fields for "title" or "author", it currently returns a 500 error. I would prefer to respond with a '400 Bad Request' ins ...
I am working with 2 tables, physical-assessment-exercise and physical-assessment-lesson. In the file psysical-assessment-lesson.model.js: const Sequelize = require('sequelize'); const DataTypes = Sequelize.DataTypes; module.exports = function ( ...
Currently, as part of my Node.js application, I am using Sequelize to develop a user registration feature. However, I seem to be facing an issue when attempting to verify the existence of a user based on their email address. The error that keeps popping up ...
Currently, I am working on a project using node.js with express framework and mysql with sequelize ORM. In this method, an API is utilized to retrieve a large amount of data which is then stored in a database table. The data is in CSV format and I am util ...
My experience with sequelize is limited and I am having trouble understanding certain aspects. Despite my efforts to search for more information, I couldn't find anything specific that addresses my confusion. // API Method function SeederApi(req: Request, ...
Looking for a Query Function that allows dynamic data retrieval with FindAll Query For instance, if I need to fetch data like age>5, I want to be able to do so using query parameters directly This is just an illustration In essence, I require a query ...
I am looking to create a straightforward web form that allows users to input a person's first name, last name, and select multiple groups for that individual (for now, just one). Currently, I am utilizing node.js and sequelize to store the person dat ...
Is there a way to enable users to click on the default avatar and upload their own image? Although I can successfully upload files to the database, I'm facing issues in accessing them from the client side. It seems like I might not be storing them correctl ...
Currently, I am in the process of learning about "Sequelize". After going through the documentation, I stumbled upon this code snippet elsewhere. Model = require('../models/Salesman') module.exports.creareSalesman = (req, res, next) => { Model.create(re ...