Backend Web Framework
Problem
Even though Diesel provides a way to write type-safe queries in Rust that get translated to SQL, not all features of SQL are supported (e.g Diesel only supports INNER JOIN and LEFT JOIN). Furthermore, long and complicated queries (like recursive queries) are hard to read and write. The problem here is mainly development speed, we keep "fighting Diesel" instead of just writing queries.
Constraints
Assumptions
Considered Alternatives
- sqlx (We want to keep Diesel)
Decision
We will continue using Diesel for as much functionality as possible. When raw SQL is easier,
we will store the SQL in a separate file under backend/src/model/sql
or include it in the migration files.
This approach allows us to use linting tools to catch potential issues in our SQL.
Rationale
We have a lot of existing Diesel code, switching to an alternative like sqlx
at this time would
incur migration costs. By isolating raw SQL queries, we can maintain the benefits of type
safety in the majority of our code while still accessing the advanced features of Postgres as needed.
Implications
- There is SQL code that is not checked by Diesel.