Call stored procedures and user-defined functions across all supported databases with type-safe parameter handling.
Prax provides a unified API for calling stored procedures and functions across PostgreSQL, MySQL, MSSQL, and SQLite. Support includes IN/OUT/INOUT parameters, table-valued functions, and custom aggregates.
| Feature | PostgreSQL | MySQL | SQLite | MSSQL | MongoDB |
|---|---|---|---|---|---|
| Stored Procedures | ✅ | ✅ | ❌ | ✅ | ❌ |
| User-Defined Functions | ✅ | ✅ | ✅ Rust | ✅ | ✅ $function |
| Table-Valued Functions | ✅ | ❌ | ❌ | ✅ | ❌ |
| Aggregate Functions | ✅ | ✅ | ✅ Rust | ✅ | ✅ $accumulator |
Use ProcedureCall to invoke stored procedures
with type-safe parameters.
Handle output parameters with ParameterMode.
Call scalar and table-valued functions with the same fluent API.
Since SQLite doesn't support stored procedures, register Rust functions directly with the connection.
Note: SQLite UDFs are registered per-connection. Use the connection pool's
after_connect hook to register functions on all connections.
Define custom JavaScript functions for MongoDB aggregation pipelines.
Version control your stored procedures with Prax migrations. The differ detects changes automatically.
Prax generates the correct syntax for each database:
Wrap procedure calls in transactions when they modify data. Some procedures handle their own transactions—check the procedure definition.
Some procedures return multiple result sets. Use result.next_result_set()
to iterate through them.
Keep procedure definitions in migrations. Use ProcedureDiffer to detect
changes and generate appropriate ALTER/DROP/CREATE statements.
Don't call procedures in a loop. Batch operations when possible, or design procedures to accept arrays/table-valued parameters.