db

package
v0.16.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2024 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultOptions added in v0.15.0

func DefaultOptions() url.Values

func Dump added in v0.16.0

func Dump(ctx context.Context, db *gorm.DB, to string) error

Types

type Album

type Album struct {
	ID             int `gorm:"primary_key"`
	CreatedAt      time.Time
	UpdatedAt      time.Time
	ModifiedAt     time.Time
	LeftPath       string `gorm:"unique_index:idx_album_abs_path"`
	RightPath      string `gorm:"not null; unique_index:idx_album_abs_path" sql:"default: null"`
	RightPathUDec  string `sql:"default: null"`
	Parent         *Album
	ParentID       int       `sql:"default: null; type:int REFERENCES albums(id) ON DELETE CASCADE"`
	RootDir        string    `gorm:"unique_index:idx_album_abs_path" sql:"default: null"`
	Genres         []*Genre  `gorm:"many2many:album_genres"`
	Cover          string    `sql:"default: null"`
	Artists        []*Artist `gorm:"many2many:album_artists"`
	TagTitle       string    `sql:"default: null"`
	TagAlbumArtist string    // display purposes only
	TagTitleUDec   string    `sql:"default: null"`
	TagBrainzID    string    `sql:"default: null"`
	TagYear        int       `sql:"default: null"`
	Tracks         []*Track
	ChildCount     int `sql:"-"`
	Duration       int `sql:"-"`
	AlbumStar      *AlbumStar
	AlbumRating    *AlbumRating
	AverageRating  float64 `sql:"default: null"`
	Play           *Play
}

func (*Album) IndexRightPath

func (a *Album) IndexRightPath() string

func (*Album) ParentSID added in v0.15.0

func (a *Album) ParentSID() *specid.ID

func (*Album) SID added in v0.15.0

func (a *Album) SID() *specid.ID

type AlbumArtist added in v0.16.0

type AlbumArtist struct {
	AlbumID  int `gorm:"not null; unique_index:idx_album_id_artist_id" sql:"default: null; type:int REFERENCES albums(id) ON DELETE CASCADE"`
	ArtistID int `gorm:"not null; unique_index:idx_album_id_artist_id" sql:"default: null; type:int REFERENCES artists(id) ON DELETE CASCADE"`
}

type AlbumGenre added in v0.15.0

type AlbumGenre struct {
	AlbumID int `gorm:"not null; unique_index:idx_album_id_genre_id" sql:"default: null; type:int REFERENCES albums(id) ON DELETE CASCADE"`
	GenreID int `gorm:"not null; unique_index:idx_album_id_genre_id" sql:"default: null; type:int REFERENCES genres(id) ON DELETE CASCADE"`
}

type AlbumInfo added in v0.16.1

type AlbumInfo struct {
	ID            int `gorm:"primary_key" sql:"type:int REFERENCES albums(id) ON DELETE CASCADE"`
	CreatedAt     time.Time
	UpdatedAt     time.Time `gorm:"index"`
	Notes         string
	MusicBrainzID string
	LastFMURL     string
}

type AlbumRating added in v0.15.0

type AlbumRating struct {
	UserID  int `gorm:"primary_key; not null" sql:"default: null; type:int REFERENCES users(id) ON DELETE CASCADE"`
	AlbumID int `gorm:"primary_key; not null" sql:"default: null; type:int REFERENCES albums(id) ON DELETE CASCADE"`
	Rating  int `gorm:"not null; check:(rating >= 1 AND rating <= 5)"`
}

type AlbumStar added in v0.15.0

type AlbumStar struct {
	UserID   int `gorm:"primary_key; not null" sql:"default: null; type:int REFERENCES users(id) ON DELETE CASCADE"`
	AlbumID  int `gorm:"primary_key; not null" sql:"default: null; type:int REFERENCES albums(id) ON DELETE CASCADE"`
	StarDate time.Time
}

type Artist

type Artist struct {
	ID              int      `gorm:"primary_key"`
	Name            string   `gorm:"not null; unique_index"`
	NameUDec        string   `sql:"default: null"`
	Albums          []*Album `gorm:"many2many:album_artists"`
	AlbumCount      int      `sql:"-"`
	Appearances     []*Album `gorm:"many2many:artist_appearances"`
	AppearanceCount int      `sql:"-"`
	ArtistStar      *ArtistStar
	ArtistRating    *ArtistRating
	AverageRating   float64     `sql:"default: null"`
	Info            *ArtistInfo `gorm:"foreignkey:id"`
}

func (*Artist) IndexName

func (a *Artist) IndexName() string

func (*Artist) SID added in v0.15.0

func (a *Artist) SID() *specid.ID

