1 Commits
Author SHA1 Message Date
Tau 7b21a0bdae idz: Implement multi-page Garage fetch 2020-01-25 19:26:42 -05:00
4 changed files with 16 additions and 5 deletions
+1 -1
View File
@@ -10,6 +10,6 @@ export async function loadGarage(
return {
type: "load_garage_res",
cars: await w.car().loadAllCars(profileId),
cars: await w.car().loadCars(profileId, 10, req.fetchOffset),
};
}
+5 -1
View File
@@ -11,7 +11,11 @@ export type TeamSpec = Subtract<
export interface CarRepository {
countCars(profileId: Id<Model.Profile>): Promise<number>;
loadAllCars(profileId: Id<Model.Profile>): Promise<Model.Car[]>;
loadCars(
profileId: Id<Model.Profile>,
limit: number,
offset: number
): Promise<Model.Car[]>;
loadSelectedCar(profileId: Id<Model.Profile>): Promise<Model.Car>;
+9 -2
View File
@@ -40,11 +40,18 @@ export class SqlCarRepository implements CarRepository {
return parseInt(row!.result);
}
async loadAllCars(profileId: Id<Profile>): Promise<Car[]> {
async loadCars(
profileId: Id<Profile>,
limit: number,
offset: number
): Promise<Car[]> {
const loadSql = sql
.select("c.*")
.from("idz_car c")
.where("c.profile_id", profileId);
.where("c.profile_id", profileId)
.orderBy("selector asc")
.limit(limit)
.offset(offset);
const rows = await this._txn.fetchRows(loadSql);
+1 -1
View File
@@ -7,7 +7,7 @@ declare module "sql-bricks-postgres" {
}
interface LimitClause extends sql.SelectStatement {
offset(value: number): sql.Statement;
offset(value: number): sql.SelectStatement;
}
export interface PgInsertStatement extends sql.InsertStatement {