mirror of
https://github.com/Dvorinka/SpotifyRecAlg.git
synced 2026-06-04 04:23:02 +00:00
217 lines
6.6 KiB
Go
217 lines
6.6 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: provider.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const createImportJob = `-- name: CreateImportJob :exec
|
|
insert into import_jobs (id, provider, source_type, source_value, market, status, imported_tracks, updated_tracks, skipped, warnings, started_at)
|
|
values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10::jsonb, $11)
|
|
`
|
|
|
|
type CreateImportJobParams struct {
|
|
ID string `json:"id"`
|
|
Provider string `json:"provider"`
|
|
SourceType string `json:"source_type"`
|
|
SourceValue string `json:"source_value"`
|
|
Market string `json:"market"`
|
|
Status string `json:"status"`
|
|
ImportedTracks int32 `json:"imported_tracks"`
|
|
UpdatedTracks int32 `json:"updated_tracks"`
|
|
Skipped int32 `json:"skipped"`
|
|
Column10 []byte `json:"column_10"`
|
|
StartedAt pgtype.Timestamptz `json:"started_at"`
|
|
}
|
|
|
|
func (q *Queries) CreateImportJob(ctx context.Context, arg CreateImportJobParams) error {
|
|
_, err := q.db.Exec(ctx, createImportJob,
|
|
arg.ID,
|
|
arg.Provider,
|
|
arg.SourceType,
|
|
arg.SourceValue,
|
|
arg.Market,
|
|
arg.Status,
|
|
arg.ImportedTracks,
|
|
arg.UpdatedTracks,
|
|
arg.Skipped,
|
|
arg.Column10,
|
|
arg.StartedAt,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const finishImportJob = `-- name: FinishImportJob :exec
|
|
update import_jobs
|
|
set status = $2,
|
|
imported_tracks = $3,
|
|
updated_tracks = $4,
|
|
skipped = $5,
|
|
warnings = $6::jsonb,
|
|
finished_at = $7
|
|
where id = $1
|
|
`
|
|
|
|
type FinishImportJobParams struct {
|
|
ID string `json:"id"`
|
|
Status string `json:"status"`
|
|
ImportedTracks int32 `json:"imported_tracks"`
|
|
UpdatedTracks int32 `json:"updated_tracks"`
|
|
Skipped int32 `json:"skipped"`
|
|
Column6 []byte `json:"column_6"`
|
|
FinishedAt pgtype.Timestamptz `json:"finished_at"`
|
|
}
|
|
|
|
func (q *Queries) FinishImportJob(ctx context.Context, arg FinishImportJobParams) error {
|
|
_, err := q.db.Exec(ctx, finishImportJob,
|
|
arg.ID,
|
|
arg.Status,
|
|
arg.ImportedTracks,
|
|
arg.UpdatedTracks,
|
|
arg.Skipped,
|
|
arg.Column6,
|
|
arg.FinishedAt,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const getProviderCache = `-- name: GetProviderCache :one
|
|
select provider, item_type, item_id, market, payload, fetched_at, expires_at, coalesce(last_error, '') as last_error
|
|
from provider_cache
|
|
where provider = $1 and item_type = $2 and item_id = $3 and market = $4
|
|
`
|
|
|
|
type GetProviderCacheParams struct {
|
|
Provider string `json:"provider"`
|
|
ItemType string `json:"item_type"`
|
|
ItemID string `json:"item_id"`
|
|
Market string `json:"market"`
|
|
}
|
|
|
|
type GetProviderCacheRow struct {
|
|
Provider string `json:"provider"`
|
|
ItemType string `json:"item_type"`
|
|
ItemID string `json:"item_id"`
|
|
Market string `json:"market"`
|
|
Payload []byte `json:"payload"`
|
|
FetchedAt pgtype.Timestamptz `json:"fetched_at"`
|
|
ExpiresAt pgtype.Timestamptz `json:"expires_at"`
|
|
LastError string `json:"last_error"`
|
|
}
|
|
|
|
func (q *Queries) GetProviderCache(ctx context.Context, arg GetProviderCacheParams) (GetProviderCacheRow, error) {
|
|
row := q.db.QueryRow(ctx, getProviderCache,
|
|
arg.Provider,
|
|
arg.ItemType,
|
|
arg.ItemID,
|
|
arg.Market,
|
|
)
|
|
var i GetProviderCacheRow
|
|
err := row.Scan(
|
|
&i.Provider,
|
|
&i.ItemType,
|
|
&i.ItemID,
|
|
&i.Market,
|
|
&i.Payload,
|
|
&i.FetchedAt,
|
|
&i.ExpiresAt,
|
|
&i.LastError,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const providerCacheStats = `-- name: ProviderCacheStats :one
|
|
select count(*)::bigint as entries,
|
|
count(*) filter (where expires_at > now())::bigint as fresh_entries,
|
|
count(*) filter (where expires_at <= now())::bigint as stale_entries
|
|
from provider_cache
|
|
`
|
|
|
|
type ProviderCacheStatsRow struct {
|
|
Entries int64 `json:"entries"`
|
|
FreshEntries int64 `json:"fresh_entries"`
|
|
StaleEntries int64 `json:"stale_entries"`
|
|
}
|
|
|
|
func (q *Queries) ProviderCacheStats(ctx context.Context) (ProviderCacheStatsRow, error) {
|
|
row := q.db.QueryRow(ctx, providerCacheStats)
|
|
var i ProviderCacheStatsRow
|
|
err := row.Scan(&i.Entries, &i.FreshEntries, &i.StaleEntries)
|
|
return i, err
|
|
}
|
|
|
|
const upsertProviderCache = `-- name: UpsertProviderCache :exec
|
|
insert into provider_cache (provider, item_type, item_id, market, payload, fetched_at, expires_at, last_error)
|
|
values ($1, $2, $3, $4, $5::jsonb, $6, $7, nullif($8, ''))
|
|
on conflict (provider, item_type, item_id, market) do update set
|
|
payload = excluded.payload,
|
|
fetched_at = excluded.fetched_at,
|
|
expires_at = excluded.expires_at,
|
|
last_error = excluded.last_error
|
|
`
|
|
|
|
type UpsertProviderCacheParams struct {
|
|
Provider string `json:"provider"`
|
|
ItemType string `json:"item_type"`
|
|
ItemID string `json:"item_id"`
|
|
Market string `json:"market"`
|
|
Column5 []byte `json:"column_5"`
|
|
FetchedAt pgtype.Timestamptz `json:"fetched_at"`
|
|
ExpiresAt pgtype.Timestamptz `json:"expires_at"`
|
|
Column8 interface{} `json:"column_8"`
|
|
}
|
|
|
|
func (q *Queries) UpsertProviderCache(ctx context.Context, arg UpsertProviderCacheParams) error {
|
|
_, err := q.db.Exec(ctx, upsertProviderCache,
|
|
arg.Provider,
|
|
arg.ItemType,
|
|
arg.ItemID,
|
|
arg.Market,
|
|
arg.Column5,
|
|
arg.FetchedAt,
|
|
arg.ExpiresAt,
|
|
arg.Column8,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const upsertTrackEnrichment = `-- name: UpsertTrackEnrichment :exec
|
|
insert into track_enrichment (track_id, provider, musicbrainz_recording_id, musicbrainz_artist_id, isrc, payload, updated_at)
|
|
values ($1, $2, $3, $4, $5, $6::jsonb, $7)
|
|
on conflict (track_id, provider) do update set
|
|
musicbrainz_recording_id = excluded.musicbrainz_recording_id,
|
|
musicbrainz_artist_id = excluded.musicbrainz_artist_id,
|
|
isrc = excluded.isrc,
|
|
payload = excluded.payload,
|
|
updated_at = excluded.updated_at
|
|
`
|
|
|
|
type UpsertTrackEnrichmentParams struct {
|
|
TrackID string `json:"track_id"`
|
|
Provider string `json:"provider"`
|
|
MusicbrainzRecordingID string `json:"musicbrainz_recording_id"`
|
|
MusicbrainzArtistID string `json:"musicbrainz_artist_id"`
|
|
Isrc string `json:"isrc"`
|
|
Column6 []byte `json:"column_6"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) UpsertTrackEnrichment(ctx context.Context, arg UpsertTrackEnrichmentParams) error {
|
|
_, err := q.db.Exec(ctx, upsertTrackEnrichment,
|
|
arg.TrackID,
|
|
arg.Provider,
|
|
arg.MusicbrainzRecordingID,
|
|
arg.MusicbrainzArtistID,
|
|
arg.Isrc,
|
|
arg.Column6,
|
|
arg.UpdatedAt,
|
|
)
|
|
return err
|
|
}
|