95cab106d8
- PostgreSQL schema: sources, manga, chapters, pages, source_meta with indexes - golang-migrate runner with embedded SQL via go:embed (pgx5:// scheme) - sqlc-generated type-safe queries for all tables (pgx/v5 native) - Config package with all env vars including TTL durations - Wire DB init and config into cmd/server/main.go
256 lines
7.0 KiB
Go
256 lines
7.0 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: manga.sql
|
|
|
|
package queries
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
const getMangaByID = `-- name: GetMangaByID :one
|
|
SELECT id, source_id, url, title, initialized, artist, author, description, genre, status, thumbnail_url, thumbnail_last_fetched, in_library, in_library_at, real_url, last_fetched_at, chapters_last_fetched_at, update_strategy FROM manga WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetMangaByID(ctx context.Context, id int32) (Manga, error) {
|
|
row := q.db.QueryRow(ctx, getMangaByID, id)
|
|
var i Manga
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.SourceID,
|
|
&i.Url,
|
|
&i.Title,
|
|
&i.Initialized,
|
|
&i.Artist,
|
|
&i.Author,
|
|
&i.Description,
|
|
&i.Genre,
|
|
&i.Status,
|
|
&i.ThumbnailUrl,
|
|
&i.ThumbnailLastFetched,
|
|
&i.InLibrary,
|
|
&i.InLibraryAt,
|
|
&i.RealUrl,
|
|
&i.LastFetchedAt,
|
|
&i.ChaptersLastFetchedAt,
|
|
&i.UpdateStrategy,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getMangaBySourceURL = `-- name: GetMangaBySourceURL :one
|
|
SELECT id, source_id, url, title, initialized, artist, author, description, genre, status, thumbnail_url, thumbnail_last_fetched, in_library, in_library_at, real_url, last_fetched_at, chapters_last_fetched_at, update_strategy FROM manga WHERE source_id = $1 AND url = $2
|
|
`
|
|
|
|
type GetMangaBySourceURLParams struct {
|
|
SourceID int64 `db:"source_id" json:"source_id"`
|
|
Url string `db:"url" json:"url"`
|
|
}
|
|
|
|
func (q *Queries) GetMangaBySourceURL(ctx context.Context, arg GetMangaBySourceURLParams) (Manga, error) {
|
|
row := q.db.QueryRow(ctx, getMangaBySourceURL, arg.SourceID, arg.Url)
|
|
var i Manga
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.SourceID,
|
|
&i.Url,
|
|
&i.Title,
|
|
&i.Initialized,
|
|
&i.Artist,
|
|
&i.Author,
|
|
&i.Description,
|
|
&i.Genre,
|
|
&i.Status,
|
|
&i.ThumbnailUrl,
|
|
&i.ThumbnailLastFetched,
|
|
&i.InLibrary,
|
|
&i.InLibraryAt,
|
|
&i.RealUrl,
|
|
&i.LastFetchedAt,
|
|
&i.ChaptersLastFetchedAt,
|
|
&i.UpdateStrategy,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listMangaBySource = `-- name: ListMangaBySource :many
|
|
SELECT id, source_id, url, title, initialized, artist, author, description, genre, status, thumbnail_url, thumbnail_last_fetched, in_library, in_library_at, real_url, last_fetched_at, chapters_last_fetched_at, update_strategy FROM manga
|
|
WHERE source_id = $1
|
|
ORDER BY last_fetched_at DESC
|
|
`
|
|
|
|
func (q *Queries) ListMangaBySource(ctx context.Context, sourceID int64) ([]Manga, error) {
|
|
rows, err := q.db.Query(ctx, listMangaBySource, sourceID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Manga
|
|
for rows.Next() {
|
|
var i Manga
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.SourceID,
|
|
&i.Url,
|
|
&i.Title,
|
|
&i.Initialized,
|
|
&i.Artist,
|
|
&i.Author,
|
|
&i.Description,
|
|
&i.Genre,
|
|
&i.Status,
|
|
&i.ThumbnailUrl,
|
|
&i.ThumbnailLastFetched,
|
|
&i.InLibrary,
|
|
&i.InLibraryAt,
|
|
&i.RealUrl,
|
|
&i.LastFetchedAt,
|
|
&i.ChaptersLastFetchedAt,
|
|
&i.UpdateStrategy,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const updateChaptersFetchedAt = `-- name: UpdateChaptersFetchedAt :exec
|
|
UPDATE manga SET chapters_last_fetched_at = $2 WHERE id = $1
|
|
`
|
|
|
|
type UpdateChaptersFetchedAtParams struct {
|
|
ID int32 `db:"id" json:"id"`
|
|
ChaptersLastFetchedAt int64 `db:"chapters_last_fetched_at" json:"chapters_last_fetched_at"`
|
|
}
|
|
|
|
func (q *Queries) UpdateChaptersFetchedAt(ctx context.Context, arg UpdateChaptersFetchedAtParams) error {
|
|
_, err := q.db.Exec(ctx, updateChaptersFetchedAt, arg.ID, arg.ChaptersLastFetchedAt)
|
|
return err
|
|
}
|
|
|
|
const updateMangaDetails = `-- name: UpdateMangaDetails :exec
|
|
UPDATE manga
|
|
SET artist = $2,
|
|
author = $3,
|
|
description = $4,
|
|
genre = $5,
|
|
status = $6,
|
|
thumbnail_url = $7,
|
|
initialized = TRUE
|
|
WHERE id = $1
|
|
`
|
|
|
|
type UpdateMangaDetailsParams struct {
|
|
ID int32 `db:"id" json:"id"`
|
|
Artist *string `db:"artist" json:"artist"`
|
|
Author *string `db:"author" json:"author"`
|
|
Description *string `db:"description" json:"description"`
|
|
Genre *string `db:"genre" json:"genre"`
|
|
Status int32 `db:"status" json:"status"`
|
|
ThumbnailUrl *string `db:"thumbnail_url" json:"thumbnail_url"`
|
|
}
|
|
|
|
func (q *Queries) UpdateMangaDetails(ctx context.Context, arg UpdateMangaDetailsParams) error {
|
|
_, err := q.db.Exec(ctx, updateMangaDetails,
|
|
arg.ID,
|
|
arg.Artist,
|
|
arg.Author,
|
|
arg.Description,
|
|
arg.Genre,
|
|
arg.Status,
|
|
arg.ThumbnailUrl,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const updateMangaFetchedAt = `-- name: UpdateMangaFetchedAt :exec
|
|
UPDATE manga SET last_fetched_at = $2 WHERE id = $1
|
|
`
|
|
|
|
type UpdateMangaFetchedAtParams struct {
|
|
ID int32 `db:"id" json:"id"`
|
|
LastFetchedAt int64 `db:"last_fetched_at" json:"last_fetched_at"`
|
|
}
|
|
|
|
func (q *Queries) UpdateMangaFetchedAt(ctx context.Context, arg UpdateMangaFetchedAtParams) error {
|
|
_, err := q.db.Exec(ctx, updateMangaFetchedAt, arg.ID, arg.LastFetchedAt)
|
|
return err
|
|
}
|
|
|
|
const upsertManga = `-- name: UpsertManga :one
|
|
INSERT INTO manga (
|
|
source_id, url, title, artist, author, description, genre,
|
|
status, thumbnail_url, initialized, last_fetched_at
|
|
) VALUES (
|
|
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11
|
|
)
|
|
ON CONFLICT (source_id, url) DO UPDATE
|
|
SET title = EXCLUDED.title,
|
|
artist = EXCLUDED.artist,
|
|
author = EXCLUDED.author,
|
|
description = EXCLUDED.description,
|
|
genre = EXCLUDED.genre,
|
|
status = EXCLUDED.status,
|
|
thumbnail_url = EXCLUDED.thumbnail_url,
|
|
initialized = EXCLUDED.initialized,
|
|
last_fetched_at = EXCLUDED.last_fetched_at
|
|
RETURNING id, source_id, url, title, initialized, artist, author, description, genre, status, thumbnail_url, thumbnail_last_fetched, in_library, in_library_at, real_url, last_fetched_at, chapters_last_fetched_at, update_strategy
|
|
`
|
|
|
|
type UpsertMangaParams struct {
|
|
SourceID int64 `db:"source_id" json:"source_id"`
|
|
Url string `db:"url" json:"url"`
|
|
Title string `db:"title" json:"title"`
|
|
Artist *string `db:"artist" json:"artist"`
|
|
Author *string `db:"author" json:"author"`
|
|
Description *string `db:"description" json:"description"`
|
|
Genre *string `db:"genre" json:"genre"`
|
|
Status int32 `db:"status" json:"status"`
|
|
ThumbnailUrl *string `db:"thumbnail_url" json:"thumbnail_url"`
|
|
Initialized bool `db:"initialized" json:"initialized"`
|
|
LastFetchedAt int64 `db:"last_fetched_at" json:"last_fetched_at"`
|
|
}
|
|
|
|
func (q *Queries) UpsertManga(ctx context.Context, arg UpsertMangaParams) (Manga, error) {
|
|
row := q.db.QueryRow(ctx, upsertManga,
|
|
arg.SourceID,
|
|
arg.Url,
|
|
arg.Title,
|
|
arg.Artist,
|
|
arg.Author,
|
|
arg.Description,
|
|
arg.Genre,
|
|
arg.Status,
|
|
arg.ThumbnailUrl,
|
|
arg.Initialized,
|
|
arg.LastFetchedAt,
|
|
)
|
|
var i Manga
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.SourceID,
|
|
&i.Url,
|
|
&i.Title,
|
|
&i.Initialized,
|
|
&i.Artist,
|
|
&i.Author,
|
|
&i.Description,
|
|
&i.Genre,
|
|
&i.Status,
|
|
&i.ThumbnailUrl,
|
|
&i.ThumbnailLastFetched,
|
|
&i.InLibrary,
|
|
&i.InLibraryAt,
|
|
&i.RealUrl,
|
|
&i.LastFetchedAt,
|
|
&i.ChaptersLastFetchedAt,
|
|
&i.UpdateStrategy,
|
|
)
|
|
return i, err
|
|
}
|