Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ordering on JSON columns #132

Merged
merged 1 commit into from Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/PostgrestTransformBuilder.ts
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
@@ -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
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()
})