From 448e9ea835ad05ec54efc2c4422b0b9360760ddc Mon Sep 17 00:00:00 2001 From: Adam Gough <77861281+aadamgough@users.noreply.github.com> Date: Fri, 26 Sep 2025 19:26:50 -0700 Subject: [PATCH] fix(tools): fixed supabase order by (#1467) Co-authored-by: Adam Gough --- apps/sim/tools/supabase/query.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/apps/sim/tools/supabase/query.ts b/apps/sim/tools/supabase/query.ts index 57337d5d54..41025cf7f5 100644 --- a/apps/sim/tools/supabase/query.ts +++ b/apps/sim/tools/supabase/query.ts @@ -58,9 +58,21 @@ export const queryTool: ToolConfig = // Add order by if provided if (params.orderBy) { - const orderParam = params.orderBy.includes('DESC') - ? `${params.orderBy.replace(' DESC', '').replace('DESC', '')}.desc` - : `${params.orderBy}.asc` + let orderParam = params.orderBy.trim() + + // Check if DESC is specified (case-insensitive) + if (/\s+DESC$/i.test(orderParam)) { + orderParam = `${orderParam.replace(/\s+DESC$/i, '').trim()}.desc` + } + // Check if ASC is specified (case-insensitive) + else if (/\s+ASC$/i.test(orderParam)) { + orderParam = `${orderParam.replace(/\s+ASC$/i, '').trim()}.asc` + } + // Default to ascending if no direction specified + else { + orderParam = `${orderParam}.asc` + } + url += `&order=${orderParam}` }