diesel

A safe, extensible ORM and Query Builder for Rust

APACHE-2.0 License

Downloads
52.2M
Stars
11.9K
Committers
390

Bot releases are visible (Hide)

diesel - Diesel 2.1.6 Latest Release

Published by weiznich 6 months ago

  • Fix using BoxableExpression with having clauses
  • Fix using numeric expressions with aliased fields
  • Minor documentation fixes

You can support the development of diesel by contributions or by sponsoring the project on Github.

Full Changelog: https://github.com/diesel-rs/diesel/compare/v2.1.5...v2.1.6

diesel - Diesel 2.1.5

Published by weiznich 7 months ago

  • Fix impl SqlOrd postgres > postgres_backend feature flag.
  • Allow Queryable to be used with multiple table names.
  • Update libsqlite3-sys to allow version 0.28 as well

Full Changelog: https://github.com/diesel-rs/diesel/compare/v2.1.4...v2.1.5

diesel - Diesel 2.1.4

Published by weiznich 11 months ago

  • Update libsqlite3-sys to allow version 0.27 as well

You can support the development of diesel by contributions or by sponsoring the project on Github.

diesel - Diesel 2.1.3

Published by weiznich about 1 year ago

  • Increased accidentally decreased limit around element count in DISTINCT ON and ORDER BY clauses again as that broke existing code
diesel - Diesel 2.1.2

Published by weiznich about 1 year ago

  • Fixed another potential breaking chaneg around queries containing DISTINCT ON and ORDER BY clauses consisting of custom sql expressions (e.g. .nullable())
  • Fixed an issue where #[derive(Selectable)] and #[diesel(check_for_backend)] generates invalid rust code if the struct contains lifetimes/generic types

You can support the development of diesel by contributions or by sponsoring the project on Github.

diesel - Diesel 2.1.1

Published by weiznich about 1 year ago

Fixed

  • Fixed an issue in diesel-cli that lead to using unquoted table names in one of the internal queries
  • Fixed a bug in diesel print-schema that lead to generating invalid table! macros if both the #[sql_name] and the #[max_lenght] attribute are present
  • Fixed an issue in diesel-cli that lead to ignoring certain foreign key constraints for postgresql
  • Fixed an crash while using diesel print-schema with really old sqlite versions
  • Fixed an issue where #[diesel(check_for_backend)] ignored #[diesel(deserialize_as)] attributes
  • Fixed several issues with the new #[derive(MultiConnection)] feature
  • Fixed some edge cases in our sqlite timestamp parsing behaviour
  • diesel migration generate --diff-schema now respects table filters as setup for print-schema via diesel.toml
  • Fixed a potential breaking change around queries containing DISTINCT ON and ORDER BY clauses consisting of custom sql expressions (e.g. diesel::dsl::sql)

Added

  • Support for bigdecimal 0.4

You can support the development of diesel by sponsoring the project on github

diesel - Diesel 2.1.0

Published by weiznich over 1 year ago

Diesel 2.1.0 contains the contributions of 42 people. More than 380 commits were submitted
over a span of 9 months.

This release contains several new features and improves existing features. It introduces support for generating migrations based on the diff between your schema.rs file and your database via Diesel CLI. Diesel derives now provides a #[derive(MultiConnection)] derive macro that allows to easily combine different database connections into a single enum, which implements Connection on its own. The MySQL backend gets support for upsert queries via the ON DUPLICATE KEYS syntax. Finally we provide new tooling to improve complex error messages generated for common error cases. Check out our changelog for a complete list of changes.

This release wouldn't be possible without the support of our contributors and sponsors. If you want to support diesels development, consider joining the reviewer team, submitting PR's, help writing documentation or sponsor the maintainers.

Migration generation

Diesel CLI now includes support for generating migrations based on the difference of your schema.rs file and your local database.
This works as following:

  1. Start editing your schema.rs file, for example by adding your first table:
diesel::table! {
    users {
        id -> Integer,
        name -> Text,
    }
}
  1. Run diesel migration generate my_first_migration --diff-schema --database-url DATABASE_URL
  2. Checkout, verify and possible modify the generated migration:
