sequelize.js

Value is not getting inserted in the array,array returns blank values

吃可爱长大的小学妹 提交于 2020-01-05 07:12:18
问题 I have following code , the problem is that obj is not inserted in the array arr. let arr=[]; let frommilisec=1620000000; let tomilisec=4680000000; let slotmilisec=900000; while(frommilisec<=tomilisec) { let timeslot_milisec=frommilisec+slotmilisec; clinicslotsfunc(timeslot_milisec,maximumAppointment,clinicid,dated).then(results=> { let obj=results[0]; console.log(obj); // this displays { slot: '12:30:00', isbooked: 1 } arr.push(obj); }); console.log(arr) //this logs blank array frommilisec

Sequelize calculate value before saving

丶灬走出姿态 提交于 2020-01-05 04:36:12
问题 I want to calculate the difference in hours before saving a model. I have tried beforeUpdate (and other hooks), but the field is never calculated. I have also tried the set: option, but that doesn't work either. I have to fields 'started_at' and 'ended_at'. If ended_at is not null, then calc difference and save to field hours. I have tried: hours: { type: DataTypes.DECIMAL(10,2), allowNull: true, set: function(){ var duration = 0; if(this.ended_at){ var Start = moment(this.started_at); var

Get raw query generated by sequelize.js [duplicate]

只愿长相守 提交于 2020-01-05 04:34:10
问题 This question already has answers here : How can I see the SQL generated by Sequelize.js? (3 answers) Closed 2 years ago . Good afternoon everyone. I am developing a node.js/express system using sequelize.js (postgresql). My problem is: I need to store the raw queries generated by sequelize in a log history, but I can't find a function that returns the generated query. Does anyone know if sequelize provides a function that returns the generated SQL query, or if there's any other way to

Logging into local SQL Server instance with windows auth

孤街浪徒 提交于 2020-01-05 04:10:11
问题 I have a nodejs and express based project. I currently use sequelize to connect to a SQL Server instance. This works fine for external SQL Servers using SQL Server authentication. However, I am now trying to connect to a local SQL Server instance using Windows auth. This is what my connection string looks like: export var sequelize = new Sequelize({ dialect: 'mssql', dialectModulePath: 'sequelize-msnodesqlv8', dialectOptions: { connectionString: 'Server=localhost\MSSQLSERVER01;Database=DB

How to add logging for sequelize update

徘徊边缘 提交于 2020-01-05 04:07:12
问题 In my project sequelize logging is disabled, but I want active logging in the exact query. How can I do that? TableModel.update( {counter: 0}, {where: { id: itm.i }}, ).then((res) =>{ console.log('res',res); }).catch(e => { console.log('update error : ', e); }); I know how I can do it in findall query like this: TableModel.findAll({where: {...}, logging: console.log}) but in the update, I can't find any solution. sequelize version: 5.21 回答1: I found solution. that was so easy just adding

Achieve Single Table Inheritance with Sequelize

人走茶凉 提交于 2020-01-05 03:06:53
问题 Is there a way to use sequelize to create single table inheritance? I would like to have a STI for a Purchase and PartialPurchase model where I would have a type field which would be "Purchase" or "PartialPurchase" and classes Purchase and PartialPurchase which would each inherit from an Operation class. I don't see this as supported by sequelize, but is an implementation possible? 回答1: Hey so I know you didn't get an answer to this, in a reasonable time, but you can use a type column that's

Achieve Single Table Inheritance with Sequelize

我与影子孤独终老i 提交于 2020-01-05 03:06:25
问题 Is there a way to use sequelize to create single table inheritance? I would like to have a STI for a Purchase and PartialPurchase model where I would have a type field which would be "Purchase" or "PartialPurchase" and classes Purchase and PartialPurchase which would each inherit from an Operation class. I don't see this as supported by sequelize, but is an implementation possible? 回答1: Hey so I know you didn't get an answer to this, in a reasonable time, but you can use a type column that's

Webpack Error: please install sqlite3 package manually

房东的猫 提交于 2020-01-04 06:57:07
问题 I'm building an application with Electron and Sequelize. I started to configure my database, then, I've received this error: Uncaught Error: Please install sqlite3 package manually at new ConnectionManager (/home/matheusdrdj/Documentos/Git/personal- management/node_modules/sequelize/lib/dialects/sqlite/con…:31) at new SqliteDialect (/home/matheusdrdj/Documentos/Git/personal- management/node_modules/sequelize/lib/dialects/sqlite/ind…:14) at new Sequelize (/home/matheusdrdj/Documentos/Git

Insert data in a 4D spatial column using Sequelize

非 Y 不嫁゛ 提交于 2020-01-04 05:51:22
问题 My application uses Node.js (v9.3.0), PostgreSQL (v9.5.1.0) as database with PostGIS (v2.2.1) installed as an extension and Sequelize (v4.37.6) as ORM. I'm trying to insert a 4D data - with longitude, latitude, altitude and a unix timestamp - in a LineStringZM column but I'm getting the following error: DatabaseError: Column has M dimension but geometry does not After some research, I've found out that Sequelize uses the function ST_GeomFromGeoJSON to insert spatial data. However, this

Sequelize increment function returning error

北战南征 提交于 2020-01-04 05:22:18
问题 Trying to increment an integer field on a model instance in my DB. Here is the relevant code. models.Options.findAll({ where: { PollId: poll_id, name: option_to_update } }).then((option) => { option.increment('votes'); res.json(option); }); When I console.log(option), it shows as an Instance so I know it inherits from the Instance class which has an increment function as can be seen here https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/instance.js#L934