PostgREST API Client.
npm i postgrester
import postgrester from "postgrester";
const postgrestClient = postgrester.create({
baseUri: "https://api.example.com"
});
(async () => {
const [data, pagesLength] = await postgrestClient
.select("*")
.select("author(first_name,last_name)")
.is("is_published", true)
.not.is("isbn", null)
.eq("publication_year", 1970)
.in("language_code", ["en-UK", "en-US"])
.ilike("title", "island")
.like("author.last_name", "Hemingway")
.orderBy("publication_year", true) // `true` = DESC
.orderBy("title")
.page(3, 25) // 4th page with 25 items per page
.get("/books", true); // `true` = require the total `pagesLength` value to be calculated
})();
When creating the instance via postgrester.create()
:
Property | Type | Default | Description |
---|---|---|---|
axiosConfig |
AxiosRequestConfig |
{} |
Axios config called with axios.create() . |
axiosInstance |
AxiosInstance |
null |
Axios custom instance. |
baseUri |
string |
"" |
API URL. |
⚠️ Important
If you specify theaxiosInstance
property, it's useless to set theaxiosConfig
one since it will be overridden by your instance. And if you use theaxiosConfig
property with thebaseUri
one, the providedbaseUri
will ooverride the axiosbaseURL
if you set it whithin youraxiosConfig
.
Parameters
Name | Type | Default | Examples |
---|---|---|---|
selector |
string |
required | "*" , "author" , "category(id,label)" |
Parameters
Name | Type | Default | Examples |
---|---|---|---|
column |
string |
required | "author" , "category.label" |
value |
`boolean | null` | required |
Parameters
Name | Type | Default | Examples |
---|---|---|---|
column |
string |
required | "author" , "category.label" |
value |
`number | string` | required |
withQuotes |
boolean |
false |
Parameters
Name | Type | Default | Examples |
---|---|---|---|
column |
string |
required | "author" , "category.label" |
value |
`Array<number | string>` | required |
withQuotes |
boolean |
false |
Parameters
Name | Type | Default | Examples |
---|---|---|---|
column |
string |
required | "author" , "category.label" |
value |
string |
required | "Tolstoy" |
Parameters
Name | Type | Default | Examples |
---|---|---|---|
column |
string |
required | "author" , "category.label" |
value |
string |
required | "tolstoy" |
This getter negates the next filter method.
For example, postgrestClient.not.is("category_id", null).ilike("author", "dostoevsky")
will negate
the is()
filter but not the ilike()
one.
This getter condition *all the next filter methods to be conjuncted as "ors".
For example, postgrestClient.not.is("category_id", null).ilike("author", "dostoevsky")
will negate
the is()
filter but not the ilike()
one.
This getter condition *all the next filter methods to be conjuncted as "ands".
Parameters
Name | Type | Default | Examples |
---|---|---|---|
column |
string |
required | "author" , "category.label" |
isDesc |
boolean |
false |
Parameters
Name | Type | Default | Examples |
---|---|---|---|
pageIndex |
number |
required | 0 , 123 |
limit |
number |
10 |
All calling methods are asynchronous promises.
Parameters
Name | Type | Default | Examples |
---|---|---|---|
path | string |
required | "/books" |
withPagesLength | boolean |
false |
Return value
Promise<{
data: any;
pagesLength: number; // -1 if the pages length was not requested or couldn't be calculated.
}>
Parameters
Name | Type | Default | Examples |
---|---|---|---|
path | string |
required | "/books" |
Return value
Promise<void>
Parameters
Name | Type | Default | Examples |
---|---|---|---|
path | string |
required | "/books" |
Return value
Promise<void>
Parameters
Name | Type | Default | Examples |
---|---|---|---|
path | string |
required | "/books" |
Return value
Promise<void>
yarn
- All Tests:
yarn test
- Lint Tests:
yarn test:lint
- Unit Tests:
yarn test:unit
- Unit Tests (watch):
yarn test:watch
npm version [major|minor|patch|preversion]
This will automatically tag, push, build and publish to Github & NPM.
{
"editor.formatOnSave": true,
"editor.rulers": [100],
"travis.pro": true
}
This package and its sources are distributed under Apache 2.0.