Documentation
¶
Overview ¶
Package bbolt provides a Hord database driver for BoltDB.
BoltDB is an embedded key-value database that persists data on disk. To use this driver, import it as follows:
import ( "github.com/tarmac-project/hord" "github.com/tarmac-project/hord/bbolt" )
Connecting to the Database ¶
Use the Dial() function to create a new client for interacting with BoltDB.
var db hord.Database db, err := bbolt.Dial(bbolt.Config{}) if err != nil { // Handle connection error }
Initialize database ¶
Hord provides a Setup() function for preparing a database. This function is safe to execute after every Dial().
err := db.Setup() if err != nil { // Handle setup error }
Database Operations ¶
Hord provides a simple abstraction for working with BoltDB, with easy-to-use methods such as Get() and Set() to read and write values.
// Connect to the BoltDB database db, err := bbolt.Dial(bbolt.Config{}) if err != nil { // Handle connection error } err := db.Setup() if err != nil { // Handle setup error } // Set a value err = db.Set("key", []byte("value")) if err != nil { // Handle error } // Retrieve a value value, err := db.Get("key") if err != nil { // Handle error }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // Bucketname specifies the bucket to store and retrieve data from. Bucketname string // Filename specifies the file path of the bbolt file. Filename string // Permissions specifies the file permissions for the bbolt database file. Permissions os.FileMode // Timeout specifies the timeout duration for opening obtaining a file lock on the database file. // Default value is 5 Seconds, a value of 0 is invalid. Timeout time.Duration }
Config represents the configuration for the bbolt database.
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database is an bbolt implementation of the hord.Database interface.
func (*Database) Close ¶
func (db *Database) Close()
Close closes the bbolt database connection and clears all stored data.
func (*Database) Delete ¶
Delete removes data from the bbolt database based on the provided key. It returns an error if the key is invalid.
func (*Database) Get ¶
Get retrieves data from the bbolt database based on the provided key. It returns the data associated with the key or an error if the key is invalid or the data does not exist.
func (*Database) HealthCheck ¶
HealthCheck performs a health check on the bbolt database.