Documentation ¶
Overview ¶
A binding to Berkeley DB storing records encoded as Protocol Buffers.
The records you use should have a single optional field called key that holds the key for the record; this field can be of any protobuf serializable message type or, if you plan to store the records in a numbered or queue database, it should hold an unsigned 32-bit integer.
Index ¶
- Constants
- Variables
- type Cursor
- func (cur Cursor) Close() (err error)
- func (cur Cursor) Del() (err error)
- func (cur Cursor) First(rec proto.Message) (err error)
- func (cur Cursor) Last(rec proto.Message) (err error)
- func (cur Cursor) Next(rec proto.Message) (err error)
- func (cur Cursor) Prev(rec proto.Message) (err error)
- func (cur Cursor) Set(rec proto.Message, exact bool) (err error)
- type Database
- func (db Database) Close() (err error)
- func (db Database) Cursor(txn Transaction) (cur Cursor, err error)
- func (db Database) Del(txn Transaction, recs ...proto.Message) (err error)
- func (db Database) Get(txn Transaction, consume bool, recs ...proto.Message) (err error)
- func (db Database) Put(txn Transaction, append bool, recs ...proto.Message) (err error)
- func (db Database) Type() (dbtype DatabaseType, err error)
- type DatabaseConfig
- type DatabaseType
- type Environment
- type EnvironmentConfig
- type Errno
- type IsolationLevel
- type NumberedTestRecord
- type TestRecord
- type TestRecord_Key
- type Transaction
- type TransactionConfig
Constants ¶
const ( BTree = DatabaseType(C.DB_BTREE) Hash = DatabaseType(C.DB_HASH) Numbered = DatabaseType(C.DB_RECNO) Queue = DatabaseType(C.DB_QUEUE) Unknown = DatabaseType(C.DB_UNKNOWN) )
Available database types.
const ( ErrAgain = Errno(C.EAGAIN) ErrInvalid = Errno(C.EINVAL) ErrNoEntry = Errno(C.ENOENT) ErrExists = Errno(C.EEXIST) ErrAccess = Errno(C.EACCES) ErrNoSpace = Errno(C.ENOSPC) ErrPermission = Errno(C.EPERM) ErrRunRecovery = Errno(C.DB_RUNRECOVERY) ErrVersionMismatch = Errno(C.DB_VERSION_MISMATCH) ErrOldVersion = Errno(C.DB_OLD_VERSION) ErrLockDeadlock = Errno(C.DB_LOCK_DEADLOCK) ErrLockNotGranted = Errno(C.DB_LOCK_NOTGRANTED) ErrBufferTooSmall = Errno(C.DB_BUFFER_SMALL) ErrSecondaryBad = Errno(C.DB_SECONDARY_BAD) ErrForeignConflict = Errno(C.DB_FOREIGN_CONFLICT) ErrKeyExists = Errno(C.DB_KEYEXIST) ErrKeyEmpty = Errno(C.DB_KEYEMPTY) ErrNotFound = Errno(C.DB_NOTFOUND) )
Status codes representing common errors.
const ( ReadCommitted = IsolationLevel(C.DB_READ_COMMITTED) ReadUncommitted = IsolationLevel(C.DB_READ_UNCOMMITTED) Snapshot = IsolationLevel(C.DB_TXN_SNAPSHOT) )
Available transaction isolation levels.
Variables ¶
var NoEnvironment = Environment{/* contains filtered or unexported fields */}
Special constant to indicate no environment should be used.
var NoTransaction = Transaction{/* contains filtered or unexported fields */}
Special constant indicating no transaction should be used.
Functions ¶
This section is empty.
Types ¶
type Cursor ¶
type Cursor struct {
// contains filtered or unexported fields
}
Database cursor.
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database.
func OpenDatabase ¶
func OpenDatabase(env Environment, txn Transaction, file string, config *DatabaseConfig) (db Database, err error)
Open a database in the given file and environment.
func (Database) Cursor ¶
func (db Database) Cursor(txn Transaction) (cur Cursor, err error)
Obtain a cursor over the database.
func (Database) Del ¶
func (db Database) Del(txn Transaction, recs ...proto.Message) (err error)
Delete records from the database.
func (Database) Get ¶
Get records from the database. The consume flag makes sense only in combination with a queue database and causes the operation to wait for and obtain the next enqueued record.
func (Database) Put ¶
Store records in the database. In combination with a queue or numbered database the append flags causes the keys of the records to be set to fresh record numbers, for any other database it prevents an existing record with the same key from being overwritten.
func (Database) Type ¶
func (db Database) Type() (dbtype DatabaseType, err error)
Get the type of the database.
type DatabaseConfig ¶
type DatabaseConfig struct { Create bool // Create the database, if necessary. Mode os.FileMode // File creation mode for the database. Password string // Encryption password or an empty string. Name string // Identifier of the database inside the file. Type DatabaseType // Type of database to create ReadUncommitted bool // Enable support for read-uncommitted isolation. Snapshot bool // Enable support for snapshot isolation. }
Database configuration.
type Environment ¶
type Environment struct {
// contains filtered or unexported fields
}
Database environment.
func OpenEnvironment ¶
func OpenEnvironment(home string, config *EnvironmentConfig) (env Environment, err error)
Open an environment at the given home path.
func (Environment) WithTransaction ¶
func (env Environment) WithTransaction(config *TransactionConfig, action func(Transaction) error) (err error)
Perform an operation within a transaction. The transaction is automatically committed if the action doesn't return an error. If an error occurs, the transaction is automatically aborted. Any error is passed through to the caller.
type EnvironmentConfig ¶
type EnvironmentConfig struct { Create bool // Create the environment, if necessary. Mode os.FileMode // File creation mode for the environment. Password string // Encryption password or an empty string. Recover bool // Run recovery on the environment, if necessary. Transactional bool // Enable transactions in the environment. NoSync bool // Do not flush to log when committing. WriteNoSync bool // Do not flush log when committing. }
Database environment configuration.
type NumberedTestRecord ¶
type NumberedTestRecord struct { Key *uint32 `protobuf:"fixed32,1,opt,name=key" json:"key,omitempty"` Val *string `protobuf:"bytes,2,req,name=val" json:"val,omitempty"` XXX_unrecognized []byte `json:"-"` }
func (*NumberedTestRecord) GetKey ¶
func (this *NumberedTestRecord) GetKey() uint32
func (*NumberedTestRecord) GetVal ¶
func (this *NumberedTestRecord) GetVal() string
func (*NumberedTestRecord) ProtoMessage ¶
func (*NumberedTestRecord) ProtoMessage()
func (*NumberedTestRecord) Reset ¶
func (this *NumberedTestRecord) Reset()
func (*NumberedTestRecord) String ¶
func (this *NumberedTestRecord) String() string
type TestRecord ¶
type TestRecord struct { Key *TestRecord_Key `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"` Val *string `protobuf:"bytes,2,req,name=val" json:"val,omitempty"` XXX_unrecognized []byte `json:"-"` }
func (*TestRecord) GetKey ¶
func (this *TestRecord) GetKey() *TestRecord_Key
func (*TestRecord) GetVal ¶
func (this *TestRecord) GetVal() string
func (*TestRecord) ProtoMessage ¶
func (*TestRecord) ProtoMessage()
func (*TestRecord) Reset ¶
func (this *TestRecord) Reset()
func (*TestRecord) String ¶
func (this *TestRecord) String() string
type TestRecord_Key ¶
type TestRecord_Key struct { Val *string `protobuf:"bytes,1,req,name=val" json:"val,omitempty"` XXX_unrecognized []byte `json:"-"` }
func (*TestRecord_Key) GetVal ¶
func (this *TestRecord_Key) GetVal() string
func (*TestRecord_Key) ProtoMessage ¶
func (*TestRecord_Key) ProtoMessage()
func (*TestRecord_Key) Reset ¶
func (this *TestRecord_Key) Reset()
func (*TestRecord_Key) String ¶
func (this *TestRecord_Key) String() string
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
Transaction in a database environment.
type TransactionConfig ¶
type TransactionConfig struct { Parent Transaction // Parent transaction. Isolation IsolationLevel // Transaction isolation level. Bulk bool // Optimize for bulk insertions. NoWait bool // Fail instead of waiting for locks. NoSync bool // Do not flush to log when committing. WriteNoSync bool // Do not flush log when committing. }
Transaction configuration.