db

package
v0.0.0-...-7b353df Latest Latest
Warning

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

Go to latest
Published: May 15, 2018 License: BSD-3-Clause Imports: 24 Imported by: 0

Documentation

Overview

Package db contains all interfaces to the databases used by Ponzu, including exported functions to easily manage addons, users, indices, search, content, and configuration.

Index

Constants

View Source
const (
	// DefaultMaxAge provides a 2592000 second (30-day) cache max-age setting
	DefaultMaxAge = int64(60 * 60 * 24 * 30)
)

Variables

View Source
var (
	// ErrNoAddonExists indicates that there was not addon found in the db
	ErrNoAddonExists = errors.New("No addon exists.")
)
View Source
var ErrNoUserExists = errors.New("Error. No user exists.")

ErrNoUserExists is used for the db to report to admin user of non-existing user

View Source
var ErrUserExists = errors.New("Error. User exists.")

ErrUserExists is used for the db to report to admin user of existing user

Functions

func AddBucket

func AddBucket(name string)

AddBucket adds a bucket to be created if it doesn't already exist

func Addon

func Addon(key string) ([]byte, error)

Addon looks for an addon by its addon_reverse_dns as the key and returns the []byte as json representation of an addon

func AddonAll

func AddonAll() [][]byte

AddonAll returns all registered addons as a [][]byte

func AddonExists

func AddonExists(key string) bool

AddonExists checks if there is an existing addon stored. The key is an the value at addon_reverse_dns

func Backup

func Backup(ctx context.Context, res http.ResponseWriter) error

Backup writes a snapshot of the system.db database to an HTTP response. The output is discarded if we get a cancellation signal.

func CacheControl

func CacheControl(next http.Handler) http.HandlerFunc

CacheControl sets the default cache policy on static asset responses

func Close

func Close()

Close exports the abillity to close our db file. Should be called with defer after call to Init() from the same place.

func Config

func Config(key string) ([]byte, error)

Config gets the value of a key in the configuration from the db

func ConfigAll

func ConfigAll() ([]byte, error)

ConfigAll gets the configuration from the db

func ConfigCache

func ConfigCache(key string) interface{}

ConfigCache is a in-memory cache of the Configs for quicker lookups 'key' is the JSON tag associated with the config field

func Content

func Content(target string) ([]byte, error)

Content retrives one item from the database. Non-existent values will return an empty []byte The `target` argument is a string made up of namespace:id (string:int)

func ContentAll

func ContentAll(namespace string) [][]byte

ContentAll retrives all items from the database within the provided namespace

func ContentBySlug

func ContentBySlug(slug string) (string, []byte, error)

ContentBySlug does a lookup in the content index to find the type and id of the requested content. Subsequently, issues the lookup in the type bucket and returns the the type and data at that ID or nil if nothing exists.

func ContentMulti

func ContentMulti(targets []string) ([][]byte, error)

ContentMulti returns a set of content based on the the targets / identifiers provided in Ponzu target string format: Type:ID NOTE: All targets should be of the same type

func CurrentUser

func CurrentUser(req *http.Request) ([]byte, error)

CurrentUser extracts the user from the request data and returns the current user from the db

func DeleteAddon

func DeleteAddon(key string) error

DeleteAddon removes an addon from the db by its key, the addon_reverse_dns

func DeleteContent

func DeleteContent(target string) error

DeleteContent removes an item from the database. Deleting a non-existent item will return a nil error.

func DeleteIndex

func DeleteIndex(namespace, key string) error

DeleteIndex removes the key and value from the namespace provided and will return an error if it fails. It will return nil if there was no key/value in the index to delete.

func DeleteUpload

func DeleteUpload(target string) error

DeleteUpload removes the value for an upload at its key id, based on the target provided i.e. __uploads:{id}

func DeleteUser

func DeleteUser(email string) error

DeleteUser deletes a user from the db by email

func DropIndex

func DropIndex(namespace string) error

DropIndex removes the index and all key/value pairs in the namespace index

func Index

func Index(namespace, key string) ([]byte, error)

