fix: return URL if it already exists

This commit is contained in:
Bastien Riviere 2024-01-29 21:37:27 +01:00
parent 38f29e147f
commit a3dc0b646b
Signed by: babariviere
GPG key ID: 4E5F0839249F162E
3 changed files with 2 additions and 8 deletions

View file

@ -24,7 +24,7 @@ func (q *Queries) GetURLByHash(ctx context.Context, hash string) (Url, error) {
const insertURL = `-- name: InsertURL :one
INSERT INTO urls (hash, long_url)
VALUES ($1, $2)
ON CONFLICT (hash) DO NOTHING
ON CONFLICT (hash) DO UPDATE SET hash = EXCLUDED.hash -- force row to be returned
RETURNING id, hash, long_url
`