del.js 886 B

1234567891011121314151617181920212223242526272829303132
  1. import mysql from "mysql2/promise"
  2. async function del(start, end) {
  3. const connection = await mysql.createConnection({
  4. host: "rm-bp1cj5j76a6hp1zm5yo.rwlb.rds.aliyuncs.com",
  5. user: "rcs",
  6. password: "hsDL6W@5a%F@wNA@8AP&",
  7. database: "rcs"
  8. })
  9. const [results, fields] = await connection.query(
  10. `SELECT * from task where createdAt >= '${start}' and createdAt < '${end}'`
  11. )
  12. for (let task of results) {
  13. const [items] = await connection.query(
  14. `select * from task_item where taskId = ${task.id}`
  15. )
  16. console.log(task.id, items.length)
  17. await connection.query(
  18. `delete from task_item where taskId = ${task.id}`
  19. )
  20. }
  21. }
  22. await Promise.all([
  23. del("2024-08-01 00:00:00", "2024-08-20 00:00:00"),
  24. del("2024-08-20 00:00:00", "2024-09-01 00:00:00")
  25. ])
  26. connection.end()