private async Task HandleImpl(IVideoAdded busEvent) { // Record the id in our sample data tracking table PreparedStatement prepared = await _statementCache.NoContext.GetOrAddAsync("INSERT INTO sample_data_videos (videoid) VALUES (?)"); await _session.ExecuteAsync(prepared.Bind(busEvent.VideoId)).ConfigureAwait(false); }
private async Task HandleImpl(IVideoAdded video) { PreparedStatement[] prepared = await _statementCache.GetOrAddAllAsync( "INSERT INTO videos_by_tag (tag, videoid, added_date, userid, name, preview_image_location, tagged_date) VALUES (?, ?, ?, ?, ?, ?, ?) USING TIMESTAMP ?", "INSERT INTO tags_by_letter (first_letter, tag) VALUES (?, ?) USING TIMESTAMP ?"); // Create a batch for executing the updates var batch = new BatchStatement(); // We need to add multiple statements for each tag foreach (string tag in video.Tags) { // INSERT INTO videos_by_tag batch.Add(prepared[0].Bind(tag, video.VideoId, video.AddedDate, video.UserId, video.Name, video.PreviewImageLocation, video.Timestamp, video.Timestamp.ToMicrosecondsSinceEpoch())); // INSERT INTO tags_by_letter string firstLetter = tag.Substring(0, 1); batch.Add(prepared[1].Bind(firstLetter, tag, video.Timestamp.ToMicrosecondsSinceEpoch())); } await _session.ExecuteAsync(batch).ConfigureAwait(false); }