How does mysql query the summary data for today and seven days through knex

  node.js, question

The specific implementation is to query the number of products in the product table for today, seven days and thirty days, and the specific sql statement has been written

select sum(inputer as productNum) from `product` where to_days(`createdAt`)= to_days(now());

But in knex.js, I am writing this wrong at all.

return knex('product')
 .where({ inputer: user, deletedAt: null })
 .andWhere('to_days(add_time)', '=', 'to_days(now())')
 .sum('inputer as productNum')
 .then(function (productRow) {
 return { product: productRow };
 })

Using having is also wrong, knex document inside did not see the use of aggregate functions, please advise

return knex('product')
 .where({ inputer: user, deletedAt: null })
 .groupBy(id)
 .having('to_days(add_time)', '=', 'to_days(now())')
 .sum('inputer as productNum')
 .then(function (productRow) {
 return { product: productRow };
 })

Never usedknex.js, but SQL seems to be complicated (the original SQL will be rightcreatedAtField operation, may make the index of the field invalid).

SELECT sum(inputer) AS product_num FROM `product`
 WHERE createdAt >= ?

The starting time of today, 7 days ago and 30 days ago (i.e. yyy-mm-dd00: 00: 00) is calculated through the program, and then it can be substituted into SQL.