Ejemplo n.º 1
0
func (db *LevelDB) Delete(key []byte) error {
	var err *C.char
	C.leveldb_delete(db.db, db.writeOpts.Opts, C.CString(string(key)), C.size_t(len(key)),
		&err)
	if err != nil {
		e := &DBError{}
		e.Err = C.GoString(err)
		return e
	}
	return nil
}
Ejemplo n.º 2
0
func (db *DB) delete(wo *WriteOptions, key []byte) error {
	var errStr *C.char
	var k *C.char
	if len(key) != 0 {
		k = (*C.char)(unsafe.Pointer(&key[0]))
	}

	C.leveldb_delete(
		db.db, wo.Opt, k, C.size_t(len(key)), &errStr)

	if errStr != nil {
		return saveError(errStr)
	}
	return nil
}
Ejemplo n.º 3
0
func (ldb *Db) Delete(key []byte, w_options *Writeoptions) error {
	var db_err *C.char

	key_len := len(key)
	if key_len == 0 {
		return ldb_error("key must not empty")
	}

	key_c := (*C.char)(unsafe.Pointer(&key[0]))
	C.leveldb_delete(ldb.ldb, w_options.options, key_c, C.size_t(key_len), &db_err)
	if db_err != nil {
		return ldb_error(C.GoString(db_err))
	}

	return nil
}
Ejemplo n.º 4
0
// Delete removes the data associated with the key from the database.
//
// The key byte slice may be reused safely. Delete takes a copy of
// them before returning.
func (db *DB) Delete(wo *WriteOptions, key []byte) error {
	var errStr *C.char
	var k *C.char
	if len(key) != 0 {
		k = (*C.char)(unsafe.Pointer(&key[0]))
	}

	C.leveldb_delete(
		db.Ldb, wo.Opt, k, C.size_t(len(key)), &errStr)

	if errStr != nil {
		gs := C.GoString(errStr)
		C.free(unsafe.Pointer(errStr))
		return DatabaseError(gs)
	}
	return nil
}
func (db *LevelDB) Delete(key string) (err error) {
	opt := C.leveldb_writeoptions_create() // write option
	defer C.leveldb_free(unsafe.Pointer(opt))

	k := C.CString(key) // copy
	defer C.leveldb_free(unsafe.Pointer(k))

	var cerr *C.char
	C.leveldb_delete(db.CLevelDB, opt, k, C.size_t(len(key)), &cerr)

	if cerr != nil {
		defer C.leveldb_free(unsafe.Pointer(cerr))
		return errors.New(C.GoString(cerr))
	}

	return
}