public void Test_GetRangeSlice() { // arrange var keyspace = _db.Keyspace; // create column family using API _db.TryDropColumnFamily("supercolumns"); keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema { FamilyName = "supercolumns", FamilyType = ColumnType.Super, KeyValueType = CassandraType.UTF8Type, SuperColumnNameType = CassandraType.TimeUUIDType, ColumnNameType = CassandraType.UTF8Type, DefaultColumnValueType = CassandraType.UTF8Type }); InsertData("testKey"); // act var actual = _db.GetSuperColumnFamily("supercolumns").Get().TakeKeys(5); // assert Assert.NotNull(actual); Assert.Equal(1, actual.Count()); Assert.Equal("testKey", actual.First().Key.ToString()); }
private static void CreateComments() { using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server)) { var key = "lista_razgovori"; // get the comments family var commentsFamily = db.GetSuperColumnFamily("razgovor"); var postComments = commentsFamily.CreateRecord(key: key); // lets attach it to the database before we add the comments db.Attach(postComments); var comment = postComments.CreateSuperColumn(); postComments["3"] = comment; comment["broj_a"] = "070441113"; comment["broj_b"] = "078487693"; comment["dolzina"] = "28"; comment["vreme"] = "23.11.2013 10:44:32"; db.SaveChanges(); db.ExecuteNonQuery("INSERT INTO poraka(naslov, sodrzina) VALUES ('test 2 naslov','test 2 sodrzina')"); } }
private void button4_Click(object sender, EventArgs e) { using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server)) { var commentsFamily = db.GetSuperColumnFamily("razgovor"); commentsFamily.RemoveAllRows(); listBox1.Items.Clear(); ReadAllPosts(); } }
public CassandraDatabaseSetup(bool reset = false, string cqlVersion = CqlVersion.Edge) { ConnectionBuilder = new ConnectionBuilder(keyspace: Keyspace, server: Server, cqlVersion: cqlVersion); DB = new CassandraContext(ConnectionBuilder); var exists = DB.KeyspaceExists(Keyspace); Family = DB.GetColumnFamily<AsciiType>("Standard"); SuperFamily = DB.GetColumnFamily<AsciiType, AsciiType>("Super"); UserFamily = DB.GetColumnFamily("Users"); CounterFamily = DB.GetColumnFamily("Counters"); SuperCounterFamily = DB.GetSuperColumnFamily("SuperCounters"); if (exists && !reset) return; ResetDatabase(); }
public CassandraDatabaseSetup(bool reset = false, string cqlVersion = CqlVersion.Edge) { ConnectionBuilder = new ConnectionBuilder(keyspace: Keyspace, server: Server, cqlVersion: cqlVersion); DB = new CassandraContext(ConnectionBuilder); var exists = DB.KeyspaceExists(Keyspace); Family = DB.GetColumnFamily <AsciiType>("Standard"); SuperFamily = DB.GetColumnFamily <AsciiType, AsciiType>("Super"); UserFamily = DB.GetColumnFamily("Users"); CounterFamily = DB.GetColumnFamily("Counters"); SuperCounterFamily = DB.GetSuperColumnFamily("SuperCounters"); if (exists && !reset) { return; } ResetDatabase(); }
private static void ReadComments() { using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server)) { var key = "first-blog-post"; var lastDate = DateTime.Now; // get the comments family var commentsFamily = db.GetSuperColumnFamily("Comments"); for (int page = 0; page < 2; page++) { // lets back the date off by a millisecond so we don't get paging overlaps lastDate = lastDate.AddMilliseconds(-1D); ConsoleHeader("showing page " + page + " of comments starting at " + lastDate.ToLocalTime()); // query using API var comments = commentsFamily.Get(key) .ReverseColumns() .StartWithColumn(lastDate) .TakeColumns(3) .FirstOrDefault(); foreach (dynamic comment in comments) { var dateTime = (DateTime)comment.ColumnName; Console.WriteLine(String.Format("{0:T} : {1} ({2} - {3})", dateTime.ToLocalTime(), comment.Name, comment.Email, comment.Website )); lastDate = dateTime; } } } }
private static void CreateComments() { using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server)) { var key = "first-blog-post"; // get the comments family var commentsFamily = db.GetSuperColumnFamily("Comments"); ConsoleHeader("create comments"); var postComments = commentsFamily.CreateRecord(key: key); // lets attach it to the database before we add the comments db.Attach(postComments); var dt = new DateTime(2010, 11, 29, 5, 03, 00, DateTimeKind.Local); // add 5 comments for (int i = 0; i < 5; i++) { var comment = postComments.CreateSuperColumn(); comment["Name"] = "Nick Berardi"; comment["Email"] = "*****@*****.**"; // you can also use it as a dynamic object dynamic dcomment = comment; dcomment.Website = "www.coderjournal.com"; dcomment.Comment = "Wow fluent cassandra is really great and easy to use."; var commentPostedOn = dt; postComments[commentPostedOn] = comment; Console.WriteLine("Comment " + (i + 1) + " Posted On " + commentPostedOn.ToLongTimeString()); dt = dt.AddMinutes(2); } // save the comments db.SaveChanges(); } }