Suppose I have a class
class Dog {
id: number
legs: number
}
and a table with the same properties. I am using pg-promise to query from the database like so:
getDogs(): Promise<Dog[]> {
return obj.any('SELECT id, legs FROM Dog')
}
and I want to call this function like this:
const dogs: Dog[] = await Database.getDogs()
What I want is the result to automatically map to an array of dogs. Right now I have to iterate over the result and manually map each result and then add it to the array and I don't want to do this for every object I query from the database.