protodb

package
v0.0.0-...-6ee0f2d Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2013 License: MIT Imports: 7 Imported by: 0

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

Available database types.

View Source
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.

Available transaction isolation levels.

Variables

View Source
var NoEnvironment = Environment{/* contains filtered or unexported fields */}

Special constant to indicate no environment should be used.

View Source
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.

func (Cursor) Close

func (cur Cursor) Close() (err error)

Close the cursor.

func (Cursor) Del

func (cur Cursor) Del() (err error)

Delete the current record at the cursor.

func (Cursor) First

func (cur Cursor) First(rec proto.Message) (err error)

Retrieve the first record of the database.

func (Cursor) Last

func (cur Cursor) Last(rec proto.Message) (err error)

Retrieve the last record of the database.

func (Cursor) Next

func (cur Cursor) Next(rec proto.Message) (err error)

Retrieve the next record from the cursor.

func (Cursor) Prev

func (cur Cursor) Prev(rec proto.Message) (err error)

Retrieve the previous record from the cursor.

func (Cursor) Set

func (cur Cursor) Set(rec proto.Message, exact bool) (err error)

Retrieve the first record with matching key from the database. If exact is false, the first record with a key greater than or equal to the given one is fetched; this operation mode only makes sense in combination with a B-tree database.

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) Close

func (db Database) Close() (err error)

Close the database.

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

func (db Database) Get(txn Transaction, consume bool, recs ...proto.Message) (err error)

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

func (db Database) Put(txn Transaction, append bool, recs ...proto.Message) (err error)

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 DatabaseType

type DatabaseType int

Type of databases.

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) Close

func (env Environment) Close() (err error)

Close the environment.

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 Errno

type Errno int

Status code implementing the error interface.

func (Errno) Error

func (err Errno) Error() string

Turn a status code into a human readable message.

type IsolationLevel

type IsolationLevel int

Transaction isolation level.

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.

Jump to

Keyboard shortcuts

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