Skip to content
This repository has been archived by the owner on Mar 17, 2023. It is now read-only.

Commit

Permalink
feat: add neq, gt, gte, lt and lte methods (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangabriele committed Feb 20, 2020
1 parent d709ece commit 9981fe2
Show file tree
Hide file tree
Showing 8 changed files with 338 additions and 112 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ jobs:
- stage: Test
name: Unit Tests (v10)
node_js: "10"
install: yarn --frozen-lockfile
- stage: Test
name: Unit Tests (v12)
install: yarn --frozen-lockfile
after_script: ./node_modules/.bin/coveralls < ./coverage/lcov.info
after_script:
- npx codecov

- stage: Release
name: Github
Expand Down
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.2.0] - 2020-02-20

### Added

- `gt()` method.
- `gte()` method.
- `lt()` method.
- `lte()` method.
- `neq()` method.

## [1.1.1] - 2020-02-12

### Fixed
Expand All @@ -15,7 +25,7 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### Changed

- Deprecate `baseUri` option.
- Deprecated `baseUri` option.

### Fixed

Expand Down
142 changes: 100 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,45 @@
[![License][img-license]][link-license]
[![NPM Version][img-npm]][link-npm]
[![Build Status][img-travis]][link-travis]
[![Code Coverage][img-coveralls]][link-coveralls]
[![Code Coverage][img-codecov]][link-codecov]

JS/TS [PostgREST][link-postgrest] API Client.
[PostgREST][link-postgrest] API Client for Javascript and Typescript.

## Install
---

