Ejemplo n.º 1
0
        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.GetColumnFamily<TimeUUIDType, UTF8Type>("Comments");

                ConsoleHeader("create comments");
                dynamic postComments = commentsFamily.CreateRecord(key: key);

                // lets attach it to the database before we add the comments
                db.Attach(postComments);

                // add 5 comments
                for (int i = 0; i < 5; i++)
                {
                    dynamic comment = postComments.CreateSuperColumn();
                    comment.Name = "Nick Berardi";
                    comment.Email = "*****@*****.**";
                    comment.Website = "www.coderjournal.com";
                    comment.Comment = "Wow fluent cassandra is really great and easy to use.";

                    var commentPostedOn = DateTime.Now;
                    postComments[commentPostedOn] = comment;

                    Console.WriteLine("Comment " + (i + 1) + " Posted On " + commentPostedOn.ToLongTimeString());
                    Thread.Sleep(TimeSpan.FromSeconds(2));
                }

                // save the comments
                db.SaveChanges();
            }
        }
Ejemplo n.º 2
0
        private static void CreateColumnFamilyWithTimestampOperator()
        {
            using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
            {

                db.ExecuteNonQuery("CREATE TABLE TestCF2 (KEY text PRIMARY KEY) WITH comparator=timestamp AND default_validation=text;");

                DateTimeOffset UnixStart = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);
                DateTimeOffset TimeNow = DateTimeOffset.UtcNow;

                var columnName2 = Convert.ToInt64(Math.Floor((TimeNow - UnixStart).TotalMilliseconds));
                var columnName1 = columnName2 + 5000;

                db.ExecuteNonQuery(string.Format("INSERT INTO TestCF2 (KEY, {0}, {1}) VALUES ('Key1', 'Value1', 'Value2')", columnName1, columnName2));

                List<ICqlRow> rows = db.ExecuteQuery("SELECT * FROM TestCF2 WHERE KEY = 'Key1'").ToList();

                DateTime value1 = rows[0].Columns[1].ColumnName.GetValue<DateTime>();
                DateTime value2 = rows[0].Columns[2].ColumnName.GetValue<DateTime>();

                ConsoleHeader("Returned data from db for timestamp comparator");
                ConsoleHeader(value1.ToString());
                ConsoleHeader(value2.ToString());

            }
        }
Ejemplo n.º 3
0
        private static void BigDecimalTest()
        {
            using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
            {

                // arrange
                db.ExecuteNonQuery("CREATE TABLE OfferReservation2 (KEY text PRIMARY KEY) WITH comparator = text AND default_validation = decimal");
                db.ExecuteNonQuery("INSERT INTO OfferReservation2 (KEY, 'MyColumn') VALUES ('Key0', 1000000000000000000)");
                db.ExecuteNonQuery("INSERT INTO OfferReservation2 (KEY, 'MyColumn') VALUES ('Key1', 0.25)");
                db.ExecuteNonQuery("INSERT INTO OfferReservation2 (KEY, 'MyColumn') VALUES ('Key2', 2000000000000.1234)");
                db.ExecuteNonQuery("INSERT INTO OfferReservation2 (KEY, 'MyColumn') VALUES ('Key3', -0.25)");
                db.ExecuteNonQuery("INSERT INTO OfferReservation2 (KEY, 'MyColumn') VALUES ('Key4', -0.25122333)");

                var actual = db.ExecuteQuery("SELECT * FROM OfferReservation2");

                var results = actual.ToList();

                var firstValue = (decimal)results.First(x => x.Key == "Key0")["MyColumn"];
                var secondValue = (decimal)results.First(x => x.Key == "Key1")["MyColumn"];
                var thirdValue = (decimal)results.First(x => x.Key == "Key2")["MyColumn"];
                var fourthValue = (decimal)results.First(x => x.Key == "Key3")["MyColumn"];
                var fifthValue = (decimal)results.First(x => x.Key == "Key4")["MyColumn"];

                ConsoleHeader("Returned data from Big Decimal Test");
                ConsoleHeader(firstValue.ToString());
                ConsoleHeader(secondValue.ToString());
                ConsoleHeader(thirdValue.ToString());
                ConsoleHeader(fourthValue.ToString());
                ConsoleHeader(fifthValue.ToString());
            }
        }
