short/internal/db/query.sql.go

42 lines
924 B
Go
Raw Permalink Normal View History

2024-01-29 18:32:01 +00:00
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.25.0
// source: query.sql
package db
import (
"context"
)
const getURLByHash = `-- name: GetURLByHash :one
SELECT id, hash, long_url FROM urls
WHERE hash = $1
`
func (q *Queries) GetURLByHash(ctx context.Context, hash string) (Url, error) {
row := q.db.QueryRow(ctx, getURLByHash, hash)
var i Url
err := row.Scan(&i.ID, &i.Hash, &i.LongUrl)
return i, err
}
2024-01-29 20:21:23 +00:00
const insertURL = `-- name: InsertURL :one
INSERT INTO urls (hash, long_url)
VALUES ($1, $2)
2024-01-29 20:37:27 +00:00
ON CONFLICT (hash) DO UPDATE SET hash = EXCLUDED.hash -- force row to be returned
2024-01-29 20:21:23 +00:00
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
}