regenerate sqlc
This commit is contained in:
@@ -11,6 +11,40 @@ import (
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createAlbum = `-- name: CreateAlbum :one
|
||||
INSERT INTO albums (id, name, artist, release_date, album_art_url) VALUES ($1, $2, $3, $4, $5) RETURNING id
|
||||
`
|
||||
|
||||
type CreateAlbumParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Artist string `json:"artist"`
|
||||
ReleaseDate pgtype.Date `json:"release_date"`
|
||||
AlbumArtUrl pgtype.Text `json:"album_art_url"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateAlbum(ctx context.Context, arg CreateAlbumParams) (pgtype.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, createAlbum,
|
||||
arg.ID,
|
||||
arg.Name,
|
||||
arg.Artist,
|
||||
arg.ReleaseDate,
|
||||
arg.AlbumArtUrl,
|
||||
)
|
||||
var id pgtype.UUID
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const deleteAlbum = `-- name: DeleteAlbum :exec
|
||||
DELETE FROM albums WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteAlbum(ctx context.Context, id pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, deleteAlbum, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const getAlbumByID = `-- name: GetAlbumByID :one
|
||||
SELECT id, name, artist, release_date, album_art_url FROM albums WHERE id = $1
|
||||
`
|
||||
@@ -29,6 +63,36 @@ func (q *Queries) GetAlbumByID(ctx context.Context, id pgtype.UUID) (Album, erro
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getAlbumsByArtist = `-- name: GetAlbumsByArtist :many
|
||||
SELECT id, name, artist, release_date, album_art_url FROM albums WHERE artist = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetAlbumsByArtist(ctx context.Context, artist string) ([]Album, error) {
|
||||
rows, err := q.db.Query(ctx, getAlbumsByArtist, artist)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Album
|
||||
for rows.Next() {
|
||||
var i Album
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.Artist,
|
||||
&i.ReleaseDate,
|
||||
&i.AlbumArtUrl,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getAllAlbums = `-- name: GetAllAlbums :many
|
||||
SELECT id, name, artist, release_date, album_art_url FROM albums
|
||||
`
|
||||
@@ -58,3 +122,56 @@ func (q *Queries) GetAllAlbums(ctx context.Context) ([]Album, error) {
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const searchAlbums = `-- name: SearchAlbums :many
|
||||
SELECT id, name, artist, release_date, album_art_url FROM albums WHERE name ILIKE '%' || $1 || '%' OR artist ILIKE '%' || $1 || '%'
|
||||
`
|
||||
|
||||
func (q *Queries) SearchAlbums(ctx context.Context, dollar_1 pgtype.Text) ([]Album, error) {
|
||||
rows, err := q.db.Query(ctx, searchAlbums, dollar_1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Album
|
||||
for rows.Next() {
|
||||
var i Album
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.Artist,
|
||||
&i.ReleaseDate,
|
||||
&i.AlbumArtUrl,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updateAlbum = `-- name: UpdateAlbum :exec
|
||||
UPDATE albums SET name = $2, artist = $3, release_date = $4, album_art_url = $5 WHERE id = $1
|
||||
`
|
||||
|
||||
type UpdateAlbumParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Artist string `json:"artist"`
|
||||
ReleaseDate pgtype.Date `json:"release_date"`
|
||||
AlbumArtUrl pgtype.Text `json:"album_art_url"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateAlbum(ctx context.Context, arg UpdateAlbumParams) error {
|
||||
_, err := q.db.Exec(ctx, updateAlbum,
|
||||
arg.ID,
|
||||
arg.Name,
|
||||
arg.Artist,
|
||||
arg.ReleaseDate,
|
||||
arg.AlbumArtUrl,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user