appsmithorg / appsmith

Platform to build admin panels, internal tools, and dashboards. Integrates with 25+ databases and any API.
https://www.appsmith.com
Apache License 2.0
34.6k stars 3.73k forks source link

[Feature]: Json Array / postgres text[] type handling #30077

Open thebadking opened 10 months ago

thebadking commented 10 months ago

Is there an existing issue for this?

Summary

image

I have this Array of string in postgres that represents multiple choices, they can't be an enum since they are different for every entry (the overlap is insignificant), and then they need to be parsed as such with a helper function to be inserted into postgres:

const data = JSON.parse(jsonInput);
const pgArray = `{${data.map(item => `"${item}"`).join(", ")}}`;

Field type Array makes a mess of it as it creates list of objects and this is not what we need and to be honest, if I am not mistaken there is a bug there at the moment because selecting it does not allow for inputting any values:

image

the input field for the value cant be clicked for some reason

A workaround I have currently is converting the list to a csv for easy human inputting:

return inputArray.map(item => ({"": item}));

and on the update query I convert it to a pgarray:

const items = inputArray.map(obj => `"${Object.values(obj)[0]}"`);
const pgArray = `{${items.join(", ")}}`;

Why should this be worked on?

Because it is a very common use of data types and a huge hassle at the moment on both projects that I have going with Appsmith and I can imagine it affects more people

Nikhil-Nandagopal commented 10 months ago

@thebadking to understand this correctly, you are looking to automatically handle text arrays so that when they are inserted, appsmith converts the javascript array into { "a", "b", "c" } Did I get that right?

thebadking commented 10 months ago

Yes, back and forward between the Postgres Array and appsmith array, because it requires conversion to insert to the DB