From 04d8684a9287096915928750286ccdf952ab226e Mon Sep 17 00:00:00 2001 From: Michael Vlach Date: Tue, 12 Sep 2023 12:12:31 +0200 Subject: [PATCH] [ci] Prune access modifiers #723 (#728) * first batch * second batch * Update storage.rs * batch 3 * add more types to public api * revise pub(crate) in agdb * Update graph.rs --- agdb/src/collections/indexed_map.rs | 22 ++--- agdb/src/collections/map.rs | 12 +-- agdb/src/collections/multi_map.rs | 12 +-- agdb/src/collections/vec.rs | 4 +- agdb/src/command.rs | 2 +- agdb/src/db.rs | 8 +- agdb/src/db/db_element.rs | 2 +- agdb/src/db/db_f64.rs | 2 +- agdb/src/db/db_id.rs | 4 +- agdb/src/db/db_key.rs | 2 +- agdb/src/db/db_key_value.rs | 8 +- agdb/src/db/db_search_handlers.rs | 20 ++--- agdb/src/db/db_value.rs | 28 +++--- agdb/src/db/db_value_index.rs | 28 +++--- agdb/src/graph.rs | 90 ++++++++----------- agdb/src/graph_search.rs | 24 ++--- agdb/src/graph_search/breadth_first_search.rs | 9 +- .../breadth_first_search_reverse.rs | 13 ++- agdb/src/graph_search/depth_first_search.rs | 6 +- .../depth_first_search_reverse.rs | 6 +- agdb/src/graph_search/path_search.rs | 32 +++---- agdb/src/graph_search/search_impl.rs | 34 ++++--- agdb/src/lib.rs | 7 +- agdb/src/query.rs | 2 +- agdb/src/query/insert_aliases_query.rs | 6 +- agdb/src/query/insert_edges_query.rs | 8 +- agdb/src/query/insert_nodes_query.rs | 6 +- agdb/src/query/insert_values_query.rs | 6 +- agdb/src/query/query_condition.rs | 2 +- agdb/src/query/query_error.rs | 2 +- agdb/src/query/query_ids.rs | 4 +- agdb/src/query/query_values.rs | 5 +- agdb/src/query/remove_aliases_query.rs | 4 +- agdb/src/query/remove_query.rs | 6 +- agdb/src/query/remove_values_query.rs | 6 +- agdb/src/query/search_query.rs | 6 +- agdb/src/query/select_aliases_query.rs | 6 +- agdb/src/query/select_all_aliases_query.rs | 6 +- agdb/src/query/select_key_count_query.rs | 4 +- agdb/src/query/select_keys_query.rs | 4 +- agdb/src/query/select_query.rs | 4 +- agdb/src/query/select_values_query.rs | 4 +- agdb/src/query_builder/insert.rs | 20 ++--- agdb/src/query_builder/insert_aliases.rs | 4 +- agdb/src/query_builder/insert_edge.rs | 4 +- agdb/src/query_builder/insert_nodes.rs | 2 +- agdb/src/query_builder/insert_values.rs | 4 +- agdb/src/query_builder/remove.rs | 16 ++-- agdb/src/query_builder/remove_aliases.rs | 2 +- agdb/src/query_builder/remove_ids.rs | 2 +- agdb/src/query_builder/remove_values.rs | 4 +- agdb/src/query_builder/search.rs | 6 +- agdb/src/query_builder/select.rs | 22 ++--- agdb/src/query_builder/select_aliases.rs | 10 +-- agdb/src/query_builder/select_ids.rs | 2 +- agdb/src/query_builder/select_key_count.rs | 4 +- agdb/src/query_builder/select_keys.rs | 4 +- agdb/src/query_builder/select_values.rs | 4 +- agdb/src/storage.rs | 5 +- agdb/src/storage/file_storage.rs | 2 +- .../src/storage/file_storage_memory_mapped.rs | 2 +- agdb/src/storage/memory_storage.rs | 10 ++- agdb/src/storage/storage_records.rs | 2 +- agdb/src/storage/write_ahead_log.rs | 2 +- agdb/src/test_utilities/collision_value.rs | 6 +- agdb/src/test_utilities/test_file.rs | 9 +- agdb/src/transaction.rs | 2 +- agdb/src/transaction_mut.rs | 2 +- agdb/src/utilities/serialize.rs | 2 +- agdb/tests/db_test.rs | 14 ++- agdb/tests/test_db/mod.rs | 1 + 71 files changed, 324 insertions(+), 311 deletions(-) diff --git a/agdb/src/collections/indexed_map.rs b/agdb/src/collections/indexed_map.rs index b44ee386c..25288645d 100644 --- a/agdb/src/collections/indexed_map.rs +++ b/agdb/src/collections/indexed_map.rs @@ -1,14 +1,14 @@ -use super::map::DbMap; -use super::map::DbMapData; -use super::map::MapData; -use super::map::MapImpl; -use super::map::MapIterator; -use super::vec::VecValue; -use crate::db::db_error::DbError; +use crate::collections::map::DbMap; +use crate::collections::map::DbMapData; +use crate::collections::map::MapData; +use crate::collections::map::MapImpl; +use crate::collections::map::MapIterator; +use crate::collections::vec::VecValue; use crate::storage::Storage; -use crate::storage::StorageData; use crate::storage::StorageIndex; use crate::utilities::stable_hash::StableHash; +use crate::DbError; +use crate::StorageData; use std::marker::PhantomData; pub struct IndexedMapImpl @@ -17,9 +17,9 @@ where DataKT: MapData, DataTK: MapData, { - pub(crate) keys_to_values: MapImpl, - pub(crate) values_to_keys: MapImpl, - pub(crate) storage: PhantomData, + keys_to_values: MapImpl, + values_to_keys: MapImpl, + storage: PhantomData, } impl IndexedMapImpl diff --git a/agdb/src/collections/map.rs b/agdb/src/collections/map.rs index 7fd54e86d..c2742a0bd 100644 --- a/agdb/src/collections/map.rs +++ b/agdb/src/collections/map.rs @@ -1,13 +1,13 @@ -use super::multi_map::MultiMapImpl; -use super::vec::DbVec; +use crate::collections::multi_map::MultiMapImpl; +use crate::collections::vec::DbVec; use crate::collections::vec::VecValue; -use crate::db::db_error::DbError; use crate::storage::Storage; -use crate::storage::StorageData; use crate::storage::StorageIndex; use crate::utilities::serialize::Serialize; use crate::utilities::serialize::SerializeStatic; use crate::utilities::stable_hash::StableHash; +use crate::DbError; +use crate::StorageData; use std::marker::PhantomData; #[derive(Clone, Debug, Default, Eq, PartialEq)] @@ -338,8 +338,8 @@ where D: StorageData, Data: MapData, { - pub(crate) multi_map: MultiMapImpl, - pub(crate) storage: PhantomData, + multi_map: MultiMapImpl, + storage: PhantomData, } impl MapImpl diff --git a/agdb/src/collections/multi_map.rs b/agdb/src/collections/multi_map.rs index 0644f7118..f22d5e422 100644 --- a/agdb/src/collections/multi_map.rs +++ b/agdb/src/collections/multi_map.rs @@ -1,13 +1,13 @@ -use super::map::DbMapData; -use super::map::MapData; -use super::map::MapIterator; -use super::map::MapValueState; +use crate::collections::map::DbMapData; +use crate::collections::map::MapData; +use crate::collections::map::MapIterator; +use crate::collections::map::MapValueState; use crate::collections::vec::VecValue; -use crate::db::db_error::DbError; use crate::storage::Storage; -use crate::storage::StorageData; use crate::storage::StorageIndex; use crate::utilities::stable_hash::StableHash; +use crate::DbError; +use crate::StorageData; use std::marker::PhantomData; pub struct MultiMapImpl diff --git a/agdb/src/collections/vec.rs b/agdb/src/collections/vec.rs index 26f2e1a72..6d3cd6b5d 100644 --- a/agdb/src/collections/vec.rs +++ b/agdb/src/collections/vec.rs @@ -1,9 +1,9 @@ -use crate::db::db_error::DbError; use crate::storage::Storage; -use crate::storage::StorageData; use crate::storage::StorageIndex; use crate::utilities::serialize::Serialize; use crate::utilities::serialize::SerializeStatic; +use crate::DbError; +use crate::StorageData; use std::marker::PhantomData; pub trait VecData diff --git a/agdb/src/command.rs b/agdb/src/command.rs index f565ef532..466a7ba44 100644 --- a/agdb/src/command.rs +++ b/agdb/src/command.rs @@ -2,7 +2,7 @@ use crate::graph::GraphIndex; use crate::DbId; use crate::DbKeyValue; -pub(crate) enum Command { +pub enum Command { InsertAlias { alias: String, id: DbId }, InsertEdge { from: GraphIndex, to: GraphIndex }, InsertNode, diff --git a/agdb/src/db.rs b/agdb/src/db.rs index 87363d939..2f847a033 100644 --- a/agdb/src/db.rs +++ b/agdb/src/db.rs @@ -34,9 +34,7 @@ use crate::storage::file_storage::FileStorage; use crate::storage::file_storage_memory_mapped::FileStorageMemoryMapped; use crate::storage::memory_storage::MemoryStorage; use crate::storage::Storage; -use crate::storage::StorageData; use crate::storage::StorageIndex; -use crate::transaction_mut::TransactionMut; use crate::utilities::serialize::Serialize; use crate::utilities::serialize::SerializeStatic; use crate::DbId; @@ -46,7 +44,9 @@ use crate::DbValue; use crate::QueryError; use crate::QueryResult; use crate::SearchQueryAlgorithm; +use crate::StorageData; use crate::Transaction; +use crate::TransactionMut; #[derive(Default)] struct DbStorageIndex { @@ -724,13 +724,13 @@ impl DbImpl { .ok_or(DbError::from("Data integrity corrupted"))?; for edge in node.edge_iter_from() { - edges.push((edge.index, edge.index_from(), edge.index_to())); + edges.push((edge.index(), edge.index_from(), edge.index_to())); } for edge in node.edge_iter_to() { let from = edge.index_from(); if from != graph_index { - edges.push((edge.index, from, edge.index_to())); + edges.push((edge.index(), from, edge.index_to())); } } diff --git a/agdb/src/db/db_element.rs b/agdb/src/db/db_element.rs index 1e68285f5..a636515c8 100644 --- a/agdb/src/db/db_element.rs +++ b/agdb/src/db/db_element.rs @@ -1,5 +1,5 @@ -use super::db_key_value::DbKeyValue; use crate::DbId; +use crate::DbKeyValue; /// Database element used in `QueryResult` /// that represents a node or an edge. diff --git a/agdb/src/db/db_f64.rs b/agdb/src/db/db_f64.rs index 28f3a8636..6085a006a 100644 --- a/agdb/src/db/db_f64.rs +++ b/agdb/src/db/db_f64.rs @@ -1,6 +1,6 @@ -use super::db_error::DbError; use crate::utilities::serialize::Serialize; use crate::utilities::stable_hash::StableHash; +use crate::DbError; use std::cmp::Ordering; use std::hash::Hash; use std::hash::Hasher; diff --git a/agdb/src/db/db_id.rs b/agdb/src/db/db_id.rs index 944b96295..cc171a18e 100644 --- a/agdb/src/db/db_id.rs +++ b/agdb/src/db/db_id.rs @@ -1,10 +1,10 @@ -use super::db_error::DbError; use crate::collections::vec::VecValue; use crate::storage::Storage; -use crate::storage::StorageData; use crate::utilities::serialize::Serialize; use crate::utilities::serialize::SerializeStatic; use crate::utilities::stable_hash::StableHash; +use crate::DbError; +use crate::StorageData; /// Database id is a wrapper around `i64`. /// The id is an identifier of a database element diff --git a/agdb/src/db/db_key.rs b/agdb/src/db/db_key.rs index 4b3fa2772..2e5c0a12b 100644 --- a/agdb/src/db/db_key.rs +++ b/agdb/src/db/db_key.rs @@ -1,4 +1,4 @@ -use super::db_value::DbValue; +use crate::DbValue; /// Alias to `DbValue` pub type DbKey = DbValue; diff --git a/agdb/src/db/db_key_value.rs b/agdb/src/db/db_key_value.rs index fa47fa2f8..eaf2a8349 100644 --- a/agdb/src/db/db_key_value.rs +++ b/agdb/src/db/db_key_value.rs @@ -1,13 +1,13 @@ -use super::db_error::DbError; -use super::db_value_index::DbValueIndex; use crate::collections::vec::VecValue; +use crate::db::db_value_index::DbValueIndex; use crate::storage::Storage; -use crate::storage::StorageData; use crate::storage::StorageIndex; use crate::utilities::serialize::Serialize; use crate::utilities::serialize::SerializeStatic; +use crate::DbError; use crate::DbKey; use crate::DbValue; +use crate::StorageData; /// Database key-value pair (aka property) attached to /// database elements. It can be constructed from a @@ -38,7 +38,7 @@ impl VecValue for DbKeyValue { fn store(&self, storage: &mut Storage) -> Result, DbError> { let key_index = self.key.store_db_value(storage)?; let value_index = self.value.store_db_value(storage)?; - Ok([key_index.value, value_index.value].concat()) + Ok([key_index.data(), value_index.data()].concat()) } fn load(storage: &Storage, bytes: &[u8]) -> Result { diff --git a/agdb/src/db/db_search_handlers.rs b/agdb/src/db/db_search_handlers.rs index 078759232..eb4bf919b 100644 --- a/agdb/src/db/db_search_handlers.rs +++ b/agdb/src/db/db_search_handlers.rs @@ -1,32 +1,32 @@ -use super::db_error::DbError; use crate::graph::GraphIndex; -use crate::graph_search::PathSearchHandler; +use crate::graph_search::path_search::PathSearchHandler; use crate::graph_search::SearchControl; use crate::graph_search::SearchHandler; -use crate::query::query_condition::QueryCondition; -use crate::storage::StorageData; +use crate::DbError; use crate::DbImpl; +use crate::QueryCondition; +use crate::StorageData; -pub(crate) struct DefaultHandler<'a, Store: StorageData> { +pub struct DefaultHandler<'a, Store: StorageData> { db: &'a DbImpl, conditions: &'a Vec, } -pub(crate) struct LimitHandler<'a, Store: StorageData> { +pub struct LimitHandler<'a, Store: StorageData> { limit: u64, counter: u64, db: &'a DbImpl, conditions: &'a Vec, } -pub(crate) struct OffsetHandler<'a, Store: StorageData> { +pub struct OffsetHandler<'a, Store: StorageData> { offset: u64, counter: u64, db: &'a DbImpl, conditions: &'a Vec, } -pub(crate) struct LimitOffsetHandler<'a, Store: StorageData> { +pub struct LimitOffsetHandler<'a, Store: StorageData> { limit: u64, offset: u64, counter: u64, @@ -34,13 +34,13 @@ pub(crate) struct LimitOffsetHandler<'a, Store: StorageData> { conditions: &'a Vec, } -pub(crate) struct PathHandler<'a, Store: StorageData> { +pub struct PathHandler<'a, Store: StorageData> { db: &'a DbImpl, conditions: &'a Vec, } impl<'a, Store: StorageData> DefaultHandler<'a, Store> { - pub(crate) fn new(db: &'a DbImpl, conditions: &'a Vec) -> Self { + pub fn new(db: &'a DbImpl, conditions: &'a Vec) -> Self { Self { db, conditions } } } diff --git a/agdb/src/db/db_value.rs b/agdb/src/db/db_value.rs index afb6efafd..743929cb5 100644 --- a/agdb/src/db/db_value.rs +++ b/agdb/src/db/db_value.rs @@ -1,10 +1,10 @@ -use super::db_error::DbError; -use super::db_f64::DbF64; -use super::db_value_index::DbValueIndex; +use crate::db::db_f64::DbF64; +use crate::db::db_value_index::DbValueIndex; use crate::storage::Storage; -use crate::storage::StorageData; use crate::storage::StorageIndex; use crate::utilities::stable_hash::StableHash; +use crate::DbError; +use crate::StorageData; use std::fmt::Display; use std::fmt::Formatter; use std::fmt::Result as DisplayResult; @@ -49,15 +49,15 @@ pub enum DbValue { VecString(Vec), } -pub(crate) const BYTES_META_VALUE: u8 = 1_u8; -pub(crate) const I64_META_VALUE: u8 = 2_u8; -pub(crate) const U64_META_VALUE: u8 = 3_u8; -pub(crate) const F64_META_VALUE: u8 = 4_u8; -pub(crate) const STRING_META_VALUE: u8 = 5_u8; -pub(crate) const VEC_I64_META_VALUE: u8 = 6_u8; -pub(crate) const VEC_U64_META_VALUE: u8 = 7_u8; -pub(crate) const VEC_F64_META_VALUE: u8 = 8_u8; -pub(crate) const VEC_STRING_META_VALUE: u8 = 9_u8; +const BYTES_META_VALUE: u8 = 1_u8; +const I64_META_VALUE: u8 = 2_u8; +const U64_META_VALUE: u8 = 3_u8; +const F64_META_VALUE: u8 = 4_u8; +const STRING_META_VALUE: u8 = 5_u8; +const VEC_I64_META_VALUE: u8 = 6_u8; +const VEC_U64_META_VALUE: u8 = 7_u8; +const VEC_F64_META_VALUE: u8 = 8_u8; +const VEC_STRING_META_VALUE: u8 = 9_u8; impl DbValue { /// Returns `&Vec` or an error if the value is @@ -779,7 +779,7 @@ mod tests { #[should_panic] fn bad_deserialization() { let test_file = TestFile::new(); - let storage = Storage::::new(&test_file.filename).unwrap(); + let storage = Storage::::new(test_file.file_name()).unwrap(); let _ = DbValue::load_db_value(DbValueIndex::new(), &storage); } diff --git a/agdb/src/db/db_value_index.rs b/agdb/src/db/db_value_index.rs index 674b6f253..c32f75192 100644 --- a/agdb/src/db/db_value_index.rs +++ b/agdb/src/db/db_value_index.rs @@ -1,42 +1,46 @@ -use super::db_error::DbError; use crate::utilities::serialize::Serialize; use crate::utilities::serialize::SerializeStatic; +use crate::DbError; #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] -pub(crate) struct DbValueIndex { - pub(crate) value: [u8; 16], +pub struct DbValueIndex { + value: [u8; 16], } impl DbValueIndex { - pub(crate) fn new() -> Self { + pub fn new() -> Self { Self { value: [0_u8; 16] } } - pub(crate) fn get_type(&self) -> u8 { + pub fn data(&self) -> [u8; 16] { + self.value + } + + pub fn get_type(&self) -> u8 { self.value[15] >> 4 } - pub(crate) fn index(&self) -> u64 { + pub fn index(&self) -> u64 { let mut bytes = [0_u8; 8]; bytes.copy_from_slice(&self.value[0..std::mem::size_of::()]); u64::from_le_bytes(bytes) } - pub(crate) fn is_value(&self) -> bool { + pub fn is_value(&self) -> bool { self.size() != 0 || self.index() == 0 } - pub(crate) fn set_type(&mut self, value: u8) { + pub fn set_type(&mut self, value: u8) { let v = (value << 4) | self.size(); self.value[15] = v; } - pub(crate) fn set_index(&mut self, index: u64) { + pub fn set_index(&mut self, index: u64) { self.set_size(0); self.value[0..std::mem::size_of::()].copy_from_slice(&index.to_le_bytes()); } - pub(crate) fn set_value(&mut self, value: &[u8]) -> bool { + pub fn set_value(&mut self, value: &[u8]) -> bool { if value.len() > 15 { return false; } @@ -47,11 +51,11 @@ impl DbValueIndex { true } - pub(crate) fn size(&self) -> u8 { + pub fn size(&self) -> u8 { self.value[15] & 0b00001111 } - pub(crate) fn value(&self) -> &[u8] { + pub fn value(&self) -> &[u8] { let pos = self.size(); &self.value[0..(pos as usize)] } diff --git a/agdb/src/graph.rs b/agdb/src/graph.rs index f991c0f34..c61b6482d 100644 --- a/agdb/src/graph.rs +++ b/agdb/src/graph.rs @@ -1,11 +1,11 @@ use crate::collections::vec::DbVec; -use crate::db::db_error::DbError; use crate::storage::Storage; -use crate::storage::StorageData; use crate::storage::StorageIndex; use crate::utilities::serialize::Serialize; use crate::utilities::serialize::SerializeStatic; use crate::utilities::stable_hash::StableHash; +use crate::DbError; +use crate::StorageData; use std::marker::PhantomData; #[derive(Clone, Copy, Debug, Default, Eq, Ord, Hash, PartialEq, PartialOrd)] @@ -24,7 +24,7 @@ impl GraphIndex { self.0 != 0 } - pub(crate) fn as_u64(&self) -> u64 { + pub fn as_u64(&self) -> u64 { if self.is_edge() { (-self.0) as u64 } else { @@ -84,11 +84,11 @@ pub trait GraphData { fn transaction(&mut self, storage: &mut Storage) -> u64; } -pub(crate) struct GraphDataStorageIndexes { - pub(crate) from: StorageIndex, - pub(crate) to: StorageIndex, - pub(crate) from_meta: StorageIndex, - pub(crate) to_meta: StorageIndex, +pub struct GraphDataStorageIndexes { + from: StorageIndex, + to: StorageIndex, + from_meta: StorageIndex, + to_meta: StorageIndex, } impl Serialize for GraphDataStorageIndexes { @@ -130,12 +130,12 @@ pub struct GraphDataStorage where D: StorageData, { - pub(crate) storage: PhantomData, - pub(crate) storage_index: StorageIndex, - pub(crate) from: DbVec, - pub(crate) to: DbVec, - pub(crate) from_meta: DbVec, - pub(crate) to_meta: DbVec, + storage: PhantomData, + storage_index: StorageIndex, + from: DbVec, + to: DbVec, + from_meta: DbVec, + to_meta: DbVec, } impl GraphDataStorage @@ -295,9 +295,9 @@ where Data: GraphData, D: StorageData, { - pub(crate) graph: &'a GraphImpl, - pub(crate) index: GraphIndex, - pub(crate) storage: &'a Storage, + graph: &'a GraphImpl, + index: GraphIndex, + storage: &'a Storage, } impl<'a, D, Data> GraphNode<'a, D, Data> @@ -354,9 +354,9 @@ where Data: GraphData, D: StorageData, { - pub(crate) graph: &'a GraphImpl, - pub(crate) index: GraphIndex, - pub(crate) storage: &'a Storage, + graph: &'a GraphImpl, + index: GraphIndex, + storage: &'a Storage, } impl<'a, D, Data> Iterator for GraphNodeIterator<'a, D, Data> @@ -389,9 +389,9 @@ where Data: GraphData, D: StorageData, { - pub(crate) graph: &'a GraphImpl, - pub(crate) index: GraphIndex, - pub(crate) storage: &'a Storage, + graph: &'a GraphImpl, + index: GraphIndex, + storage: &'a Storage, } impl<'a, D, Data> GraphEdge<'a, D, Data> @@ -417,9 +417,9 @@ where Data: GraphData, D: StorageData, { - pub(crate) graph: &'a GraphImpl, - pub(crate) index: GraphIndex, - pub(crate) storage: &'a Storage, + graph: &'a GraphImpl, + index: GraphIndex, + storage: &'a Storage, } impl<'a, D, Data> Iterator for GraphEdgeIterator<'a, D, Data> @@ -454,9 +454,9 @@ where Data: GraphData, D: StorageData, { - pub(crate) graph: &'a GraphImpl, - pub(crate) index: GraphIndex, - pub(crate) storage: &'a Storage, + graph: &'a GraphImpl, + index: GraphIndex, + storage: &'a Storage, } impl<'a, D, Data> Iterator for GraphEdgeReverseIterator<'a, D, Data> @@ -491,8 +491,8 @@ where Data: GraphData, D: StorageData, { - pub(crate) data: Data, - pub(crate) storage: PhantomData, + data: Data, + storage: PhantomData, } impl GraphImpl @@ -626,11 +626,11 @@ where Ok(GraphIndex::from(-self.data.to(storage, index)?)) } - pub(crate) fn edge_from(&self, storage: &Storage, index: GraphIndex) -> GraphIndex { + fn edge_from(&self, storage: &Storage, index: GraphIndex) -> GraphIndex { GraphIndex::from(-self.data.from(storage, index).unwrap_or_default()) } - pub(crate) fn edge_to(&self, storage: &Storage, index: GraphIndex) -> GraphIndex { + fn edge_to(&self, storage: &Storage, index: GraphIndex) -> GraphIndex { GraphIndex::from(-self.data.to(storage, index).unwrap_or_default()) } @@ -682,7 +682,7 @@ where Ok(0 <= self.data.from(storage, index)?) } - pub(crate) fn next_edge_from( + fn next_edge_from( &self, storage: &Storage, index: GraphIndex, @@ -690,31 +690,19 @@ where Ok(GraphIndex::from(-self.data.from_meta(storage, index)?)) } - pub(crate) fn next_edge_to( - &self, - storage: &Storage, - index: GraphIndex, - ) -> Result { + fn next_edge_to(&self, storage: &Storage, index: GraphIndex) -> Result { Ok(GraphIndex::from(-self.data.to_meta(storage, index)?)) } - pub(crate) fn edge_count_from( - &self, - storage: &Storage, - index: GraphIndex, - ) -> Result { + fn edge_count_from(&self, storage: &Storage, index: GraphIndex) -> Result { self.data.from_meta(storage, index) } - pub(crate) fn edge_count_to( - &self, - storage: &Storage, - index: GraphIndex, - ) -> Result { + fn edge_count_to(&self, storage: &Storage, index: GraphIndex) -> Result { self.data.to_meta(storage, index) } - pub(crate) fn next_node( + fn next_node( &self, storage: &Storage, index: GraphIndex, @@ -906,8 +894,8 @@ mod tests { use std::hash::Hash; use std::hash::Hasher; - #[test] #[allow(clippy::clone_on_copy)] + #[test] fn derived_from_clone() { let index = GraphIndex(1); let other = index.clone(); diff --git a/agdb/src/graph_search.rs b/agdb/src/graph_search.rs index 8f57d7eed..e2a149c6c 100644 --- a/agdb/src/graph_search.rs +++ b/agdb/src/graph_search.rs @@ -1,24 +1,24 @@ +pub mod path_search; + mod breadth_first_search; mod breadth_first_search_reverse; mod depth_first_search; mod depth_first_search_reverse; -mod path_search; mod search_impl; -pub use self::path_search::PathSearchHandler; - use self::breadth_first_search::BreadthFirstSearch; use self::breadth_first_search_reverse::BreadthFirstSearchReverse; use self::depth_first_search::DepthFirstSearch; use self::depth_first_search_reverse::DepthFirstSearchReverse; use self::path_search::PathSearch; +use self::path_search::PathSearchHandler; use self::search_impl::SearchImpl; -use crate::db::db_error::DbError; use crate::graph::GraphData; use crate::graph::GraphImpl; use crate::graph::GraphIndex; use crate::storage::Storage; -use crate::storage::StorageData; +use crate::DbError; +use crate::StorageData; #[derive(Debug, Copy, Clone, Eq, PartialEq)] pub enum SearchControl { @@ -36,8 +36,8 @@ where Data: GraphData, D: StorageData, { - pub(crate) graph: &'a GraphImpl, - pub(crate) storage: &'a Storage, + graph: &'a GraphImpl, + storage: &'a Storage, } impl<'a, D, Data> GraphSearch<'a, D, Data> @@ -138,7 +138,7 @@ where } impl SearchControl { - pub(crate) fn and(self, other: SearchControl) -> SearchControl { + pub fn and(self, other: SearchControl) -> SearchControl { use SearchControl::Continue; use SearchControl::Finish; use SearchControl::Stop; @@ -156,7 +156,7 @@ impl SearchControl { } } - pub(crate) fn or(self, other: SearchControl) -> SearchControl { + pub fn or(self, other: SearchControl) -> SearchControl { use SearchControl::Continue; use SearchControl::Finish; use SearchControl::Stop; @@ -174,7 +174,7 @@ impl SearchControl { } } - pub(crate) fn flip(&mut self) { + pub fn flip(&mut self) { match self { SearchControl::Continue(v) | SearchControl::Finish(v) | SearchControl::Stop(v) => { *v = !*v; @@ -182,13 +182,13 @@ impl SearchControl { }; } - pub(crate) fn is_true(&self) -> bool { + pub fn is_true(&self) -> bool { match self { SearchControl::Continue(v) | SearchControl::Finish(v) | SearchControl::Stop(v) => *v, } } - pub(crate) fn set_value(&mut self, value: bool) { + pub fn set_value(&mut self, value: bool) { match self { SearchControl::Continue(v) | SearchControl::Finish(v) | SearchControl::Stop(v) => { *v = value; diff --git a/agdb/src/graph_search/breadth_first_search.rs b/agdb/src/graph_search/breadth_first_search.rs index ef5bc88bd..46a6e4472 100644 --- a/agdb/src/graph_search/breadth_first_search.rs +++ b/agdb/src/graph_search/breadth_first_search.rs @@ -4,18 +4,17 @@ use crate::graph::GraphData; use crate::graph::GraphImpl; use crate::graph::GraphIndex; use crate::storage::Storage; -use crate::storage::StorageData; -use std::mem::swap; +use crate::StorageData; use std::vec::IntoIter; -pub(crate) struct BreadthFirstSearch { +pub struct BreadthFirstSearch { stack_iterator: IntoIter, } impl BreadthFirstSearch { fn take_stack(stack: &mut Vec) -> Vec { let mut res = Vec::::new(); - swap(&mut res, stack); + std::mem::swap(&mut res, stack); res } @@ -62,11 +61,11 @@ mod tests { use super::super::SearchControl; use super::super::SearchHandler; use super::*; - use crate::db::db_error::DbError; use crate::graph::DbGraph; use crate::graph_search::GraphSearch; use crate::storage::file_storage::FileStorage; use crate::test_utilities::test_file::TestFile; + use crate::DbError; struct Handler { pub processor: fn(GraphIndex, u64) -> SearchControl, diff --git a/agdb/src/graph_search/breadth_first_search_reverse.rs b/agdb/src/graph_search/breadth_first_search_reverse.rs index f25842bc7..55bc92b64 100644 --- a/agdb/src/graph_search/breadth_first_search_reverse.rs +++ b/agdb/src/graph_search/breadth_first_search_reverse.rs @@ -1,21 +1,20 @@ -use super::search_impl::SearchIndex; -use super::search_impl::SearchIterator; use crate::graph::GraphData; use crate::graph::GraphImpl; use crate::graph::GraphIndex; +use crate::graph_search::search_impl::SearchIndex; +use crate::graph_search::search_impl::SearchIterator; use crate::storage::Storage; -use crate::storage::StorageData; -use std::mem::swap; +use crate::StorageData; use std::vec::IntoIter; -pub(crate) struct BreadthFirstSearchReverse { +pub struct BreadthFirstSearchReverse { stack_iterator: IntoIter, } impl BreadthFirstSearchReverse { fn take_stack(stack: &mut Vec) -> Vec { let mut res = Vec::::new(); - swap(&mut res, stack); + std::mem::swap(&mut res, stack); res } @@ -62,11 +61,11 @@ mod tests { use super::super::SearchControl; use super::super::SearchHandler; use super::*; - use crate::db::db_error::DbError; use crate::graph::DbGraph; use crate::graph_search::GraphSearch; use crate::storage::file_storage::FileStorage; use crate::test_utilities::test_file::TestFile; + use crate::DbError; struct Handler { pub processor: fn(GraphIndex, u64) -> SearchControl, diff --git a/agdb/src/graph_search/depth_first_search.rs b/agdb/src/graph_search/depth_first_search.rs index de9f3d4bc..5ebe7ef16 100644 --- a/agdb/src/graph_search/depth_first_search.rs +++ b/agdb/src/graph_search/depth_first_search.rs @@ -4,9 +4,9 @@ use crate::graph::GraphData; use crate::graph::GraphImpl; use crate::graph::GraphIndex; use crate::storage::Storage; -use crate::storage::StorageData; +use crate::StorageData; -pub(crate) struct DepthFirstSearch { +pub struct DepthFirstSearch { index: Option, } @@ -52,11 +52,11 @@ mod tests { use super::super::SearchControl; use super::super::SearchHandler; use super::*; - use crate::db::db_error::DbError; use crate::graph::DbGraph; use crate::graph_search::GraphSearch; use crate::storage::file_storage::FileStorage; use crate::test_utilities::test_file::TestFile; + use crate::DbError; struct Handler { pub processor: fn(GraphIndex, u64) -> SearchControl, diff --git a/agdb/src/graph_search/depth_first_search_reverse.rs b/agdb/src/graph_search/depth_first_search_reverse.rs index 4e3763bc4..ea74883a1 100644 --- a/agdb/src/graph_search/depth_first_search_reverse.rs +++ b/agdb/src/graph_search/depth_first_search_reverse.rs @@ -4,9 +4,9 @@ use crate::graph::GraphData; use crate::graph::GraphImpl; use crate::graph::GraphIndex; use crate::storage::Storage; -use crate::storage::StorageData; +use crate::StorageData; -pub(crate) struct DepthFirstSearchReverse { +pub struct DepthFirstSearchReverse { index: Option, } @@ -52,11 +52,11 @@ mod tests { use super::super::SearchControl; use super::super::SearchHandler; use super::*; - use crate::db::db_error::DbError; use crate::graph::DbGraph; use crate::graph_search::GraphSearch; use crate::storage::file_storage::FileStorage; use crate::test_utilities::test_file::TestFile; + use crate::DbError; struct Handler { pub processor: fn(GraphIndex, u64) -> SearchControl, diff --git a/agdb/src/graph_search/path_search.rs b/agdb/src/graph_search/path_search.rs index 2c58b6843..c2db19857 100644 --- a/agdb/src/graph_search/path_search.rs +++ b/agdb/src/graph_search/path_search.rs @@ -1,10 +1,10 @@ use crate::collections::bit_set::BitSet; -use crate::db::db_error::DbError; use crate::graph::GraphData; use crate::graph::GraphImpl; use crate::graph::GraphIndex; use crate::storage::Storage; -use crate::storage::StorageData; +use crate::DbError; +use crate::StorageData; use std::cmp::Ordering; pub trait PathSearchHandler { @@ -12,25 +12,25 @@ pub trait PathSearchHandler { } #[derive(Clone)] -pub(crate) struct Path { - pub(crate) elements: Vec<(GraphIndex, bool)>, - pub(crate) cost: u64, +struct Path { + elements: Vec<(GraphIndex, bool)>, + cost: u64, } -pub(crate) struct PathSearch<'a, D, Data, Handler> +pub struct PathSearch<'a, D, Data, Handler> where Data: GraphData, D: StorageData, Handler: PathSearchHandler, { - pub(crate) current_path: Path, - pub(crate) destination: GraphIndex, - pub(crate) graph: &'a GraphImpl, - pub(crate) storage: &'a Storage, - pub(crate) handler: Handler, - pub(crate) paths: Vec, - pub(crate) result: Vec<(GraphIndex, bool)>, - pub(crate) visited: BitSet, + current_path: Path, + destination: GraphIndex, + graph: &'a GraphImpl, + storage: &'a Storage, + handler: Handler, + paths: Vec, + result: Vec<(GraphIndex, bool)>, + visited: BitSet, } impl<'a, D, Data, Handler> PathSearch<'a, D, Data, Handler> @@ -39,7 +39,7 @@ where D: StorageData, Handler: PathSearchHandler, { - pub(crate) fn new( + pub fn new( graph: &'a GraphImpl, storage: &'a Storage, from: GraphIndex, @@ -66,7 +66,7 @@ where } } - pub(crate) fn search(&mut self) -> Result, DbError> { + pub fn search(&mut self) -> Result, DbError> { while !self.is_finished() { self.sort_paths(); self.process_last_path()?; diff --git a/agdb/src/graph_search/search_impl.rs b/agdb/src/graph_search/search_impl.rs index 385c3e698..71becce46 100644 --- a/agdb/src/graph_search/search_impl.rs +++ b/agdb/src/graph_search/search_impl.rs @@ -1,22 +1,22 @@ use super::SearchControl; use super::SearchHandler; use crate::collections::bit_set::BitSet; -use crate::db::db_error::DbError; use crate::graph::GraphData; use crate::graph::GraphImpl; use crate::graph::GraphIndex; use crate::storage::Storage; -use crate::storage::StorageData; +use crate::DbError; +use crate::StorageData; use std::marker::PhantomData; use std::mem::swap; #[derive(Clone, Copy)] -pub(crate) struct SearchIndex { - pub(crate) index: GraphIndex, - pub(crate) distance: u64, +pub struct SearchIndex { + index: GraphIndex, + distance: u64, } -pub(crate) trait SearchIterator { +pub trait SearchIterator { fn expand_edge>( index: GraphIndex, graph: &GraphImpl, @@ -31,18 +31,18 @@ pub(crate) trait SearchIterator { fn next(&mut self) -> Option; } -pub(crate) struct SearchImpl<'a, D, Data, SearchIt> +pub struct SearchImpl<'a, D, Data, SearchIt> where Data: GraphData, D: StorageData, SearchIt: SearchIterator, { - pub(crate) algorithm: PhantomData, - pub(crate) graph: &'a GraphImpl, - pub(crate) storage: &'a Storage, - pub(crate) result: Vec, - pub(crate) stack: Vec, - pub(crate) visited: BitSet, + algorithm: PhantomData, + graph: &'a GraphImpl, + storage: &'a Storage, + result: Vec, + stack: Vec, + visited: BitSet, } impl<'a, D, Data, SearchIt> SearchImpl<'a, D, Data, SearchIt> @@ -51,11 +51,7 @@ where D: StorageData, SearchIt: SearchIterator, { - pub(crate) fn new( - graph: &'a GraphImpl, - storage: &'a Storage, - index: GraphIndex, - ) -> Self { + pub fn new(graph: &'a GraphImpl, storage: &'a Storage, index: GraphIndex) -> Self { Self { algorithm: PhantomData, graph, @@ -66,7 +62,7 @@ where } } - pub(crate) fn search( + pub fn search( &mut self, mut handler: Handler, ) -> Result, DbError> { diff --git a/agdb/src/lib.rs b/agdb/src/lib.rs index 22e5c7821..f7aabddc6 100644 --- a/agdb/src/lib.rs +++ b/agdb/src/lib.rs @@ -59,6 +59,9 @@ pub use query::insert_values_query::InsertValuesQuery; pub use query::query_condition::Comparison; pub use query::query_condition::CountComparison; pub use query::query_condition::QueryCondition; +pub use query::query_condition::QueryConditionData; +pub use query::query_condition::QueryConditionLogic; +pub use query::query_condition::QueryConditionModifier; pub use query::query_error::QueryError; pub use query::query_id::QueryId; pub use query::query_ids::QueryIds; @@ -69,7 +72,8 @@ pub use query::remove_query::RemoveQuery; pub use query::remove_values_query::RemoveValuesQuery; pub use query::search_query::SearchQuery; pub use query::search_query::SearchQueryAlgorithm; -pub use query::select_all_aliases_query::SelectAllAliases; +pub use query::select_aliases_query::SelectAliasesQuery; +pub use query::select_all_aliases_query::SelectAllAliasesQuery; pub use query::select_key_count_query::SelectKeyCountQuery; pub use query::select_keys_query::SelectKeysQuery; pub use query::select_query::SelectQuery; @@ -77,5 +81,6 @@ pub use query::select_values_query::SelectValuesQuery; pub use query::Query; pub use query::QueryMut; pub use query_builder::QueryBuilder; +pub use storage::StorageData; pub use transaction::Transaction; pub use transaction_mut::TransactionMut; diff --git a/agdb/src/query.rs b/agdb/src/query.rs index f994e67d1..8b6873503 100644 --- a/agdb/src/query.rs +++ b/agdb/src/query.rs @@ -20,10 +20,10 @@ pub mod select_keys_query; pub mod select_query; pub mod select_values_query; -use crate::storage::StorageData; use crate::DbImpl; use crate::QueryError; use crate::QueryResult; +use crate::StorageData; /// Trait for immutable `agdb` database queries. This /// trait is unlikely to be implementable for user types. diff --git a/agdb/src/query/insert_aliases_query.rs b/agdb/src/query/insert_aliases_query.rs index ab8c998da..5dafe7284 100644 --- a/agdb/src/query/insert_aliases_query.rs +++ b/agdb/src/query/insert_aliases_query.rs @@ -1,9 +1,9 @@ -use super::query_ids::QueryIds; -use super::QueryMut; -use crate::storage::StorageData; use crate::DbImpl; use crate::QueryError; +use crate::QueryIds; +use crate::QueryMut; use crate::QueryResult; +use crate::StorageData; /// Query to insert or update aliases of existing nodes. /// All `ids` must exist. None of the `aliases` can be empty. diff --git a/agdb/src/query/insert_edges_query.rs b/agdb/src/query/insert_edges_query.rs index 9ef8251a3..2010ce41b 100644 --- a/agdb/src/query/insert_edges_query.rs +++ b/agdb/src/query/insert_edges_query.rs @@ -1,13 +1,13 @@ -use super::query_ids::QueryIds; -use super::query_values::QueryValues; -use super::QueryMut; -use crate::storage::StorageData; +use crate::query::query_values::QueryValues; use crate::DbElement; use crate::DbId; use crate::DbImpl; use crate::DbKeyValue; use crate::QueryError; +use crate::QueryIds; +use crate::QueryMut; use crate::QueryResult; +use crate::StorageData; /// Query to inserts edges to the database. The `from` /// and `to` ids must exist in the database. There must be diff --git a/agdb/src/query/insert_nodes_query.rs b/agdb/src/query/insert_nodes_query.rs index 892613710..7dfbf806e 100644 --- a/agdb/src/query/insert_nodes_query.rs +++ b/agdb/src/query/insert_nodes_query.rs @@ -1,10 +1,10 @@ -use super::query_values::QueryValues; -use super::QueryMut; -use crate::storage::StorageData; +use crate::query::query_values::QueryValues; use crate::DbElement; use crate::DbImpl; use crate::QueryError; +use crate::QueryMut; use crate::QueryResult; +use crate::StorageData; /// Query to insert nodes to the database. Only one of /// `count`, `values` or `aliases` need to be given as the diff --git a/agdb/src/query/insert_values_query.rs b/agdb/src/query/insert_values_query.rs index 482016f28..6f47548be 100644 --- a/agdb/src/query/insert_values_query.rs +++ b/agdb/src/query/insert_values_query.rs @@ -1,10 +1,10 @@ -use super::query_ids::QueryIds; -use super::query_values::QueryValues; -use crate::storage::StorageData; +use crate::query::query_values::QueryValues; use crate::DbImpl; use crate::QueryError; +use crate::QueryIds; use crate::QueryMut; use crate::QueryResult; +use crate::StorageData; /// Query to insert or update key-value pairs (properties) /// to existing elements in the database. All `ids` must exist diff --git a/agdb/src/query/query_condition.rs b/agdb/src/query/query_condition.rs index 653a0d4da..fb13b7932 100644 --- a/agdb/src/query/query_condition.rs +++ b/agdb/src/query/query_condition.rs @@ -1,7 +1,7 @@ -use super::query_id::QueryId; use crate::graph_search::SearchControl; use crate::DbKey; use crate::DbValue; +use crate::QueryId; /// Logical operator for query conditions #[derive(Clone, Copy, Debug, PartialEq)] diff --git a/agdb/src/query/query_error.rs b/agdb/src/query/query_error.rs index 8c258c1ea..12438a520 100644 --- a/agdb/src/query/query_error.rs +++ b/agdb/src/query/query_error.rs @@ -1,4 +1,4 @@ -use crate::db::db_error::DbError; +use crate::DbError; use std::error::Error; use std::fmt::Display; use std::fmt::Formatter; diff --git a/agdb/src/query/query_ids.rs b/agdb/src/query/query_ids.rs index 137e2d6b8..992011cc0 100644 --- a/agdb/src/query/query_ids.rs +++ b/agdb/src/query/query_ids.rs @@ -1,7 +1,7 @@ -use super::query_id::QueryId; -use super::search_query::SearchQuery; use crate::DbId; +use crate::QueryId; use crate::QueryResult; +use crate::SearchQuery; /// List of database ids used in queries. It /// can either represent a list of `QueryId`s diff --git a/agdb/src/query/query_values.rs b/agdb/src/query/query_values.rs index 2d9c82584..1575645d2 100644 --- a/agdb/src/query/query_values.rs +++ b/agdb/src/query/query_values.rs @@ -1,5 +1,6 @@ -use crate::db::db_key_value::DbKeyValue; -use crate::{DbKey, DbUserValue}; +use crate::DbKey; +use crate::DbKeyValue; +use crate::DbUserValue; /// Helper type distinguishing uniform (`Single`) values /// and multiple (`Multi`) values in database queries. diff --git a/agdb/src/query/remove_aliases_query.rs b/agdb/src/query/remove_aliases_query.rs index bb37e461e..1539f3c08 100644 --- a/agdb/src/query/remove_aliases_query.rs +++ b/agdb/src/query/remove_aliases_query.rs @@ -1,8 +1,8 @@ -use super::QueryMut; -use crate::storage::StorageData; use crate::DbImpl; use crate::QueryError; +use crate::QueryMut; use crate::QueryResult; +use crate::StorageData; /// Query to remove aliases from the database. It /// is not an error if an alias to be removed already diff --git a/agdb/src/query/remove_query.rs b/agdb/src/query/remove_query.rs index 521452b64..0fb531e98 100644 --- a/agdb/src/query/remove_query.rs +++ b/agdb/src/query/remove_query.rs @@ -1,9 +1,9 @@ -use super::query_ids::QueryIds; -use super::QueryMut; -use crate::storage::StorageData; use crate::DbImpl; use crate::QueryError; +use crate::QueryIds; +use crate::QueryMut; use crate::QueryResult; +use crate::StorageData; /// Query to remove database elements (nodes & edges). It /// is not an error if any of the `ids` do not already exist. diff --git a/agdb/src/query/remove_values_query.rs b/agdb/src/query/remove_values_query.rs index 23d4e20ea..75fe3470e 100644 --- a/agdb/src/query/remove_values_query.rs +++ b/agdb/src/query/remove_values_query.rs @@ -1,10 +1,10 @@ -use super::query_ids::QueryIds; -use super::select_values_query::SelectValuesQuery; -use crate::storage::StorageData; use crate::DbImpl; use crate::QueryError; +use crate::QueryIds; use crate::QueryMut; use crate::QueryResult; +use crate::SelectValuesQuery; +use crate::StorageData; /// Query to remove properties from existing elements /// in the database. All of the specified `ids` must diff --git a/agdb/src/query/search_query.rs b/agdb/src/query/search_query.rs index 5eb653f69..3a5990d6a 100644 --- a/agdb/src/query/search_query.rs +++ b/agdb/src/query/search_query.rs @@ -1,14 +1,14 @@ -use super::query_condition::QueryCondition; -use super::query_id::QueryId; use crate::db::db_key::DbKeyOrder; -use crate::storage::StorageData; use crate::DbElement; use crate::DbId; use crate::DbImpl; use crate::DbKey; use crate::Query; +use crate::QueryCondition; use crate::QueryError; +use crate::QueryId; use crate::QueryResult; +use crate::StorageData; use std::cmp::Ordering; /// Search algorithm to be used diff --git a/agdb/src/query/select_aliases_query.rs b/agdb/src/query/select_aliases_query.rs index 8bb57b08f..5ca33cb29 100644 --- a/agdb/src/query/select_aliases_query.rs +++ b/agdb/src/query/select_aliases_query.rs @@ -1,11 +1,11 @@ -use super::query_id::QueryId; -use super::query_ids::QueryIds; -use crate::storage::StorageData; use crate::DbElement; use crate::DbImpl; use crate::Query; use crate::QueryError; +use crate::QueryId; +use crate::QueryIds; use crate::QueryResult; +use crate::StorageData; /// Query to select aliases of given ids. All of the ids /// must exist in the database and have an alias. diff --git a/agdb/src/query/select_all_aliases_query.rs b/agdb/src/query/select_all_aliases_query.rs index d765d786c..0263943d1 100644 --- a/agdb/src/query/select_all_aliases_query.rs +++ b/agdb/src/query/select_all_aliases_query.rs @@ -1,18 +1,18 @@ -use crate::storage::StorageData; use crate::DbElement; use crate::DbImpl; use crate::Query; use crate::QueryError; use crate::QueryResult; +use crate::StorageData; /// Query to select all aliases in the database. /// /// The result will be number of returned aliases and list /// of elements with a single property `String("alias")` holding /// the value `String`. -pub struct SelectAllAliases {} +pub struct SelectAllAliasesQuery {} -impl Query for SelectAllAliases { +impl Query for SelectAllAliasesQuery { fn process(&self, db: &DbImpl) -> Result { let mut result = QueryResult::default(); diff --git a/agdb/src/query/select_key_count_query.rs b/agdb/src/query/select_key_count_query.rs index 7d20b34dc..636762af2 100644 --- a/agdb/src/query/select_key_count_query.rs +++ b/agdb/src/query/select_key_count_query.rs @@ -1,10 +1,10 @@ -use super::query_ids::QueryIds; -use crate::storage::StorageData; use crate::DbElement; use crate::DbImpl; use crate::Query; use crate::QueryError; +use crate::QueryIds; use crate::QueryResult; +use crate::StorageData; /// Query to select number of properties (key count) of /// given ids. All of the ids must exist in the database. diff --git a/agdb/src/query/select_keys_query.rs b/agdb/src/query/select_keys_query.rs index dff929bfd..9b3675b1d 100644 --- a/agdb/src/query/select_keys_query.rs +++ b/agdb/src/query/select_keys_query.rs @@ -1,10 +1,10 @@ -use super::query_ids::QueryIds; -use crate::storage::StorageData; use crate::DbElement; use crate::DbImpl; use crate::Query; use crate::QueryError; +use crate::QueryIds; use crate::QueryResult; +use crate::StorageData; /// Query to select only property keys of given ids. All /// of the ids must exist in the database. diff --git a/agdb/src/query/select_query.rs b/agdb/src/query/select_query.rs index 71cf8be07..a791720e5 100644 --- a/agdb/src/query/select_query.rs +++ b/agdb/src/query/select_query.rs @@ -1,10 +1,10 @@ -use super::query_ids::QueryIds; -use crate::storage::StorageData; use crate::DbElement; use crate::DbImpl; use crate::Query; use crate::QueryError; +use crate::QueryIds; use crate::QueryResult; +use crate::StorageData; /// Query to select elements with all properties of /// given ids. All ids must exist in the database. diff --git a/agdb/src/query/select_values_query.rs b/agdb/src/query/select_values_query.rs index 4c40bbb85..920928da6 100644 --- a/agdb/src/query/select_values_query.rs +++ b/agdb/src/query/select_values_query.rs @@ -1,11 +1,11 @@ -use super::query_ids::QueryIds; -use crate::storage::StorageData; use crate::DbElement; use crate::DbImpl; use crate::DbKey; use crate::Query; use crate::QueryError; +use crate::QueryIds; use crate::QueryResult; +use crate::StorageData; /// Query to select elements with only certain properties of /// given ids. All ids must exist in the database and all diff --git a/agdb/src/query_builder/insert.rs b/agdb/src/query_builder/insert.rs index fff1ba0ee..2fe182081 100644 --- a/agdb/src/query_builder/insert.rs +++ b/agdb/src/query_builder/insert.rs @@ -1,18 +1,18 @@ -use super::insert_aliases::InsertAliases; -use super::insert_edge::InsertEdges; -use super::insert_nodes::InsertNodes; -use super::insert_values::InsertValues; -use super::insert_values::InsertValuesIds; -use crate::query::insert_aliases_query::InsertAliasesQuery; -use crate::query::insert_edges_query::InsertEdgesQuery; -use crate::query::insert_nodes_query::InsertNodesQuery; -use crate::query::insert_values_query::InsertValuesQuery; use crate::query::query_aliases::QueryAliases; -use crate::query::query_ids::QueryIds; use crate::query::query_values::MultiValues; use crate::query::query_values::QueryValues; use crate::query::query_values::SingleValues; +use crate::query_builder::insert_aliases::InsertAliases; +use crate::query_builder::insert_edge::InsertEdges; +use crate::query_builder::insert_nodes::InsertNodes; +use crate::query_builder::insert_values::InsertValues; +use crate::query_builder::insert_values::InsertValuesIds; use crate::DbUserValue; +use crate::InsertAliasesQuery; +use crate::InsertEdgesQuery; +use crate::InsertNodesQuery; +use crate::InsertValuesQuery; +use crate::QueryIds; /// Insert builder for inserting various data /// into the database. diff --git a/agdb/src/query_builder/insert_aliases.rs b/agdb/src/query_builder/insert_aliases.rs index 62c075899..4a6acd497 100644 --- a/agdb/src/query_builder/insert_aliases.rs +++ b/agdb/src/query_builder/insert_aliases.rs @@ -1,5 +1,5 @@ -use crate::query::insert_aliases_query::InsertAliasesQuery; -use crate::query::query_ids::QueryIds; +use crate::InsertAliasesQuery; +use crate::QueryIds; /// Insert aliases builder to select `ids` /// of the aliases. diff --git a/agdb/src/query_builder/insert_edge.rs b/agdb/src/query_builder/insert_edge.rs index 1f8e5c596..f71a8218f 100644 --- a/agdb/src/query_builder/insert_edge.rs +++ b/agdb/src/query_builder/insert_edge.rs @@ -1,8 +1,8 @@ -use crate::query::insert_edges_query::InsertEdgesQuery; -use crate::query::query_ids::QueryIds; use crate::query::query_values::MultiValues; use crate::query::query_values::QueryValues; use crate::query::query_values::SingleValues; +use crate::InsertEdgesQuery; +use crate::QueryIds; /// Insert edges builder that lets you add `from` /// (origin) nodes. diff --git a/agdb/src/query_builder/insert_nodes.rs b/agdb/src/query_builder/insert_nodes.rs index a40bbd672..297440c28 100644 --- a/agdb/src/query_builder/insert_nodes.rs +++ b/agdb/src/query_builder/insert_nodes.rs @@ -1,8 +1,8 @@ -use crate::query::insert_nodes_query::InsertNodesQuery; use crate::query::query_aliases::QueryAliases; use crate::query::query_values::MultiValues; use crate::query::query_values::QueryValues; use crate::query::query_values::SingleValues; +use crate::InsertNodesQuery; /// Insert nodes builder to add aliases or count /// or values. diff --git a/agdb/src/query_builder/insert_values.rs b/agdb/src/query_builder/insert_values.rs index a47ac26ac..bb752f191 100644 --- a/agdb/src/query_builder/insert_values.rs +++ b/agdb/src/query_builder/insert_values.rs @@ -1,5 +1,5 @@ -use crate::query::insert_values_query::InsertValuesQuery; -use crate::query::query_ids::QueryIds; +use crate::InsertValuesQuery; +use crate::QueryIds; /// Insert values builder to set ids to which the values /// should be inserted. diff --git a/agdb/src/query_builder/remove.rs b/agdb/src/query_builder/remove.rs index aeca74a76..19ac0a4ce 100644 --- a/agdb/src/query_builder/remove.rs +++ b/agdb/src/query_builder/remove.rs @@ -1,13 +1,13 @@ -use super::remove_aliases::RemoveAliases; -use super::remove_ids::RemoveIds; -use super::remove_values::RemoveValues; use crate::query::query_aliases::QueryAliases; -use crate::query::query_ids::QueryIds; use crate::query::query_values::QueryKeys; -use crate::query::remove_aliases_query::RemoveAliasesQuery; -use crate::query::remove_query::RemoveQuery; -use crate::query::remove_values_query::RemoveValuesQuery; -use crate::query::select_values_query::SelectValuesQuery; +use crate::query_builder::remove_aliases::RemoveAliases; +use crate::query_builder::remove_ids::RemoveIds; +use crate::query_builder::remove_values::RemoveValues; +use crate::QueryIds; +use crate::RemoveAliasesQuery; +use crate::RemoveQuery; +use crate::RemoveValuesQuery; +use crate::SelectValuesQuery; /// Remove builder to choose what to delete from the database. pub struct Remove {} diff --git a/agdb/src/query_builder/remove_aliases.rs b/agdb/src/query_builder/remove_aliases.rs index a997faefb..eb7209c25 100644 --- a/agdb/src/query_builder/remove_aliases.rs +++ b/agdb/src/query_builder/remove_aliases.rs @@ -1,4 +1,4 @@ -use crate::query::remove_aliases_query::RemoveAliasesQuery; +use crate::RemoveAliasesQuery; /// Final builder that lets you create /// an actual query object. diff --git a/agdb/src/query_builder/remove_ids.rs b/agdb/src/query_builder/remove_ids.rs index acb500c20..20541332c 100644 --- a/agdb/src/query_builder/remove_ids.rs +++ b/agdb/src/query_builder/remove_ids.rs @@ -1,4 +1,4 @@ -use crate::query::remove_query::RemoveQuery; +use crate::RemoveQuery; /// Final builder that lets you create /// an actual query object. diff --git a/agdb/src/query_builder/remove_values.rs b/agdb/src/query_builder/remove_values.rs index 2652a16a0..6befc33c2 100644 --- a/agdb/src/query_builder/remove_values.rs +++ b/agdb/src/query_builder/remove_values.rs @@ -1,5 +1,5 @@ -use crate::query::query_ids::QueryIds; -use crate::query::remove_values_query::RemoveValuesQuery; +use crate::QueryIds; +use crate::RemoveValuesQuery; /// Remove values builder that lets you select the ids from /// which to remove the values. diff --git a/agdb/src/query_builder/search.rs b/agdb/src/query_builder/search.rs index 146590bec..49944d041 100644 --- a/agdb/src/query_builder/search.rs +++ b/agdb/src/query_builder/search.rs @@ -1,7 +1,7 @@ use super::where_::Where; -use crate::db::db_key::DbKeyOrder; -use crate::query::query_id::QueryId; -use crate::query::search_query::SearchQuery; +use crate::DbKeyOrder; +use crate::QueryId; +use crate::SearchQuery; use crate::SearchQueryAlgorithm; /// Search builder query. diff --git a/agdb/src/query_builder/select.rs b/agdb/src/query_builder/select.rs index e3cb1bb93..7cc7a23b0 100644 --- a/agdb/src/query_builder/select.rs +++ b/agdb/src/query_builder/select.rs @@ -1,15 +1,15 @@ -use super::select_aliases::SelectAliases; -use super::select_ids::SelectIds; -use super::select_key_count::SelectKeyCount; -use super::select_keys::SelectKeys; -use super::select_values::SelectValues; -use crate::query::query_ids::QueryIds; use crate::query::query_values::QueryKeys; -use crate::query::select_aliases_query::SelectAliasesQuery; -use crate::query::select_key_count_query::SelectKeyCountQuery; -use crate::query::select_keys_query::SelectKeysQuery; -use crate::query::select_query::SelectQuery; -use crate::query::select_values_query::SelectValuesQuery; +use crate::query_builder::select_aliases::SelectAliases; +use crate::query_builder::select_ids::SelectIds; +use crate::query_builder::select_key_count::SelectKeyCount; +use crate::query_builder::select_keys::SelectKeys; +use crate::query_builder::select_values::SelectValues; +use crate::QueryIds; +use crate::SelectAliasesQuery; +use crate::SelectKeyCountQuery; +use crate::SelectKeysQuery; +use crate::SelectQuery; +use crate::SelectValuesQuery; /// Select builder that lets you choose what /// data you want to select form the database. diff --git a/agdb/src/query_builder/select_aliases.rs b/agdb/src/query_builder/select_aliases.rs index 746636e06..d6b83c241 100644 --- a/agdb/src/query_builder/select_aliases.rs +++ b/agdb/src/query_builder/select_aliases.rs @@ -1,6 +1,6 @@ -use crate::query::query_ids::QueryIds; -use crate::query::select_aliases_query::SelectAliasesQuery; -use crate::query::select_all_aliases_query::SelectAllAliases; +use crate::QueryIds; +use crate::SelectAliasesQuery; +use crate::SelectAllAliasesQuery; /// Select aliases builder. pub struct SelectAliases(pub SelectAliasesQuery); @@ -19,8 +19,8 @@ impl SelectAliases { } /// Returns the built `SelectAllAliases` object. - pub fn query(self) -> SelectAllAliases { - SelectAllAliases {} + pub fn query(self) -> SelectAllAliasesQuery { + SelectAllAliasesQuery {} } } diff --git a/agdb/src/query_builder/select_ids.rs b/agdb/src/query_builder/select_ids.rs index c0b5a77ba..1649c6629 100644 --- a/agdb/src/query_builder/select_ids.rs +++ b/agdb/src/query_builder/select_ids.rs @@ -1,4 +1,4 @@ -use crate::query::select_query::SelectQuery; +use crate::SelectQuery; /// Final builder that lets you create /// an actual query object. diff --git a/agdb/src/query_builder/select_key_count.rs b/agdb/src/query_builder/select_key_count.rs index aaeb4263e..de6824b7c 100644 --- a/agdb/src/query_builder/select_key_count.rs +++ b/agdb/src/query_builder/select_key_count.rs @@ -1,5 +1,5 @@ -use crate::query::query_ids::QueryIds; -use crate::query::select_key_count_query::SelectKeyCountQuery; +use crate::QueryIds; +use crate::SelectKeyCountQuery; /// Select key count builder. pub struct SelectKeyCount(pub SelectKeyCountQuery); diff --git a/agdb/src/query_builder/select_keys.rs b/agdb/src/query_builder/select_keys.rs index c9f0022fd..c24998a96 100644 --- a/agdb/src/query_builder/select_keys.rs +++ b/agdb/src/query_builder/select_keys.rs @@ -1,5 +1,5 @@ -use crate::query::query_ids::QueryIds; -use crate::query::select_keys_query::SelectKeysQuery; +use crate::QueryIds; +use crate::SelectKeysQuery; /// Select keys builder. pub struct SelectKeys(pub SelectKeysQuery); diff --git a/agdb/src/query_builder/select_values.rs b/agdb/src/query_builder/select_values.rs index 33969d430..0968a194c 100644 --- a/agdb/src/query_builder/select_values.rs +++ b/agdb/src/query_builder/select_values.rs @@ -1,5 +1,5 @@ -use crate::query::query_ids::QueryIds; -use crate::query::select_values_query::SelectValuesQuery; +use crate::QueryIds; +use crate::SelectValuesQuery; /// Select values builder. pub struct SelectValues(pub SelectValuesQuery); diff --git a/agdb/src/storage.rs b/agdb/src/storage.rs index 9c1ba401c..5777a2aae 100644 --- a/agdb/src/storage.rs +++ b/agdb/src/storage.rs @@ -7,9 +7,9 @@ mod write_ahead_log; use self::storage_records::StorageRecord; use self::storage_records::StorageRecords; -use crate::db::db_error::DbError; use crate::utilities::serialize::Serialize; use crate::utilities::serialize::SerializeStatic; +use crate::DbError; #[derive(Clone, Copy, Debug, Default, Eq, PartialEq, PartialOrd, Ord)] pub struct StorageIndex(pub u64); @@ -43,6 +43,9 @@ pub trait StorageData: Sized { fn flush(&mut self) -> Result<(), DbError> { Ok(()) } + fn is_empty(&self) -> bool { + self.len() == 0 + } fn len(&self) -> u64; fn name(&self) -> &str; fn new(name: &str) -> Result; diff --git a/agdb/src/storage/file_storage.rs b/agdb/src/storage/file_storage.rs index 75388eea3..b6930b636 100644 --- a/agdb/src/storage/file_storage.rs +++ b/agdb/src/storage/file_storage.rs @@ -1,7 +1,7 @@ use super::write_ahead_log::WriteAheadLog; use super::write_ahead_log::WriteAheadLogRecord; use super::StorageData; -use crate::db::db_error::DbError; +use crate::DbError; use std::fs::File; use std::fs::OpenOptions; use std::io::Read; diff --git a/agdb/src/storage/file_storage_memory_mapped.rs b/agdb/src/storage/file_storage_memory_mapped.rs index 673e02bff..d5e146d75 100644 --- a/agdb/src/storage/file_storage_memory_mapped.rs +++ b/agdb/src/storage/file_storage_memory_mapped.rs @@ -1,7 +1,7 @@ use super::file_storage::FileStorage; use super::memory_storage::MemoryStorage; use super::StorageData; -use crate::db::db_error::DbError; +use crate::DbError; pub struct FileStorageMemoryMapped { file: FileStorage, diff --git a/agdb/src/storage/memory_storage.rs b/agdb/src/storage/memory_storage.rs index d215553f6..3ba9128d0 100644 --- a/agdb/src/storage/memory_storage.rs +++ b/agdb/src/storage/memory_storage.rs @@ -1,5 +1,5 @@ use super::StorageData; -use crate::db::db_error::DbError; +use crate::DbError; pub struct MemoryStorage { buffer: Vec, @@ -76,6 +76,14 @@ mod tests { assert_eq!(storage.name(), "storage"); } + #[test] + fn is_empty() { + let mut store = MemoryStorage::new("name").unwrap(); + assert!(store.is_empty()); + store.write(0, "Hi".as_bytes()).unwrap(); + assert!(!store.is_empty()); + } + #[test] fn index_reuse() { let mut storage = Storage::::new("storage").unwrap(); diff --git a/agdb/src/storage/storage_records.rs b/agdb/src/storage/storage_records.rs index ffe5ea022..f106bb63f 100644 --- a/agdb/src/storage/storage_records.rs +++ b/agdb/src/storage/storage_records.rs @@ -1,5 +1,5 @@ -use crate::db::db_error::DbError; use crate::utilities::serialize::Serialize; +use crate::DbError; #[derive(Clone, Copy, Default)] pub struct StorageRecord { diff --git a/agdb/src/storage/write_ahead_log.rs b/agdb/src/storage/write_ahead_log.rs index 1686777aa..9734f6ae2 100644 --- a/agdb/src/storage/write_ahead_log.rs +++ b/agdb/src/storage/write_ahead_log.rs @@ -1,6 +1,6 @@ -use crate::db::db_error::DbError; use crate::utilities::serialize::Serialize; use crate::utilities::serialize::SerializeStatic; +use crate::DbError; use std::fs::File; use std::fs::OpenOptions; use std::io::Read; diff --git a/agdb/src/test_utilities/collision_value.rs b/agdb/src/test_utilities/collision_value.rs index cb38324bd..7a0922867 100644 --- a/agdb/src/test_utilities/collision_value.rs +++ b/agdb/src/test_utilities/collision_value.rs @@ -1,13 +1,13 @@ use crate::collections::vec::VecValue; -use crate::db::db_error::DbError; use crate::storage::Storage; -use crate::storage::StorageData; use crate::utilities::serialize::Serialize; use crate::utilities::serialize::SerializeStatic; use crate::utilities::stable_hash::StableHash; +use crate::DbError; +use crate::StorageData; #[derive(Clone, Debug, Eq, PartialEq)] -pub struct CollisionValue { +struct CollisionValue { pub value: T, } diff --git a/agdb/src/test_utilities/test_file.rs b/agdb/src/test_utilities/test_file.rs index 7c6a0b221..7318e8373 100644 --- a/agdb/src/test_utilities/test_file.rs +++ b/agdb/src/test_utilities/test_file.rs @@ -1,9 +1,8 @@ -use std::fs::remove_file; use std::panic::Location; use std::path::Path; pub struct TestFile { - pub(crate) filename: String, + filename: String, } impl TestFile { @@ -28,7 +27,7 @@ impl TestFile { TestFile::from(file) } - pub(crate) fn hidden_filename(filename: &String) -> String { + fn hidden_filename(filename: &String) -> String { let path = Path::new(filename); let name: String = path.file_name().unwrap().to_str().unwrap().to_string(); let parent = path.parent().unwrap(); @@ -40,9 +39,9 @@ impl TestFile { .to_string() } - pub(crate) fn remove_file_if_exists(filename: &String) { + fn remove_file_if_exists(filename: &String) { if Path::new(filename).exists() { - remove_file(filename).unwrap(); + std::fs::remove_file(filename).unwrap(); } } } diff --git a/agdb/src/transaction.rs b/agdb/src/transaction.rs index f62d39189..59d26e72a 100644 --- a/agdb/src/transaction.rs +++ b/agdb/src/transaction.rs @@ -1,8 +1,8 @@ use crate::query::Query; -use crate::storage::StorageData; use crate::DbImpl; use crate::QueryError; use crate::QueryResult; +use crate::StorageData; /// The `Transaction` is a proxy struct that /// encapsulates an immutably borrowed `Db`. diff --git a/agdb/src/transaction_mut.rs b/agdb/src/transaction_mut.rs index d0f8e22b3..dd1454ec8 100644 --- a/agdb/src/transaction_mut.rs +++ b/agdb/src/transaction_mut.rs @@ -1,9 +1,9 @@ use crate::query::Query; use crate::query::QueryMut; -use crate::storage::StorageData; use crate::DbImpl; use crate::QueryError; use crate::QueryResult; +use crate::StorageData; use crate::Transaction; /// The `TransactionMut` is a proxy struct that diff --git a/agdb/src/utilities/serialize.rs b/agdb/src/utilities/serialize.rs index 39aa88d86..95ab2ccc2 100644 --- a/agdb/src/utilities/serialize.rs +++ b/agdb/src/utilities/serialize.rs @@ -1,4 +1,4 @@ -use crate::db::db_error::DbError; +use crate::DbError; use std::any::type_name; pub trait Serialize: Sized { diff --git a/agdb/tests/db_test.rs b/agdb/tests/db_test.rs index f48949b4a..1a383cf26 100644 --- a/agdb/tests/db_test.rs +++ b/agdb/tests/db_test.rs @@ -15,13 +15,18 @@ use test_db::TestDb; fn public_types() { use agdb::Comparison; use agdb::CountComparison; + use agdb::Db; use agdb::DbElement; use agdb::DbError; + use agdb::DbFile; + use agdb::DbFileTransaction; + use agdb::DbFileTransactionMut; use agdb::DbId; - use agdb::DbImpl; use agdb::DbKey; use agdb::DbKeyOrder; use agdb::DbKeyValue; + use agdb::DbTransaction; + use agdb::DbTransactionMut; use agdb::DbUserValue; use agdb::DbValue; use agdb::InsertAliasesQuery; @@ -31,6 +36,9 @@ fn public_types() { use agdb::Query; use agdb::QueryBuilder; use agdb::QueryCondition; + use agdb::QueryConditionData; + use agdb::QueryConditionLogic; + use agdb::QueryConditionModifier; use agdb::QueryError; use agdb::QueryId; use agdb::QueryIds; @@ -41,11 +49,13 @@ fn public_types() { use agdb::RemoveQuery; use agdb::RemoveValuesQuery; use agdb::SearchQuery; - use agdb::SelectAllAliases; + use agdb::SelectAliasesQuery; + use agdb::SelectAllAliasesQuery; use agdb::SelectKeyCountQuery; use agdb::SelectKeysQuery; use agdb::SelectQuery; use agdb::SelectValuesQuery; + use agdb::StorageData; use agdb::Transaction; use agdb::TransactionMut; use agdb::UserValue; diff --git a/agdb/tests/test_db/mod.rs b/agdb/tests/test_db/mod.rs index 7559b3def..e7ea40ef5 100644 --- a/agdb/tests/test_db/mod.rs +++ b/agdb/tests/test_db/mod.rs @@ -8,6 +8,7 @@ use agdb::Query; use agdb::QueryError; use agdb::QueryMut; use agdb::QueryResult; + pub use test_file::TestFile; pub struct TestDb {