我正在尝试自动化一些我每周都在运行的脚本。
mySQL脚本:
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)
在knexjs文件中:
const knex = require('knex')({
client: 'mysql',
connection: {
host: myIP,
port: myPort,
debug: true,
dateStrings: true,
user: user,
password: pwd,
database: myDB
}
})
查询构建部分:
(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)
})()
如何在knexjs语法中在.where()
和.select()
子句中添加日期格式化?