Documentation ¶
Index ¶
- Constants
- Variables
- func Update(db Backend, f func(tx RwTx) error) error
- func View(db Backend, f func(tx RTx) error) error
- type Backend
- func GetBoltBackend(path, name string, noFreeListSync bool) (Backend, error)
- func GetEtcdBackend(ctx context.Context, prefix string, etcdConfig *EtcdConfig) (Backend, error)
- func GetEtcdTestBackend(path, name string) (Backend, func(), error)
- func GetTestBackend(path, name string) (Backend, func(), error)
- type BoltConfig
- type Driver
- type EtcdConfig
- type RBucket
- type RCursor
- type RTx
- type RwBucket
- type RwCursor
- type RwTx
Constants ¶
const BoltBackendName = "bdb"
BoltBackendName is the name of the backend that should be passed into kvdb.Create to initialize a new instance of kvdb.Backend backed by a live instance of bolt.
const DefaultDBTimeout = 60 * time.Second
DefaultDBTimeout is taken from github.com/btcsuite/btcwallet/wallet/loader.go
const EtcdBackendName = "etcd"
EtcdBackendName is the name of the backend that should be passed into kvdb.Create to initialize a new instance of kvdb.Backend backed by a live instance of etcd.
const TestBackend = BoltBackendName
TestBackend is conditionally set to bdb when the kvdb_etcd build tag is not defined, allowing testing our database code with bolt backend.
Variables ¶
var ( // ErrBucketNotFound is returned when trying to access a bucket that // has not been created yet. ErrBucketNotFound = walletdb.ErrBucketNotFound // ErrBucketExists is returned when creating a bucket that already // exists. ErrBucketExists = walletdb.ErrBucketExists // ErrDatabaseNotOpen is returned when a database instance is accessed // before it is opened or after it is closed. ErrDatabaseNotOpen = walletdb.ErrDbNotOpen )
var Batch = walletdb.Batch
Batch is identical to the Update call, but it attempts to combine several individual Update transactions into a single write database transaction on an optimistic basis. This only has benefits if multiple goroutines call Batch.
var Create = walletdb.Create
Create initializes and opens a database for the specified type. The arguments are specific to the database type driver. See the documentation for the database driver for further details.
ErrDbUnknownType will be returned if the database type is not registered.
var Open = walletdb.Open
Open opens an existing database for the specified type. The arguments are specific to the database type driver. See the documentation for the database driver for further details.
ErrDbUnknownType will be returned if the database type is not registered.
Functions ¶
func Update ¶
Update opens a database read/write transaction and executes the function f with the transaction passed as a parameter. After f exits, if f did not error, the transaction is committed. Otherwise, if f did error, the transaction is rolled back. If the rollback fails, the original error returned by f is still returned. If the commit fails, the commit error is returned.
Types ¶
type Backend ¶
Backend represents an ACID database. All database access is performed through read or read+write transactions.
func GetBoltBackend ¶
GetBoltBackend opens (or creates if doesn't exits) a bbolt backed database and returns a kvdb.Backend wrapping it.
func GetEtcdBackend ¶
GetEtcdBackend is a stub returning nil and errEtcdNotAvailable error.
func GetEtcdTestBackend ¶
GetTestEtcdBackend is a stub returning nil, an empty closure and an errEtcdNotAvailable error.
func GetTestBackend ¶
GetTestBackend opens (or creates if doesn't exist) a bbolt or etcd backed database (for testing), and returns a kvdb.Backend and a cleanup func. Whether to create/open bbolt or embedded etcd database is based on the TestBackend constant which is conditionally compiled with build tag. The passed path is used to hold all db files, while the name is only used for bolt.
type BoltConfig ¶
type BoltConfig struct {
SyncFreelist bool `` /* 234-byte string literal not displayed */
}
BoltConfig holds bolt configuration.
type Driver ¶
Driver defines a structure for backend drivers to use when they registered themselves as a backend which implements the Backend interface.
type EtcdConfig ¶
type EtcdConfig struct { Host string `long:"host" description:"Etcd database host."` User string `long:"user" description:"Etcd database user."` Pass string `long:"pass" description:"Password for the database user."` CertFile string `long:"cert_file" description:"Path to the TLS certificate for etcd RPC."` KeyFile string `long:"key_file" description:"Path to the TLS private key for etcd RPC."` InsecureSkipVerify bool `long:"insecure_skip_verify" description:"Whether we intend to skip TLS verification"` CollectStats bool `long:"collect_stats" description:"Whether to collect etcd commit stats."` }
EtcdConfig holds etcd configuration.
type RBucket ¶
type RBucket = walletdb.ReadBucket
RBucket represents a bucket (a hierarchical structure within the database) that is only allowed to perform read operations.
type RCursor ¶
type RCursor = walletdb.ReadCursor
RCursor represents a bucket cursor that can be positioned at the start or end of the bucket's key/value pairs and iterate over pairs in the bucket. This type is only allowed to perform database read operations.
type RTx ¶
RTx represents a database transaction that can only be used for reads. If a database update must occur, use a RwTx.
type RwBucket ¶
type RwBucket = walletdb.ReadWriteBucket
RwBucket represents a bucket (a hierarchical structure within the database) that is allowed to perform both read and write operations.
type RwCursor ¶
type RwCursor = walletdb.ReadWriteCursor
RwCursor represents a bucket cursor that can be positioned at the start or end of the bucket's key/value pairs and iterate over pairs in the bucket. This abstraction is allowed to perform both database read and write operations.
type RwTx ¶
type RwTx = walletdb.ReadWriteTx
ReadWriteTx represents a database transaction that can be used for both reads and writes. When only reads are necessary, consider using a RTx instead.