2.7.0 • Published 2 years ago

@lomray/typeorm-json-query v2.7.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

TypeORM JSON Query

Converting JSON query to TypeORM query builder.

npm GitHub GitHub package.json dependency version (dev dep on branch) semantic-release

Quality Gate Status Reliability Rating Security Rating Vulnerabilities Lines of Code Coverage

Install

npm i --save @lomray/typeorm-json-query

Usage

Pass request JSON query to TypeormJsonQuery.

Request:

POST http://127.0.0.1:3000
Content-Type: application/json

{
  "attributes": ["id", "param"], // or empty for select all
  "orderBy": { "id": "DESC", { "param": { "order": "ASC", "nulls": "last" } } },
  "relations": ["demo"],
  "where": { "id": 1, "or": [{ "param": "hello" }, { "param": "world" }] },
}

Server implementation:

import TypeormJsonQuery from '@lomray/typeorm-json-query';
import express from 'express';
import { getRepository } from 'typeorm';
import TestEntity from './entities/test-entity';

express()
  .get('/demo-endpoint', (req, res) => {
    const jsonQuery = req.body;
    const typeormQuery = TypeormJsonQuery.init({
      queryBuilder: getRepository(TestEntity).createQueryBuilder(),
      query: jsonQuery,
    });
    
    console.log(typeormQuery.toQuery().getSql());

    res.send('Ok.');
  });

Also, you can use IJsonQuery interface for support build JSON query on client side:

import { IJsonQuery } from '@lomray/typeorm-json-query';
import ITestEntity from './interfaces/i-test-entity';
import axios from 'axios';

const body: IJsonQuery<ITestEntity> = {
  relations: [{ name: 'test', where: { id: 1 } }],
  where: { and: [{ id: { '<': 5 } }, { param: { like: '%hello%' } }] },
};

axios.request({
  method: 'POST',
  body,
});

Check out tests/index-test.ts or src/index.ts for more info.

2.7.0

2 years ago

2.6.0

2 years ago

2.5.4

2 years ago

2.5.5

2 years ago

2.5.2

2 years ago

2.5.3

2 years ago

2.3.0

2 years ago

2.5.0

2 years ago

2.4.0

2 years ago

2.3.1

2 years ago

2.5.1

2 years ago

1.8.0

2 years ago

2.1.2

2 years ago

2.2.0

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

1.7.6

2 years ago

1.7.3

3 years ago

1.7.2

3 years ago

1.7.1

3 years ago

1.7.0

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.7.5

3 years ago

1.7.4

3 years ago

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.1

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago