Add initial database setup and user/artist management functionality
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: albums.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const getAlbumByID = `-- name: GetAlbumByID :one
|
||||
SELECT id, name, artist, release_date, album_art_url FROM albums WHERE id = $1
|
||||
`
|
||||
|
||||
// albums.sql
|
||||
func (q *Queries) GetAlbumByID(ctx context.Context, id pgtype.UUID) (Album, error) {
|
||||
row := q.db.QueryRow(ctx, getAlbumByID, id)
|
||||
var i Album
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.Artist,
|
||||
&i.ReleaseDate,
|
||||
&i.AlbumArtUrl,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getAllAlbums = `-- name: GetAllAlbums :many
|
||||
SELECT id, name, artist, release_date, album_art_url FROM albums
|
||||
`
|
||||
|
||||
func (q *Queries) GetAllAlbums(ctx context.Context) ([]Album, error) {
|
||||
rows, err := q.db.Query(ctx, getAllAlbums)
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: artists.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createArtist = `-- name: CreateArtist :one
|
||||
INSERT INTO artists (id, name, genre, bio, artist_image_url) VALUES ($1, $2, $3, $4, $5) RETURNING id
|
||||
`
|
||||
|
||||
type CreateArtistParams 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) CreateArtist(ctx context.Context, arg CreateArtistParams) (pgtype.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, createArtist,
|
||||
arg.ID,
|
||||
arg.Name,
|
||||
arg.Genre,
|
||||
arg.Bio,
|
||||
arg.ArtistImageUrl,
|
||||
)
|
||||
var id pgtype.UUID
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const getAllArtists = `-- name: GetAllArtists :many
|
||||
SELECT id, name, genre, bio, artist_image_url FROM artists
|
||||
`
|
||||
|
||||
func (q *Queries) GetAllArtists(ctx context.Context) ([]Artist, error) {
|
||||
rows, err := q.db.Query(ctx, getAllArtists)
|
||||
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 getArtistByID = `-- name: GetArtistByID :one
|
||||
SELECT id, name, genre, bio, artist_image_url FROM artists WHERE id = $1
|
||||
`
|
||||
|
||||
// artists.sql
|
||||
func (q *Queries) GetArtistByID(ctx context.Context, id pgtype.UUID) (Artist, error) {
|
||||
row := q.db.QueryRow(ctx, getArtistByID, id)
|
||||
var i Artist
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.Genre,
|
||||
&i.Bio,
|
||||
&i.ArtistImageUrl,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
)
|
||||
|
||||
type DBTX interface {
|
||||
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
|
||||
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
|
||||
QueryRow(context.Context, string, ...interface{}) pgx.Row
|
||||
}
|
||||
|
||||
func New(db DBTX) *Queries {
|
||||
return &Queries{db: db}
|
||||
}
|
||||
|
||||
type Queries struct {
|
||||
db DBTX
|
||||
}
|
||||
|
||||
func (q *Queries) WithTx(tx pgx.Tx) *Queries {
|
||||
return &Queries{
|
||||
db: tx,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
type Album 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"`
|
||||
}
|
||||
|
||||
type Artist 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"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserName string `json:"user_name"`
|
||||
UserMail string `json:"user_mail"`
|
||||
Password string `json:"password"`
|
||||
CreatedAt pgtype.Timestamp `json:"created_at"`
|
||||
}
|
||||
|
||||
type UserAlbum 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"`
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
type Querier interface {
|
||||
CheckUserExistsByEmail(ctx context.Context, userMail string) (pgtype.UUID, error)
|
||||
CreateArtist(ctx context.Context, arg CreateArtistParams) (pgtype.UUID, error)
|
||||
CreateUser(ctx context.Context, arg CreateUserParams) (pgtype.UUID, error)
|
||||
// albums.sql
|
||||
GetAlbumByID(ctx context.Context, id pgtype.UUID) (Album, error)
|
||||
GetAllAlbums(ctx context.Context) ([]Album, error)
|
||||
GetAllArtists(ctx context.Context) ([]Artist, error)
|
||||
// artists.sql
|
||||
GetArtistByID(ctx context.Context, id pgtype.UUID) (Artist, error)
|
||||
// users.sql
|
||||
GetUsernameByID(ctx context.Context, id pgtype.UUID) (string, error)
|
||||
// user_albums.sql
|
||||
UpdateUserAlbumStatus(ctx context.Context, arg UpdateUserAlbumStatusParams) error
|
||||
}
|
||||
|
||||
var _ Querier = (*Queries)(nil)
|
||||
@@ -0,0 +1,44 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: user_albums.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
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)
|
||||
ON CONFLICT (user_id, album_id) DO UPDATE SET
|
||||
album_owned = EXCLUDED.album_owned,
|
||||
album_want = EXCLUDED.album_want,
|
||||
is_vinyl = EXCLUDED.is_vinyl,
|
||||
is_cd = EXCLUDED.is_cd
|
||||
`
|
||||
|
||||
type UpdateUserAlbumStatusParams 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"`
|
||||
}
|
||||
|
||||
// user_albums.sql
|
||||
func (q *Queries) UpdateUserAlbumStatus(ctx context.Context, arg UpdateUserAlbumStatusParams) error {
|
||||
_, err := q.db.Exec(ctx, updateUserAlbumStatus,
|
||||
arg.UserID,
|
||||
arg.AlbumID,
|
||||
arg.AlbumOwned,
|
||||
arg.AlbumWant,
|
||||
arg.IsVinyl,
|
||||
arg.IsCd,
|
||||
)
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: users.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const checkUserExistsByEmail = `-- name: CheckUserExistsByEmail :one
|
||||
SELECT id FROM users WHERE user_mail = $1
|
||||
`
|
||||
|
||||
func (q *Queries) CheckUserExistsByEmail(ctx context.Context, userMail string) (pgtype.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, checkUserExistsByEmail, userMail)
|
||||
var id pgtype.UUID
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const createUser = `-- name: CreateUser :one
|
||||
INSERT INTO users (id, user_name, user_mail, password) VALUES ($1, $2, $3, $4) RETURNING id
|
||||
`
|
||||
|
||||
type CreateUserParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserName string `json:"user_name"`
|
||||
UserMail string `json:"user_mail"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (pgtype.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, createUser,
|
||||
arg.ID,
|
||||
arg.UserName,
|
||||
arg.UserMail,
|
||||
arg.Password,
|
||||
)
|
||||
var id pgtype.UUID
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const getUsernameByID = `-- name: GetUsernameByID :one
|
||||
SELECT user_name FROM users WHERE id = $1
|
||||
`
|
||||
|
||||
// users.sql
|
||||
func (q *Queries) GetUsernameByID(ctx context.Context, id pgtype.UUID) (string, error) {
|
||||
row := q.db.QueryRow(ctx, getUsernameByID, id)
|
||||
var user_name string
|
||||
err := row.Scan(&user_name)
|
||||
return user_name, err
|
||||
}
|
||||
Reference in New Issue
Block a user