Skip to content

Commit 448e9ea

Browse files
aadamgoughAdam Gough
andauthored
fix(tools): fixed supabase order by (#1467)
Co-authored-by: Adam Gough <[email protected]>
1 parent a63f3a3 commit 448e9ea

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

apps/sim/tools/supabase/query.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,21 @@ export const queryTool: ToolConfig<SupabaseQueryParams, SupabaseQueryResponse> =
5858

5959
// Add order by if provided
6060
if (params.orderBy) {
61-
const orderParam = params.orderBy.includes('DESC')
62-
? `${params.orderBy.replace(' DESC', '').replace('DESC', '')}.desc`
63-
: `${params.orderBy}.asc`
61+
let orderParam = params.orderBy.trim()
62+
63+
// Check if DESC is specified (case-insensitive)
64+
if (/\s+DESC$/i.test(orderParam)) {
65+
orderParam = `${orderParam.replace(/\s+DESC$/i, '').trim()}.desc`
66+
}
67+
// Check if ASC is specified (case-insensitive)
68+
else if (/\s+ASC$/i.test(orderParam)) {
69+
orderParam = `${orderParam.replace(/\s+ASC$/i, '').trim()}.asc`
70+
}
71+
// Default to ascending if no direction specified
72+
else {
73+
orderParam = `${orderParam}.asc`
74+
}
75+
6476
url += `&order=${orderParam}`
6577
}
6678

0 commit comments

Comments
 (0)