Exemple #1
0
		public async Task<List<string>> Get(string appId, string itemId, string relation, string userId)
		{
			using (var conn = new CqlConnection(_connString))
			{
				await conn.OpenAsync().ConfigureAwait(false);
				var query = string.Format(
					System.Globalization.CultureInfo.InvariantCulture,
					"select values from negrapi.relations where app_id = '{0}' and item_id='{1}' and relation='{2}';",
					appId,
					GetKey(itemId, userId),
					relation);

				var cmd = new CqlCommand(
					conn,
					query,
					CqlConsistency.One);

				var result = await cmd.ExecuteScalarAsync().ConfigureAwait(false) as string;

				if (string.IsNullOrEmpty(result))
				{
					return null;
				}

				var list = JsonConvert.DeserializeObject<List<RecommendationsDataValue>>(result);
				return list
					.Select(i => i.ItemId)
					.ToList();
			}
		}
Exemple #2
0
        public async Task SelectScalarNoValue()
        {
            //Assume
            const string retrieveCql = @"select value from Test.BasicFlow where id=10001;";

            //Act
            using(var connection = new CqlConnection(ConnectionString))
            {
                await connection.OpenAsync();

                //select data
                var selectCmd = new CqlCommand(connection, retrieveCql, CqlConsistency.One);
                string value = (string)await selectCmd.ExecuteScalarAsync();

                //if row does not exist value should be null
                Assert.IsNull(value);
            }
        }
Exemple #3
0
        public async Task SelectScalarNullValue()
        {
            //Assume
            const string insertCql = @"insert into Test.BasicFlow (id) values (2001);";
            const string retrieveCql = @"select value from Test.BasicFlow where id=2001;";

            //Act
            using(var connection = new CqlConnection(ConnectionString))
            {
                await connection.OpenAsync();

                //insert data
                var cmd = new CqlCommand(connection, insertCql, CqlConsistency.One);
                await cmd.ExecuteNonQueryAsync();

                //select data
                var selectCmd = new CqlCommand(connection, retrieveCql, CqlConsistency.One);

                object value = await selectCmd.ExecuteScalarAsync();
                Assert.AreEqual(DBNull.Value, value);
            }
        }
Exemple #4
0
        public async Task BasicInsertSelectScalar()
        {
            //Assume
            const string insertCql = @"insert into Test.BasicFlow (id,value) values (1001,'Hallo 1001');";
            const string retrieveCql = @"select value from Test.BasicFlow where id=1001;";

            //Act
            using(var connection = new CqlConnection(ConnectionString))
            {
                await connection.OpenAsync();

                //insert data
                var cmd = new CqlCommand(connection, insertCql, CqlConsistency.One);
                await cmd.ExecuteNonQueryAsync();

                //select data
                var selectCmd = new CqlCommand(connection, retrieveCql, CqlConsistency.One);

                string value = (string)await selectCmd.ExecuteScalarAsync();
                Assert.AreEqual("Hallo 1001", value);
            }
        }