Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

some much needed refactoring of the schema

  • Loading branch information...
commit 4526a65b9864de37481145d4071b17b9e2a075cf 1 parent 2ba33bc
@nberardi nberardi authored
View
8 src/BaseCassandraColumnFamily.cs
@@ -71,6 +71,14 @@ public bool IsPartOfFamily(IFluentBaseColumnFamily family)
public abstract void ClearCachedColumnFamilySchema();
/// <summary>
+ ///
+ /// </summary>
+ public void TryCreateSelf()
+ {
+ Context.Keyspace.TryCreateColumnFamily(GetSchema());
+ }
+
+ /// <summary>
/// Removes all the rows from the given column family.
/// </summary>
public void RemoveAllRows()
View
21 src/CassandraColumnFamily.cs
@@ -35,25 +35,12 @@ public FluentColumnFamily CreateRecord(CassandraType key)
public override CassandraColumnFamilySchema GetSchema()
{
- var def = Context.Keyspace.GetColumnFamilyDescription(FamilyName);
-
- if (def == null && _cachedSchema == null)
- _cachedSchema = new CassandraColumnFamilySchema();
+ var schema = Context.Keyspace.GetColumnFamilySchema(FamilyName);
if (_cachedSchema == null)
- {
- _cachedSchema = new CassandraColumnFamilySchema();
-
- var keyType = CassandraType.GetCassandraType(def.Key_validation_class);
- var colNameType = CassandraType.GetCassandraType(def.Default_validation_class);
-
- _cachedSchema.FamilyName = FamilyName;
- _cachedSchema.KeyType = keyType;
- _cachedSchema.Columns = def.Column_metadata.Select(col => new CassandraColumnSchema {
- Name = CassandraType.GetTypeFromDatabaseValue(col.Name, colNameType),
- ValueType = CassandraType.GetCassandraType(col.Validation_class)
- }).ToList();
- }
+ _cachedSchema = (schema == null)
+ ? new CassandraColumnFamilySchema(FamilyName, ColumnType.Standard)
+ : schema;
return _cachedSchema;
}
View
51 src/CassandraColumnFamilySchema.cs
@@ -1,31 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using Apache.Cassandra;
using FluentCassandra.Types;
namespace FluentCassandra
{
public class CassandraColumnFamilySchema
{
- public static readonly AsciiType DefaultKeyName = CassandraType.GetTypeFromDatabaseValue<AsciiType>(new byte[] { 75, 69, 89 });
+ public static readonly AsciiType DefaultKeyName = "KEY";
- public CassandraColumnFamilySchema()
+ public CassandraColumnFamilySchema(CfDef def)
{
- KeyName = DefaultKeyName;
+ var familyType = ColumnType.Standard;
+ Enum.TryParse<ColumnType>(def.Column_type, out familyType);
+
+ var keyType = CassandraType.GetCassandraType(def.Key_validation_class);
+ var defaultColumnValueType = CassandraType.GetCassandraType(def.Default_validation_class);
+ Type columnNameType, superColumnNameType;
+
+ if (familyType == ColumnType.Super)
+ {
+ superColumnNameType = CassandraType.GetCassandraType(def.Comparator_type);
+ columnNameType = CassandraType.GetCassandraType(def.Subcomparator_type);
+ }
+ else
+ {
+ superColumnNameType = null;
+ columnNameType = CassandraType.GetCassandraType(def.Comparator_type);
+ }
+
+ FamilyType = familyType;
+ FamilyName = def.Name;
+ FamilyDescription = def.Comment;
+
+ KeyName = CassandraType.GetTypeFromDatabaseValue<BytesType>(def.Key_alias);
+ KeyType = keyType;
+ SuperColumnNameType = superColumnNameType;
+ ColumnNameType = columnNameType;
+ DefaultColumnValueType = defaultColumnValueType;
+
+ Columns = def.Column_metadata.Select(col => new CassandraColumnSchema(col, columnNameType)).ToList();
+ }
+
+ public CassandraColumnFamilySchema(string name = null, ColumnType type = ColumnType.Standard)
+ {
+ FamilyType = type;
+ FamilyName = name;
+ FamilyDescription = null;
+ KeyName = DefaultKeyName;
KeyType = typeof(BytesType);
- SuperColumnNameType = typeof(BytesType);
+ SuperColumnNameType = type == ColumnType.Super ? typeof(BytesType) : null;
ColumnNameType = typeof(BytesType);
+ DefaultColumnValueType = typeof(BytesType);
Columns = new List<CassandraColumnSchema>();
}
+ public ColumnType FamilyType { get; set; }
public string FamilyName { get; set; }
- public CassandraType KeyName { get; set; }
+ public string FamilyDescription { get; set; }
+ public CassandraType KeyName { get; set; }
public Type KeyType { get; set; }
public Type SuperColumnNameType { get; set; }
public Type ColumnNameType { get; set; }
+ public Type DefaultColumnValueType { get; set; }
public IList<CassandraColumnSchema> Columns { get; set; }
}
View
15 src/CassandraColumnPathSchema.cs
@@ -1,15 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using FluentCassandra.Types;
-
-namespace FluentCassandra
-{
- public class CassandraColumnPathSchema
- {
- public string ColumnFamily { get; set; }
- public CassandraType SuperColumnNameType { get; set; }
- public CassandraType ColumnNameType { get; set; }
- }
-}
View
29 src/CassandraColumnSchema.cs
@@ -1,4 +1,5 @@
using System;
+using Apache.Cassandra;
using FluentCassandra.Types;
namespace FluentCassandra
@@ -11,7 +12,13 @@ public CassandraColumnSchema()
ValueType = typeof(BytesType);
}
- private Type _nameType;
+ public CassandraColumnSchema(ColumnDef def, Type columnNameType)
+ {
+ NameType = columnNameType;
+ Name = def.Name;
+ ValueType = CassandraType.GetCassandraType(def.Validation_class);
+ }
+
private CassandraType _name;
public CassandraType Name
@@ -19,25 +26,11 @@ public CassandraType Name
get { return _name; }
set
{
- if (value != null)
- NameType = value.GetType();
-
- _name = value;
- }
- }
-
- public Type NameType
- {
- get
- {
- if (_nameType == null && Name != null)
- _nameType = Name.GetType();
-
- return _nameType;
+ _name = (CassandraType)value.GetValue(NameType);
}
- set { _nameType = value; }
}
- public virtual Type ValueType { get; set; }
+ public Type NameType { get; set; }
+ public Type ValueType { get; set; }
}
}
View
2  src/CassandraContext.cs
@@ -171,7 +171,7 @@ public IEnumerable<CassandraKeyspace> DescribeKeyspaces()
{
return ExecuteOperation(new SimpleOperation<IEnumerable<CassandraKeyspace>>(ctx => {
IEnumerable<KsDef> keyspaces = ctx.Session.GetClient(setKeyspace: false).describe_keyspaces();
- return keyspaces.Select(keyspace => new CassandraKeyspace(keyspace, this));
+ return keyspaces.Select(keyspace => new CassandraKeyspace(new CassandraKeyspaceSchema(keyspace), this));
}));
}
View
125 src/CassandraKeyspace.cs
@@ -12,34 +12,22 @@ namespace FluentCassandra
public class CassandraKeyspace
{
private readonly string _keyspaceName;
- private KsDef _cachedKeyspaceDescription;
+ private CassandraKeyspaceSchema _cachedSchema;
private CassandraContext _context;
- /// <summary>
- ///
- /// </summary>
- /// <param name="definition"></param>
- public CassandraKeyspace(KsDef definition, CassandraContext context)
- {
- if (definition == null)
- throw new ArgumentNullException("definition");
-
- _keyspaceName = definition.Name;
- _cachedKeyspaceDescription = definition;
- _context = context;
- }
-
- /// <summary>
- ///
- /// </summary>
- /// <param name="keyspaceName"></param>
- /// <param name="connecton"></param>
public CassandraKeyspace(string keyspaceName, CassandraContext context)
+ : this(new CassandraKeyspaceSchema { Name = keyspaceName }, context) { }
+
+ public CassandraKeyspace(CassandraKeyspaceSchema schema, CassandraContext context)
{
- if (keyspaceName == null)
- throw new ArgumentNullException("keyspaceName");
+ if (schema == null)
+ throw new ArgumentNullException("schema");
- _keyspaceName = keyspaceName;
+ if (schema.Name == null)
+ throw new ArgumentException("Must specify the keyspace name.");
+
+ _keyspaceName = schema.Name;
+ _cachedSchema = schema;
_context = context;
}
@@ -70,55 +58,63 @@ public void TryCreateSelf()
string result = _context.AddKeyspace(new KsDef {
Name = KeyspaceName,
- Strategy_class = "org.apache.cassandra.locator.SimpleStrategy",
+ Strategy_class = "org.apache.cassandra.locator.NetworkTopologyStrategy",
Replication_factor = 1,
Cf_defs = new List<CfDef>(0)
});
Debug.WriteLine(result, "keyspace setup");
}
- public void TryCreateColumnFamily<CompareWith>(string columnFamilyName)
- where CompareWith : CassandraType
+ public void TryCreateColumnFamily(CassandraColumnFamilySchema schema)
{
try
{
- var comparatorType = GetCassandraComparatorType(typeof(CompareWith));
-
- string result = _context.AddColumnFamily(new CfDef {
- Name = columnFamilyName,
+ var def = new CfDef {
Keyspace = KeyspaceName,
- Comparator_type = comparatorType
- });
- Debug.WriteLine(result, "keyspace setup");
+ Name = schema.FamilyName,
+ Comment = schema.FamilyDescription,
+ Column_type = schema.FamilyType.ToString(),
+ Key_alias = schema.KeyName.ToBigEndian(),
+ Key_validation_class = GetCassandraComparatorType(schema.KeyType),
+ Comparator_type = GetCassandraComparatorType(schema.ColumnNameType),
+ Default_validation_class = GetCassandraComparatorType(schema.DefaultColumnValueType)
+ };
+
+ if (schema.FamilyType == ColumnType.Super)
+ {
+ def.Comparator_type = GetCassandraComparatorType(schema.SuperColumnNameType);
+ def.Subcomparator_type = GetCassandraComparatorType(schema.ColumnNameType);
+ }
+
+ string result = _context.AddColumnFamily(def);
+ Debug.WriteLine(result, "column family setup");
}
catch
{
- Debug.WriteLine(columnFamilyName + " already exists", "keyspace setup");
+ Debug.WriteLine(schema.FamilyName + " already exists", "column family setup");
}
}
+ [Obsolete("Use \"TryCreateColumnFamily\" class with out generic type")]
+ public void TryCreateColumnFamily<CompareWith>(string columnFamilyName)
+ where CompareWith : CassandraType
+ {
+ TryCreateColumnFamily(new CassandraColumnFamilySchema {
+ ColumnNameType = typeof(CompareWith),
+ FamilyName = columnFamilyName
+ });
+ }
+
+ [Obsolete("Use \"TryCreateColumnFamily\" class with out generic type")]
public void TryCreateColumnFamily<CompareWith, CompareSubcolumnWith>(string columnFamilyName)
where CompareWith : CassandraType
where CompareSubcolumnWith : CassandraType
{
- try
- {
- var comparatorType = GetCassandraComparatorType(typeof(CompareWith));
- var subComparatorType = GetCassandraComparatorType(typeof(CompareSubcolumnWith));
-
- string result = _context.AddColumnFamily(new CfDef {
- Name = columnFamilyName,
- Keyspace = KeyspaceName,
- Column_type = "Super",
- Comparator_type = comparatorType,
- Subcomparator_type = subComparatorType
- });
- Debug.WriteLine(result, "keyspace setup");
- }
- catch
- {
- Debug.WriteLine(columnFamilyName + " already exists", "keyspace setup");
- }
+ TryCreateColumnFamily(new CassandraColumnFamilySchema(type: ColumnType.Super) {
+ ColumnNameType = typeof(CompareWith),
+ SuperColumnNameType = typeof(CompareSubcolumnWith),
+ FamilyName = columnFamilyName
+ });
}
private string GetCassandraComparatorType(Type comparatorType)
@@ -142,31 +138,38 @@ private string GetCassandraComparatorType(Type comparatorType)
return comparatorTypeName;
}
- public CfDef GetColumnFamilyDescription(string columnFamily)
+ public KsDef GetDescription()
{
- return Describe().Cf_defs.FirstOrDefault(cf => cf.Name == columnFamily);
+ return _context.ExecuteOperation(new SimpleOperation<Apache.Cassandra.KsDef>(ctx => {
+ return ctx.Session.GetClient().describe_keyspace(KeyspaceName);
+ }));
+ }
+
+ public CassandraColumnFamilySchema GetColumnFamilySchema(string columnFamily)
+ {
+ return GetSchema().ColumnFamilies.FirstOrDefault(cf => cf.FamilyName == columnFamily);
}
public bool ColumnFamilyExists(string columnFamilyName)
{
- return Describe().Cf_defs.Any(columnFamily => columnFamily.Name == columnFamilyName);
+ return GetSchema().ColumnFamilies.Any(cf => cf.FamilyName == columnFamilyName);
}
public void ClearCachedKeyspaceDescription()
{
- _cachedKeyspaceDescription = null;
+ _cachedSchema = null;
}
#region Cassandra Keyspace Server Operations
- public KsDef Describe()
+ public CassandraKeyspaceSchema GetSchema()
{
- if (_cachedKeyspaceDescription == null)
- _cachedKeyspaceDescription = _context.ExecuteOperation(new SimpleOperation<Apache.Cassandra.KsDef>(ctx => {
+ if (_cachedSchema == null)
+ _cachedSchema = new CassandraKeyspaceSchema(_context.ExecuteOperation(new SimpleOperation<Apache.Cassandra.KsDef>(ctx => {
return ctx.Session.GetClient().describe_keyspace(KeyspaceName);
- }));
+ })));
- return _cachedKeyspaceDescription;
+ return _cachedSchema;
}
public IEnumerable<CassandraTokenRange> DescribeRing()
View
35 src/CassandraKeyspaceSchema.cs
@@ -0,0 +1,35 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Apache.Cassandra;
+
+namespace FluentCassandra
+{
+ public class CassandraKeyspaceSchema
+ {
+ public const string ReplicaPlacementStrategySimple = "org.apache.cassandra.locator.SimpleStrategy";
+ public const string ReplicaPlacementStrategyLocal = "org.apache.cassandra.locator.LocalStrategy";
+ public const string ReplicaPlacementStrategyNetworkTopology = "org.apache.cassandra.locator.NetworkTopologyStrategy";
+
+ public CassandraKeyspaceSchema()
+ {
+ Strategy = ReplicaPlacementStrategyNetworkTopology;
+ ReplicationFactor = 1;
+ ColumnFamilies = new List<CassandraColumnFamilySchema>();
+ }
+
+ public CassandraKeyspaceSchema(KsDef def)
+ {
+ Name = def.Name;
+ Strategy = def.Strategy_class;
+ ReplicationFactor = def.Replication_factor;
+ ColumnFamilies = def.Cf_defs.Select(family => new CassandraColumnFamilySchema(family)).ToList();
+ }
+
+ public string Name { get; set; }
+ public string Strategy { get; set; }
+ public int ReplicationFactor { get; set; }
+
+ public IList<CassandraColumnFamilySchema> ColumnFamilies { get; set; }
+ }
+}
View
21 src/CassandraSuperColumnFamily.cs
@@ -37,25 +37,12 @@ public FluentSuperColumnFamily CreateRecord(CassandraType key)
public override CassandraColumnFamilySchema GetSchema()
{
- var def = Context.Keyspace.GetColumnFamilyDescription(FamilyName);
+ var schema = Context.Keyspace.GetColumnFamilySchema(FamilyName);
if (_cachedSchema == null)
- {
- _cachedSchema = new CassandraColumnFamilySchema();
-
- var keyType = CassandraType.GetCassandraType(def.Key_validation_class);
- var colNameType = CassandraType.GetCassandraType(def.Default_validation_class);
- var subColNameType = CassandraType.GetCassandraType(def.Subcomparator_type);
-
- _cachedSchema.FamilyName = FamilyName;
- _cachedSchema.KeyType = keyType;
- _cachedSchema.SuperColumnNameType = colNameType;
- _cachedSchema.ColumnNameType = subColNameType;
- _cachedSchema.Columns = def.Column_metadata.Select(col => new CassandraColumnSchema {
- Name = CassandraType.GetTypeFromDatabaseValue(col.Name, colNameType),
- ValueType = CassandraType.GetCassandraType(col.Validation_class)
- }).ToList();
- }
+ _cachedSchema = (schema == null)
+ ? new CassandraColumnFamilySchema(FamilyName, ColumnType.Super)
+ : schema;
return _cachedSchema;
}
View
2  src/FluentCassandra.csproj
@@ -95,11 +95,11 @@
<Compile Include="BaseCassandraColumnFamily.cs" />
<Compile Include="CassandraColumnFamilySchema.cs" />
<Compile Include="CassandraColumnFamily.cs" />
- <Compile Include="CassandraColumnPathSchema.cs" />
<Compile Include="CassandraColumnSchema.cs" />
<Compile Include="CassandraContext.cs" />
<Compile Include="CassandraException.cs" />
<Compile Include="CassandraKeyspace.cs" />
+ <Compile Include="CassandraKeyspaceSchema.cs" />
<Compile Include="CassandraSession.cs" />
<Compile Include="CassandraSuperColumnFamilyOperations.cs" />
<Compile Include="CassandraSuperColumnFamily.cs" />
View
8 src/Types/AsciiTypeConverter.cs
@@ -1,4 +1,5 @@
using System;
+using System.Text;
namespace FluentCassandra.Types
{
@@ -23,18 +24,15 @@ public override bool CanConvertTo(Type destinationType)
public override string ConvertFromInternal(object value)
{
if (value is byte[])
- return ((byte[])value).FromBytes<string>();
+ return Encoding.ASCII.GetString((byte[])value);
return (string)Convert.ChangeType(value, typeof(string));
}
public override object ConvertToInternal(string value, Type destinationType)
{
- if (!(value is string))
- return null;
-
if (destinationType == typeof(byte[]))
- return value.ToBytes();
+ return Encoding.ASCII.GetBytes(value);
return Convert.ChangeType(value, destinationType);
}
View
1  src/Types/CompositeType.cs
@@ -60,6 +60,7 @@ public static CompositeType Create(params CassandraType[] types)
public CompositeType()
{
ComponentTypeHints = new List<Type>();
+ _value = new List<CassandraType>();
}
#region Implimentation
View
19 src/Types/DynamicCompositeType.cs
@@ -10,19 +10,26 @@ public class DynamicCompositeType : CassandraType, IList<CassandraType>
public DynamicCompositeType()
: this(new Dictionary<char, Type> {
- { 'a', typeof(AsciiType) },
- { 'b', typeof(BytesType) },
- { 'i', typeof(IntegerType) },
- { 'x', typeof(LexicalUUIDType) },
+ { 'b', typeof(BooleanType) },
+ { 't', typeof(DateType) },
+ { 'm', typeof(DecimalType) },
+ { 'f', typeof(FloatType) },
+ { 'd', typeof(DoubleType) },
+ { 'i', typeof(Int32Type) },
{ 'l', typeof(LongType) },
- { 't', typeof(TimeUUIDType) },
+ { 'z', typeof(IntegerType) },
+ { 'a', typeof(AsciiType) },
{ 's', typeof(UTF8Type) },
- { 'u', typeof(UUIDType) }
+ { 'x', typeof(BytesType) },
+ { 'u', typeof(UUIDType) },
+ { '1', typeof(TimeUUIDType) },
+ { '2', typeof(LexicalUUIDType) }
}) { }
public DynamicCompositeType(IDictionary<char, Type> aliases)
{
Converter = new DynamicCompositeTypeConverter(aliases);
+ _value = new List<CassandraType>();
}
#region Implimentation
View
2  test/FluentCassandra.Tests/TypesToDatabase/CompositeTypeTest.cs
@@ -29,7 +29,7 @@ public void TestCleanup()
public void Save_CompositeType()
{
// arrange
- var family = _db.GetColumnFamily<CompositeType<LongType, UTF8Type>>(FamilyName);
+ var family = _db.GetColumnFamily(FamilyName);
var expected = new CompositeType<LongType, UTF8Type>(300L, "string1");
// act
View
35 test/FluentCassandra.Tests/TypesToDatabase/DynamicCompositeTypeTest.cs
@@ -1,5 +1,6 @@
using System;
using System.Linq;
+using FluentCassandra.Types;
using NUnit.Framework;
namespace FluentCassandra.TypesToDatabase
@@ -7,5 +8,39 @@ namespace FluentCassandra.TypesToDatabase
[TestFixture]
public class DynamicCompositeTypeTest
{
+ public const string FamilyName = "StandardDynamicCompositeType";
+ public const string TestKey = "Test1";
+ private CassandraContext _db;
+
+ [TestFixtureSetUp]
+ public void TestInit()
+ {
+ var setup = new CassandraDatabaseSetup();
+ _db = setup.DB;
+ }
+
+ [TestFixtureTearDown]
+ public void TestCleanup()
+ {
+ _db.Dispose();
+ }
+
+ [Test]
+ public void Save_DynamicCompositeType()
+ {
+ // arrange
+ var family = _db.GetColumnFamily(FamilyName);
+ var expected = new DynamicCompositeType();
+ expected.Add(300L);
+ expected.Add("string1");
+
+ // act
+ family.InsertColumn(TestKey, expected, Math.PI);
+ var value = family.Get(TestKey).Execute();
+ var actual = value.FirstOrDefault().Columns.FirstOrDefault();
+
+ // assert
+ Assert.AreEqual((object)expected, (object)actual.ColumnName);
+ }
}
}
View
9 utility/FluentCassandra.LinqPad/CassandraDriver.cs
@@ -14,21 +14,12 @@ namespace FluentCassandra.LinqPad
/// </summary>
public class CassandraDriver : DynamicDataContextDriver
{
- private Apache.Cassandra.KsDef _schema;
-
public override string Name { get { return "Cassandra"; } }
public override string Author { get { return "Nick Berardi"; } }
private void CacheDefinitionIfNessisary(CassandraConnectionInfo info)
{
- if (_schema != null)
- return;
-
- var context = info.CreateContext();
- var keyspace = context.Keyspace;
-
- _schema = keyspace.Describe();
}
/// <summary>Returns the text to display in the root Schema Explorer node for a given connection info.</summary>
View
28 utility/FluentCassandra.LinqPad/SchemaBuilder.cs
@@ -18,7 +18,7 @@ internal static List<ExplorerItem> GetSchemaAndBuildAssembly(CassandraConnection
var context = info.CreateContext();
var keyspace = context.Keyspace;
- var def = keyspace.Describe();
+ var def = keyspace.GetSchema();
var code = GenerateCode(def, nameSpace, typeName);
var schema = GetSchema(def);
@@ -28,7 +28,7 @@ internal static List<ExplorerItem> GetSchemaAndBuildAssembly(CassandraConnection
return schema;
}
- private static string GenerateCode(Apache.Cassandra.KsDef def, string nameSpace, string typeName)
+ private static string GenerateCode(CassandraKeyspaceSchema schema, string nameSpace, string typeName)
{
var code = new StringBuilder();
@@ -62,16 +62,14 @@ public void Dispose()
Context.Dispose();
}
");
- foreach (var familyDef in def.Cf_defs)
+ foreach (var familyDef in schema.ColumnFamilies)
{
- var type = CassandraType.GetCassandraType(familyDef.Default_validation_class);
- var validationName = type.Name;
- var familyName = familyDef.Name;
+ var familyName = familyDef.FamilyName;
code.AppendLine(@"
- private FluentCassandra.CassandraColumnFamily<" + validationName + @"> _" + familyName + @";
- public FluentCassandra.CassandraColumnFamily<" + validationName + @"> " + familyName + @" { get {
+ private FluentCassandra.CassandraColumnFamily _" + familyName + @";
+ public FluentCassandra.CassandraColumnFamily " + familyName + @" { get {
if (_" + familyName + @" == null)
- _" + familyName + @" = Context.GetColumnFamily<" + validationName + @">(""" + familyName + @""");
+ _" + familyName + @" = Context.GetColumnFamily(""" + familyName + @""");
return _" + familyName + @";
} }");
@@ -103,20 +101,20 @@ private static void BuildAssembly(string code, string driverFolder, AssemblyName
("Cannot compile typed context: " + results.Errors[0].ErrorText + " (line " + results.Errors[0].Line + ")");
}
- private static List<ExplorerItem> GetSchema(Apache.Cassandra.KsDef def)
+ private static List<ExplorerItem> GetSchema(CassandraKeyspaceSchema schema)
{
var families = new List<ExplorerItem>();
- foreach (var familyDef in def.Cf_defs)
+ foreach (var familyDef in schema.ColumnFamilies)
{
- var family = new ExplorerItem(familyDef.Name, ExplorerItemKind.QueryableObject, ExplorerIcon.Table);
+ var family = new ExplorerItem(familyDef.FamilyName, ExplorerItemKind.QueryableObject, ExplorerIcon.Table);
family.IsEnumerable = true;
family.Children = new List<ExplorerItem>();
- family.Children.Add(new ExplorerItem("KEY", ExplorerItemKind.Property, ExplorerIcon.Key));
+ family.Children.Add(new ExplorerItem(familyDef.KeyName.GetValue<string>(), ExplorerItemKind.Property, ExplorerIcon.Key));
- foreach (var colDef in familyDef.Column_metadata)
+ foreach (var colDef in familyDef.Columns)
{
- var col = new ExplorerItem(CassandraType.GetTypeFromDatabaseValue(colDef.Name, familyDef.Default_validation_class).GetValue<string>(), ExplorerItemKind.Property, ExplorerIcon.Column);
+ var col = new ExplorerItem(colDef.Name.GetValue<string>(), ExplorerItemKind.Property, ExplorerIcon.Column);
family.Children.Add(col);
}
Please sign in to comment.
Something went wrong with that request. Please try again.