ts-typed-sql icon indicating copy to clipboard operation
ts-typed-sql copied to clipboard

Allow getting result meta information

Open phiresky opened this issue 7 years ago • 1 comments

With pg you can get the number of updated / inserted rows like this:

const {rowCount} = await db.query("update ...."); without needing a RETURNING statement.

specifically, the return type of Query in pg is

export interface QueryResult {
    command: string;
    rowCount: number;
    oid: number;
    rows: any[];
}

This library always returns only the rows property of that interface, which is mostly what you want, but in some cases getting the rowCount is useful (e.g. for performance of not having to return an array).

phiresky avatar Feb 03 '18 16:02 phiresky

I think we can wrap db.query so:

let persons = await wrapped_query(from(Persons).select(Persons.$all));
// here we know the type of persons is (typeof Persons.obj)[]

// or no wrapped version
let persons: (typeof Persons.obj)[] = db.query(from(Persons).select(Persons.$all));

xialvjun avatar May 16 '19 02:05 xialvjun