db

package
v0.0.0-...-fbcb358 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2026 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Overview

Package db contains Datastore-related types and constants used by the server.

Index

Constants

View Source
const (
	// Datastore kinds of various objects.
	PlayKind        = "Play"
	SongKind        = "Song"
	DeletedPlayKind = "DeletedPlay"
	DeletedSongKind = "DeletedSong"
)

Variables

This section is empty.

Functions

func CleanSong

func CleanSong(s *common.Song, id int64)

CleanSong prepares s to be returned to clients. This is exported so it can be called by tests in other packages.

func Normalize

func Normalize(s string) (string, error)

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

func SplitIntoKeywords(s string) []string

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

func (s *Song) Load(orig []datastore.Property) error

Load implements datastore.PropertyLoadSaver. A custom implementation is needed to handle old DeletedSong entities.

func (Song) MarshalJSON

func (s Song) MarshalJSON() ([]byte, error)

func (*Song) RebuildPlayStats

func (s *Song) RebuildPlayStats(plays []common.Play)

RebuildPlayStats regenerates NumPlays, FirstStartTime, and LastStartTime based on the supplied plays.

func (*Song) Save

func (s *Song) Save() ([]datastore.Property, error)

Save implements datastore.PropertyLoadSaver.

func (*Song) SetRating

func (s *Song) SetRating(r int)

SetRating sets Rating to r and updates RatingAtLeast*.

func (Song) UnmarshalJSON

func (s Song) UnmarshalJSON([]byte) error

func (*Song) Update

func (dst *Song) Update(src *Song, copyUserData bool) error

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

func (s *Song) UpdatePlayStats(startTime time.Time)

UpdatePlayStats updates NumPlays, FirstStartTime, and LastStartTime to reflect an additional play starting at startTime.

Jump to

Keyboard shortcuts

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