Documentation
¶
Overview ¶
Package db contains Datastore-related types and constants used by the server.
Index ¶
- Constants
- func CleanSong(s *common.Song, id int64)
- func Normalize(s string) (string, error)
- func SplitIntoKeywords(s string) []string
- type Song
- func (s *Song) Clean()
- func (s *Song) Load(orig []datastore.Property) error
- func (s Song) MarshalJSON() ([]byte, error)
- func (s *Song) RebuildPlayStats(plays []common.Play)
- func (s *Song) Save() ([]datastore.Property, error)
- func (s *Song) SetRating(r int)
- func (s Song) UnmarshalJSON([]byte) error
- func (dst *Song) Update(src *Song, copyUserData bool) error
- func (s *Song) UpdatePlayStats(startTime time.Time)
Constants ¶
const ( // Datastore kinds of various objects. PlayKind = "Play" SongKind = "Song" DeletedPlayKind = "DeletedPlay" DeletedSongKind = "DeletedSong" )
Variables ¶
This section is empty.
Functions ¶
func CleanSong ¶
CleanSong prepares s to be returned to clients. This is exported so it can be called by tests in other packages.
func Normalize ¶
Normalize normalizes s for searches.
NFKD form is used. Unicode characters are decomposed (runes are broken into their components) and replaced for compatibility equivalence (characters that represent the same characters but have different visual representations, e.g. '9' and '⁹', are equal). Visually-similar characters from different alphabets will not be equal, however (e.g. Latin 'o', Greek 'ο', and Cyrillic 'о'). See https://go.dev/blog/normalization for more details.
Characters are also de-accented and lowercased, but punctuation is preserved.
func SplitIntoKeywords ¶
SplitIntoKeywords splits s into individual keywords for searching.
The returned keywords are not deduped or normalized.
Types ¶
type Song ¶
type Song struct {
common.Song
// Lowercase versions used for searching and sorting.
// Additional normalization is performed: see the Normalize function.
ArtistLower string
TitleLower string
AlbumLower string
// Keywords contains words from ArtistLower, TitleLower, AlbumLower, and
// AlbumArtist and DiscSubtitle (after normalization). It is used for searching.
Keywords []string
// RatingAtLeast* are true if Rating is at least the specified value.
// These are maintained to sidestep Datastore's restriction against using multiple
// inequality filters in a query.
RatingAtLeast1 bool
RatingAtLeast2 bool
RatingAtLeast3 bool
RatingAtLeast4 bool
// FirstStartTime is the first time the song was played.
FirstStartTime time.Time
// LastStartTime is the last time the song was played.
LastStartTime time.Time
// NumPlays is the number of times the song has been played.
NumPlays int
// LastModifiedTime is the time that the song was modified.
LastModifiedTime time.Time
}
Song wraps common.Song, adding additional fields used by datastore.
func (*Song) Clean ¶
func (s *Song) Clean()
Clean sorts and removes duplicates from slice fields in s.
func (*Song) Load ¶
Load implements datastore.PropertyLoadSaver. A custom implementation is needed to handle old DeletedSong entities.
func (Song) MarshalJSON ¶
func (*Song) RebuildPlayStats ¶
RebuildPlayStats regenerates NumPlays, FirstStartTime, and LastStartTime based on the supplied plays.
func (Song) UnmarshalJSON ¶
func (*Song) Update ¶
Update copies fields from src to dst.
If copyUserData is true, the Rating*, FirstStartTime, LastStartTime, Plays, and Tags fields are also copied; otherwise they are left unchanged.
ArtistLower, TitleLower, AlbumLower, and Keywords are also initialized in dst, and Clean is called. RebuildPlayStats is not called (since plays may not have been loaded).
func (*Song) UpdatePlayStats ¶
UpdatePlayStats updates NumPlays, FirstStartTime, and LastStartTime to reflect an additional play starting at startTime.