| Crates.io | prisma-rust-schema |
| lib.rs | prisma-rust-schema |
| version | 0.2.1 |
| created_at | 2025-04-17 17:11:50.215836+00 |
| updated_at | 2025-04-30 20:43:09.19605+00 |
| description | A Rust binary to act as a Prisma generator, generating Rust code from Prisma schema files. |
| homepage | |
| repository | https://github.com/ShaunSHamilton/prisma-rust-schema/ |
| max_upload_size | |
| id | 1638161 |
| size | 91,436 |
cargo install prisma-rust-schema
.prisma file:generator prisma_rust_schema {
provider = "prisma-rust-schema"
output = "./src/prisma"
}
npx prisma generate
use prisma::MyModel;
This crate exports the internal TypeScript types from prisma/prisma.
| Option | Example | Description |
|---|---|---|
@prs.rename = <new_name> |
@prs.rename = username |
Rename the field in the generated Rust struct. |
@prs.skip |
@prs.skip |
Skip the field in the generated Rust struct. |
@prs.type = <type_override> |
@prs.type = usize |
Override the type of the field in the generated Rust struct. |
@prs.visibility = <visibility> |
@prs.visibility = public |
Override the visibility (public, private, protected) of the field in the generated Rust struct. |
@prs.derive = <trait> |
@prs.derive = Debug,Clone,serde::Deserialize |
Fully-qualified, comma-separated derive attributes for the generated Rust struct. |
/// User model documentation
/// @prs.visibility = protected
/// @prs.derive = Debug,Clone,serde::Deserialize,serde::Serialize
model User {
/// User ID
/// @prs.rename = `user_id`
/// @prs.type = `usize`
/// @prs.derive = `Debug,Clone,serde::Deserialize`
id Int @id @default(autoincrement())
/// User name
/// @prs.skip
name String?
/// User emails
emails String[]
/// User age
age Int? @default(0)
}
/// Post model with only defaults
/// @prs.derive = Debug,Clone,serde::Deserialize,serde::Serialize
model post {
id Int @id @default(autoincrement())
title String
content Json
published Boolean @default(false)
publishedAt DateTime? @default(now())
}
Becomes:
#[doc = "User model documentation"]
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
pub(crate) struct User {
#[doc = "User ID"]
#[serde(rename = "user")]
pub(crate) user_id: usize,
#[doc = "User emails"]
pub(crate) emails: Vec<String>,
/// User age
pub(crate) age: Option<i32>,
}
#[doc = "Post model with only defaults"]
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
pub struct Post {
pub id: i32,
pub title: String,
pub content: serde_json::Value,
pub published: bool,
pub published_at: Option<chrono::DateTime<chrono::Utc>>,
}
This package is tested to work with prisma@^6. It does work with prisma@^5 but there are no native types such as @db.ObjectId. So, @prs.type must be used, otherwise the type will be the .prisma type.
| Version | Prisma Schema | Rust Type |
|---|---|---|
| 5.x |
|
|
| 6.x |
|
|
Currently, it is up to the user to ensure all types have valid derive attributes. Specifically, if the rename attribute is needed, then serde::Deserialize and serde::Serialize must be used. The generator will not add them automatically.