Skip to main content
Version: 3.x

Custom Procedure

This amazing feature is implemented by Mike Willbanks .

Preview Feature
Custom procedure is in preview and may be subject to breaking changes in future releases.
Available since v3.2.0
🔋 ZModel vs Prisma Schema

Custom procedure is a ZModel feature and doesn't exist in PSL.

Custom procedures are like database stored procedures that allow you to define reusable routines encapsulating complex logic.

Use the procedure keyword to define a custom procedure in ZModel. Here's an example for a query procedure:

schema.zmodel
procedure getUserFeeds(userId: Int, limit: Int?) : Post[] 

Mutation procedures (that write to the database) should be defined with mutation procedure:

schema.zmodel
mutation procedure signUp(email: String) : User

You can use all types supported by ZModel to define procedure parameters and return types, including:

  • Primitive types like Int, String
  • Models
  • Enums
  • Custom types
  • Array of the types above

Parameter types can be marked optional with a ? suffix. If a procedure doesn't return anything, use Void as the return type.

Custom procedures are implemented with TypeScript when constructing the ORM client, and can be invoked via the ORM client in backend code. See Custom Procedures in the ORM part for more details.

They are also accessible via Query-as-a-Service (via RPC-style or RESTful-style API), plus consumable via Client SDKs like TanStack Query Client.

Comments
Feel free to ask questions, give feedback, or report issues.

Don't Spam


You can edit/delete your comments by going directly to the discussion, clicking on the 'comments' link below