-
Notifications
You must be signed in to change notification settings - Fork 51
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,12 +1,11 @@ | ||||||
use sqlx::database::HasValueRef; | ||||||
use sqlx::error::BoxDynError; | ||||||
#[cfg(any( | ||||||
feature = "sqlx-mysql", | ||||||
feature = "sqlx-postgres", | ||||||
feature = "sqlx-sqlite" | ||||||
))] | ||||||
use sqlx::{database::HasArguments, encode::IsNull, Encode}; | ||||||
use sqlx::{Database, Decode, Type, Value, ValueRef}; | ||||||
use sqlx::{encode::IsNull, Encode}; | ||||||
use sqlx::{Database, Decode, Type}; | ||||||
|
||||||
use crate::{CompactString, ToCompactString}; | ||||||
|
||||||
|
@@ -28,17 +27,19 @@ where | |||||
DB: Database, | ||||||
for<'x> &'x str: Decode<'x, DB> + Type<DB>, | ||||||
{ | ||||||
fn decode(value: <DB as HasValueRef<'r>>::ValueRef) -> Result<Self, BoxDynError> { | ||||||
let value = value.to_owned(); | ||||||
let value: &str = value.try_decode()?; | ||||||
fn decode(value: <DB as Database>::ValueRef<'r>) -> Result<Self, BoxDynError> { | ||||||
let value = <&str as Decode<DB>>::decode(value)?; | ||||||
Ok(value.try_to_compact_string()?) | ||||||
} | ||||||
} | ||||||
|
||||||
#[cfg(feature = "sqlx-mysql")] | ||||||
#[cfg_attr(docsrs, doc(cfg(feature = "sqlx-mysql")))] | ||||||
impl<'q> Encode<'q, sqlx::MySql> for CompactString { | ||||||
fn encode_by_ref(&self, buf: &mut <sqlx::MySql as HasArguments<'q>>::ArgumentBuffer) -> IsNull { | ||||||
fn encode_by_ref( | ||||||
&self, | ||||||
buf: &mut <sqlx::MySql as Database>::ArgumentBuffer<'q>, | ||||||
) -> Result<IsNull, BoxDynError> { | ||||||
Encode::<'_, sqlx::MySql>::encode_by_ref(&self.as_str(), buf) | ||||||
} | ||||||
|
||||||
|
@@ -58,8 +59,8 @@ impl<'q> Encode<'q, sqlx::MySql> for CompactString { | |||||
impl<'q> Encode<'q, sqlx::Postgres> for CompactString { | ||||||
fn encode_by_ref( | ||||||
&self, | ||||||
buf: &mut <sqlx::Postgres as HasArguments<'q>>::ArgumentBuffer, | ||||||
) -> IsNull { | ||||||
buf: &mut <sqlx::Postgres as Database>::ArgumentBuffer<'q>, | ||||||
) -> Result<IsNull, BoxDynError> { | ||||||
Encode::<'_, sqlx::Postgres>::encode_by_ref(&self.as_str(), buf) | ||||||
} | ||||||
|
||||||
|
@@ -85,14 +86,17 @@ impl sqlx::postgres::PgHasArrayType for CompactString { | |||||
#[cfg(feature = "sqlx-sqlite")] | ||||||
#[cfg_attr(docsrs, doc(cfg(feature = "sqlx-sqlite")))] | ||||||
impl<'q> Encode<'q, sqlx::Sqlite> for CompactString { | ||||||
fn encode(self, buf: &mut <sqlx::Sqlite as HasArguments<'q>>::ArgumentBuffer) -> IsNull { | ||||||
fn encode( | ||||||
self, | ||||||
buf: &mut <sqlx::Sqlite as Database>::ArgumentBuffer<'q>, | ||||||
) -> Result<IsNull, BoxDynError> { | ||||||
Encode::<'_, sqlx::Sqlite>::encode(self.into_string(), buf) | ||||||
} | ||||||
|
||||||
fn encode_by_ref( | ||||||
&self, | ||||||
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) | ||||||
} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the above, here we have a |
||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needless allocation?
There was a problem hiding this comment.
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 aSqliteArgumentValue
which contains aCow<'q, str>
. Because we haveself
as an owned value, trying to useself.as_str()
doesn't work becauseself
gets dropped at the end of this scope, but needs to live for'q
.There was a problem hiding this comment.
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.