style: run clippy fix and fmt (#9965)

This commit is contained in:
Brooooooklyn
2025-02-05 13:48:17 +00:00
parent db1fcf42c9
commit 58aa18afa6
11 changed files with 54 additions and 27 deletions

View File

@@ -1,6 +1,7 @@
use std::fs;
use affine_schema::get_migrator;
use sqlx::sqlite::SqliteConnectOptions;
use std::fs;
#[tokio::main]
async fn main() -> Result<(), std::io::Error> {

View File

@@ -60,7 +60,8 @@ impl SqliteDocStorage {
pub async fn list_blobs(&self) -> Result<Vec<ListedBlob>> {
let result = sqlx::query_as!(
ListedBlob,
"SELECT key, size, mime, created_at FROM blobs WHERE deleted_at IS NULL ORDER BY created_at DESC;"
"SELECT key, size, mime, created_at FROM blobs WHERE deleted_at IS NULL ORDER BY created_at \
DESC;"
)
.fetch_all(&self.pool)
.await?;
@@ -90,7 +91,7 @@ mod tests {
storage
.set_blob(SetBlob {
key: format!("test_{}", i),
data: vec![0, 0].into(),
data: vec![0, 0],
mime: "text/plain".to_string(),
})
.await
@@ -130,7 +131,7 @@ mod tests {
storage
.set_blob(SetBlob {
key: format!("test_{}", i),
data: vec![0, 0].into(),
data: vec![0, 0],
mime: "text/plain".to_string(),
})
.await
@@ -178,7 +179,7 @@ mod tests {
storage
.set_blob(SetBlob {
key: format!("test_{}", i),
data: vec![0, 0].into(),
data: vec![0, 0],
mime: "text/plain".to_string(),
})
.await

View File

@@ -84,7 +84,7 @@ impl SqliteDocStorage {
}
// Increment timestamp by 1ms and retry
timestamp = timestamp + chrono::Duration::milliseconds(1);
timestamp += chrono::Duration::milliseconds(1);
tried += 1;
}
}
@@ -102,7 +102,7 @@ impl SqliteDocStorage {
let mut tx = self.pool.begin().await?;
sqlx::query(r#"INSERT INTO updates (doc_id, data, created_at) VALUES ($1, $2, $3);"#)
.bind(&doc_id)
.bind(doc_id)
.bind(update.as_ref())
.bind(timestamp)
.execute(&mut *tx)
@@ -114,7 +114,7 @@ impl SqliteDocStorage {
ON CONFLICT(doc_id)
DO UPDATE SET timestamp=$2;"#,
)
.bind(&doc_id)
.bind(doc_id)
.bind(timestamp)
.execute(&mut *tx)
.await?;
@@ -293,7 +293,7 @@ mod tests {
storage
.set_doc_snapshot(DocRecord {
doc_id: "test".to_string(),
bin: vec![0, 0].into(),
bin: vec![0, 0],
timestamp: Utc::now().naive_utc(),
})
.await
@@ -373,7 +373,7 @@ mod tests {
let snapshot = DocRecord {
doc_id: "test".to_string(),
bin: vec![0, 0].into(),
bin: vec![0, 0],
timestamp: Utc::now().naive_utc(),
};
@@ -391,7 +391,7 @@ mod tests {
let snapshot = DocRecord {
doc_id: "test".to_string(),
bin: vec![0, 0].into(),
bin: vec![0, 0],
timestamp: Utc::now().naive_utc(),
};
@@ -404,7 +404,7 @@ mod tests {
let snapshot = DocRecord {
doc_id: "test".to_string(),
bin: vec![0, 1].into(),
bin: vec![0, 1],
timestamp: DateTime::from_timestamp_millis(Utc::now().timestamp_millis() - 1000)
.unwrap()
.naive_utc(),

View File

@@ -93,7 +93,7 @@ impl DocStoragePool {
})
}
async fn get<'a>(&'a self, universal_id: String) -> Result<Ref<'a, SqliteDocStorage>> {
async fn get(&self, universal_id: String) -> Result<Ref<SqliteDocStorage>> {
Ok(self.pool.get(universal_id).await?)
}

View File

@@ -12,7 +12,7 @@ pub struct Ref<'a, V> {
_guard: RwLockReadGuard<'a, V>,
}
impl<'a, V> Deref for Ref<'a, V> {
impl<V> Deref for Ref<'_, V> {
type Target = V;
fn deref(&self) -> &Self::Target {
@@ -24,17 +24,17 @@ pub struct RefMut<'a, V> {
_guard: RwLockMappedWriteGuard<'a, V>,
}
impl<'a, V> Deref for RefMut<'a, V> {
impl<V> Deref for RefMut<'_, V> {
type Target = V;
fn deref(&self) -> &Self::Target {
&*self._guard
&self._guard
}
}
impl<'a, V> DerefMut for RefMut<'a, V> {
impl<V> DerefMut for RefMut<'_, V> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut *self._guard
&mut self._guard
}
}
@@ -62,7 +62,7 @@ impl SqliteDocStoragePool {
RefMut { _guard: lock }
}
pub async fn get<'a>(&'a self, universal_id: String) -> Result<Ref<'a, SqliteDocStorage>> {
pub async fn get(&self, universal_id: String) -> Result<Ref<SqliteDocStorage>> {
let lock = RwLockReadGuard::try_map(self.inner.read().await, |lock| {
if let Some(storage) = lock.get(&universal_id) {
Some(storage)

View File

@@ -51,7 +51,7 @@ impl SqliteDocStorage {
let name: &str = row.try_get("description")?;
Ok(name == "init_v2")
}
_ => return Ok(false),
_ => Ok(false),
}
}

View File

@@ -1,6 +1,7 @@
use sqlx::sqlite::SqliteConnectOptions;
use std::fs;
use sqlx::sqlite::SqliteConnectOptions;
#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
napi_build::setup();

View File

@@ -89,7 +89,8 @@ impl SqliteConnection {
let blob = blob.as_ref();
sqlx::query_as!(
BlobRow,
"INSERT INTO blobs (key, data) VALUES ($1, $2) ON CONFLICT(key) DO UPDATE SET data = excluded.data",
"INSERT INTO blobs (key, data) VALUES ($1, $2) ON CONFLICT(key) DO UPDATE SET data = \
excluded.data",
key,
blob,
)
@@ -288,7 +289,8 @@ impl SqliteConnection {
pub async fn set_server_clock(&self, key: String, data: Uint8Array) -> napi::Result<()> {
let data = data.as_ref();
sqlx::query!(
"INSERT INTO server_clock (key, data) VALUES ($1, $2) ON CONFLICT(key) DO UPDATE SET data = excluded.data",
"INSERT INTO server_clock (key, data) VALUES ($1, $2) ON CONFLICT(key) DO UPDATE SET data = \
excluded.data",
key,
data,
)
@@ -342,7 +344,8 @@ impl SqliteConnection {
pub async fn set_sync_metadata(&self, key: String, data: Uint8Array) -> napi::Result<()> {
let data = data.as_ref();
sqlx::query!(
"INSERT INTO sync_metadata (key, data) VALUES ($1, $2) ON CONFLICT(key) DO UPDATE SET data = excluded.data",
"INSERT INTO sync_metadata (key, data) VALUES ($1, $2) ON CONFLICT(key) DO UPDATE SET data \
= excluded.data",
key,
data,
)