예제 #1
0
파일: cluster.go 프로젝트: rayleyva/fdb-go
// OpenDatabase returns a database handle from the FoundationDB cluster. It is
// generally preferable to use Open or OpenDefault to obtain a database handle
// directly.
//
// In the current release, the database name must be "DB".
func (c Cluster) OpenDatabase(dbName []byte) (Database, error) {
	f := C.fdb_cluster_create_database(c.ptr, byteSliceToPtr(dbName), C.int(len(dbName)))
	fdb_future_block_until_ready(f)

	var outd *C.FDBDatabase

	if err := C.fdb_future_get_database(f, &outd); err != 0 {
		return Database{}, Error(err)
	}

	C.fdb_future_destroy(f)

	d := &database{outd}
	runtime.SetFinalizer(d, (*database).destroy)

	return Database{d}, nil
}
예제 #2
0
파일: fdb.go 프로젝트: rayleyva/fdb-go
func createCluster(clusterFile string) (Cluster, error) {
	var cf *C.char

	if len(clusterFile) != 0 {
		cf = C.CString(clusterFile)
	}

	f := C.fdb_create_cluster(cf)
	fdb_future_block_until_ready(f)

	var outc *C.FDBCluster

	if err := C.fdb_future_get_cluster(f, &outc); err != 0 {
		return Cluster{}, Error(err)
	}

	C.fdb_future_destroy(f)

	c := &cluster{outc}
	runtime.SetFinalizer(c, (*cluster).destroy)

	return Cluster{c}, nil
}
예제 #3
0
func newFuture(ptr *C.FDBFuture) *future {
	f := &future{ptr}
	runtime.SetFinalizer(f, func(f *future) { C.fdb_future_destroy(f.ptr) })
	return f
}
예제 #4
0
파일: futures.go 프로젝트: rayleyva/fdb-go
func (f *future) destroy() {
	C.fdb_future_destroy(f.ptr)
}