-- Your SQL goes here
CREATE TABLE `users`(
	`id` INTEGER NOT NULL PRIMARY KEY,
	`name` TEXT NOT NULL
);
  1. Run the migration via diesel migration run --database-url DATABASE_URL

It's important to note that the generated migrations can only contain information that are part of the schema.rs file. This explicitly excludes default value, custom check constraints and similar SQL features. We expect the generated migrations to be a good starting point for writing the actual migration you need, we do not expect them to include all necessary information in all cases or to provide the perfect solution in each scenario.

MultiConnection support

Diesel now includes a #[derive(MultiConnection)] proc macro derive, which allows to easily support more than one database backend in a single application. It can be applied to an enum of different connections:

#[derive(diesel::MultiConnection)]
pub enum AnyConnection {
    Postgresql(diesel::PgConnection),
    Mysql(diesel::MysqlConnection),
    Sqlite(diesel::SqliteConnection),
}

Afterwards the AnyConnection type can be used as ordinary connection:


fn use_multi(conn: &mut AnyConnection) -> QueryResult<()> {
   // Use the connection enum as any other connection type
   // for inserting/updating/loading/…
   diesel::insert_into(users::table)
       .values(users::name.eq("Sean"))
       .execute(conn)?;

   let users = users::table.load::<(i32, String)>(conn)?;
   Ok(())
}