Ejemplo n.º 4
0
        private static void DoWork()
        {
            using (var db = new CassandraContext(keyspace: keyspaceName, server: server))
            {
                Stopwatch watch = new Stopwatch();
                watch.Start();

                Random random = new Random();
                byte[] data = new byte[dataLength];
                random.NextBytes(data);
                int errors = 0;

                for (int i = 0; i < count; i++)
                {
                    // Insert
                    Guid postId = Guid.NewGuid();
                    string titleName = i.ToString();

                    var family = db.GetColumnFamily<UTF8Type, UTF8Type>("Posts");

                    dynamic post = family.CreateRecord(postId);
                    dynamic details = post.CreateSuperColumn();

                    details.Body = data;

                    post[DateTime.Now] = details;
                    db.Attach(post);
                    db.SaveChanges();
                }

                double rate = count / watch.Elapsed.TotalSeconds;
                double throughput = rate * data.Length;
                Console.WriteLine("Completed: " + watch.Elapsed + "\tRate: " + rate + "\tThroughput: " + throughput + "\tErrors:" + errors);
            }
        }
Ejemplo n.º 5
0
 public void TestInit()
 {
     var setup = new CassandraDatabaseSetup();
     _db = setup.DB;
     _family = setup.Family;
     _superFamily = setup.SuperFamily;
 }
Ejemplo n.º 6
0
 public void TestInit()
 {
     var setup = new CassandraDatabaseSetup();
     _db = setup.DB;
     _family = setup.UserFamily;
     _users = setup.Users;
 }
        public void ResetDatabase()
        {
            using (var session = new CassandraSession(ConnectionBuilder))
            using (var db = new CassandraContext(session))
            {
                db.ThrowErrors = true;
                db.TryDropKeyspace(Keyspace);

                var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema
                {
                    Name = Keyspace
                }, db);
                db.Keyspace = keyspace;

                keyspace.TryCreateSelf();

                db.ExecuteNonQuery(@"
            CREATE TABLE users (
            id int ,
            name ascii,
            email ascii,
            age int,
            PRIMARY KEY(id, email)
            );");

                ResetUsersFamily(db);
            }
        }
        public CompatibilityCassandraDatabaseSetup(bool reset = false, bool toLower = false, bool toLower2 = false)
        {
            this.toLower = toLower;
            this.toLower2 = toLower2;

            ConnectionBuilder = new ConnectionBuilder(keyspace: Keyspace, server: Server, cqlVersion: CqlVersion.Cql3);
            DB = new CassandraContext(ConnectionBuilder);

            if (DB.KeyspaceExists(Keyspace))
                DB.DropKeyspace(Keyspace);

            var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema
            {
                Name = Keyspace,
            }, DB);

            var exists = DB.KeyspaceExists(Keyspace);
            if(!exists)
                keyspace.TryCreateSelf();

            Family = DB.GetColumnFamily<AsciiType>("Standard");
            SuperFamily = DB.GetColumnFamily<AsciiType, AsciiType>("Super");
            UserFamily = DB.GetColumnFamily(toLowerIf(toLower,"Users"));

            if (exists && !reset)
                return;

            ResetDatabase();
        }
Ejemplo n.º 9
0
        private static void CreateFirstPost()
        {
            using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
            {
                var key = "first-blog-post";

                var postFamily = db.GetColumnFamily("Posts");
                var tagsFamily = db.GetColumnFamily("Tags");

                // create post
                ConsoleHeader("create post");
                dynamic post = postFamily.CreateRecord(key: key);
                post.Title = "My First Cassandra Post";
                post.Body = "Blah. Blah. Blah. about my first post on how great Cassandra is to work with.";
                post.Author = "Nick Berardi";
                post.PostedOn = DateTimeOffset.Now;

                // create tags
                ConsoleHeader("create post tags");
                dynamic tags = tagsFamily.CreateRecord(key: key);
                tags[0] = "Cassandra";
                tags[1] = ".NET";
                tags[2] = "Database";
                tags[3] = "NoSQL";

                // attach the post to the database
                ConsoleHeader("attaching record");
                db.Attach(post);
                db.Attach(tags);

                // save the changes
                ConsoleHeader("saving changes");
                db.SaveChanges();
            }
        }
        public LinqToCqlObjectsTests()
        {
            var keyspaceName = ConfigurationManager.AppSettings["TestKeySpace"];
            var server = new Server(ConfigurationManager.AppSettings["TestServer"]);

            _db = new CassandraContext(keyspace: keyspaceName, server: server);
            _family = _db.GetColumnFamily<AsciiType>("Users");
        }
