From 46956a4153ea00d6ec31160511a17030bb1d3826 Mon Sep 17 00:00:00 2001 From: Gabe Ruttner Date: Wed, 21 Aug 2024 10:55:15 -0700 Subject: [PATCH] fix: sort (#803) --- pkg/repository/prisma/dbsqlc/events.sql | 5 +++- pkg/repository/prisma/dbsqlc/events.sql.go | 33 ++++++++++++---------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/pkg/repository/prisma/dbsqlc/events.sql b/pkg/repository/prisma/dbsqlc/events.sql index cb602a709..84d818f59 100644 --- a/pkg/repository/prisma/dbsqlc/events.sql +++ b/pkg/repository/prisma/dbsqlc/events.sql @@ -140,7 +140,10 @@ LEFT JOIN LEFT JOIN "WorkflowRun" as runs ON runTriggers."parentId" = runs."id" GROUP BY - events."id", events."createdAt"; + events."id", events."createdAt" +ORDER BY + case when @orderBy = 'createdAt ASC' THEN events."createdAt" END ASC , + case when @orderBy = 'createdAt DESC' then events."createdAt" END DESC; -- name: GetEventsForRange :many SELECT diff --git a/pkg/repository/prisma/dbsqlc/events.sql.go b/pkg/repository/prisma/dbsqlc/events.sql.go index cb0ff17f7..eacb50184 100644 --- a/pkg/repository/prisma/dbsqlc/events.sql.go +++ b/pkg/repository/prisma/dbsqlc/events.sql.go @@ -280,29 +280,29 @@ WITH filtered_events AS ( events."tenantId" = $1 AND events."deletedAt" IS NULL AND ( - $2::text[] IS NULL OR - events."key" = ANY($2::text[]) + $3::text[] IS NULL OR + events."key" = ANY($3::text[]) ) AND ( - $3::jsonb IS NULL OR - events."additionalMetadata" @> $3::jsonb + $4::jsonb IS NULL OR + events."additionalMetadata" @> $4::jsonb ) AND ( - ($4::text[])::uuid[] IS NULL OR - (workflow."id" = ANY($4::text[]::uuid[])) + ($5::text[])::uuid[] IS NULL OR + (workflow."id" = ANY($5::text[]::uuid[])) ) AND ( - $5::text IS NULL OR - workflow.name like concat('%', $5::text, '%') OR - jsonb_path_exists(events."data", cast(concat('$.** ? (@.type() == "string" && @ like_regex "', $5::text, '")') as jsonpath)) + $6::text IS NULL OR + workflow.name like concat('%', $6::text, '%') OR + jsonb_path_exists(events."data", cast(concat('$.** ? (@.type() == "string" && @ like_regex "', $6::text, '")') as jsonpath)) ) AND ( - $6::text[] IS NULL OR - "status" = ANY(cast($6::text[] as "WorkflowRunStatus"[])) + $7::text[] IS NULL OR + "status" = ANY(cast($7::text[] as "WorkflowRunStatus"[])) ) ORDER BY - case when $7 = 'createdAt ASC' THEN events."createdAt" END ASC , - case when $7 = 'createdAt DESC' then events."createdAt" END DESC + case when $2 = 'createdAt ASC' THEN events."createdAt" END ASC , + case when $2 = 'createdAt DESC' then events."createdAt" END DESC OFFSET COALESCE($8, 0) LIMIT @@ -325,16 +325,19 @@ LEFT JOIN "WorkflowRun" as runs ON runTriggers."parentId" = runs."id" GROUP BY events."id", events."createdAt" +ORDER BY + case when $2 = 'createdAt ASC' THEN events."createdAt" END ASC , + case when $2 = 'createdAt DESC' then events."createdAt" END DESC ` type ListEventsParams struct { TenantId pgtype.UUID `json:"tenantId"` + Orderby interface{} `json:"orderby"` Keys []string `json:"keys"` AdditionalMetadata []byte `json:"additionalMetadata"` Workflows []string `json:"workflows"` Search pgtype.Text `json:"search"` Statuses []string `json:"statuses"` - Orderby interface{} `json:"orderby"` Offset interface{} `json:"offset"` Limit interface{} `json:"limit"` } @@ -351,12 +354,12 @@ type ListEventsRow struct { func (q *Queries) ListEvents(ctx context.Context, db DBTX, arg ListEventsParams) ([]*ListEventsRow, error) { rows, err := db.Query(ctx, listEvents, arg.TenantId, + arg.Orderby, arg.Keys, arg.AdditionalMetadata, arg.Workflows, arg.Search, arg.Statuses, - arg.Orderby, arg.Offset, arg.Limit, )