I'm trying to automate some scripts that i've been running weekly.
The mySQL script:
select count(*), date(updated) from myDB.table where itemId = 50 and date(updated) >= "2017-12-01" and date(updated) <= date(now()) group by date(updated)
In knexjs file:
const knex = require('knex')({
client: 'mysql',
connection: {
host: myIP,
port: myPort,
debug: true,
dateStrings: true,
user: user,
password: pwd,
database: myDB
}
})
The query building part:
(async () => {
let data = await knex
.select('updated')
.count()
.from('myDB.table')
.where('itemId', '=', 50)
.where('updated', '>=', '2017-12-01')
.where('updated', '<=', Date())
.groupByRaw('date(updated)')
console.log(data)
})()
How do i add date formating within .where()
and .select()
clause, in knexjs syntax?