Index gets the value from the namespace at the key provided

func Init

func Init()

Init creates a db connection, initializes db with required info, sets secrets

func InitSearchIndex

func InitSearchIndex()

InitSearchIndex initializes Search Index for search to be functional This was moved out of db.Init and put to main(), because addon checker was initializing db together with search indexing initialisation in time when there were no item.Types defined so search index was always empty when using addons. We still have no guarentee whatsoever that item.Types is defined Should be called from a goroutine after SetContent is successful (SortContent requirement)

func InvalidateCache

func InvalidateCache() error

InvalidateCache sets a new Etag for http responses

func IsValidID

func IsValidID(id string) bool

IsValidID checks that an ID from a DB target is valid. ID should be an integer greater than 0. ID of -1 is special for new posts, not updates. IDs start at 1 for auto-incrementing

func LoadCacheConfig

func LoadCacheConfig() error

LoadCacheConfig loads the config into a cache to be accessed by ConfigCache()

func NewEtag

func NewEtag() string

NewEtag generates a new Etag for response caching

func PutConfig

func PutConfig(key string, value interface{}) error

PutConfig updates a single k/v in the config

func Query

func Query(namespace string, opts QueryOptions) (int, [][]byte)

Query retrieves a set of content from the db based on options and returns the total number of content in the namespace and the content

func RecoveryKey

func RecoveryKey(email string) (string, error)

RecoveryKey gets a previously set recovery key to verify an email address submitted in order to recover/reset an account password

func SetAddon

func SetAddon(data url.Values, kind interface{}) error

SetAddon stores the values of an addon into the __addons bucket with a the `addon_reverse_dns` field used as the key. `kind` is the interface{} type for the provided addon (as in the result of calling addon.Types[id])

func SetConfig

func SetConfig(data url.Values) error

SetConfig sets key:value pairs in the db for configuration settings

func SetContent

func SetContent(target string, data url.Values) (int, error)

SetContent inserts/replaces values in the database. The `target` argument is a string made up of namespace:id (string:int)

func SetIndex

func SetIndex(namespace, key string, value interface{}) error

SetIndex sets a key/value pair within the namespace provided and will return an error if it fails

func SetRecoveryKey

func SetRecoveryKey(email string) (string, error)

SetRecoveryKey generates and saves a random secret key to verify an email address submitted in order to recover/reset an account password

func SetUpload

func SetUpload(target string, data url.Values) (int, error)

SetUpload stores information about files uploaded to the system

func SetUser

func SetUser(usr *user.User) (int, error)

SetUser sets key:value pairs in the db for user settings

func SortContent

func SortContent(namespace string)

SortContent sorts all content of the type supplied as the namespace by time, in descending order, from most recent to least recent Should be called from a goroutine after SetContent is successful

func Store

func Store() *bolt.DB

Store provides access to the underlying *bolt.DB store

func SystemInitComplete

func SystemInitComplete() bool

SystemInitComplete checks if there is at least 1 admin user in the db which would indicate that the system has been configured to the minimum required.

func UpdateContent

func UpdateContent(target string, data url.Values) (int, error)

UpdateContent updates/merges values in the database. The `target` argument is a string made up of namespace:id (string:int)

func UpdateUser

func UpdateUser(usr, updatedUsr *user.User) error

UpdateUser sets key:value pairs in the db for existing user settings

func Upload

func Upload(target string) ([]byte, error)

Upload returns the value for an upload by its target (__uploads:{id})

func UploadAll

func UploadAll() [][]byte

UploadAll returns a [][]byte containing all upload data from the system

func UploadBySlug

func UploadBySlug(slug string) ([]byte, error)

UploadBySlug returns the value for an upload by its slug

func User

func User(email string) ([]byte, error)

User gets the user by email from the db

func UserAll

func UserAll() ([][]byte, error)

UserAll returns all users from the db

Types

type QueryOptions

type QueryOptions struct {
	Count  int
	Offset int
	Order  string
}

QueryOptions holds options for a query

Jump to

Keyboard shortcuts

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