options

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// The database table name for options.
	TableName = "options"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Repository

type Repository interface {
	Map() (domain.OptionsDBMap, error)
	Struct() domain.Options
	Find(name string) (interface{}, error)
	Insert(options domain.OptionsDBMap) error
	Create(name string, value interface{}) error
	Update(name string, value interface{}) error
	GetTheme() (string, error)
	SetTheme(theme string) error
	Exists(name string) bool
}

Repository defines methods for options to interact with the database.

type Store

type Store struct {
	*config.Config
}

Store defines the data layer for options.

func New

func New(cfg *config.Config) *Store

New

Creates a new options store.

func (*Store) Create

func (s *Store) Create(name string, value interface{}) error

Create

Returns a nil upon creation. Returns errors.INTERNAL if the SQL query was invalid or the function could not get the newly created ID.

func (*Store) Exists

func (s *Store) Exists(name string) bool

Exists

Returns a bool indicating if the option exists by name. Logs errors.INTERNAL if there was an error executing the query.

func (*Store) Find

func (s *Store) Find(name string) (interface{}, error)

Find

Returns a option by searching with the given name. Returns errors.INTERNAL if there was an error executing the query. Returns errors.NOTFOUND if the option was not found by the given name.

func (*Store) GetTheme

func (s *Store) GetTheme() (string, error)

GetTheme

Returns the currently active theme within the options table if it has been retrieved successfully. Returns errors.NOTFOUND if the 'active_theme' column could not be found. Returns errors.INVALID if the option value could not be successfully parsed to a string.

func (*Store) Insert

func (s *Store) Insert(options domain.OptionsDBMap) error

Insert

Updates or creates a new option depending on if it already exists in the database.

func (*Store) Map

func (s *Store) Map() (domain.OptionsDBMap, error)

Map

Returns options as a map. Returns errors.INTERNAL if the SQL query was invalid. Returns errors.NOTFOUND if there are no options available.

func (*Store) SetTheme

func (s *Store) SetTheme(theme string) error

SetTheme

Returns nil if the theme has been updated successfully.

func (*Store) Struct

func (s *Store) Struct() domain.Options

Struct

Returns the options struct for use in the API. Logs errors.INTERNAL and panics if any condition failed.

func (*Store) Update

func (s *Store) Update(name string, value interface{}) error

Update

Returns a nil upon successful update. Returns errors.INTERNAL if the SQL query was invalid.

Jump to

Keyboard shortcuts

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