Brendonovich / prisma-client-rust

Type-safe database access for Rust
https://prisma.brendonovich.dev
Apache License 2.0
1.75k stars 106 forks source link

`where!` macro #367

Closed merlindru closed 11 months ago

merlindru commented 11 months ago

Nested queries could be simplified using a where! macro that automatically nests ::is calls

In JavaScript:

db.transcript.findFirst({
    where: {
        id: transcriptId,
        project: {
            team: {
                members: { some: { id: userId } }
            },
        },
    }
});

Currently in prisma-client-rust:

db.transcript().find_first(vec![
    transcript::id::equals(self.transcript_id),
    transcript::project::is(vec![
        project::team::is(vec![
            team::members::some(vec![
                user::id::equals(user_id),
            ])
        ])
    ]),
]);

Proposed:

db.transcript().find_first(transcript::where! {
    id: self.transcript_id,
    project: {
        team: {
            members: { some: { id: user_id } }
        }
    }
});