139 lines
2.6 KiB
Go
139 lines
2.6 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.26.0
|
|
// source: track.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
const addTrack = `-- name: AddTrack :one
|
|
INSERT INTO track (path, album_artist, title, album, disc, year, artist, genre, lyrics, composer)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
|
ON CONFLICT DO NOTHING
|
|
RETURNING id, path, album_artist, title, album, disc, year, artist, genre, lyrics, composer
|
|
`
|
|
|
|
type AddTrackParams struct {
|
|
Path string
|
|
AlbumArtist string
|
|
Title string
|
|
Album string
|
|
Disc [][]int32
|
|
Year int32
|
|
Artist string
|
|
Genre string
|
|
Lyrics string
|
|
Composer string
|
|
}
|
|
|
|
func (q *Queries) AddTrack(ctx context.Context, arg AddTrackParams) (Track, error) {
|
|
row := q.db.QueryRow(ctx, addTrack,
|
|
arg.Path,
|
|
arg.AlbumArtist,
|
|
arg.Title,
|
|
arg.Album,
|
|
arg.Disc,
|
|
arg.Year,
|
|
arg.Artist,
|
|
arg.Genre,
|
|
arg.Lyrics,
|
|
arg.Composer,
|
|
)
|
|
var i Track
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Path,
|
|
&i.AlbumArtist,
|
|
&i.Title,
|
|
&i.Album,
|
|
&i.Disc,
|
|
&i.Year,
|
|
&i.Artist,
|
|
&i.Genre,
|
|
&i.Lyrics,
|
|
&i.Composer,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const exists = `-- name: Exists :one
|
|
SELECT EXISTS (SELECT 1
|
|
FROM track
|
|
WHERE path = $1) as exists
|
|
`
|
|
|
|
func (q *Queries) Exists(ctx context.Context, path string) (bool, error) {
|
|
row := q.db.QueryRow(ctx, exists, path)
|
|
var exists bool
|
|
err := row.Scan(&exists)
|
|
return exists, err
|
|
}
|
|
|
|
const getAlbumTracks = `-- name: GetAlbumTracks :many
|
|
SELECT id, path, album_artist, title, album, disc, year, artist, genre, lyrics, composer
|
|
FROM track
|
|
WHERE album = $1
|
|
ORDER BY track.title
|
|
`
|
|
|
|
func (q *Queries) GetAlbumTracks(ctx context.Context, album string) ([]Track, error) {
|
|
rows, err := q.db.Query(ctx, getAlbumTracks, album)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Track
|
|
for rows.Next() {
|
|
var i Track
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Path,
|
|
&i.AlbumArtist,
|
|
&i.Title,
|
|
&i.Album,
|
|
&i.Disc,
|
|
&i.Year,
|
|
&i.Artist,
|
|
&i.Genre,
|
|
&i.Lyrics,
|
|
&i.Composer,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getTrackByID = `-- name: GetTrackByID :one
|
|
SELECT id, path, album_artist, title, album, disc, year, artist, genre, lyrics, composer
|
|
FROM track
|
|
WHERE id = $1
|
|
LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetTrackByID(ctx context.Context, id int64) (Track, error) {
|
|
row := q.db.QueryRow(ctx, getTrackByID, id)
|
|
var i Track
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Path,
|
|
&i.AlbumArtist,
|
|
&i.Title,
|
|
&i.Album,
|
|
&i.Disc,
|
|
&i.Year,
|
|
&i.Artist,
|
|
&i.Genre,
|
|
&i.Lyrics,
|
|
&i.Composer,
|
|
)
|
|
return i, err
|
|
}
|