Skip to content

Commit

Permalink
- Removed unused 'options' from the db
Browse files Browse the repository at this point in the history
- Added the ability to construct the db from the native handle
- Added added pinned version of GetCF
  • Loading branch information
02p01r committed Mar 26, 2020
1 parent f0fad39 commit c63f8b6
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions db.go
Expand Up @@ -20,7 +20,10 @@ type Range struct {
type DB struct {
c *C.rocksdb_t
name string
opts *Options
}

func NewDBFromNative(db_native *C.rocksdb_t, name_optional string) *DB {
return &DB{c: db_native, name: name_optional}
}

// OpenDb opens a database with the specified options.
Expand All @@ -38,7 +41,6 @@ func OpenDb(opts *Options, name string) (*DB, error) {
return &DB{
name: name,
c: db,
opts: opts,
}, nil
}

Expand All @@ -57,7 +59,6 @@ func OpenDbWithTTL(opts *Options, name string, ttl int) (*DB, error) {
return &DB{
name: name,
c: db,
opts: opts,
}, nil
}

Expand All @@ -76,7 +77,6 @@ func OpenDbForReadOnly(opts *Options, name string, errorIfLogFileExist bool) (*D
return &DB{
name: name,
c: db,
opts: opts,
}, nil
}

Expand Down Expand Up @@ -135,7 +135,6 @@ func OpenDbColumnFamilies(
return &DB{
name: name,
c: db,
opts: opts,
}, cfHandles, nil
}

Expand Down Expand Up @@ -197,7 +196,6 @@ func OpenDbForReadOnlyColumnFamilies(
return &DB{
name: name,
c: db,
opts: opts,
}, cfHandles, nil
}

Expand Down Expand Up @@ -286,6 +284,20 @@ func (db *DB) GetCF(opts *ReadOptions, cf *ColumnFamilyHandle, key []byte) (*Sli
return NewSlice(cValue, cValLen), nil
}

// GetCF returns the data associated with the key from the database and column family.
func (db *DB) GetCFPinned(opts *ReadOptions, cf *ColumnFamilyHandle, key []byte) (*PinnableSliceHandle, error) {
var (
cErr *C.char
cKey = byteToChar(key)
)
cRet := C.rocksdb_get_pinned_cf(db.c, opts.c, cf.c, cKey, C.size_t(len(key)), &cErr)
if cErr != nil {
defer C.rocksdb_free(unsafe.Pointer(cErr))
return nil, errors.New(C.GoString(cErr))
}
return NewNativePinnableSliceHandle(cRet), nil
}

// GetPinned returns the data associated with the key from the database.
func (db *DB) GetPinned(opts *ReadOptions, key []byte) (*PinnableSliceHandle, error) {
var (
Expand Down

0 comments on commit c63f8b6

Please sign in to comment.