Example #1
0
function getLast(cf, limit, callback){    
    if(arguments.length != 3)
        return callback('Error: Wrong number of arguments. 3 required');
    var self = this;
    var cql = 'SELECT FIRST ' + limit + ' ?..? FROM ' + cf +' WHERE KEY = ?;';
    var date = new Date();
    self.params = [    
        helenus.TimeUUID.fromTimestamp(date),
        helenus.TimeUUID.fromTimestamp(getMidnigth(date)),
        getTextDate(date)
    ];
    var results = [];
    var count = 0;
    var recGet = function(){
        //console.log(cql, [date, getMidnigth(date), getTextDate(date)])
        genericQuery(cql, self.params, function(err, res){
            if(err)
                return callback(err, null);
            for(var i in res)
                results.push(res[i]);
            if(results.length < limit && ++count < 90){
                date = new Date(date.setDate(date.getDate() - 1));
                self.params = [
                    helenus.TimeUUID.fromTimestamp(new Date()),
                    helenus.TimeUUID.fromTimestamp(getMidnigth(date)),
                    getTextDate(date)
                ];
                return recGet();
            }        
            return callback(null, results);            
        });    
    }
    recGet(); 
}
Example #2
0
 genericQuery(cql, self.params, function(err, res){
     if(err)
         return callback(err, null);
     for(var i in res)
         results.push(res[i]);
     if(results.length < limit && ++count < 90){
         date = new Date(date.setDate(date.getDate() - 1));
         self.params = [
             helenus.TimeUUID.fromTimestamp(new Date()),
             helenus.TimeUUID.fromTimestamp(getMidnigth(date)),
             getTextDate(date)
         ];
         return recGet();
     }        
     return callback(null, results);            
 });    
Example #3
0
        genericQuery(cql, self.params, function(err, res){
            if(err)
                return callback(err, null);
            for(var i in res)
                results.push(res[i]);

            if(results.length < limit && ++count < 90){
                date = new Date(date.setDate(date.getDate() - 1));
                self.params = [    
                    helenus.TimeUUID.fromTimestamp(new Date(timestamp)),
                    helenus.TimeUUID.fromTimestamp(new Date(1970,1,1)),
                    getTextDate(date)
                ];
                return recGet();
            }
            //TODO fix loop problem when go to the last row            
            return callback(null, results);            
        });    
Example #4
0
function getNext(timestamp, cf, limit, callback){
    if(arguments.length != 4)
        return callback('Error: Wrong number of arguments. 3 required');
    var self = this;
    var cql = 'SELECT FIRST ' + limit + ' ?..? FROM ' + cf +' WHERE KEY = ?;';
    var date = new Date(timestamp);
    self.params = [    
        helenus.TimeUUID.fromTimestamp(new Date()),
        helenus.TimeUUID.fromTimestamp(date),
        getTextDate(new Date())
    ]; 
    //console.log(cql, [new Date(), date, getTextDate(new Date())])
    genericQuery(cql, self.params, function(err, res){
        if(err)
            return callback(err, null);
        return callback(null, res);
    });    
     
}
Example #5
0
function getRange(start, end, cf, limit, callback){
    if(arguments.length != 3)
        return callback('Error: Wrong number of arguments. 3 required');
    var self = this;
    var cql = 'SELECT FIRST ' + limit + ' ?..? FROM ' + cf +' WHERE KEY = ?;';
    var date = new Date(start);
    self.params = [    
        helenus.TimeUUID.fromTimestamp(end),
        helenus.TimeUUID.fromTimestamp(start),
        getTextDate(start)
    ];
    var results = [];
    var recGet = function(){
        //console.log(cql, [date, getMidnigth(date), getTextDate(date)])
        genericQuery(cql, self.params, function(err, res){
            if(err)
                return callback(err, null);

            for(var i in res)
                results.push(res[i]);

            if(results.length < limit){
                date = new Date(date.setDate(date.getDate() - 1));
                self.params = [
                    helenus.TimeUUID.fromTimestamp(end),
                    helenus.TimeUUID.fromTimestamp(start),
                    getTextDate(date)
                ];
                return recGet();
            }
            //TODO fix loop problem when go to the last row            
            return callback(null, results);            
        });    
    }
    recGet();
}