- [Gettting Started](#gettting-started)
- [Example](#example)
- [API](#api)
- [Options](#options)
- [Vertical Filtering (columns) Methods](#vertical-filtering-columns-methods)
- [select()](#select)
- [Hoizontal Filtering (rows) Methods](#hoizontal-filtering-rows-methods)
- [is()](#is)
- [eq()](#eq)
- [neq()](#neq)
- [gt()](#gt)
- [gte()](#gte)
- [lt()](#lt)
- [lte()](#lte)
- [in()](#in)
- [like()](#like)
- [ilike()](#ilike)
- [not](#not)
- [and](#and)
- [or](#or)
- [Ordering Methods](#ordering-methods)
- [orderBy()](#orderby)
- [Pagination Methods](#pagination-methods)
- [page()](#page)
- [Request Methods](#request-methods)
- [get()](#get)
- [post()](#post)
- [patch()](#patch)
- [delete()](#delete)
- [Contribute](#contribute)
- [License](#license)

## Gettting Started

```bash
npm i postgrester
Expand Down Expand Up @@ -58,40 +92,80 @@ When creating the instance via `postgrester.create([options])`:
> `baseUri` will be **deprecated** in the next minor version release and should be removed in the
> next major one.
### Query Methods
### Vertical Filtering (columns) Methods

#### select()

**Parameters**

| Name | Type | Default | Examples |
| ---------- | -------- | ------------ | ----------------------------------------- |
| `selector` | `string` | **required** | `"*"`, `"author"`, `"category(id,label)"` |

### Filter Methods
You can also rename them by inserting a colon: `original_column_name:new_column_name`.

#### is()
### Hoizontal Filtering (rows) Methods

**Parameters**
#### is()

| Name | Type | Default | Examples |
| -------- | ---------------- | ------------ | ------------------------------ |
| `column` | `string` | **required** | `"author"`, `"category.label"` |
| `value` | `boolean | null` | **required** | |
| Name | Type | Default | Examples |
| -------- | ----------------- | ------------ | ------------------------------ |
| `column` | `string` | **required** | `"author"`, `"category.label"` |
| `value` | `boolean \| null` | **required** | |

#### eq()

**Parameters**
| Name | Type | Default | Examples |
| ------------ | ------------------------------------- | ------------ | ------------------------------ |
| `column` | `string` | **required** | `"author"`, `"category.label"` |
| `value` | `boolean \| number \| null \| string` | **required** | `"Leo Tolstoy"` |
| `withQuotes` | `boolean` | `false` | |

| Name | Type | Default | Examples |
| ------------ | ------------------ | ------------ | ------------------------------ |
| `column` | `string` | **required** | `"author"`, `"category.label"` |
| `value` | `number \| string` | **required** | `"Leo Tolstoy"` |
| `withQuotes` | `boolean` | `false` | |
> **Note:** `boolean` and `null` values will be converted into an `is()`.
#### in()
#### neq()

| Name | Type | Default | Examples |
| ------------ | ------------------------------------- | ------------ | ------------------------------ |
| `column` | `string` | **required** | `"author"`, `"category.label"` |
| `value` | `boolean \| number \| null \| string` | **required** | `"Leo Tolstoy"` |
| `withQuotes` | `boolean` | `false` | |

> **Note:** `boolean` and `null` values will be converted into a **negated** `is()`.
#### gt()

| Name | Type | Default | Examples |
| ------------- | ------------------ | ------------ | --------------------------------------- |
| `column` | `string` | **required** | `"quantity"`, `"category.updated_at"` |
| `value` | `number \| string` | **required** | |
| `isInclusive` | `boolean` | `false` | |

#### gte()

| Name | Type | Default | Examples |
| -------- | ------------------ | ------------ | --------------------------------------- |
| `column` | `string` | **required** | `"quantity"`, `"category.updated_at"` |
| `value` | `number \| string` | **required** | |

> **Note:** This method is an alias for `gt()` with `<isInclusive>` set to `true`.
#### lt()

**Parameters**
| Name | Type | Default | Examples |
| ------------- | ------------------ | ------------ | --------------------------------------- |
| `column` | `string` | **required** | `"quantity"`, `"category.updated_at"` |
| `value` | `number \| string` | **required** | |
| `isInclusive` | `boolean` | `false` | |

#### lte()

| Name | Type | Default | Examples |
| -------- | ------------------ | ------------ | --------------------------------------- |
| `column` | `string` | **required** | `"quantity"`, `"category.updated_at"` |
| `value` | `number \| string` | **required** | |

> **Note:** This method is an alias for `lt()` with `<isInclusive>` set to `true`.
#### in()

| Name | Type | Default | Examples |
| ------------ | ------------------------- | ------------ | -------------------------------------- |
Expand All @@ -101,17 +175,13 @@ When creating the instance via `postgrester.create([options])`:

#### like()

**Parameters**

| Name | Type | Default | Examples |
| -------- | -------- | ------------ | ------------------------------ |
| `column` | `string` | **required** | `"author"`, `"category.label"` |
| `value` | `string` | **required** | `"Tolstoy"` |

#### ilike()

**Parameters**

| Name | Type | Default | Examples |
| -------- | -------- | ------------ | ------------------------------ |
| `column` | `string` | **required** | `"author"`, `"category.label"` |
Expand All @@ -138,12 +208,10 @@ This getter condition **ALL** the following filtering methods to be conjuncted a
For example, `postgrestClient.and.is("category_id", null).ilike("author", "dostoevsky")` will
**unite** both `is()` and `ilike()` filters.

### Sort Methods
### Ordering Methods

#### orderBy()

**Parameters**

| Name | Type | Default | Examples |
| -------- | --------- | ------------ | ------------------------------ |
| `column` | `string` | **required** | `"author"`, `"category.label"` |
Expand All @@ -153,21 +221,17 @@ For example, `postgrestClient.and.is("category_id", null).ilike("author", "dosto

#### page()

**Parameters**

| Name | Type | Default | Examples |
| ----------- | -------- | ------------ | ---------- |
| `pageIndex` | `number` | **required** | `0`, `123` |
| `limit` | `number` | `10` | |

### Call Methods
### Request Methods

All calling methods are asynchronous promises.
All request methods are asynchronous promises.

#### get()

**Parameters**

| Name | Type | Default | Examples |
| --------------- | --------- | ------------ | ---------- |
| path | `string` | **required** | `"/books"` |
Expand All @@ -189,8 +253,6 @@ Promise<{

#### post()

**Parameters**

| Name | Type | Default | Examples |
| ---- | -------- | ------------ | ---------- |
| path | `string` | **required** | `"/books"` |
Expand All @@ -203,8 +265,6 @@ Promise<void>

#### patch()

**Parameters**

| Name | Type | Default | Examples |
| ---- | -------- | ------------ | ---------- |
| path | `string` | **required** | `"/books"` |
Expand All @@ -217,8 +277,6 @@ Promise<void>

#### delete()

**Parameters**

| Name | Type | Default | Examples |
| ---- | -------- | ------------ | ---------- |
| path | `string` | **required** | `"/books"` |
Expand All @@ -239,13 +297,13 @@ This package and its sources are distributed under [Apache 2.0][link-license].

---

[img-coveralls]: https://img.shields.io/coveralls/github/SocialGouv/postgrester/master?style=flat-square
[img-codecov]: https://img.shields.io/codecov/c/github/SocialGouv/postgrester?style=flat-square
[img-license]: https://img.shields.io/badge/License-Apache%202.0-blue?style=flat-square
[img-npm]: https://img.shields.io/npm/v/postgrester?style=flat-square
[img-travis]: https://img.shields.io/travis/com/SocialGouv/postgrester/master?style=flat-square

[link-contributing]: https://github.com/SocialGouv/postgrester/blob/master/CONTRIBUTING.md
[link-coveralls]: https://coveralls.io/github/SocialGouv/postgrester
[link-codecov]: https://codecov.io/gh/SocialGouv/postgrester
[link-license]: https://github.com/SocialGouv/postgrester/blob/master/LICENSE
[link-npm]: https://www.npmjs.com/package/postgrester
[link-postgrest]: http://postgrest.org
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"archiver": "3.1.1",
"colors": "1.4.0",
"copyfiles": "2.2.0",
"coveralls": "3.0.9",
"jest": "25.1.0",
"keep-a-changelog": "0.10.0",
"numeral": "2.0.6",
Expand Down
Loading

0 comments on commit 9981fe2

Please sign in to comment.