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
125 lines
2.7 KiB
Go
125 lines
2.7 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: source.sql
|
|
|
|
package queries
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
const getSourceByID = `-- name: GetSourceByID :one
|
|
SELECT id, name, lang, is_nsfw FROM sources WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetSourceByID(ctx context.Context, id int64) (Source, error) {
|
|
row := q.db.QueryRow(ctx, getSourceByID, id)
|
|
var i Source
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Lang,
|
|
&i.IsNsfw,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getSourceMeta = `-- name: GetSourceMeta :one
|
|
SELECT value FROM source_meta
|
|
WHERE source_id = $1 AND key = $2
|
|
`
|
|
|
|
type GetSourceMetaParams struct {
|
|
SourceID int64 `db:"source_id" json:"source_id"`
|
|
Key string `db:"key" json:"key"`
|
|
}
|
|
|
|
func (q *Queries) GetSourceMeta(ctx context.Context, arg GetSourceMetaParams) (string, error) {
|
|
row := q.db.QueryRow(ctx, getSourceMeta, arg.SourceID, arg.Key)
|
|
var value string
|
|
err := row.Scan(&value)
|
|
return value, err
|
|
}
|
|
|
|
const listSources = `-- name: ListSources :many
|
|
SELECT id, name, lang, is_nsfw FROM sources ORDER BY id
|
|
`
|
|
|
|
func (q *Queries) ListSources(ctx context.Context) ([]Source, error) {
|
|
rows, err := q.db.Query(ctx, listSources)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Source
|
|
for rows.Next() {
|
|
var i Source
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Lang,
|
|
&i.IsNsfw,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const setSourceMeta = `-- name: SetSourceMeta :exec
|
|
INSERT INTO source_meta (source_id, key, value)
|
|
VALUES ($1, $2, $3)
|
|
ON CONFLICT (source_id, key) DO UPDATE
|
|
SET value = EXCLUDED.value
|
|
`
|
|
|
|
type SetSourceMetaParams struct {
|
|
SourceID int64 `db:"source_id" json:"source_id"`
|
|
Key string `db:"key" json:"key"`
|
|
Value string `db:"value" json:"value"`
|
|
}
|
|
|
|
func (q *Queries) SetSourceMeta(ctx context.Context, arg SetSourceMetaParams) error {
|
|
_, err := q.db.Exec(ctx, setSourceMeta, arg.SourceID, arg.Key, arg.Value)
|
|
return err
|
|
}
|
|
|
|
const upsertSource = `-- name: UpsertSource :one
|
|
INSERT INTO sources (id, name, lang, is_nsfw)
|
|
VALUES ($1, $2, $3, $4)
|
|
ON CONFLICT (id) DO UPDATE
|
|
SET name = EXCLUDED.name,
|
|
lang = EXCLUDED.lang,
|
|
is_nsfw = EXCLUDED.is_nsfw
|
|
RETURNING id, name, lang, is_nsfw
|
|
`
|
|
|
|
type UpsertSourceParams struct {
|
|
ID int64 `db:"id" json:"id"`
|
|
Name string `db:"name" json:"name"`
|
|
Lang string `db:"lang" json:"lang"`
|
|
IsNsfw bool `db:"is_nsfw" json:"is_nsfw"`
|
|
}
|
|
|
|
func (q *Queries) UpsertSource(ctx context.Context, arg UpsertSourceParams) (Source, error) {
|
|
row := q.db.QueryRow(ctx, upsertSource,
|
|
arg.ID,
|
|
arg.Name,
|
|
arg.Lang,
|
|
arg.IsNsfw,
|
|
)
|
|
var i Source
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Lang,
|
|
&i.IsNsfw,
|
|
)
|
|
return i, err
|
|
}
|