Add initial database setup and user/artist management functionality
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user