Documentation ¶
Index ¶
- type DB
- type DataBase
- func (idb DataBase) Close() error
- func (idb DataBase) Delete(key string) error
- func (db *DataBase) DeleteBucket(name string) error
- func (db *DataBase) Destroy() error
- func (db *DataBase) Exists(key string) bool
- func (idb DataBase) Get(key string) (raw []byte, err error)
- func (db *DataBase) Map() (all map[string][]byte, err error)
- func (idb DataBase) Path() string
- func (idb DataBase) Put(key string, val []byte) error
- func (db *DataBase) ResetTimeStamp(key string) error
- func (db *DataBase) SetBucket(name string)
- func (db *DataBase) TimeStamp(key string) (time.Time, error)
- func (db *DataBase) UpdateTS(key string, updater Updater) error
- func (db *DataBase) WithBucket(bucket string) *DataBase
- type Deleter
- type FullDB
- type Getter
- type MapDB
- type Putter
- type Storage
- type TimeStamper
- type TimerDB
- type Updater
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB interface { Get(string) ([]byte, error) Put(string, []byte) error Delete(string) error Path() string Close() error }
DB is an interface that represents a database wrapper.
type DataBase ¶
type DataBase struct {
// contains filtered or unexported fields
}
DataBase is a wrapper struct for boltdb key-value pair database.
Example ¶
package main import ( "fmt" "log" "github.com/harrybrwn/apizza/pkg/cache" "github.com/harrybrwn/apizza/pkg/tests" ) func main() { // open the database db, err := cache.GetDB(tests.TempFile()) if err != nil { log.Fatal(err) } defer func() { if err = db.Close(); err != nil { log.Fatal(err) } }() if err = db.Put("key", []byte("some string of values")); err != nil { log.Fatal(err) } data, err := db.Get("key") if err != nil { log.Fatal(err) } fmt.Println(string(data)) if err = db.Destroy(); err != nil { panic(err) } }
Output: some string of values
func GetDB ¶
GetDB returns an initialized DataBase. Will either create a brand new boltdb or open existing one.
func (DataBase) Close ¶
func (idb DataBase) Close() error
Close will close the DataBase's inner bolt.DB
func (*DataBase) DeleteBucket ¶
DeleteBucket will delete the bucket given.
Will panic if the name argument is the same as the database's default bucket.
func (*DataBase) ResetTimeStamp ¶
ResetTimeStamp stores a new timestamp for the given key.
func (*DataBase) TimeStamp ¶
TimeStamp gets the timestamp for a given key and will also create one if it does not already exist.
func (*DataBase) UpdateTS ¶
UpdateTS or "UpdateTimeStamp" will execute an Updater's methods in correspondence with the database's timestamp at the key given
func (*DataBase) WithBucket ¶
WithBucket temporarily sets the bucket to the string given and returns the database with the new bucket.
The default bucket will be reset when the database calls Put, Get, Exists, Map, TimeStamp, and UpdateTS (any method that calls view or update internally).
type TimeStamper ¶
TimeStamper defines objects that support named timestamps.
type TimerDB ¶
type TimerDB interface { DB TimeStamper }
TimerDB is an interface that defines a database that can store timestamps.