count with rpc does not work as expected
See original GitHub issueBug report
Describe the bug
In the documentation, the following example does not work because it sets the params
object instead.
const { data, error, count } = await postgrest
.rpc('hello_world', { count: 'exact' })
}
A workaround is to provide undefined
as the second argument to rpc
, for example: .rpc('hello_world', undefined, { count: 'exact' })
. I’m not sure if this is the intended behavior though so I filed as a bug report instead of docs improvement.
To Reproduce
You can add the following tests to /test/basic.ts
. The 1st case fails and the 2nd one passes.
test("stored procedure with count but no params (1): 'exact'", async () => {
const res = await postgrest.rpc('void_func', { count: 'exact' })
expect(res.count).toBe(1)
})
test("stored procedure with count but no params (2): 'exact'", async () => {
const res = await postgrest.rpc('void_func', undefined, { count: 'exact' })
expect(res.count).toBe(1)
})
Expected behavior
According to the documentation, using rpc('hello_world', { count: 'exact' })
should return an object with count
in it. I’m not sure what the optimal solution to this problem would be since both the params
and { count: '...' }
are optional.
System information
- OS: macOS
- Version of supabase-js: 1.21.0
- Version of Node.js: v16.4.2
Additional context
A related problem is: in supabase/supabase.js
, when using const supabase = createClient()
, the { count: 'exact' }
never works because it is never passed to postgrest-js
.
I think I should file this issue in supabase/supabase.js
instead.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
@PatoDeVille can you file a new issue in the supabase/postgrest-js repo about this? Would be helpful if you can provide the function definition as well.
@soedirgo - I’ve add the fix to the docs, will let you approve/merge 🙏