Questions tagged [sequelize.js]
The Sequelize library provides an ORM (Object-Relational-Mapper) for Node.js, written entirely in JavaScript. Provides easy mapping for MySQL, MariaDB, SQLite, PostgreSQL and SQL Server.
12,448
questions
-1
votes
0
answers
10
views
Id is not found when i Trying to delete data using method
3 sequelize models namely account, account type, accountgroup and want to delete all record of account type which are stored on one accountgroup but it showing id not found
This is getall data ...
0
votes
0
answers
5
views
Sequelize adds a bunch of spaces at the end of the DataTypes.CHAR
My Store.ts file:
import {DataTypes, Model, ModelAttributes} from "sequelize";
export default class Store extends Model {
declare id: number
declare name: string
declare phone: string
...
0
votes
0
answers
11
views
TypeScript complains when I define a Sequelize model with an id, but don't provide an id when calling Model.create()
I'm using the class style model declaration:
export class Supplier extends Model<InferAttributes<Supplier>, InferCreationAttributes<Supplier>> {
declare id: number
declare ...
0
votes
0
answers
9
views
NodeJs backend with Sequelize as my ORM not working
I currently have a NodeJS backend and sequelize as my ORM and postgress as my database. I will post below my file structure and can anyone tell me if what im doing is correct or not please. Would ...
-1
votes
0
answers
8
views
createMethod not working in one-Many association in sequelize
const express= require('express')
const cors = require('cors')
const bodyParser = require('body-parser')
const reviewRoute = require('./router/reviewRoute')
const sequelize = require('./util/database')...
-1
votes
0
answers
12
views
Handle replica db failure in sequelize, which is using read replication
I am using sequelize in my nodejs application and with read replica feature we are connecting both db and redirecting our read queries to replica db using this config
const sequelize = new DbSequelize(...
0
votes
0
answers
10
views
How to determine selection of an instance based on the associated instance in a 1:M relationship?
I have two models Task and TaskMember
Task
id: Primary key
added_by: Foreign key to user
title
TaskMember
id: Primary key
task_id: Foreign key to task
member_id: Foreign key to user
Both these model ...
-1
votes
1
answer
27
views
Wrong pagination in MAX() query of postgres
This is my query to fetch the latest message from each room:
SELECT MAX
( "Messages"."id" ) AS messageId,
"Rooms"."id"
FROM
"RoomUsers"
...
0
votes
0
answers
23
views
MySQL error when inserting data into JSON column ER_INVALID_JSON_CHARSET
Last Saturday I've upgraded our database into MySQL 8 since AWS is deprecating 5.7.
Everything seemed to be working at first, but now we are seeing issues in our system.
I'm using expressJS & ...
0
votes
0
answers
23
views
How to use Sequelize Transaction inside a node-schedule job?
How do I use Sequelize Transaction insde a node-schedule job?
For example I have this function here:
async doSomething(
params
) {
// Create > Transaction1
const ...
0
votes
0
answers
11
views
Why is sequelize not generating automatically my join table?
I am trying to make a many to many relationship with sequelize, nodejs, and expressjs.
I have my Sale.model.js
const { Sequelize, DataTypes } = require('sequelize');
const sequelize = require('../...
1
vote
1
answer
27
views
Postgresql: resolve a one-to-many relationship and delete given tuples, all in one query
I have a table as such:
CREATE TABLE users (id, ...)
CREATE TABLE groups (id, ...)
CREATE TABLE group_roles (group_id REFERENCES pages.id, role, ...)
CREATE TABLE user_memberships (
user_id ...
0
votes
2
answers
50
views
I build an API with Sequelize and my controllers don't display foreign key informations with findAndCountAll
I'm a beginner in creating APIs with NodeJS and Sequelize.
Before coming here I searched for my problem on several forums/docs but I always get the same result.
As you can see in my result, I always ...
0
votes
0
answers
11
views
Next.js high connection count with SSG
I have a nextjs site with about 7800 product pages. The site runs completely fine when I have the product pages setup as SSR with getServerSideProps. However, if I switch them to ISR, I quickly run ...
0
votes
0
answers
48
views
Issue with Sequelize migration - "No database selected" error
Title:
Issue with Sequelize migration - "No database selected" error
Description:
I'm currently facing an issue with Sequelize migrations. When I try to run npx sequelize-cli db:migrate, I ...
0
votes
0
answers
40
views
InnoDB - errno: 1005, sqlState: 'HY000' sqlMessage: "Can't create table (tableName) (errno: -1)",
I was trying to make club, and students database
I am using sequelize, my engine is innoDB
and I wrote like this
module.exports = (seq, DataTypes) => {
const Club = seq.define("clubs",...
0
votes
0
answers
26
views
How can i remove json object from mysql sequalize
I am using Nodejs express and my database is Mysql with sequalize.. I am storing very large json data but my requirement is i want to clear stored json first, then store new json that is coming from ...
0
votes
0
answers
32
views
Sequelize : Count LEFT OUTER JOIN Table Row Not Working
I have searched stackoverflow for the answer to this, none worked, all throws the same error:
Unknown column 'contact_label.label_id' in 'field list'
for example:
https://stackoverflow.com/questions/...
0
votes
0
answers
28
views
Sequelize Error: Named bind parameter "$amount" has no value in the given object
This is my sequelize code:
const insertQuery = `
INSERT INTO transaction (amount, company_id, user_id, journal_id, type, account_id, plaid_transaction_id)
SELECT $amount, $company, $user_id, $...
0
votes
1
answer
29
views
How to get an array of joined table in sequelize in findAll()
const response = await OrderDal.findAll({
where: { buyerId: userId },
attributes: { exclude: ['outcomeId', 'programId'] },
include: [
{
model: User,
as: 'buyerOrders',
...
0
votes
1
answer
45
views
Electron + Vite + Sequelize
Stack:
Electron + vite + vue
I have the issue with sequelize framework. My model looks like:
Operation.init({
itemId: {
type: DataTypes.STRING
},
startDate: {
type: DataTypes.DATE,
},
...
0
votes
0
answers
38
views
Sequelize Models, registered, synced, but how to do CRUD-Operations?
i used a course on udemy to make my first steps with sequelize: https://github.com/DavidArmendariz/sequelize-course/tree/master
Because I only want to use ES-Modules I had to make a few adjustments.
...
0
votes
0
answers
15
views
count with group and joins in sequelize node.js
Below is mysql query which works
select c.name, count(*) as 'count' from product p
join product_category pc on pc.product_id = p.id
join category c on c.id = pc.category_id
where p.user_id = 1
group ...
0
votes
1
answer
41
views
Unable to connect to Cloud SQL (PostgreSQL) instance with Sequelize
I am simply not able to establish a connection to my Cloud SQL instance (PostreSQL). For deployment, I have created a cloudbuild.yamlbut no matter what I try, I'm not able to connect.
For now, I am ...
0
votes
0
answers
31
views
Sequelize "is not associated" model problem
Got a problem with associations using sequelize.
models/Category.js
import { sequelize } from '@/utils/server/db'
import { Sequelize, Model, DataTypes } from 'sequelize'
class Category extends Model {...
0
votes
0
answers
12
views
SequelizeJS ordering by nested includes
I try to order my include models but it still not working when I add sub_section model.
It works for section model.
Working code :
sequelize.models.page
.findOne({
where: {
id
},
...
0
votes
0
answers
13
views
Sequelize query to count total based on foreign key from second table (3 tables)
I have 3 tables. courses, course_sections, and course_videos. courses has a one to many relationship with course_sections which has a one to many relationship with course_videos. I want to return ...
0
votes
1
answer
21
views
Why I cannot select the specific Game object?
I want to increase my game which is select(you can se below), but unfortunately my selection not working it throws an exception.
I want to make the following sql query:
Select * from Games
where ...
0
votes
1
answer
60
views
Sequelize transaction include not working when creating objects?
I'm adding objects into a SQL Server database with Sequelize.
I perform all operations in one single transaction. When I want to retrieve the inserted objects, the associated models aren't fetched. ...
0
votes
0
answers
14
views
Sequelize association hasOne(one to one relationship) is creating 2 foreign keys in mySql (in expressJs)
I am defining 2 columns us,books with primary key usId and bookId respectively. After that i am using association us.hasOne(books,{foreignKey:'usId'});books.belongsTo(us). These lines are now creating ...
0
votes
0
answers
26
views
Is it possible to pass an object into model.init in Sequelize?
I'm wondering basically what the title says, since for my nodejs application I need to create multiple tables with the same set of columns, so I'm wondering if I can do something like this:
Let's say ...
0
votes
0
answers
17
views
Nodejs Sequelize Require Module with connection parameter
I have 2 database connections, one for read and one for write. I want to keep the read connection as default when a model is loaded.
const Sequelize = require("sequelize");
const readDB = ...
1
vote
1
answer
48
views
Remove sensitive Sequelize error messages in Express.js
I have a bunch of sequelize models defined for my database. We are using Express to create CRUD APIs to handle db operations and the UI will call these APIs for the user interaction. Now my biggest ...
2
votes
1
answer
68
views
Indexing strategy for filters including a JSONB property
I have a jsonb column created via sequelize migration this way:
queryInterface.addColumn('Entities', 'summary', {
type: Sequelize.DataTypes.JSONB,
})
My Postgres version:
PostgreSQL 15.2 (Debian ...
1
vote
1
answer
49
views
Sequelize with sqlite auto increment strange errors. No error but no auto increment when I use AutoIncrement but error when I use autoIncrement
I'm creating a discord bot. With 2 slash commands. One command named /setup for adding the guildId and a adminChannel to the database. And one command named /onduty for adding the user, onduty and ...
0
votes
0
answers
28
views
azure-active-directory-service-principal-secret node sequelize migrations
I'm connecting db with service principal by using below method in express using
link
but while running migrations it will establish connection from db.config file
where db.config file contains
"...
0
votes
0
answers
18
views
How to add modules using sequelize-typescript & es modules & providing path?
const _sequelize = new Sequelize({
host: dbHost,
database: dbName,
dialect: "postgres",
username: dbUsername,
password: dbPassword,
logging: false,
models:[...
0
votes
1
answer
36
views
How to create ES module ('.mjs') migration files through sequelize-cli?
I'm writing PostgreSQL database migrations in my NodeJs project using sequelize-cli and trying to follow ES module syntax in my files.
Unfortunately, I can't find how to enable creation and execution ...
0
votes
0
answers
10
views
how to find join tables and filter only results where it has all matches in an array?
I have a database that has a demo, allyTeam, and players tables. demo has many allyTeam. allyTeam has many players.
Say I want to find all demos where Alice and Bob are both players in the demo.
I ...
0
votes
0
answers
28
views
Is sequelize flawed? How to ensure independent DB connections in an Express server?
Ok, this is the situation: I don't think there is a way to ensure independent DB connections for each HTTP request in a Node server that uses the sequelize NPM package. I am currently using Express, ...
0
votes
0
answers
21
views
PassportJS, PassportJWT and Express - 401 Unauthorized
App.ts - This is done initially to setup the strategies. I have bodyParser before them and setup like shown.
// for parsing application/x-www-form-urlencoded
this.app.use(bodyParser.urlencoded({ ...
0
votes
0
answers
13
views
_backup table out of sync with main table in Sequelize
In my Node/SQLite/Sequelize project, the database is initialised like this:
import db from './db.ts';
import Order from './orders.ts';
import User from './users.ts';
await db.sync({ alter: true, ...
-1
votes
0
answers
17
views
Sequelize Spatial Query Issue with Variable Coordinates
I'm facing an issue with a Sequelize spatial query where I'm trying to retrieve records within a 5-meter radius based on latitude and longitude. The query works as expected with hardcoded values, but ...
0
votes
0
answers
16
views
"TypeError: Cannot read properties of undefined (reading 'create') when using Sequelize's User.create() method"
I'm facing a peculiar issue with my Node.js application using Sequelize. When I run my code locally, everything works smoothly without any errors. However, when I send a POST request using Thunder (a ...
0
votes
1
answer
21
views
How to get flag in case of existing record in association in Sequelize
I have a model A with a 1:N association to a model B. I want to get all records from A, and true if there exists at least one associated record from B, false otherwise.
The associations:
ModelA....
0
votes
0
answers
24
views
Can't access association field. Sequilize + TypeScript. Property '...Info' does not exist on type
I am developing on Node JS + TS + express + sequilize. I am trying to connect device info table to device table. I thing I am doing same as in official documentation:
documentation:
class User extends ...
0
votes
0
answers
9
views
Accessing elements inside a returned sequelize object
In my messageReactionAdd.js file I'm trying to just get the value of one of the properties in the returned object from my query. How can I pull the value myDiscordUsername from the returned query ...
0
votes
1
answer
24
views
Unable to create association with Sequelize
I'm using sequelize for my project and trying to create a simple association between two models.
User model:
const { DataTypes } = require('sequelize');
import db from '../db';
const UserModel = db....
0
votes
2
answers
40
views
API with sequelize and Express: verification in controller
I'm building my API for my app web. I'm using Sequelize and Express.
I have created models with Sequelize and I'm writing for the moment the different controller and end-point.
My question is: Do I ...
0
votes
0
answers
42
views
Using PostgreSQL with Sequelize and Umzug in ES6+: Seeking Guidance
I'm currently working on a project using PostgreSQL with Sequelize and Umzug in an ES6+ environment. However, I've encountered challenges with setting up the environment as I want to use ES6+. I'm ...