# postgrest-syntax-builder

> [![CircleCI](https://circleci.com/gh/amoshydra/postgrest-syntax-builder.svg?style=svg)](https://circleci.com/gh/amoshydra/postgrest-syntax-builder) [![Known Vulnerabilities](https://snyk.io/test/github/amoshydra/postgrest-syntax-builder/badge.svg?targetF

Latest version **0.2.0** (published 2018-11-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install postgrest-syntax-builder
pnpm add postgrest-syntax-builder
yarn add postgrest-syntax-builder
bun add postgrest-syntax-builder
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2018-11-13 |
| First published | 2018-11-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 422.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Amos Wong |
| Maintainers | amoshydra |
| Keywords | postgrest, postgres, url, query, queries |

## Links

- npm: https://www.npmjs.com/package/postgrest-syntax-builder
- Repository: https://github.com/amoshydra/postgrest-syntax-builder
- Issues: https://github.com/amoshydra/postgrest-syntax-builder/issues
- npm.io page: https://npm.io/package/postgrest-syntax-builder

## Dependencies (1)

- [lodash-es](https://npm.io/package/lodash-es.md) ^4.17.11

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 0.2.0 (latest) — 2018-11-13
- 0.1.5 — 2018-11-06
- 0.1.4 — 2018-11-06
- 0.1.3 — 2018-11-06
- 0.1.2 — 2018-11-06
- 0.1.1 — 2018-11-05
- 0.1.0 — 2018-11-05

## README

# PostgREST Syntax Builder

[![CircleCI](https://circleci.com/gh/amoshydra/postgrest-syntax-builder.svg?style=svg)](https://circleci.com/gh/amoshydra/postgrest-syntax-builder)
[![Known Vulnerabilities](https://snyk.io/test/github/amoshydra/postgrest-syntax-builder/badge.svg?targetFile=package.json)](https://snyk.io/test/github/amoshydra/postgrest-syntax-builder?targetFile=package.json)
[![Maintainability](https://api.codeclimate.com/v1/badges/45829fe93b3b9e209ba4/maintainability)](https://codeclimate.com/github/amoshydra/postgrest-syntax-builder/maintainability)
[![codecov](https://codecov.io/gh/amoshydra/postgrest-syntax-builder/branch/master/graph/badge.svg)](https://codecov.io/gh/amoshydra/postgrest-syntax-builder)

[![npm](https://nodei.co/npm/postgrest-syntax-builder.png?downloads=true&downloadRank=true&stars=true)](https://www.npmjs.com/package/postgrest-syntax-builder)

This library implement the "Tables and Views" section listed here: http://postgrest.org/en/v5.1/api.html
- horizontal filtering
- vertical filtering
- ordering
- limits and pagination

# Install
```sh
npm install --save postgrest-syntax-builder
```

or

```sh
yarn add postgrest-syntax-builder
```

# Usage
Live example

[![Edit PostgREST Syntax Builder Example](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/k3pjrzv21v?expanddevtools=1&module=%2Fsrc%2Findex.js)

## Input
```js
import p from 'postgrest-syntax-builder'

// Input
const result = [
  p('age').gt(1),
  p.limit(30),
  p.not(
    p.and(
      p('age').gt(18),
      p('age').lt(24),
    )
  ),
]

// `result` is evaluated to an array of PostgrestSyntaxBuilder objects
[
  { param: 'age', value: 'gt.1' },
  { param: 'limit', value: '30' },
  { param: 'not.and', value: '(age=gt.18,age=lt.24)' },
]

// PostgrestSyntaxBuilder object extends the native String object, thus it can also be treated and used as String
[
  'age=gt.1',
  'limit=30',
  'not.and=(age=gt.18,age=lt.24)',
]
```


## Utility
A `reduce` function that transform this:
```js
p.reduce(...examples)
```

into this:
```js
{
  age: 'gt.1',
  limit: 30,
  'not.and': '(age=gt.18,age=lt.24)'
}
```

# Development

## Building from source
```
yarn build
```

## Run test
```
yarn test
```

# Run example
After the project is built, you can test each built target.

## With browser (ES module & UMD)
```
yarn example
```


## With node (CommonJS)
```
node example
```

# Publishing

This project uses CircleCI to test, build and publish to npm registry. This workflow will be triggered whenever a new version tag is made.

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