Exemplo n.º 1
0
// Walk the DB from a specific location.
func (db *Couchstore) Walk(startkey string, callback WalkFun) error {
	startc := C.CString(startkey)
	defer C.freecstring(startc)
	e := C.start_all_docs(db.db,
		startc, unsafe.Pointer(&callback))
	if e != C.COUCHSTORE_ERROR_CANCEL && e != C.COUCHSTORE_SUCCESS {
		return couchError(e)
	}
	return nil
}
Exemplo n.º 2
0
func (db *Couchstore) getDocInfo(id string) (*DocInfo, error) {
	var inf *C.DocInfo
	idstr := C.CString(id)
	defer C.freecstring(idstr)
	err := maybeError(C.couchstore_docinfo_by_id(db.db,
		unsafe.Pointer(idstr), _Ctype_size_t(len(id)), &inf))
	if err == nil {
		rv := &DocInfo{*inf, inf}
		runtime.SetFinalizer(rv, freeDocInfo)
		return rv, nil
	}
	return &DocInfo{}, err
}
Exemplo n.º 3
0
// Open a database.
func Open(pathname string, create bool) (*Couchstore, error) {
	rv := &Couchstore{}
	flags := _Ctype_couchstore_open_flags(0)
	if create {
		flags = C.COUCHSTORE_OPEN_FLAG_CREATE
	}
	cstr := C.CString(pathname)
	defer C.freecstring(cstr)
	err := maybeError(C.couchstore_open_db(cstr, flags, &rv.db))
	if err == nil {
		rv.isOpen = true
	} else {
		rv = nil
	}

	return rv, err
}
Exemplo n.º 4
0
// Compact this DB to a new file.
func (db *Couchstore) CompactTo(newfile string) error {
	cstr := C.CString(newfile)
	defer C.freecstring(cstr)
	return maybeError(C.couchstore_compact_db(db.db, cstr))
}
Exemplo n.º 5
0
// Free doc made from go.
func freeMyDoc(doc *Document) {
	C.freecstring(doc.doc.id.buf)
}
Exemplo n.º 6
0
// Free docinfo made from go.
func freeMyDocInfo(info *DocInfo) {
	C.freecstring(info.info.id.buf)
}