Skip to content

Commit

Permalink
Merge pull request #74 from raphiniert-com/christiaanwesterbeek-extra…
Browse files Browse the repository at this point in the history
…-headers-via-meta

Collection of new features of old pull requests
  • Loading branch information
scheiblr authored Apr 9, 2023
2 parents fa2f184 + 2877503 commit 2bd2a8c
Show file tree
Hide file tree
Showing 12 changed files with 472 additions and 170 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
Find all notable changes of this project in this file.

## unpublished (v2.0.0)
- package updates
### Improvements
- updated dependencies
- updated `urlBuilder` and integrated URL encoding

### New feature
- [#48](https://github.com/raphiniert-com/ra-data-postgrest/issues/48) solved by pull request [#55](https://github.com/raphiniert-com/ra-data-postgrest/pull/55), the create method should return the data returned by postgrest and not the posted data - @[christiaanwesterbeek](https://github.com/christiaanwesterbeek)
- [#39](https://github.com/raphiniert-com/ra-data-postgrest/pull/39), allow passing extra headers via meta for react-admin hooks - @[christiaanwesterbeek](https://github.com/christiaanwesterbeek)
- [#41](https://github.com/raphiniert-com/ra-data-postgrest/pull/41), allow columns filtering for getList and getManyReference - @[christiaanwesterbeek](https://github.com/christiaanwesterbeek)
- added support of [#41](https://github.com/raphiniert-com/ra-data-postgrest/pull/41) for other functions, but `create` and `updateMany`
- [#38](https://github.com/raphiniert-com/ra-data-postgrest/pull/38), Let the sort param in getList be optional - @[christiaanwesterbeek](https://github.com/christiaanwesterbeek)


## v1.2.1 - 2023-04-07
Expand Down
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,48 @@ const dataProvider = postgrestRestProvider(
);
```

### Passing extra headers via meta
Postgrest supports calling functions with a single JSON parameter by sending the header Prefer: params=single-object with your request according to its [docs](https://postgrest.org/en/stable/api.html#calling-functions-with-a-single-json-parameter).

Within the data provider one can add any kind of header to the request while calling react-admin hooks, e.g.:
```
const [create, { isLoading, error }] = useCreate(
'rpc/my-function',
{
data: { ... },
meta: { headers: { Prefer: 'params=single-object' } },
}
);
```

### Vertical filtering
Postgrest supports a feature of [Vertical Filtering (Columns)](https://postgrest.org/en/stable/api.html#vertical-filtering-columns). Within the react-admin hooks this feature can be used as in the following example:
```
const { data, total, isLoading, error } = useGetList(
'posts',
{
pagination: { page: 1, perPage: 10 },
sort: { field: 'published_at', order: 'DESC' }
meta: { columns: ['id', 'title'] }
}
);
```

Further, one should be able to leverage this feature to rename columns:
```
columns: ['id', 'somealias:title']
```
, to cast columns:
```
columns: ['id::text', 'title']
```
and even get bits from a json or jsonb column"
```
columns: ['id', 'json_data->>blood_type', 'json_data->phones']
```

**Note**: not working for `create` and `updateMany`.

## Developers notes

The current development of this library was done with node v19.10 and npm 8.19.3. In this version the unit tests and the development environment should work.
Expand Down
Loading

0 comments on commit 2bd2a8c

Please sign in to comment.