Permalink
Browse files

refactored LINQ to CQL and CQL Row's to make it a little more flexibl…

…e in the future, hopefully for ADO.NET support down the line
  • Loading branch information...
1 parent ff16fb5 commit 8949df0b5f36dd33c69f11bef0a2e3320252b944 @nberardi nberardi committed Jun 6, 2012
@@ -56,7 +56,7 @@ IEnumerator IEnumerable.GetEnumerator()
/// <returns></returns>
public IEnumerator<T> GetEnumerator()
{
- var result = CqlQueryEvaluator.GetCql(Expression, _family.ObjectConventions);
+ var result = CqlQueryEvaluator.GetCql(Expression);
var fluentObjects = _family.Context.ExecuteQuery(result);
var serializer = ObjectSerializerFactory.Get(typeof(T));
@@ -114,7 +114,7 @@ public IQueryProvider Provider
/// <returns></returns>
public override string ToString()
{
- return CqlQueryEvaluator.GetCql(Expression, _family.ObjectConventions);
+ return CqlQueryEvaluator.GetCql(Expression);
}
}
}
@@ -20,6 +20,11 @@ public string FamilyName
get { return _family.FamilyName; }
}
+ public CassandraColumnFamilySchema GetSchema()
+ {
+ return _family.GetSchema();
+ }
+
public CqlObjectQuery<T> ToQuery()
{
var queryable = (IQueryable)this;
@@ -13,14 +13,12 @@ namespace FluentCassandra.Linq
internal class CqlQueryEvaluator
{
private string _columnFamily;
- private readonly ObjectSerializerConventions _conventions;
+ private CassandraColumnFamilySchema _schema;
- internal CqlQueryEvaluator(ObjectSerializerConventions conventions = null)
+ internal CqlQueryEvaluator()
{
SelectFieldsArray = new List<string>();
OrderByFieldsArray = new List<string>();
-
- _conventions = conventions;
}
public string Query
@@ -92,6 +90,7 @@ private string Fields
private void AddTable(ICassandraColumnFamilyInfo provider)
{
_columnFamily = provider.FamilyName;
+ _schema = provider.GetSchema();
}
private void AddOrderByFieldDescending(Expression exp)
@@ -163,7 +162,7 @@ private string GetPropertyName(Expression exp)
if (name != "Key")
throw new NotSupportedException(name + " is not a supported property.");
- return "KEY";
+ return _schema.KeyName.GetValue<string>();
case ExpressionType.Call:
@@ -183,9 +182,9 @@ private string GetPropertyName(Expression exp)
#region Expression Parsing
- public static string GetCql(Expression expression, ObjectSerializerConventions conventions = null)
+ public static string GetCql(Expression expression)
{
- var eval = new CqlQueryEvaluator(conventions);
+ var eval = new CqlQueryEvaluator();
eval.Evaluate(expression);
return eval.Query;
@@ -6,5 +6,6 @@ namespace FluentCassandra.Linq
public interface ICassandraColumnFamilyInfo
{
string FamilyName { get; }
+ CassandraColumnFamilySchema GetSchema();
}
}
@@ -50,6 +50,9 @@ BEGIN BATCH
// assert
var results = actual.ToList();
Assert.Equal(4, results.Count);
+
+ var row = results.FirstOrDefault();
+ Assert.Equal(2, row.Columns.Count);
}
[Fact]
@@ -88,6 +91,9 @@ BEGIN BATCH
// assert
var results = actual.ToList();
Assert.Equal(7, results.Count);
+
+ var row = results.FirstOrDefault();
+ Assert.Equal(4, row.Columns.Count);
}
}
}
@@ -94,7 +94,7 @@ public void ResetDatabase()
db.ExecuteNonQuery(@"
CREATE COLUMNFAMILY Users (
- KEY int PRIMARY KEY,
+ Id int PRIMARY KEY,
Name ascii,
Email ascii,
Age int
@@ -108,7 +108,7 @@ public void SELECT_Two_Columns()
[Fact]
public void WHERE_Using_KEY()
{
- var expected = "SELECT * FROM Users WHERE KEY = 1234";
+ var expected = "SELECT * FROM Users WHERE Id = 1234";
var query =
from f in _family.AsObjectQueryable<User>()
@@ -123,7 +123,7 @@ public void WHERE_Using_KEY()
[Fact]
public void WHERE_Using_KEY_And_One_Parameter()
{
- var expected = "SELECT * FROM Users WHERE KEY = 1234 AND Age = 10";
+ var expected = "SELECT * FROM Users WHERE Id = 1234 AND Age = 10";
var query =
from f in _family.AsObjectQueryable<User>()
@@ -166,7 +166,7 @@ orderby f.Age
[Fact]
public void ORDER_BY_Two_Fields()
{
- var expected = "SELECT * FROM Users ORDER BY Age ASC, KEY DESC";
+ var expected = "SELECT * FROM Users ORDER BY Age ASC, Id DESC";
var query =
from f in _family.AsObjectQueryable<User>()
@@ -181,7 +181,7 @@ public void ORDER_BY_Two_Fields()
[Fact]
public void ORDER_BY_Two_Fields_2()
{
- var expected = "SELECT * FROM Users ORDER BY Age DESC, KEY ASC";
+ var expected = "SELECT * FROM Users ORDER BY Age DESC, Id ASC";
var query =
from f in _family.AsObjectQueryable<User>()
@@ -24,7 +24,7 @@ public void Dispose()
public void With_Compression()
{
// arrange
- var insertQuery = @"INSERT INTO Users (KEY, Name, Email, Age) VALUES (23, '" + new String('X', 200) + "', 'test@test.com', 43)";
+ var insertQuery = @"INSERT INTO Users (Id, Name, Email, Age) VALUES (23, '" + new String('X', 200) + "', 'test@test.com', 43)";
// act
_db.ExecuteNonQuery(insertQuery);

0 comments on commit 8949df0

Please sign in to comment.