add sqlc, fix background img fetching

This commit is contained in:
2025-07-15 01:16:07 +02:00
parent cb8a52693a
commit a3440326e8
15 changed files with 869 additions and 91 deletions

View File

@@ -0,0 +1,276 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.29.0
// source: beatmap.sql
package db
import (
"context"
"database/sql"
)
const getArtists = `-- name: GetArtists :many
SELECT Artist, COUNT(Artist) AS count
FROM Beatmap
WHERE Artist LIKE ? OR Title LIKE ?
GROUP BY Artist
LIMIT ? OFFSET ?
`
type GetArtistsParams struct {
Artist sql.NullString `json:"artist"`
Title sql.NullString `json:"title"`
Limit int64 `json:"limit"`
Offset int64 `json:"offset"`
}
type GetArtistsRow struct {
Artist sql.NullString `json:"artist"`
Count int64 `json:"count"`
}
func (q *Queries) GetArtists(ctx context.Context, arg GetArtistsParams) ([]GetArtistsRow, error) {
rows, err := q.db.QueryContext(ctx, getArtists,
arg.Artist,
arg.Title,
arg.Limit,
arg.Offset,
)
if err != nil {
return nil, err
}
defer rows.Close()
items := []GetArtistsRow{}
for rows.Next() {
var i GetArtistsRow
if err := rows.Scan(&i.Artist, &i.Count); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getBeatmapByHash = `-- name: GetBeatmapByHash :one
SELECT beatmapid, artist, artistunicode, title, titleunicode, creator, difficulty, audio, md5hash, file, rankedstatus, lastmodifiedtime, totaltime, audiopreviewtime, beatmapsetid, source, tags, lastplayed, folder FROM Beatmap WHERE MD5Hash = ?
`
func (q *Queries) GetBeatmapByHash(ctx context.Context, md5hash sql.NullString) (Beatmap, error) {
row := q.db.QueryRowContext(ctx, getBeatmapByHash, md5hash)
var i Beatmap
err := row.Scan(
&i.Beatmapid,
&i.Artist,
&i.Artistunicode,
&i.Title,
&i.Titleunicode,
&i.Creator,
&i.Difficulty,
&i.Audio,
&i.Md5hash,
&i.File,
&i.Rankedstatus,
&i.Lastmodifiedtime,
&i.Totaltime,
&i.Audiopreviewtime,
&i.Beatmapsetid,
&i.Source,
&i.Tags,
&i.Lastplayed,
&i.Folder,
)
return i, err
}
const getBeatmapCount = `-- name: GetBeatmapCount :one
SELECT COUNT(*) FROM Beatmap
`
func (q *Queries) GetBeatmapCount(ctx context.Context) (int64, error) {
row := q.db.QueryRowContext(ctx, getBeatmapCount)
var count int64
err := row.Scan(&count)
return count, err
}
const getRecentBeatmaps = `-- name: GetRecentBeatmaps :many
SELECT BeatmapId, MD5Hash, Title, Artist, Creator, Folder, File, Audio, TotalTime
FROM Beatmap GROUP BY Folder ORDER BY LastModifiedTime DESC LIMIT ? OFFSET ?
`
type GetRecentBeatmapsParams struct {
Limit int64 `json:"limit"`
Offset int64 `json:"offset"`
}
type GetRecentBeatmapsRow struct {
Beatmapid sql.NullInt64 `json:"beatmapid"`
Md5hash sql.NullString `json:"md5hash"`
Title sql.NullString `json:"title"`
Artist sql.NullString `json:"artist"`
Creator sql.NullString `json:"creator"`
Folder sql.NullString `json:"folder"`
File sql.NullString `json:"file"`
Audio sql.NullString `json:"audio"`
Totaltime sql.NullInt64 `json:"totaltime"`
}
func (q *Queries) GetRecentBeatmaps(ctx context.Context, arg GetRecentBeatmapsParams) ([]GetRecentBeatmapsRow, error) {
rows, err := q.db.QueryContext(ctx, getRecentBeatmaps, arg.Limit, arg.Offset)
if err != nil {
return nil, err
}
defer rows.Close()
items := []GetRecentBeatmapsRow{}
for rows.Next() {
var i GetRecentBeatmapsRow
if err := rows.Scan(
&i.Beatmapid,
&i.Md5hash,
&i.Title,
&i.Artist,
&i.Creator,
&i.Folder,
&i.File,
&i.Audio,
&i.Totaltime,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const insertBeatmap = `-- name: InsertBeatmap :exec
INSERT INTO Beatmap (
BeatmapId, Artist, ArtistUnicode, Title, TitleUnicode, Creator,
Difficulty, Audio, MD5Hash, File, RankedStatus,
LastModifiedTime, TotalTime, AudioPreviewTime, BeatmapSetId,
Source, Tags, LastPlayed, Folder
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`
type InsertBeatmapParams struct {
Beatmapid sql.NullInt64 `json:"beatmapid"`
Artist sql.NullString `json:"artist"`
Artistunicode sql.NullString `json:"artistunicode"`
Title sql.NullString `json:"title"`
Titleunicode sql.NullString `json:"titleunicode"`
Creator sql.NullString `json:"creator"`
Difficulty sql.NullString `json:"difficulty"`
Audio sql.NullString `json:"audio"`
Md5hash sql.NullString `json:"md5hash"`
File sql.NullString `json:"file"`
Rankedstatus sql.NullString `json:"rankedstatus"`
Lastmodifiedtime sql.NullTime `json:"lastmodifiedtime"`
Totaltime sql.NullInt64 `json:"totaltime"`
Audiopreviewtime sql.NullInt64 `json:"audiopreviewtime"`
Beatmapsetid sql.NullInt64 `json:"beatmapsetid"`
Source sql.NullString `json:"source"`
Tags sql.NullString `json:"tags"`
Lastplayed sql.NullTime `json:"lastplayed"`
Folder sql.NullString `json:"folder"`
}
func (q *Queries) InsertBeatmap(ctx context.Context, arg InsertBeatmapParams) error {
_, err := q.db.ExecContext(ctx, insertBeatmap,
arg.Beatmapid,
arg.Artist,
arg.Artistunicode,
arg.Title,
arg.Titleunicode,
arg.Creator,
arg.Difficulty,
arg.Audio,
arg.Md5hash,
arg.File,
arg.Rankedstatus,
arg.Lastmodifiedtime,
arg.Totaltime,
arg.Audiopreviewtime,
arg.Beatmapsetid,
arg.Source,
arg.Tags,
arg.Lastplayed,
arg.Folder,
)
return err
}
const searchBeatmaps = `-- name: SearchBeatmaps :many
SELECT BeatmapId, MD5Hash, Title, Artist, Creator, Folder, File, Audio, TotalTime
FROM Beatmap
WHERE Title LIKE ? OR Artist LIKE ?
LIMIT ? OFFSET ?
`
type SearchBeatmapsParams struct {
Title sql.NullString `json:"title"`
Artist sql.NullString `json:"artist"`
Limit int64 `json:"limit"`
Offset int64 `json:"offset"`
}
type SearchBeatmapsRow struct {
Beatmapid sql.NullInt64 `json:"beatmapid"`
Md5hash sql.NullString `json:"md5hash"`
Title sql.NullString `json:"title"`
Artist sql.NullString `json:"artist"`
Creator sql.NullString `json:"creator"`
Folder sql.NullString `json:"folder"`
File sql.NullString `json:"file"`
Audio sql.NullString `json:"audio"`
Totaltime sql.NullInt64 `json:"totaltime"`
}
func (q *Queries) SearchBeatmaps(ctx context.Context, arg SearchBeatmapsParams) ([]SearchBeatmapsRow, error) {
rows, err := q.db.QueryContext(ctx, searchBeatmaps,
arg.Title,
arg.Artist,
arg.Limit,
arg.Offset,
)
if err != nil {
return nil, err
}
defer rows.Close()
items := []SearchBeatmapsRow{}
for rows.Next() {
var i SearchBeatmapsRow
if err := rows.Scan(
&i.Beatmapid,
&i.Md5hash,
&i.Title,
&i.Artist,
&i.Creator,
&i.Folder,
&i.File,
&i.Audio,
&i.Totaltime,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}

View File

@@ -0,0 +1,223 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.29.0
// source: collection.sql
package db
import (
"context"
"database/sql"
)
const getCollection = `-- name: GetCollection :many
SELECT
c.Name,
b.BeatmapId,
b.MD5Hash,
b.Title,
b.Artist,
b.Creator,
b.Folder,
b.File,
b.Audio,
b.TotalTime
FROM Collection c
JOIN Beatmap b ON c.MD5Hash = b.MD5Hash
JOIN (
SELECT DISTINCT Name
FROM Collection
ORDER BY Name
LIMIT 1 OFFSET ?
) selected_name ON c.Name = selected_name.Name
LIMIT ? OFFSET ?
`
type GetCollectionParams struct {
Offset int64 `json:"offset"`
Limit int64 `json:"limit"`
Offset_2 int64 `json:"offset_2"`
}
type GetCollectionRow struct {
Name sql.NullString `json:"name"`
Beatmapid sql.NullInt64 `json:"beatmapid"`
Md5hash sql.NullString `json:"md5hash"`
Title sql.NullString `json:"title"`
Artist sql.NullString `json:"artist"`
Creator sql.NullString `json:"creator"`
Folder sql.NullString `json:"folder"`
File sql.NullString `json:"file"`
Audio sql.NullString `json:"audio"`
Totaltime sql.NullInt64 `json:"totaltime"`
}
func (q *Queries) GetCollection(ctx context.Context, arg GetCollectionParams) ([]GetCollectionRow, error) {
rows, err := q.db.QueryContext(ctx, getCollection, arg.Offset, arg.Limit, arg.Offset_2)
if err != nil {
return nil, err
}
defer rows.Close()
items := []GetCollectionRow{}
for rows.Next() {
var i GetCollectionRow
if err := rows.Scan(
&i.Name,
&i.Beatmapid,
&i.Md5hash,
&i.Title,
&i.Artist,
&i.Creator,
&i.Folder,
&i.File,
&i.Audio,
&i.Totaltime,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getCollectionByName = `-- name: GetCollectionByName :many
SELECT c.Name, b.BeatmapId, b.MD5Hash, b.Title, b.Artist, b.Creator, b.Folder, b.File, b.Audio, b.TotalTime
FROM Collection c
JOIN Beatmap b ON c.MD5Hash = b.MD5Hash
WHERE c.Name = ?
LIMIT ? OFFSET ?
`
type GetCollectionByNameParams struct {
Name sql.NullString `json:"name"`
Limit int64 `json:"limit"`
Offset int64 `json:"offset"`
}
type GetCollectionByNameRow struct {
Name sql.NullString `json:"name"`
Beatmapid sql.NullInt64 `json:"beatmapid"`
Md5hash sql.NullString `json:"md5hash"`
Title sql.NullString `json:"title"`
Artist sql.NullString `json:"artist"`
Creator sql.NullString `json:"creator"`
Folder sql.NullString `json:"folder"`
File sql.NullString `json:"file"`
Audio sql.NullString `json:"audio"`
Totaltime sql.NullInt64 `json:"totaltime"`
}
func (q *Queries) GetCollectionByName(ctx context.Context, arg GetCollectionByNameParams) ([]GetCollectionByNameRow, error) {
rows, err := q.db.QueryContext(ctx, getCollectionByName, arg.Name, arg.Limit, arg.Offset)
if err != nil {
return nil, err
}
defer rows.Close()
items := []GetCollectionByNameRow{}
for rows.Next() {
var i GetCollectionByNameRow
if err := rows.Scan(
&i.Name,
&i.Beatmapid,
&i.Md5hash,
&i.Title,
&i.Artist,
&i.Creator,
&i.Folder,
&i.File,
&i.Audio,
&i.Totaltime,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getCollectionCountByName = `-- name: GetCollectionCountByName :one
SELECT COUNT(*) FROM Collection WHERE Name = ?
`
func (q *Queries) GetCollectionCountByName(ctx context.Context, name sql.NullString) (int64, error) {
row := q.db.QueryRowContext(ctx, getCollectionCountByName, name)
var count int64
err := row.Scan(&count)
return count, err
}
const getCollections = `-- name: GetCollections :many
SELECT c.Name, COUNT(b.MD5Hash) AS Count, MIN(b.Folder) AS Folder, MIN(b.File) AS File
FROM Collection c
JOIN Beatmap b ON c.MD5Hash = b.MD5Hash
WHERE c.Name LIKE ?
GROUP BY c.Name
LIMIT ? OFFSET ?
`
type GetCollectionsParams struct {
Name sql.NullString `json:"name"`
Limit int64 `json:"limit"`
Offset int64 `json:"offset"`
}
type GetCollectionsRow struct {
Name sql.NullString `json:"name"`
Count int64 `json:"count"`
Folder interface{} `json:"folder"`
File interface{} `json:"file"`
}
func (q *Queries) GetCollections(ctx context.Context, arg GetCollectionsParams) ([]GetCollectionsRow, error) {
rows, err := q.db.QueryContext(ctx, getCollections, arg.Name, arg.Limit, arg.Offset)
if err != nil {
return nil, err
}
defer rows.Close()
items := []GetCollectionsRow{}
for rows.Next() {
var i GetCollectionsRow
if err := rows.Scan(
&i.Name,
&i.Count,
&i.Folder,
&i.File,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const insertCollection = `-- name: InsertCollection :exec
INSERT INTO Collection (Name, MD5Hash) VALUES (?, ?)
`
type InsertCollectionParams struct {
Name sql.NullString `json:"name"`
Md5hash sql.NullString `json:"md5hash"`
}
func (q *Queries) InsertCollection(ctx context.Context, arg InsertCollectionParams) error {
_, err := q.db.ExecContext(ctx, insertCollection, arg.Name, arg.Md5hash)
return err
}

View File

@@ -0,0 +1,31 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.29.0
package db
import (
"context"
"database/sql"
)
type DBTX interface {
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
PrepareContext(context.Context, string) (*sql.Stmt, error)
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
}
func New(db DBTX) *Queries {
return &Queries{db: db}
}
type Queries struct {
db DBTX
}
func (q *Queries) WithTx(tx *sql.Tx) *Queries {
return &Queries{
db: tx,
}
}

View File

@@ -0,0 +1,36 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.29.0
package db
import (
"database/sql"
)
type Beatmap struct {
Beatmapid sql.NullInt64 `json:"beatmapid"`
Artist sql.NullString `json:"artist"`
Artistunicode sql.NullString `json:"artistunicode"`
Title sql.NullString `json:"title"`
Titleunicode sql.NullString `json:"titleunicode"`
Creator sql.NullString `json:"creator"`
Difficulty sql.NullString `json:"difficulty"`
Audio sql.NullString `json:"audio"`
Md5hash sql.NullString `json:"md5hash"`
File sql.NullString `json:"file"`
Rankedstatus sql.NullString `json:"rankedstatus"`
Lastmodifiedtime sql.NullTime `json:"lastmodifiedtime"`
Totaltime sql.NullInt64 `json:"totaltime"`
Audiopreviewtime sql.NullInt64 `json:"audiopreviewtime"`
Beatmapsetid sql.NullInt64 `json:"beatmapsetid"`
Source sql.NullString `json:"source"`
Tags sql.NullString `json:"tags"`
Lastplayed sql.NullTime `json:"lastplayed"`
Folder sql.NullString `json:"folder"`
}
type Collection struct {
Name sql.NullString `json:"name"`
Md5hash sql.NullString `json:"md5hash"`
}

View File

@@ -0,0 +1,26 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.29.0
package db
import (
"context"
"database/sql"
)
type Querier interface {
GetArtists(ctx context.Context, arg GetArtistsParams) ([]GetArtistsRow, error)
GetBeatmapByHash(ctx context.Context, md5hash sql.NullString) (Beatmap, error)
GetBeatmapCount(ctx context.Context) (int64, error)
GetCollection(ctx context.Context, arg GetCollectionParams) ([]GetCollectionRow, error)
GetCollectionByName(ctx context.Context, arg GetCollectionByNameParams) ([]GetCollectionByNameRow, error)
GetCollectionCountByName(ctx context.Context, name sql.NullString) (int64, error)
GetCollections(ctx context.Context, arg GetCollectionsParams) ([]GetCollectionsRow, error)
GetRecentBeatmaps(ctx context.Context, arg GetRecentBeatmapsParams) ([]GetRecentBeatmapsRow, error)
InsertBeatmap(ctx context.Context, arg InsertBeatmapParams) error
InsertCollection(ctx context.Context, arg InsertCollectionParams) error
SearchBeatmaps(ctx context.Context, arg SearchBeatmapsParams) ([]SearchBeatmapsRow, error)
}
var _ Querier = (*Queries)(nil)