2738 Commits

Author SHA1 Message Date
Austin Bonander
8a0f1ab230 fix(pool): add timeout to return_to_pool() 2025-12-24 23:05:17 -08:00
Austin Bonander
b9781c2f10 refactor(pool): use a unique ID per connection 2025-12-24 23:05:17 -08:00
Austin Bonander
dd17a3d98b fix(pool): spawn task for before_acquire 2025-12-24 23:05:17 -08:00
Austin Bonander
3ec35e06bd WIP pool changes 2025-12-24 23:05:17 -08:00
Austin Bonander
0601c3a75d breaking(pool): use usize for all connection counts 2025-12-24 23:05:17 -08:00
Austin Bonander
54564bead6 feat: create Pool::acquire() benchmark 2025-12-24 23:05:15 -08:00
Austin Bonander
a2a219f175
fix CI: replace removed macOS runner, deprecated use of Command::cargo_bin() (#4134)
* fix(ci): update macOS intel runner version

* fix(cli/tests): replace use of deprecated `Command::cargo_bin()`
2025-12-24 21:40:53 -08:00
Joey de Waal
e8384f2a00
fix spelling (#4069) 2025-10-28 05:18:47 -07:00
Andreas Molitor
e4afbd4ca1
chore: update hashlink to v0.11.0 (#4072)
Co-authored-by: amolitor <andreas.molitor@andrena.de>
2025-10-28 04:46:25 -07:00
Austin Bonander
2a1eedd299
fix(CHANGELOG): correct link to #4015 2025-10-28 04:44:02 -07:00
Kevin R
a802da0e67
Fix typo in migration example from 'uesrs' to 'users' (#4068) 2025-10-22 19:40:50 +02:00
Austin Bonander
946b6d4d16 fix: break dev-dependency cycle because of rust-lang/cargo#15622 2025-10-14 19:08:15 -07:00
Austin Bonander
1b2b19fe8e
chore: update CHANGELOG for 0.9.0-alpha-1 (#4057) 2025-10-14 18:47:11 -07:00
Austin Bonander
388c424f48
fix(macros): smarter .env loading, caching, and invalidation (#4053)
* fix(macros): smarter `.env` loading, caching, and invalidation

* feat(mysql): test `.env` loading in CI

* feat(postgres): test `.env` loading in CI

* feat(macros): allow `DATABASE_URL` to be empty

* fix(examples/postgres): make `cargo-sqlx` executable

* fix(examples/postgres): `cargo sqlx` invocation

* feat(examples/postgres): check offline prepare on more examples

* fix(examples/postgres): the name of this step

* fix(cli): don't suppress error from `dotenv()`

* fix(ci/examples/postgres): don't use heredoc in this step

* fix(ci/examples/postgres): multi-tenant

* fix(ci/examples/sqlite): test `.env` loading

* chore: add CHANGELOG entry
2025-10-14 17:31:12 -07:00
David Uebler
064d649abd
native tls handshake: build TlsConnector in blocking threadpool (#4027)
* build TlsConnector in blocking threadpool

The openssl TlsConnector synchronously loads certificates from files.
Loading these files can block for tens of milliseconds.

* Update sqlx-core/src/net/tls/tls_native_tls.rs

---------

Co-authored-by: David Übler <david.uebler@puzzleyou.de>
Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
2025-09-23 07:23:01 -07:00
Dosenpfand
c52e129e83
fix(sqlite) Migrate revert with no-transaction (#4024)
* Fix migration reverts for no-TX SQLite

* Add regression test

---------

Co-authored-by: Markus Gasser <markus.gasser@frauscher.com>
2025-09-14 17:43:39 -07:00
iamjpotts
81526898d4
refactor(core): Remove lifetime parameter from Arguments trait (#3960)
* refactor(core): Remove lifetime parameter from Arguments trait

Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>

* refactor(core): Also relax lifetime of argument passed to Query::bind and Query::try_bind

Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>

---------

Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>
2025-09-13 21:47:45 -07:00
iamjpotts
54a0492ee2
refactor(any): Remove lifetime parameter from AnyArguments (#3958)
Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>
2025-09-12 16:11:39 -07:00
Alejandro González
1f4b5f28f3
feat(sqlite): no_tx migration support (#4015)
* chore(sqlx-postgres): fix typo in `migrate.rs` comment

* feat(sqlite): support `no_tx` migrations

SQLite includes several SQL statements that are useful during migrations but
must be executed outside of a transaction to take effect, such as `PRAGMA
foreign_keys = ON|OFF` or `VACUUM`. Additionally, advanced migrations may want
more precise control over how statements are grouped into transactions or
savepoints to achieve the desired atomicity for different parts of the
migration.

While SQLx already supports marking migrations to run outside explicit
transactions through a `-- no-transaction` comment, this feature is currently
only available for `PgConnection`'s `Migrate` implementation, leaving SQLite and
MySQL without this capability. Although it's possible to work around this
limitation by implementing custom migration logic instead of executing
`Migrator#run`, this comes at a cost of significantly reduced developer
ergonomics: code that relies on the default migration logic, such as
`#[sqlx::test]` or `cargo sqlx database setup`, won't support these migrations.

These changes extend `SqliteConnection`'s `Migrate` implementation to support
`no_tx` migrations in the same way as PostgreSQL, addressing this feature gap. I
also considered implementing the same functionality for MySQL, but since I
haven't found a practical use case for it yet, and every
non-transaction-friendly statement I could think about in MySQL triggers
implicit commits anyway, I determined it wasn't necessary at this time and could
be considered an overreach.

* test(sqlite): add test for `no_tx` migrations

* chore(sqlx-sqlite): bring back useful comment

* chore(sqlx-sqlite): unify SQL dialect in annotation comments
2025-09-08 14:55:58 -07:00
Austin Bonander
66526d9c56
refactor: tweaks after #3791 (#4022)
* restore fallback to `async-io` for `connect_tcp()` when `runtime-tokio` feature is enabled
* `smol` and `async-global-executor` both use `async-task`, so `JoinHandle` impls can be consolidated
* no need for duplicate `yield_now()` impls
* delete `impl Socket for ()`
2025-09-08 14:28:58 -07:00
Paul Xu
500cd18f19
Add Migrator::with_migrations() constructor (#4020)
* Add the helper function with_migrations() to Migrator.

* cargo fmt

* cargo fmt

* cargo fmt

* Improve comments.
2025-09-08 14:01:23 -07:00
martin-kolarik
6b828e698f
Smol+async global executor 1.80 dev (#3791)
* Sqlx-core: rename async_io dependency for async-std

* Sqlx-core: simplify TimeoutError

* Sqlx-core: code for async-global-executor

* Sqlx: integrate async-global-executor feature

* Note to unsafe

* Step up MSRV as async-global-executor needs it

* Sqlx-core: fix of unix socket build

* Unsafe fixes, smol executor added

* Workflow fix

* Changes outside sqlx_rt

* Cleanup conditional rt compilation

* Warning

* Add executors to test matrix

* Fix of skipping code sqlite due to mismatch in cargo feature names

* Smol executor isolated

* Fix, reduce number of tests, remove async_std

* Fix of test_block_on, regression

* Format fixes

* async-global-executor added

* async-std changed to 1.13

* litemap, zerofrom requires rustc 1.81

* Fix of missing _sqlite in cargo.toml

* Clippy lints

* Clean up

* Remove features combinations

* Fixes after merge

* Fix of compiling connect_tcp_address with both tokio + other executor selected

* Try to fix CI -Z minimal-versions check

Try to fix CI -Z minimal-versions check
2025-09-08 11:17:55 -07:00
Thom Wright
482c9427a9
PostgreSQL SASL – run SHA256 in a blocking executor (#4006)
* Yield while salting password for PG SASL

To prevent spenting too much time doing synchronous work on the
event loop, we yield every few iterations of the hmac-sha256.

* Remove unused bench
2025-09-05 18:02:39 -07:00
Sean Lynch
69bb5952ab
Drop cached db connections in macros upon hitting an error (#4009)
Once a connection to the database is lost all future macro evaluations
will fail. This is fine for normal compilation since it tends to be
short but causes issues with rust-analyzer since it keeps the macro
binaries loaded for a long time.

This commit changes the macro implementation to drop the cached
connection when it encounters an IO or protocol error. In practice these
seem to be the errors that show up when the connection is lost and
dumping the connection on every error would have unnecessary overhead.
2025-08-28 20:37:49 -07:00
Jonatan Czarniecki
3abb186324
make #[derive(sqlx::Type)] automatically generate impl PgHasArrayType by default for newtype structs (#4008)
add regression tests
2025-08-27 18:12:20 -07:00
Jonatan Czarniecki
e6e8fc7219
use random ports for all conatiners (#4007)
I couldn't follow the steps in `tests/README.md` because two containers failed to bind to the same port, already used by a local running database.
2025-08-27 11:16:19 -07:00
iamjpotts
c5037f1fca
chore(deps): Resolve deprecation warning for chrono Date and ymd methods (#3987)
* chore(deps): Resolve deprecation warning for chrono Date and ymd methods

Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>

* chore(ci): Fail postgres tests if compiling them generates warnings

Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>

---------

Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>
2025-08-27 11:03:03 -07:00
iamjpotts
5d4e1a4d4d
chore(deps): Set default-features=false on sqlx in workspace.dependencies (#3989)
Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>
2025-08-27 11:02:27 -07:00
Joey de Waal
4566df70a0
sqlx-postgres(tests): cleanup 2 unit tests. (#4002)
* sqlx-postgres(tests): fix positive_int domain type

* sqlx-postgres(tests): Update no pg array test

* sqlx-core: Remove conflicting Type impl for Box<JsonRawValue>
2025-08-26 22:29:10 -07:00
Dario Nieuwenhuis
648250dc6d
Add more JsonRawValue encode/decode impls. (#3859)
* Add support for `Box<JsonRawValue>` types.

This allows keeping structs that implement FromRow lifetime-free,
previously you had to use `&'a JsonRawValue`.

```rust
struct Foo {
    bar: Box<JsonRawValue>,
}
```

* Add Encode impls for `JsonRawValue`.
2025-08-25 16:40:26 -07:00
iamjpotts
99ec41913c
refactor(sqlite): Resolve duplicate test target warning for macros.rs (#3988)
* refactor(sqlite): Resolve duplicate test target warning for macros.rs

Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>

* refactor(sqlite): For macros tests, use _sqlite pseudo feature instead of #![cfg(...)] in the module

Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>

---------

Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>
2025-08-25 15:28:11 -07:00
jerryq
c01f51330a
Rename PgLTree::from to from_labels and add From<Vec<PgLTreeLabel>> implementation (#3949) 2025-08-21 22:11:35 -07:00
iamjpotts
0849fe3c5c
chore(core): Fix docstring for Query::try_bind (#3986)
* chore(core): Fix docstring for Query::try_bind

Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>

* chore(core): Touch up docstring a little more

Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>

---------

Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>
2025-08-21 22:11:12 -07:00
Austin Bonander
b81a44ddda
fix(sqlite): regression when decoding nulls (#3991) 2025-08-21 22:10:16 -07:00
Xiretza
a301d9abad
Allow single-field named structs to be transparent (#3971)
* Allow single-field named structs to be transparent

This more closely matches the criteria for e.g. #[repr(transparent)]
and #[serde(transparent)].

* Add tests, fix error messages
2025-08-21 13:57:35 -07:00
iamjpotts
ff93aa017a
refactor(sqlite): do not borrow bound values, delete lifetime on SqliteArguments (#3957)
* bug(sqlite): query macro argument lifetime use inconsistent with other db platforms

Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>

* refactor(sqlite): Improve support for references as query macro bind arguments by removing lifetime parameter from SqliteArguments

Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>

Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>

* refactor(sqlite): Introduce SqliteArgumentsBuffer type

Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>

* refactor(sqlite): Improve cloning of SqliteArgumentValue, SqliteArguments, and SqliteArgumentsBuffer

Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>

* refactor(any): Simplify AnyArguments::convert_to to convert_into

Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>

---------

Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>
2025-08-19 13:59:37 -07:00
iamjpotts
e77f32ea5e
chore: Fix warnings for custom postgres_## cfg flags (#3950)
* chore: Fix warnings for custom postgres_## cfg flags

Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>

* pr feedback - reorder cfg allowance; enable test_pg_copy_chunked test

Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>

* refactor(postgres): Remove two more deprecated cfg flag uses (from docstrings)

Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>

* refactor(ci): Use separate job for postgres ssl auth tests

Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>

---------

Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>
2025-08-18 16:17:45 -07:00
Kevin Cox
1f7af3abc2
SQLite: fix transaction level accounting with bad custom command. (#3981)
In the previous code the worker would always assume that the custom command worked. However the higher level code would run a check and notice that a transaction was not actually started and raise an error without rolling back the transaction.

This improves the code by moving the transaction check into the worker to ensure that the transaction depth tracker is only modified if the user's custom command actually started a transaction.

Fixes: https://github.com/launchbadge/sqlx/issues/3932
2025-08-18 16:16:52 -07:00
Kevin Cox
ce878ce874
Correctly ROLLBACK transaction when dropped during BEGIN. (#3980)
Previously if the transaction was dropped while the transaction was being set up it was possible that the transaction was successfully opened but not closed. In common usage this would result in returning an open transaction to the connection pool which would have unexpected effects ranging from errors due to trying to nest transaction or serious bugs such as intended changes not occurring as they were unexpectedly inside a transaction that would never commit.

This resolves the issue by constructing the `Transaction` object (which activates the drop handler) before starting to open the transaction. In the worst case this could result in trying to `ROLLBACK` a transaction that was never started but this just results in a harmless error which is much better than leaving an unexpected open transaction active on the connection.

Fixes: https://github.com/launchbadge/sqlx/issues/3932
2025-08-18 16:16:17 -07:00
iamjpotts
a096548221
refactor(ci): Use separate job for postgres ssl auth tests (#3977)
Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>
2025-08-18 16:15:37 -07:00
João Sampaio
5f8fc6b752
Pool.close: close all connections before returning (#3952)
* fix race condition in pool close (#3217)

* fix deadlock in the postgres/listen example

* Only acquire as many permits as a child pool can offer

---------

Co-authored-by: Adam Cigánek <adam.ciganek@proton.me>
2025-08-15 17:20:51 -07:00
Predko Silvestr
ed002f89e5
CLi: made cli-lib modules publicly available for other crates (#3881)
* change module visibility to public to easily integrate into other crates

* update module documentation for SQLx CLI
2025-08-15 15:06:13 -07:00
Beau Gieskens
c79ccb71b2
Bump ipnetwork to v0.21.1 (#3670) 2025-08-15 15:03:09 -07:00
iamjpotts
52e59e6b94
chore(ci): Add timeouts to ci jobs (#3968)
Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>
2025-08-15 15:01:13 -07:00
Niclas Klugmann
129e3351ae
fix documentation for rustls native root certificates (#3975) 2025-08-15 14:32:08 -07:00
Psionic K
fb6b13eee2
macros-core: give SQLX_OFFLINE_DIR from environment precedence (#3962)
We need to be able to supply this variable via the environment when built via
Nix Crane, which uses cargo vendor, which will filter the .sqlx path.  Renaming
is necessary in that case.
2025-08-15 14:31:30 -07:00
iamjpotts
c825bd36b5
chore(sqlite): Remove unused test of removed git2 feature (#3956)
Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>
2025-08-09 13:57:10 -07:00
Joey de Waal
24317d5eab
Fix logger regression (#3938) 2025-07-17 14:58:36 -07:00
Duncan
01d5443f15
feat(postgres): remove lifetime from PgAdvisoryLockGuard (#3495)
Unlike with CPU synchronization primitives, there is no semantic requirement
that the guard borrows the lock object.

We preserve the optimization of memoizing the release query by wrapping it in
an Arc. This way all instances of `PgAdvisoryLockGuard` that originate from the
same lock will share a single instance of the release query.

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
2025-07-17 02:32:05 -07:00
Austin Bonander
21598cfec6
breaking(sqlite): libsqlite3-sys versioning, feature flags, safety changes (#3928) 2025-07-17 01:13:32 -07:00