예제 #1
0
파일: db.go 프로젝트: daaku/gorocksdb
// ListCFs lists the names of the column families in the DB.
func ListCFs(opts *Options, name string) ([]string, error) {
	cName := C.CString(name)
	defer C.free(unsafe.Pointer(cName))
	var cLen C.size_t
	var cErr *C.char
	cNames := C.rocksdb_list_column_families(opts.c, cName, &cLen, &cErr)
	if cErr != nil {
		return nil, convertErr(cErr)
	}
	namesLen := int(cLen)
	names := make([]string, namesLen)
	cNamesArr := (*[1 << 30]*C.char)(unsafe.Pointer(cNames))[:namesLen:namesLen]
	for i, n := range cNamesArr {
		names[i] = C.GoString(n)
	}
	C.rocksdb_list_column_families_destroy(cNames, cLen)
	return names, nil
}
예제 #2
0
파일: cfam.go 프로젝트: rdallman/gorocksdb
// ListColumnFamilies lists all the column families in the database specified at name.
func ListColumnFamilies(dbOpts *Options, name string) ([]string, error) {
	var len C.size_t
	var cErr *C.char
	cname := C.CString(name)
	defer C.free(unsafe.Pointer(cname))
	cfs := C.rocksdb_list_column_families(dbOpts.c, cname, &len, &cErr)
	if cErr != nil {
		defer C.free(unsafe.Pointer(cErr))
		return nil, errors.New(C.GoString(cErr))
	}

	hdr := reflect.SliceHeader{Data: uintptr(unsafe.Pointer(cfs)), Len: int(len), Cap: int(len)}
	cfSlice := *(*[]*C.char)(unsafe.Pointer(&hdr))

	names := make([]string, int(len))
	for i, nameChar := range cfSlice {
		names[i] = string(C.GoString(nameChar))
	}
	C.rocksdb_list_column_families_destroy(cfs, len)
	return names, nil
}