Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.

Commit c92493e

Browse files
authored
Merge pull request #132 from supabase/fix/order-column
Fix ordering on JSON columns
2 parents 43b093d + 548ea28 commit c92493e

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

src/lib/PostgrestTransformBuilder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default class PostgrestTransformBuilder<T> extends PostgrestBuilder<T> {
2424
const key = typeof foreignTable === 'undefined' ? 'order' : `"${foreignTable}".order`
2525
this.url.searchParams.set(
2626
key,
27-
`"${column}".${ascending ? 'asc' : 'desc'}.${nullsFirst ? 'nullsfirst' : 'nullslast'}`
27+
`${column}.${ascending ? 'asc' : 'desc'}.${nullsFirst ? 'nullsfirst' : 'nullslast'}`
2828
)
2929
return this
3030
}

test/__snapshots__/basic.test.ts.snap

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,38 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`allow ordering on JSON column 1`] = `
4+
Array [
5+
Object {
6+
"age_range": "[1,2)",
7+
"catchphrase": "'cat' 'fat'",
8+
"data": null,
9+
"status": "ONLINE",
10+
"username": "supabot",
11+
},
12+
Object {
13+
"age_range": "[25,35)",
14+
"catchphrase": "'bat' 'cat'",
15+
"data": null,
16+
"status": "OFFLINE",
17+
"username": "kiwicopple",
18+
},
19+
Object {
20+
"age_range": "[25,35)",
21+
"catchphrase": "'bat' 'rat'",
22+
"data": null,
23+
"status": "ONLINE",
24+
"username": "awailas",
25+
},
26+
Object {
27+
"age_range": "[20,30)",
28+
"catchphrase": "'fat' 'rat'",
29+
"data": null,
30+
"status": "ONLINE",
31+
"username": "dragarcia",
32+
},
33+
]
34+
`;
35+
336
exports[`basic insert, update, delete basic delete 1`] = `
437
Object {
538
"body": Array [

test/basic.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,8 @@ test("don't mutate PostgrestClient.headers", async () => {
126126
const { error } = await postgrest.from('users').select()
127127
expect(error).toMatchSnapshot()
128128
})
129+
130+
test("allow ordering on JSON column", async () => {
131+
const { data } = await postgrest.from('users').select().order('data->something')
132+
expect(data).toMatchSnapshot()
133+
})

0 commit comments

Comments
 (0)