Documentation ¶
Overview ¶
The database service consists of a set of high-level operations built on top of a simple key/value store.
The backend implementation is abstracted in the DatabaseClient interface, and is currently implemented as a single-instance RPC server using an SQLite backend. The implementation can be replaced by any key/value store that supports buckets and range scans.
The high-level API implements some simple relational behavior for the more complex objects (such as Song), and it hides the bucket names from the caller. Access is managed via Session objects, which are supposed to be short-lived and expose the low-level API. One day Sessions might acquire transactional semantics, but it currently has none.
Index ¶
- Constants
- Variables
- func IncrementKey(key string) string
- func ParallelFetchSongs(db services.Database, songIds []api.SongID) ([]*api.Song, error)
- type ClientCodec
- type DatabaseImpl
- func (db *DatabaseImpl) AppendPlayLog(s services.Session, entry *api.PlayLogEntry) error
- func (db *DatabaseImpl) Del(s services.Session, bucket string, key string) error
- func (db *DatabaseImpl) Get(s services.Session, bucket string, key string, obj interface{}) error
- func (db *DatabaseImpl) GetArtists(s services.Session, prefix string) ([]string, error)
- func (db *DatabaseImpl) GetAudioFile(s services.Session, key string) (*api.AudioFile, bool)
- func (db *DatabaseImpl) GetAuthKey(s services.Session, keyId string) (*api.AuthKey, bool)
- func (db *DatabaseImpl) GetMarkovMap(s services.Session, user string) (*api.MarkovMap, bool)
- func (db *DatabaseImpl) GetPlayLog(s services.Session, key string) (*api.PlayLogEntry, bool)
- func (db *DatabaseImpl) GetSong(s services.Session, id api.SongID) (*api.Song, bool)
- func (db *DatabaseImpl) GetSongAcousticCorrelation(s services.Session, songId1, songId2 api.SongID) (float32, error)
- func (db *DatabaseImpl) GetSongAcousticCorrelations(s services.Session, id api.SongID) ([]api.AcousticCorrelation, error)
- func (db *DatabaseImpl) GetSongAcousticData(s services.Session, song *api.Song) (*api.AcousticData, error)
- func (db *DatabaseImpl) GetSongFingerprint(s services.Session, id api.SongID) (*api.Fingerprint, error)
- func (db *DatabaseImpl) GetSongWithoutDupes(s services.Session, id api.SongID) (*api.Song, bool)
- func (db *DatabaseImpl) GetUser(s services.Session, email string) (*api.User, bool)
- func (db *DatabaseImpl) NewSession() (services.Session, error)
- func (db *DatabaseImpl) Put(s services.Session, bucket string, key string, obj interface{}) error
- func (db *DatabaseImpl) PutAudioFile(s services.Session, af *api.AudioFile) error
- func (db *DatabaseImpl) PutAuthKey(s services.Session, authKey *api.AuthKey) error
- func (db *DatabaseImpl) PutMarkovMap(s services.Session, user string, m *api.MarkovMap) error
- func (db *DatabaseImpl) PutSong(s services.Session, song *api.Song) error
- func (db *DatabaseImpl) PutSongAcousticCorrelation(s services.Session, songId1, songId2 api.SongID, corr float32) error
- func (db *DatabaseImpl) PutSongAcousticData(s services.Session, song *api.Song, ac *api.AcousticData) error
- func (db *DatabaseImpl) PutSongFingerprint(s services.Session, id api.SongID, fp *api.Fingerprint) error
- func (db *DatabaseImpl) PutUser(s services.Session, user *api.User) error
- type DatabaseRpcClient
- type DatabaseRpcClientSession
- func (s *DatabaseRpcClientSession) Close()
- func (s *DatabaseRpcClientSession) Del(bucket, key string) error
- func (s *DatabaseRpcClientSession) Get(bucket, key string, obj interface{}) error
- func (s *DatabaseRpcClientSession) Put(bucket, key string, obj interface{}) error
- func (s *DatabaseRpcClientSession) Scan(bucket, startKey, endKey string, limit int) (services.Iterator, error)
- func (s *DatabaseRpcClientSession) ScanKeys(bucket, startKey, endKey string, limit int) (services.Iterator, error)
- type JsonCodec
- type RawCodec
Constants ¶
const ( // Key prefixes for various object types. SongBucket = "song" AudioFileBucket = "audio" FingerprintBucket = "fp" AcousticDataBucket = "ac_data" AcousticCorrelationBucket = "ac_corr" UserBucket = "user" AuthKeyBucket = "auth_key" PlaylogBucket = "playlog" MarkovBucket = "markov" StatsBucket = "stats" )
Variables ¶
var (
EOF = errors.New("EOF")
)
Functions ¶
func IncrementKey ¶
IncrementKey returns the key immediately following the given one (key + 1).
Types ¶
type ClientCodec ¶
type DatabaseImpl ¶
type DatabaseImpl struct {
// contains filtered or unexported fields
}
func NewDatabaseImpl ¶
func NewDatabaseImpl(client services.DatabaseClient) *DatabaseImpl
func NewDatabaseImplFromConfig ¶
func NewDatabaseImplFromConfig() *DatabaseImpl
func (*DatabaseImpl) AppendPlayLog ¶
func (db *DatabaseImpl) AppendPlayLog(s services.Session, entry *api.PlayLogEntry) error
func (*DatabaseImpl) GetArtists ¶
func (*DatabaseImpl) GetAudioFile ¶
func (*DatabaseImpl) GetAuthKey ¶
func (*DatabaseImpl) GetMarkovMap ¶
func (*DatabaseImpl) GetPlayLog ¶
func (db *DatabaseImpl) GetPlayLog(s services.Session, key string) (*api.PlayLogEntry, bool)
func (*DatabaseImpl) GetSongAcousticCorrelation ¶
func (*DatabaseImpl) GetSongAcousticCorrelations ¶
func (db *DatabaseImpl) GetSongAcousticCorrelations(s services.Session, id api.SongID) ([]api.AcousticCorrelation, error)
func (*DatabaseImpl) GetSongAcousticData ¶
func (db *DatabaseImpl) GetSongAcousticData(s services.Session, song *api.Song) (*api.AcousticData, error)
func (*DatabaseImpl) GetSongFingerprint ¶
func (db *DatabaseImpl) GetSongFingerprint(s services.Session, id api.SongID) (*api.Fingerprint, error)
func (*DatabaseImpl) GetSongWithoutDupes ¶
func (*DatabaseImpl) NewSession ¶
func (db *DatabaseImpl) NewSession() (services.Session, error)
func (*DatabaseImpl) PutAudioFile ¶
func (*DatabaseImpl) PutAuthKey ¶
func (*DatabaseImpl) PutMarkovMap ¶
func (*DatabaseImpl) PutSongAcousticCorrelation ¶
func (*DatabaseImpl) PutSongAcousticData ¶
func (db *DatabaseImpl) PutSongAcousticData(s services.Session, song *api.Song, ac *api.AcousticData) error
func (*DatabaseImpl) PutSongFingerprint ¶
func (db *DatabaseImpl) PutSongFingerprint(s services.Session, id api.SongID, fp *api.Fingerprint) error
type DatabaseRpcClient ¶
type DatabaseRpcClient struct {
// contains filtered or unexported fields
}
func NewDatabaseRpcClient ¶
func NewDatabaseRpcClient(endpoint string, codec ClientCodec) *DatabaseRpcClient
func NewDatabaseRpcClientFromConfig ¶
func NewDatabaseRpcClientFromConfig() *DatabaseRpcClient
func NewRawDatabaseRpcClientFromConfig ¶
func NewRawDatabaseRpcClientFromConfig() *DatabaseRpcClient
func (*DatabaseRpcClient) NewSession ¶
func (c *DatabaseRpcClient) NewSession() (services.Session, error)
type DatabaseRpcClientSession ¶
type DatabaseRpcClientSession struct { *DatabaseRpcClient RpcOptions *rrpc.Options }
In this implementation, the session only contains a pointer back to a DatabaseRpcClient object.
func (*DatabaseRpcClientSession) Close ¶
func (s *DatabaseRpcClientSession) Close()
func (*DatabaseRpcClientSession) Del ¶
func (s *DatabaseRpcClientSession) Del(bucket, key string) error
func (*DatabaseRpcClientSession) Get ¶
func (s *DatabaseRpcClientSession) Get(bucket, key string, obj interface{}) error
func (*DatabaseRpcClientSession) Put ¶
func (s *DatabaseRpcClientSession) Put(bucket, key string, obj interface{}) error