@@ -7,20 +7,21 @@ export const client = new Client({
constmakeQuery=(cl:Client)=>({
pixelsWithinTimeframe:(start:Date,end:Date)=>{
returncl.query<DBPixel>(
`SELECT * FROM "Pixel" WHERE ("createdAt" >= $1 AND "createdAt" < $2) or ("deletedAt" >= $1 AND "deletedAt" < $2) ORDER BY "createdAt" ASC`,
[start,end]
`SELECT x, y, color, "createdAt", "deletedAt" FROM "Pixel" WHERE ("createdAt" >= $1 AND "createdAt" < $2) or ("deletedAt" >= $1 AND "deletedAt" < $2) ORDER BY "createdAt" ASC`,
[start,end],
);
},
existingPixelsBeforeTime:(end:Date)=>{
returncl.query<DBPixel>(
`SELECT * FROM "Pixel" WHERE "createdAt" < $1 AND "deletedAt" IS NULL ORDER BY "createdAt" ASC`,
[end]
`SELECT DISTINCT ON (x, y) x, y, color, "createdAt" FROM "Pixel" WHERE "createdAt" < $1 AND "deletedAt" IS NULL ORDER BY x, y, "createdAt" DESC`,
[end],
);
},
/** Batch: get all pixel history for a set of (x,y) positions, ordered by createdAt ASC per position.
* Used to avoid N+1 queries when resolving covering pixels for deleted pixels. */