database

package
v0.18.1 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidFilter = errors.New("invalid filter")

TODO(patrik): Move

View Source
var ErrInvalidSort = errors.New("invalid sort")
View Source
var ErrItemAlreadyExists = errors.New("database: item already exists")
View Source
var ErrItemNotFound = errors.New("database: item not found")

Functions

func AlbumQuery added in v0.16.2

func AlbumQuery() *goqu.SelectDataset

func ApiTokenQuery added in v0.18.0

func ApiTokenQuery() *goqu.SelectDataset

func ArtistQuery added in v0.16.2

func ArtistQuery() *goqu.SelectDataset

func FeaturingArtistsQuery added in v0.18.0

func FeaturingArtistsQuery(table, idColName string) *goqu.SelectDataset

TODO(patrik): Move

func InvalidFilter added in v0.18.0

func InvalidFilter(err error) error

func InvalidSort added in v0.18.0

func InvalidSort(err error) error

func PlaylistQuery added in v0.18.0

func PlaylistQuery() *goqu.SelectDataset

func RunMigrateUp added in v0.14.0

func RunMigrateUp(db *Database) error

func TagQuery added in v0.16.2

func TagQuery() *goqu.SelectDataset

func TrackMapNameToId added in v0.11.0

func TrackMapNameToId(typ string, name string) string

func TrackQuery added in v0.13.0

func TrackQuery() *goqu.SelectDataset

TODO(patrik): Use goqu.T more

func UserQuery added in v0.18.0

func UserQuery() *goqu.SelectDataset

func UserSettingsQuery added in v0.18.0

func UserSettingsQuery() *goqu.SelectDataset

Types

type Album

type Album struct {
	Id        string         `db:"id"`
	Name      string         `db:"name"`
	OtherName sql.NullString `db:"other_name"`

	ArtistId string `db:"artist_id"`

	CoverArt sql.NullString `db:"cover_art"`
	Year     sql.NullInt64  `db:"year"`

	ArtistName      string         `db:"artist_name"`
	ArtistOtherName sql.NullString `db:"artist_other_name"`

	Created int64 `db:"created"`
	Updated int64 `db:"updated"`

	Tags sql.NullString `db:"tags"`

	FeaturingArtists FeaturingArtists `db:"featuring_artists"`
}

type AlbumChanges added in v0.7.0

type AlbumChanges struct {
	Name      types.Change[string]
	OtherName types.Change[sql.NullString]

	ArtistId types.Change[string]

	CoverArt types.Change[sql.NullString]
	Year     types.Change[sql.NullInt64]

	Created types.Change[int64]
}

type ApiToken added in v0.18.0

type ApiToken struct {
	Id     string `db:"id"`
	UserId string `db:"user_id"`

	Name string `db:"name"`

	Created int64 `db:"created"`
	Updated int64 `db:"updated"`
}

type Artist

type Artist struct {
	Id        string         `db:"id"`
	Name      string         `db:"name"`
	OtherName sql.NullString `db:"other_name"`

	Picture sql.NullString `db:"picture"`

	Created int64 `db:"created"`
	Updated int64 `db:"updated"`

	Tags sql.NullString `db:"tags"`
}

type ArtistChanges added in v0.7.0

type ArtistChanges struct {
	Name      types.Change[string]
	OtherName types.Change[sql.NullString]
	Picture   types.Change[sql.NullString]

	Created types.Change[int64]
}

type ArtistSearch added in v0.18.0

type ArtistSearch struct {
	Id   string `json:"id"`
	Name string `json:"name"`
}

type Connection added in v0.10.0

type Connection interface {
	Query(query string, args ...any) (*sql.Rows, error)
	QueryRow(query string, args ...any) *sql.Row
	Exec(query string, args ...any) (sql.Result, error)
}

type CreateAlbumParams

type CreateAlbumParams struct {
	Id        string
	Name      string
	OtherName sql.NullString

	ArtistId string

	CoverArt sql.NullString
	Year     sql.NullInt64

	Created int64
	Updated int64
}

type CreateApiTokenParams added in v0.18.0

type CreateApiTokenParams struct {
	Id     string
	UserId string
	Name   string

	Created int64
	Updated int64
}

