Ejemplo n.º 1
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.º 2
0
// Append ...
func (db *Database) Append(key, value []byte) (err error) {
	res := C.unqlite_kv_append(db.handle,
		unsafe.Pointer(&key[0]), C.int(len(key)),
		unsafe.Pointer(&value[0]), C.unqlite_int64(len(value)))
	if res != C.UNQLITE_OK {
		err = UnQLiteError(res)
	}
	return
}
Ejemplo n.º 3
0
func (u *Unqlite) KvFetch(key, value []byte) ([]byte, error) {
	outlen := C.unqlite_int64(len(value))
	e := C.unqlite_kv_fetch(u.db, unsafe.Pointer(&key[0]), C.int(len(key)), unsafe.Pointer(&value[0]), &outlen)
	err := code2Error(e)
	n := int(outlen)
	if n <= 0 {
		return nil, err
	}
	return value[:n], err
}
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)
}
Ejemplo n.º 5
0
//get data from the cursor, data can be nil
func (c *Cursor) Data(data []byte) ([]byte, error) {
	var v unsafe.Pointer
	outlen := C.unqlite_int64(len(data))
	if outlen == 0 {
		e := C.unqlite_kv_cursor_data(c.c, nil, &outlen)
		if e != C.UNQLITE_OK {
			return nil, code2Error(e)
		}
		data = make([]byte, outlen)
	}
	v = unsafe.Pointer(&data[0])
	e := C.unqlite_kv_cursor_data(c.c, v, &outlen)
	if e != C.UNQLITE_OK {
		return nil, code2Error(e)
	}
	return data[:outlen], code2Error(e)
}
Ejemplo n.º 6
0
// KvStore write a new record into the database. If the record does not exists, it is created. Otherwise, the new data chunk is appended to the end of the old chunk.
// See: http://unqlite.org/c_api/unqlite_kv_append.html
func (u *Unqlite) KvAppend(key []byte, value []byte) error {
	if rc := C.unqlite_kv_append(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.º 7
0
// Append appends value to the key-value pair in the database.
func (h *Handle) Append(key, value []byte) error {
	rv := C.unqlite_kv_append(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.º 8
0
func (c *Context) Int64(i64 int64) error {
	e := C.unqlite_result_int64(c.c, C.unqlite_int64(i64))
	return code2Error(e)
}
Ejemplo n.º 9
0
func (v *Value) Int64(i64 int64) error {
	e := C.unqlite_value_int64(v.v, C.unqlite_int64(i64))
	return code2Error(e)
}