Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust migration with rust-prisma-client and axum #38

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

paahaad
Copy link

@paahaad paahaad commented Jan 25, 2025

This PR proposes an idea: if we're building the backend in Rust, why not consider using the Rust Prisma client? Most of the schema design, relationships, and query logic are already in place, which makes it a good fit.

This PR included:

  1. Axum setup in different folder
  2. Prisma-cli setup
  • to schema sync
cargo prisma db push
  • to generate prisma client
cargo prisma generate

example:
This node.js code is

const user = await client.user.upsert({
       where: {
            number
        },
        create: {
            number,
            name: ""
        },
        update: {

        }
    })

equivalent to

let db = db
        .user()
        .upsert(
                user::number::equals(payload.number.to_string()), // where clause
                user::create(payload.number.clone().to_string(), "".to_string(), vec![]), //create clause
                vec![], // update clause
             )
         .exec()
         .await;
  1. zod like input validations
#[derive(Debug, Validate, Deserialize)]
pub struct SignupVerifyPayload {
    #[validate(length(min = 9, max = 13, message = "Invalid Number"))]
    number: String,

    #[validate(length(min = 6, max = 6, message = "OTP should be of lenght 6"))]
    otp: String,

    #[validate(length(min = 1, max = 255, message = "Username cannot be empty"))]
    name: String,
}

Note: This PR implements a single endpoint as a demo using the existing Prisma schema. If you think this approach could work, I'd be more than happy to migrate the entire codebase to Rust!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant