3 ms·
Is there anything like this for Rust or C++? I like the idea of code generation instead of doing the work at runtime (like in ORMs). This is like making your d
by zelly 6y ago
Is there anything like this for Rust or C++?
I like the idea of code generation instead of doing the work at runtime (like in ORMs). This is like making your database schema the IDL spec.
- aganame 6y agohttps://github.com/launchbadge/sqlx https://github.com/launchbadge/sqlx perhaps Also hugsql for clojure and pugsql for python.
- alde 6y agoSqlx looks nice! I had some ideas about porting pgtyped to rust and utilizing macros to do query type inference at build time, but was worried that such db-connected macros will slow down the build process. Nice to see that it worked out for sqlx.
- K0nserv 6y agoThere's Diesel[0] for Rust which is a full ORM. It's by Siân Griffin[1] who, as I understand it, is also behind a lot of how rail's ActiveRecord works. 0: https://diesel.rs/ https://diesel.rs/ 1: https://twitter.com/sgrif https://twitter.com/sgrif
- status_quo69 6y agoJust to clarify a bit for other readers since I've worked with diesel for while, diesel isn't a "full" orm, as there are no real helpers provided to you outside of "we can map the result of a db query into a struct(s) that you specify" and some really nice guarantees for compile time queries. Other than that, your struct is a pretty dumb mapped representation and it's on the implementers of the application code to provide sugar for better access patterns. For people coming from something like active record, this is (in my opinion) closer to Arel than ActiveRecord, or closer to sqlalchemy core than sqlalchemy orm. As an example, you won't necessarily be able to do `MyStruct.join(OtherStruct)` and have it magically figure out how to query the database and map the results out of the box.
- status_quo69 6y agoClarification: compile time query building, not querying. Due to inlining from the compiler, you can almost entirely construct the query at compile time and shave it down to a few string concatenations.