S
S
Sergey Turbanov2018-07-12 11:42:17
Node.js
Sergey Turbanov, 2018-07-12 11:42:17

Is there an implementation of SELECT FLOOR(.....) as UserVariable in sequilize, when using a model?

I am writing a complex query to the database. It is necessary to implement a line that would generate the following line in the SELECT part of the query:

FLOOR(UNIX_TIMESTAMP(`tablename`.`timestamp`) /24 /60 /60) AS mtime

but could not find an implementation of the FLOOR operation and UNIX_TIMESTAMP.
This is how I build the query, I found the implementation of the COUNT method
models.devices.findAll({
                    where: {
                        id: {$in: mas_id},
                        enabled: true
                    },
                    order: ,
                    attributes: [
                        'id',
                        'name',
                        [
                            models.sequelize.fn('sum', models.sequelize.col('devices_keys->devices_statistics.count')), 
                            'sums'
                        ]
                    ],
                    include: [{
                        model: models.devices_keys,
                        where:{
                            direction_id: 0
                        },
                        include: [{
                            model: models.stat_keys,
                            where:{
                                id: {$in: [1,2]}
                            }
                        },{
                            model: models.devices_statistics,
                            where:{
                                timestamp: {$between: ['2018-06-12 00:00:00','2018-06-15 00:00:00']}
                            }
                        }]
                    }]
                }).then(data2 => {....})

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question