Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/lib/PostgrestTransformBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ export default class PostgrestTransformBuilder<T> extends PostgrestBuilder<T> {
}: { ascending?: boolean; nullsFirst?: boolean; foreignTable?: string } = {}
): this {
const key = typeof foreignTable === 'undefined' ? 'order' : `${foreignTable}.order`
const existingOrder = this.url.searchParams.get(key)

this.url.searchParams.set(
key,
`${column}.${ascending ? 'asc' : 'desc'}.${nullsFirst ? 'nullsfirst' : 'nullslast'}`
`${existingOrder ? `${existingOrder},` : ''}${column}.${ascending ? 'asc' : 'desc'}.${
nullsFirst ? 'nullsfirst' : 'nullslast'
}`
)
return this
}
Expand Down
108 changes: 108 additions & 0 deletions test/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,73 @@ Object {
}
`;

exports[`embedded transforms embedded order on multiple columns 1`] = `
Object {
"body": Array [
Object {
"messages": Array [
Object {
"channel_id": 2,
"data": null,
"id": 2,
"message": "Perfection is attained, not when there is nothing more to add, but when there is nothing left to take away.",
"username": "supabot",
},
Object {
"channel_id": 1,
"data": null,
"id": 1,
"message": "Hello World 👋",
"username": "supabot",
},
],
},
Object {
"messages": Array [],
},
Object {
"messages": Array [],
},
Object {
"messages": Array [],
},
],
"count": null,
"data": Array [
Object {
"messages": Array [
Object {
"channel_id": 2,
"data": null,
"id": 2,
"message": "Perfection is attained, not when there is nothing more to add, but when there is nothing left to take away.",
"username": "supabot",
},
Object {
"channel_id": 1,
"data": null,
"id": 1,
"message": "Hello World 👋",
"username": "supabot",
},
],
},
Object {
"messages": Array [],
},
Object {
"messages": Array [],
},
Object {
"messages": Array [],
},
],
"error": null,
"status": 200,
"statusText": "OK",
}
`;

exports[`embedded transforms embedded range 1`] = `
Object {
"body": Array [
Expand Down Expand Up @@ -2591,6 +2658,47 @@ Object {
}
`;

exports[`order on multiple columns 1`] = `
Object {
"body": Array [
Object {
"channel_id": 2,
"data": null,
"id": 2,
"message": "Perfection is attained, not when there is nothing more to add, but when there is nothing left to take away.",
"username": "supabot",
},
Object {
"channel_id": 1,
"data": null,
"id": 1,
"message": "Hello World 👋",
"username": "supabot",
},
],
"count": null,
"data": Array [
Object {
"channel_id": 2,
"data": null,
"id": 2,
"message": "Perfection is attained, not when there is nothing more to add, but when there is nothing left to take away.",
"username": "supabot",
},
Object {
"channel_id": 1,
"data": null,
"id": 1,
"message": "Hello World 👋",
"username": "supabot",
},
],
"error": null,
"status": 200,
"statusText": "OK",
}
`;

exports[`ov 1`] = `
Object {
"body": Array [
Expand Down
9 changes: 9 additions & 0 deletions test/resource-embedding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ describe('embedded transforms', () => {
expect(res).toMatchSnapshot()
})

test('embedded order on multiple columns', async () => {
const res = await postgrest
.from('users')
.select('messages(*)')
.order('channel_id', { foreignTable: 'messages', ascending: false })
.order('username', { foreignTable: 'messages', ascending: false })
expect(res).toMatchSnapshot()
})

test('embedded limit', async () => {
const res = await postgrest
.from('users')
Expand Down
9 changes: 9 additions & 0 deletions test/transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ test('order', async () => {
expect(res).toMatchSnapshot()
})

test('order on multiple columns', async () => {
const res = await postgrest
.from('messages')
.select()
.order('channel_id', { ascending: false })
.order('username', { ascending: false })
expect(res).toMatchSnapshot()
})

test('limit', async () => {
const res = await postgrest.from('users').select().limit(1)
expect(res).toMatchSnapshot()
Expand Down