Documentation ¶
Overview ¶
Package kc provides types, methods and functions to interact with an Kyoto Cabinet database.
It's just a binding to the Kyoto Cabinet C library, so make sure you have installed Kyoto Cabinet in your system.
Index ¶
- Constants
- type ApplyFunc
- type ApplyResult
- type DB
- func (d *DB) Append(key, value string) error
- func (d *DB) Apply(f ApplyFunc, args ...interface{})
- func (d *DB) AsyncApply(f ApplyFunc, args ...interface{}) Waiter
- func (d *DB) BeginTransaction(hard bool) error
- func (d *DB) Clear() error
- func (d *DB) Close()
- func (d *DB) Commit() error
- func (d *DB) CompareAndSwap(key, old, new string) error
- func (d *DB) Count() (int, error)
- func (d *DB) Get(key string) (string, error)
- func (d *DB) GetGob(key string, e interface{}) error
- func (d *DB) GetInt(key string) (int, error)
- func (d *DB) Increment(key string, number int) (int, error)
- func (d *DB) LastError() error
- func (d *DB) MatchPrefix(prefix string, max int64) ([]string, error)
- func (d *DB) MatchRegex(regex string, max int64) ([]string, error)
- func (d *DB) Remove(key string) error
- func (d *DB) Rollback() error
- func (d *DB) Set(key, value string) error
- func (d *DB) SetGob(key string, e interface{}) error
- func (d *DB) SetInt(key string, number int) error
- func (d *DB) Size() (int64, error)
- type KCError
- type Waiter
Constants ¶
const ( READ WRITE )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ApplyFunc ¶
type ApplyFunc func(key string, value interface{}, args ...interface{})
ApplyFunc, function used as parameter to the Apply and AsyncApply methods. The function receives three parameters:
key: the record key value: the record value args: extra arguments passed to Apply method
type ApplyResult ¶
type ApplyResult struct {
// contains filtered or unexported fields
}
func NewApplyResult ¶
func NewApplyResult() *ApplyResult
func (*ApplyResult) Wait ¶
func (r *ApplyResult) Wait()
type DB ¶
type DB struct { // Path to the database file. Path string // contains filtered or unexported fields }
DB is the basic type for the gokabinet library. Holds an unexported instance of the database, for interactions.
func Open ¶
Open opens a database.
There are constants for the modes: READ and WRITE.
READ indicates read-only access to the database, and WRITE indicates read and write access to the database (there is no write-only mode).
func (*DB) Append ¶
Append appends a string to the end of the value of a string record. It can't append any value to a numeric record.
Returns a KCError instance when trying to append a string to a numeric record and when trying to append a string in read-only mode.
If the append is successful, the method returns nil.
func (*DB) Apply ¶
Applies a function to all records in the database
The function is called with the key and the value as parameters. All extra arguments passed to Apply are used in the call to f
func (*DB) AsyncApply ¶
Similar to Apply, but asynchronous. Returns a Waiter object, so you can wait for the applying to finish
func (*DB) BeginTransaction ¶
BeginTransaction begins a new transaction. It accepts a boolean flag that indicates whether the transaction should be hard or not. A hard transaction is a transaction that provides physical synchronization in the device, while a non-hard transaction provides logical synchronization with the file system.
func (*DB) Clear ¶
Clear removes all records from the database.
Returns a KCError in case of failure.
func (*DB) Close ¶
func (d *DB) Close()
Close closes the database, make sure you always call this method after using the database.
You can do it using the defer statement:
db := Open("my_db.kch", WRITE) defer db.Close()
func (*DB) CompareAndSwap ¶
CompareAndSwap performs a compare-and-swap operation, receiving three parameters: key, old and new.
If the value corresponding to key is equal to old, then it is set to new. If the operation fails, this method returns a non-nil error.
func (*DB) Get ¶
Get retrieves a record in the database by its key.
Returns the string value and nil in case of success, in case of errors, return a zero-valued string and an KCError instance (including when the key doesn't exist in the database).
func (*DB) GetGob ¶
GetGob gets a record in the database by its key, decoding from gob format.
Returns nil in case of success. In case of errors, it returns a KCError instance explaining what happened.
func (*DB) GetInt ¶
GetInt gets a numeric record from the database.
In case of errors (e.g.: when the given key refers to a non-numeric record), returns 0 and a KCError instance.
func (*DB) Increment ¶
Increment increments the value of a numeric record by a given number, and return the incremented value.
In case of errors, returns 0 and a KCError instance with detailed error message.
func (*DB) LastError ¶
LastError returns a KCError instance representing the last occurred error in the database.
func (*DB) MatchPrefix ¶
MatchPrefix returns a list of keys that matches a prefix or an error in case of failure.
func (*DB) MatchRegex ¶
MatchRegex returns a list of keys that matches a regular expression string or an error in case of failure.
func (*DB) Remove ¶
Remove removes a record from the database by its key.
Returns a KCError instance if there is no record for the given key, or in case of other errors. The error instance contains a message describing what happened
func (*DB) Set ¶
Set adds a record to the database. Currently, it's able to store only string values.
Returns a KCError instance in case of errors, otherwise, returns nil.
func (*DB) SetGob ¶
SetGob adds a record to the database, stored in gob format.
Returns a KCError instance in case of errors, otherwise, returns nil.