type CreateArtistParams

type CreateArtistParams struct {
	Id        string
	Name      string
	OtherName sql.NullString

	Picture sql.NullString

	Created int64
	Updated int64
}

type CreatePlaylistParams added in v0.10.0

type CreatePlaylistParams struct {
	Id      string
	Name    string
	Picture sql.NullString

	OwnerId string

	Created int64
	Updated int64
}

type CreateTaglistParams added in v0.18.0

type CreateTaglistParams struct {
	Name    string
	Filter  string
	OwnerId string

	Created int64
	Updated int64
}

type CreateTrackParams

type CreateTrackParams struct {
	Id        string
	Name      string
	OtherName sql.NullString

	AlbumId  string
	ArtistId string

	Duration int64
	Number   sql.NullInt64
	Year     sql.NullInt64

	OriginalFilename string
	MobileFilename   string

	Created int64
	Updated int64
}

type CreateUserParams added in v0.18.0

type CreateUserParams struct {
	Id       string
	Username string
	Password string
	Role     string

	Created int64
	Updated int64
}

type Database added in v0.6.0

type Database struct {
	NewRawConn *sqlx.DB
	RawConn    *sql.DB
	Conn       Connection
}

func New

func New(conn *sql.DB) *Database

func Open added in v0.10.0

func Open(workDir types.WorkDir) (*Database, error)

func (*Database) AddFeaturingArtistToAlbum added in v0.18.0

func (db *Database) AddFeaturingArtistToAlbum(ctx context.Context, albumId, artistId string) error

TODO(patrik): Generalize

func (*Database) AddFeaturingArtistToTrack added in v0.18.0

func (db *Database) AddFeaturingArtistToTrack(ctx context.Context, trackId, artistId string) error

TODO(patrik): Generalize

func (*Database) AddItemToPlaylist added in v0.18.0

func (db *Database) AddItemToPlaylist(ctx context.Context, playlistId, trackId string) error

func (*Database) AddTagToAlbum added in v0.18.0

func (db *Database) AddTagToAlbum(ctx context.Context, tagSlug, albumId string) error

TODO(patrik): Generalize TODO(patrik): Rename to AddAlbumTag, same with track

func (*Database) AddTagToArtist added in v0.18.0

func (db *Database) AddTagToArtist(ctx context.Context, tagSlug, artistId string) error

TODO(patrik): Generalize TODO(patrik): Rename to AddArtistTag, same with track

func (*Database) AddTagToTrack added in v0.8.0

func (db *Database) AddTagToTrack(ctx context.Context, tagSlug, trackId string) error

func (*Database) Begin added in v0.10.0

func (db *Database) Begin() (*Database, *sqlx.Tx, error)

func (*Database) CreateAlbum added in v0.6.0

func (db *Database) CreateAlbum(ctx context.Context, params CreateAlbumParams) (Album, error)

func (*Database) CreateApiToken added in v0.18.0

func (db *Database) CreateApiToken(ctx context.Context, params CreateApiTokenParams) (ApiToken, error)

func (*Database) CreateArtist added in v0.6.0

func (db *Database) CreateArtist(ctx context.Context, params CreateArtistParams) (Artist, error)

func (*Database) CreatePlaylist added in v0.10.0

func (db *Database) CreatePlaylist(ctx context.Context, params CreatePlaylistParams) (Playlist, error)

func (*Database) CreateTag added in v0.8.0

func (db *Database) CreateTag(ctx context.Context, slug string) error

func (*Database) CreateTaglist added in v0.18.0

func (db *Database) CreateTaglist(ctx context.Context, params CreateTaglistParams) (Taglist, error)

func (*Database) CreateTrack added in v0.6.0

func (db *Database) CreateTrack(ctx context.Context, params CreateTrackParams) (string, error)

func (*Database) CreateUser added in v0.10.0

func (db *Database) CreateUser(ctx context.Context, params CreateUserParams) (User, error)

func (*Database) Exec added in v0.6.0

func (db *Database) Exec(ctx context.Context, s ToSQL) (sql.Result, error)

func (*Database) Get added in v0.16.2

func (db *Database) Get(dest any, s ToSQL) error

