mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-03-20 09:04:10 +00:00
Cleanup format arguments (#2650)
Inlined format args make code more readable, and code more compact. I ran this clippy command to fix most cases, and then cleaned up a few trailing commas and uncaught edge cases. ``` cargo clippy --bins --examples --benches --tests --lib --workspace --fix -- -A clippy::all -W clippy::uninlined_format_args ```
This commit is contained in:
@@ -148,11 +148,8 @@ impl<'a> TryFrom<&'a SqliteTypeInfo> for AnyTypeInfo {
|
||||
DataType::Text => AnyTypeInfoKind::Text,
|
||||
_ => {
|
||||
return Err(sqlx_core::Error::AnyDriverError(
|
||||
format!(
|
||||
"Any driver does not support the SQLite type {:?}",
|
||||
sqlite_type
|
||||
)
|
||||
.into(),
|
||||
format!("Any driver does not support the SQLite type {sqlite_type:?}")
|
||||
.into(),
|
||||
))
|
||||
}
|
||||
},
|
||||
@@ -214,7 +211,7 @@ fn map_arguments(args: AnyArguments<'_>) -> SqliteArguments<'_> {
|
||||
AnyValueKind::Text(t) => SqliteArgumentValue::Text(t),
|
||||
AnyValueKind::Blob(b) => SqliteArgumentValue::Blob(b),
|
||||
// AnyValueKind is `#[non_exhaustive]` but we should have covered everything
|
||||
_ => unreachable!("BUG: missing mapping for {:?}", val),
|
||||
_ => unreachable!("BUG: missing mapping for {val:?}"),
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ impl EstablishParams {
|
||||
}
|
||||
|
||||
if let Some(vfs) = &options.vfs {
|
||||
query_params.push(format!("vfs={}", vfs))
|
||||
query_params.push(format!("vfs={vfs}"))
|
||||
}
|
||||
|
||||
if !query_params.is_empty() {
|
||||
|
||||
@@ -430,7 +430,7 @@ pub(super) fn explain(
|
||||
) -> Result<(Vec<SqliteTypeInfo>, Vec<Option<bool>>), Error> {
|
||||
let root_block_cols = root_block_columns(conn)?;
|
||||
let program: Vec<(i64, String, i64, i64, i64, Vec<u8>)> =
|
||||
execute::iter(conn, &format!("EXPLAIN {}", query), None, false)?
|
||||
execute::iter(conn, &format!("EXPLAIN {query}"), None, false)?
|
||||
.filter_map(|res| res.map(|either| either.right()).transpose())
|
||||
.map(|row| FromRow::from_row(&row?))
|
||||
.collect::<Result<Vec<_>, Error>>()?;
|
||||
|
||||
@@ -133,7 +133,7 @@ impl Connection for SqliteConnection {
|
||||
if let OptimizeOnClose::Enabled { analysis_limit } = self.optimize_on_close {
|
||||
let mut pragma_string = String::new();
|
||||
if let Some(limit) = analysis_limit {
|
||||
write!(pragma_string, "PRAGMA analysis_limit = {}; ", limit).ok();
|
||||
write!(pragma_string, "PRAGMA analysis_limit = {limit}; ").ok();
|
||||
}
|
||||
pragma_string.push_str("PRAGMA optimize;");
|
||||
self.execute(&*pragma_string).await?;
|
||||
@@ -258,7 +258,7 @@ impl LockedSqliteHandle<'_> {
|
||||
/// The progress handler callback must not do anything that will modify the database connection that invoked
|
||||
/// the progress handler. Note that sqlite3_prepare_v2() and sqlite3_step() both modify their database connections
|
||||
/// in this context.
|
||||
pub fn set_progress_handler<F>(&mut self, num_ops: i32, mut callback: F)
|
||||
pub fn set_progress_handler<F>(&mut self, num_ops: i32, callback: F)
|
||||
where
|
||||
F: FnMut() -> bool + Send + 'static,
|
||||
{
|
||||
|
||||
@@ -35,7 +35,7 @@ impl FromStr for SqliteAutoVacuum {
|
||||
|
||||
_ => {
|
||||
return Err(Error::Configuration(
|
||||
format!("unknown value {:?} for `auto_vacuum`", s).into(),
|
||||
format!("unknown value {s:?} for `auto_vacuum`").into(),
|
||||
));
|
||||
}
|
||||
})
|
||||
|
||||
@@ -64,7 +64,7 @@ impl SqliteConnectOptions {
|
||||
|
||||
for (key, opt_value) in &self.pragmas {
|
||||
if let Some(value) = opt_value {
|
||||
write!(string, "PRAGMA {} = {}; ", key, value).ok();
|
||||
write!(string, "PRAGMA {key} = {value}; ").ok();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ impl FromStr for SqliteJournalMode {
|
||||
|
||||
_ => {
|
||||
return Err(Error::Configuration(
|
||||
format!("unknown value {:?} for `journal_mode`", s).into(),
|
||||
format!("unknown value {s:?} for `journal_mode`").into(),
|
||||
));
|
||||
}
|
||||
})
|
||||
|
||||
@@ -35,7 +35,7 @@ impl FromStr for SqliteLockingMode {
|
||||
|
||||
_ => {
|
||||
return Err(Error::Configuration(
|
||||
format!("unknown value {:?} for `locking_mode`", s).into(),
|
||||
format!("unknown value {s:?} for `locking_mode`").into(),
|
||||
));
|
||||
}
|
||||
})
|
||||
|
||||
@@ -196,7 +196,7 @@ impl SqliteConnectOptions {
|
||||
extensions: Default::default(),
|
||||
collations: Default::default(),
|
||||
serialized: false,
|
||||
thread_name: Arc::new(DebugFn(|id| format!("sqlx-sqlite-worker-{}", id))),
|
||||
thread_name: Arc::new(DebugFn(|id| format!("sqlx-sqlite-worker-{id}"))),
|
||||
command_channel_size: 50,
|
||||
row_channel_size: 50,
|
||||
optimize_on_close: OptimizeOnClose::Disabled,
|
||||
|
||||
@@ -18,7 +18,7 @@ impl SqliteConnectOptions {
|
||||
options.in_memory = true;
|
||||
options.shared_cache = true;
|
||||
let seqno = IN_MEMORY_DB_SEQ.fetch_add(1, Ordering::Relaxed);
|
||||
options.filename = Cow::Owned(PathBuf::from(format!("file:sqlx-in-memory-{}", seqno)));
|
||||
options.filename = Cow::Owned(PathBuf::from(format!("file:sqlx-in-memory-{seqno}")));
|
||||
} else {
|
||||
// % decode to allow for `?` or `#` in the filename
|
||||
options.filename = Cow::Owned(
|
||||
@@ -58,7 +58,7 @@ impl SqliteConnectOptions {
|
||||
|
||||
_ => {
|
||||
return Err(Error::Configuration(
|
||||
format!("unknown value {:?} for `mode`", value).into(),
|
||||
format!("unknown value {value:?} for `mode`").into(),
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -78,7 +78,7 @@ impl SqliteConnectOptions {
|
||||
|
||||
_ => {
|
||||
return Err(Error::Configuration(
|
||||
format!("unknown value {:?} for `cache`", value).into(),
|
||||
format!("unknown value {value:?} for `cache`").into(),
|
||||
));
|
||||
}
|
||||
},
|
||||
@@ -92,7 +92,7 @@ impl SqliteConnectOptions {
|
||||
}
|
||||
_ => {
|
||||
return Err(Error::Configuration(
|
||||
format!("unknown value {:?} for `immutable`", value).into(),
|
||||
format!("unknown value {value:?} for `immutable`").into(),
|
||||
));
|
||||
}
|
||||
},
|
||||
@@ -101,11 +101,8 @@ impl SqliteConnectOptions {
|
||||
|
||||
_ => {
|
||||
return Err(Error::Configuration(
|
||||
format!(
|
||||
"unknown query parameter `{}` while parsing connection URL",
|
||||
key
|
||||
)
|
||||
.into(),
|
||||
format!("unknown query parameter `{key}` while parsing connection URL")
|
||||
.into(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ impl FromStr for SqliteSynchronous {
|
||||
|
||||
_ => {
|
||||
return Err(Error::Configuration(
|
||||
format!("unknown value {:?} for `synchronous`", s).into(),
|
||||
format!("unknown value {s:?} for `synchronous`").into(),
|
||||
));
|
||||
}
|
||||
})
|
||||
|
||||
@@ -157,7 +157,7 @@ unsafe fn get_text_from_arg<'a>(
|
||||
match std::str::from_utf8(slice) {
|
||||
Ok(result) => Some(result),
|
||||
Err(e) => {
|
||||
log::error!("Incoming text is not valid UTF8: {e:?}",);
|
||||
log::error!("Incoming text is not valid UTF8: {e:?}");
|
||||
ffi::sqlite3_result_error_code(ctx, ffi::SQLITE_CONSTRAINT_FUNCTION);
|
||||
None
|
||||
}
|
||||
@@ -190,7 +190,7 @@ mod tests {
|
||||
.unwrap();
|
||||
for i in 0..10 {
|
||||
sqlx::query("INSERT INTO test VALUES (?)")
|
||||
.bind(format!("value {}", i))
|
||||
.bind(format!("value {i}"))
|
||||
.execute(&mut conn)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -73,7 +73,7 @@ impl DataType {
|
||||
SQLITE_TEXT => DataType::Text,
|
||||
|
||||
// https://sqlite.org/c3ref/c_blob.html
|
||||
_ => panic!("unknown data type code {}", code),
|
||||
_ => panic!("unknown data type code {code}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,7 +104,7 @@ impl FromStr for DataType {
|
||||
_ if s.contains("real") || s.contains("floa") || s.contains("doub") => DataType::Float,
|
||||
|
||||
_ => {
|
||||
return Err(format!("unknown type: `{}`", s).into());
|
||||
return Err(format!("unknown type: `{s}`").into());
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -201,6 +201,6 @@ impl<'r> Decode<'r, Sqlite> for NaiveTime {
|
||||
}
|
||||
}
|
||||
|
||||
Err(format!("invalid time: {}", value).into())
|
||||
Err(format!("invalid time: {value}").into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ impl<'r> Decode<'r, Sqlite> for Time {
|
||||
}
|
||||
}
|
||||
|
||||
Err(format!("invalid time: {}", value).into())
|
||||
Err(format!("invalid time: {value}").into())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user