1 module fdb.cluster; 2 3 import 4 std.conv, 5 std.exception, 6 std.string; 7 8 import 9 fdb.database, 10 fdb.disposable, 11 fdb.error, 12 fdb.fdb_c, 13 fdb.future; 14 15 shared class Cluster : IDisposable 16 { 17 private ClusterHandle ch; 18 19 private Database[] databases; 20 21 this(ClusterHandle ch) 22 in 23 { 24 enforce(ch !is null, "ch must be set"); 25 } 26 body 27 { 28 this.ch = cast(shared)ch; 29 } 30 31 ~this() 32 { 33 dispose; 34 } 35 36 void dispose() 37 { 38 if (!ch) return; 39 40 fdb_cluster_destroy(cast(ClusterHandle)ch); 41 ch = null; 42 } 43 44 auto openDatabase(const string dbName = "DB") 45 out (result) 46 { 47 assert(result !is null); 48 } 49 body 50 { 51 auto fh = fdb_cluster_create_database( 52 cast(ClusterHandle)ch, 53 dbName.toStringz(), 54 cast(int)dbName.length); 55 scope auto future = createFuture!VoidFuture(fh); 56 future.await; 57 58 DatabaseHandle dbh; 59 auto err = fdb_future_get_database(fh, &dbh); 60 enforceError(err); 61 62 auto db = new shared Database(dbh, this); 63 synchronized (this) 64 databases ~= db; 65 return db; 66 } 67 }