database

package
v0.0.0-...-6217932 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2016 License: GPL-3.0 Imports: 13 Imported by: 0

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

View Source
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

View Source
var (
	EOF = errors.New("EOF")
)

Functions

func IncrementKey

func IncrementKey(key string) string

IncrementKey returns the key immediately following the given one (key + 1).

func ParallelFetchSongs

func ParallelFetchSongs(db services.Database, songIds []api.SongID) ([]*api.Song, error)

Utility function to fetch a number of songs in parallel.

Types

type ClientCodec

type ClientCodec interface {
	Marshal(interface{}) ([]byte, error)
	Unmarshal([]byte, interface{}) error
}

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) Del

func (db *DatabaseImpl) Del(s services.Session, bucket string, key string) error

Del exposes the generic 'del' method with optional session wrap.

func (*DatabaseImpl) Get

func (db *DatabaseImpl) Get(s services.Session, bucket string, key string, obj interface{}) error

Get exposes the generic 'get' method with optional session wrap.

func (*DatabaseImpl) GetArtists

func (db *DatabaseImpl) GetArtists(s services.Session, prefix string) ([]string, error)

func (*DatabaseImpl) GetAudioFile

func (db *DatabaseImpl) GetAudioFile(s services.Session, key string) (*api.AudioFile, bool)

func (*DatabaseImpl) GetAuthKey

func (db *DatabaseImpl) GetAuthKey(s services.Session, keyId string) (*api.AuthKey, bool)

func (*DatabaseImpl) GetMarkovMap

func (db *DatabaseImpl) GetMarkovMap(s services.Session, user string) (*api.MarkovMap, bool)

func (*DatabaseImpl) GetPlayLog

func (db *DatabaseImpl) GetPlayLog(s services.Session, key string) (*api.PlayLogEntry, bool)

func (*DatabaseImpl) GetSong

func (db *DatabaseImpl) GetSong(s services.Session, id api.SongID) (*api.Song, bool)

func (*DatabaseImpl) GetSongAcousticCorrelation

func (db *DatabaseImpl) GetSongAcousticCorrelation(s services.Session, songId1, songId2 api.SongID) (float32, error)

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 (db *DatabaseImpl) GetSongWithoutDupes(s services.Session, id api.SongID) (*api.Song, bool)

func (*DatabaseImpl) GetUser

func (db *DatabaseImpl) GetUser(s services.Session, email string) (*api.User, bool)

func (*DatabaseImpl) NewSession

func (db *DatabaseImpl) NewSession() (services.Session, error)

func (*DatabaseImpl) Put

func (db *DatabaseImpl) Put(s services.Session, bucket string, key string, obj interface{}) error

Put exposes the generic 'put' method with optional session wrap.

func (*DatabaseImpl) PutAudioFile

func (db *DatabaseImpl) PutAudioFile(s services.Session, af *api.AudioFile) error

func (*DatabaseImpl) PutAuthKey

func (db *DatabaseImpl) PutAuthKey(s services.Session, authKey *api.AuthKey) error

func (*DatabaseImpl) PutMarkovMap

func (db *DatabaseImpl) PutMarkovMap(s services.Session, user string, m *api.MarkovMap) error

func (*DatabaseImpl) PutSong

func (db *DatabaseImpl) PutSong(s services.Session, song *api.Song) error

func (*DatabaseImpl) PutSongAcousticCorrelation

func (db *DatabaseImpl) PutSongAcousticCorrelation(s services.Session, songId1, songId2 api.SongID, corr float32) error

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

func (*DatabaseImpl) PutUser

func (db *DatabaseImpl) PutUser(s services.Session, user *api.User) 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

func (*DatabaseRpcClientSession) Scan

func (s *DatabaseRpcClientSession) Scan(bucket, startKey, endKey string, limit int) (services.Iterator, error)

func (*DatabaseRpcClientSession) ScanKeys

func (s *DatabaseRpcClientSession) ScanKeys(bucket, startKey, endKey string, limit int) (services.Iterator, error)

type JsonCodec

type JsonCodec struct{}

func (JsonCodec) Marshal

func (j JsonCodec) Marshal(obj interface{}) ([]byte, error)

func (JsonCodec) Unmarshal

func (j JsonCodec) Unmarshal(data []byte, obj interface{}) error

type RawCodec

type RawCodec struct{}

func (RawCodec) Marshal

func (r RawCodec) Marshal(obj interface{}) ([]byte, error)

func (RawCodec) Unmarshal

func (r RawCodec) Unmarshal(data []byte, obj interface{}) error

Jump to

Keyboard shortcuts

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