By default this connection type will only support a subset of SQL that's supported by all inner connection types. By being an enum it's easy to fallback to backend specific SQL as soon as required. We provide this feature as derive macro so that it is possible to:

  • Select the backends you actually use
  • Allow to use third party connections as well (this requires the third party connection to be based at least on diesel 2.1 and to implement the MultiConnectionHelper trait in addition to the existing Connection trait.

Upsert support for the MySQL backend

Diesel 2.1 adds support for INSERT INTO … ON DUPLICATE KEYS … queries for the MySQL backend using the existing upsert framework. It's now possible to write such queries using the diesel provided DSL:

diesel::insert_into(users)
    .values(&user2)
    .on_conflict(diesel::dsl::DuplicatedKeys)
    .do_update()
    .set(name.eq("I DONT KNOW ANYMORE"))
    .execute(conn)?;

Improved error messages

We spend some effort to improve error messages generated by rustc for common diesel issues further.

Consider the following example:

table! {
    users {
        id -> Integer,
        name -> Text,
    }
}

#[derive(Queryable)]
struct User {
    name: String,
    id: i32,
}


users::table.load::<User>(&mut conn)

which would generate the following error message:

error[E0277]: the trait bound `(diesel::sql_types::Integer, diesel::sql_types::Text): load_dsl::private::CompatibleType<User, Mysql>` is not satisfied
    --> src/main.rs:20:31
     |
20   |     users::table.load::<User>(&mut conn);
     |                  ----         ^^^^^^^^^ the trait `load_dsl::private::CompatibleType<User, Mysql>` is not implemented for `(diesel::sql_types::Integer, diesel::sql_types::Text)`
     |                  |
     |                  required by a bound introduced by this call
     |
     = help: the following other types implement trait `load_dsl::private::CompatibleType<U, DB>`:
               (ST0, ST1)
               (ST0, ST1, ST2)
               (ST0, ST1, ST2, ST3)
               (ST0, ST1, ST2, ST3, ST4)
               (ST0, ST1, ST2, ST3, ST4, ST5)
               (ST0, ST1, ST2, ST3, ST4, ST5, ST6)
               (ST0, ST1, ST2, ST3, ST4, ST5, ST6, ST7)
               (ST0, ST1, ST2, ST3, ST4, ST5, ST6, ST7, ST8)
             and 24 others
     = note: required for `users::table` to implement `LoadQuery<'_, _, User>`
note: required by a bound in `diesel::RunQueryDsl::load`
    --> /home/weiznich/.cargo/git/checkouts/diesel-6e3331fb3b9331ec/ef6252e/diesel/src/query_dsl/mod.rs:1543:15
     |
1543 |         Self: LoadQuery<'query, Conn, U>,
     |               ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `diesel::RunQueryDsl::load`

This is caused by an field order mismatch between what your query returns and what your struct expects the query to return.

With diesel 2.0 we introduced the Selectable trait and a corresponding derive. That allows to automatically generate a matching select clause to prevent such issues from happening. While this already solved parts of the problem it does not solve the following case:

#[derive(Queryable, Selectable)]
struct User {
    name: i32,
    id: i32,
}

users::table.select(User::as_select()).load(&mut conn);

which generates the following error message:

error[E0277]: the trait bound `expression::select_by::SelectBy<User, _>: load_dsl::private::CompatibleType<_, _>` is not satisfied
    --> src/main.rs:20:49
     |
20   |     users::table.select(User::as_select()).load(&mut conn);
     |                                            ---- ^^^^^^^^^ the trait `load_dsl::private::CompatibleType<_, _>` is not implemented for `expression::select_by::SelectBy<User, _>`
     |                                            |
     |                                            required by a bound introduced by this call
     |
     = help: the trait `load_dsl::private::CompatibleType<U, DB>` is implemented for `expression::select_by::SelectBy<U, DB>`
     = note: required for `SelectStatement<FromClause<users::table>, query_builder::select_clause::SelectClause<expression::select_by::SelectBy<User, _>>>` to implement `LoadQuery<'_, _, _>`
note: required by a bound in `diesel::RunQueryDsl::load`
    --> /home/weiznich/.cargo/git/checkouts/diesel-6e3331fb3b9331ec/ef6252e/diesel/src/query_dsl/mod.rs:1543:15
     |
1543 |         Self: LoadQuery<'query, Conn, U>,
     |               ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `diesel::RunQueryDsl::load`

This is caused by a type mismatch in the name field. With diesel 2.1 we now introduce an additional #[diesel(check_for_backend(diesel::backend::BackendType))] attribute that greatly improves the error messages generated for these cases. This helps pining down which field exactly causes a type mismatch.

By applying this attribute to our example:


#[derive(Queryable, Selectable)]
#[diesel(check_for_backend(diesel::mysql::Mysql))]
struct User {
    name: i32,
    id: i32,
}

we get the following error message:

error[E0277]: the trait bound `i32: FromSql<diesel::sql_types::Text, Mysql>` is not satisfied
  --> src/main.rs:13:11
   |
13 |     name: i32,
   |           ^^^ the trait `FromSql<diesel::sql_types::Text, Mysql>` is not implemented for `i32`
   |
   = help: the trait `FromSql<diesel::sql_types::Integer, Mysql>` is implemented for `i32`
   = note: required for `i32` to implement `diesel::Queryable<diesel::sql_types::Text, Mysql>`
   = note: required for `i32` to implement `FromSqlRow<diesel::sql_types::Text, Mysql>`
   = help: see issue #48214

This error message now points to the exact cause of the issue: You cannot deserialize an Text value into a i32 field. This attribute accepts one or more diesel backend type to check the struct definition against. It requires that the struct is using either both, #[derive(Queryable)] and #[derive(Selectable)] or #[derive(QueryableByName)].

Internal changes

Changes listed here are relevant for crates using the i-implement-a-third-party-backend-and-opt-into-breaking-changes feature flag.
With Diesel 2.1 we have migrated some traits to use GAT. This affects the following traits:

  • RowGatWorkaround
  • ConnectionGatWorkaround
  • HasRawValue
  • HasBindCollector

These traits are removed in favour of generic associated types on the corresponding child trait.

Additionally we slightly relaxed one trait bound on BindCollector::push_bound_value to allow unsized values there as well.

Thanks

Thank you to everyone who helped make this release happen through sponsoring, bug reports, and discussion on GitHub and Gitter. While we don't have a way to collect stats on that form of contribution, it's greatly appreciated.

In addition to the Diesel core team, 42 people contributed code to this release. A huge thank you to:

  • 6293
  • Aleksei Orazov
  • Alexx Roche
  • AndrolGenhald
  • AndyJado
  • Artemis Livingstone
  • czotomo
  • Diana
  • Elliott Forde
  • Elrendio
  • Gorg Worgington
  • Heliozoa
  • Ian
  • Jake Goulding
  • Jeff Schwab
  • Jeremy Lardenois
  • johnmai
  • Leonardo Yvens
  • mikemcdermottredjack
  • Moritz Hedtke
  • MOZGIII
  • Neil Svedberg
  • Neo
  • Nishant Joshi
  • Oliver Cooper
  • Omid Rad
  • Pablito Labarta
  • Pavan Kumar Sunkara
  • Peter Todorov
  • Rutvik Patel
  • Sanchith Hegde
  • schlamar
  • sebasv
  • Silas McCroskey
  • Šimon Lukašík
  • Steven Chu
  • stormofice
  • Thomas Sieverding
  • Trevor Gross
  • Yuki Okushi
  • 无穷无尽的爱
  • 管唯宇
diesel - Diesel 2.0.4

Published by weiznich over 1 year ago

Fixed

  • Workaround the missing name resolution in rust-analyzer. This should fix type inference for some diesel queries. (It remains broken for queries containing .filter()/.inner_join()/.left_join(). These require fixes in rust-analyzer itself)
  • Fixed a bug that could lead to inserting null values instead of empty values for custom sqlite types
  • Fixed a bug that could lead to an unexpected panic while providing an out of bounds bind for sql_query in the sqlite backend
  • Fixed some mysql backend specific impl being behind the mysql instead of the mysql_backend feature flag

Added

  • Support for libsqlite3-sys 0.26
diesel - Diesel-derives 2.0.2

Published by weiznich over 1 year ago

  • Fixing the fallout of a breaking change from quote by not using their internal API
diesel - Diesel 2.0.3

Published by weiznich over 1 year ago

Fixed

  • Fixed a bug with our transaction manager implementation that caused by marking transactions as broken which could be recovered.
  • Fixed an issue with the combination of BoxableExpression and order clauses
diesel - Diesel 2.0.2

Published by weiznich about 2 years ago

Fixed

  • Reverted a fix from the 2.0.1 release that breaks valid INSERT … ON CONFLICT queries
diesel - Diesel 2.0.1

Published by weiznich about 2 years ago

This is a bugfix release containing the following fixes:

  • Fixed an issue with diesel_cli generating incompatible type names for the generate_missing_sql_type_definitions feature on PostgreSQL
  • Fixed an issue how diesel_cli handles sqlite urls while checking if a given database exists
  • Fixed an issue with PgConnection becoming unusable after hitting a database error in certain situations
  • Fixed an issue with diesel generating invalid SQL for certain INSERT … ON CONFLICT queries
  • Fixed diesel_derives generating code that triggers the disabled by default unused_qualifications lint

This release includes updated versions of diesel, diesel_cli and diesel_derives

diesel - Diesel 2.0.0

Published by weiznich about 2 years ago

Diesel 2.0.0 contains the contributions of more than 130 people. More than 1700 commits were submitted
over a span of 3 years.

As part of this release we introduced numerous new features and rewrote large parts of the internal structure.
Check out our changelog for a complete list of changes. As this is a new major Diesel release it contains a number of breaking changes. Checkout our migration guide for details about how to handle those breaking changes.

This release contains the following parts:

  • diesel 2.0.0-rc.0
  • diesel_derives 2.0.0-rc.0
  • diesel_migrations 2.0.0-rc.0
  • diesel_cli 2.0.0-rc.0
  • diesel_dynamic_schema 0.2.0-rc.0

This release marks a first prerelease of the upcoming Diesel 2.0 release. We ask you for your help to finalise the release.
Checkout the "Timeline for a Diesel 2.0 release" section for details about how you can help us finishing the release.

Features

As a highlight Diesel 2.0.0 adds support for the following features:

  • Fully type checked GROUP BY support
  • Support for table aliasing
  • Support for defining select clauses via a corresponding type
  • Support for UNION/INTERSECT queries

Support for GROUP BY clauses

Diesel 2.0 adds support for GROUP BY clauses for select queries.

This means queries like the following one will just work.

 users::table.inner_join(posts::table)
    .group_by(users::id)
    .select((users::name, count(posts::id)))

As this is the case for all other Diesel built-in query dsl, this construct is fully checked at compile time. This means Diesel
will ensure that the GROUP BY clause is valid for the current query and it will also ensure that expressions appearing inside
of your SELECT clause will match the aggregation rules provided by the current GROUP BY clause.

Support for table aliasing

Diesel 2.0 adds support for table aliasing. This enables users to write queries, where a table appears more than once in the corresponding
FROM clause. For this Diesel provides a Diesel::alias! macro that allows to define new alias for existing tables.

The following query demonstrates the support for this feature:

// 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))

Again all of this is checked at compile time. So similar to a normal table, columns from aliases are only allowed to appear if
the corresponding query actually uses the alias.

Implied selection via the new Selectable trait

Diesel 2.0 features a new Selectable trait and derive that lets users declare that a type expects a certain kind of select clause.
The major use case for this feature is to ensure that columns from a specific query are always requested in the right order
for a corresponding type implementing Queryable. This also works for complex queries involving joins or other kinds of nesting.

#[derive(Queryable, Selectable)]
struct User {
    id: i32,
    name: String,
}

let first_user = users.select(User::as_select()).first(connection)?;

Diesel enforces at type system level that once you provided such a select clause via User::as_select() you are only allowed
to construct this type from the returned result of the corresponding query. This means there is no need to specify the User type
twice in the query above.

Support for UNION/INTERSECT/EXCEPT queries

Diesel 2.0 extents the query builder to support query combinations via UNION/INTERSECT/EXCEPT. This allows you
to easily chain multiple queries together as long as they return fields of the same type. Queries like the following
one are now supported:

 users.select(user_name.nullable())
    .union(animals.select(animal_name).filter(animal_name.is_not_null()))

As always this is checked at compile time to reject invalid queries, like for example that ones containing select
clauses with different fields.

Call for Participation

The release of Diesel 2.0 does not only include the features listed above, but also marks the
point where the following things can be provided by third party crates:

  • Custom QueryDsl extensions to support previously unsupported SQL features. Checkout
    diesel_full_text_search for an example
  • Alternative query dsl implementations reusing the existing Connection infrastructure
  • Custom Connection implementations for existing backends
  • Custom Connection
    and Backend implementations for previously unsupported backends. Checkout diesel-oci for an example.

We encourage our community to try out those features. Especially we would like to see experimentation around:

  • Previously unsupported database backends
  • Pure rust implementations of existing backend implementations. Checkout this and this discussion for starting points.
  • Alternative query dsl implementations. Checkout this discussion as starting point.

Please get in touch with us for pointers, help and details.

Input for Future Roadmap

With the release of Diesel 2.0 the planing for our next releases start. Hopefully they will not take as long as Diesel 2.0. We are looking for input on which features are wanted by our community. Please open a discussion thread with your idea in our discussion forum.

Weiznich will work on improving error messages for trait heavy crates based on a Rust Foundation Project Grant. This work will hopefully improve error messages for Diesel as well. If you are aware of bad error messages please submit a
minimal example here.

Thanks

As part of this release we would like to welcome @Ten0 as part of the
diesel core team.

Thank you to everyone who helped make this release happen through bug reports, and discussion on Gitter. While we don't have a way to collect stats on that form of contribution, it's greatly appreciated.

In addition to the Diesel core team, 141 people contributed code to this release. A huge thank you to:

  • Alessandro Menezes
  • Alexander 'z33ky' Hirsch
  • Alexei Pastuchov
  • Alice Ryhl
  • Amila Welihinda
  • Andre Braga Reis
  • Andreas Runfalk
  • Andrew Safigan
  • Andrew Speed
  • Andy Russell
  • Artem Vorotnikov
  • Arve Seljebu
  • Billy Chan
  • Blas Rodriguez Irizar
  • Bryan Henry
  • Callym
  • Caroline Glassberg-Powell
  • Cassie Jones
  • Chenxi Yuan
  • Chris Eckhardt
  • Chris Hanks
  • Chris Maddox
  • Chris West (Faux)
  • Clouds Flowing
  • Corentin Henry
  • Daniel Buse
  • Danilo Bargen
  • David Teller
  • David Tulig
  • DebugSteven
  • Diggory Blake
  • Dmitriy Pleshevskiy
  • Dusty Mabe
  • DrVilepis
  • EclipsedSolari
  • Emile Fugulin
  • Emm
  • Emmanuel Surleau
  • Erlend Langseth
  • Felix Watts
  • Filip Gospodinov
  • Garrett Thornburg
  • Giorgio Gambino
  • Grégory Obanos
  • Hal Gentz
  • Han Xu
  • Heliozoa
  • Henk van der Laan
  • Henry Boisdequin
  • Hirokazu Hata
  • Iban Eguia (Razican)
  • Igor Raits
  • Ivan Tham
  • JR Heard
  • Jean SIMARD
  • Jeremy Stucki
  • Jiří Sejkora
  • jigaoqiang
  • Joel Parker Henderson
  • John Brandt
  • Jonas Platte
  • Jonas Schievink
  • Joshua Koudys
  • Juhasz Sandor
  • Justice4Joffrey
  • Katharina Fey
  • Kevin King
  • Kevin Kirchner
  • Khionu Sybiern
  • Kitsu
  • Koisell
  • Kononnable
  • Leonardo Yvens
  • Lukas Markeffsky
  • Maccesch
  • Marc-Stefan Cassola
  • Martell Malone
  • Martijn Groeneveldt
  • Martin Nordholts
  • Matthew Kuo
  • Matthieu Guillemot
  • Mcat12
  • Meven
  • Mike Cronce
  • Mr Ceperka
  • Nafiul Islam
  • Nathan Papapietro
  • Nicholas Yang
  • Oliver Cooper
  • Otto Castle
  • Pankaj Jangid
  • Paolo Barbolini
  • Paul Le Corre
  • Paul Martensen
  • Pavan Kumar Sunkara
  • Paweł Przeniczny
  • Philip Trauner
  • Raphael Arias
  • Roman
  • Ryan Leckey
  • Sarthak Singh
  • Scott Driggers
  • Sean Klein
  • Simon Ertl
  • Spencer Taylor
  • Steven Chu
  • Storm Timmermans
  • Sébastien Santoro
  • Takayuki Maeda
  • Thomas Constantine Moore
  • Thomas Eizinger
  • Thomas Etter
  • Tom MacWright
  • Tuetuopay
  • Urhengulas
  • Vanio Begic
  • WebeWizard
  • William Myers
  • Yin Jifeng
  • Yuki Okushi
  • Zane Duffield
  • blackghost1987
  • czotomo
  • dchenk
  • ejc Drobnič
  • gorbit99
  • hasezoey
  • hi-rustin
  • kevinpoitra
  • kpcyrd
  • matthew-dowdell
  • ode79
  • ropottnik
  • telios
  • theredfish
  • zoewithabang
  • Zhenhui Xie
  • Émile Fugulin
  • κeen
  • 二手掉包工程师
  • 棒棒彬_Binboy
diesel - Diesel 2.0.0 RC1

Published by weiznich about 2 years ago

We are happy to announce the release of Diesel 2.0.0 RC1

This release contains a number of fixes and improvements compared to the previous 2.0.0 RC0 release.

Notably the following fixes and improvements are included:

  • A fix for an issue preventing connection reuse with the built-in r2d2 integration
  • Support for types from the ipnet crate
  • Support for loading values via libpq's row by row mode
  • Improvements to error messages generated by #[derive(Insertable)] for the case of type mismatches

This release hopefully marks the last prerelease before a stable 2.0.0 release.
We plan to release the final 2.0.0 soon after this, as long no other blocking issues are found.

Thank you to everyone who helped make this release happen through bug reports, and discussion on Gitter. While we don't have a way to collect stats on that form of contribution, it's greatly appreciated.

In addition to the Diesel core team, 8 people contributed code to this release. A huge thank you to:

  • Chris Eckhardt
  • Emile Fugulin
  • Iban Eguia Moraza
  • Jean SIMARD
  • Martin Nordholts
  • Otto Castle
  • Sean Klein
  • Steven Chu
diesel - Diesel 2.0.0-rc.0

Published by weiznich over 2 years ago

Diesel 2.0.0-rc.0

This release marks the first release candidate for the upcoming Diesel 2.0 Release.

Diesel 2.0.0 contains the contributions of more than 130 people. More than 1700 commits were submitted
over a span of 3 years.

As part of this release we introduced numerous new features and rewrote large parts of the internal structure.
Check out our changelog for a complete list of changes. As this is a new major Diesel release it contains a number of breaking changes. Checkout our draft migration guide for details about how to handle those breaking changes.

This release contains the following parts:

  • diesel 2.0.0-rc.0
  • diesel_derives 2.0.0-rc.0
  • diesel_migrations 2.0.0-rc.0
  • diesel_cli 2.0.0-rc.0
  • diesel_dynamic_schema 0.2.0-rc.0

This release marks a first prerelease of the upcoming Diesel 2.0 release. We ask you for your help to finalise the release.
Checkout the "Timeline for a Diesel 2.0 release" section for details about how you can help us finishing the release.

Features

As a highlight Diesel 2.0.0 adds support for the following features:

  • Fully type checked GROUP BY support
  • Support for table aliasing
  • Support for defining select clauses via a corresponding type
  • Support for UNION/INTERSECT queries

Support for GROUP BY clauses

Diesel 2.0 adds support for GROUP BY clauses for select queries.

This means queries like the following one will just work.

 users::table.inner_join(posts::table)
    .group_by(users::id)
    .select((users::name, count(posts::id)))

As this is the case for all other Diesel built-in query dsl, this construct is fully checked at compile time. This means Diesel
will ensure that the GROUP BY clause is valid for the current query and it will also ensure that expressions appearing inside
of your SELECT clause will match the aggregation rules provided by the current GROUP BY clause.

Support for table aliasing

Diesel 2.0 adds support for table aliasing. This enables users to write queries, where a table appears more than once in the corresponding
FROM clause. For this Diesel provides a Diesel::alias! macro that allows to define new alias for existing tables.

The following query demonstrates the support for this feature:

// 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))

Again all of this is checked at compile time. So similar to a normal table, columns from aliases are only allowed to appear if
the corresponding query actually uses the alias.

Implied selection via the new Selectable trait

Diesel 2.0 features a new Selectable trait and derive that lets users declare that a type expects a certain kind of select clause.
The major use case for this feature is to ensure that columns from a specific query are always requested in the right order
for a corresponding type implementing Queryable. This also works for complex queries involving joins or other kinds of nesting.

#[derive(Queryable, Selectable)]
struct User {
    id: i32,
    name: String,
}

let first_user = users.select(User::as_select()).first(connection)?;

Diesel enforces at type system level that once you provided such a select clause via User::as_select() you are only allowed
to construct this type from the returned result of the corresponding query. This means there is no need to specify the User type
twice in the query above.

Support for UNION/INTERSECT/EXCEPT queries

Diesel 2.0 extents the query builder to support query combinations via UNION/INTERSECT/EXCEPT. This allows you
to easily chain multiple queries together as long as they return fields of the same type. Queries like the following
one are now supported:

 users.select(user_name.nullable())
    .union(animals.select(animal_name).filter(animal_name.is_not_null()))

As always this is checked at compile time to reject invalid queries, like for example that ones containing select
clauses with different fields.

Timeline for Diesel 2.0

We consider this release candidate of Diesel 2.0 as feature complete.
Before finally releasing a stable 2.0 release we want to address the following points:

  • Updating the guides on our web page to use the new Diesel 2.0 release
  • Improve the migration guide to cover missed details or changes
  • Improve our documentation to include more details on new features

You can help us rounding up this release by:

  • Updating your code to the RC release and report problems here
  • Help us improving the documentation by submitting reports and improvements
  • Help us porting our guides to the new release by submitting a PR here

Thanks

As part of this release we would like to welcome @Ten0 as part of the
diesel core team.

Thank you to everyone who helped make this release happen through bug reports, and discussion on Gitter. While we don't have a way to collect stats on that form of contribution, it's greatly appreciated.

In addition to the Diesel core team, 134 people contributed code to this release. A huge thank you to:

  • Alessandro Menezes
  • Alexander 'z33ky' Hirsch
  • Alexei Pastuchov
  • Alice Ryhl
  • Amila Welihinda
  • Andre Braga Reis
  • Andreas Runfalk
  • Andrew Safigan
  • Andrew Speed
  • Andy Russell
  • Artem Vorotnikov
  • Arve Seljebu
  • Billy Chan
  • Blas Rodriguez Irizar
  • Bryan Henry
  • Callym
  • Caroline Glassberg-Powell
  • Cassie Jones
  • Chenxi Yuan
  • Chris Hanks
  • Chris Maddox
  • Chris West (Faux)
  • Clouds Flowing
  • Corentin Henry
  • Daniel Buse
  • Danilo Bargen
  • David Teller
  • David Tulig
  • DebugSteven
  • Diggory Blake
  • Dmitriy Pleshevskiy
  • Dusty Mabe
  • EclipsedSolari
  • Emile Fugulin
  • Emm
  • Emmanuel Surleau
  • Erlend Langseth
  • Felix Watts
  • Filip Gospodinov
  • Garrett Thornburg
  • Giorgio Gambino
  • Grégory Obanos
  • Hal Gentz
  • Han Xu
  • Henk van der Laan
  • Henry Boisdequin
  • Hirokazu Hata
  • Iban Eguia (Razican)
  • Igor Raits
  • Ivan Tham
  • JR Heard
  • Jeremy Stucki
  • Jiří Sejkora
  • Joel Parker Henderson
  • John Brandt
  • Jonas Platte
  • Jonas Schievink
  • Joshua Koudys
  • Juhasz Sandor
  • Justice4Joffrey
  • Katharina Fey
  • Kevin King
  • Kevin Kirchner
  • Khionu Sybiern
  • Kitsu
  • Koisell
  • Kononnable
  • Leonardo Yvens
  • Lukas Markeffsky
  • Maccesch
  • Marc-Stefan Cassola
  • Martell Malone
  • Martijn Groeneveldt
  • Matthew Kuo
  • Matthieu Guillemot
  • Mcat12
  • Meven
  • Mike Cronce
  • Mr Ceperka
  • Nafiul Islam
  • Nathan Papapietro
  • Nicholas Yang
  • Oliver Cooper
  • Otto Castle
  • Pankaj Jangid
  • Paolo Barbolini
  • Paul Le Corre
  • Paul Martensen
  • Pavan Kumar Sunkara
  • Paweł Przeniczny
  • Philip Trauner
  • Raphael Arias
  • Roman
  • Ryan Leckey
  • Sarthak Singh
  • Scott Driggers
  • Sean Klein
  • Simon Ertl
  • Spencer Taylor
  • Steven Chu
  • Storm Timmermans
  • Sébastien Santoro
  • Takayuki Maeda
  • Thomas Constantine Moore
  • Thomas Eizinger
  • Thomas Etter
  • Tom MacWright
  • Tuetuopay
  • Urhengulas
  • Vanio Begic
  • WebeWizard
  • William Myers
  • Yin Jifeng
  • Yuki Okushi
  • Zane Duffield
  • blackghost1987
  • czotomo
  • dchenk
  • ejc Drobnič
  • gorbit99
  • hasezoey
  • hi-rustin
  • kevinpoitra
  • kpcyrd
  • matthew-dowdell
  • ode79
  • ropottnik
  • telios
  • theredfish
  • zoewithabang
  • Émile Fugulin
  • κeen
  • 二手掉包工程师
  • 棒棒彬_Binboy
diesel - 1.4.8

Published by weiznich about 3 years ago

This release fixes an incompatibility between features passed to diesel and diesel_migrations while using cargos new resolver feature (resolver = "2") which will become the new default with the upcoming Rust 2021 edition

diesel - 1.4.7

Published by weiznich over 3 years ago

  • Updated libsqlite3-sys to allow version 0.22
  • Updated ipnetwork to allow version 0.18
diesel - 1.4.6

Published by weiznich over 3 years ago

Fixed

  • Fixed a use-after-free issue in the QueryableByName implementation
    of our Sqlite backend
  • Updated several dependencies
diesel - 1.4.5

Published by weiznich over 4 years ago

Fixed

  • Update several dependencies
  • Fixed an issue where transactions that would fail to commit would leave the connection
    in a broken non-committed non-rolled-back state.
  • Fix a bug that result in leaking sockets/file descriptors on failed connection attempts
    for postgresql
  • Fix an incompatibility with newer libmysqlclient versions
  • Remove some potential harmful usages of mem::uninitialized
diesel - 1.4.4

Published by weiznich over 4 years ago

Fixed

  • Update several dependencies
  • Fixed a bug with printing embedded migrations

As part of this release also updated versions of migration_internals and migration_macros are published.