Use prepared statement for intervals

This commit is contained in:
jvoisin 2024-02-26 11:45:52 +01:00 committed by Frédéric Guillot
parent b054506e3a
commit 7660910232
2 changed files with 4 additions and 4 deletions

View File

@ -128,9 +128,9 @@ func (s *Storage) CleanOldSessions(days int) int64 {
DELETE FROM
sessions
WHERE
created_at < now() - interval '%d days'
created_at < now() - $1::interval
`
result, err := s.db.Exec(fmt.Sprintf(query, days))
result, err := s.db.Exec(query, fmt.Sprintf("%d days", days))
if err != nil {
return 0
}

View File

@ -170,9 +170,9 @@ func (s *Storage) CleanOldUserSessions(days int) int64 {
DELETE FROM
user_sessions
WHERE
created_at < now() - interval '%d days'
created_at < now() - $1::interval
`
result, err := s.db.Exec(fmt.Sprintf(query, days))
result, err := s.db.Exec(query, fmt.Sprintf("%d days", days))
if err != nil {
return 0
}