sqlx 0.9#246
Open
peterschutt wants to merge 2 commits into
Open
Conversation
transact-rs/sqlx#3723 introduces `SqlStr` as the arg type to `query*()` functions. The only included implementation is `SqlSafeStr for &'static str`, so dynamically built queries like those found in `SqlQueryFactory` have to be constructed via `AssertSqlSafe`. PR changes `SqlQueryFactory` to hold owned `SqlStr` and return clones of those from getters where the clones return a `SqlStr` that owns an `Arc<&str>` of the original owned `String`. This is the `SqlStr` clone impl ([ref](https://github.com/transact-rs/sqlx/blob/75bc0487eb661da811bb7a3c5d158f1bd463fef4/sqlx-core/src/sql_str.rs#L129-L154)): ```rs impl Clone for SqlStr { fn clone(&self) -> Self { Self(match &self.0 { Repr::Static(s) => Repr::Static(s), Repr::Arced(s) => Repr::Arced(s.clone()), // If `.clone()` gets called once, assume it might get called again. _ => Repr::Arced(self.as_str().into()), }) } } ``` `SqlQueryFactory` becomes: ```rs pub(crate) struct SqlQueryFactory { event_table: &'static str, select_events: SqlStr, insert_event: SqlStr, all_events: SqlStr, insert_snapshot: SqlStr, update_snapshot: SqlStr, select_snapshot: SqlStr, } ``` and the getters return clones of the owned `SqlStr`s: ```rs impl SqlQueryFactory { ... pub fn select_events(&self) -> SqlStr { self.select_events.clone() } ... } ``` As we are now passing `event_table` and `snapshot_table` interpolations directly into `AssertSqlSafe` I changed their types to `&'static str` so we are making the same safety assumption [that sqlx does](https://github.com/transact-rs/sqlx/blob/75bc0487eb661da811bb7a3c5d158f1bd463fef4/sqlx-core/src/sql_str.rs#L52). sqlx 0.9 is msrv 1.94.0 per [sqlx msrv policy](https://github.com/transact-rs/sqlx/blob/75bc0487eb661da811bb7a3c5d158f1bd463fef4/sqlx-core/src/sql_str.rs#L52), so I've made the same change here. Also, sqlx removed runtime + TLS combined features so the PR reconstructs the same combinations so that this crates features remain stable.
da7d10d to
fd4f3cc
Compare
Collaborator
|
Thanks for this work @peterschutt , I had not followed those changes. I'll take a look this evening. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #246 +/- ##
==========================================
+ Coverage 85.40% 85.54% +0.14%
==========================================
Files 33 33
Lines 3433 3467 +34
==========================================
+ Hits 2932 2966 +34
Misses 501 501
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
davegarred
requested changes
Jun 2, 2026
Users passing `&'static str` to the constructor methods will continue to work unaffected. Users passing dynamically generated `&str` values to the constructors will need to wrap with `AssertSqlSafe`.
92e2f8a to
7f93224
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
transact-rs/sqlx#3723 introduces
SqlStras the arg type toquery*()functions.The only included implementation is
SqlSafeStr for &'static str, so dynamically built queries like those found inSqlQueryFactoryhave to be constructed viaAssertSqlSafe.PR changes
SqlQueryFactoryto hold ownedSqlStrand return clones of those from getters where the clones return aSqlStrthat owns anArc<&str>of the original ownedString. This is theSqlStrclone impl (ref):SqlQueryFactorybecomes:and the getters return clones of the owned
SqlStrs:As we are now passing
event_tableandsnapshot_tableinterpolations directly intoAssertSqlSafeI changed their types toimpl SqlSafeStrso we are making the same safety assumption that sqlx does.sqlx 0.9 is msrv 1.94.0 per sqlx msrv policy, so I've made the same change here.
Also, sqlx removed runtime + TLS combined features so the PR reconstructs the same combinations so that this crates features remain stable.