Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/skynet2/ngx-odata
OData ts library
https://github.com/skynet2/ngx-odata
angular javascript odata odata-client odatav4 typescript-library
Last synced: about 1 month ago
JSON representation
OData ts library
- Host: GitHub
- URL: https://github.com/skynet2/ngx-odata
- Owner: skynet2
- License: mit
- Created: 2018-01-24T15:48:48.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-05-11T12:27:14.000Z (over 6 years ago)
- Last Synced: 2024-11-11T20:38:19.589Z (about 1 month ago)
- Topics: angular, javascript, odata, odata-client, odatav4, typescript-library
- Language: TypeScript
- Homepage:
- Size: 243 KB
- Stars: 10
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ngx-odata
Simple typescript library for generating odata queries using fluent api.[![NPM](https://nodei.co/npm/ngx-odata-v4.png)](https://nodei.co/npm/ngx-odata-v4/)
# Prerequisite
Can be used as typescript\javascript library. Angular is not required.# Installation
#### npm
```
npm install ngx-odata-v4
```
#### yarn
```
yarn add ngx-odata-v4
```
# Integration
1. Install library
2. Import Query class
```
import { Query } from "ngx-odata-v4";
```# Examples
Simple query example
```ts
Query.create()
.expand('Requester', o => o.select('Email', 'ID'))
.expand('Responder', o => o.select('Email', 'ID'))
.orderBy('Created', OrderBy.Desc)
.orderBy('Status', OrderBy.Desc);
```
Complex query example
```ts
Query.create()
.filter('Id', OperatorType.Greater, 1)
.filter('ReferenceId', OperatorType.Eq, 'c8027a81-5f7a-4a24-87a4-eec9afe48751')
.filterComplex(`Status eq 'Pending' or Status eq 'Approved'`)
.filter('Name', OperatorType.NotEqual, 'qwerty').compile();
```
Complex expand query example
```ts
Query.create()
.expand('Prop1')
.expand('Prop2', o => {
o.select('Id', 'Name', 'Value')
.orderBy('Id', OrderBy.Asc)
.top(5);
})
.expand('Complex', o => {
o.select('Id', 'Name')
.expand('Internal', i => {
i.select('Description', 'Requester')
.skip(5)
});
})
.select('RootId', 'RootName').compile()
```
Angular usage Example
```ts
const query = Query.create()
.expand('Requester', o => o.select('Email', 'ID'))
.expand('Responder', o => o.select('Email', 'ID'))
.orderBy('Created', OrderBy.Desc)
.orderBy('Status', OrderBy.Desc);let x = new HttpHeaders();
this.generatedUrl = `http://localhost/PrivateKey?${query.compile()}`;
this.resp = await this.http.get(this.generatedUrl,
{ headers: x }).toPromise()
```# GitHub
Please feel free to declare issues or contribute: https://github.com/skynet2/ngx-odata