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.

sequelize.js
Filter by
Sorted by
Tagged with
0 votes
1 answer
80 views

Difference between as and foreignKey when defining belongsTo relationship in Sequelize

Consider the following snippet from Sequelize documentation class User extends Model {} User.init({/* attributes */}, { sequelize, modelName: 'user' }) class UserRole extends Model {} UserRole.init({/...
Raniere Silva's user avatar
1 vote
1 answer
6k views

how to use select and extract date into month and year from timestamp in sequelize ORM?

I have this query in sql: select to_char (created_at,'Mon') as month, extract (year from created_at) as year, id_activity as activity from event group by 1, 2, 3 i tried something simple at first, ...
Naju Mat Isa's user avatar
0 votes
0 answers
304 views

Sequelize performance issue with PostgreSQL

I am having a really big performance issue working with Sequelize. I have a query. SELECT "canstitution".*, "user"."id" AS "user.id", "user"."salutation" AS "user.salutation", "user"."firstName" ...
Sonu Bamniya's user avatar
  • 1,105
0 votes
1 answer
138 views

Find matching objects on Sequelize backend query

we are working on a MariaDB backend with Sequelize and Express, and we need to find every matching object that contains an uncomplete string, I mean, if somebody searches JO and the database entry is ...
Carles - PLAVED's user avatar
4 votes
1 answer
2k views

How to modify virtual fields from sequelize findAll result?

I have looked everywhere and couldn't find any clear answers for this. I have a complex findAll() with many inclusions and each with their own virtual fields. What I want is to modify the virtual ...
Icecubelegacy's user avatar
2 votes
3 answers
943 views

Check if all entries exist in table

Good Day, I am using Sequelize mysql in nodeJs. My problem is that, given an array of IDs such as [4,5,6,7,8] And a table T where each row holds a ID. say, Table T: ID 4 5 7 8 How do I ...
Ask the cat's user avatar
0 votes
1 answer
754 views

Sequelize Maximum call stack size exceeded with associations

this is my first question :) I need your help, my problem is that I have associations in sequelize the first: AssistantGroupModel.hasOne(StaffGroup(), { sourceKey: 'staff_group_id', ...
AntonioDev97's user avatar
0 votes
1 answer
203 views

When to use Sequelize paranoid deletedAt

Am trying to create a database and maintain a restful api service built upon sequelize. I want a model, UserGameProfile, which can be deleted and restored according to user preference. I want it to ...
Janan Tan's user avatar
1 vote
1 answer
326 views

How to use transactions in two different ORMs

I have a codebase using the sequelize ORM and want to move to Objection.js ORM. Is there a way to reuse a transaction started in sequelize with Objectionjs? So that I could migrate iteratively instead ...
petabyte's user avatar
  • 1,518
1 vote
1 answer
664 views

Sequelize / Typescript / Graphql clashing on ID as Int vs String

I've created an Apollo Server that is underpinned by Sequelize. I'm also writing my application in TypeScript. This has created a clash between Sequelize's notion of a primary key (an Int) versus ...
earnold's user avatar
  • 1,462
1 vote
1 answer
3k views

Duplicated column name with sequelize.where

What you are doing? I'm trying to use a function with sequelize.where inside a included model Post a minimal code sample that reproduces the issue, including models and associations class Promotion ...
LkzFox's user avatar
  • 36
1 vote
2 answers
1k views

Correct way to create a k8s secret?

I am not sure if I'm interpreting the output from my container correctly, but I am seeing the following output from sequelize in the logs: Nates-MacBook-Pro:k8s natereed$ docker logs 1a3e6141d050 ... ...
Nate Reed's user avatar
  • 6,881
0 votes
0 answers
191 views

SEQUELIZE: Cant access database of an intermediate table

I am learning how to use sequelize in nodeJS, I really like it but there are some tables that i am not being be able to access, let me show you: GIVEN THESE ASSOCIATIONS: Product.belongsTo(User,{...
user avatar
0 votes
1 answer
288 views

Dev server restarts itself due to "file change" when inserting data with Sequelize into SQLITE DB, does not occur with MySQL [Repo included]

Issue this.userModel.create({email, password }) [github] causes the Nest dev server to restart itself when there is a fresh sqlite db. Called from here Here is the dev server log. I run the mutation ...
W. Reyna's user avatar
  • 734
4 votes
1 answer
7k views

How can I use raw SQL in NestJS instead of TypeOrm or Sequelize?

As of today TypeOrm has 1.493 issues over 282.102 weekly downloads and Sequelize 783 issues over 571.781 weekly downloads in Github. As I read over the TypeOrm and Sequelize Github issues, I want to ...
Domiserver's user avatar
0 votes
1 answer
1k views

Sequelize raw query to return data as array

my current output is: { "students": [ { "email": "[email protected]" }, { "email": "[email protected]" } ] } What i am trying to ...
Ask the cat's user avatar
0 votes
0 answers
53 views

How to findAll query where value is from associated table in Sequelize?

I am using Sequelize as my ORM and I want to know the best way to achieve the desired outcome. With the models below, how do I return an array that returns all the Books and Novels while removing ...
Icecubelegacy's user avatar
3 votes
2 answers
7k views

greater than and less than a date gives no records in sequelize but works with heidisql

It's really weird, I can't debug the issue. I also don't know what's causing the issue. I have a query like below: const sequelize = require('sequelize') const Op = sequelize.Op const TODAY_START = ...
sujeet's user avatar
  • 3,700
0 votes
2 answers
31 views

How to perform inner join for this query

Can someone help me trouble shoot my syntax i spent 1 hour on it yet i cant figure it out. I have 3 tables: **Student** -ID (UUID) email (String) **Teacher** -ID (UUID) email (String) **...
Ask the cat's user avatar
-1 votes
1 answer
612 views

In sequelize, how do I select records that match all values that i am searching for?

As an example, I have the following table: T | S ------ 1 | 5 1 | 6 1 | 7 2 | 6 2 | 7 3 | 6 Query: array [1,2] I want to select all values in S that have the value 1 AND 2 in the T Column. So in ...
Ask the cat's user avatar
0 votes
2 answers
1k views

Automatically include referenced model in Sequelize on each GET

So I have user model and admin model and they're associated as user n:1 admin. The code defining the user model as follows: // users.model.ts const users = sequelize.define('users', { ... ...
Milkncookiez's user avatar
  • 7,067
0 votes
1 answer
140 views

How to remove the ":", for the FindOne of my query in SQL-Server?

Ok, I just want to get an object from my database, so I'm using sequelize, but at query time it brings me ": 80810", so it sends me an error in the database: "Conversion failed when converting the ...
Jonathan's user avatar
  • 225
2 votes
2 answers
6k views

Sequelize - Get max date for a group of objects

I want to get the max (most recent) created at date of each group of objects from a table using sequelize. My entity roughly follows this interface: class MyEntity { id, groupName, ...
coler-j's user avatar
  • 1,915
0 votes
1 answer
2k views

sequelize methods from association fooInstance.getBars() returning a wrong value

I've got 2 models with a many-to-many association through another model. By default, Sequelize creates instance methods for both models as you all may know (https://sequelize.org/master/manual/assocs....
Tanpo's user avatar
  • 263
0 votes
2 answers
343 views

Only return specified associated model from sequelize junction model

I'm trying to properly use sequelize queries to work with graphql + apollo. Here is my Pool gql schema: type Pool { id: ID! name: String! createdBy: User members: [User] } ...
Matt H's user avatar
  • 23
0 votes
2 answers
1k views

How to keep sequelize associations name in lower_case?

Cannot get my foreignKey in lower_case, all my associations are PascalCase. So I have a simple table "user" with role_id (foreignKey) And I have table "role". So when create a user it works fine. But ...
Nicks's user avatar
  • 744
0 votes
1 answer
445 views

How do I convert SQL query to sequelize?

I have this block of sql - I'm using postgres DB. How do I convert this query into sequelize ORM format? Thank you select to_char (created_at,'Mon') as month, extract (year from created_at) ...
Naju Mat Isa's user avatar
1 vote
1 answer
579 views

Sequelize MySQL - Join with two rows from same associated table

I am into a tricky question involving Sequelize MySQL. I have two models: Calibration and Device, associated many-to-one respectively. const Calibration = sequelize.define('Calibration', { id:...
necroface's user avatar
  • 3,405
0 votes
1 answer
43 views

How I can include array of model?

var user = await db.user.findOne({ attributes: attributes, include: ['charges', 'availability', 'practice',// 'services', 'education',// 'user_role', '...
Wang Liang's user avatar
  • 4,360
0 votes
1 answer
234 views

how to define Sequelize model of complex object?

I just start to use Sequelize, I try to define a model but my object that should insert into the db is like this: { year: 2017, circle1: { value: 50 }, categories: [ { ...
Idan Malul's user avatar
0 votes
1 answer
156 views

GraphQL doesn't allow querying on different fields

I'm an absolute beginner in GraphQL. So apologies if the question is amateur. I'm writing this graphQL end point where it will filter person by name. Works good, but I want to be able to filter by ...
Shri's user avatar
  • 731
1 vote
2 answers
968 views

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'create' of undefined using Sequelize ORM

I am trying to make a Node.js API, however every time I try to create a new user in my database using Sequelize I get the following error: Error Stack Trace Here is my User.js model: 'use strict'; ...
pedrohcms's user avatar
  • 335
0 votes
1 answer
1k views

generate sequilize models from sql file

I am building a nodejs API with PostgreSQL & Sequilize. My client gave me a .sql file which has been exported from dbdiagram.io. Is it possible to generate all my models base on .sql file ? or ...
Nicks's user avatar
  • 744
4 votes
1 answer
9k views

Sequelize ORDER BY

Hello I want to query a company and list all the users ordered by name This is what I have. Relationship works fine is just the ordering that´s not working. I don´t see the ORDER BY name when I debug ...
handsome's user avatar
  • 2,325
0 votes
1 answer
424 views

use "npx sequelize" locally without install globally

I want to prepare the configuration of my website on a server of my university. I have the follow problem: npx sequelize is not working because sequelize is not installed globally and can't install ...
inlor's user avatar
  • 5
1 vote
1 answer
1k views

Sequelize Many to Many Include fails with column does not exist

I have 2 tables that are using the belongsToMany association through a 3rd table. I would like to query a specific user from the user table with an array of the associated playlists (from the ...
rt_'s user avatar
  • 1,135
6 votes
1 answer
10k views

Sequelize Query Where not equal and Other Conditions

I want to make the query id not equal in Sequelize. Here is my current sequelize query: return db.Area.findAll({ where: { id: { $ne: Id }, slug: conditions.slug } }) The resulting SQL Query:...
Muhammad Fazeel's user avatar
8 votes
4 answers
4k views

Set optimistic locking as global option in node , sequelize

I am trying to set up sequelize in my node project and for now I have //sequelize init const { DataTypes } = Sequelize; const sequelize = new Sequelize({ database: database, username: user, host:...
codebot's user avatar
  • 597
0 votes
1 answer
800 views

Need advice on how to populate "through" table in Sequelize?

I'm trying to figure out how N:M works in sequelize, and I have a problem with populating the "through" table. So I have these models : Product / Category models 'use strict'; module.exports = (...
sillenius's user avatar
0 votes
1 answer
823 views

customize validation error null error unique error

i am using sequelize.js nodejs as backend. when there is a validation error/ unique error/ null error it is sequelize validation error. Basically i want to get error as node js error. It is ...
john's user avatar
  • 58
2 votes
1 answer
1k views

Node.js Sequelize returns date minus 1 day

Sequelize is returning the date -1 day. For instance if I do a select statement with a date in WHERE for: "date":"2017-01-01" it will return: '2016-12-31'. Everything else will be ...
Jonathan E. Emmett's user avatar
0 votes
1 answer
813 views

Use aliases for column names when setting Models in sequelize

I am new to sequelize and I try to implemented in an existing node/express project. So far, I have this simple Model and it works when I query it const User = sequelize.define('AppUser', { // ...
codebot's user avatar
  • 597
1 vote
2 answers
3k views

sequelize findall with count every relation child for each parent

and thank for the answers. i use nodejs / sequelize / mysql this is my problem: i have table client like this: id username age name ---------------------- 12 seveun 25 john | --------------...
Matehis Langlais's user avatar
0 votes
0 answers
226 views

beforeUpdate Sequelize

Hello I´m using this hook to encrypt the passwords on save Account.beforeUpdate((account, options) => { return bcrypt .hash(account.password, bcrypt.genSaltSync(10)) .then(hash ...
handsome's user avatar
  • 2,325
0 votes
2 answers
1k views

Sequelize does not return object but instead extra data

When I run any find function with sequelize, I expect to get an object of the data I am trying to get, instead, I get a bunch of extra data back.This is what I get when I print the result of what ...
eek's user avatar
  • 57
0 votes
1 answer
401 views

Sequelize loading in initial data

I need to load data into a DB using Sequelize on first application load. The initial excel data was given in the following format: Car group fields: title | group_code Car group data: ('Mercedes','M'...
Rezzy's user avatar
  • 314
0 votes
1 answer
6k views

How to use BLOB data type with sequalize migrations

I have been started to using nodejs and sequalize recently and I have been developing a sample application. In my application I have users. When adding some dummy data using seeders in sequalize I ...
Yasiru Nilan's user avatar
2 votes
1 answer
699 views

Find Child Object in Parent Object using Sequelize

I have three tables in MySQL database:- categoryTypes, categories and categoryTemplates. The parent table is categoryTypes. In categoryTypes, there are the following fields and id of categoryTypes is ...
Dev's user avatar
  • 57
0 votes
0 answers
156 views

How to update "updatedAt" on main table after child table with foreign key updated or created on sequelize

I have main table "flow" and other table that connect to flow table with foreign key. How can I update "flow" table "updateAt" column when the other table create new data or update data. Example: I ...
Baruch Mashasha's user avatar
0 votes
0 answers
32 views

How to know in a 2 form situation that I am using correct data?

I am planning on creating an app which could be used to fill out internship information. There are 2 forms, first of all student fills out their side of the form. After student entry, info will be ...
Bix's user avatar
  • 23

1
109 110
111
112 113
250