I am trying to do manual pagination using cassandra-driver npm module by storing pageState in session but it throws error TypeError has no copy method.

1,217 views
Skip to first unread message

Ravikant Sinha

unread,
Jan 28, 2015, 12:37:19 AM1/28/15
to nodejs-dr...@lists.datastax.com
Hi,

I am trying to do manual pagination using cassandra-driver npm module. Pagination works fine when I am storing pagestate in global variable  but when I store pagestate in session (using node.js express project), it throws error TypeError has no copy method.
Following is the snippet used in one of the routes in the express:

var options={pageState:req.session.pageStateMeta,prepare :  1 , fetchSize :  50};
var data=[];
var responseObj=DMUtil.Response();
cassandraClient.eachRow(query,[],options,function (n, row) {
          
            data.push(row);
        }, function (err, result) {
            // End callback.
            // Store the paging state.
          
            if(!err && result){
               
                req.session.pageStateMeta = result.meta.pageState;
              
            }
            responseObj.responseData=data;
            res.send(responseObj);
        });

In first call to this route  its getting data but in next call, its not able to use req.session.pageStateMeta  and throws following error
 [TypeError: Object 0,0,0,61,0,8,0,0,1,74,75,62,148,0,0,0,2,117,115,0,0,4,0,0,0,7,0,0,19,68,73,83,80,76,65,89,95,65,68,86,69,82,84,73,83,73,78,71,0,0,3,65,76,76,0,0,4,7,173,159,179,0,0,0,0,127,255,255,205 has no method 'copy']

Has anyone of you faced this issue.

Krassimir Fotev

unread,
Jan 28, 2015, 2:39:43 AM1/28/15
to nodejs-dr...@lists.datastax.com
We've exposed a nextPage method in the manual-paging cassandra-driver branch.
You call res.nextPage() to advance to the next chunk. It is far easier than storing and reusing state.

I still owe Jorge support for stream throttling. Will do as soon things on Peerbelt's side calm a bit (funding, team, clients).

Cheers, 

To unsubscribe from this group and stop receiving emails from it, send an email to nodejs-driver-u...@lists.datastax.com.

--
Krassimir Fotev
Founder, PeerBelt Inc



Ravikant

unread,
Jan 28, 2015, 3:38:02 AM1/28/15
to nodejs-dr...@lists.datastax.com
Thanks Krassimir for prompt reply.Could you please give small code snippet for the same ?. Basically its web app in express. So, things should work for concurrent user, that's here session is needed. It would be great, If you could suggest something better.

Thanks & Regards
Ravikant

Jorge Bay Gondra

unread,
Jan 28, 2015, 3:42:16 AM1/28/15
to nodejs-dr...@lists.datastax.com
Hi Ravikant,
In your case, you will need the actual pageState, so you are using it correctly except from one detail.
The pageState in the clientOptions is a Buffer and it looks like you are not providing one.

The easiest solution would be to store the pageState in an hex string and then reuse it.

Storing it in the session:

req.session.pageStateMeta = result.meta.pageState.toString('hex');

Use it:

var options={pageState: new Buffer(req.session.pageStateMeta, 'hex')};

Hope it helps,
Jorge

Ravikant

unread,
Jan 28, 2015, 3:56:45 AM1/28/15
to nodejs-dr...@lists.datastax.com
Thanks a lot Jorge. You made my  day.

Richard Armstrong

unread,
Mar 4, 2015, 5:59:25 AM3/4/15
to nodejs-dr...@lists.datastax.com
Hi Jorge,

On this same topic, when doing manual paging is there any way the client will let you know when you've reached the last page? 
I've found that when I using the pageState it will automatically loop back to the first page unless I manually write a break (i.e. if(firstId == currentId) then exit) 

Thanks
Richard

To unsubscribe from this group and stop receiving emails from it, send an email to nodejs-driver-user+unsub...@lists.datastax.com.

--
Krassimir Fotev
Founder, PeerBelt Inc



To unsubscribe from this group and stop receiving emails from it, send an email to nodejs-driver-user+unsub...@lists.datastax.com.



--

Thanks & Regards
Ravikant

To unsubscribe from this group and stop receiving emails from it, send an email to nodejs-driver-user+unsub...@lists.datastax.com.

Jorge Bay Gondra

unread,
Mar 4, 2015, 6:03:51 AM3/4/15
to nodejs-dr...@lists.datastax.com
Hi Richard,
Yes, when the pageState is null, there are no more pages. Having a not null pageState means that there are further result pages.
BTW: I will add it to the paging documentation, as it is not noted there.

Thanks,
Jorge

To unsubscribe from this group and stop receiving emails from it, send an email to nodejs-driver-u...@lists.datastax.com.

Richard Armstrong

unread,
Mar 4, 2015, 6:57:41 AM3/4/15
to nodejs-dr...@lists.datastax.com
Thanks Jorge, that makes life a lot easier!
--
Richard J Armstrong

Director


M: 
+44(0) 7983536940 T:  +44(0) 20 8123 1288 E: richard....@gimanzo.com Skype: r.j.armstrong
GIMANZO Systems Ltd 2013, 17 Camellia Place, Twickenham, TW2 7HZ

Jorge Bay Gondra

unread,
Mar 4, 2015, 9:15:58 AM3/4/15
to nodejs-dr...@lists.datastax.com

Richard Armstrong

unread,
Mar 4, 2015, 10:07:16 AM3/4/15
to nodejs-dr...@lists.datastax.com
Great thanks -  I realise the intention of this is for paging but it also is a great feature for batching - as a suggestion this is the api I ended up creating (hiding the internals of the pageState)

e.g. client.eachRow(query, [], { prepare :  1 , fetchSize :  1000 },  function (n, row) {

}, function(err, result, next){

next()
})

Am sure you have loads of other features to implement, but just thought which others might find useful.


Reply all
Reply to author
Forward
0 new messages