Search code examples
javascriptnode.jscoffeescriptsoda

SODA where clause - soda-js in node


In the soda-js package, in src/soda-js.coffee, I found the following:

# convenience functions for building where clauses, if so desired
expr =
  and: (clauses...) -> ("(#{clause})" for clause in clauses).join(' and ')
  or:  (clauses...) -> ("(#{clause})" for clause in clauses).join(' or ')

  gt:  (column, literal) -> "#{column} > #{handleLiteral(literal)}"
  gte: (column, literal) -> "#{column} >= #{handleLiteral(literal)}"
  lt:  (column, literal) -> "#{column} < #{handleLiteral(literal)}"
  lte: (column, literal) -> "#{column} <= #{handleLiteral(literal)}"
  eq:  (column, literal) -> "#{column} = #{handleLiteral(literal)}"

I have a function to query data:

function getData() {
    consumer.query()
    .withDataset('emea-ai2t')
    .limit(10000)
    .where() //what do I put here to query greater than x in a column? 
    .getRows()
        .on('success', function(rows) { console.log(rows); })
        .on('error', function(error) { console.error(error); });
}

How do I use the where convenience function to query for greater than x?

FYI, I'm trying to query for a floating timestamp greater than a certain value.

Thanks.


Solution

  • Of course, I just figured it out.

    var soda = require('soda-js');
    
    function getData() {
        consumer.query()
        .withDataset('emea-ai2t')
        .limit(10000)
        .where(soda.expr.gt('inc_datetime', '2017-01-26T13:23:00.000'))
        .getRows()
            .on('success', function(rows) { console.log(rows); })
            .on('error', function(error) { console.error(error); });
    }