oneOrUndefined / singleOrNone
Closed this issue · 1 comments
phiresky commented
is missing
hediet commented
Introduced singleOrUndefined
:
public async singleOrUndefined<TRow extends Row>(query: Query<TRow, any>): Promise<MapOutType<TRow> | undefined> {
if (query instanceof RetrievalQuery)
query = query.limit(2);
const rows = await this.exec(query);
if (rows.length === 0) return undefined;
if (rows.length >= 2) throw new Error("More than one row returned.");
return rows[0];
}