postgres add rows from array of objects

Viewed 14

So what I'm trying to do is take an array of objects that are similar to the rows stored in the db (minus the id since that's auto-generated). However, I can't seem to figure it out. I'm using node-postgres. It would go something like this

const fooObj:Omit<Food, fooId> = {
   // foodId omitted
   a: 'a',
   b: 'b',
   c: 'c'
}

const fooArr = [...] // array of above Foo objects

const {rows} = pool.query(format(
`
 INSERT INTO "foo" ("a","b","c")
 VALUES // insert properties into column from each obj in fooArr //
 RETURNING *
`,fooArr
))
0 Answers
Related