Ejemplo n.º 11
0
		public LinqToCqlTests()
		{
			var keyspaceName = ConfigurationManager.AppSettings["TestKeySpace"];
			var server = new Server(ConfigurationManager.AppSettings["TestServer"]);

			_db = new CassandraContext(new ConnectionBuilder(keyspace: keyspaceName, server: server, cqlVersion: CqlVersion.Cql));
			_family = _db.GetColumnFamily<AsciiType>("Users");
		}
        public LinqToCqlObjectsTests()
        {
            var keyspaceName = "Testing";
            var server = new Server("localhost");

            _db = new CassandraContext(keyspace: keyspaceName, server: server);
            _family = _db.GetColumnFamily<AsciiType>("Users");
        }
        public void ResetDatabase()
        {
            using (var session = new CassandraSession(ConnectionBuilder))
            using (var db = new CassandraContext(session))
            {
                db.ThrowErrors = true;
                db.TryDropKeyspace(Keyspace);

                var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema
                {
                    Name = Keyspace
                }, db);
                db.Keyspace = keyspace;

                keyspace.TryCreateSelf();
                keyspace.TryCreateColumnFamily<AsciiType>("Standard");
                keyspace.TryCreateColumnFamily<AsciiType, AsciiType>("Super");
                keyspace.TryCreateColumnFamily<AsciiType>("StandardAsciiType");
                keyspace.TryCreateColumnFamily<BytesType>("StandardBytesType");
                keyspace.TryCreateColumnFamily<IntegerType>("StandardIntegerType");
                keyspace.TryCreateColumnFamily<LexicalUUIDType>("StandardLexicalUUIDType");
                keyspace.TryCreateColumnFamily<LongType>("StandardLongType");
                keyspace.TryCreateColumnFamily<TimeUUIDType>("StandardTimeUUIDType");
                keyspace.TryCreateColumnFamily<UTF8Type>("StandardUTF8Type");
                keyspace.TryCreateColumnFamily<UUIDType>("StandardUUIDType");
                keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema
                {
                    FamilyName = "StandardCompositeType",
                    ColumnNameType = CassandraType.CompositeType(new[] { CassandraType.AsciiType, CassandraType.DoubleType })
                });
                keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema
                {
                    FamilyName = "StandardDynamicCompositeType",
                    ColumnNameType = CassandraType.DynamicCompositeType(new Dictionary<char, CassandraType> { { 'a', CassandraType.AsciiType }, { 'd', CassandraType.DoubleType } })
                });

                db.ExecuteNonQuery(string.Format(@"
            CREATE TABLE {0} (
            id int ,
            name ascii,
            email ascii,
            age int,
            PRIMARY KEY(id)
            );", toLowerIf(toLower, "Users")));

                //db.ExecuteNonQuery(@"CREATE INDEX User_Age ON users (Age);");
                db.Keyspace.ClearCachedKeyspaceSchema();

                var family = db.GetColumnFamily<AsciiType>("Standard");
                var superFamily = db.GetColumnFamily<AsciiType, AsciiType>("Super");
                var userFamily = db.GetColumnFamily(toLowerIf(toLower, "Users"));

                ResetFamily(family);
                ResetSuperFamily(superFamily);
                ResetUsersFamily(userFamily);
            }
        }
        public void ResetDatabase()
        {
            using (var session = new CassandraSession(ConnectionBuilder))
            using (var db = new CassandraContext(session))
            {
                db.ThrowErrors = true;

                try { db.DropKeyspace(Keyspace); }
                catch (Exception exc) { Console.WriteLine(exc); }

                var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema {
                    Name = Keyspace
                }, db);
                db.Keyspace = keyspace;

                keyspace.TryCreateSelf();
                keyspace.TryCreateColumnFamily<AsciiType>("Standard");
                keyspace.TryCreateColumnFamily<AsciiType, AsciiType>("Super");
                keyspace.TryCreateColumnFamily<AsciiType>("StandardAsciiType");
                keyspace.TryCreateColumnFamily<BytesType>("StandardBytesType");
                keyspace.TryCreateColumnFamily<IntegerType>("StandardIntegerType");
                keyspace.TryCreateColumnFamily<LexicalUUIDType>("StandardLexicalUUIDType");
                keyspace.TryCreateColumnFamily<LongType>("StandardLongType");
                keyspace.TryCreateColumnFamily<TimeUUIDType>("StandardTimeUUIDType");
                keyspace.TryCreateColumnFamily<UTF8Type>("StandardUTF8Type");
                keyspace.TryCreateColumnFamily<UUIDType>("StandardUUIDType");
                keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema {
                    FamilyName = "StandardCompositeType",
                    ColumnNameType = CassandraType.CompositeType(new[] { CassandraType.AsciiType, CassandraType.DoubleType })
                });
                keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema {
                    FamilyName = "StandardDynamicCompositeType",
                    ColumnNameType = CassandraType.DynamicCompositeType(new Dictionary<char, CassandraType> { { 'a', CassandraType.AsciiType }, { 'd', CassandraType.DoubleType } })
                });

                db.ExecuteNonQuery(@"
            CREATE COLUMNFAMILY Users (
            KEY int PRIMARY KEY,
            Name ascii,
            Email ascii,
            Age int
            );");
                db.ExecuteNonQuery(@"CREATE INDEX User_Age ON Users (Age);");
                db.Keyspace.ClearCachedKeyspaceSchema();

                var family = db.GetColumnFamily<AsciiType>("Standard");
                var superFamily = db.GetColumnFamily<AsciiType, AsciiType>("Super");
                var userFamily = db.GetColumnFamily("Users");

                ResetFamily(family);
                ResetSuperFamily(superFamily);
                ResetUsersFamily(userFamily);
            }
        }