func (*Database) GetAlbumById added in v0.6.0

func (db *Database) GetAlbumById(ctx context.Context, id string) (Album, error)

func (*Database) GetAlbumByName added in v0.10.0

func (db *Database) GetAlbumByName(ctx context.Context, name string) (Album, error)

func (*Database) GetAlbumsByArtist added in v0.6.0

func (db *Database) GetAlbumsByArtist(ctx context.Context, artistId string) ([]Album, error)

func (*Database) GetAllAlbums added in v0.6.0

func (db *Database) GetAllAlbums(ctx context.Context, filterStr string, sortStr string) ([]Album, error)

func (*Database) GetAllApiTokensForUser added in v0.18.0

func (db *Database) GetAllApiTokensForUser(ctx context.Context, userId string) ([]ApiToken, error)

func (*Database) GetAllArtists added in v0.6.0

func (db *Database) GetAllArtists(ctx context.Context, filterStr, sortStr string) ([]Artist, error)

func (*Database) GetAllTags added in v0.9.0

func (db *Database) GetAllTags(ctx context.Context) ([]Tag, error)

func (*Database) GetAllTracks added in v0.6.0

func (db *Database) GetAllTracks(ctx context.Context, filterStr, sortStr string) ([]Track, error)

func (*Database) GetAllUsers added in v0.12.0

func (db *Database) GetAllUsers(ctx context.Context) ([]User, error)

func (*Database) GetApiTokenById added in v0.18.0

func (db *Database) GetApiTokenById(ctx context.Context, id string) (ApiToken, error)

func (*Database) GetArtistById added in v0.6.0

func (db *Database) GetArtistById(ctx context.Context, id string) (Artist, error)

func (*Database) GetArtistByName added in v0.8.0

func (db *Database) GetArtistByName(ctx context.Context, name string) (Artist, error)

func (*Database) GetPagedTracks added in v0.18.0

func (db *Database) GetPagedTracks(ctx context.Context, opts FetchOption) ([]Track, types.Page, error)

func (*Database) GetPlaylistById added in v0.10.0

func (db *Database) GetPlaylistById(ctx context.Context, id string) (Playlist, error)

func (*Database) GetPlaylistItems added in v0.10.0

func (db *Database) GetPlaylistItems(ctx context.Context, playlistId string) ([]PlaylistItem, error)

func (*Database) GetPlaylistTracks added in v0.16.2

func (db *Database) GetPlaylistTracks(ctx context.Context, playlistId string) ([]Track, error)

func (*Database) GetPlaylistsByUser added in v0.10.0

func (db *Database) GetPlaylistsByUser(ctx context.Context, userId string) ([]Playlist, error)

func (*Database) GetTagBySlug added in v0.16.2

func (db *Database) GetTagBySlug(ctx context.Context, slug string) (Tag, error)

func (*Database) GetTaglistById added in v0.18.0

func (db *Database) GetTaglistById(ctx context.Context, id string) (Taglist, error)

func (*Database) GetTaglistByUser added in v0.18.0

func (db *Database) GetTaglistByUser(ctx context.Context, userId string) ([]Taglist, error)

func (*Database) GetTrackById added in v0.6.0

func (db *Database) GetTrackById(ctx context.Context, id string) (Track, error)

func (*Database) GetTrackByNameAndAlbum added in v0.11.0

func (db *Database) GetTrackByNameAndAlbum(ctx context.Context, name string, albumId string) (Track, error)

func (*Database) GetTracksByAlbum added in v0.6.0

func (db *Database) GetTracksByAlbum(ctx context.Context, albumId string) ([]Track, error)

func (*Database) GetUserById added in v0.10.0

func (db *Database) GetUserById(ctx context.Context, id string) (User, error)

func (*Database) GetUserByUsername added in v0.10.0

func (db *Database) GetUserByUsername(ctx context.Context, username string) (User, error)

func (*Database) GetUserSettingsById added in v0.18.0

func (db *Database) GetUserSettingsById(ctx context.Context, id string) (UserSettings, error)

func (*Database) InitializeSearch added in v0.18.0

func (db *Database) InitializeSearch() error

func (*Database) Query added in v0.6.0

