1169 Commits

Author SHA1 Message Date
zebrapurring
e627673869
chore: upgrade async-io to v2.4.1 (#3911)
* chore: upgrade async-io to v2.4

* refactor: replace `get_mut()` with `get_ref()` in Socket impls

---------

Co-authored-by: zebrapurring <>
2025-07-04 19:10:03 -07:00
Joey de Waal
60f67dbc39
feat: implement Encode, Decode, Type for Arc<str> and Arc<[u8]> (and Rc equivalents) (#3675)
* implement Encode, Decode, Type for Arc<str> and Arc<[u8]> (and Rc equivalents)

* sqlx-sqlite: Remove clone in Encode impl

* sqlx-sqlite: Remove unnecessary impls
2025-07-04 17:58:33 -07:00
Joey de Waal
0f891a3c56
Remove unnecessary boxfutures (#3525)
* Remove `BoxFuture`'s from `Connection` and `ConnectOptions`

* Remove `BoxFuture`'s for `MigrateDatabase`

* Remove `BoxFuture`'s for `TransactionManager`

* Remove `BoxFuture`'s for `TestSupport`

* Remove `BoxFuture`'s from `PgPoolCopyExt`

* Clippy fixes

* Box timeout future in debug mode
2025-07-04 17:53:46 -07:00
Bogdan Mircea
a9fb581626
fix: use Executor::fetch in QueryAs::fetch (#3886) 2025-07-04 17:44:20 -07:00
Ole Martin Ruud
a0c7769d85
Feature: Add exclusion violation error kind (#3918)
* feat: add exclusion violation error kind

* chore: add test for exclusion error kind
2025-07-04 16:52:58 -07:00
Elichai Turkel
2970559e25
Fix NoHostnameTlsVerifier for rustls 0.23.24 and above (#3861) 2025-07-02 03:48:51 -07:00
Austin Bonander
eb792a3044 fix(core): lint warning in decode.rs 2025-06-30 19:17:39 -07:00
Nipunn Koorapati
798d1075a7
Return &mut Self from the migrator set_ methods (#3526) 2025-06-30 17:13:26 -07:00
Austin Bonander
7f728295b2
fix: RawSql lifetime issues (#3613)
* chore(raw_sql): create regression test

* fix: `RawSql` lifetime issues

* chore(raw_sql): try not adding another lifetime param
2025-06-30 17:08:48 -07:00
Joey de Waal
8602d94c4d
Implement Decode, Encode and Type for Box, Arc, Cow and Rc (#3674)
* feat: implement Decode,Encode,Type for Box,Arc,Cow

* feat implement Encode,Type for Rc

* feat: implement Decode for Rc

* chore: make tests more concise

* chore: use macro's

* chore: remove conflicting impls

* chore: more macro's

* Relax Sized bound for Decode, Encode

* update unit tests

* fixes after review

* add comment in `Decode` impl

* add comment about `ToOwned` trait bound

* add comment explaining why decoding to `Cow::Owned` was chosen

* Remove unnecessary Decode impls
2025-06-30 17:03:48 -07:00
iamjpotts
64e154abfa
fix(logs): Correct spelling of aquired_after_secs tracing field (#3486)
Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>
2025-06-30 16:56:47 -07:00
Austin Bonander
25cbeedab4
feat: create sqlx.toml format (#3383)
* feat: create `sqlx.toml` format

* feat: add support for ignored_chars config to sqlx_core::migrate

* chore: test ignored_chars with `U+FEFF` (ZWNBSP/BOM)

https://en.wikipedia.org/wiki/Byte_order_mark

* refactor: make `Config` always compiled

simplifies usage while still making parsing optional for less generated code

* refactor: add origin information to `Column`

* feat(macros): implement `type_override` and `column_override` from `sqlx.toml`

* refactor(sqlx.toml): make all keys kebab-case, create `macros.preferred-crates`

* feat: make macros aware of `macros.preferred-crates`

* feat: make `sqlx-cli` aware of `database-url-var`

* feat: teach macros about `migrate.table-name`, `migrations-dir`

* feat: teach macros about `migrate.ignored-chars`

* chore: delete unused source file `sqlx-cli/src/migration.rs`

* feat: teach `sqlx-cli` about `migrate.defaults`

* feat: teach `sqlx-cli` about `migrate.migrations-dir`

* feat: teach `sqlx-cli` about `migrate.table-name`

* feat: introduce `migrate.create-schemas`

* WIP feat: create multi-tenant database example

* fix(postgres): don't fetch `ColumnOrigin` for transparently-prepared statements

* feat: progress on axum-multi-tenant example

* feat(config): better errors for mislabeled fields

* WIP feat: filling out axum-multi-tenant example

* feat: multi-tenant example

No longer Axum-based because filling out the request routes would have distracted from the purpose of the example.

* chore(ci): test multi-tenant example

* fixup after merge

* fix(ci): enable `sqlx-toml` in CLI build for examples

* fix: CI, README for `multi-tenant`

* fix: clippy warnings

* fix: multi-tenant README

* fix: sequential versioning inference for migrations

* fix: migration versioning with explicit overrides

* fix: only warn on ambiguous crates if the invocation relies on it

* fix: remove unused imports

* fix: doctest

* fix: `sqlx mig add` behavior and tests

* fix: restore original type-checking order

* fix: deprecation warning in `tests/postgres/macros.rs`

* feat: create postgres/multi-database example

* fix: examples/postgres/multi-database

* fix: cargo fmt

* chore: add tests for config `migrate.defaults`

* fix: sqlx-cli/tests/add.rs

* feat(cli): add `--config` override to all relevant commands

* chore: run `sqlx mig add` test with `RUST_BACKTRACE=1`

* fix: properly canonicalize config path for `sqlx mig add` test

* fix: get `sqlx mig add` test passing

* fix(cli): test `migrate.ignored-chars`, fix bugs

* feat: create `macros.preferred-crates` example

* fix(examples): use workspace `sqlx`

* fix: examples

* fix(sqlite): unexpected feature flags in `type_checking.rs`

* fix: run `cargo fmt`

* fix: more example fixes

* fix(ci): preferred-crates setup

* fix(examples): enable default-features for workspace `sqlx`

* fix(examples): issues in `preferred-crates`

* chore: adjust error message for missing param type in `query!()`

* doc: mention new `sqlx.toml` configuration

* chore: add `CHANGELOG` entry

Normally I generate these when cutting the release, but I wanted to take time to editorialize this one.

* doc: fix new example titles

* refactor: make `sqlx-toml` feature non-default, improve errors

* refactor: eliminate panics in `Config` read path

* chore: remove unused `axum` dependency from new examples

* fix(config): restore fallback to default config for macros

* chore(config): remove use of `once_cell` (to match `main`)
2025-06-30 16:34:46 -07:00
Paolo Barbolini
764ae2f702
chore: replace once_cell OnceCell/Lazy with std OnceLock/LazyLock (#3709) 2025-06-17 16:38:02 -07:00
Paolo Barbolini
df47ffedd2
Replace some more futures_util APIs with std variants (#3874) 2025-06-15 15:18:39 -07:00
Austin Bonander
90797200ee
groundwork for 0.9.0-alpha.1 (#3821)
* chore: bump version to `0.9.0-alpha.1`

* chore: delete unused `sqlx-bench` package

* chore: set `rust-version` to 1.85 for all crates

* fix: lots of new Clippy warnings

* fix: lots more Clippy warnings

* fix(cli): add `_sqlite` feature

* fix: lots, *lots* more Clippy warnings

* fix(core): warning in `tls_rustls`

* breaking: delete runtime+TLS combination features

* chore: don't re-export unstable `TransactionManager` trait

* chore: 0.9.0-alplha.1 CHANGELOG

* chore: increase MSRV further to 1.86

* fix: more clippy warnings
2025-06-01 21:09:55 -07:00
Josh
1b94e1d07d
chore(doc): clarify compile-time verification and case conversion behavior (#3866)
* chore(doc): clarify compile-time verification and case conversion behavior

* apply review suggestions

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>

* fix(fmt): remove trailing spaces

* fix(doc): links

---------

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
2025-05-17 21:50:18 -07:00
Nikolai Vincent Vaags
92c3845952
fix attrubute typo in doc (#3855) 2025-05-07 17:06:34 -07:00
tison
5736ab6c21
chore: clean up no longer used imports (#3845)
Signed-off-by: tison <wander4096@gmail.com>
2025-05-02 18:20:34 -07:00
Austin Bonander
f9084035d7
0.8.4 release (#3819)
* chore: prepare 0.8.4 release

* fix(postgres): send `limit: 0` for all `Execute` messages

fixes #3673

* fix: let `CertificateInput::from` infer any PEM-encoded document

https://github.com/launchbadge/sqlx/pull/3809#issuecomment-2800293813

* doc: improve documentation of `PgConnectOptions`

fixes #3740

* chore: update CHANGELOG from PR
2025-04-13 21:55:14 -07:00
Beau Gieskens
1c9cbe939a
feat: add ipnet support (#3710)
* feat: add ipnet support

* fix: ipnet not decoding IP address strings

* fix: prefer ipnetwork to ipnet for compatibility

* fix: unnecessary cfg
2025-03-23 17:19:05 -07:00
Austin Bonander
393b731d5e
Merge of #3427 (by @mpyw) and #3614 (by @bonsairobo) (#3765)
* feat: Implement `get_transaction_depth` for drivers

* test: Verify `get_transaction_depth()` on postgres

* Refactor: `TransactionManager` delegation without BC

SQLite implementation is currently WIP

* Fix: Avoid breaking changes on `AnyConnectionBackend`

* Refactor: Remove verbose `SqliteConnection` typing

* Feat: Implementation for SQLite

I have included `AtomicUsize` in `WorkerSharedState`. Ideally, it is not desirable to execute `load` and `fetch_add` in two separate steps, but we decided to allow it here since there is only one thread writing. To prevent writing from other threads, the field itself was made private, and a getter method was provided with `pub(crate)`.

* Refactor: Same approach for `cached_statements_size`

ref: a66787d36d62876b55475ef2326d17bade817aed

* Fix: Add missing `is_in_transaction` for backend

* Doc: Remove verbose "synchronously" word

* Fix: Remove useless `mut` qualifier

* feat: add Connection::begin_with

This patch completes the plumbing of an optional statement from these methods to
`TransactionManager::begin` without any validation of the provided statement.

There is a new `Error::InvalidSavePoint` which is triggered by any attempt to
call `Connection::begin_with` when we are already inside of a transaction.

* feat: add Pool::begin_with and Pool::try_begin_with

* feat: add Error::BeginFailed and validate that custom "begin" statements are successful

* chore: add tests of Error::BeginFailed

* chore: add tests of Error::InvalidSavePointStatement

* chore: test begin_with works for all SQLite "BEGIN" statements

* chore: improve comment on Connection::begin_with

* feat: add default impl of `Connection::begin_with`

This makes the new method a non-breaking change.

* refactor: combine if statement + unwrap_or_else into one match

* feat: use in-memory SQLite DB to avoid conflicts across tests run in parallel

* feedback: remove public wrapper for sqlite3_txn_state

Move the wrapper directly into the test that uses it instead.

* fix: cache Status on MySqlConnection

* fix: compilation errors

* fix: format

* fix: postgres test

* refactor: delete `Connection::get_transaction_depth`

* fix: tests

---------

Co-authored-by: mpyw <ryosuke_i_628@yahoo.co.jp>
Co-authored-by: Duncan Fairbanks <duncanfairbanks6@gmail.com>
2025-03-10 14:29:46 -07:00
Chitoku
a92626d6cc postgres: Use current tracing span when dropping PgListener 2025-03-05 01:30:38 -08:00
Mattia Righetti
c5ea6c4435
feat: sqlx sqlite expose de/serialize (#3745)
* feat: implement serialze no copy on lockedsqlitehandle

* feat: implement serialize on sqliteconnection

* feat: implement deserialize on sqliteconnection and add sqlitebuf wrapper type

* refactor: misc sqlite type and deserialize refactoring

* chore: misc clippy refactoring

* fix: misc refactoring and fixes

- pass non-owned byte slice to deserialize
- `SqliteBufError` and better error handling
- more impl for `SqliteOnwedBuf` so it can be used as a slice
- default serialize for `SqliteConnection`

* refactor: move serialize and deserialize on worker thread

This implements `Command::Serialize` and `Command::Deserialize` and moves the
serialize and deserialize logic to the worker thread.

`Serialize` will need some more iterations as it's not clear whether it would
need to wait for other write transactions before running.

* refactor: misc refactoring and changes

- Merged deserialize module with serialize module
- Moved `SqliteOwnedBuf` into serialize module
- Fixed rustdocs

* chore: API tweaks, better docs, tests

* fix: unused import

* fix: export `SqliteOwnedBuf`, docs and safety tweaks

---------

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
2025-03-02 14:29:29 -08:00
Jonas Malaco
5d6d6985cd
docs(pool): recommend actix-web ThinData over Data to avoid two Arcs (#3762)
Both actix_web::web::Data and sqlx::PgPool internally wrap an Arc. Thus,
using Data<PgPool> as an extractor in an actix-web route handler results
in two Arcs wrapping the data of interest, which isn't ideal.

Actix-web 4.9.0 introduced a new web::ThinData extractor for cases like
this, where the data is already wrapped in an `Arc` (or is otherwise
similarly cheap and sensible to simply clone), which doesn't wrap the
inner value in a (second) Arc.

Since the new extractor is better suited to the task, suggest it in
place of web::Data when giving an example on how to share a pool.
2025-02-28 16:42:53 -08:00
Marti Serra
3dec1d186a
Small doc correction. (#3755)
When sqlx-core/src/from_row.rs was updated to implement FromRow for tuples of up to 16 values, a comment was left stating that it was implemented up to tuples of 9 values.
2025-02-22 13:33:14 -08:00
Stefan Schindler
8dce6bd9e1
Fix example calculation (#3741) 2025-02-20 12:57:54 -08:00
Ethan Wang
b859914153
QueryBuilder: add debug_assert when push_values is passed an empty set of tuples (#3734)
* throw a warning in tracing so that the empty tuples would be noticed

* use debug assertion to throw a panic in debug mode
2025-02-17 17:39:40 -08:00
tottoto
3a20a92a3f
chore: replace rustls-pemfile with rustls-pki-types (#3725) 2025-02-05 13:48:19 -08:00
joeydewaal
f42561b8d7
chore: expose bstr feature (#3714) 2025-02-04 10:53:05 -08:00
Paolo Barbolini
65229f7ff9
Replace some futures_util APIs with std variants (#3721) 2025-02-01 16:01:56 -08:00
Tobias Bieniek
4d638c9e24
FromRow: Fix documentation order (#3712)
The `try_from` and `json` sections are "Field attributes" so they should probably be part of the corresponding section instead of subsections of "Manual implementation". `flatten` should be H4 instead of H3, since "Field attributes" is H3 and all other field attribute sections are H4 too.
2025-01-29 15:00:21 -08:00
Sean Aye
2aab4cd237
Add json(nullable) macro attribute (#3677)
* add json optional attribute parser and expansion

* rename attribute

* add test

* fix tests

* fix lints

* Add docs
2025-01-28 10:56:33 -08:00
Andreas Liljeqvist
a83395a360
Fix: nextest cleanup race condition (#3334)
* remove unused trait fn `cleanup_test_dbs`

* *wip* solve test cleanup race condition

* check for exactly 63 chars in database name

* move base64 dependency

* change

* Use url_safe base64 encoding

* Assert quoting for database name

* refactor

* add mysql support?

* borrow

* fix borrows

* ensure quoting

* re-add trait cleanup_test_dbs

* fix mysql insert

* cargo lock

* use actual field

* cleanup converted path in sqlite

* replace dashes with underscore in db name

* refactor: remove redundant path conversion in cleanup_test and add db_name method

---------

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
2025-01-23 17:36:55 -08:00
joeydewaal
f6d2fa3a3d
fix: handle nullable values by printing NULL instead of panicking (#3686) 2025-01-15 17:08:16 -08:00
Karam Barakat
b386862ed5 Update row.rs
Row::get should track caller for a better development experience.
2025-01-13 05:57:25 -08:00
Paolo Barbolini
7d148bd96b Bump hashbrown to v0.15 2024-12-24 01:52:20 -08:00
Paolo Barbolini
2b82ce3faa Bump hashlink to v0.10 2024-12-12 12:43:39 -08:00
joeydewaal
1f6ce33df4
chore: remove BoxFuture's (non-breaking) (#3629)
* chore: reduce BoxFuture's when using recursion.

* remove BoxFuture's in WithSocket

* chore: better document previous changes
2024-12-12 12:43:22 -08:00
Ilya Bizyaev
35c78f5175
Support building with rustls but native certificates (#3551)
This adds an alternative TLS configuration that relies on rustls-native-certs,
for users who cannot bundle the MPL-licensed webpki-roots.

The approach is copied from reqwest:

* https://github.com/seanmonstar/reqwest/blob/3ad6e02cd/Cargo.toml#L48
* https://github.com/seanmonstar/reqwest/blob/3ad6e02cd/src/async_impl/client.rs#L513

— except error handling is relaxed to accommodate for tls_config.root_cert_path.
2024-11-27 16:39:18 -08:00
XueHaonan
5c6623dee2
fix: fix example code of query_as (#3558)
query_as.rs: 230 mismatched bracket.
query_as.rs: 230 move TIMESTAMP to TIMESTAMPTZ to match type time::OffsetDateTime.
query_as.rs: 241, 251, 260 move i64 to i32 to match postgres type `INT4`.
2024-11-27 13:51:52 -08:00
Paolo Barbolini
3e8952b0d4
Bump thiserror to v2.0.0 (#3596) 2024-11-26 11:01:33 -08:00
Henri Sivonen
4fac945d5a
Remove default-features = false from url (#3601)
Fixes #3589.
2024-11-26 11:01:18 -08:00
Trevor
cadf152e99
fix: remove sqlformat (#3545)
* removed sqlformat from sql-core/src/logger.rs causing ref error to FormatOptions

* removed sqlformat from sql-core/src/logger.rs causing ref error to FormatOptions

---------

Co-authored-by: tbarnes <tbarnes@tbserver.tbarnes-server.local>
2024-10-04 21:34:18 -07:00
依云
5b8bb3b28b
Add a "sqlite-unbundled" feature that dynamically links to system libsqlite3.so library (#3507)
* Add a "sqlite-unbundled" feature that dynamically links to system libsqlite3.so library

* update README abouot the newly-added `sqlite-unbundled` feature

* Update README.md to make it clear with bulleted list

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>

* more cfg feature updates

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>

* update documentation in sqlx-sqlx/src/lib.rs too

and also mention possible build time increasement.

* cargo fmt

* Add "sqlite-unbundled" feature to sqlx-cli

* Add sqlite-unbundled to gituhb actions tests

* cfg(feature = "sqlite") => cfg(any(feature = "sqlite", feature = "sqlite-unbundled"))

* fix

* CI: make sqlite-unbundled tests workaround required-features

by duplicating the relevant test section

* use an internal "_sqlite" feature to do the conditional compilation

---------

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
2024-10-02 11:55:21 -07:00
vsuryamurthy
293c55ce89 Remove unused dependencies from sqlx-core, sqlx-cli and sqlx-postgres 2024-09-24 18:46:31 -07:00
Austin Bonander
e10789d9d7
fix cancellation issues with PgListener, PgStream::recv() (#3467)
* fix(postgres): make `PgStream::recv_unchecked()` cancel-safe

* fix(postgres): make `PgListener` close the connection on-error

* fix: incorrect math in `BufferedSocket::read_buffered()`
2024-08-27 10:54:31 -07:00
Leon Lux
f69f370f25
Clarify usage of Json/Jsonb in query macros (#3447)
* add information and example on using json in query macros

* run cargo format

* add missing bracket to docs of json

* wrap docs in hidden async function

* change no_run to ignore
2024-08-24 15:59:40 -07:00
Austin Bonander
56d0225378 chore(postgres): include nullables query in error 2024-08-23 23:39:32 -07:00
Austin Bonander
2ab7565bd8 chore: configure clippy cast lints at workspace level 2024-08-23 23:39:32 -07:00
Austin Bonander
9b3808b2d5 refactor: rename sqlx_core::io::{Encode, Decode} for clarity 2024-08-23 23:39:32 -07:00