database

package
v0.0.0-...-57178c3 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2021 License: ISC Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FKViolationAccountErr = DbHTTPErr{"foreign_key_violation", "_account_id_fkey", http.StatusForbidden}

FKViolationAccountErr is a foreign key violation on account id

View Source
var FKViolationTemplateErr = DbHTTPErr{"foreign_key_violation", "_template_id_fkey", http.StatusBadRequest}

FKViolationTemplateErr is a foreign key violation on template id

View Source
var GenreLabels []string

GenreLabels contains the instrument constraints

View Source
var InstrumentLabels []string

InstrumentLabels contains the instrument constraints

View Source
var LabelConstraints map[string]*models.RecordingLabel

LabelConstraints contains the label constraints

View Source
var MoodLabels []string

MoodLabels contains the instrument constraints

View Source
var UniqueViolationEmailErr = DbHTTPErr{"unique_violation", "_email_key", http.StatusConflict}

UniqueViolationEmailErr is a unique violation error on email

View Source
var UniqueViolationUsernameErr = DbHTTPErr{"unique_violation", "_username_key", http.StatusConflict}

UniqueViolationUsernameErr is a unique violation error on email

Functions

func CollectLabels

func CollectLabels(rows *sql.Rows, hasAccount bool) *models.Benchmark

CollectLabels returns a benchmark from SQL recording labels

Expects rows to be in sorted order by the benchmark group, i.e. recording ID.

func ConnectDb

func ConnectDb() *gorm.DB

ConnectDb returns a gorm database object

func ConnectNewDb

func ConnectNewDb() *pg.DB

ConnectNewDb returns a thread safe db connection

func Decode

func Decode(r io.ReadCloser, v interface{}) error

Decode tries to decode the interface as json

func Encode

func Encode(w http.ResponseWriter, v interface{}, status int)

Encode writes the encoded value

func FindAccount

func FindAccount(db *gorm.DB, username string) (*models.Account, error)

FindAccount returns an account object

func FindTemplate

func FindTemplate(db *gorm.DB, reqTpl string, accountID string) (models.Templates, error)

FindTemplate gets an existing template

func GetAccountQualities

func GetAccountQualities(db *gorm.DB) (*models.AccountQuality, error)

GetAccountQualities loads account quality data from the database

func GetConstraints

func GetConstraints(db *gorm.DB)

GetConstraints gets

func GetRecordingLabels

func GetRecordingLabels(db *gorm.DB, recordingID string, opener int, closer int) (interface{}, error)

GetRecordingLabels retrieves labels for a template

func GetSpectrograms

func GetSpectrograms(db *gorm.DB, window int) (*[]models.Spectrogram, error)

GetSpectrograms returns spectrograms matching the given window

func GetSystemBenchmarkGroup

func GetSystemBenchmarkGroup(db *gorm.DB) (*models.Benchmark, error)

GetSystemBenchmarkGroup returns a benchmark group tied to all users

func GetTables

func GetTables(lbl models.Label) []string

GetTables get the tables for a corresponding label

func GetTemplateLabel

func GetTemplateLabel(db *gorm.DB, templateID string, number int) (interface{}, error)

GetTemplateLabel retrieves labels for a template

func GetUserBenchmarkGroup

func GetUserBenchmarkGroup(db *gorm.DB, acc *models.Account) (*models.Benchmark, error)

GetUserBenchmarkGroup returns a benchmark group If an account is provided, get a group relevant to that user If an account is not provided, get the entire system benchmark that contains user metadata

func IsError

func IsError(err error, constraint DbHTTPErr) bool

IsError checks for database pq errors

func Migrate

func Migrate()

Migrate runs a migration on the database

func ParseErrors

func ParseErrors(err []error, key string) error

ParseErrors parses the database errors

func SetLabelKinds

func SetLabelKinds(lbls []models.Label) error

SetLabelKinds sets the label kinds

func SetLabels

func SetLabels(db *gorm.DB, cl *models.Clip) error

SetLabels sets the labels

func UpdateAccountFeedback

func UpdateAccountFeedback(db *gorm.DB, acc *models.Account, val int) error

UpdateAccountFeedback updates the account feedback column with provided value

Types

type DbHTTPErr

type DbHTTPErr struct {
	Codename    string
	Description string
	HTTPStatus  int
}

DbHTTPErr contains a mapping of database errors with HTTP statuses

type FKViolationAccount

type FKViolationAccount struct {
	AccountID *string
}

FKViolationAccount formats violation info

func (*FKViolationAccount) Error

func (e *FKViolationAccount) Error() string

type FKViolationTemplate

type FKViolationTemplate struct {
	TemplateID string
}

FKViolationTemplate formats violation info

func (*FKViolationTemplate) Error

func (e *FKViolationTemplate) Error() string

type GeneralPqError

type GeneralPqError struct{}

GeneralPqError has violation information

func (*GeneralPqError) Error

func (e *GeneralPqError) Error() string

type MemoryCache

type MemoryCache struct {
	Lock          sync.RWMutex
	ClipIDClipMap map[string]*models.Clip `json:"omitempty"`
	ClipIDSlice   []*string               `json:"omitempty"`
	LblRecMap     map[string]internal.Set `json:"omitempty"`
	RecClipMap    map[string]internal.Set `json:"omitempty"`
	MemSel        memoizedMap
}

MemoryCache represents a memory cache of clips

func NewMemoryCache

func NewMemoryCache() *MemoryCache

NewMemoryCache returns an initialized MemoryCache

func (*MemoryCache) ClipByClipID

func (mc *MemoryCache) ClipByClipID(clipID string) *models.Clip

ClipByClipID gets a clip by clipID

func (*MemoryCache) GetClipSelection

func (mc *MemoryCache) GetClipSelection(lbls []models.TemplateLabel) []*string

GetClipSelection gets the clip selection

func (*MemoryCache) GetRedis

func (mc *MemoryCache) GetRedis() error

GetRedis gets a redis data

func (*MemoryCache) SetRedis

func (mc *MemoryCache) SetRedis() error

SetRedis sets redis data

type UniqueViolationEmail

type UniqueViolationEmail struct {
	Email string
}

UniqueViolationEmail formats violation info

func (*UniqueViolationEmail) Error

func (e *UniqueViolationEmail) Error() string

type UniqueViolationUsername

type UniqueViolationUsername struct {
	Username *string
}

UniqueViolationUsername formats violation info

func (*UniqueViolationUsername) Error

func (e *UniqueViolationUsername) Error() string

Jump to

Keyboard shortcuts

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