Ejemplo n.º 15
0
		public void CreateRecord_Doesnt_Check_BytesType_Zero_Length()
		{
			// arrange
			var db = new CassandraContext("Test1", "localhost");
			var family = db.GetColumnFamily<AsciiType>(FamilyName);
			
			// act
			// assert
			Assert.Throws<ArgumentException>(delegate {
				dynamic value = family.CreateRecord("");
			});
		}
Ejemplo n.º 16
0
        public _CassandraSetup()
        {
            var keyspaceName = "Testing";
            var server = new Server("localhost");

            if (CassandraSession.KeyspaceExists(server, keyspaceName))
                CassandraSession.DropKeyspace(server, keyspaceName);

            var keyspace = new CassandraKeyspace(keyspaceName);
            keyspace.TryCreateSelf(server);
            keyspace.TryCreateColumnFamily<AsciiType>(server, "Standard");
            keyspace.TryCreateColumnFamily<AsciiType, AsciiType>(server, "Super");
            keyspace.TryCreateColumnFamily<AsciiType>(server, "StandardAsciiType");
            keyspace.TryCreateColumnFamily<BytesType>(server, "StandardBytesType");
            keyspace.TryCreateColumnFamily<IntegerType>(server, "StandardIntegerType");
            keyspace.TryCreateColumnFamily<LexicalUUIDType>(server, "StandardLexicalUUIDType");
            keyspace.TryCreateColumnFamily<LongType>(server, "StandardLongType");
            keyspace.TryCreateColumnFamily<TimeUUIDType>(server, "StandardTimeUUIDType");
            keyspace.TryCreateColumnFamily<UTF8Type>(server, "StandardUTF8Type");
            keyspace.TryCreateColumnFamily<UUIDType>(server, "StandardUUIDType");
            keyspace.TryCreateColumnFamily<CompositeType<LongType, UTF8Type>>(server, "StandardCompositeType");
            keyspace.TryCreateColumnFamily<DynamicCompositeType>(server, "StandardDynamicCompositeType");

            DB = new CassandraContext(keyspaceName, server);
            DB.ThrowErrors = true;

            Family = DB.GetColumnFamily<AsciiType>("Standard");
            SuperFamily = DB.GetColumnFamily<AsciiType, AsciiType>("Super");

            Family.RemoveAllRows();
            SuperFamily.RemoveAllRows();

            Family.InsertColumn(TestKey1, "Test1", Math.PI);
            Family.InsertColumn(TestKey1, "Test2", Math.PI);
            Family.InsertColumn(TestKey1, "Test3", Math.PI);

            SuperFamily.InsertColumn(TestKey1, TestSuperName, "Test1", Math.PI);
            SuperFamily.InsertColumn(TestKey1, TestSuperName, "Test2", Math.PI);
            SuperFamily.InsertColumn(TestKey1, TestSuperName, "Test3", Math.PI);

            Family.InsertColumn(TestKey2, "Test1", Math.PI);
            Family.InsertColumn(TestKey2, "Test2", Math.PI);
            Family.InsertColumn(TestKey2, "Test3", Math.PI);

            SuperFamily.InsertColumn(TestKey2, TestSuperName, "Test1", Math.PI);
            SuperFamily.InsertColumn(TestKey2, TestSuperName, "Test2", Math.PI);
            SuperFamily.InsertColumn(TestKey2, TestSuperName, "Test3", Math.PI);
        }
		public CassandraDatabaseSetup(bool reset = false)
		{
			ConnectionBuilder = new ConnectionBuilder(keyspace: Keyspace, server: Server);
			DB = new CassandraContext(ConnectionBuilder);
			
			var exists = DB.KeyspaceExists(Keyspace);

			Family = DB.GetColumnFamily<AsciiType>("Standard");
			SuperFamily = DB.GetColumnFamily<AsciiType, AsciiType>("Super");
			UserFamily = DB.GetColumnFamily("Users");

			if (exists && !reset)
				return;

			ResetDatabase();
		}
