ts-typed-sql
ts-typed-sql copied to clipboard
Allow getting result meta information
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).
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));