# rollun-ts-rql

> RQL query object and serializer written in TypeScript

Latest version **0.10.0** (published 2023-06-27) · ISC license · 0 weekly downloads

## Install

```sh
npm install rollun-ts-rql
pnpm add rollun-ts-rql
yarn add rollun-ts-rql
bun add rollun-ts-rql
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.10.0 |
| Published | 2023-06-27 |
| First published | 2018-12-04 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 499.9 KB |
| Known vulnerabilities | 0 (+4 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | rollun-com |
| Keywords | rql, typescript, rollun |

## Links

- npm: https://www.npmjs.com/package/rollun-ts-rql
- Repository: https://github.com/rollun-com/rollun-ts-rql
- Homepage: https://github.com/rollun-com/rollun-ts-rql#readme
- Issues: https://github.com/rollun-com/rollun-ts-rql/issues
- npm.io page: https://npm.io/package/rollun-ts-rql

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [locutus](https://npm.io/package/locutus.md) ^2.0.15

## Alternatives

- [apollo-link-http-common](https://npm.io/package/apollo-link-http-common.md) — 879.0K weekly downloads
- [react-relay](https://npm.io/package/react-relay.md) — 336.8K weekly downloads
- [relay-test-utils](https://npm.io/package/relay-test-utils.md) — 181.6K weekly downloads
- [@vendure/core](https://npm.io/package/@vendure/core.md) — 14.8K weekly downloads
- [@pnpm/deps.graph-sequencer](https://npm.io/package/@pnpm/deps.graph-sequencer.md) — 13.4K weekly downloads

## Recent versions

- 0.10.0 (latest) — 2023-06-27
- 0.9.4 — 2021-01-14
- 0.9.3 — 2020-10-26
- 0.9.2 — 2020-10-12
- 0.9.1 — 2020-10-12
- 0.9.0 — 2020-10-12
- 0.8.1 — 2020-10-11
- 0.8.0 — 2020-10-02
- 0.6.1 — 2020-07-16
- 0.7.3 — 2020-06-05
- 0.7.2 — 2020-06-05
- 0.7.1 — 2020-03-31
- 0.6.13 — 2020-02-05
- 0.6.12 — 2020-01-29
- 0.6.11 — 2020-01-29
- … 27 more at https://npm.io/package/rollun-ts-rql/versions

## README

![Coverage badge](https://img.shields.io/badge/Coverage%20Statements-91.42%25-green.svg)
![Coverage badge](https://img.shields.io/badge/Coverage%20Lines-91.25%25-green.svg)
![Coverage badge](https://img.shields.io/badge/Coverage%20Functions-78.98%25-orange.svg)
![Coverage badge](https://img.shields.io/badge/Coverage%20Branches-82.49%25-green.svg)

# rollun-ts-rql
RQL library written in Typescript.
This library contains:
* Set of objects that represent RQL nodes
* Stringifier that converts object tree into RQL string
## Installation
preferred way to install this library is via npm.
Run

```
npm install rollun-ts-rql
```

## Basic usage
```typescript
import { QueryStringifier } from 'rollun-ts-rql';
import { Query } from 'rollun-ts-rql';
import { Select } from 'rollun-ts-rql';
import { And } from 'rollun-ts-rql';
import { Eq } from 'rollun-ts-rql';
import { Ge } from 'rollun-ts-rql';

const query = new Query({
    select: new Select(['id', 'name', 'age', 'city']),
    query: new And([
        new Eq('name', 'John'),
        new Ge('age', 18)
    ])
});
const rqlString = QueryStringifier.stringify(query);
console.log(rqlString);

// using builder pattern

const query = new Query()
  .addSelect(new Select(['id', 'name', 'age', 'city']))
  .addQuery(new And([
	new Eq('name', 'John'),
	new Ge('age', 18)
  ]))
  // {
	// select: new Select(['id', 'name', 'age', 'city']),
	// query: new And([
	// 	new Eq('name', 'John'),
	// 	new Ge('age', 18)
	// ])
// });
const rqlString = QueryStringifier.stringify(query);
console.log(rqlString);
//output: select(id,name,age,city)&and(eq(name,John),ge(age,18))
```

## Nodes
Scalar nodes:
* eq - new Eq(&lt;field>,&lt;value>)
* ne - new Ne(&lt;field>,&lt;value>)
* lt - new Lt(&lt;field>,&lt;value>)
* gt - new Gt(&lt;field>,&lt;value>)
* le - new Le(&lt;field>,&lt;value>)
* ge - new Ge(&lt;field>,&lt;value>)
* like - new Like(&lt;field>,&lt;value>)
* alike - new Alike(&lt;field>,&lt;value>)

Array Nodes
* in - new In(&lt;field>,&lt;array of values>)
* out - new Out(&lt;field>,&lt;array of values>)

Logic operators
* and - new And(&lt;array of nodes>)
* or - new Or(&lt;array of nodes>)
* not - new Not(&lt;array of nodes>)

Aggregate nodes
* groupby - new GroupBy(&lt;array of values>)

## Query to string
QueryStringifier exposes static method `stringify`, that takes a node
and returns a string representation of that node
```typescript
import { QueryStringifier } from 'rollun-ts-rql';

const rqlString = QueryStringifier.stringify(
    new Query({
        query: new And([
            new Eq('status', 'active'),
            new Eq('age', 33)
        ])
    })
);
console.log(rqlString);
//output: and(eq(status,active),eq(age,33))
```

## Contributing

Before contributing to this lib, make sure you have correct node.js version. It is specified in `.nvmrc` file

You can use [NVM](https://github.com/nvm-sh/nvm) to manage node versions.

For example, run following command to automatically use correct node version:

```shell
nvm use
```

---
_Source: https://npm.io/package/rollun-ts-rql · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
