does Rust have a Python-like ORM like sqlalchemy with imperative mapping or C# EF Core? In these ORMs, you can describe your pure domain entities that will not know about the database in any way, you can use them in your program without knowing anything about the database. Is there such a thing in Rust?
Everything I see requires me to specify special macros in domain entities related to the database in one way or another, changing the attribute of a database entity requires me to use library classes, for example SeaORM:
pear.name = Set("Sweet pear".to_owned());
In python sqlalchemy (with imperative mapping) i just do:
pear.name = "smth"
On my domain entity (just usual python class)
I just want to keep my business logic clean and don't want it to know about database or ORM related details. I want to separately describe my business entities and separate structures that directly represent database tables, and then "link" them through ORM capabilities, so in my business logic I can work with my business entities and the changes will display in database (UoW pattern)
In fact, I could even put up with special macros on structures if the library allowed me to continue working with my entities as with ordinary structures in Rust, without thinking about classes from ORM.
Rust is a statically typed language. You'll need a way to map your domain models to something that the ORM understands in one way or another.
If you don't want your domain types to get polluted with database-related details such as ORM macros or types, you can create a type that interacts with the ORM, and then convert your domain into that type using the Fromand Ìnto traits.
I'm not sure if there is any crate about it but I think it's possible with serde like things but feels like it's a bit code mess for Rust. Since Rust is very strict about data.
In that kind of design probably every data field will return result data type since we don't know if the field even there or not.
Crates like diesel (and sea-orm) allow you to describe your columns from a struct and macro attributes, and you can create queries by using them without much boilerplate. This is from the diesel crate:
The code you show about sea-orm seems to use Set to indicate what to do with the columns, which looks a little more verbose, but I don't know much about it.
Without these newtypes, you would lose compile time verified queries. They don't just exist to make your code more difficult. Sqlalchemy and EF give you no such validation.