feat: add create short url

This commit is contained in:
Bastien Riviere 2024-01-29 21:21:23 +01:00
parent c7be765c23
commit 31fde6cad6
Signed by: babariviere
GPG key ID: 4E5F0839249F162E
8 changed files with 149 additions and 20 deletions

View file

@ -20,3 +20,22 @@ func (q *Queries) GetURLByHash(ctx context.Context, hash string) (Url, error) {
err := row.Scan(&i.ID, &i.Hash, &i.LongUrl)
return i, err
}
const insertURL = `-- name: InsertURL :one
INSERT INTO urls (hash, long_url)
VALUES ($1, $2)
ON CONFLICT (hash) DO NOTHING
RETURNING id, hash, long_url
`
type InsertURLParams struct {
Hash string
LongUrl string
}
func (q *Queries) InsertURL(ctx context.Context, arg InsertURLParams) (Url, error) {
row := q.db.QueryRow(ctx, insertURL, arg.Hash, arg.LongUrl)
var i Url
err := row.Scan(&i.ID, &i.Hash, &i.LongUrl)
return i, err
}