项目作者: jin-qu

项目描述 :
:link: Jinqu Linq implementation
高级语言: TypeScript
项目地址: git://github.com/jin-qu/linquest.git
创建时间: 2018-09-05T21:27:14Z
项目社区:https://github.com/jin-qu/linquest

开源协议:MIT License

下载


linquest - Remote Linq implementation with Jinqu infrastructure

Build and Test
codecov
Codacy Badge
@jin-qu/linquest">@jin-qu/linquest/badge.svg" alt="Known Vulnerabilities" data-canonical-src="https://snyk.io/test/npm/@jin-qu/linquest" style="max-width:100%;">

@jin-qu/linquest"">npm version
@jin-qu/linquest"">npm downloads

GitHub issues
GitHub license
GitHub stars
GitHub forks

Written completely in TypeScript.

Installation

npm i @jin-qu/linquest

Let’s See

  1. // first, create a service
  2. const service = new LinqService('https://my.company.service.com/');
  3. // then create a query
  4. const query = service.createQuery<Company>('Companies');
  5. // execute the query
  6. const result = await query.where(p => p.Id > 5).toArrayAsync();

Request providers

Linquest uses fetch as default, you might need to use a polyfill.

To use a custom request provider, you need to implement IAjaxProvider interface from jinqu

  1. import { IAjaxProvider, AjaxOptions } from "jinqu";
  2. // implement the IAjaxProvider interface
  3. export class MyAjaxProvider implements IAjaxProvider {
  4. ajax<T>(o: AjaxOptions): Promise<T> {
  5. // implement this
  6. }
  7. }
  8. // inject provider to LinqService
  9. const service = new LinqService('https://my.company.service.com/', new MyAjaxProvider());

Code Generation

With code generation from a metadata (like Swagger or OpenAPI, you can really simplify the usage.

  1. // generated code
  2. export interface Company {
  3. id: number;
  4. name: string;
  5. createDate: Date;
  6. }
  7. export class CompanyService extends LinqService {
  8. constructor(provider?: IAjaxProvider) {
  9. super('https://my.company.service.com/', provider);
  10. }
  11. companies() {
  12. return this.createQuery<Company>('Companies');
  13. }
  14. }
  15. // and you can use it like this
  16. const service = new CompanyService();
  17. const query = service.companies().where(c => c.name !== "Netflix");
  18. const result = await query.toArrayAsync();

Old Browsers

linquest uses jinqu as a querying platform, if you want to use jinqu features with old browsers, please refer to jinqu documentation.

License

Linquest is under the MIT License.