How can I return a String Array of object value instead of objects with the key value? Supabase / Postgresql

141 views Asked by At

Is there a way to shove the value from likes into a string array rather than selecting the value inside an object as key pair?

Likes is the join table between the user and the item. (User_Id, Item_Id)

const { data: result, error }: ResultType = await supabase
  .from("items")
  .select(`id, title, description, price, images, likes (user_id)`);

Currently returns:

[
  {
    id: 61,
    title: 'Mustang',
    description: 'cool ford',
    price: 50000,
    images: [ 'd7677083-c72c-417b-926c-070bbdc05cf5' ],
    likes: [ [Object] ]
  }
]

Id prefer:

[
  {
    id: 61,
    title: 'Mustang',
    description: 'cool ford',
    price: 50000,
    images: [ 'd7677083-c72c-417b-926c-070bbdc05cf5' ],
    likes: [ '964b5270-c77d-48fc-b897-1744d470ed3c' ]
  }
]

The object looks like:

{ user_id: "964b5270-c77d-48fc-b897-1744d470ed3c" }

Can this be done in a DB function? If so, how would we achieve this in SQL?

0

There are 0 answers