Ejemplo n.º 18
0
		private static void SetupKeyspace()
		{
			using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
			{
				if (db.KeyspaceExists(KeyspaceName))
					db.DropKeyspace(KeyspaceName);

				var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema
				{
					Name = KeyspaceName,
				}, db);

				keyspace.TryCreateSelf();

				// create column family using CQL
				db.ExecuteNonQuery(@"
				CREATE COLUMNFAMILY Posts (
				KEY ascii PRIMARY KEY,
				Title text,
				Body text,
				Author text,
				PostedOn timestamp
				);");

				// create column family using API
				keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema
				{
					FamilyName = "Tags",
					KeyValueType = CassandraType.AsciiType,
					ColumnNameType = CassandraType.Int32Type,
					DefaultColumnValueType = CassandraType.UTF8Type
				});

				// create super column family using API
				keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema
				{
					FamilyName = "Comments",
					FamilyType = ColumnType.Super,
					KeyValueType = CassandraType.AsciiType,
					SuperColumnNameType = CassandraType.DateType,
					ColumnNameType = CassandraType.UTF8Type,
					DefaultColumnValueType = CassandraType.UTF8Type
				});
			}
		}
        public void ResetDatabase()
        {
            using (var session = new CassandraSession(ConnectionBuilder))
            using (var db = new CassandraContext(session))
            {
                db.ThrowErrors = true;
                db.TryDropKeyspace(Keyspace);

                var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema
                {
                    Name = Keyspace
                }, db);
                db.Keyspace = keyspace;

                keyspace.TryCreateSelf();

            }
        }
