Example #1
0
// 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
}
Example #2
0
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
}
Example #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
}
Example #4
0
func (f *future) destroy() {
	C.fdb_future_destroy(f.ptr)
}