odata-parser

OData query string parser

npm install odata-parser
30 downloads in the last month

OData query string parser for node.js based on pegjs.

Installation

npm install odata-parser

Usage

var parser = require("odata-parser");

var ast = parser.parse("$top=10&$skip=5&$select")

util.inspect(ast)

will result in:

{ 
  '$top': 10,
  '$skip': 5,
  '$select': [ 'foo' ] 
}

Filters like:

parser.parse("$filter=Name eq 'John' and LastName lt 'Doe'")

results in:


{
    $filter: {
        type: 'and',
        left: {
            type: 'eq',
            left: {
                type: 'property',
                name: 'Name'
            },
            right: {
                type: 'literal',
                value: 'John'
            }
        },
        right: {
            type: 'lt',
            left: {
                type: 'property',
                name: 'LastName'
            },
            right: {
                type: 'literal',
                value: 'Doe'
            }
        }
    }
}

Using functions in filters

parser.parse("$filter=substringof('nginx', Servers)")

restuls in:

{
    $filter: {
        type: 'functioncall',
        func: 'substringof',
        args: [{
            type: 'literal',
            value: 'nginx'
        }, {
            type: 'property',
            name: 'Servers'
        }]
    }
}

License

MIT - qraftlabs - 2012

npm loves you