12,397 questions
Best practices
0
votes
1
replies
77
views
Implementing the Repository Pattern with complex Sequelize associations
I am working on a university project using Node.js, TypeScript, and Sequelize. I've implemented a Repository layer to decouple my database logic from the Service layer.
Initially, my repository was ...
Advice
1
vote
0
replies
54
views
Sequelize: Difference between "constraints: true" vs "constraints: false" with manual FK creation to handle Circular Dependencies
I'm working with Sequelize v6, and facing a circular dependency between two models: User and Profile. To solve this, I am setting constraints: false in one association and then manually adding the ...
0
votes
1
answer
138
views
Property 'VECTOR' does not exist on 'DataTypes' in Sequelize with pgvector
I am building a RAG application using Node.js, Sequelize, and PostgreSQL with the pgvector extension. I have successfully enabled the vector extension in my database.
I am now trying to create a ...
1
vote
2
answers
195
views
Sequelize transaction stays open too long during API calls, causing connection pool exhaustion
I'm facing an issue with Sequelize(postgres) transactions in a high-traffic Node.js/Express app. I have a flow like this:
async function createPayment(data, trnx) {
// Save in DB within transaction
...
3
votes
1
answer
118
views
Getting SQLite Syntax Error when saving model in Sequelize.js v7
So, I'm trying to learn full stack by making a list app, and I'm using
Sequelize.js for the database. So far I've got User and List models. I
recently switched to Sequelize v7.0.0-alpha.47. I can't ...
1
vote
0
answers
67
views
Sequelize limit insert or create in 100 rows
I am use Sequelize with Postgree in a Serveless project. I just try to get an array of +600 objects from API and I need to send to DB. I use a map() for that array and I use sequelize upsert() or ...
0
votes
0
answers
44
views
Many to many relationship Sequelize v7
I´m trying to establish a follow list to from user to user:
class Follower extends Model<InferAttributes<Follower>, InferCreationAttributes<Follower>> {
@Attribute(DataTypes.UUID)
...
-1
votes
2
answers
62
views
sequelize relationships Cannot read properties of undefined (reading 'hasMany')
I'm trying to integrate sequelize with the db conection to postgres and i am getting an error where relationships are built.
i don't know if i'm missing something at this point
index.js
'use strict';
...
0
votes
0
answers
62
views
Sequelize bulkCreate updateOnDuplicate: Cannot read properties of undefined (reading 'map')
I want to update multiple records ( more than 100 ) and for this I am trying to use bulkCreate method of sequelize with following parameters:
const updatedUsers = await User.bulkCreate(allUserInfo, {
...
1
vote
0
answers
34
views
Cannot generate model using sequelize-cli enum with defaultValue
My sequelize-cli is
npx sequelize-cli model:generate --name Profile --attributes username:string,imageUrl:string,fullname:string,dateOfBirth:date,UserId:UUID,role:enum:'{staff,admin}':defaultValue:...
0
votes
0
answers
64
views
How to infer model type from plain schema in Sequelize?
In Sequelize, I've the following schema:
const User = sequelize.define('User', {
name: DataTypes.STRING,
email: DataTypes.STRING,
})
But in TS, User ends up being typed as ModelCtor<Model<...
0
votes
0
answers
28
views
How do I get the typed raw attributes of a Sequelize model that's a property of another model that is optional?
I have a Sequelize model that has a property that is also a model. In this case, Category has a property ParentCategory that is an optional model of Category. When I get the "non model" ...
0
votes
0
answers
15
views
exclude sequelize lib when using vite to build application
I have a frontend web project A with dependencies B, the dependencies B using sequelize that only work in node with server side. So I tried to exlclude sequelize https://sequelize.org/ in project A ...
1
vote
1
answer
365
views
How to properly include SQLite3 with an Electron, Electron Forge, Sequelizer set-up in production?
I've been trying to set-up a working Electron application using Electron Forge with Sqlite3 and Sequelize. This has worked great up until where I need to actually build and package, and distribute the ...
-3
votes
1
answer
149
views
Getting False-positive SQL Injection warnings on parameterized Sequelize queries in Snyk Code
I maintain a Node.js (v14.x) + Express + Sequelize (v6.x) application and use Snyk Code to catch security issues in our CI pipeline. We rely heavily on Sequelize’s parameter binding (:param) to ...
1
vote
1
answer
89
views
How to add order clause in sequelize-cursor-pagination
I'm using the sequelize-cursor-pagination package to implement pagination in my Node-Postgres application. I need to order my results based on a field from an included (associated) model, but the ...
-1
votes
1
answer
77
views
How to exclude unnecessary database dialects while bundling with esbuild/rollup in Vite with Sequelize?
I have been scratching my head for a while now trying to figure out how to exclude unnecessary database dialect adapters. For context, I am building an app with Vite. Its using ElectronJs and ...
0
votes
1
answer
49
views
Sequelize Associations Miss Some Data
I'm making a query to Articles table to get the article data with publisher, tags, images and categories. The relation between publisher and article is M:1, between tags and articles N:M, between ...
0
votes
1
answer
38
views
Dynamic includes in node API with Sequelize
I am creating a node API connecting to a mySql db using Sequelize. I want users of the API to be able to specify which models to include in the results of a query. For example I have a model like this:...
0
votes
0
answers
45
views
Associating two models twice
In sequelize documentation, it is stated in association alias section
Aliases are especially useful when you need to define two different associations between the same models. For example, if we have ...
1
vote
0
answers
80
views
Error creating property: no pg_hba.conf entry for host "172.31.8.1", user "postgres", database NAME, no encryption
I'm having issues running RDS sequelize queries. I'm using EC2 Node.js
original: error: no pg_hba.conf entry for host "172.31.8.1", user "postgres", database NAME, no encryption
5|...
1
vote
0
answers
48
views
Is possible to use VS Code Intellisense with Sequelize + JS
I'm learning sequelize + other stuff and I'm using sequelize-cli to initialize the sequelize and generate the models. When I try to use the model in other file it doesn't suggest anything related to ...
1
vote
1
answer
132
views
Migrating sequelize model to typescript and getting the error "error relation does not exist"
I'm in the process of migrating a Javascript project to Typescript. One of the steps is to migrate the sequelize models. I'm following the instructions located at: https://sequelize.org/docs/v6/other-...
0
votes
0
answers
31
views
graphql-sequelize and useMaster
I would like to know how to correctly use useMaster with graphql-sequelize.
I'm trying to force the query to go to the master database using this code:
before: (findOptions) => {
const ...
1
vote
1
answer
43
views
Sequelize magic method not adding foreign key
Sequelize's createXXXXX method doesn't seem to be adding the necessary foreign key.
This running the following code for these two models gives me a "notNull Violation: Seat.office_id cannot be ...
0
votes
1
answer
57
views
Getting just the associated id(s) of a record
I don't want to eagerly load all the associated data, it won't be used. But, I might want to know that related records exist, for example to link to related records.
So I'm trying to set up an ...
0
votes
0
answers
40
views
I'm new to Node.js and sequelized and I'm having a problem with related tables
Here is the full code:
const StockTypes = require('./stock_types');
module.exports = (sequelize, DataTypes) => {
const Stock = sequelize.define('Stock', {
name: {
type: DataTypes....
0
votes
0
answers
38
views
Postgres Sequelize not using provided name
Trying to establish a connection to my local PostgreSQL database via Sequelize. I have no trouble accessing it with pgAdmin, using postgres as the user and no password.
I am passing this into the ...
2
votes
1
answer
299
views
PostgreSQL 63-Character Limit Issue in Sequelize with Multiple Includes
I’m currently working on a project where we are using PostgreSQL with Sequelize to perform complex queries involving multiple nested include relationships. However, we’ve encountered an issue related ...
0
votes
0
answers
52
views
Sequelize sync still running the alter queries even when alter is false
await sequelize.sync({ alter: false, force: false });
My expectation and also as per the sequelize documentation this will only create the new tables if not present, it will not run any alter query.
...
1
vote
1
answer
57
views
NodeJS Sequelize Raw Query Not Returning All 2 Rows
I have 2 rows in the database table moneys.
Using Sequelize, I want to select all rows from the table.
The following raw query in DBeaver MySQL client returns all the results. So, that works as it ...
0
votes
0
answers
139
views
How to properly configure @adminjs/upload to store image files and hide the text input for the file path?
Product Model
import { DataTypes } from "sequelize";
import sequelize from "../util/database.js";
const Product = sequelize.define("product", {
id: {
type: ...
0
votes
1
answer
80
views
Using import vs require with Node and Sequelize
I'm using type module/import syntax for the rest of my project, but the Sequelize CLI generates files with require syntax. How should I handle this? I'm already having trouble with not being able to ...
0
votes
1
answer
279
views
Sequelize.js with sequelize-typescript started emitting warnings
I've been using Sequelize (6.37.X) on a small side-project for a while. Just a day or so ago, I started having failures in my unit tests, and I'm seeing a lot of this warning on the console:
(...
0
votes
0
answers
66
views
SequelizeEagerLoadingError: ModelA is not associated to ModelB (intermittent in multi-schema setup)
I'm using Sequelize v6.37.5 with PostgreSQL in a multi-tenant architecture, where each tenant has its own schema. Models are defined once globally, and we use .schema(schemaName) to access tenant-...
1
vote
1
answer
110
views
mysql2 ETIMEDOUT error with rate-limiter-flexible, but Sequelize connects fine
I'm working on a Node.js backend project and have run into a strange issue involving MySQL connections. Here's the situation:
I am using a MySQL database hosted on Digital Ocean (Managed MySQL ...
0
votes
1
answer
77
views
GraphQL not accepting login credentials
So I'm trying to create a user for my task management app, I'm using Express.js, Sequelize ORM for PostGres and Apollo/Server for graphql.
Creating a user works fine, but when I try to login using ...
0
votes
0
answers
54
views
Sequelize findOrCreate() creates duplicate Terms and Listings
Consider these models and the Listing post route.
I fetch the body data in the request.
router.post("/", async (req, res, next) => {
const {
address: addressData,
building: ...
1
vote
1
answer
84
views
Netlify app can't login to Express app only on mobile
I have a Vue 3 app hosted on Netlify, and the backend is hosted on Heroku. The login is a simple /login endpoint made with Express and Sequelize. It works well on desktop, but when I try to log in on ...
0
votes
2
answers
46
views
Function count associated entries with Sequelize return 1 instead 0
I try count foreign table rows with Sequelize
this.publicationModel.findAll({
attributes: {
include: [
[Sequelize.cast(Sequelize.fn('COUNT', 'comments.id'), 'int' ), '...
0
votes
1
answer
93
views
How to push data in an array of JSONB column using sequelize
I have a table named Expenses and the table has a column named expenseEditHistory. The column is of JSONB type. I am using sequelize to manage the database (postgres).
Structure for expenseEditHistory ...
0
votes
2
answers
200
views
SequelizeModule — autoLoadModels / [Nest] ERROR SequelizeModule Unable to connect to the database. Retrying
I'm learning Nest.js, I'm trying to connect via SequelizeModule to my local postgres database, but I keep getting this error
Error when starting start:dev
[20:41:14] Starting compilation in watch mode....
0
votes
1
answer
60
views
Sequelize Model Not Creating Table in MySQL Database (TypeError: Cannot read properties of undefined (reading 'define'))
I’m working on a Node.js project using Sequelize with MySQL. The database connection is established successfully, and sequelize.sync({ alter: true }) runs without errors, but my users table is not ...
0
votes
1
answer
91
views
Sync Sequelize model with database
I am trying to sync a Sequelize model with my database, but I can't get over this error.
Using Sequelize as my ORM, database is Oracle express:21.3.0-xe
This is the error:
Executing (default): ...
0
votes
0
answers
37
views
Sequelize.Model.create success but never create row in db
Postgres, Sequelize, Node.js environment.
Model.create function success at creation and return dataValues, however when I check in db, it's never been added.
What's happening behind create or is this ...
1
vote
2
answers
128
views
SequelizeConnectionRefusedError: Unable to connect to PostgreSQL Database in Node.js
I'm working on a Node.js backend using Express and Sequelize to connect to a PostgreSQL database. However, when I run node index.js, I get a SequelizeConnectionRefusedError.
My index.js file:
import ...
0
votes
0
answers
24
views
sequelize unknown column in having clause but generated mysql query works
I wrote following sequelize query
const result = await VendorCompany.findAll({
attributes: [
"id",
[Sequelize.fn("COUNT", Sequelize.col("Vendor->...
0
votes
1
answer
16
views
Sequelize.js model.save() method is not throwing ValidationError
I use the following function in an API I am building
const editUserInfo = catchAsync(async(req, res, next) => {
const userId = req.user.id;
const body = req.body;
const result = await ...
0
votes
0
answers
55
views
Pagination on high amount of rows using Sequelize and MySQL
I am using Sequelize with Node for my backend.
One of my tables is probably going to grow a lot in the coming weeks (at this moment, the table is around 1-2M rows).
I added 30M lines and added the ...
1
vote
1
answer
58
views
sequelize-typescript many-to-many on same table, include acts weird
I am implementing a social network where a User can follow another user.
So I have a Follow model:
export default class Follow extends Model {
@PrimaryKey
@ForeignKey(() => User)
@...