All user visible changes to this project will be documented in this file. This project adheres to Semantic Versioning, as described for Rust libraries in RFC #1105
pq-sys
and mysqlclient-sys
will no longer attempt to generate bindings at compile time. Generating the bindings required a bleeding edge version of clang, which caused too many issues..on_conflict_do_nothing()
now interacts with slices properly.
MysqlConnection
now implements Send
, which is required for connection pooling.
features = ["mysql"]
to Cargo.toml. See the docs for details.ON CONFLICT DO NOTHING
clause. See the docs for details.diesel::select
now work properly when boxed.Arrays containing null are now supported. infer_schema!
will never infer an array that contains null, but a table!
definition which specifies a type of Array<Nullable<X>>
can now be deserialized to Vec<Option<T>>
#[belongs_to]
associations can now be self referential. This will generate the code required for belonging_to
, without generating code for performing a join.
rust-lang-deprecated/time
crate on PostgreSQL. To use it, add features = ["deprecated-time"]
It is no longer possible to exhaustively match against result::ConnectionError
.
Updated chrono to version 0.3.
max
and min
are now always nullable. The database will return NULL
when the table is empty.
now
can now be used as an expression of type Timestamptz
.Connection::transaction
now returns your error directly instead of wrapping it in TransactionError
. It requires that the error implement From<diesel::result::Error>
.select
has changed. If you are deserializing into an option of a tuple (instead of a tuple of options), you will need to explicitly call .nullable()
. (e.g. .select(users::name, (posts::title, posts::body).nullable())
)result::TransactionError
result::TransactionResult
infer_table_from_schema!
properly handles table names with a custom schema specified.json
and jsonb
types. They can be mapped to/from serde_json::Value
. The serde
feature must be enabled to use the JSON types.print-schema
command to Diesel CLI. This command will print the output of the infer_schema!
macro. For more information run diesel help print-schema
.When possible, we will use deprecation warnings for breaking changes. Deprecated code requires the with-deprecated
feature, which is enabled by default.
The postgres
feature is no longer enabled by default by diesel
or diesel_codegen_syntex
. Add features = ["postgres"]
to your Cargo.toml
.
The persistable
module has been renamed to insertable
.
#[derive(Insertable)]
allows fields of type Option<T>
to be used with columns that are not null if they have a default value.diesel_codegen_syntex
is no longer supported. diesel_codegen
can now be used on stable Rust.
Dropped support for Rust 1.14 and earlier
Added missing impls for loading chrono::NaiveDateTime
from a column of type Timestamptz
#[derive(AsChangeset)]
no longer assumes that use diesel::prelude::*
has been done.
debug_sql!
can now properly be used with types from chrono
or std::time
.
When using PostgreSQL, attempting to get the error message of a query which could not be transmitted to the server (such as a query with greater than 65535 bind parameters) will no longer panic.
Added support for SQL NOT IN
using the ne_any
method.
The table!
macro now allows custom schemas to be specified. Example:
table! { schema_1.table_1 { id -> Integer, } }
The generated module will still be called table_1
.
The infer_table_from_schema!
macro now allows custom schemas to be specified. Example:
infer_table_from_schema!("dotenv:DATABASE_URL", "schema_1.table_1");
The infer_schema!
optionally allows a schema name as the second argument. Any schemas other than public
will be wrapped in a module with the same name as the schema. For example, schema_1.table_1
would be referenced as schema_1::table_1
.
Added support for batch insert on SQLite. This means that you can now pass a slice or vector to diesel::insert
on all backends.
EXISTS
expressions. See diesel::expression::dsl::exists
for details.#[derive(Identifiable)]
can be used with structs that have primary keys other than id
, as well as structs with composite primary keys. You can now annotate the struct with #[primary_key(nonstandard)]
or #[primary_key(foo, bar)]
.Queryable!
) have been renamed to impl_Queryable!
or similar.#[derive(Identifiable)]
now works on structs with lifetimes
Attempting to insert an empty slice will no longer panic. It does not execute any queries, but the result will indicate that we successfully inserted 0 rows.
Attempting to update a record with no changes will no longer generate invalid SQL. The result of attempting to execute the query will still be an error, but but it will be a Error::QueryBuilderError
, rather than a database error. This means that it will not abort the current transaction, and can be handled by applications.
Calling eq_any
or ne_any
with an empty array no longer panics. eq_any(vec![])
will return no rows. ne_any(vec![])
will return all rows.
Fixed support for nightlies later than 2016-11-07
Removed support for nightlies earlier than 2016-11-07
Calls to infer_table_from_schema!
will need to be wrapped in a module if called more than once. This change is to work around further limitations of the Macros 1.1 system. Example:
mod infer_users { infer_table_from_schema!("dotenv:DATABASE_URL", "users"); } pub use self::infer_users::*;
diesel_codegen
on nightlies >= 2016-10-20Added partial support for composite primary keys.
Added support for PostgreSQL NULLS FIRST
and NULLS LAST
when sorting. See http://docs.diesel.rs/diesel/prelude/trait.SortExpressionMethods.html for details.
Added support for the timestamp with time zone
type in PostgreSQL (referred to as diesel::types::Timestamptz
)
Diesel CLI can now generate bash completion. See the readme for details.
infer_schema!
and infer_table_from_schema!
can now take "env:foo"
instead of env!("foo")
and "dotenv:foo"
instead of dotenv!("foo")
. The use of dotenv
requires the dotenv
feature on diesel_codegen
, which is included by default. Using env!
and dotenv!
will no longer work with diesel_codegen
. They continue to work with diesel_codgen_syntex
, but that crate will be deprecated when Macros 1.1 is in the beta channel for Rust.
Structs annotated with #[has_many]
or #[belongs_to]
now require #[derive(Associations)]
. This is to allow them to work with Macros 1.1.
embed_migrations!
now resolves paths relative to Cargo.toml
instead of the file the macro was called from. This change is required to allow this macro to work with Macros 1.1.
diesel migrations run
will now respect migration directories overridden by command line argument or environment variableinfer_schema!
macro will no longer fetch views alongside with tables. This was a source of trouble for people that had created views or are using any extension that automatically creates views (e.g. PostGIS)#[changeset_for(foo)]
should now be written as #[derive(AsChangeset)] #[table_name="foo"]
. If you were specifying treat_none_as_null = "true"
, you should additionally have #[changeset_options(treat_none_as_null = "true")]
.#[insertable_into(foo)]
should now be written as #[derive(Insertable)] #[table_name="foo"]
.Copy
constraint has been removed from Identifiable::Id
, and Identifiable#id
now returns &Identifiable::Id
.#[belongs_to]
now respects the foreign_key
option when using diesel_codegen
or diesel_codegen_syntex
.The initial APIs have been added in the form of #[has_many]
and #[belongs_to]
. See the module documentation for more information.
The Insertable!
macro can now be used instead of #[insertable_into]
for those wishing to avoid syntax extensions from diesel_codegen
. See http://docs.diesel.rs/diesel/macro.Insertable!.html for details.
The Queryable!
macro can now be used instead of #[derive(Queryable)]
for those wishing to avoid syntax extensions from diesel_codegen
. See http://docs.diesel.rs/diesel/macro.Queryable!.html for details.
The Identifiable!
macro can now be used instead of #[derive(Identifiable)]
for those wishing to avoid syntax extensions from diesel_codegen
. See http://docs.diesel.rs/diesel/macro.Identifiable!.html for details.
The AsChangeset!
macro can now be used instead of #[changeset_for(table)]
for those wishing to avoid syntax extensions from diesel_codegen
. See http://docs.diesel.rs/diesel/macro.AsChangeset!.html for details.
Added support for the PostgreSQL ALL
operator. See http://docs.diesel.rs/diesel/pg/expression/dsl/fn.all.html for details.
Added support for RETURNING
expressions in DELETE
statements. Implicitly these queries will use RETURNING *
.
Diesel now targets nightly-2016-07-07
. Future releases will update to a newer nightly version on the date that Rust releases.
diesel_codegen
has been split into two crates. diesel_codegen
and diesel_codegen_syntex
. See this commit for migration information.
Most structs that implement Queryable
will now also need #[derive(Identifiable)]
.
infer_schema!
on SQLite now accepts a larger range of type names
types::VarChar
is now an alias for types::Text
. Most code should be unaffected by this. PG array columns are treated slightly differently, however. If you are using varchar[]
, you should switch to text[]
instead.
Struct fields annotated with #[column_name="name"]
should be changed to #[column_name(name)]
.
The structure of DatabaseError
has changed to hold more information. See http://docs.diesel.rs/diesel/result/enum.Error.html and http://docs.diesel.rs/diesel/result/trait.DatabaseErrorInformation.html for more information
Structs which implement Identifiable
can now be passed to update
and delete
. This means you can now write delete(&user).execute(&connection)
instead of delete(users.find(user.id)).execute(&connection)
&&[T]
can now be used in queries. This allows using slices with things like #[insertable_into]
.escape
method to Like
and NotLike
, to specify the escape character used in the pattern. See EscapeExpressionMethods for details.diesel_codegen
and diesel_cli
now properly rely on Diesel 0.6.0. The restriction to 0.5.0 was an oversight.
infer_schema!
now properly excludes metadata tables on SQLite.
infer_schema!
now properly maps types on SQLite.
Queries can now be boxed using the into_boxed()
method. This is useful for conditionally modifying queries without changing the type. See BoxedDsl for more details.
infer_schema!
is now supported for use with SQLite3.
The maximum table size can be increased to 52 by enabling the huge-tables
feature. This feature will substantially increase compile times.
The DISTINCT
keyword can now be added to queries via the distinct()
method.
SqliteConnection
now implements Send
diesel::result::Error
now implements Send
and Sync
. This required a change in the return type of ToSql
and FromSql
to have those bounds as well.
It is no longer possible to pass an owned value to diesel::insert
. insert
will now give a more helpful error message when you accidentally try to pass an owned value instead of a reference.
#[insertable_into]
can now be used with structs that have lifetimes with names other than 'a'
.
Tables with a single column now properly return a single element tuple. E.g. if the column was of type integer, then users::all_columns
is now (id,)
and not id
.
infer_schema!
can now work with tables that have a primary key other than id
.
no select
option for the table!
macro. This was a niche feature that didn‘t fit with Diesel’s philosophies. You can write a function that calls select
for you if you need this functionality.diesel_codegen
to allow syntex versions up to 0.30.0.Added helper function diesel_manage_updated_at('TABLE_NAME')
to postgres upon database setup. This function sets up a trigger on the specified table that automatically updates the updated_at
column to the current_timestamp
for each affected row in UPDATE
statements.
Added support for explicit RETURNING
expressions in INSERT
and UPDATE
queries. Implicitly these queries will still use RETURNING *
.
cargo install diesel_cli --no-default-features --features postgres
or cargo install diesel_cli --no-default-features --features sqlite
Added support for SQLite. Diesel still uses postgres by default. To use SQLite instead, add default-features = false, features = ["sqlite"]
to your Cargo.toml. You'll also want to add default-features = false, features = ["sqlite"]
to diesel_codegen
. Since SQLite is a much more limited database, it does not support our full set of features. You can use SQLite and PostgreSQL in the same project if you desire.
Added support for mapping types::Timestamp
, types::Date
, and types::Time
to/from chrono::NaiveDateTime
, chrono::NaiveDate
, and chrono::NaiveTime
. Add features = ["chrono"]
to enable.
Added a treat_none_as_null
option to changeset_for
. When set to true
, a model will set a field to Null
when an optional struct field is None
, instead of skipping the field entirely. The default value of the option is false
, as we think the current behavior is a much more common use case.
Added Expression#nullable()
, to allow comparisons of not null columns with nullable ones when required.
Added sum
and avg
functions.
Added the diesel setup
, diesel database setup
, and diesel database reset
commands to the CLI.
Added support for SQL IN
statements through the eq_any
method.
Added a top level select
function for select statements with no from clause. This is primarily intended to be used for testing Diesel itself, but it has been added to the public API as it will likely be useful for third party crates in the future. select(foo).from(bar)
might be a supported API in the future as an alternative to bar.select(foo)
.
Added expression::dsl::sql
as a helper function for constructing SqlLiteral
nodes. This is primarily intended to be used for testing Diesel itself, but is part of the public API as an escape hatch if our query builder DSL proves inadequate for a specific case. Use of this function in any production code is discouraged as it is inherently unsafe and avoids real type checking.
Moved most of our top level trait exports into a prelude module, and re-exported our CRUD functions from the top level. diesel::query_builder::update
and friends are now diesel::update
, and you will get them by default if you import diesel::*
. For a less aggressive glob, you can import diesel::prelude::*
, which will only export our traits.
Connection
is now a trait instead of a struct. The struct that was previously known as Connection
can be found at diesel::pg::PgConnection
.
Rename both the #[derive(Queriable)]
attribute and the Queriable
trait to use the correct spelling Queryable
.
load
and get_results
now return a Vec<Model>
instead of an iterator.
Replaced Connection#find(source, id)
with source.find(id).first(&connection)
.
The debug_sql!
macro now uses ` for identifier quoting, and ?
for bind parameters, which is closer to a “generic” backend. The previous behavior had no identifier quoting, and used PG specific bind params.
Many user facing types are now generic over the backend. This includes, but is not limited to Queryable
and Changeset
. This change should not have much impact, as most impls will have been generated by diesel_codegen, and that API has not changed.
The mostly internal NativeSqlType
has been removed. It now requires a known backend. fn<T> foo() where T: NativeSqlType
is now fn<T, DB> foo() where DB: HasSqlType<T>
Connection#query_sql
and Connection#query_sql_params
have been removed. These methods were not part of the public API, and were only meant to be used for testing Diesel itself. However, they were technically callable from any crate, so the removal has been noted here. Their usage can be replaced with bare select
and expression::dsl::sql
.Diesel CLI will no longer output notices about __diesel_schema_migrations
already existing.
Relicensed under MIT/Apache dual
Added Diesel CLI, a tool for managing your schema. See the readme for more information.
Add the ability for diesel to maintain your schema for you automatically. See the migrations module for individual methods.
Add DebugQueryBuilder to build sql without requiring a connection.
Add print_sql! and debug_sql! macros to print out and return sql strings from QueryFragments.
#[changeset_for]
can now be used with structs containing a Vec
. Fixes #63.
No longer generate invalid SQL when an optional update field is not the first field on a changeset. Fixes #68.
#[changeset_for]
can now be used with structs containing only a single field other than id
. Fixes #66.
infer_schema!
properly works with array columns. Fixes #65.
#[changeset_for(table)]
now treats Option
fields as an optional update. Previously a field with None
for the value would insert NULL
into the database field. It now does not update the field if the value is None
.
.save_changes
(generated by #[changeset_for]
) now returns a new struct, rather than mutating self
. The returned struct can be any type that implements Queryable
for the right SQL type
#[derive(Queryable)]
now allows generic parameters on the struct.
Table definitions can now support up to 26 columns. Because this increases our compile time by 3x, features = ["large-tables"]
is needed to support table definitions above 16 columns.
Quickcheck is now an optional dependency. When features = ["quickcheck"]
is added to Cargo.toml
, you'll gain Arbitrary
implementations for everything in diesel::data_types
.
Added support for the SQL MIN
function.
Added support for the Numeric
data type. Since there is no Big Decimal type in the standard library, a dumb struct has been provided which mirrors what Postgres provides, which can be converted into whatever crate you are using.
Timestamp columns can now be used with std::time::SystemTime
when compiled with --features unstable
Implemented Send
on Connection
(required for R2D2 support)
Added infer_schema!
and infer_table_from_schema!
. Both macros take a database URL, and will invoke table!
for you automatically based on the schema. infer_schema!
queries for the table names, while infer_table_from_schema!
takes a table name as the second argument.
Added an execute
method to QueryFragment
, which is intended to replace Connection#execute_returning_count
. The old method still exists for use under the hood, but has been hidden from docs and is not considered public API.
Added get_result
and get_results
, which work similarly to load
and first
, but are intended to make code read better when working with commands like create
and update
. In the future, get_result
may also check that only a single row was affected.
Added insert
, which mirrors the pattern of update
and delete
.
Added a hidden __Nonexhaustive
variant to result::Error
. This is not intended to be something you can exhaustively match on, but I do want people to be able to check for specific cases, so Box<std::error::Error>
is not an option.
query_one
, find
, and first
now assume a single row is returned. For cases where you actually expect 0 or 1 rows to be returned, the optional
method has been added to the result, in case having a Result<Option<T>>
is more ideomatic than checking for Err(NotFound)
.
Connection#insert
and Connection#insert_returning_count
have been deprecated in favor of insert