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

Allow Data structs to perform write operations #366

Closed RustyNova016 closed 11 months ago

RustyNova016 commented 11 months ago

Something nice to have would be using the Data structs to modify data without having to write a query, something like data.create(), data.update(), or data.delete()

It could be really useful for APIs. If we take the same DB schema from the documentation (https://prisma.brendonovich.dev/writing-data/create), we could have an API end point that is just Post::from(request_body).create().await, which makes it really convenient.

It could probably be done with a macro, but those are still alien to me.

Brendonovich commented 11 months ago

While this more ActiveRecord style of API can be convenient, it's entirely outside of PCR's goals. The Prisma way of doing things is that data is purely data, and in my experience this is a superior approach even if it sacrifices some DX. This could probably be implemented using a custom generator (you can pretty much do anything with a custom generator), but it will not be part of PCR.

It could be really useful for APIs. If we take the same DB schema from the documentation (https://prisma.brendonovich.dev/writing-data/create), we could have an API end point that is just Post::from(request_body).create().await, which makes it really convenient.

I have other plans for how this can work, for example partial_unchecked can already be used to go directly from request body to parameters that can be provided to update_unchecked. I've got plans to support declaring data types with relations and create operations too.

RustyNova016 commented 11 months ago

I see. But partial_unchecked seems to be a pretty good alternative, apart when it comes to creating data, but that's just a matter of waiting for it to come. I do hope it will need less wait than waiting for Prisma to implement CUID2...