regenerate sqlc
This commit is contained in:
+139
-1
@@ -11,6 +11,145 @@ import (
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const addUserAlbum = `-- name: AddUserAlbum :exec
|
||||
INSERT INTO user_albums (user_id, album_id, album_owned, album_want,
|
||||
is_vinyl, is_cd) VALUES ($1, $2, $3, $4, $5, $6)
|
||||
`
|
||||
|
||||
type AddUserAlbumParams struct {
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
AlbumID pgtype.UUID `json:"album_id"`
|
||||
AlbumOwned bool `json:"album_owned"`
|
||||
AlbumWant bool `json:"album_want"`
|
||||
IsVinyl bool `json:"is_vinyl"`
|
||||
IsCd bool `json:"is_cd"`
|
||||
}
|
||||
|
||||
func (q *Queries) AddUserAlbum(ctx context.Context, arg AddUserAlbumParams) error {
|
||||
_, err := q.db.Exec(ctx, addUserAlbum,
|
||||
arg.UserID,
|
||||
arg.AlbumID,
|
||||
arg.AlbumOwned,
|
||||
arg.AlbumWant,
|
||||
arg.IsVinyl,
|
||||
arg.IsCd,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const getUserAlbum = `-- name: GetUserAlbum :one
|
||||
SELECT ua.user_id, ua.album_id, ua.date_added, ua.album_owned, ua.album_want, ua.is_vinyl, ua.is_cd, a.name AS album_name, a.artist AS album_artist, a.release_date, a.album_art_url
|
||||
FROM user_albums ua
|
||||
JOIN albums a ON ua.album_id = a.id
|
||||
WHERE ua.user_id = $1 AND ua.album_id = $2
|
||||
`
|
||||
|
||||
type GetUserAlbumParams struct {
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
AlbumID pgtype.UUID `json:"album_id"`
|
||||
}
|
||||
|
||||
type GetUserAlbumRow struct {
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
AlbumID pgtype.UUID `json:"album_id"`
|
||||
DateAdded pgtype.Timestamp `json:"date_added"`
|
||||
AlbumOwned bool `json:"album_owned"`
|
||||
AlbumWant bool `json:"album_want"`
|
||||
IsVinyl bool `json:"is_vinyl"`
|
||||
IsCd bool `json:"is_cd"`
|
||||
AlbumName string `json:"album_name"`
|
||||
AlbumArtist string `json:"album_artist"`
|
||||
ReleaseDate pgtype.Date `json:"release_date"`
|
||||
AlbumArtUrl pgtype.Text `json:"album_art_url"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetUserAlbum(ctx context.Context, arg GetUserAlbumParams) (GetUserAlbumRow, error) {
|
||||
row := q.db.QueryRow(ctx, getUserAlbum, arg.UserID, arg.AlbumID)
|
||||
var i GetUserAlbumRow
|
||||
err := row.Scan(
|
||||
&i.UserID,
|
||||
&i.AlbumID,
|
||||
&i.DateAdded,
|
||||
&i.AlbumOwned,
|
||||
&i.AlbumWant,
|
||||
&i.IsVinyl,
|
||||
&i.IsCd,
|
||||
&i.AlbumName,
|
||||
&i.AlbumArtist,
|
||||
&i.ReleaseDate,
|
||||
&i.AlbumArtUrl,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUserAlbums = `-- name: GetUserAlbums :many
|
||||
SELECT ua.user_id, ua.album_id, ua.date_added, ua.album_owned, ua.album_want, ua.is_vinyl, ua.is_cd, a.name AS album_name, a.artist AS album_artist, a.release_date, a.album_art_url
|
||||
FROM user_albums ua
|
||||
JOIN albums a ON ua.album_id = a.id
|
||||
WHERE ua.user_id = $1
|
||||
`
|
||||
|
||||
type GetUserAlbumsRow struct {
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
AlbumID pgtype.UUID `json:"album_id"`
|
||||
DateAdded pgtype.Timestamp `json:"date_added"`
|
||||
AlbumOwned bool `json:"album_owned"`
|
||||
AlbumWant bool `json:"album_want"`
|
||||
IsVinyl bool `json:"is_vinyl"`
|
||||
IsCd bool `json:"is_cd"`
|
||||
AlbumName string `json:"album_name"`
|
||||
AlbumArtist string `json:"album_artist"`
|
||||
ReleaseDate pgtype.Date `json:"release_date"`
|
||||
AlbumArtUrl pgtype.Text `json:"album_art_url"`
|
||||
}
|
||||
|
||||
// user_albums.sql
|
||||
func (q *Queries) GetUserAlbums(ctx context.Context, userID pgtype.UUID) ([]GetUserAlbumsRow, error) {
|
||||
rows, err := q.db.Query(ctx, getUserAlbums, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []GetUserAlbumsRow
|
||||
for rows.Next() {
|
||||
var i GetUserAlbumsRow
|
||||
if err := rows.Scan(
|
||||
&i.UserID,
|
||||
&i.AlbumID,
|
||||
&i.DateAdded,
|
||||
&i.AlbumOwned,
|
||||
&i.AlbumWant,
|
||||
&i.IsVinyl,
|
||||
&i.IsCd,
|
||||
&i.AlbumName,
|
||||
&i.AlbumArtist,
|
||||
&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 removeUserAlbum = `-- name: RemoveUserAlbum :exec
|
||||
DELETE FROM user_albums WHERE user_id = $1 AND album_id = $2
|
||||
`
|
||||
|
||||
type RemoveUserAlbumParams struct {
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
AlbumID pgtype.UUID `json:"album_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) RemoveUserAlbum(ctx context.Context, arg RemoveUserAlbumParams) error {
|
||||
_, err := q.db.Exec(ctx, removeUserAlbum, arg.UserID, arg.AlbumID)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateUserAlbumStatus = `-- name: UpdateUserAlbumStatus :exec
|
||||
INSERT INTO user_albums (user_id, album_id, album_owned, album_want,
|
||||
is_vinyl, is_cd) VALUES ($1, $2, $3, $4, $5, $6)
|
||||
@@ -30,7 +169,6 @@ type UpdateUserAlbumStatusParams struct {
|
||||
IsCd bool `json:"is_cd"`
|
||||
}
|
||||
|
||||
// user_albums.sql
|
||||
func (q *Queries) UpdateUserAlbumStatus(ctx context.Context, arg UpdateUserAlbumStatusParams) error {
|
||||
_, err := q.db.Exec(ctx, updateUserAlbumStatus,
|
||||
arg.UserID,
|
||||
|
||||
Reference in New Issue
Block a user