Ejemplo n.º 1
0
// Stores data for a specified key. Any existing data for the key will be replaced.
// If `data` is nil, then the key will be deleted if it exists in the database.
func (d *Database) Store(key, data []byte) {
	dkey := toDatum(key)
	if data == nil {
		C.gdbm_delete(d.dbf, dkey)
	} else {
		C.gdbm_store(d.dbf, dkey, toDatum(data), C.GDBM_REPLACE)
	}
}
Ejemplo n.º 2
0
func (d *gdbm) Store(keydata, valuedata []byte) error {
	key := toDatum(keydata)
	if valuedata == nil {
		C.gdbm_delete(d.dbf, key)
		return nil
	}
	value := toDatum(valuedata)
	C.gdbm_store(d.dbf, key, value, C.GDBM_REPLACE)
	return nil
}
Ejemplo n.º 3
0
// Removes a key-value pair from the database. If the database is opened in "r"
// mode, an error is returned
func (db *Database) Delete(key string) (err error) {
	kcs := C.CString(key)
	k := C.mk_datum(kcs)
	defer C.free(unsafe.Pointer(kcs))

	retv := C.gdbm_delete(db.dbf, k)
	if retv == -1 && db.mode == C.GDBM_READER {
		err = lastError()
	}
	return err
}