mirror of
https://github.com/Dvorinka/SpotifyRecAlg.git
synced 2026-06-04 12:33:03 +00:00
first commit
This commit is contained in:
@@ -0,0 +1,337 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.29.0
|
||||
// source: catalog.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const getControls = `-- name: GetControls :one
|
||||
select user_id, allow_explicit, excluded_tracks, excluded_artists, excluded_genres, postponed_tracks
|
||||
from user_controls
|
||||
where user_id = $1
|
||||
`
|
||||
|
||||
type GetControlsRow struct {
|
||||
UserID string `json:"user_id"`
|
||||
AllowExplicit bool `json:"allow_explicit"`
|
||||
ExcludedTracks []byte `json:"excluded_tracks"`
|
||||
ExcludedArtists []byte `json:"excluded_artists"`
|
||||
ExcludedGenres []byte `json:"excluded_genres"`
|
||||
PostponedTracks []byte `json:"postponed_tracks"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetControls(ctx context.Context, userID string) (GetControlsRow, error) {
|
||||
row := q.db.QueryRow(ctx, getControls, userID)
|
||||
var i GetControlsRow
|
||||
err := row.Scan(
|
||||
&i.UserID,
|
||||
&i.AllowExplicit,
|
||||
&i.ExcludedTracks,
|
||||
&i.ExcludedArtists,
|
||||
&i.ExcludedGenres,
|
||||
&i.PostponedTracks,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getTracksByIDs = `-- name: GetTracksByIDs :many
|
||||
select id, title, artist, album, genres, release_date, duration_ms, popularity,
|
||||
explicit, features, external, created_at, updated_at, commercial_boost, quality_penalty, discovery_allowed
|
||||
from tracks
|
||||
where id = any($1::text[])
|
||||
order by id
|
||||
`
|
||||
|
||||
type GetTracksByIDsRow struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Artist string `json:"artist"`
|
||||
Album string `json:"album"`
|
||||
Genres []byte `json:"genres"`
|
||||
ReleaseDate string `json:"release_date"`
|
||||
DurationMs int32 `json:"duration_ms"`
|
||||
Popularity float64 `json:"popularity"`
|
||||
Explicit bool `json:"explicit"`
|
||||
Features []byte `json:"features"`
|
||||
External []byte `json:"external"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
CommercialBoost float64 `json:"commercial_boost"`
|
||||
QualityPenalty float64 `json:"quality_penalty"`
|
||||
DiscoveryAllowed bool `json:"discovery_allowed"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetTracksByIDs(ctx context.Context, dollar_1 []string) ([]GetTracksByIDsRow, error) {
|
||||
rows, err := q.db.Query(ctx, getTracksByIDs, dollar_1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []GetTracksByIDsRow
|
||||
for rows.Next() {
|
||||
var i GetTracksByIDsRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Title,
|
||||
&i.Artist,
|
||||
&i.Album,
|
||||
&i.Genres,
|
||||
&i.ReleaseDate,
|
||||
&i.DurationMs,
|
||||
&i.Popularity,
|
||||
&i.Explicit,
|
||||
&i.Features,
|
||||
&i.External,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.CommercialBoost,
|
||||
&i.QualityPenalty,
|
||||
&i.DiscoveryAllowed,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listRecentInteractions = `-- name: ListRecentInteractions :many
|
||||
select user_id, track_id, type, weight, occurred_at, context, completed_ms
|
||||
from interactions
|
||||
where occurred_at >= now() - interval '365 days'
|
||||
order by occurred_at desc
|
||||
limit 250000
|
||||
`
|
||||
|
||||
type ListRecentInteractionsRow struct {
|
||||
UserID string `json:"user_id"`
|
||||
TrackID string `json:"track_id"`
|
||||
Type string `json:"type"`
|
||||
Weight float64 `json:"weight"`
|
||||
OccurredAt pgtype.Timestamptz `json:"occurred_at"`
|
||||
Context []byte `json:"context"`
|
||||
CompletedMs int32 `json:"completed_ms"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListRecentInteractions(ctx context.Context) ([]ListRecentInteractionsRow, error) {
|
||||
rows, err := q.db.Query(ctx, listRecentInteractions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListRecentInteractionsRow
|
||||
for rows.Next() {
|
||||
var i ListRecentInteractionsRow
|
||||
if err := rows.Scan(
|
||||
&i.UserID,
|
||||
&i.TrackID,
|
||||
&i.Type,
|
||||
&i.Weight,
|
||||
&i.OccurredAt,
|
||||
&i.Context,
|
||||
&i.CompletedMs,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listTracks = `-- name: ListTracks :many
|
||||
select id, title, artist, album, genres, release_date, duration_ms, popularity,
|
||||
explicit, features, external, created_at, updated_at, commercial_boost, quality_penalty, discovery_allowed
|
||||
from tracks
|
||||
order by id
|
||||
`
|
||||
|
||||
type ListTracksRow struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Artist string `json:"artist"`
|
||||
Album string `json:"album"`
|
||||
Genres []byte `json:"genres"`
|
||||
ReleaseDate string `json:"release_date"`
|
||||
DurationMs int32 `json:"duration_ms"`
|
||||
Popularity float64 `json:"popularity"`
|
||||
Explicit bool `json:"explicit"`
|
||||
Features []byte `json:"features"`
|
||||
External []byte `json:"external"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
CommercialBoost float64 `json:"commercial_boost"`
|
||||
QualityPenalty float64 `json:"quality_penalty"`
|
||||
DiscoveryAllowed bool `json:"discovery_allowed"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListTracks(ctx context.Context) ([]ListTracksRow, error) {
|
||||
rows, err := q.db.Query(ctx, listTracks)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListTracksRow
|
||||
for rows.Next() {
|
||||
var i ListTracksRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Title,
|
||||
&i.Artist,
|
||||
&i.Album,
|
||||
&i.Genres,
|
||||
&i.ReleaseDate,
|
||||
&i.DurationMs,
|
||||
&i.Popularity,
|
||||
&i.Explicit,
|
||||
&i.Features,
|
||||
&i.External,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.CommercialBoost,
|
||||
&i.QualityPenalty,
|
||||
&i.DiscoveryAllowed,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const recordInteraction = `-- name: RecordInteraction :exec
|
||||
insert into interactions (user_id, track_id, type, weight, occurred_at, context, completed_ms)
|
||||
values ($1, $2, $3, $4, $5, $6::jsonb, $7)
|
||||
`
|
||||
|
||||
type RecordInteractionParams struct {
|
||||
UserID string `json:"user_id"`
|
||||
TrackID string `json:"track_id"`
|
||||
Type string `json:"type"`
|
||||
Weight float64 `json:"weight"`
|
||||
OccurredAt pgtype.Timestamptz `json:"occurred_at"`
|
||||
Column6 []byte `json:"column_6"`
|
||||
CompletedMs int32 `json:"completed_ms"`
|
||||
}
|
||||
|
||||
func (q *Queries) RecordInteraction(ctx context.Context, arg RecordInteractionParams) error {
|
||||
_, err := q.db.Exec(ctx, recordInteraction,
|
||||
arg.UserID,
|
||||
arg.TrackID,
|
||||
arg.Type,
|
||||
arg.Weight,
|
||||
arg.OccurredAt,
|
||||
arg.Column6,
|
||||
arg.CompletedMs,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const upsertControls = `-- name: UpsertControls :exec
|
||||
insert into user_controls (user_id, allow_explicit, excluded_tracks, excluded_artists, excluded_genres, postponed_tracks)
|
||||
values ($1, $2, $3::jsonb, $4::jsonb, $5::jsonb, $6::jsonb)
|
||||
on conflict (user_id) do update set
|
||||
allow_explicit = excluded.allow_explicit,
|
||||
excluded_tracks = excluded.excluded_tracks,
|
||||
excluded_artists = excluded.excluded_artists,
|
||||
excluded_genres = excluded.excluded_genres,
|
||||
postponed_tracks = excluded.postponed_tracks,
|
||||
updated_at = now()
|
||||
`
|
||||
|
||||
type UpsertControlsParams struct {
|
||||
UserID string `json:"user_id"`
|
||||
AllowExplicit bool `json:"allow_explicit"`
|
||||
Column3 []byte `json:"column_3"`
|
||||
Column4 []byte `json:"column_4"`
|
||||
Column5 []byte `json:"column_5"`
|
||||
Column6 []byte `json:"column_6"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertControls(ctx context.Context, arg UpsertControlsParams) error {
|
||||
_, err := q.db.Exec(ctx, upsertControls,
|
||||
arg.UserID,
|
||||
arg.AllowExplicit,
|
||||
arg.Column3,
|
||||
arg.Column4,
|
||||
arg.Column5,
|
||||
arg.Column6,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const upsertTrack = `-- name: UpsertTrack :exec
|
||||
insert into tracks (
|
||||
id, title, artist, album, genres, release_date, duration_ms, popularity,
|
||||
explicit, features, external, commercial_boost, quality_penalty, discovery_allowed
|
||||
) values (
|
||||
$1, $2, $3, $4, $5::jsonb, $6, $7, $8,
|
||||
$9, $10::jsonb, $11::jsonb, $12, $13, $14
|
||||
)
|
||||
on conflict (id) do update set
|
||||
title = excluded.title,
|
||||
artist = excluded.artist,
|
||||
album = excluded.album,
|
||||
genres = excluded.genres,
|
||||
release_date = excluded.release_date,
|
||||
duration_ms = excluded.duration_ms,
|
||||
popularity = excluded.popularity,
|
||||
explicit = excluded.explicit,
|
||||
features = excluded.features,
|
||||
external = excluded.external,
|
||||
commercial_boost = excluded.commercial_boost,
|
||||
quality_penalty = excluded.quality_penalty,
|
||||
discovery_allowed = excluded.discovery_allowed,
|
||||
updated_at = now()
|
||||
`
|
||||
|
||||
type UpsertTrackParams struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Artist string `json:"artist"`
|
||||
Album string `json:"album"`
|
||||
Column5 []byte `json:"column_5"`
|
||||
ReleaseDate string `json:"release_date"`
|
||||
DurationMs int32 `json:"duration_ms"`
|
||||
Popularity float64 `json:"popularity"`
|
||||
Explicit bool `json:"explicit"`
|
||||
Column10 []byte `json:"column_10"`
|
||||
Column11 []byte `json:"column_11"`
|
||||
CommercialBoost float64 `json:"commercial_boost"`
|
||||
QualityPenalty float64 `json:"quality_penalty"`
|
||||
DiscoveryAllowed bool `json:"discovery_allowed"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertTrack(ctx context.Context, arg UpsertTrackParams) error {
|
||||
_, err := q.db.Exec(ctx, upsertTrack,
|
||||
arg.ID,
|
||||
arg.Title,
|
||||
arg.Artist,
|
||||
arg.Album,
|
||||
arg.Column5,
|
||||
arg.ReleaseDate,
|
||||
arg.DurationMs,
|
||||
arg.Popularity,
|
||||
arg.Explicit,
|
||||
arg.Column10,
|
||||
arg.Column11,
|
||||
arg.CommercialBoost,
|
||||
arg.QualityPenalty,
|
||||
arg.DiscoveryAllowed,
|
||||
)
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.29.0
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
)
|
||||
|
||||
type DBTX interface {
|
||||
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
|
||||
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
|
||||
QueryRow(context.Context, string, ...interface{}) pgx.Row
|
||||
}
|
||||
|
||||
func New(db DBTX) *Queries {
|
||||
return &Queries{db: db}
|
||||
}
|
||||
|
||||
type Queries struct {
|
||||
db DBTX
|
||||
}
|
||||
|
||||
func (q *Queries) WithTx(tx pgx.Tx) *Queries {
|
||||
return &Queries{
|
||||
db: tx,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.29.0
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
type ImportJob 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"`
|
||||
Warnings []byte `json:"warnings"`
|
||||
StartedAt pgtype.Timestamptz `json:"started_at"`
|
||||
FinishedAt pgtype.Timestamptz `json:"finished_at"`
|
||||
}
|
||||
|
||||
type Interaction struct {
|
||||
ID int64 `json:"id"`
|
||||
UserID string `json:"user_id"`
|
||||
TrackID string `json:"track_id"`
|
||||
Type string `json:"type"`
|
||||
Weight float64 `json:"weight"`
|
||||
OccurredAt pgtype.Timestamptz `json:"occurred_at"`
|
||||
Context []byte `json:"context"`
|
||||
CompletedMs int32 `json:"completed_ms"`
|
||||
}
|
||||
|
||||
type ProviderCache 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 pgtype.Text `json:"last_error"`
|
||||
}
|
||||
|
||||
type Track struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Artist string `json:"artist"`
|
||||
Album string `json:"album"`
|
||||
Genres []byte `json:"genres"`
|
||||
ReleaseDate string `json:"release_date"`
|
||||
DurationMs int32 `json:"duration_ms"`
|
||||
Popularity float64 `json:"popularity"`
|
||||
Explicit bool `json:"explicit"`
|
||||
Features []byte `json:"features"`
|
||||
External []byte `json:"external"`
|
||||
CommercialBoost float64 `json:"commercial_boost"`
|
||||
QualityPenalty float64 `json:"quality_penalty"`
|
||||
DiscoveryAllowed bool `json:"discovery_allowed"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type TrackEnrichment 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"`
|
||||
Payload []byte `json:"payload"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type UserControl struct {
|
||||
UserID string `json:"user_id"`
|
||||
AllowExplicit bool `json:"allow_explicit"`
|
||||
ExcludedTracks []byte `json:"excluded_tracks"`
|
||||
ExcludedArtists []byte `json:"excluded_artists"`
|
||||
ExcludedGenres []byte `json:"excluded_genres"`
|
||||
PostponedTracks []byte `json:"postponed_tracks"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
// 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
|
||||
}
|
||||
Reference in New Issue
Block a user