type ArtistAppearances added in v0.16.1

type ArtistAppearances struct {
	ArtistID int `gorm:"not null; unique_index:idx_artist_id_album_id" sql:"default: null; type:int REFERENCES artists(id) ON DELETE CASCADE"`
	AlbumID  int `gorm:"not null; unique_index:idx_artist_id_album_id" sql:"default: null; type:int REFERENCES albums(id) ON DELETE CASCADE"`
}

type ArtistInfo added in v0.16.0

type ArtistInfo struct {
	ID             int `gorm:"primary_key" sql:"type:int REFERENCES artists(id) ON DELETE CASCADE"`
	CreatedAt      time.Time
	UpdatedAt      time.Time `gorm:"index"`
	Biography      string
	MusicBrainzID  string
	LastFMURL      string
	ImageURL       string
	SimilarArtists string
	TopTracks      string
}

func (*ArtistInfo) GetSimilarArtists added in v0.16.0

func (p *ArtistInfo) GetSimilarArtists() []string

func (*ArtistInfo) GetTopTracks added in v0.16.0

func (p *ArtistInfo) GetTopTracks() []string

func (*ArtistInfo) SetSimilarArtists added in v0.16.0

func (p *ArtistInfo) SetSimilarArtists(items []string)

func (*ArtistInfo) SetTopTracks added in v0.16.0

func (p *ArtistInfo) SetTopTracks(items []string)

type ArtistRating added in v0.15.0

type ArtistRating struct {
	UserID   int `gorm:"primary_key; not null" sql:"default: null; type:int REFERENCES users(id) ON DELETE CASCADE"`
	ArtistID int `gorm:"primary_key; not null" sql:"default: null; type:int REFERENCES artists(id) ON DELETE CASCADE"`
	Rating   int `gorm:"not null; check:(rating >= 1 AND rating <= 5)"`
}

type ArtistStar added in v0.15.0

type ArtistStar struct {
	UserID   int `gorm:"primary_key; not null" sql:"default: null; type:int REFERENCES users(id) ON DELETE CASCADE"`
	ArtistID int `gorm:"primary_key; not null" sql:"default: null; type:int REFERENCES artists(id) ON DELETE CASCADE"`
	StarDate time.Time
}

type AudioFile added in v0.15.0

type AudioFile interface {
	Ext() string
	MIME() string
	AudioFilename() string
	AudioBitrate() int
	AudioLength() int
}

AudioFile is used to avoid some duplication in handlers_raw.go between Track and Podcast

type Bookmark added in v0.15.0

