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,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
}