edb

package
v0.0.0-...-c928bda Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package edb contains the Elakshi database models.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidURN = errors.New("invalid elakshi urn")
	ErrInvalidNID = errors.New("urn has invalid nid")
)
View Source
var (
	// ErrEIDInvalid is the error returned if an invalid eid is being parsed.
	ErrEIDInvalid = errors.New("eid invalid")
)

Functions

func AutoMigrate

func AutoMigrate(db *gorm.DB) error

func DecodeEID

func DecodeEID(eid string) (uint64, error)

DecodeEID converts the encoded id into its integer representation. Returns ErrEIDInvalid if the eid is invalid.

func EncodeEID

func EncodeEID(id uint64) string

EncodeEID encodes an id into an eid.

func GetAlbumLengthMS

func GetAlbumLengthMS(db *gorm.DB, albumID uint64) (uint64, error)

GetAlbumLengthMS returns the total length of all tracks in an album.

func GetModelByExternalRef

func GetModelByExternalRef(db *gorm.DB, service, identifier string, out interface{}) (bool, error)

GetModelByExternalRef searches a model out based on an external reference.

func GetModelByExternalRefs

func GetModelByExternalRefs(db *gorm.DB, out interface{}, refs []ExternalRef) (bool, error)

GetModelByExternalRefs returns the first model found using one of the references.

func JoinModelExternalRef

func JoinModelExternalRef(model interface{}) func(*gorm.DB) *gorm.DB

JoinModelExternalRef joins the ExternalRef rows under the alias "er". The join table is also available under the alias "jt". Assumes that the model stores the external references in an "ExternalReferences" field.

Types

type Album

type Album struct {
	DBModel

	Name        string
	Artists     []Artist `gorm:"MANY2MANY:album_artists"`
	Images      []Image  `gorm:"MANY2MANY:album_images"`
	ReleaseDate *time.Time

	Genres []Genre `gorm:"MANY2MANY:album_genres"`

	ExternalReferences []ExternalRef `gorm:"MANY2MANY:album_references"`
}

func (Album) Namespace

func (a Album) Namespace() string

type Artist

type Artist struct {
	DBModel

	Name   string
	Images []Image `gorm:"MANY2MANY:artist_images"`

	StartDate *time.Time
	EndDate   *time.Time
	Genres    []Genre `gorm:"MANY2MANY:artist_genres"`

	ExternalReferences []ExternalRef `gorm:"MANY2MANY:artist_references"`
}

func (Artist) IsEmpty

func (a Artist) IsEmpty() bool

IsEmpty checks whether the artist is empty.

func (Artist) Namespace

func (a Artist) Namespace() string

type AudioSource

type AudioSource struct {
	DBModel

	Service string `gorm:"UNIQUE_INDEX:uix_uri_type;NOT NULL"`
	URI     string `gorm:"UNIQUE_INDEX:uix_uri_type;NOT NULL"`

	TrackSources []TrackSource
}

type DBModel

type DBModel struct {
	ID        uint64 `gorm:"primary_key"`
	CreatedAt *time.Time
	UpdatedAt *time.Time
}

DBModel contains common fields shared by most Elakshi models.

func (DBModel) EID

func (m DBModel) EID() string

EID returns the eid of the model.

type ElakshiURN

type ElakshiURN struct {
	Namespace string
	EID       string
	// contains filtered or unexported fields
}

ElakshiURN represents a URN for an Elakshi entity.

func NewElakshiURN

func NewElakshiURN(namespace, eid string) ElakshiURN

NewElakshiURN builds an ElakshiURN from the namespace and eid.

func ParseURN

func ParseURN(u string) (ElakshiURN, error)

ParseURN parses a urn string into an ElakshiURN string. Note that it only accepts Elakshi urns.

func URNFromParts

func URNFromParts(parts URNPartsProvider) ElakshiURN

URNFromParts creates an ElakshiURN from a URNPartsProvider.

func (ElakshiURN) DecodeEID

func (u ElakshiURN) DecodeEID() (uint64, error)

func (ElakshiURN) String

func (u ElakshiURN) String() string

func (ElakshiURN) URN

func (u ElakshiURN) URN() string

type ExternalRef

