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

Abstracting over fetching relations #430

Open affanshahid opened 5 months ago

affanshahid commented 5 months ago

I have fairly complicated type with a bunch of relations that I want looked up for all of its queries. It is a hassle to copy-paste all the with() calls everywhere so I decided to build a function that wraps adding the with() calls:

fn relations<'a, T>(mut q: T) -> T
    where
        T: WithQuery<
            'a,
            RawType = submission::Data,
            Types = submission::Types,
            ReturnValue = submission::Data,
        >,
    {
        q.add_with(
            submission::dynamic_quiz_stage_data::fetch().with(
                prisma::dynamic_quiz_stage_data::stage_data::fetch()
                    .with(prisma::stage_data::pipeline_assignment::fetch()),
            ),
        );
        q
    }

However this doesn't work with find_many() since the RawType for that is Vec<Data> instead of Data. Any ideas?

I can't use include! here since my code base relies heavily on custom traits implemented on the internal Datas for different types