I want to get a array of ids from my database table as a one-dimensional array.
I've used QueryArrayConfig for my query string with the rowMode set to "array". I get my ids correctly, but it returns a two-dimensional array.
const idQuery: pg.QueryArrayConfig = {
name: 'get-ids',
text: 'SELECT id FROM MySchema.SomeTable'
rowMode: "array"
};
pool.query(idQuery).then((result: pg.QueryResult) => {
console.log(result.rows);
...
I get : [ [ 1 ], [ 2 ] ], but I need [1 , 2]. Is there a way to do this with my query directly? Or do I need to flatten my array after I get my results?
Edit :
If I remove rowMode: array, I get an array of javascript objects : [anonymous { id: 1 }, anonymous { id: 2 }], which doesn't give me what I need.