func (db *Database) Query(ctx context.Context, s ToSQL) (*sql.Rows, error)

func (*Database) QueryRow added in v0.6.0

func (db *Database) QueryRow(ctx context.Context, s ToSQL) (*sql.Row, error)

func (*Database) RefillSearchTables added in v0.18.0

func (db *Database) RefillSearchTables(ctx context.Context) error

func (*Database) RemoveAlbum added in v0.16.2

func (db *Database) RemoveAlbum(ctx context.Context, id string) error

func (*Database) RemoveAlbumTracks added in v0.16.2

func (db *Database) RemoveAlbumTracks(ctx context.Context, albumId string) error

func (*Database) RemoveAllAlbumFeaturingArtists added in v0.18.0

func (db *Database) RemoveAllAlbumFeaturingArtists(ctx context.Context, albumId string) error

TODO(patrik): Generalize

func (*Database) RemoveAllTagsFromAlbum added in v0.18.0

func (db *Database) RemoveAllTagsFromAlbum(ctx context.Context, albumId string) error

TODO(patrik): Generalize TODO(patrik): Rename to RemoveAllAlbumTags, same with track

func (*Database) RemoveAllTagsFromArtist added in v0.18.0

func (db *Database) RemoveAllTagsFromArtist(ctx context.Context, artistId string) error

TODO(patrik): Generalize TODO(patrik): Rename to RemoveAllArtistTags, same with track

func (*Database) RemoveAllTagsFromTrack added in v0.16.2

func (db *Database) RemoveAllTagsFromTrack(ctx context.Context, trackId string) error

func (*Database) RemoveAllTrackFeaturingArtists added in v0.18.0

func (db *Database) RemoveAllTrackFeaturingArtists(ctx context.Context, trackId string) error

TODO(patrik): Generalize

func (*Database) RemoveApiToken added in v0.18.0

func (db *Database) RemoveApiToken(ctx context.Context, id string) error

func (*Database) RemovePlaylistItem added in v0.18.0

func (db *Database) RemovePlaylistItem(ctx context.Context, playlistId, trackId string) error

func (*Database) RemoveTaglist added in v0.18.0

func (db *Database) RemoveTaglist(ctx context.Context, id string) error

func (*Database) RemoveTrack added in v0.16.2

func (db *Database) RemoveTrack(ctx context.Context, id string) error

func (*Database) RunMigrateDown added in v0.16.2

func (db *Database) RunMigrateDown() error

func (*Database) RunMigrateUp added in v0.16.2

func (db *Database) RunMigrateUp() error

func (*Database) SearchAlbums added in v0.18.0

func (db *Database) SearchAlbums(searchQuery string) ([]Album, error)

func (*Database) SearchArtists added in v0.18.0

func (db *Database) SearchArtists(searchQuery string) ([]Artist, error)

func (*Database) SearchTracks added in v0.18.0

func (db *Database) SearchTracks(searchQuery string) ([]Track, error)

func (*Database) Select added in v0.16.2

func (db *Database) Select(dest any, s ToSQL) error

func (*Database) UpdateAlbum added in v0.7.0

func (db *Database) UpdateAlbum(ctx context.Context, id string, changes AlbumChanges) error

func (*Database) UpdateArtist added in v0.7.0

func (db *Database) UpdateArtist(ctx context.Context, id string, changes ArtistChanges) error

func (*Database) UpdateTaglist added in v0.18.0

func (db *Database) UpdateTaglist(ctx context.Context, id string, changes TaglistChanges) error

func (*Database) UpdateTrack added in v0.6.0

func (db *Database) UpdateTrack(ctx context.Context, id string, changes TrackChanges) error

func (*Database) UpdateUser added in v0.17.0

func (db *Database) UpdateUser(ctx context.Context, id string, changes UserChanges) error

func (*Database) UpdateUserSettings added in v0.18.0

func (db *Database) UpdateUserSettings(ctx context.Context, settings UserSettings) error

type FeaturingArtist added in v0.18.0

type FeaturingArtist struct {
	Id        string  `json:"id"`
	Name      string  `json:"name"`
	OtherName *string `json:"other_name"`
}

type FeaturingArtists added in v0.18.0