Ejemplo n.º 20
0
        public static void CreateTablesIfNotExists(CassandraContext db)
        {
            try
            {
                db.ExecuteNonQuery(string.Format(@"
            CREATE TABLE {0} (
             id     uuid,
             logic text,
             command text,
             hidden_till timestamp,
             PRIMARY KEY (id));
            ", TableName("main")));
            }
            catch (CassandraException) { }
            try
            {

                db.ExecuteNonQuery(string.Format(@"
            CREATE TABLE {0} (
             id     uuid,
             oid    uuid,
             progress double,
             last_access timestamp,
             PRIMARY KEY (id,oid));
            ", TableName("trans")));
            }
            catch (CassandraException) { }
            try
            {
                db.ExecuteNonQuery(string.Format(@"
            CREATE TABLE {0} (
             id     uuid,
             oid    uuid,
             what   int,
             when   timestamp,
             info   text,
             PRIMARY KEY (id,oid,what,when));
            ", TableName("out")));
            }
            catch (CassandraException) { }
        }
        public void Init()
        {
            _context = new CassandraContext(keyspace: DummiesKeySpace, host: "localhost");
            if (!_context.KeyspaceExists(DummiesKeySpace))
            {
                var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema
                {
                    Name = DummiesKeySpace,
                }, _context);
                keyspace.TryCreateSelf();
                _context.ExecuteQuery(
                    @"
                CREATE COLUMNFAMILY Dummies (
                KEY ascii PRIMARY KEY,
                Blob blob
                );");
                _context.SaveChanges();
            }

            _dummies = _context.GetColumnFamily("Dummies");
        }
Ejemplo n.º 22
0
        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();
            }
        }
        public GenericDatabaseSetup(bool reset = false)
        {
            ConnectionBuilder = new ConnectionBuilder(keyspace: Keyspace, server: Server, cqlVersion: CqlVersion.Cql3);
            DB = new CassandraContext(ConnectionBuilder);

            if (DB.KeyspaceExists(Keyspace))
                DB.DropKeyspace(Keyspace);

            var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema
            {
                Name = Keyspace,
            }, DB);

            var exists = DB.KeyspaceExists(Keyspace);
            if (!exists)
                keyspace.TryCreateSelf();

            if (exists && !reset)
                return;

            ResetDatabase();
        }
Ejemplo n.º 24
0
 public void TestInit()
 {
     var setup = new _CassandraSetup();
     _db = setup.DB;
 }
Ejemplo n.º 25
0
        private static void CreateColumnFamilyWithUUIDOperator()
        {
            using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
            {

                db.ExecuteNonQuery("CREATE TABLE TestCF (KEY text PRIMARY KEY) WITH comparator=uuid AND default_validation=text;");

                Guid columnName1 = GuidGenerator.GenerateTimeBasedGuid(DateTime.Now);

                Guid columnName2 = GuidGenerator.GenerateTimeBasedGuid(DateTime.Now);

                db.ExecuteNonQuery(string.Format("INSERT INTO TestCF (KEY, {0}, {1}) VALUES ('Key1', 'Value1', 'Value2')", columnName1, columnName2));

                List<ICqlRow> rows = db.ExecuteQuery("SELECT * FROM TestCF WHERE KEY = 'Key1'").ToList();

                Guid value = rows[0].Columns[1].ColumnName.GetValue<Guid>();

                ConsoleHeader("Returned data from db");
                ConsoleHeader(value.ToString());
            }
        }
Ejemplo n.º 26
0
        private static void UpdateFirstPost()
        {
            using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
            {
                var key = "first-blog-post";

                var postFamily = db.GetColumnFamily("Posts");

                // get the post back from the database
                ConsoleHeader("getting 'first-blog-post' for update");

                // query using API
                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();
            }
        }
Ejemplo n.º 27
0
        private static void TombstoneTest()
        {
            using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
            {

                db.ExecuteNonQuery("CREATE TABLE OfferReservation (KEY int PRIMARY KEY) WITH comparator = text AND default_validation = float");
                db.ExecuteNonQuery("INSERT INTO OfferReservation (KEY, '25:100') VALUES (5, 0.25)");
                db.ExecuteNonQuery("INSERT INTO OfferReservation (KEY, '25:101') VALUES (5, 0.25)");
                db.ExecuteNonQuery("DELETE '25:100' FROM OfferReservation WHERE KEY = 5");

                List<ICqlRow> rows = db.ExecuteQuery("SELECT '25:100' FROM OfferReservation WHERE KEY = 5").ToList();

            }
        }
Ejemplo n.º 28
0
        private static void ReadFirstPost()
        {
            using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
            {
                var key = "first-blog-post";

                var postFamily = db.GetColumnFamily("Posts");
                var tagsFamily = db.GetColumnFamily("Tags");

                // get the post back from the database
                ConsoleHeader("getting 'first-blog-post'");

                // query using API
                dynamic post = postFamily.Get(key).FirstOrDefault();

                // query using CQL-LINQ
                dynamic tags = (
                    from t in tagsFamily
                    where t.Key == key
                    select t).FirstOrDefault();

                // show details
                ConsoleHeader("showing post");
                Console.WriteLine(
                    String.Format("=={0} by {1}==\n{2}",
                        post.Title,
                        post.Author,
                        post.Body
                    ));

                // show tags
                ConsoleHeader("showing tags");
                foreach (var tag in tags)
                    Console.WriteLine(String.Format("{0}:{1}", tag.ColumnName, tag.ColumnValue));
            }
        }
Ejemplo n.º 29
0
        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;
                    }
                }
            }
        }
Ejemplo n.º 30
0
        private static void ReadAllPosts()
        {
            using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
            {
                var key = "first-blog-post";

                var tagsFamily = db.GetColumnFamily("Tags");

                // get the post back from the database
                ConsoleHeader("getting 'first-blog-post'");

                // query using CQL
                var posts = db.ExecuteQuery("SELECT * FROM Posts LIMIT 25");

                // query using API
                dynamic tags = tagsFamily.Get(key).FirstOrDefault();

                // show details
                ConsoleHeader("showing post");
                foreach (dynamic post in posts)
                {
                    Console.WriteLine(
                        String.Format("=={0} by {1}==\n{2}",
                            post.Title,
                            post.Author,
                            post.Body
                        ));
                }

                // show tags
                ConsoleHeader("showing tags");
                foreach (var tag in tags)
                    Console.WriteLine(String.Format("{0}:{1}", tag.ColumnName, tag.ColumnValue));
            }
        }