// Fetch ... func (db *Database) Fetch(key []byte) (value []byte, err error) { var n C.unqlite_int64 res := C.unqlite_kv_fetch(db.handle, unsafe.Pointer(&key[0]), C.int(len(key)), nil, &n) if res != C.UNQLITE_OK { err = UnQLiteError(res) return } value = make([]byte, int(n)) res = C.unqlite_kv_fetch(db.handle, unsafe.Pointer(&key[0]), C.int(len(key)), unsafe.Pointer(&value[0]), &n) if res != C.UNQLITE_OK { err = UnQLiteError(res) } return }
// KvFetch a record from the database // See: http://unqlite.org/c_api/unqlite_kv_fetch.html func (u *Unqlite) KvFetch(key []byte) ([]byte, error) { var n C.unqlite_int64 if rc := C.unqlite_kv_fetch(u.db, unsafe.Pointer(&key[0]), C.int(len(key)), nil, &n); rc != C.UNQLITE_OK { return nil, ErrCode(rc) } buf := make([]byte, int64(n)) if rc := C.unqlite_kv_fetch(u.db, unsafe.Pointer(&key[0]), C.int(len(key)), unsafe.Pointer(&buf[0]), &n); rc != C.UNQLITE_OK { return nil, ErrCode(rc) } return buf, nil }
// Fetch retrieves the value for the specified key from the database. func (h *Handle) Fetch(key []byte) (value []byte, err error) { // Fetch size of value. var n C.unqlite_int64 rv := C.unqlite_kv_fetch(h.db, unsafe.Pointer(&key[0]), C.int(len(key)), nil, &n) if rv != C.UNQLITE_OK { return nil, Errno(rv) } // Fetch value. b := make([]byte, int(n)) rv = C.unqlite_kv_fetch(h.db, unsafe.Pointer(&key[0]), C.int(len(key)), unsafe.Pointer(&b[0]), &n) if rv != C.UNQLITE_OK { return nil, Errno(rv) } return b, nil }
func (u *Unqlite) KvFetch(key, value []byte) ([]byte, error) { outlen := C.unqlite_int64(len(value)) e := C.unqlite_kv_fetch(u.db, unsafe.Pointer(&key[0]), C.int(len(key)), unsafe.Pointer(&value[0]), &outlen) err := code2Error(e) n := int(outlen) if n <= 0 { return nil, err } return value[:n], err }