Stored Procedures: rpc()
You can call stored procedures as a "Remote Procedure Call".
That's a fancy way of saying that you can put some logic into your database then call it from anywhere. It's especially useful when the logic rarely changes - like password resets and updates.
- JavaScript
const { data, error } = await supabase
.rpc('hello_world')
}
Parameters
fnrequired
string
The function name to call.
paramsoptional
undefined
|object
The parameters to pass to the function call.
__namedParametersrequired
object
No description provided.
countrequired
null
|exact
|planned
|estimated
Count algorithm to use to count rows in a table.
Properties
Examples
Call a stored procedure
This is an example invoking a stored procedure.
- JavaScript
const { data, error } = await supabase
.rpc('hello_world')
}
With Parameters
- JavaScript
const { data, error } = await supabase
.rpc('echo_city', { name: 'The Shire' })
}
Bulk call
- JavaScript
const { data, error } = await supabase
.rpc('echo_city', [
{ name: 'The Shire' },
{ name: 'Mordor' }
])
}
With filters.
Stored procedures that return tables can also be combined with Modifiers and Filters.
- JavaScript
const { data, error } = await supabase
.rpc('echo_all_cities')
.eq('name', 'The Shire')
With count option
You can specify a count option to get the row count along with your data.
Allowed values for count option are null
, exact
, planned
and estimated
.
- JavaScript
const { data, error, count } = await supabase
.from('cities')
.rpc('hello_world', { count: 'exact' })
}