Reformat code

This commit is contained in:
micialware committed 2026-08-31 11:26:05 +03:00
1 parent 2fc58fcc2d
commit 29a90d48d9
8 files changed
+26 -33

No files matched your search

+3 -3
View File
@@ -3,7 +3,7 @@ pub mod repositories;
use rusqlite::ToSql; use rusqlite::ToSql;
use rusqlite::types::{FromSql, FromSqlError, FromSqlResult, ToSqlOutput, ValueRef}; use rusqlite::types::{FromSql, FromSqlError, FromSqlResult, ToSqlOutput, ValueRef};
use std::fmt::{write, Display, Formatter}; use std::fmt::{Display, Formatter, write};
use std::num::ParseIntError; use std::num::ParseIntError;
use std::str::FromStr; use std::str::FromStr;
@@ -63,7 +63,7 @@ macro_rules! id_impl {
self.0 != 0 self.0 != 0
} }
} }
} };
} }
id_impl!(u32, Id, INVALID_ID); id_impl!(u32, Id, INVALID_ID);
@@ -79,4 +79,4 @@ impl From<Id> for SmallId {
fn from(value: Id) -> Self { fn from(value: Id) -> Self {
Self(value.0 as u16) Self(value.0 as u16)
} }
} }
+1 -1
View File
@@ -3,13 +3,13 @@ use crate::core::srs::{FADE_PER_DAY, MAX_SCORE, OrderMode, WordOpenMode};
use crate::data::{INVALID_ID, Id}; use crate::data::{INVALID_ID, Id};
use chrono::{DateTime, NaiveDate, Utc}; use chrono::{DateTime, NaiveDate, Utc};
use fsrs::MemoryState; use fsrs::MemoryState;
use litemap::LiteMap;
use log::info; use log::info;
use rayon::prelude::*; use rayon::prelude::*;
use rhai::{Engine, Scope}; use rhai::{Engine, Scope};
use std::cmp::Ordering; use std::cmp::Ordering;
use std::marker::PhantomData; use std::marker::PhantomData;
use std::time::Instant; use std::time::Instant;
use litemap::LiteMap;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct WordData { pub struct WordData {
+3 -2
View File
@@ -320,7 +320,8 @@ impl<T: EntityData + Clone, D: DbLayer<T>> Repository<T, D> for DataRepositoryIn
} }
fn create_now(&mut self, mut new: T) -> Result<EntityHandle<T>, NotificationData> { fn create_now(&mut self, mut new: T) -> Result<EntityHandle<T>, NotificationData> {
self.data_layer.add_entity(&mut new, &self.connection.read())?; self.data_layer
.add_entity(&mut new, &self.connection.read())?;
let index = self.cache.len(); let index = self.cache.len();
let handle = EntityHandle::new(new.id(), index, true); let handle = EntityHandle::new(new.id(), index, true);
self.cache.push(new); self.cache.push(new);
@@ -378,7 +379,7 @@ impl<T: EntityData + Clone, D: DbLayer<T>> Repository<T, D> for DataRepositoryIn
fn start(&mut self) -> MaybeError { fn start(&mut self) -> MaybeError {
if self.version != 0 { if self.version != 0 {
return Ok(()) return Ok(());
} }
self.init()?; self.init()?;
+2 -2
View File
@@ -1,6 +1,6 @@
use rusqlite::{Error, Params, Row};
use crate::data::entities::WordGroup; use crate::data::entities::WordGroup;
use crate::data_provider::TableAccessQuerySet; use crate::data_provider::TableAccessQuerySet;
use rusqlite::{Error, Params, Row};
pub struct CustomFieldsQuerySet; pub struct CustomFieldsQuerySet;
impl TableAccessQuerySet<WordGroup> for CustomFieldsQuerySet { impl TableAccessQuerySet<WordGroup> for CustomFieldsQuerySet {
@@ -34,4 +34,4 @@ impl TableAccessQuerySet<WordGroup> for CustomFieldsQuerySet {
fn update_params(entity: &WordGroup) -> impl Params { fn update_params(entity: &WordGroup) -> impl Params {
(&entity.name, entity.id) (&entity.name, entity.id)
} }
} }
+7 -1
View File
@@ -46,7 +46,13 @@ impl TableAccessQuerySet<DeckSettings> for DeckQuerySet {
} }
fn update_params(entity: &DeckSettings) -> impl Params { fn update_params(entity: &DeckSettings) -> impl Params {
(&entity.name, &entity.forward, &entity.backward, &entity.filter, entity.id) (
&entity.name,
&entity.forward,
&entity.backward,
&entity.filter,
entity.id,
)
} }
} }
+5 -17
View File
@@ -9,6 +9,7 @@ use std::marker::PhantomData;
use std::time::Instant; use std::time::Instant;
pub(crate) mod card_states; pub(crate) mod card_states;
pub mod custom_fields;
pub(crate) mod decks; pub(crate) mod decks;
pub(crate) mod history; pub(crate) mod history;
pub(crate) mod import; pub(crate) mod import;
@@ -16,9 +17,8 @@ pub(crate) mod settings;
pub(crate) mod sqlite; pub(crate) mod sqlite;
pub(crate) mod voice; pub(crate) mod voice;
pub(crate) mod web_api; pub(crate) mod web_api;
pub(crate) mod words;
pub mod word_groups; pub mod word_groups;
pub mod custom_fields; pub(crate) mod words;
pub trait TableAccessQuerySet<T> { pub trait TableAccessQuerySet<T> {
fn load() -> &'static str; fn load() -> &'static str;
@@ -44,11 +44,7 @@ impl<T: EntityData, Q: TableAccessQuerySet<T>> DbLayer<T> for SqliteDbLayer<T, Q
connection connection
.execute(Q::load(), Q::update_params(entity)) .execute(Q::load(), Q::update_params(entity))
.map_err(|_| DbSaveError)?; .map_err(|_| DbSaveError)?;
debug!( debug!("Updated in {} for {:?}", Q::name(), time.elapsed());
"Updated in {} for {:?}",
Q::name(),
time.elapsed()
);
Ok(()) Ok(())
} }
@@ -60,11 +56,7 @@ impl<T: EntityData, Q: TableAccessQuerySet<T>> DbLayer<T> for SqliteDbLayer<T, Q
.map_err(|_| DbSaveError)?; .map_err(|_| DbSaveError)?;
entity.set_id(index.into()); entity.set_id(index.into());
debug!( debug!("Added into {} for {:?}", Q::name(), time.elapsed());
"Added into {} for {:?}",
Q::name(),
time.elapsed()
);
Ok(()) Ok(())
} }
@@ -80,11 +72,7 @@ impl<T: EntityData, Q: TableAccessQuerySet<T>> DbLayer<T> for SqliteDbLayer<T, Q
(&id,), (&id,),
) )
.map_err(|_| DbSaveError)?; .map_err(|_| DbSaveError)?;
debug!( debug!("Deleted from {} for {:?}", Q::name(), time.elapsed());
"Deleted from {} for {:?}",
Q::name(),
time.elapsed()
);
Ok(()) Ok(())
} }
+2 -2
View File
@@ -1,6 +1,6 @@
use rusqlite::{Error, Params, Row};
use crate::data::entities::WordGroup; use crate::data::entities::WordGroup;
use crate::data_provider::TableAccessQuerySet; use crate::data_provider::TableAccessQuerySet;
use rusqlite::{Error, Params, Row};
pub struct WordGroupQuerySet; pub struct WordGroupQuerySet;
impl TableAccessQuerySet<WordGroup> for WordGroupQuerySet { impl TableAccessQuerySet<WordGroup> for WordGroupQuerySet {
@@ -34,4 +34,4 @@ impl TableAccessQuerySet<WordGroup> for WordGroupQuerySet {
fn update_params(entity: &WordGroup) -> impl Params { fn update_params(entity: &WordGroup) -> impl Params {
(&entity.name, entity.id) (&entity.name, entity.id)
} }
} }
+3 -5
View File
@@ -2,9 +2,9 @@ use crate::data::entities::{WordData, WordGroup};
use crate::data_provider::TableAccessQuerySet; use crate::data_provider::TableAccessQuerySet;
use crate::notification::NotificationData::{DbLoadError, DbSaveError}; use crate::notification::NotificationData::{DbLoadError, DbSaveError};
use crate::notification::{MaybeError, NotificationData}; use crate::notification::{MaybeError, NotificationData};
use litemap::LiteMap;
use rusqlite::{Connection, Error, Params, Row, params}; use rusqlite::{Connection, Error, Params, Row, params};
use std::collections::HashMap; use std::collections::HashMap;
use litemap::LiteMap;
pub struct WordQuerySet; pub struct WordQuerySet;
impl TableAccessQuerySet<WordData> for WordQuerySet { impl TableAccessQuerySet<WordData> for WordQuerySet {
@@ -31,8 +31,7 @@ impl TableAccessQuerySet<WordData> for WordQuerySet {
key: row.get(1)?, key: row.get(1)?,
value: row.get(2)?, value: row.get(2)?,
tags: row.get(3)?, tags: row.get(3)?,
additional: serde_json::from_str(&additional) additional: serde_json::from_str(&additional).unwrap_or_default(),
.unwrap_or_default(),
group_id: row.get(5)?, group_id: row.get(5)?,
}) })
} }
@@ -153,8 +152,7 @@ pub fn load_words(connection: &Connection) -> Result<Vec<WordData>, Notification
key: row.get(1)?, key: row.get(1)?,
value: row.get(2)?, value: row.get(2)?,
tags: row.get(3)?, tags: row.get(3)?,
additional: serde_json::from_str(&additional) additional: serde_json::from_str(&additional).unwrap_or_default(),
.unwrap_or_default(),
group_id: row.get(5)?, group_id: row.get(5)?,
}) })
}) })