NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
crates.io · #2115 most downloaded on crates.io
Runtime abstraction used by SQLx, the Rust SQL toolkit. Not intended to be used directly.
Last release 4 years ago
no release in 18 months
Ships fairly regularly
a new release about every 2 months
Most releases are documented
notes for 16 of 18 stable releases
2 versions withdrawn
withdrawn after publishing
6 years old
20 releases · first in 2020
One column per quarter.
This is a hotfix to address the breakage caused by transitive dependencies upgrading to syn = "2".
This is a hotfix to address the breakage caused by transitive dependencies upgrading to syn = "2".
We set default-features = false for our dependency on syn = "1" to be good crates.io citizens,
but failed to enable the features we actually used, which went undetected because we transitively depended on
syn with the default features enabled through other crates,
and so they were also on for us because features are additive.
When those other dependencies upgraded to syn = "2" it was no longer enabling those features for us,
and so compilation broke for projects that don't also depend on syn = "1", transitively or otherwise.
There is no PR for this fix as there was no longer a dedicated development branch for 0.6,
but discussion can be found in issue #2418.
As of this release, the 0.7 release is in alpha and so development is no longer occurring against 0.6.
This fix will be forward-ported to 0.7.
NOTE: this is a breaking change and has been postponed to 0.7.0.
25 pull requests were merged this release cycle.
try_from attribute for FromRow derive [[@zzhengzhuo]]
IpAddr support in Postgres [[@rakshith-ravi]]prepare [[@cycraig]]#[sqlx(flatten)] for FromRow derive [[@RustyYato]]#[test] from #[sqlx::test] [[@alexander-jackson]]FromRow docs [[@zlidner]]sqlite3_exec [[@madadam]]prepare race condition in workspaces [[@cycraig]]\
target/ that cargo sqlx prepare depends on.
If you use offline mode in your workflow, please rerun cargo install sqlx-cli to upgrade.[33 pull requests][0.6.1-prs] were merged this release cycle.
33 pull requests were merged this release cycle.
FromRow trait [[@Erik1000]]std::net::IpAddr [[@meh]]
INET value in Postgres is a prefix and not a full address
(/32 for IPv4, /128 for IPv6).time crate [[@johnbcodes]]QueryBuilder::separated() [[@sbeckeriv]]sqlx::types::Json [[@jayy-lmao]]Clone for PoolOptions [[@Thomasdezeeuw]]push_tuples for QueryBuilder [[@0xdeafbeef]]#[sqlx(flatten)] attribute in FromRow [[@TheoOiry]]query_builder::Separated::push_bind_unseparated() [[@0xdeafbeef]]#[sqlx::test] for general use
QueryBuilder improvements [[@abonander]]
QueryAs instead of Query.query_as!() and FromRow [[@abonander]]dotenv with dotenvy [[@abonander]]cargo sqlx prepare --merged [[@LovecraftianHorror]]Any database driver [[@raviqqe]]CARGO_TARGET_DIR when compiling queries [[@sedrik]]BYTEA decode [[@e00E]]S or V notice fields are not UTF-8 [[@abonander]]rust-cache action for CI [[@abonander]]PgListener [[@crepererum]]master to main in docs [[@crepererum]]
This release marks the end of the 0.5.x series of releases and contains a number of breaking changes, mainly to do with backwards-incompatible depende…
This release marks the end of the 0.5.x series of releases and contains a number of breaking changes, mainly to do with backwards-incompatible dependency upgrades.
As we foresee many more of these in the future, we surveyed the community on how to handle this; the consensus appears to be "just release breaking changes more often."
As such, we expect the 0.6.x release series to be a shorter one.
39 pull requests(!) (not counting "prepare 0.5.12 release", of course) were merged this release cycle.
server_version_num from trait to inherent impl [[@AtkinsChang]]ipnetwork to 0.19 [[@paolobarbolini]]time to 0.3 [[@paolobarbolini]]rustls to 0.20 [[@paolobarbolini]]
webpki is no longer exposed in the API.bigdecimal to 0.3 [[@e00E]]Oid everywhere instead of u32 [[@paolobarbolini]]
Type, Decode, Encode impls for u32 for Postgres as it was misleading.
Postgres doesn't support unsigned ints without using an extension. These impls were decoding Postgres OIDs
as bare u32s without any context (and trying to bind a u32 to a query would produce an OID value in SQL).
This changes that to use a newtype instead, for clarity.ConnectOptions types cloneable [[@05storm26]]chrono::DateTime<FixedOffset> timezone fix [[@05storm26]]
DateTime<FixedOffset> will be stored in SQLite with the correct timezone instead of always in UTC.
This was flagged as a "potentially breaking change" since it changes how dates are sent to SQLite.git2 to 0.14 [[@joshtriplett]]PgLTree::push() infallible and take PgLTreeLabel directly [[@sebpuetz]]REAL [[@pruthvikar]]
REAL column to f64 instead of f32 as SQLite uses only 64-bit floats.sqlx::query!() with SQLite.uuid crate to v1 [[@paolobarbolini]]PoolOptions::connect_timeout to acquire_timeout for clarity.PoolOptions::after_connect, before_acquire, after_releasePool::close() slightly
.awaiting is only necessary if you want to ensure a graceful shutdown.PoolConnection::release() which was previously deprecated in favor of PoolConnection::detach()..close().PgHasArrayType for #[sqlx(transparent)] types [[@carols10cents]]
PgValueRef [[@mfreeborn]]--connect-timeout [[@abonander]]
i16 to Any driver [[@EthanYuan]]ConnectOptions and PoolOptions on Pool and database name on PgConnectOptions [[@Nukesor]]sqlx-macros [[@LovecraftianHorror]]crc to 3.0 [[@djc]]Usage to the same level as Install [[@tobymurray]][] from host string before passing to TcpStream [[@smonv]]
serde_json in macros [[@mfreeborn]]field is never read warnings on Postgres test [[@walf443]]unused result must be used warnings [[@walf443]]sqlx migrate info [[@mdtusz]]This is a hotfix that reverts [#1748] as that was an accidental breaking change: the generated PgHasArrayType impl conflicts with manual impls of the…
This is a hotfix that reverts [#1748] as that was an accidental breaking change:
the generated PgHasArrayType impl conflicts with manual impls of the trait.
This change will have to wait for 0.6.0.
[27 pull requests][0.5.12-prs] were merged this release cycle.
27 pull requests were merged this release cycle.
PgHasArrayType for serde_json::{Value, RawValue} [[@abreis]]Clone for MySqlArguments and MssqlArguments [[@0xdeafbeef]]PgHasArrayType for #[sqlx(transparent)] types [[@carols10cents]]Type for Cow<str> for MySQL, MSSQL and SQLite [[@ipetkov]]--source to migration subcommands [[@pedromfedricci]]extra_float_digits settable [[@abonander]]
None for Postgres or third-party database servers that don't support the option.PgListener preventing Pool::close() from resolving.NUMERIC[] using decimal feature [[@tm-drtina]]FromStr, Copy, PartialEq, Eq impls for options enums [[@andrewwhitehead]]heck to 0.4 [[@paolobarbolini]]regex [[@Dylan-DPC]]libsqlite3-sys [[@espindola]]query!() docs [[@vbmade2000]]DATABASE_URL to command spawned in prepare [[@LovecraftianHorror]]TSTZRANGE [[@mgrachev]]QueryAs to query_as() in docs [[@mgrachev]]query!() macros [[@tyrelr]].pgpass files [[@SebastienGllmt]]PoolConnection: don't leak connection permit if drop task fails to run [[@abonander]][20 pull requests][0.5.11-prs] were merged this release cycle.
20 pull requests were merged this release cycle.
AnyConnectOptions to a specific ConnectOptions [[@05storm26]]From for AnyConnection [[@genusistimelord]]SQLITE_LOCKED [[@madadam]]sqlx migrate info [[@ifn3]]opt-level for sqlx-macros [[@LovecraftianHorror]]Acquire examples and alternative [[@stoically]]ltree [[@cemoktra]]lquery [[@cemoktra]]NOTICE logs [[@dbeckwith]]sqlx-data.json instead of reparsing [[@LovecraftianHorror]]as _ [[@k-jun]]cargo-sqlx command-line definition [[@tranzystorek-io]]Option<T> for Any driver [[@ArGGu]]BigDecimal into NUMERIC [[@VersBinarii]]Additionally, we have introduced two mitigations for the issue of the cyclic dependency on ahash:
indexmap from 1.7.0 back to 1.6.2 so users can pin it to that
version as recommended in aHash#95.
preserve_order feature of
serde_json which gives users another place to break the cycle by simply not enabling that feature.
sqlx-data.json, however. If this is an issue for you but
the dependency cycle isn't, you can re-enable the preserve_order feature:[dependencies]
serde_json = { version = "1", features = ["preserve_order"] }
[A whopping 31 pull requests][0.5.10-prs] were merged this release cycle!
A whopping 31 pull requests were merged this release cycle!
According to this changelog, we saw 18 new contributors! However, some of these folks may have missed getting mentioned in previous entries since we only listed highlights. To avoid anyone feeling left out, I put in the effort this time and tried to list every single one here.
Pool::any_kind() [[@nitnelave]]Encode/Decode impl for Cow<'_, str> [[@Drevoed]]Clone, Copy for AnyKind [[@yuyawk]]migrate!() docs [[@zbigniewzolnierowicz]].persistent(bool) to QueryAs, QueryScalar [[@akiradeveloper]]rust_decimal::Decimal in PgRange [[@meh]]PGOPTIONS and adding custom configuration options in PgConnectOptions [[@liushuyu]]either::Either used by Executor::fetch_many() [[@DoumanAsh]]native-tls for sqlx-cli [[@SonicZentropy]]AnyConnection::kind() [[@05storm26]]runtime-async-std-native-tls as the default runtime in README.md [[@yerke]]Pool docs in a couple places [[@abonander]]libsqlite-sys to 0.23.1 [[@nitsky]]whoami dep optional, only pull it in for Postgres [[@joshtriplett]]rsa crate to 0.5 [[@paolobarbolini]]itoa and dirs [[@paolobarbolini]]chrono::Duration to PgInterval [[@yuyawk]]indexmap version requirement to 1.6.2 [[@dimfeld]]PgCopyIn [[@akiradeveloper]]~/.pgpass password after URL parsing and fix user and database ordering [[@D1plo1d]]cargo sqlx prepare: Append to existing RUSTFLAGS instead of overwriting [[@tkintscher]]PRAGMA key on a new connection before anything else. [[@parazyd]]
A hotfix release to address the issue of the sqlx crate itself still depending on older versions of sqlx-core and sqlx-macros.
A hotfix release to address the issue of the sqlx crate itself still depending on older versions of sqlx-core and
sqlx-macros.
No other changes from 0.5.8.
[A total of 24 pull requests][0.5.8-prs] were merged this release cycle! Some highlights:
A total of 24 pull requests were merged this release cycle! Some highlights:
immutable option on SQLite connections [[@djmarcin]]PRAGMAs and overriding those set by SQLx.COPY FROM/TO[[@montanalow], [@abonander]][[#1392]] use resolve_path when getting path for include_str!() [[@abonander]]
A large bugfix release, including but not limited to:
A large bugfix release, including but not limited to:
MACADDR type for Postgres [[@nomick]]PortalSuspended for array of composite types in Postgres [[@AtkinsChang]]sqlx::Pool internals using futures-intrusive [[@abonander]]
sqlx build-script to create a build.rs to watch migrations/ for changes.RUSTFLAGS=--cfg sqlx_macros_unstable to tell the compiler
to watch migrations/ for changes instead of using a build script.sqlx::migrate!() for details.INSERT/UPDATE/DELETE ... RETURNING ... in SQLite.A total of 25 pull requests were merged this release cycle!
[[#1242]] Fix infinite loop at compile time when using query macros [[@toshokan]]
[[#1235]] Fix compilation with rustls from an eager update to webpki [[@ETCaton]]
[[#1211]] Even more tweaks and fixes to the Pool internals [[@abonander]]
[#1211] Even more tweaks and fixes to the Pool internals [[@abonander]]
[#1213] Add support for bytes and chrono::NaiveDateTime to Any [[@guylapid]]
[#1224] Add support for chrono::DateTime<Local> to Any with MySQL [[@NatPRoach]]
[#1216] Skip empty lines and comments in pgpass files [[@feikesteenbergen]]
[#1218] Add support for PgMoney to the compile-time type-checking [[@iamsiddhant05]]
[[#1149]] Tweak and optimize Pool internals [[@abonander]]
[#1149] Tweak and optimize Pool internals [[@abonander]]
[#1132] Remove 'static bound on Connection::transaction [[@argv-minus-one]]
[#1128] Fix -y flag for sqlx db reset -y [[@qqwa]]
[#1099] [#1097] Truncate buffer when BufStream is dropped [[@Diggsey]]
[#1170] Remove Self: Type bounds in Encode / Decode implementations for arrays [[@jplatte]]
Enables working around the lack of support for user-defined array types:
#[derive(sqlx::Encode)]
struct Foos<'a>(&'a [Foo]);
impl sqlx::Type<sqlx::Postgres> for Foos<'_> {
fn type_info() -> PgTypeInfo {
PgTypeInfo::with_name("_foo")
}
}
query_as!(
Whatever,
"<QUERY with $1 of type foo[]>",
Foos(&foo_vec) as _,
)
[#1141] Use u16::MAX instead of i16::MAX for a check against the largest number of parameters in a query [[@crajcan]]
[#1112] Add support for DOMAIN types [[@demurgos]]
[#1100] Explicitly UNLISTEN before returning connections to the pool in PgListener [[@Diggsey]]
sqlx::Row now has a lifetime ('c) tied to the database connection. In effect, this means that you cannot store Rows or collect them into a collection.
sqlx::Row now has a lifetime ('c) tied to the database connection. In effect, this means that you cannot store Rows or collect
them into a collection. Query (returned from sqlx::query()) has map() which takes a function to map from the Row to
another type to make this transition easier.
In 0.2.x
let rows = sqlx::query("SELECT 1")
.fetch_all(&mut conn).await?;
In 0.3.x
let values: Vec<i32> = sqlx::query("SELECT 1")
.map(|row: PgRow| row.get(0))
.fetch_all(&mut conn).await?;
To assist with the above, sqlx::query_as() now supports querying directly into tuples (up to 9 elements) or
struct types with a #[derive(FromRow)].
// This extension trait is needed until a rust bug is fixed
use sqlx::postgres::PgQueryAs;
let values: Vec<(i32, bool)> = sqlx::query_as("SELECT 1, false")
.fetch_all(&mut conn).await?;
HasSqlType<T>: Database is now T: Type<Database> to mirror Encode and Decode
Query::fetch (returned from query()) now returns a new Cursor type. Cursor is a Stream-like type where the
item type borrows into the stream (which itself borrows from connection). This means that using query().fetch() you can now
stream directly from the database with zero-copy and zero-allocation.
Remove PgTypeInfo::with_oid and replace with PgTypeInfo::with_name
Results from the database are now zero-copy and no allocation beyond a shared read buffer for the TCP stream ( in other words, almost no per-query allocation ). Bind arguments still do allocate a buffer per query.
[#129] Add support for SQLite. Generated code should be very close to normal use of the C API.
Sqlite, SqliteConnection, SqlitePool, and other supporting types[#97] [#134] Add support for user-defined types. [[@Freax13]]
Rust-only domain types or transparent wrappers around SQL types. These may be used transparently inplace of the SQL type.
#[derive(sqlx::Type)]
#[repr(transparent)]
struct Meters(i32);
Enumerations may be defined in Rust and can match SQL by integer discriminant or variant name.
#[derive(sqlx::Type)]
#[repr(i32)] // Expects a INT in SQL
enum Color { Red = 1, Green = 2, Blue = 3 }
#[derive(sqlx::Type)]
#[sqlx(rename = "TEXT")] // May also be the name of a user defined enum type
#[sqlx(rename_all = "lowercase")] // similar to serde rename_all
enum Color { Red, Green, Blue } // expects 'red', 'green', or 'blue'
Postgres further supports user-defined composite types.
#[derive(sqlx::Type)]
#[sqlx(rename = "interface_type")]
struct InterfaceType {
name: String,
supplier_id: i32,
price: f64
}
[#98] [#131] Add support for asynchronous notifications in Postgres (LISTEN / NOTIFY). [[@thedodd]]
Supports automatic reconnection on connection failure.
PgListener implements Executor and may be used to execute queries. Be careful however as if the
intent is to handle and process messages rapidly you don't want to be tying up the connection
for too long. Messages received during queries are buffered and will be delivered on the next call
to recv().
let mut listener = PgListener::new(DATABASE_URL).await?;
listener.listen("topic").await?;
loop {
let message = listener.recv().await?;
println!("payload = {}", message.payload);
}
Add unchecked variants of the query macros. These will still verify the SQL for syntactic and semantic correctness with the current database but they will not check the input or output types.
This is intended as a temporary solution until query_as! is able to support user defined types.
query_as_unchecked!query_file_as_unchecked!Add support for many more types in Postgres
JSON, JSONB [[@oeb25]]INET, CIDR [[@PoiScript]]#[derive(Type)] )NUMERIC [[@abonander]]OID (u32)"CHAR" (i8)TIMESTAMP, TIMESTAMPTZ, etc. with the time crate [[@utter-step]]#[derive(Type)] ) [[@Freax13]]Query (and QueryAs; returned from query(), query_as(), query!(), and query_as!()) now will accept both &mut Connection or
&Pool where as in 0.2.x they required &mut &Pool.
Executor now takes any value that implements Execute as a query. Execute is implemented for Query and QueryAs to mean
exactly what they've meant so far, a prepared SQL query. However, Execute is also implemented for just &str which now performs
a raw or unprepared SQL query. You can further use this to fetch Rows from the database though it is not as efficient as the
prepared API (notably Postgres and MySQL send data back in TEXT mode as opposed to in BINARY mode).
use sqlx::Executor;
// Set the time zone parameter
conn.execute("SET TIME ZONE LOCAL;").await
// Demonstrate two queries at once with the raw API
let mut cursor = conn.fetch("SELECT 1; SELECT 2");
let row = cursor.next().await?.unwrap();
let value: i32 = row.get(0); // 1
let row = cursor.next().await?.unwrap();
let value: i32 = row.get(0); // 2
Query (returned from query()) no longer has fetch_one, fetch_optional, or fetch_all. You must map the row using map() and then
you will have a query::Map value that has the former methods available.
let values: Vec<i32> = sqlx::query("SELECT 1")
.map(|row: PgRow| row.get(0))
.fetch_all(&mut conn).await?;
[#62] [#130] [#135] Remove explicit set of IntervalStyle. Allow usage of SQLx for CockroachDB and potentially PgBouncer. [[@bmisiak]]
[#108] Allow nullable and borrowed values to be used as arguments in query! and query_as!. For example, where the column would
resolve to String in Rust (TEXT, VARCHAR, etc.), you may now use Option<String>, Option<&str>, or &str instead. [[@abonander]]
[#108] Make unknown type errors far more informative. As an example, trying to SELECT a DATE column will now try and tell you about the
chrono feature. [[@abonander]]
optional feature `chrono` required for type DATE of column #1 ("now")
https://github.com/launchbadge/sqlx/issues/47
Support Tokio through an optional runtime-tokio feature.
Support SQL transactions. You may now use the begin() function on Pool or Connection to
start a new SQL transaction. This returns sqlx::Transaction which will ROLLBACK on Drop
or can be explicitly COMMIT using commit().
Support TLS connections.
Nothing published for this version
Nothing published for this version
Your coding agent can read these notes before it upgrades. Set up the MCP server →