Example #1
0
func (db *DB) Remove(key []byte) error {
	db.lk.Lock()
	defer db.lk.Unlock()

	k := C.str{unsafe.Pointer(&key[0]), C.size_t(len(key))}

	n, err := C.db_del(db.db, &k)

	switch {
	case n < 0:
		return err
	case n > 0:
		return ErrKeyNotFound(string(key))
	}

	return nil
}
Example #2
0
func (db BerkeleyDB) Del(txn Transaction, key []byte, flags DbFlag) error {
	cKey := AllocDBT(key)
	defer cKey.Free()
	return Err(C.db_del(db.ptr, txn.ptr, cKey, C.u_int32_t(flags)))
}
Example #3
-1
// Delete records from the database.
func (db Database) Del(txn Transaction, recs ...proto.Message) (err error) {
	var key C.DBT

	key.flags |= C.DB_DBT_READONLY

	for _, rec := range recs {
		err = db.marshalKey(&key, rec)
		if err != nil {
			return
		}

		err = check(C.db_del(db.ptr, txn.ptr, &key, 0))
		if err != nil {
			return
		}
	}

	return
}