type FeaturingArtists []FeaturingArtist

func (*FeaturingArtists) Scan added in v0.18.0

func (v *FeaturingArtists) Scan(value any) error

func (FeaturingArtists) Value added in v0.18.0

func (s FeaturingArtists) Value() (driver.Value, error)

type FetchOption added in v0.18.0

type FetchOption struct {
	Filter  string
	Sort    string
	PerPage int
	Page    int
}

TODO(patrik): Move

type Playlist added in v0.10.0

type Playlist struct {
	Id      string         `db:"id"`
	Name    string         `db:"name"`
	Picture sql.NullString `db:"picture"`

	OwnerId string `db:"owner_id"`

	Created string `db:"created"`
	Updated string `db:"updated"`
}

type PlaylistItem added in v0.10.0

type PlaylistItem struct {
	PlaylistId string `db:"playlist_id"`
	TrackId    string `db:"track_id"`
}

type Tag added in v0.8.0

type Tag struct {
	Slug string `db:"slug"`
}

type Taglist added in v0.18.0

type Taglist struct {
	Id     string `db:"id"`
	Name   string `db:"name"`
	Filter string `db:"filter"`

	OwnerId string `db:"owner_id"`

	Created int64 `db:"created"`
	Updated int64 `db:"updated"`
}

type TaglistChanges added in v0.18.0

type TaglistChanges struct {
	Name   types.Change[string]
	Filter types.Change[string]

	Created types.Change[int64]
}

type ToSQL added in v0.6.0

type ToSQL interface {
	ToSQL() (string, []interface{}, error)
}

type Track

type Track struct {
	Id        string         `db:"id"`
	Name      string         `db:"name"`
	OtherName sql.NullString `db:"other_name"`

	AlbumId  string `db:"album_id"`
	ArtistId string `db:"artist_id"`

	Duration int64         `db:"duration"`
	Number   sql.NullInt64 `db:"number"`
	Year     sql.NullInt64 `db:"year"`

	OriginalFilename string `db:"original_filename"`
	MobileFilename   string `db:"mobile_filename"`

	AlbumName      string         `db:"album_name"`
	AlbumOtherName sql.NullString `db:"album_other_name"`
	AlbumCoverArt  sql.NullString `db:"album_cover_art"`

	ArtistName      string         `db:"artist_name"`
	ArtistOtherName sql.NullString `db:"artist_other_name"`

	Created int64 `db:"created"`
	Updated int64 `db:"updated"`

	Tags sql.NullString `db:"tags"`

	FeaturingArtists FeaturingArtists `db:"featuring_artists"`
}

type TrackChanges added in v0.7.0

type TrackChanges struct {
	Name      types.Change[string]
	OtherName types.Change[sql.NullString]

	AlbumId  types.Change[string]
	ArtistId types.Change[string]

	Duration types.Change[int64]
	Number   types.Change[sql.NullInt64]
	Year     types.Change[sql.NullInt64]

	OriginalFilename types.Change[string]
	MobileFilename   types.Change[string]

	Created types.Change[int64]
}

type TrackSearch added in v0.18.0

type TrackSearch struct {
	Id     string `json:"id"`
	Name   string `json:"name"`
	Artist string `json:"artist"`
	Album  string `json:"album"`
	Tags   string `json:"tags"`
}

type User added in v0.10.0

type User struct {
	Id       string `db:"id"`
	Username string `db:"username"`
	Password string `db:"password"`
	Role     string `db:"role"`

	Created int64 `db:"created"`
	Updated int64 `db:"updated"`

	// NOTE(patrik): This needs to match UserSettings
	DisplayName   sql.NullString `db:"display_name"`
	QuickPlaylist sql.NullString `db:"quick_playlist"`
}

func (User) ToUserSettings added in v0.18.0

func (u User) ToUserSettings() UserSettings

type UserChanges added in v0.17.0

type UserChanges struct {
	Username types.Change[string]
	Password types.Change[string]

	Created types.Change[int64]
}

type UserSettings added in v0.18.0

type UserSettings struct {
	Id            string         `db:"id"`
	DisplayName   sql.NullString `db:"display_name"`
	QuickPlaylist sql.NullString `db:"quick_playlist"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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