regenerate sqlc
This commit is contained in:
@@ -11,6 +11,40 @@ import (
|
|||||||
"github.com/jackc/pgx/v5/pgtype"
|
"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
|
const getAlbumByID = `-- name: GetAlbumByID :one
|
||||||
SELECT id, name, artist, release_date, album_art_url FROM albums WHERE id = $1
|
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
|
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
|
const getAllAlbums = `-- name: GetAllAlbums :many
|
||||||
SELECT id, name, artist, release_date, album_art_url FROM albums
|
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
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -36,6 +36,15 @@ func (q *Queries) CreateArtist(ctx context.Context, arg CreateArtistParams) (pgt
|
|||||||
return id, err
|
return id, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const deleteArtist = `-- name: DeleteArtist :exec
|
||||||
|
DELETE FROM artists WHERE id = $1
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) DeleteArtist(ctx context.Context, id pgtype.UUID) error {
|
||||||
|
_, err := q.db.Exec(ctx, deleteArtist, id)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
const getAllArtists = `-- name: GetAllArtists :many
|
const getAllArtists = `-- name: GetAllArtists :many
|
||||||
SELECT id, name, genre, bio, artist_image_url FROM artists
|
SELECT id, name, genre, bio, artist_image_url FROM artists
|
||||||
`
|
`
|
||||||
@@ -83,3 +92,56 @@ func (q *Queries) GetArtistByID(ctx context.Context, id pgtype.UUID) (Artist, er
|
|||||||
)
|
)
|
||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const searchArtists = `-- name: SearchArtists :many
|
||||||
|
SELECT id, name, genre, bio, artist_image_url FROM artists WHERE name ILIKE '%' || $1 || '%' OR genre ILIKE '%' || $1 || '%'
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) SearchArtists(ctx context.Context, dollar_1 pgtype.Text) ([]Artist, error) {
|
||||||
|
rows, err := q.db.Query(ctx, searchArtists, dollar_1)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
var items []Artist
|
||||||
|
for rows.Next() {
|
||||||
|
var i Artist
|
||||||
|
if err := rows.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.Name,
|
||||||
|
&i.Genre,
|
||||||
|
&i.Bio,
|
||||||
|
&i.ArtistImageUrl,
|
||||||
|
); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
items = append(items, i)
|
||||||
|
}
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
const updateArtist = `-- name: UpdateArtist :exec
|
||||||
|
UPDATE artists SET name = $2, genre = $3, bio = $4, artist_image_url = $5 WHERE id = $1
|
||||||
|
`
|
||||||
|
|
||||||
|
type UpdateArtistParams struct {
|
||||||
|
ID pgtype.UUID `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Genre pgtype.Text `json:"genre"`
|
||||||
|
Bio pgtype.Text `json:"bio"`
|
||||||
|
ArtistImageUrl pgtype.Text `json:"artist_image_url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) UpdateArtist(ctx context.Context, arg UpdateArtistParams) error {
|
||||||
|
_, err := q.db.Exec(ctx, updateArtist,
|
||||||
|
arg.ID,
|
||||||
|
arg.Name,
|
||||||
|
arg.Genre,
|
||||||
|
arg.Bio,
|
||||||
|
arg.ArtistImageUrl,
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|||||||
+14
-11
@@ -25,18 +25,21 @@ type Artist struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
ID pgtype.UUID `json:"id"`
|
ID pgtype.UUID `json:"id"`
|
||||||
UserName string `json:"user_name"`
|
UserName string `json:"user_name"`
|
||||||
UserMail string `json:"user_mail"`
|
UserMail string `json:"user_mail"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
CreatedAt pgtype.Timestamp `json:"created_at"`
|
CreatedAt pgtype.Timestamp `json:"created_at"`
|
||||||
|
SessionToken pgtype.Text `json:"session_token"`
|
||||||
|
SessionExpiry pgtype.Timestamp `json:"session_expiry"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserAlbum struct {
|
type UserAlbum struct {
|
||||||
UserID pgtype.UUID `json:"user_id"`
|
UserID pgtype.UUID `json:"user_id"`
|
||||||
AlbumID pgtype.UUID `json:"album_id"`
|
AlbumID pgtype.UUID `json:"album_id"`
|
||||||
AlbumOwned bool `json:"album_owned"`
|
DateAdded pgtype.Timestamp `json:"date_added"`
|
||||||
AlbumWant bool `json:"album_want"`
|
AlbumOwned bool `json:"album_owned"`
|
||||||
IsVinyl bool `json:"is_vinyl"`
|
AlbumWant bool `json:"album_want"`
|
||||||
IsCd bool `json:"is_cd"`
|
IsVinyl bool `json:"is_vinyl"`
|
||||||
|
IsCd bool `json:"is_cd"`
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-2
@@ -11,19 +11,35 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Querier interface {
|
type Querier interface {
|
||||||
|
AddUserAlbum(ctx context.Context, arg AddUserAlbumParams) error
|
||||||
CheckUserExistsByEmail(ctx context.Context, userMail string) (pgtype.UUID, error)
|
CheckUserExistsByEmail(ctx context.Context, userMail string) (pgtype.UUID, error)
|
||||||
|
CreateAlbum(ctx context.Context, arg CreateAlbumParams) (pgtype.UUID, error)
|
||||||
CreateArtist(ctx context.Context, arg CreateArtistParams) (pgtype.UUID, error)
|
CreateArtist(ctx context.Context, arg CreateArtistParams) (pgtype.UUID, error)
|
||||||
|
// users.sql
|
||||||
CreateUser(ctx context.Context, arg CreateUserParams) (pgtype.UUID, error)
|
CreateUser(ctx context.Context, arg CreateUserParams) (pgtype.UUID, error)
|
||||||
|
DeleteAlbum(ctx context.Context, id pgtype.UUID) error
|
||||||
|
DeleteArtist(ctx context.Context, id pgtype.UUID) error
|
||||||
// albums.sql
|
// albums.sql
|
||||||
GetAlbumByID(ctx context.Context, id pgtype.UUID) (Album, error)
|
GetAlbumByID(ctx context.Context, id pgtype.UUID) (Album, error)
|
||||||
|
GetAlbumsByArtist(ctx context.Context, artist string) ([]Album, error)
|
||||||
GetAllAlbums(ctx context.Context) ([]Album, error)
|
GetAllAlbums(ctx context.Context) ([]Album, error)
|
||||||
GetAllArtists(ctx context.Context) ([]Artist, error)
|
GetAllArtists(ctx context.Context) ([]Artist, error)
|
||||||
// artists.sql
|
// artists.sql
|
||||||
GetArtistByID(ctx context.Context, id pgtype.UUID) (Artist, error)
|
GetArtistByID(ctx context.Context, id pgtype.UUID) (Artist, error)
|
||||||
// users.sql
|
GetUserAlbum(ctx context.Context, arg GetUserAlbumParams) (GetUserAlbumRow, error)
|
||||||
GetUsernameByID(ctx context.Context, id pgtype.UUID) (string, error)
|
|
||||||
// user_albums.sql
|
// user_albums.sql
|
||||||
|
GetUserAlbums(ctx context.Context, userID pgtype.UUID) ([]GetUserAlbumsRow, error)
|
||||||
|
GetUserByID(ctx context.Context, id pgtype.UUID) (GetUserByIDRow, error)
|
||||||
|
GetUsernameByID(ctx context.Context, id pgtype.UUID) (string, error)
|
||||||
|
LoginUser(ctx context.Context, arg LoginUserParams) (LoginUserRow, error)
|
||||||
|
RemoveUserAlbum(ctx context.Context, arg RemoveUserAlbumParams) error
|
||||||
|
SearchAlbums(ctx context.Context, dollar_1 pgtype.Text) ([]Album, error)
|
||||||
|
SearchArtists(ctx context.Context, dollar_1 pgtype.Text) ([]Artist, error)
|
||||||
|
UpdateAlbum(ctx context.Context, arg UpdateAlbumParams) error
|
||||||
|
UpdateArtist(ctx context.Context, arg UpdateArtistParams) error
|
||||||
|
UpdateUser(ctx context.Context, arg UpdateUserParams) error
|
||||||
UpdateUserAlbumStatus(ctx context.Context, arg UpdateUserAlbumStatusParams) error
|
UpdateUserAlbumStatus(ctx context.Context, arg UpdateUserAlbumStatusParams) error
|
||||||
|
UpdateUserSession(ctx context.Context, arg UpdateUserSessionParams) error
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ Querier = (*Queries)(nil)
|
var _ Querier = (*Queries)(nil)
|
||||||
|
|||||||
+139
-1
@@ -11,6 +11,145 @@ import (
|
|||||||
"github.com/jackc/pgx/v5/pgtype"
|
"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
|
const updateUserAlbumStatus = `-- name: UpdateUserAlbumStatus :exec
|
||||||
INSERT INTO user_albums (user_id, album_id, album_owned, album_want,
|
INSERT INTO user_albums (user_id, album_id, album_owned, album_want,
|
||||||
is_vinyl, is_cd) VALUES ($1, $2, $3, $4, $5, $6)
|
is_vinyl, is_cd) VALUES ($1, $2, $3, $4, $5, $6)
|
||||||
@@ -30,7 +169,6 @@ type UpdateUserAlbumStatusParams struct {
|
|||||||
IsCd bool `json:"is_cd"`
|
IsCd bool `json:"is_cd"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// user_albums.sql
|
|
||||||
func (q *Queries) UpdateUserAlbumStatus(ctx context.Context, arg UpdateUserAlbumStatusParams) error {
|
func (q *Queries) UpdateUserAlbumStatus(ctx context.Context, arg UpdateUserAlbumStatusParams) error {
|
||||||
_, err := q.db.Exec(ctx, updateUserAlbumStatus,
|
_, err := q.db.Exec(ctx, updateUserAlbumStatus,
|
||||||
arg.UserID,
|
arg.UserID,
|
||||||
|
|||||||
+82
-1
@@ -33,6 +33,7 @@ type CreateUserParams struct {
|
|||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// users.sql
|
||||||
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (pgtype.UUID, error) {
|
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (pgtype.UUID, error) {
|
||||||
row := q.db.QueryRow(ctx, createUser,
|
row := q.db.QueryRow(ctx, createUser,
|
||||||
arg.ID,
|
arg.ID,
|
||||||
@@ -45,14 +46,94 @@ func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (pgtype.
|
|||||||
return id, err
|
return id, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getUserByID = `-- name: GetUserByID :one
|
||||||
|
SELECT id, user_name, user_mail, created_at FROM users WHERE id = $1
|
||||||
|
`
|
||||||
|
|
||||||
|
type GetUserByIDRow struct {
|
||||||
|
ID pgtype.UUID `json:"id"`
|
||||||
|
UserName string `json:"user_name"`
|
||||||
|
UserMail string `json:"user_mail"`
|
||||||
|
CreatedAt pgtype.Timestamp `json:"created_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) GetUserByID(ctx context.Context, id pgtype.UUID) (GetUserByIDRow, error) {
|
||||||
|
row := q.db.QueryRow(ctx, getUserByID, id)
|
||||||
|
var i GetUserByIDRow
|
||||||
|
err := row.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.UserName,
|
||||||
|
&i.UserMail,
|
||||||
|
&i.CreatedAt,
|
||||||
|
)
|
||||||
|
return i, err
|
||||||
|
}
|
||||||
|
|
||||||
const getUsernameByID = `-- name: GetUsernameByID :one
|
const getUsernameByID = `-- name: GetUsernameByID :one
|
||||||
SELECT user_name FROM users WHERE id = $1
|
SELECT user_name FROM users WHERE id = $1
|
||||||
`
|
`
|
||||||
|
|
||||||
// users.sql
|
|
||||||
func (q *Queries) GetUsernameByID(ctx context.Context, id pgtype.UUID) (string, error) {
|
func (q *Queries) GetUsernameByID(ctx context.Context, id pgtype.UUID) (string, error) {
|
||||||
row := q.db.QueryRow(ctx, getUsernameByID, id)
|
row := q.db.QueryRow(ctx, getUsernameByID, id)
|
||||||
var user_name string
|
var user_name string
|
||||||
err := row.Scan(&user_name)
|
err := row.Scan(&user_name)
|
||||||
return user_name, err
|
return user_name, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const loginUser = `-- name: LoginUser :one
|
||||||
|
SELECT id, user_name, user_mail FROM users WHERE user_mail = $1 AND password = $2
|
||||||
|
`
|
||||||
|
|
||||||
|
type LoginUserParams struct {
|
||||||
|
UserMail string `json:"user_mail"`
|
||||||
|
Password string `json:"password"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type LoginUserRow struct {
|
||||||
|
ID pgtype.UUID `json:"id"`
|
||||||
|
UserName string `json:"user_name"`
|
||||||
|
UserMail string `json:"user_mail"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) LoginUser(ctx context.Context, arg LoginUserParams) (LoginUserRow, error) {
|
||||||
|
row := q.db.QueryRow(ctx, loginUser, arg.UserMail, arg.Password)
|
||||||
|
var i LoginUserRow
|
||||||
|
err := row.Scan(&i.ID, &i.UserName, &i.UserMail)
|
||||||
|
return i, err
|
||||||
|
}
|
||||||
|
|
||||||
|
const updateUser = `-- name: UpdateUser :exec
|
||||||
|
UPDATE users SET user_name = $2, user_mail = $3, password = $4 WHERE id = $1
|
||||||
|
`
|
||||||
|
|
||||||
|
type UpdateUserParams struct {
|
||||||
|
ID pgtype.UUID `json:"id"`
|
||||||
|
UserName string `json:"user_name"`
|
||||||
|
UserMail string `json:"user_mail"`
|
||||||
|
Password string `json:"password"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) error {
|
||||||
|
_, err := q.db.Exec(ctx, updateUser,
|
||||||
|
arg.ID,
|
||||||
|
arg.UserName,
|
||||||
|
arg.UserMail,
|
||||||
|
arg.Password,
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
const updateUserSession = `-- name: UpdateUserSession :exec
|
||||||
|
UPDATE users SET session_token = $2, session_expiry = $3 WHERE id = $1
|
||||||
|
`
|
||||||
|
|
||||||
|
type UpdateUserSessionParams struct {
|
||||||
|
ID pgtype.UUID `json:"id"`
|
||||||
|
SessionToken pgtype.Text `json:"session_token"`
|
||||||
|
SessionExpiry pgtype.Timestamp `json:"session_expiry"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) UpdateUserSession(ctx context.Context, arg UpdateUserSessionParams) error {
|
||||||
|
_, err := q.db.Exec(ctx, updateUserSession, arg.ID, arg.SessionToken, arg.SessionExpiry)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user