Ejemplo n.º 1
0
// Store inserts or updates a key-value pair in the database.
//
// If the key exists, its value is updated. Otherwise, a new key-value pair is created.
func (h *Handle) Store(key, value []byte) error {
	rv := C.unqlite_kv_store(h.db, unsafe.Pointer(&key[0]), C.int(len(key)), unsafe.Pointer(&value[0]), C.unqlite_int64(len(value)))
	if rv == C.UNQLITE_OK {
		return nil
	}
	return Errno(rv)
}
Ejemplo n.º 2
0
// KvStore write a new record into the database. If the record does not exists, it is created. Otherwise, it is replaced.
// See: http://unqlite.org/c_api/unqlite_kv_store.html
func (u *Unqlite) KvStore(key []byte, value []byte) error {
	if rc := C.unqlite_kv_store(u.db, unsafe.Pointer(&key[0]), C.int(len(key)), unsafe.Pointer(&value[0]), C.unqlite_int64(len(value))); rc != C.UNQLITE_OK {
		return ErrCode(rc)
	}

	return nil
}
Ejemplo n.º 3
0
// Store ...
func (db *Database) Store(key, value []byte) (err error) {
	res := C.unqlite_kv_store(db.handle,
		unsafe.Pointer(&key[0]), C.int(len(key)),
		unsafe.Pointer(&value[0]), C.unqlite_int64(len(value)))
	if res == C.UNQLITE_OK {
		return nil
	}
	return UnQLiteError(res)
}
Ejemplo n.º 4
0
// K-V store
func (u *Unqlite) KvStore(key, value []byte) error {
	var k, v unsafe.Pointer
	if len(key) > 0 {
		k = unsafe.Pointer(&key[0])
	}
	if len(value) > 0 {
		v = unsafe.Pointer(&value[0])
	}
	e := C.unqlite_kv_store(u.db, k, C.int(len(key)), v, C.unqlite_int64(len(value)))
	return code2Error(e)
}