After creating an instance of
PrismaClient, queries can be made like the following:
client .post() // Model to query on .find_many(vec!) // Query to execute .exec() // Ends query .await; // All queries are async and return Result
Queries can be filtered and extended using the generated modifiers. Each model in your schema gets a corresponding Rust module, with corresponding modules for their fields inside. Field modules contain functions for constructing modifiers based on each field.
use prisma::post; client .post() .find_many(vec![ // model:: // field:: // method() post::title::equals("Test".to_string()) ]) .exec() .await;
All model and field module names are converted to
snake_case as to be consistent with Rust's naming conventions.
The generated client is one file containing many modules, types and function. At the root level there is:
new_client_with_url(): Functions for creating an instance of the client
_prismamodule: Contains the
PrismaClientstruct and various internal enums
Model modules: One for each model in your Prisma schema
These modules contain types & functions for queries related to their respective model and its fields.
Their name is their respective model's name converted to
Used by the client to get a list of all the model's scalar fields.
Compound Field Filters
Generated for each compound unique index (
@@unique() in a Prisma schema) on the model.
Compound unique indexes don't get their own field modules since the only thing they would contain is an
so a single function with the name of all fields in the compound index combined is generated as a replacement.
Contains all relations that can be fetched for a model, with query builders for nested querying.
Contains all possible modifications to the model and their associated data.
Contains a variant with a
prisma_client_rust::Direction for each field that can be used for ordering.
Contains all possible filters for the model and their associated data.
Contains a subsection of
WhereParam that can be used to uniquely identify individual records.
Usually only contains
The struct returned by the client's function for making queries on the model.
Implements functions that return the query builders defined in the
For each of the model's fields, a module is generated that contains types and functions for operating on specific fields.
Each module gets a macro generated for doing field selection.
Generated for relation fields.
Wraps a query builder for a relation's model in a unique struct,
which can then be converted to a
This wrapping is necessary as some models may contain multiple relations to the same model,
which would result in multiple
WithParam conversions being implemented on the same query builder.
Some operations such as
set have individual structs generated for them.
They simply wrap the operations' arguments in a unique struct for conversion to an appropriate enum.
equals is a special function generated for scalar fields that can return multiple types depending on where it is used. Its implementation depends on the type of the scalar field:
Required Field: Takes a value with the same type as the field and returns a
Required Unique Field: Takes a value with the same type as the field and returns a generic type, allowing either
WhereParamto be returned depending on where it is used.
Optional Unique Field: If being used somewhere expecting a
UniqueWhereParam, takes a value matching the type of the field. If being used somewhere expecting a
WhereParam, however, takes an
Optionof the type of the field. This is necessary as
find_uniquedoes not accept SQL
NULLas a filter, but all other find methods do.
Other Filters & Operations
Functions are generated for type-specific filters and some other operations.