#Custom QueryResult type for pg-node(Postgres)

2 messages · Page 1 of 1 (latest)

compact orchid
#

I am trying to write a generic interface QueryResult so on db query the return result is not lost. Currently i am doing something like this:


interface QueryResult<T extends QueryResultRow> extends QueryResultBase {
  rows: T[];
}

export const dbquery = async <T>(
  text: string,
  params?: (string | number)[]
): Promise<QueryResult<T>> => {
  const res = await pool.query(text, params);
  return res;
};

// QueryResultRow type in index.d.ts
export interface QueryResultRow {
    [column: string]: any;
}

it seems to be working as I expect it, but i am getting "Type T doesn't satisfy the constraint QueryResultRow" error.

Could you please clarify what exactly this error means and what steps i could take to fix it?

compact orchid
#

ah i figured it out.