How to save Postgres Array type

System Information
  • Strapi: 3.4.1:
  • OS: MacOS Big Sur:
  • DB: Postgres via Docker:
  • Node: 14.13.1:
  • Npm: 6.14.8:
  • Yarn: 1.22.5:

I followed steps in Plugin’s front-end Field API docs for custom field for array type, and the UI for array type shows up. Next step is to save the Array type to DB, but I found no posts/guides about saving it to backend. I know Knexjs supports saving array type for Postgres https://stackoverflow.com/questions/50118196/how-to-insert-array-data-type-using-knex-and-potsgres/50118361

Now, I need to take the data from ui in text format or json format and transform to Array and save to db via Knex. And, of course, when showing the array data in ui, I need to transform Array to text or json so that it is easier to edit.

How do I do that? I searched for a while but found no docs or community posts about similar topics.

Looks like Knexjs has specificType, which allows Postgres Array Type . I made it work by adding columnType value as ‘text ARRAY’ in models folder. Just to change the columnType value as valid Postgres type, and you should be good to go.

Example:

"test": {
      "columnType": "text ARRAY",
    }

This would save the column as test[] in Postgres. I tested it, it works without any issues so far.

do know what i should do in v4 ?