type ExternalRef struct {
	ID uint64

	Service    string `gorm:"UNIQUE_INDEX:uix_reference_id"`
	Identifier string `gorm:"UNIQUE_INDEX:uix_reference_id"`
}

func NewExternalRef

func NewExternalRef(service, id string) ExternalRef

type Genre

type Genre struct {
	DBModel

	Name string `gorm:"UNIQUE_INDEX:uix_genre"`

	ParentID *uint64 `gorm:"UNIQUE_INDEX:uix_genre"`
	Parent   *Genre
}

func GetParentGenres

func GetParentGenres(db *gorm.DB, genreID uint64) ([]Genre, error)

GetParentGenres returns a slice containing the upper hierarchy of a genre. The order is lowest-first and includes the genre itself as the first entry.

func GetSubGenres

func GetSubGenres(db *gorm.DB, genreID uint64) ([]Genre, error)

GetSubGenres returns a slice containing the lower hierarchy of a genre. The order is lowest-first and includes the genre itself as the first entry.

func (Genre) Namespace

func (g Genre) Namespace() string

type Image

type Image struct {
	DBModel

	SourceURI string `gorm:"INDEX"`
	URI       string
}

func (Image) Namespace

func (i Image) Namespace() string

type Lyrics

type Lyrics struct {
	DBModel

	TrackID   uint64 `gorm:"INDEX;NOT NULL"`
	SourceURL string
	Text      string
}

func GetTrackLyrics

func GetTrackLyrics(db *gorm.DB, trackID uint64) (Lyrics, error)

GetTrackLyrics retrieves the lyrics for a given track.

func (Lyrics) Namespace

func (l Lyrics) Namespace() string

type Playlist

type Playlist struct {
	DBModel

	Name     string
	AuthorID uint64 `gorm:"NOT NULL"`

	ImageID *uint64
	Image   Image

	Tracks []PlaylistTrack
}

func (Playlist) Namespace

func (p Playlist) Namespace() string

type PlaylistTrack

type PlaylistTrack struct {
	DBModel

	TrackID  uint64 `gorm:"NOT NULL"`
	Track    Track
	AuthorID uint64 `gorm:"NOT NULL"`

	PlaylistID uint64 `gorm:"INDEX;NOT NULL"`
}

type RadioStation

type RadioStation struct {
	DBModel

	Name    string
	ImageID uint64 `gorm:"NOT NULL"`
	Image   Image

	Genres []Genre `gorm:"MANY2MANY:radio_genres"`
}

func (RadioStation) Namespace

func (r RadioStation) Namespace() string

type Track

type Track struct {
	DBModel

	Name     string
	LengthMS uint32 `gorm:"type:integer"`

	ArtistID          *uint64
	Artist            Artist
	AdditionalArtists []Artist `gorm:"MANY2MANY:track_additional_artists"`

	AlbumID *uint64
	Album   Album

	Images      []Image `gorm:"MANY2MANY:track_images"`
	ReleaseDate *time.Time
	Genres      []Genre `gorm:"MANY2MANY:track_genres"`

	ExternalReferences []ExternalRef `gorm:"MANY2MANY:track_references"`
}

func GetTrack

func GetTrack(db *gorm.DB, trackID uint64) (Track, error)

func (Track) AllArtists

func (track Track) AllArtists() []Artist

AllArtists a slice containing all artists.

func (Track) Length

func (track Track) Length() time.Duration

Length returns the length of the track as a duration.

func (Track) Namespace

func (track Track) Namespace() string

type TrackSource

type TrackSource struct {
	DBModel

	AudioSourceID uint64 `gorm:"NOT NULL"`
	AudioSource   *AudioSource
	TrackID       uint64 `gorm:"NOT NULL"`
	Track         Track

	StartOffsetMS uint32 `gorm:"type:integer"`
	EndOffsetMS   uint32 `gorm:"type:integer"`
}

func GetTrackSource

func GetTrackSource(db *gorm.DB, trackID uint64) (TrackSource, error)

func (TrackSource) Length

func (ts TrackSource) Length() time.Duration

Length returns the length of the track as a duration.

type URNPartsProvider

type URNPartsProvider interface {
	EID() string
	Namespace() string
}

Jump to

Keyboard shortcuts

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