Using nodejs 'cassandra-driver' prepared query with IN query
<p>This is a potential newbie question but I couldn't find an answer out in the wild.</p>

<p>I'm currently building a simple user event log of this form (some attributes elided to keep this simple): </p>

<pre><code>CREATE TABLE events.by_hour (
  level tinyint, /* 60 = FATAL, 10 = TRACE */
  hour int, /*  in YYYYMMDDHH format */
  insertion_time timeuuid,
  userid TEXT,
  message TEXT,
PRIMARY KEY ((type,hour),userid,insertion_time))
WITH CLUSTERING ORDER BY (userid ASC, insertion_time ASC);
</code></pre>

<p>I would like to make a prepared query to fetch all events optionally filtered by a given user over some set of levels ideally over the course of several hours.</p>

<p>I can easily build a query that queries a single level and hour:</p>

<pre><code>var cassandra = require('cassandra-driver');
var client = new cassandra.Client({contactPoints: ['127.0.0.1']});

var query 
    = 'SELECT * FROM events.by_hour 
      WHERE level IN (?) and hour IN (?) and userid = ?;';

var options = [ 10, 2016032117,'user_uuid' ];

client.execute(query, options, {
                    prepare: true
                }, function (err, result) {
                    // Do stuff... 
                    next(err);
                });
</code></pre>

<p>This works fine for a single hour and level. I would love to specify multiple hours and levels in the above query but playing with the code I'm unable to get that to work either by specifying the set as a string or as an array of values.</p>

<p>I think I'm forced to do something like this:</p>

<p>Build the query based upon the number of levels and hours are needed:</p>

<pre><code>// for 1 level and 2 hours:
query = 'SELECT * FROM events.by_hour 
      WHERE level IN (?) and hour IN (?,?) and userid = ?;';

options = [ 10, 2016032117,2016032118,'user_uuid' ];

client.execute(query, options, {
                    prepare: true
                }, function (err, result) {
                    // Do stuff... 
                    next(err);
                });

// for 2 levels and 2 hours:
query = 'SELECT * FROM events.by_hour 
      WHERE level IN (?,?) and hour IN (?,?) and userid = ?;';

options = [ 10, 20, 2016032117,2016032118,'user_uuid' ];

client.execute(query, options, {
                    prepare: true
                }, function (err, result) {
                    // Do stuff... 
                    next(err);
                });
</code></pre>

<p>I don't love this. BUT I can still get the benefits of prepared queries even here since we can just pass in 'prepared: true'. It feels like there should be a better way... but I'm not sure what I'm trying to do is even possible with single prepared query.</p>

<p>Can anyone lend some wisdom here?</p>

<p>Thanks!</p>