npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lexx-odata-query-builder

v1.20.0

Published

![GitHub package.json version](https://img.shields.io/github/package-json/v/lexxyar/lexx-odata-query-builder) ![GitHub](https://img.shields.io/github/license/lexxyar/lexx-odata-query-builder) ![GitHub all releases](https://img.shields.io/github/downloads/

Downloads

52

Readme

lexx-odata-query-builder

GitHub package.json version GitHub GitHub all releases

Contents

Installation

npm i lexx-odata-query-builder

Usage

Basic usage

const o = new QueryBuilder('http://site.com/odata/users')
o.build()

Output http://site.com/api/users

Or with custom query params

const o = new QueryBuilder('http://site.com/odata/users')
o.querySet('lang', 'en')
o.build()

Output http://site.com/api/users?lang=en

Ordering

Use order method to add order query parameters

Note: order method has an alias orderby

const o = new QueryBuilder('/users')
o.order(new QueryOrder('name1')).build()

Output http://site.com/odata/users?$orderby=name1 asc

Also, you can combine several order conditions

const o = new QueryBuilder('/users')
o.order(new QueryOrder('name1')).order(new QueryOrder('name2', QueryOrderDirection.DESC))
o.build()

Output /users?$orderby=name1 asc,name2 desc

Expanding

Use expand method to add expand query parameter

const o = new QueryBuilder('/users')
o.expand('company').build()

Output /users?$expand=company

Or combine several expand parameters

const o = new QueryBuilder('/users')
o.expand('company').expand('jobtitle').build()

Output /users?$expand=company,jobtitle

To add counter to expanding parameter, add true as second parameter of expand method

const o = new QueryBuilder('/users')
o.expand('emails', true).build()

Output /users?$expand=company($count=true)

Limiting

For limiting returned data, use limit and offset methods

Note: limit has an alias top offset has aliases skip and shift

const o = new QueryBuilder('/users')
o.top(7).skip(4).build()

Output /users?$top=7&$skip=4

Paging

To limit output data by page, use page method.

const o = new QueryBuilder('/users')
o.page(3).build()

Output /users?$top=10&$skip=20

By default, it has 10 records per page, but you free to change in via QueryBuilder configuration.

const o = new QueryBuilder('/users', {rowsPerPage: 5})
o.page(3).build()

Output /users?$top=5&$skip=10

Filtering

Use filter method to add constrains. QueryBuilder accept only one filter, but you free to use and and or methods of QueryFilter to combine them together.

const oFilter = new QueryFilter('gender', 'f')
oFilter.and('age', 16, QueryFilterSign.GT)
const o = new QueryBuilder('/users')
o.filter(oFilter).build()

Output /users?$filter=gender eq f and age gt 16

Filter operations

  • [X] EQ
  • [X] GT
  • [X] GE
  • [X] LT
  • [X] LE
  • [ ] NE
  • [X] SUBSTRINGOF
  • [X] STARTSWITH
  • [X] ENDSWITH

Counting

count method will add $count suffix to url

const o = new QueryBuilder('/users')
o.count().build()

Output /users/$count

Of course, you can use count with filter for example.

const oFilter = new QueryFilter('gender', 'f')
oFilter.and('age', 16, QueryFilterSign.GT)
const o = new QueryBuilder('/users')
o.filter(oFilter).count().build()

Output /users/$count?$filter=gender eq f and age gt 16

ID

ID is primary key of database. Use id method to create oData request for single entity.

const o = new QueryBuilder('/users')
o.id(4).build()

Output /users(4)

Select

Use select method to constrain returned fields

const o = new QueryBuilder('/users')
o.select(['id','name']).build()

Output /users?$select=id,name

Count

Use count method to get request for count value

const o = new QueryBuilder('/users')
o.count()

Output `/users/$count

Other-hand, if you want to make request of data with total count, you can use inlineCount method Use count method to get request for count value

const o = new QueryBuilder('/users')
o.inlineCount()

Output `/users?$count=true

File content

Getting the file content is extra path. It will not make effect to real oData server, but you can use it in development as ideology.

File content as-is

To get file content, call asFileContent method

const o = new QueryBuilder('/files')
o.id(4).asFileContent().build()

Output /files(4)/_file

Base64 encoded content

Sometimes needed to get base64 encoded content. Use asFileContentBase64 method to generate path

const o = new QueryBuilder('/files')
o.id(4).asFileContentBase64().build()

Output /files(4)/_file64