Diesel 2.0.0 has been officially released . It is said that the development cycle of this version is as long as 3 years and contains more than 1700 commits.
Diesel is a safe and extensible Rust ORM framework and query builder. Diesel avoids runtime errors and provides the best performance.
2.0 adds many new features and rewrites most of the internals. Since this is a new major version, it also contains many breaking changes, see the migration guide for specific handling .
Update highlights
- fully type-checked
GROUP BY
- Support for table aliases
- Support for defining select clauses by corresponding types
- Support
UNION
/INTERSECT
Inquiry
In addition, Diesel 2.0.0 fixes several issues in the type level SQL representation, which now correctly handles the following cases:
- mixed nesting
LEFT JOINS
andINNER JOINS
- Chaining mixed nullable expressions via
AND
, and similar operatorsOR
support GROUP BY
clause
Diesel 2.0 added GROUP BY
support for clauses for select queries.
Example
users::table.inner_join(posts::table)
.group_by(users::id)
.select((users::name, count(posts::id)))
Support for table aliases
The following query demonstrates this functionality:
// Define new table alias for the existing `users` table
let users1 = diesel::alias!(schema::users as user1);
// Use the corresponding alias inside any existing query
users::table
.inner_join(users1.on(users::id).eq(users1.field(users::id))))
.select((users::id, users::name, users1.field(users::name)))
.order_by(users1.field(users::id))
Support UNION
/ INTERSECT
Inquiry
This feature easily chains together multiple queries as long as they return fields of the same type.
users.select(user_name.nullable())
.union(animals.select(animal_name).filter(animal_name.is_not_null()))