Search code examples
postgresqlloopbackjs

How do I update a column's value based on the current time?


In PostgreSQL, I want the ability to update a column, 'closed', based on another column (close_time) compared to the current time. How do I check if the time now is greater than the close_time and update the column 'closed' to true if it now is greater than the closing time?


Solution

  • If you are using loopback 4, you can do this using update method of repository.

    await this.userRepository.updateById(id, user);
    

    If you want this to happen automatically at DB level, then you can use DB triggers in postgres. See a tutorial here - http://www.postgresqltutorial.com/creating-first-trigger-postgresql/