/// <summary> /// Add a temperature information for a given weather station /// </summary> public void AddTemperature(string weatherStationId, decimal value) { var insertCql = @" INSERT INTO temperature_by_day (weatherstation_id, date, event_time, temperature) VALUES (?, ?, ?, ?)"; //Create an insert statement var insertStatement = new SimpleStatement(insertCql); //Bind the parameters to the statement insertStatement.Bind(weatherStationId, DateTime.Now.ToString("yyyyMMdd"), DateTime.Now, value); //You can set other options of the statement execution, for example the consistency level. insertStatement.SetConsistencyLevel(ConsistencyLevel.Quorum); //Execute the insert Session.Execute(insertStatement); }
/// <summary> /// Add a temperature information for a given weather station asynchronously /// </summary> public Task AddTemperatureAsync(string weatherStationId, decimal value) { //It is basically the same code as the AddTemperature //Except it returns a Task that already started but didn't finished //The row would not be in Cassandra yet when this method finishes executing. var insertCql = @" INSERT INTO temperature_by_day (weatherstation_id, date, event_time, temperature) VALUES (?, ?, ?, ?)"; //Create an insert statement var insertStatement = new SimpleStatement(insertCql); //Bind the parameters to the statement insertStatement.Bind(weatherStationId, DateTime.Now.ToString("yyyyMMdd"), DateTime.Now, value); //You can set other options of the statement execution, for example the consistency level. insertStatement.SetConsistencyLevel(ConsistencyLevel.Quorum); //Execute the insert return Session.ExecuteAsync(insertStatement); }