private static void SetupKeyspace() { using (var db = new CassandraContext(keyspace: keyspaceName, server: server)) { if (!db.KeyspaceExists(keyspaceName)) { db.AddKeyspace(new KsDef { Name = keyspaceName, Replication_factor = 1, Strategy_class = "org.apache.cassandra.locator.SimpleStrategy", Cf_defs = new List <CfDef>() }); } if (!db.Keyspace.ColumnFamilyExists("Posts")) { db.AddColumnFamily(new CfDef { Name = "Posts", Keyspace = keyspaceName, Column_type = "Super", Comparator_type = "UTF8Type", Subcomparator_type = "UTF8Type", Comment = "Used for blog posts." }); } } }
public void ColumnFamilyTest() { string keyspaceName = Guid.NewGuid().ToString().Replace("-", string.Empty); string ConnString = string.Format(Constant.ConnectionString, keyspaceName); CassandraContext Db = new CassandraContext(new ConnectionBuilder(ConnString)); //创建Keyspace Db.Keyspace.TryCreateSelf(); string familyName = Guid.NewGuid().ToString().Replace("-", string.Empty); //创建Column Family Db.AddColumnFamily(new Apache.Cassandra.CfDef { Name = familyName, Keyspace = keyspaceName }); //或者使用 Keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema(type.Name)); Assert.AreEqual(true, Db.ColumnFamilyExists(familyName)); //删除 Column Family Db.TryDropColumnFamily(familyName); Assert.AreEqual(false, Db.ColumnFamilyExists(familyName)); Db.TryDropKeyspace(keyspaceName); Assert.AreEqual(false, Db.KeyspaceExists(keyspaceName)); }
private static void SetupKeyspace() { using (var db = new CassandraContext(keyspace: keyspaceName, server: server)) { if (!db.KeyspaceExists(keyspaceName)) db.AddKeyspace(new KsDef { Name = keyspaceName, Replication_factor = 1, Strategy_class = "org.apache.cassandra.locator.SimpleStrategy", Cf_defs = new List<CfDef>() }); if (!db.Keyspace.ColumnFamilyExists("Posts")) db.AddColumnFamily(new CfDef { Name = "Posts", Keyspace = keyspaceName, Column_type = "Super", Comparator_type = "UTF8Type", Subcomparator_type = "UTF8Type", Comment = "Used for blog posts." }); } }