Fix session timeline query, bump to 0.2.1
getSessionTimeline() grouped/ordered by a bare `bucket` identifier, assuming SQLite would resolve it against the SELECT list's alias - it doesn't in this generated query, so every /sessions/:id page and /api/stats/sessions/:id/timeline request failed with "no such column: bucket". Fixed by reusing the actual bucket expression object in groupBy/orderBy instead of referencing it by name. Verified against a seeded session - previously every request, now correct bucketed data. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W8WkFF5ppURBAB918593Eb
This commit is contained in:
@@ -37,9 +37,15 @@ export async function getSessionsSummary() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getSessionTimeline(playSessionId: number, bucketMs = 1000) {
|
export async function getSessionTimeline(playSessionId: number, bucketMs = 1000) {
|
||||||
|
// Reuse the same expression object (not a `sql`bucket`` alias reference)
|
||||||
|
// in groupBy/orderBy - drizzle doesn't emit a literal `AS bucket` that
|
||||||
|
// SQLite's GROUP BY/ORDER BY could resolve a bare "bucket" identifier
|
||||||
|
// against, so referencing it by name causes "no such column: bucket".
|
||||||
|
const bucket = sql<number>`(${sessionEvents.tsMs} / ${bucketMs}) * ${bucketMs}`;
|
||||||
|
|
||||||
return db
|
return db
|
||||||
.select({
|
.select({
|
||||||
bucket: sql<number>`(${sessionEvents.tsMs} / ${bucketMs}) * ${bucketMs}`,
|
bucket,
|
||||||
sessionDeviceId: sessionEvents.sessionDeviceId,
|
sessionDeviceId: sessionEvents.sessionDeviceId,
|
||||||
slotLabel: sessionDevices.slotLabel,
|
slotLabel: sessionDevices.slotLabel,
|
||||||
avgValue: sql<number>`avg(${sessionEvents.value})`,
|
avgValue: sql<number>`avg(${sessionEvents.value})`,
|
||||||
@@ -48,8 +54,8 @@ export async function getSessionTimeline(playSessionId: number, bucketMs = 1000)
|
|||||||
.from(sessionEvents)
|
.from(sessionEvents)
|
||||||
.innerJoin(sessionDevices, eq(sessionEvents.sessionDeviceId, sessionDevices.id))
|
.innerJoin(sessionDevices, eq(sessionEvents.sessionDeviceId, sessionDevices.id))
|
||||||
.where(and(eq(sessionEvents.playSessionId, playSessionId), ne(sessionEvents.commandType, "stop")))
|
.where(and(eq(sessionEvents.playSessionId, playSessionId), ne(sessionEvents.commandType, "stop")))
|
||||||
.groupBy(sql`bucket`, sessionEvents.sessionDeviceId)
|
.groupBy(bucket, sessionEvents.sessionDeviceId)
|
||||||
.orderBy(sql`bucket`);
|
.orderBy(bucket);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getDeviceUsageStats() {
|
export async function getDeviceUsageStats() {
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "sexy",
|
"name": "sexy",
|
||||||
"version": "0.2.0",
|
"version": "0.2.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
|
|||||||
Reference in New Issue
Block a user