chore: rename load_by_class to load
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use crate::*;
|
||||
|
||||
impl Catalog {
|
||||
/// Loads all entities of a specific class from the database into the in-memory catalog.
|
||||
/// Loads all entities of a specific type from the database into the in-memory catalog.
|
||||
///
|
||||
/// This method fetches all entities matching the given class from the database.
|
||||
/// If any of the loaded entities have IDs that match entities already in the
|
||||
@@ -23,7 +23,7 @@ impl Catalog {
|
||||
///
|
||||
/// Returns `Err(FailedTo::LoadFromDB)` if there is an issue loading entities
|
||||
/// from the database.
|
||||
pub fn load_by_class<T>(&mut self) -> Result<(), FailedTo>
|
||||
pub fn load<T>(&mut self) -> Result<(), FailedTo>
|
||||
where
|
||||
T: EAV,
|
||||
{
|
||||
@@ -11,7 +11,7 @@ pub mod catalog_is_empty;
|
||||
pub mod catalog_len;
|
||||
pub mod catalog_list_by_class;
|
||||
pub mod catalog_list_by_class_and_subclass;
|
||||
pub mod catalog_load_by_class;
|
||||
pub mod catalog_load;
|
||||
pub mod catalog_load_by_filter;
|
||||
pub mod catalog_load_by_id;
|
||||
pub mod catalog_persist;
|
||||
|
||||
@@ -69,7 +69,7 @@ mod tests {
|
||||
catalog1.persist().unwrap();
|
||||
// 2. new catalog -> 'load_by_class' -> 'list_by_class'
|
||||
let mut catalog2 = Catalog::new(db_path);
|
||||
catalog2.load_by_class::<Item>().unwrap();
|
||||
catalog2.load::<Item>().unwrap();
|
||||
let mut loaded_items: Vec<Item> = catalog2
|
||||
.list_by_class::<Item>()
|
||||
.unwrap()
|
||||
|
||||
@@ -36,7 +36,7 @@ mod tests {
|
||||
catalog1.persist().unwrap();
|
||||
// 2. Create a new catalog and load the items by class
|
||||
let mut catalog2 = Catalog::new(db_path);
|
||||
let result = catalog2.load_by_class::<Item>();
|
||||
let result = catalog2.load::<Item>();
|
||||
assert!(result.is_ok());
|
||||
// 3. Verify that all items of that class were loaded
|
||||
let len = catalog2.len().unwrap();
|
||||
@@ -102,7 +102,7 @@ mod tests {
|
||||
"Memory Version"
|
||||
);
|
||||
// 3. Load from the database, which should overwrite the in-memory version.
|
||||
let result = catalog2.load_by_class::<Item>();
|
||||
let result = catalog2.load::<Item>();
|
||||
assert!(result.is_ok());
|
||||
// 4. Verify that the in-memory entity has been replaced with the one from the DB.
|
||||
let len = catalog2.len().unwrap();
|
||||
@@ -131,7 +131,7 @@ mod tests {
|
||||
let mut catalog = Catalog::new(db_path);
|
||||
catalog.init().unwrap();
|
||||
// 2. Attempt to load from the empty DB.
|
||||
let result = catalog.load_by_class::<Item>();
|
||||
let result = catalog.load::<Item>();
|
||||
assert!(result.is_ok());
|
||||
let is_empty = catalog.is_empty().unwrap();
|
||||
assert!(is_empty);
|
||||
@@ -148,7 +148,7 @@ mod tests {
|
||||
let _ = catalog.upsert(item_in_memory.clone());
|
||||
let len = catalog.len().unwrap();
|
||||
assert_eq!(len, 1);
|
||||
let result2 = catalog.load_by_class::<Item>();
|
||||
let result2 = catalog.load::<Item>();
|
||||
assert!(result2.is_ok());
|
||||
// 4. Verify the in-memory item is untouched because nothing was loaded from DB.
|
||||
let len = catalog.len().unwrap();
|
||||
@@ -166,7 +166,7 @@ mod tests {
|
||||
std::fs::create_dir_all(invalid_path).unwrap();
|
||||
let mut catalog = Catalog::new(invalid_path);
|
||||
// Attempt to load from the invalid path.
|
||||
let result = catalog.load_by_class::<Item>();
|
||||
let result = catalog.load::<Item>();
|
||||
assert!(result.is_err());
|
||||
// Based on `load_by_id`, the error should be `LoadFromDB`.
|
||||
// This assumes `From<SqliteFailedTo>` is implemented to produce `FailedTo::LoadFromDB`.
|
||||
|
||||
@@ -167,7 +167,7 @@ mod tests {
|
||||
catalog_setup.persist().unwrap();
|
||||
// 2. Manipulation: Load the data and perform mixed operations.
|
||||
let mut catalog_ops = Catalog::new(db_path);
|
||||
catalog_ops.load_by_class::<Item>().unwrap(); // Load all items
|
||||
catalog_ops.load::<Item>().unwrap(); // Load all items
|
||||
// A new item to be inserted.
|
||||
let item_to_add = Item {
|
||||
id: "add-me".to_string(),
|
||||
@@ -197,7 +197,7 @@ mod tests {
|
||||
catalog_ops.persist().unwrap();
|
||||
// 4. Verification: Load into a new catalog and check the final state of the DB.
|
||||
let mut catalog_verify = Catalog::new(db_path);
|
||||
catalog_verify.load_by_class::<Item>().unwrap();
|
||||
catalog_verify.load::<Item>().unwrap();
|
||||
// Check total count
|
||||
assert_eq!(catalog_verify.len().unwrap(), 3);
|
||||
// Verify added item
|
||||
|
||||
@@ -40,7 +40,7 @@ mod tests {
|
||||
assert_eq!(total_items, 1000);
|
||||
catalog.persist().unwrap();
|
||||
let mut new_catalog = Catalog::new(db_path);
|
||||
new_catalog.load_by_class::<Item>().unwrap();
|
||||
new_catalog.load::<Item>().unwrap();
|
||||
let total_items_after_load = new_catalog.with_items(|items| Ok(items.len())).unwrap();
|
||||
assert_eq!(total_items_after_load, 1000);
|
||||
std::fs::remove_file(path).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user