type Bookmark struct {
	ID          int `gorm:"primary_key"`
	User        *User
	UserID      int `sql:"default: null; type:int REFERENCES users(id) ON DELETE CASCADE"`
	Position    int
	Comment     string
	EntryIDType string
	EntryID     int
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

type DB

type DB struct {
	*gorm.DB
}

func New

func New(path string, options url.Values) (*DB, error)

func NewMock

func NewMock() (*DB, error)

func (*DB) Begin added in v0.15.0

func (db *DB) Begin() *DB

func (*DB) GetSetting

func (db *DB) GetSetting(key SettingKey) (string, error)

func (*DB) GetUserByID added in v0.15.0

func (db *DB) GetUserByID(id int) *User

func (*DB) GetUserByName added in v0.15.0

func (db *DB) GetUserByName(name string) *User

func (*DB) InsertBulkLeftMany added in v0.15.0

func (db *DB) InsertBulkLeftMany(table string, head []string, left int, col []int) error

func (*DB) Migrate added in v0.15.0

func (db *DB) Migrate(ctx MigrationContext) error

func (*DB) SetSetting

func (db *DB) SetSetting(key SettingKey, value string) error

func (*DB) Stats added in v0.16.1

func (db *DB) Stats() (Stats, error)

func (*DB) Transaction added in v0.16.1

func (db *DB) Transaction(cb func(*DB) error) error

func (*DB) TransactionChunked added in v0.15.0

func (db *DB) TransactionChunked(data []int64, cb func(*DB, []int64) error) error

type Genre

type Genre struct {
	ID         int    `gorm:"primary_key"`
	Name       string `gorm:"not null; unique_index"`
	AlbumCount int    `sql:"-"`
	TrackCount int    `sql:"-"`
}

type InternetRadioStation added in v0.15.0

type InternetRadioStation struct {
	ID          int `gorm:"primary_key"`
	StreamURL   string
	Name        string
	HomepageURL string
}

func (*InternetRadioStation) AbsPath added in v0.16.4

func (ir *InternetRadioStation) AbsPath() string

func (*InternetRadioStation) SID added in v0.15.0

func (ir *InternetRadioStation) SID() *specid.ID

type MigrationContext added in v0.15.0

type MigrationContext struct {
	Production        bool
	DBPath            string
	OriginalMusicPath string
	PlaylistsPath     string
	PodcastsPath      string
}

type Play

type Play struct {
	ID      int `gorm:"primary_key"`
	User    *User
	UserID  int `gorm:"not null; index" sql:"default: null; type:int REFERENCES users(id) ON DELETE CASCADE"`
	Album   *Album
	AlbumID int       `gorm:"not null; index" sql:"default: null; type:int REFERENCES albums(id) ON DELETE CASCADE"`
	Time    time.Time `sql:"default: null"`
	Count   int
	Length  int
}

type PlayQueue

type PlayQueue struct {
	ID        int `gorm:"primary_key"`
	CreatedAt time.Time
	UpdatedAt time.Time
	User      *User
	UserID    int `sql:"default: null; type:int REFERENCES users(id) ON DELETE CASCADE"`
	Current   string
	Position  int
	ChangedBy string
	Items     string
}

func (*PlayQueue) CurrentSID added in v0.15.0

func (p *PlayQueue) CurrentSID() *specid.ID

func (*PlayQueue) GetItems

func (p *PlayQueue) GetItems() []specid.ID

func (*PlayQueue) SetItems

func (p *PlayQueue) SetItems(items []specid.ID)

type Podcast added in v0.15.0

type Podcast struct {
	ID           int `gorm:"primary_key"`
	UpdatedAt    time.Time
	ModifiedAt   time.Time
	URL          string
	Title        string
	Description  string
	ImageURL     string
	Image        string
	Error        string
	Episodes     []*PodcastEpisode
	AutoDownload PodcastAutoDownload
	RootDir      string
}

func (*Podcast) SID added in v0.15.0

func (p *Podcast) SID() *specid.ID

type PodcastAutoDownload added in v0.15.0

type PodcastAutoDownload string
const (
	PodcastAutoDownloadLatest PodcastAutoDownload = "latest"
	PodcastAutoDownloadNone   PodcastAutoDownload = "none"
)

type PodcastEpisode added in v0.15.0

type PodcastEpisode struct {
	ID          int `gorm:"primary_key"`
	CreatedAt   time.Time
	UpdatedAt   time.Time
	ModifiedAt  time.Time
	PodcastID   int `gorm:"not null" sql:"default: null; type:int REFERENCES podcasts(id) ON DELETE CASCADE"`
	Title       string
	Description string
	PublishDate *time.Time
	AudioURL    string
	Bitrate     int
	Length      int
	Size        int
	Filename    string
	Status      PodcastEpisodeStatus
	Error       string
	Podcast     *Podcast
}

func (*PodcastEpisode) AbsPath added in v0.16.0

func (pe *PodcastEpisode) AbsPath() string

func (*PodcastEpisode) AudioBitrate added in v0.15.0

func (pe *PodcastEpisode) AudioBitrate() int

func (*PodcastEpisode) AudioFilename added in v0.15.0

func (pe *PodcastEpisode) AudioFilename() string

func (*PodcastEpisode) AudioLength added in v0.15.0

func (pe *PodcastEpisode) AudioLength() int

func (*PodcastEpisode) Ext added in v0.15.0

func (pe *PodcastEpisode) Ext() string

func (*PodcastEpisode) MIME added in v0.15.0

func (pe *PodcastEpisode) MIME() string

func (*PodcastEpisode) PodcastSID added in v0.15.0

func (pe *PodcastEpisode) PodcastSID() *specid.ID

func (*PodcastEpisode) SID added in v0.15.0

func (pe *PodcastEpisode) SID() *specid.ID

type PodcastEpisodeStatus added in v0.15.0

type PodcastEpisodeStatus string
const (
	PodcastEpisodeStatusDownloading PodcastEpisodeStatus = "downloading"
	PodcastEpisodeStatusSkipped     PodcastEpisodeStatus = "skipped"
	PodcastEpisodeStatusDeleted     PodcastEpisodeStatus = "deleted"
	PodcastEpisodeStatusCompleted   PodcastEpisodeStatus = "completed"
	PodcastEpisodeStatusError       PodcastEpisodeStatus = "error"
)

type Setting

type Setting struct {
	Key   SettingKey `gorm:"not null; primary_key; auto_increment:false" sql:"default: null"`
	Value string     `sql:"default: null"`
}

type SettingKey added in v0.16.0

type SettingKey string
const (
	LastFMAPIKey SettingKey = "lastfm_api_key" //nolint:gosec
	LastFMSecret SettingKey = "lastfm_secret"
	LastScanTime SettingKey = "last_scan_time"
)

type Stats added in v0.16.1

type Stats struct {
	Folders, Albums, Artists, AlbumArtists, Tracks, InternetRadioStations, Podcasts uint
}

type Track

type Track struct {
	ID             int `gorm:"primary_key"`
	CreatedAt      time.Time
	UpdatedAt      time.Time
	Filename       string `gorm:"not null; unique_index:idx_folder_filename" sql:"default: null"`
	FilenameUDec   string `sql:"default: null"`
	Album          *Album
	AlbumID        int       `gorm:"not null; unique_index:idx_folder_filename" sql:"default: null; type:int REFERENCES albums(id) ON DELETE CASCADE"`
	Artists        []*Artist `gorm:"many2many:track_artists"`
	Genres         []*Genre  `gorm:"many2many:track_genres"`
	Size           int       `sql:"default: null"`
	Length         int       `sql:"default: null"`
	Bitrate        int       `sql:"default: null"`
	TagTitle       string    `sql:"default: null"`
	TagTitleUDec   string    `sql:"default: null"`
	TagTrackArtist string    `sql:"default: null"`
	TagTrackNumber int       `sql:"default: null"`
	TagDiscNumber  int       `sql:"default: null"`
	TagBrainzID    string    `sql:"default: null"`
	TrackStar      *TrackStar
	TrackRating    *TrackRating
	AverageRating  float64 `sql:"default: null"`
}

func (*Track) AbsPath added in v0.15.0

func (t *Track) AbsPath() string

func (*Track) AlbumSID added in v0.15.0

func (t *Track) AlbumSID() *specid.ID

func (*Track) AudioBitrate added in v0.15.0

func (t *Track) AudioBitrate() int

func (*Track) AudioFilename added in v0.15.0

func (t *Track) AudioFilename() string

func (*Track) AudioLength added in v0.15.0

func (t *Track) AudioLength() int

func (*Track) Ext

func (t *Track) Ext() string

func (*Track) MIME

func (t *Track) MIME() string

func (*Track) RelPath

func (t *Track) RelPath() string

func (*Track) SID added in v0.15.0

func (t *Track) SID() *specid.ID

type TrackArtist added in v0.16.1

type TrackArtist struct {
	TrackID  int `gorm:"not null; unique_index:idx_track_id_artist_id" sql:"default: null; type:int REFERENCES tracks(id) ON DELETE CASCADE"`
	ArtistID int `gorm:"not null; unique_index:idx_track_id_artist_id" sql:"default: null; type:int REFERENCES artists(id) ON DELETE CASCADE"`
}

type TrackGenre added in v0.15.0

type TrackGenre struct {
	TrackID int `gorm:"not null; unique_index:idx_track_id_genre_id" sql:"default: null; type:int REFERENCES tracks(id) ON DELETE CASCADE"`
	GenreID int `gorm:"not null; unique_index:idx_track_id_genre_id" sql:"default: null; type:int REFERENCES genres(id) ON DELETE CASCADE"`
}

type TrackRating added in v0.15.0

type TrackRating struct {
	UserID  int `gorm:"primary_key; not null" sql:"default: null; type:int REFERENCES users(id) ON DELETE CASCADE"`
	TrackID int `gorm:"primary_key; not null" sql:"default: null; type:int REFERENCES tracks(id) ON DELETE CASCADE"`
	Rating  int `gorm:"not null; check:(rating >= 1 AND rating <= 5)"`
}

type TrackStar added in v0.15.0

type TrackStar struct {
	UserID   int `gorm:"primary_key; not null" sql:"default: null; type:int REFERENCES users(id) ON DELETE CASCADE"`
	TrackID  int `gorm:"primary_key; not null" sql:"default: null; type:int REFERENCES tracks(id) ON DELETE CASCADE"`
	StarDate time.Time
}

type TranscodePreference

type TranscodePreference struct {
	UserID  int    `gorm:"not null; unique_index:idx_user_id_client" sql:"default: null; type:int REFERENCES users(id) ON DELETE CASCADE"`
	Client  string `gorm:"not null; unique_index:idx_user_id_client" sql:"default: null"`
	Profile string `gorm:"not null" sql:"default: null"`
}

type User

type User struct {
	ID                int `gorm:"primary_key"`
	CreatedAt         time.Time
	Name              string `gorm:"not null; unique_index" sql:"default: null"`
	Password          string `gorm:"not null" sql:"default: null"`
	LastFMSession     string `sql:"default: null"`
	ListenBrainzURL   string `sql:"default: null"`
	ListenBrainzToken string `sql:"default: null"`
	IsAdmin           bool   `sql:"default: null"`
	Avatar            []byte `sql:"default: null"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL