Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: upgrade to sqlx v0.8 #408

Merged
merged 5 commits into from
Dec 29, 2024
Merged

deps: upgrade to sqlx v0.8 #408

merged 5 commits into from
Dec 29, 2024

Conversation

ParkMyCar
Copy link
Owner

As it says on the tin! Upgrades the sqlx dependency to v0.8, this picks up the fix for RUSTSEC-2024-0363.

Fixes #407

fn encode(
self,
buf: &mut <sqlx::Sqlite as Database>::ArgumentBuffer<'q>,
) -> Result<IsNull, BoxDynError> {
Encode::<'_, sqlx::Sqlite>::encode(self.into_string(), buf)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Encode::<'_, sqlx::Sqlite>::encode(self.into_string(), buf)
Encode::<'_, sqlx::Sqlite>::encode(self.as_str(), buf)

Needless allocation?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this change but it doesn't work. AFAICT what's happening is buf here is a SqliteArgumentValue which contains a Cow<'q, str>. Because we have self as an owned value, trying to use self.as_str() doesn't work because self gets dropped at the end of this scope, but needs to live for 'q.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the 'q lifetime complicates life when Postgres or MySQL backend is used.

buf: &mut <sqlx::Sqlite as HasArguments<'q>>::ArgumentBuffer,
) -> IsNull {
buf: &mut <sqlx::Sqlite as Database>::ArgumentBuffer<'q>,
) -> Result<IsNull, BoxDynError> {
Encode::<'_, sqlx::Sqlite>::encode(alloc::string::String::from(self.as_str()), buf)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Encode::<'_, sqlx::Sqlite>::encode(alloc::string::String::from(self.as_str()), buf)
Encode::<'_, sqlx::Sqlite>::encode(self.as_str(), buf)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the above, here we have a SqliteArgumentValue. Trying to use self.as_str() doesn't work because then the lifetime of &self would need to be longer than 'q, but there's no way to enforce that because then our impl would contain more lifetimes than the definition of the Encode trait

@@ -41,7 +39,7 @@ where
DB: Database,
for<'x> &'x str: Decode<'x, DB> + Type<DB>,
{
fn decode(value: <DB as HasValueRef<'r>>::ValueRef) -> Result<Self, BoxDynError> {
fn decode(value: <DB as Database>::ValueRef<'r>) -> Result<Self, BoxDynError> {
let value = value.to_owned();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to_owned() here?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call! I tried removing the to_owned() but that didn't work because all we have here is a ValueRef. Instead I refactored this to use the Decode impl for &str which presumably would do the most efficient thing

@rshigapov-bhft
Copy link

@ParkMyCar , I tried to integrate this branch and tested Encode for &[CompactString]. It works.

* skip using to_owned in impl of Decode, defer to Decode impl for &str
* fix clippy in sqlx example
@ParkMyCar ParkMyCar merged commit be93edf into main Dec 29, 2024
26 of 27 checks passed
@ParkMyCar
Copy link
Owner Author

Hey @rshigapov-bhft, thanks for the comments and extra testing here! Going to merge the PR but please let me know if there is anything I missed :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RUSTSEC-2024-0363] Support sqlx 0.8
2 participants