// Put writes data associated with a key to the database. // // If a nil []byte is passed in as value, it will be returned by Get as an // zero-length slice. // // The key and value byte slices may be reused safely. Put takes a copy of // them before returning. func (db *DB) Put(wo *WriteOptions, key, value []byte) error { var errStr *C.char // rocksdb_put, _get, and _delete call memcpy() (by way of Memtable::Add) // when called, so we do not need to worry about these []byte being // reclaimed by GC. var k, v *C.char if len(key) != 0 { k = (*C.char)(unsafe.Pointer(&key[0])) } if len(value) != 0 { v = (*C.char)(unsafe.Pointer(&value[0])) } lenk := len(key) lenv := len(value) C.rocksdb_put( db.Ldb, wo.Opt, k, C.size_t(lenk), v, C.size_t(lenv), &errStr) if errStr != nil { gs := C.GoString(errStr) C.free(unsafe.Pointer(errStr)) return DatabaseError(gs) } return nil }
// put sets the given key to the value provided. // // The key and value byte slices may be reused safely. put takes a copy of // them before returning. func (r *RocksDB) put(key Key, value Value) error { if len(key) == 0 { return emptyKeyError() } // Empty values correspond to a null pointer. valuePointer := (*C.char)(nil) if len(value.Bytes) > 0 { valuePointer = (*C.char)(unsafe.Pointer(&value.Bytes[0])) } // rocksdb_put, _get, and _delete call memcpy() (by way of MemTable::Add) // when called, so we do not need to worry about these byte slices being // reclaimed by the GC. var cErr *C.char C.rocksdb_put( r.rdb, r.wOpts, (*C.char)(unsafe.Pointer(&key[0])), C.size_t(len(key)), valuePointer, C.size_t(len(value.Bytes)), &cErr) if cErr != nil { return charToErr(cErr) } return nil }
// Put writes data associated with a key to the database. func (db *DB) Put(opts *WriteOptions, key, value []byte) error { var ( cErr *C.char cKey = byteToChar(key) cValue = byteToChar(value) ) C.rocksdb_put(db.c, opts.c, cKey, C.size_t(len(key)), cValue, C.size_t(len(value)), &cErr) return convertErr(cErr) }
// Put writes data associated with a key to the database. func (db *DB) Put(opts *WriteOptions, key, value []byte) error { var ( cErr *C.char cKey = byteToChar(key) cValue = byteToChar(value) ) C.rocksdb_put(db.c, opts.c, cKey, C.size_t(len(key)), cValue, C.size_t(len(value)), &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
func (db *DB) put(wo *WriteOptions, key, value []byte) error { var errStr *C.char var k, v *C.char if len(key) != 0 { k = (*C.char)(unsafe.Pointer(&key[0])) } if len(value) != 0 { v = (*C.char)(unsafe.Pointer(&value[0])) } lenk := len(key) lenv := len(value) C.rocksdb_put( db.db, wo.Opt, k, C.size_t(lenk), v, C.size_t(lenv), &errStr) if errStr != nil { return saveError(errStr) } return nil }
// Put sets the given key to the value provided. // // The key and value byte slices may be reused safely. put takes a copy of // them before returning. func (r *RocksDB) Put(key Key, value []byte) error { if len(key) == 0 { return emptyKeyError() } // rocksdb_put, _get, and _delete call memcpy() (by way of MemTable::Add) // when called, so we do not need to worry about these byte slices being // reclaimed by the GC. var cErr *C.char C.rocksdb_put( r.rdb, r.wOpts, bytesPointer(key), C.size_t(len(key)), bytesPointer(value), C.size_t(len(value)), &cErr) if cErr != nil { return charToErr(cErr) } return nil }
func (db *DB) Put(rawKey, value []byte, wb *WriteBatch) error { var ck, cv *C.char if len(rawKey) > 0 { ck = (*C.char)(unsafe.Pointer(&rawKey[0])) } if len(value) > 0 { cv = (*C.char)(unsafe.Pointer(&value[0])) } if wb == nil { var errStr *C.char C.rocksdb_put(db.db, db.wOpt, ck, C.size_t(len(rawKey)), cv, C.size_t(len(value)), &errStr) if errStr != nil { defer C.free(unsafe.Pointer(errStr)) return errors.New(C.GoString(errStr)) } } else { C.rocksdb_writebatch_put(wb.batch, ck, C.size_t(len(rawKey)), cv, C.size_t(len(value))) } return nil }