Skip to content

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