|
Integrate them natively. Using Client Side Extensions To use client side extensions you need to first enable the preview feature in the schema file and then you can call the method on the client instance. instance without modifying the original instance. You can chain calls to use multiple extensions and create separate instances with different extensions. The components of an extension can contain four different types of components. Model components allow you to add new methods to the model. This is a convenient way to add new actions next to default methods such as etc. You can use it as a repository for common query methods to encapsulate the business logic of your model or to perform any operation you might perform using static methods on a class. The next example combines the methods shown in the input validation and conversion.
Field examples to provide static and runtime types for fields. It uses parsed field data and infers static types. This example includes a model with profile fields. The model has a sparse structure that m photo editing servies ay vary from user to user. This extension has two parts that add calculated fields to the extension. This field uses a schema to resolve the underlying untyped field. Static data types are inferred from the parser so query results have static and runtime type safety. An extension for parsing input data fields for model write methods such as and . View the sample code Sample Query Logging This sample shows how to use client extensions to perform tasks similar to middleware. In this example the extension tracks the time it takes to complete each query and logs the results along with the query and parameters themselves.
This technique can be used to perform generic logging to emit events to track usage, etc. NOTE You may be interested in the Tracking and Metrics features, which are both in preview and provide detailed insights into performance and how you interact with your database. View the sample code Example Retrying a Transaction This example demonstrates how to use the client extension to automatically retry a transaction that fails due to a write conflict deadlock timeout. Failed transactions will be retried with exponential backoff and jitter to reduce contention under heavy traffic. View the sample code Example Interactive Transaction Without Callbacks This example shows the client extension which adds a new one for.
|
|