Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Related to web frameworks, what is the current status on ORM in the Rust ecosystem?


There is only one option: diesel [1]. It is a powerful solution for correctness, as it is completely type-safe. It's also really fast since a lot of work is delegated to compile time.

There are also plenty of drawbacks though: the extensive type system hacking can lead to very confusing compiler errors, it doesn't work well when you need to sometimes fall back to more dynamic db handling, and it doesn't handle large tables well. (very long compile times etc), and the documentation is quite sparse.

It's a robust solution for greenfield projects where you can design the schema partially with diesel in mind, but I wouldn't recommend it for existing DBs or projects that you know will grow large (eg 100+ column tables etc).

[1] https://github.com/diesel-rs/diesel


it doesn't handle large tables well. (very long compile times etc)

By large tables you mean a large number of columns, not a large number of rows, right?


Correct.

Fun fact: The amount of traits implementations that need to be generated to support tables with 128 columns actually makes diesel an interest benchmark of the Rust compiler.


Would the recent work on const generics help with this?


Not sure. Having the ability to abstract over tuples (using a similar mechanism as HLists for example) would help.


Correct.


The main ORM in the ecosystem is Diesel[0], which is very usable, though it can be a bit hard to get into due to lack of documentation/tutorials (compared to what people are used to from other ORMs).

It has to be said though, that compared to other ecosystems, less focus is put on ORMs, and more focus is put on the specific database crates (e.g. rust-postgres), and how to make them easy to use without ORMs.

[0]: https://diesel.rs


I think this is still the state-of-the-art in Rust: https://diesel.rs/


Is there an unsafe SQL generator for Rust? Pardon my not knowing Rust syntax:

  q = select("table")
  q = q.where_greater_than("col", 5)
  if(x) { q = q.where_equal("col2", true) }




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: