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: 4 additions & 2 deletions src/lib/PostgrestFilterBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ export default class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder
* Finds all rows satisfying at least one of the filters.
*
* @param filters The filters to use, separated by commas.
* @param foreignTable The foreign table to use (if `column` is a foreign column).
*/
or(filters: string): this {
this.url.searchParams.append('or', `(${filters})`)
or(filters: string, { foreignTable }: { foreignTable?: string } = {}): this {
const key = typeof foreignTable === 'undefined' ? 'or' : `${foreignTable}.or`
this.url.searchParams.append(key, `(${filters})`)
return this
}

Expand Down
134 changes: 134 additions & 0 deletions test/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,140 @@ Object {
}
`;

exports[`embedded filters embedded or 1`] = `
Object {
"body": Array [
Object {
"messages": Array [
Object {
"channel_id": 1,
"data": null,
"id": 1,
"message": "Hello World 👋",
"username": "supabot",
},
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 {
"messages": Array [],
},
Object {
"messages": Array [],
},
Object {
"messages": Array [],
},
],
"count": null,
"data": Array [
Object {
"messages": Array [
Object {
"channel_id": 1,
"data": null,
"id": 1,
"message": "Hello World 👋",
"username": "supabot",
},
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 {
"messages": Array [],
},
Object {
"messages": Array [],
},
Object {
"messages": Array [],
},
],
"error": null,
"status": 200,
"statusText": "OK",
}
`;

exports[`embedded filters embedded or with and 1`] = `
Object {
"body": Array [
Object {
"messages": Array [
Object {
"channel_id": 1,
"data": null,
"id": 1,
"message": "Hello World 👋",
"username": "supabot",
},
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 {
"messages": Array [],
},
Object {
"messages": Array [],
},
Object {
"messages": Array [],
},
],
"count": null,
"data": Array [
Object {
"messages": Array [
Object {
"channel_id": 1,
"data": null,
"id": 1,
"message": "Hello World 👋",
"username": "supabot",
},
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 {
"messages": Array [],
},
Object {
"messages": Array [],
},
Object {
"messages": Array [],
},
],
"error": null,
"status": 200,
"statusText": "OK",
}
`;

exports[`embedded select 1`] = `
Object {
"body": Array [
Expand Down
14 changes: 14 additions & 0 deletions test/resource-embedding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ describe('embedded filters', () => {
const res = await postgrest.from('users').select('messages(*)').eq('messages.channel_id', 1)
expect(res).toMatchSnapshot()
})
test('embedded or', async () => {
const res = await postgrest
.from('users')
.select('messages(*)')
.or('channel_id.eq.2,message.eq.Hello World 👋', { foreignTable: 'messages' })
expect(res).toMatchSnapshot()
})
test('embedded or with and', async () => {
const res = await postgrest
.from('users')
.select('messages(*)')
.or('channel_id.eq.2,and(message.eq.Hello World 👋,username.eq.supabot)', { foreignTable: 'messages' })
expect(res).toMatchSnapshot()
})
})

describe('embedded transforms', () => {
Expand Down