// Get returns the value for the given key. func (r *RocksDB) Get(key Key) ([]byte, error) { if len(key) == 0 { return nil, emptyKeyError() } var ( cValLen C.size_t cErr *C.char ) cVal := C.rocksdb_get( r.rdb, r.rOpts, bytesPointer(key), C.size_t(len(key)), &cValLen, &cErr) if cErr != nil { return nil, charToErr(cErr) } if cVal == nil { return nil, nil } defer C.free(unsafe.Pointer(cVal)) return C.GoBytes(unsafe.Pointer(cVal), C.int(cValLen)), nil }
// get returns the value for the given key. func (r *RocksDB) get(key Key) (Value, error) { if len(key) == 0 { return Value{}, emptyKeyError() } var ( cValLen C.size_t cErr *C.char ) cVal := C.rocksdb_get( r.rdb, r.rOpts, (*C.char)(unsafe.Pointer(&key[0])), C.size_t(len(key)), &cValLen, &cErr) if cErr != nil { return Value{}, charToErr(cErr) } if cVal == nil { return Value{}, nil } defer C.free(unsafe.Pointer(cVal)) return Value{Bytes: C.GoBytes(unsafe.Pointer(cVal), C.int(cValLen))}, nil }
func (db *DB) Get(opt *ReadOptions, rawKey []byte) ([]byte, error) { var ck = (*C.char)(unsafe.Pointer(&rawKey[0])) var rOpt = db.rOpt if opt != nil && opt.rOpt != nil { rOpt = opt.rOpt } var errStr *C.char var vallen C.size_t var cv = C.rocksdb_get(db.db, rOpt, ck, C.size_t(len(rawKey)), &vallen, &errStr) var err error if errStr != nil { defer C.free(unsafe.Pointer(errStr)) err = errors.New(C.GoString(errStr)) } if cv != nil { defer C.free(unsafe.Pointer(cv)) return C.GoBytes(unsafe.Pointer(cv), C.int(vallen)), err } return nil, err }
// Get returns the data associated with the key from the database. func (db *DB) Get(opts *ReadOptions, key []byte) (*Slice, error) { var cValLen C.size_t var cErr *C.char cValue := C.rocksdb_get( db.c, opts.c, byteToChar(key), C.size_t(len(key)), &cValLen, &cErr) if cErr != nil { return nil, convertErr(cErr) } return newSlice(cValue, cValLen), nil }
// Get returns the data associated with the key from the database. func (db *DB) Get(opts *ReadOptions, key []byte) (*Slice, error) { var ( cErr *C.char cValLen C.size_t cKey = byteToChar(key) ) cValue := C.rocksdb_get(db.c, opts.c, cKey, C.size_t(len(key)), &cValLen, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return nil, errors.New(C.GoString(cErr)) } return NewSlice(cValue, cValLen), nil }
// GetBytes is like Get but returns a copy of the data. func (db *DB) GetBytes(opts *ReadOptions, key []byte) ([]byte, error) { var ( cErr *C.char cValLen C.size_t cKey = byteToChar(key) ) cValue := C.rocksdb_get(db.c, opts.c, cKey, C.size_t(len(key)), &cValLen, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return nil, errors.New(C.GoString(cErr)) } if cValue == nil { return nil, nil } defer C.free(unsafe.Pointer(cValue)) return C.GoBytes(unsafe.Pointer(cValue), C.int(cValLen)), nil }
func (db *DB) getSlice(ro *ReadOptions, key []byte) (driver.ISlice, error) { var errStr *C.char var vallen C.size_t var k *C.char if len(key) != 0 { k = (*C.char)(unsafe.Pointer(&key[0])) } value := C.rocksdb_get( db.db, ro.Opt, k, C.size_t(len(key)), &vallen, &errStr) if errStr != nil { return nil, saveError(errStr) } if value == nil { return nil, nil } return NewCSlice(unsafe.Pointer(value), int(vallen)), nil }
func (db *DB) get(ro *ReadOptions, key []byte) ([]byte, error) { var errStr *C.char var vallen C.size_t var k *C.char if len(key) != 0 { k = (*C.char)(unsafe.Pointer(&key[0])) } value := C.rocksdb_get( db.db, ro.Opt, k, C.size_t(len(key)), &vallen, &errStr) if errStr != nil { return nil, saveError(errStr) } if value == nil { return nil, nil } defer C.free(unsafe.Pointer(value)) return C.GoBytes(unsafe.Pointer(value), C.int(vallen)), nil }