Skip to content

Commit

Permalink
Merge pull request #132 from supabase/fix/order-column
Browse files Browse the repository at this point in the history
Fix ordering on JSON columns
  • Loading branch information
kiwicopple authored Nov 12, 2020
2 parents 43b093d + 548ea28 commit c92493e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/PostgrestTransformBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class PostgrestTransformBuilder<T> extends PostgrestBuilder<T> {
const key = typeof foreignTable === 'undefined' ? 'order' : `"${foreignTable}".order`
this.url.searchParams.set(
key,
`"${column}".${ascending ? 'asc' : 'desc'}.${nullsFirst ? 'nullsfirst' : 'nullslast'}`
`${column}.${ascending ? 'asc' : 'desc'}.${nullsFirst ? 'nullsfirst' : 'nullslast'}`
)
return this
}
Expand Down
33 changes: 33 additions & 0 deletions test/__snapshots__/basic.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`allow ordering on JSON column 1`] = `
Array [
Object {
"age_range": "[1,2)",
"catchphrase": "'cat' 'fat'",
"data": null,
"status": "ONLINE",
"username": "supabot",
},
Object {
"age_range": "[25,35)",
"catchphrase": "'bat' 'cat'",
"data": null,
"status": "OFFLINE",
"username": "kiwicopple",
},
Object {
"age_range": "[25,35)",
"catchphrase": "'bat' 'rat'",
"data": null,
"status": "ONLINE",
"username": "awailas",
},
Object {
"age_range": "[20,30)",
"catchphrase": "'fat' 'rat'",
"data": null,
"status": "ONLINE",
"username": "dragarcia",
},
]
`;

exports[`basic insert, update, delete basic delete 1`] = `
Object {
"body": Array [
Expand Down
5 changes: 5 additions & 0 deletions test/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,8 @@ test("don't mutate PostgrestClient.headers", async () => {
const { error } = await postgrest.from('users').select()
expect(error).toMatchSnapshot()
})

test("allow ordering on JSON column", async () => {
const { data } = await postgrest.from('users').select().order('data->something')
expect(data).toMatchSnapshot()
})

0 comments on commit c92493e

Please sign in to comment.