Permalink
Browse files

1. allow update rows after retrieving. 2. added update row test case.

  • Loading branch information...
1 parent 357030e commit 7e714c0b8822c4d16d8d8a122318008e24ae6c20 @DerekLiang DerekLiang committed with nberardi Dec 7, 2011
View
6 src/Operations/Helper.cs
@@ -33,14 +33,16 @@ public static long ToTimestamp(this DateTimeOffset dt)
return null;
}
- public static FluentColumn<CompareWith> ConvertColumnToFluentColumn<CompareWith>(Column col)
+ public static FluentColumn<CompareWith> ConvertColumnToFluentColumn<CompareWith>(Column col, FluentColumnFamily<CompareWith> family = null)
where CompareWith : CassandraType
{
+
return new FluentColumn<CompareWith> {
ColumnName = CassandraType.GetType<CompareWith>(col.Name),
ColumnValue = col.Value,
ColumnTimestamp = new DateTimeOffset(col.Timestamp, TimeSpan.Zero),
- ColumnTimeToLive = col.Ttl
+ ColumnTimeToLive = col.Ttl,
+ Family = family
};
}
View
2 src/Operations/MultiGetColumnFamilySlice.cs
@@ -37,7 +37,7 @@ public override IEnumerable<IFluentColumnFamily<CompareWith>> Execute()
foreach (var result in output)
{
var r = new FluentColumnFamily<CompareWith>(result.Key, ColumnFamily.FamilyName, result.Value.Select(col => {
- return Helper.ConvertColumnToFluentColumn<CompareWith>(col.Column);
+ return Helper.ConvertColumnToFluentColumn<CompareWith>(col.Column, family: new FluentColumnFamily<CompareWith>(result.Key, ColumnFamily.FamilyName));
}));
ColumnFamily.Context.Attach(r);
r.MutationTracker.Clear();
View
33 test/FluentCassandra.Sandbox/Program.cs
@@ -113,6 +113,35 @@ private static void ReadPost()
#endregion
+
+ #region Update Post
+ private static void UpdatePost()
+ {
+ using (var db = new CassandraContext(keyspace: keyspaceName, server: server))
+ {
+ var key = "first-blog-post";
+
+ var postFamily = db.GetColumnFamily<UTF8Type>("Posts");
+ // get the post back from the database
+ ConsoleHeader("getting 'first-blog-post' for update");
+ dynamic post = postFamily.Get(key).FirstOrDefault();
+
+ post.Title = post.Title + "(updated)";
+ post.Body = post.Body + "(updated)";
+ post.Author = post.Author + "(updated)";
+ post.PostedOn = DateTimeOffset.Now;
+
+ // attach the post to the database
+ ConsoleHeader("attaching record");
+ db.Attach(post);
+
+ // save the changes
+ ConsoleHeader("saving changes");
+ db.SaveChanges();
+ }
+ }
+ #endregion
+
#region Create Comments
private static void CreateComments()
@@ -205,6 +234,10 @@ private static void Main(string[] args)
ReadPost();
+ UpdatePost();
+
+ ReadPost();
+
CreateComments();
ReadComments();

0 comments on commit 7e714c0

Please sign in to comment.