raphiniert-com / ra-data-postgrest Goto Github PK
View Code? Open in Web Editor NEWreact admin client for postgREST
License: MIT License
react admin client for postgREST
License: MIT License
Hi there, thank you for this library.
I just noticed that there is a small bug in the update
method of the data-provider. It is extracting the id
from the params.data
object -- but there is no guarantee this field will exist there. This is also inconsistent with the other methods which all use params.id
/ params.ids
-- as specified in the react-admin docs.
I've created a PR with a fix: #20
Hope that's ok!
Hi there,
I have the following scenario, using version 2.0.0 alpha 3, referring to the just implemented #82.
In many scenarios I need to filter out data by two columns which could be an integer or null. I could do so with an @or operator (just beginning, so maybe I just don't know the right approach for that), but if I try to add multiple OR operators to the filters it only adds one of them in the request url.
I verified that postgrest allows this by using a custom curl request.
I don't want you to spend time on something that could just be my fault, my question is simply: has it been tested already (in which case I'll investigate on my side) or should I post what I've tried and experienced so far?
My current workaround is fairly stupid, I add the two filters to the request url in the dataprovider.
If it helps, I'm happy to test that and try around - just to get rid of any unnecessary workarounds. ;)
using postgrest
server-host = "!4"
server-port = 3001
and App.js
import postgrestRestProvider from 'ra-data-postgrest';
const dataProvider = postgrestRestProvider('http://localhost:3001');
gives index.js:1 Error: Network Error
at createError (createError.js:16)
at XMLHttpRequest.handleError (xhr.js:83)
when change posgrest to server-port = 80
it works
Thank you for the library, very useful.
As I understand, now filtering support only LIKE type of search. It would be great to have full-text search too (@@
operator in Postgres). Any plans for this?
There is a problem while calling rpc-endoints using compound key. it'll result in a and-clause.
Might require some refactor concerning the compound key functionality.
I would like to access to the Supabase tables but don't understand how to access with this plugin.
Actually, I get this :
const httpClient = (url, options = {}) => {
options.user = {
authenticated: true,
token: process.env.REACT_APP_SUPABASE_ANON
};
return fetchUtils.fetchJson(url, options);
};
const dataProvider = postgrestRestProvider(process.env.REACT_APP_SUPABASE_URL, httpClient);
return (
<Admin dataProvider={dataProvider}>
<Resource name="posts" list={ListGuesser} />
<Resource name="authors" list={ListGuesser} />
</Admin>
)
Si when I try to access to the data, I have this error message : No API key found in request
ra-data-postgrest/src/dataProvider/index.ts
Line 214 in c1677a8
line change to
}).then(({ json }) => ({ data: json.map(data => data.id) })),
fixes it for me
With my recent PR's I noticed code formatting is not enforced by something like prettier in this repo. I tried my best to format my changes to adhere to the current formatting, but it's not ideal. It makes for easier collaboration (and smaller PR's) if code formatting is enforced.
I propose to use prettier with the following .prettierrc config that adhere best to the current code formatting.
{
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false
}
npm ERR! node_modules/ra-core
npm ERR! peer ra-core@"^3.19.6" from @raphiniert/[email protected]
Currently, the create method simply returns what the posted data is (including the id returned by Postgrest). However the Prefer: 'return=representation' is passed in the request which means that Postgrest is going to return the data of the new record. So the create method should simply return the json and not { ...params.data, id: encodeId(json, primaryKey) }
I know the example rest implementation indeed shows returning the posted data, but our dataProvider specifically adds this Prefer: 'return=representation' header, so we know that Postgrest is going to return the data and we should use that for the response.
Thoughts?
Hi.
Firstly - thanks so much for this! Makes working with postgres a breeze!
With version 1.1.3 the single query URL ends with an ?id=eq.abc123 whereas in 1.1.5 it ends with ?id=abc123, and this causes an issue with my postgrest v7.0.1 instance. Am I doing something wrong?
If it's not me doing something stupid - I'm happy to work out the issue and do a PR!
Many Thanks,
Andy
Hi,
I'm currently injecting a static PostgREST token in the httpClient as specified in the documentation. However, it would be better to use DB user/password authentication to generate the token dinamically as described in https://postgrest.org/en/stable/how-tos/sql-user-management-using-postgres-users-and-passwords.html
Is there anything on the roadmap to enable this functionality?
Regards.
The limit
parameter is currently set to page * perPage - 1
but should be set to perPage
.
Indeed, the LIMIT
clause in PostgreSQL is defined as "no more than that many rows will be returned". See https://www.postgresql.org/docs/current/queries-limit.html.
When I try to filter something on my List using this filter:
filter={{ "name@ilike": "ticket"}}
Everything works fine and a URL is generated like so: &name=ilike.*ticket*
When I try to filter the embedded resources, like so:
filter={{ "prices.name@ilike": "ticket"}}
It results in the following URL, which is correct: &prices.name=ilike.*ticket*
However when I try to implement the same filter using a TextInput, everything breaks down:
<TextInput source="prices.name@ilike" label="search" />
Results in: prices=eq.%5Bobject+Object%5D
I'm trying to update a single record, and seems like ra-d-pg is performing a PATCH to the endpoint, with the ID / primary key in the payload:
PATCH /rest/v1/table?id=eq.1
{ id: 1, name: "foo" }
Because the id column was created with something like:
id INT GENERATED BY DEFAULT AS IDENTITY
and the above seems to be trying to update the id column, I'm getting this error:
column "id" can only be updated to DEFAULT
Is this expected behavior?
I'm not sure the optimal path here as it may vary by field and table. Any thoughts on how granular to get here? I'm thinking something similar to defaultOp but we could get fancier with per table or field configuration. For my specific use case I'd like to always use nullslast
which would work with a single bool but I suspect that's not enough for others.
From the Postgrest docs:
When certain columns are wide (such as those holding binary data), it is more efficient for the server to withhold them in a response. The client can specify which columns are required using the select parameter.
https://postgrest.org/en/stable/api.html#vertical-filtering-columns
Let's do this.
When using npm run build
with react-admin v4 and current version of ra-data-postgrest
there is a build issue due to differing ra-core
version usages. As a result, trying to compile using npm run build
results in needing to use react-admin v3.19
instead of the latest v4.x
.
Two forks I've found that seem to have implemented this update - unsure about whether they work or not as my investigation has been quite superficial at this point. Hoping to spend some time this weekend testing version updates for myself to ensure functionality, and hopefully open a PR for updating dependencies to match react-admin
.
https://github.com/Exact-Realty/ra-data-postgrest
https://github.com/milutinovici/ra-data-postgrest
EDIT: It seems there is currently a PR open as well with the version updates for react-admin
compatibility when using npm run build
: #30
It's not a issue, only a question :
I'm using Compound key with ShowView but I'm not very proud of my code
const RowClick = (id, basePath, record) => {
return `/myresource/${JSON.stringify([record.name,record.category] )}/show`;
}
const MyResourceList = (props) => (
<List {...props}>
<Datagrid rowClick={RowClick}>
<TextField source="name" />
</Datagrid>
</List>
);
Is there a better way to do it ? Any opinions would be greatly appreciated... :)
We've got an issue where tables or views with computed columns don't update correctly as the update method is sending all the fields even ones that haven't changed (e.g. computed fields). I've solved this in a patch via diffing field values before update to only send changed fields. I can start a PR if you are interested.
Hi !
I've set up a postgrest API following their tutorial. It works surprisingly well, but is not fully compatible with the authProvider in this repo, as the subzero starterkit does things slightly differently than vanilla postgrest :
api.example.com/rpc/login
instead of /rest/rpc/login
)./me
dict with user information for subzero, {token: "xxx.yyy.zzz"}
for vanilla postgrest). It is possible to get user information by decoding the token client side. So it's a matter of storing the token (for reuse in the restProvider) and decoding the token client side (for use in getPermissions).In the readme, you say you're open to contribution from that. How would you see that ? An alternative authProvider, or some settings/callbacks to customize behaviour ?
This repo is about querying data and is probably used in many productional apps. When adding PR's with new feature, like I've been doing today, we really need unit tests so that we can confidently merge such PR's.
Example:
When defining a filter:
const AowSelectInput = (props: AutocompleteArrayInputProps) => {
const { data, isLoading } = useGetList('areas_of_work', {
pagination: { page: 1, perPage: Number.MAX_SAFE_INTEGER },
sort: { field: 'name', order: 'asc' },
meta: { columns: ['id', 'name'] },
});
return (
<AutocompleteArrayInput
choices={data}
isLoading={isLoading}
source="aow_ids"
{...props}
/>
);
};
const ProjectFilters = (props: any) => {
return (
<Filter {...props}>
<AowSelectInput label="AoWs" source="aow_ids@cs" />
...
</Filter>
);
};
When applied to a single id, no problem but adding a second id the url is formed like:
'http://localhost:3000/projects?offset=0&limit=50&aow_ids=cs.17%2C29&order=name.asc'
(note: aow_ids=cs.17,29
)
It should be: aow_ids=cs.{17,29}
(note: parenthesis)
I'm trying to use ReferenceField with UUID
<ReferenceField source="customer" reference="customers">
<TextField source="id" />
</ReferenceField>
In the API, customer field is an UUID (fac9062f-2e20-41c6-a74a-d2d8871025a3) :
[
{
"id": "12a36bc8-85a7-46a5-9df5-15389eeffd96",
"amount": 125.55,
"customer": "fac9062f-2e20-41c6-a74a-d2d8871025a3"
}
]
I looked in the console and instead of calling something like that :
http://localhost:3000/customers?id=in.(fac9062f-2e20-41c6-a74a-d2d8871025a3)
It's calling something like that :
I think this is this line that's causing the bug :
ra-data-postgrest/src/dataProvider/index.ts
Line 111 in fcb78b0
See my PR #4
Hi, when trying to use the package I am getting the following error:
Failed to compile.
./src/App.js
Module not found: Can't resolve '@raphiniert/ra-data-postgrest' in '/home/ag/git/rexample/admin/src'
Followed these steps:
$ npx create-react-app admin
$ cd admin
$ npm install react-admin ra-data-json-server prop-types
$ npm install --save @raphiniert/ra-data-postgrest
The package is present in the node_modules directory:
$ pwd
/home/ag/git/rexample/admin
$ ls node_modules/@raphiniert/ra-data-postgrest/
CHANGELOG.md LICENSE node_modules package.json README.md src
Then added the postgrestRestProvider line to the ReactAdmin example in src/App.js:
import React from 'react';
import { Admin, Resource, ListGuesser } from 'react-admin';
import jsonServerProvider from 'ra-data-json-server';
import postgrestRestProvider from '@raphiniert/ra-data-postgrest';
const dataProvider = jsonServerProvider('https://jsonplaceholder.typicode.com');
const App = () => (
<Admin dataProvider={dataProvider}>
<Resource name="users" list={ListGuesser} />
</Admin>
);
export default App
Nodejs version is v12.16.3
Any idea what I am missing? Sorry I have few experience in Nodejs and React.
Would it make more sense to release a version 3.x and 4.x of this repo s.t. the delineation to match versions with react-admin
?
Consider a list which displays all brands , having columns (brand_name,brand_id), while updating the data below is the sample request body is getting fired to PostgRest
{
"brand_id":"88ed8a29-88ed-422e-8755-88ed577fa8be",
"brand_name":"Nike",
"id":"88ed8a29-88ed-422e-8755-88ed577fa8be"
}
Ideally the id shouldn't be present since this id column wont be available in db.
May be we should perform delete params.data.id while sending an update request
Hi !
I need a simple date range filter like this :
<Filter {...props}>
<DateInput label="After" source="date@gte" alwaysOn />
<DateInput label="Before" source="date@lte" alwaysOn />
</Filter>
But it doesn't work, only one of the two is kept : http://127.0.0.1:3000/items?date=lte.2020-02-01
It seems that this is the reason : https://github.com/raphiniert-com/ra-data-postgrest/blob/master/src/dataProvider/index.ts#L49
in react-admin document, using 'q' in searchinput component to implement full text filter, how to do that in ra-data-postgrest?
thanks
I'm using ra-supabase
which uses this library under the hood. Whenever i call updateMany
function, Supabase server returns 400 http error with response {"code":"21000","details":null,"hint":null,"message":"UPDATE requires a WHERE clause"}
. I guess it's because to bulk update in postgrest we should pass ids into url params like this id=in.(123,456,789)
instead of body
Is there any way to use a different schema from public?
I didn't see an obvious way to do this; not sure if the limitation is in this package or supabase.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.