ニジカ投稿局 https://tv.nizika.tv
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

35 lines
749 B

  1. import { QueryTypes, Sequelize, Transaction } from 'sequelize'
  2. const updating = new Set<string>()
  3. // Sequelize always skip the update if we only update updatedAt field
  4. async function setAsUpdated (options: {
  5. sequelize: Sequelize
  6. table: string
  7. id: number
  8. transaction?: Transaction
  9. }) {
  10. const { sequelize, table, id, transaction } = options
  11. const key = table + '-' + id
  12. if (updating.has(key)) return
  13. updating.add(key)
  14. try {
  15. await sequelize.query(
  16. `UPDATE "${table}" SET "updatedAt" = :updatedAt WHERE id = :id`,
  17. {
  18. replacements: { table, id, updatedAt: new Date() },
  19. type: QueryTypes.UPDATE,
  20. transaction
  21. }
  22. )
  23. } finally {
  24. updating.delete(key)
  25. }
  26. }
  27. export {
  28. setAsUpdated
  29. }