Questions tagged [sequelize.js]

1

votes
1

answer
1k

Views

How to do group_concat in select query in Sequelize?

I want to do GROUP_CONCAT in select query in sequelize here is my requirement what i want SELECT `group_name`, `description`, GROUP_CONCAT(`module_name`) FROM `group_access` GROUP BY `group_name` I want to write this type of query in sequelize. This is what i tried. groupAccess.findAll({ attributes:...
Vinit Singh
1

votes
3

answer
1.5k

Views

How to stop Sequelize to drop existing table?

I am creating a application in nodejs using express.js ,I need to connect Oracle db, I am using Sequelize ORM framework for that,I created model and tried to access db,it dropped existing table and created new table, I have lost my data,how to stop dropping table and make sync with existing table an...
Prabakaran
1

votes
1

answer
2.3k

Views

Sequelize: passing Sequelize.op.in where

I am creating where dynamically for my model. I want to use in for multiple values. I read documentation and online and found this: Patient.findAll({ limit: limit, offset: offset, where: { [Sequelize.Op.in]: patientIds } }); I want to build where something like this: var filter = { [Sequelize.Op.in]...
Ashutosh
1

votes
2

answer
2.4k

Views

Create with Include Sequelize

recently I discovered this on the sequelize documentation where you can create using include. Now I trying to do it on my program but only creates the records of the 'parent' model and not for the children. This is my model and my controller. var MainMenu = sequelize.define('MainMenu', { Name: { ty...
Ellebkey
1

votes
1

answer
29

Views

whats the difference between export.create and router.post?

I've seen 2 ways of creating a restful API. 1: 'export.create' and once you add code on postman you have to add it in json format. 2: 'router.post' which I understand that's using express and when you add code on postman you add it using 'x-www-form-urlencoded' What's the difference? router.post('...
LaCarl
1

votes
2

answer
51

Views

How to search in array with LIKE operator

id | name | ipAddress ----+----------+------------------------- 1 | testname | {192.168.1.60,192.168.1.65} I want to search ipAddress with LIKE. I tried: {'$mac_ip_addresses.ip_address$': { [OP.contains]: [searchItem]}}, This one also: {'$mac_ip_addresses.ip_address$': { [OP....
YOGESH MISHRA
0

votes
1

answer
106

Views

'myTable' is not associated to Model

I'm working on an express sequelize project. I've got an issue with sequelize. I've got a simply schema like the documentation says: class Task extends Model {} Task.init({ title: Sequelize.STRING }, { sequelize, modelName: 'task' }); class User extends Model {} User.init({ username: Sequelize.STRIN...
Pimento Web
-1

votes
0

answer
15

Views

I cannot connect to postgresql. I am getting this error - “Error: connect ECONNREFUSED 127.0.0.1:5432”

When I am trying to connect to Postgres I am getting this error. I have changed in pg_hba.conf and postgresql.conf as well but still I can't connect.
kaitlyn
1

votes
1

answer
2.4k

Views

User authentication with JWT in NodeJs with postgresQL?

I have been looking into user authentication with JWT in Node.js but everybody seems to be using mongoDB. I want to do the same thing with postgresQL and sequelize.js. Any resources or sample projects you guys know?
1

votes
2

answer
599

Views

Subtract 2 fields in Sequelize

My query looks like this so far... { where: { id: event.pathParameters.picId }, 'include': [{ 'model': db.reputations, 'where': { 'type': 'V_UP' }, 'as': 'up_reputations', 'required': false }, { 'model': db.reputations, 'where': { 'type': 'V_DONW' }, 'as': 'down_reputations', 'required': false }], '...
Justin808
1

votes
1

answer
149

Views

Sequelize | Return results if either hasMany association matches their where conditions

I have model A, B, and C. A has a hasMany association to B & C ( and B & C have a belongsTo association back to A ) I want to return records of A where B.b_column = 'b' OR C.c_column = 'c'. My current approach was to trying using the required: false in the where's but that just returns all the rec...
ndyr
0

votes
0

answer
15

Views

Sequelize - How do I query a one-to-many relationship?

I am trying to grab a list of values from a one-to-many relationship. Once I have those values I planned to delete them. I have tried using Op.in method on a where key. let queryValues = await productInput.findAll({ include: [{ model: productInputValue, where: { id: Sequelize.col('productInputValue...
Darron
1

votes
1

answer
1.4k

Views

How to properly use sub query in sequelize?

...... ..... return myDb.myTable.rollgroup.findAll({ attributes : ['ID','GROUPNAME'], where : { id : { $notIn: ? //// how to use subQuery here } } }).then((getResult) => { return getResult; }) ....... ....... My raw Query Like this: select mg.ID,mg.GROUPNAME from mygroup mg where mg.ID not in (selec...
mani
1

votes
0

answer
87

Views

Mapping generic parameter to compile time data in Typescript?

I'm playing around with trying to disentangle a codebase from Sequelize. Right now we have tons of code like: // Defining interface for model instances interface UserInstance extends Sequelize.Instance { ... database field here ... } // Wrapper class managing connection & model definitions class Db...
Chris Tavares
1

votes
0

answer
233

Views

sequelize raw query, format of columns

In a raw query I want to know the definition of each resulting column, in particular the format. Is that possible using the API? sequelize.query('SELECT * FROM `someTable`', { type: sequelize.QueryTypes.SELECT}) .then(rows=> { rows.forEach( row=>{ for (col in row) { let column=row[col]; // Is colum...
tru7
1

votes
0

answer
115

Views

One Post From Each User query via Sequelize

I am trying to write a query resolver via Sequelize and node.js There are 3 models as Group, Post and User. I want to fetch Posts (one post from each user) that sent to Group. The associations are like that. Group.belongsToMany(Post, { through:'GroupPost' }); Post.belongsToMany(Group, { through:'Gro...
Olcay Karabıyık
-1

votes
1

answer
486

Views

Nested Promise is not propagating error to parent Promise in Node.js?

I'm creating an API using Node.js/TypeScript running Express. Below is an excerpt from my get method. An error is being triggered in the format method, which throws an error that is caught by the promise, but not propagated to the parent promise after a throw: this.getModel(objectName).findAll(query...
NobleUplift
1

votes
1

answer
451

Views

How to perform where query for postgres Array in Sequelize

I have a model which defines a column keywords as an array of Strings. Now I wan't to query for all entries that do not contain a special keyword in the keywords column. My approach doesn't work like expected. Modell: export default function (sequelize, DataTypes) { return sequelize.define('transact...
Karl Adler
1

votes
1

answer
35

Views

Can't use facebook to login because user model setting in local passport

I am trying to build a login system with Facebook, Google and local passport, I am using Node.js, passport.js, and ORM to finish it, but I faced one problem now, my user model is like below const User = connection.define('user', { googleID: { type: Sequelize.STRING, }, facebookID: { type: Seq...
starsneverfall
1

votes
0

answer
150

Views

Sequelize: Filling virtual data types after model build/create

I have model (Item) with this fields: id: { type: Sequelize.UUID, defaultValue: Sequelize.UUIDV4, unique: true, primaryKey: true }, item_key: { type: Sequelize.STRING, allowNull: false, validate: { validType(value) { if (!items[value]) { throw new Error(`Wrong item key: ${value}.`); } } } }, count:...
Johny
1

votes
0

answer
388

Views

How to create two subclasses of the model class in sequelize-typescript?

I'm creating a node.js server with sequelize using sequelize-typescript. I have one entity - name it Employee. In database all profiles stores in the same table but have two different types - say Manager and Operator. Each type has its own relations with different tables - say: Manager -> ManagerOpt...
user3405844
1

votes
1

answer
165

Views

Is there a way to write a beforeEach globally?

I am trying to write tests with sequelize and I would like to truncate all my tables before each test. I don't want to write that or run that in each test file if possible. Does anyone know of a way to do that? It seems like jest should support something like that. I am currently trying to use globa...
unflores
1

votes
0

answer
110

Views

Sequelize connection error is failing with the message - Net.Connect is not a function

I am trying to use Sequelize (4.32.1) in one of my app. However, I am getting the following error I am using the code as follows Connection.js const Sequelize = require('sequelize'); const Connection = new Sequelize('mysql://[email protected]:3306/executions'); module.exports = { Connection } Ex...
Gagan
0

votes
1

answer
13

Views

How to use multiple $or in sequelize

Im writing a query where i need multiple 'or' statements. this is my whereClause: { date_added: { '$lte': '2019-04-18', '$gte': '2019-04-11' }, '$or': [ { id: [Array], secondary_id:[Array] } ], '$and': [ { channel_type: [Object] }, //i need this to be a second $or such that there where statements...
user3662456
1

votes
1

answer
648

Views

sequelize migration not work properly

config.json file is Database connection file in sequelize. In my project config.json file have group of database config.json look like: { 'TEST_CS': { 'development': { 'username': 'root', 'password': 'password', 'database': 'databaseOne', 'host': 'localhost', 'port': '3306', 'logging': true, 'diale...
mani
1

votes
1

answer
83

Views

Sequelize/Node – Concat to null value

I'm trying to concat the number '2' to a value in a row that at times may be null. Other times, it will be a string. I'm using the Sequelize.fn method to concat the '2', but in the cases where the value is null, it does not do anything. Specifically, it remains null and does not become '2' as I woul...
timothym
1

votes
1

answer
1.2k

Views

serverless webpack config, manually add directory

I have the following code I am running that is failing to work because it can not find the models folder when I upload to amazon. exports.setModels = function(connection,modelPath){ //Import all the known models for the project. //Proof of Stage being set. console.log('stage for models='+stage); con...
Joseph Astrahan
1

votes
1

answer
92

Views

How do I restrict the result of Sequelize Model.create to the properties of the model?

I'm experimenting with Sequelize for the data layer in an API. For better or for worse, I have a table with over 30 columns but API users only need to know (to simplify this question) only 5 of them. I built a Sequelize model that 'exposes' just the fields API users need to know about (the rest are...
Ray Toal
1

votes
1

answer
348

Views

db.sync({alter:true}).then(); in sequelize node.js express app

I am using sequelize as an orm for myql database , now the problem I am facing is that after I have run my node.js express app for more than 4 or 5 times I am getting this error 'Too many keys specified; max 64 keys allowed', now I want to know what is making this error appearing and can someone tel...
Mrinal Verma
1

votes
0

answer
97

Views

is possible using query assocation model in sequelize datatype virtual ?

the code example like this : var Model1 = sequelize.define('Model1', { field1: DataTypes.STRING, field2: DataTypes.INTEGER, field3: { type: DataTypes.VIRTUAL, include : {model : Model2}, get: function() { return this.Model2 where : { condition }
Arif Fathurrohman
1

votes
1

answer
252

Views

manipulate data object sequelize ORM (nodejs)

i have code like : data = await photo.findOne({ where : {id} }) that return data { 'a' : 2, 'b' : 5 } i want to manipulate the data like insert some field so i add properties : data.c = data.a * data.b i check in console.log the data added { 'a' : 2, 'b' : 5, 'c' ' 10 } but when i return to json ret...
Arif Fathurrohman
1

votes
3

answer
93

Views

sequential queries from database using sequalize in node+express

I am just starting node and am from PHP background. I have been trying to figure out promisses for some time now but unable to figure it out. I am trying to use result of one query in 2nd query in a loop, but having TWO issues: -ONE: typeof value shows an object; but when I console it out, it shows...
saqib bilal
1

votes
0

answer
231

Views

Sequelize Limit not working when using Sequelize literal in Where condition

I have the below relation: Organisation.hasMany(OrganisationAdmins) (assume that alias and all are given correctly). Now when I am trying to find all organisation's without an organisation admin, its causing issue on limit. Earlier i was unable to do this, then i saw that i can use sequelize literal...
Abdul Vajid
1

votes
0

answer
254

Views

Sequelize Multiple Column in Clause

I have a table called attribute where i need to select based on SQL IN Clause in multiple tables, How can I achieve it using Sequelize in Clause. My Query is : select * from attr where (tid, pid) in ((1, 3440), (344, 3441)) But in Sequelize only 1 column in is Supported.
Soumya
1

votes
0

answer
507

Views

Sequelize query of Sum aggregate functions in Node js

I am actually trying to get all the active and inactive users in one query using this query SELECT SUM(CASE WHEN users.status = 1 THEN 1 ELSE 0 END) AS 'Active_players', SUM(CASE WHEN users.status = 0 THEN 1 ELSE 0 END) AS `InActive_players` FROM `users` AS `users` INNER JOIN `organization_entries`...
Vikas
1

votes
1

answer
223

Views

sequelize with cls not getting current context

I am trying to log mysql queries using sequelize cls and logger module. In this i am loosing the context of namespace Request-Id and it prints either blank or some random previous Request-Id Node Version : 8.9.4 Sequelize : 4.33.4 cls-hooked : 4.2.2 Any help/solution is appreciated. mysql.js const...
Root
1

votes
2

answer
356

Views

Sequelize get MySql stored procedure data as array?

If I call a stored procedure in sequelize, like so: var query = 'CALL GetSatellites();' sequelize.query(query, { type: sequelize.QueryTypes.SELECT}) .spread(responseWithResult(res)) .catch(handleError(res)); and .json() convert it, I get: { '0': { 'timestamp': '2018-02-13T00:00:00.000Z', 'severity':...
Pete Magsig
1

votes
1

answer
528

Views

convert tinyint field as boolean in result using sequelize raw query node.js

I have problem that when I use a raw query in sequelize which is select query the tinyint fields returned are as integers and not as true/false. Here is the code: router.route('/').get(function (req, resp) { sequelize.query('select * from territory_device', {model: territoryDevice}).then(result =>...
aya magdy
1

votes
0

answer
190

Views

Is there a way to setup 2 separate DB pools on a Sequelize connection with replication enabled?

Read Replication Docs I'm essentially trying to decouple the number of connections my master and slaves get in order to maximize the number available connections and load across my read replicas. I'm currently looking for a quick an easy optimization for a Heroku hosted application (40 dynos) that i...
asdfqwer
1

votes
1

answer
83

Views

Sequelize - User model with 2 addresses as foreign keys in a SQL

I have trouble to make a more efficient/cleaner way to insert and find users. I have a user table where I have: id, mail, password, billing_address (foreign key), shipping_address (foreign key) For now, it creates the user then it creates the addresses separately and then it updates the user.billin...
user3144234

View additional questions