DEV Community

Discussion on: Practical Rust Web Development - API Rest

Collapse
 
autoferrit profile image
Shawn McElroy

I am still going through these and am new to Rust. But being used to frameworks like flask in python, is it easy or possible to abstract out the model methods to not have the boilerplate for the db connection?

some frameworks make it so you can do request.db or maybe move it to a parent model or something? that way the model methods are a lot cleaner?

Collapse
 
werner profile image
Werner Echezuría

Well, I think it's possible, passing the db connection through a Trait, and then implements the trait for every model. Seems like a fun thing to do, maybe in a future post I'll try to implement it.

Collapse
 
autoferrit profile image
Shawn McElroy

that would be great.