Skip to content

Commit

Permalink
Merge pull request #23 from carvilsi/persists-path
Browse files Browse the repository at this point in the history
added custom path to persists file
  • Loading branch information
carvilsi authored Aug 28, 2024
2 parents 4c7341f + f81da19 commit f2d71e9
Show file tree
Hide file tree
Showing 16 changed files with 369 additions and 32 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

# [v1.0.0](https://github.com/carvilsi/gruphst/releases/tag/v1.0.0) (2024-08-28)

- added custom path to persists file

# [v0.13.0](https://github.com/carvilsi/gruphst/releases/tag/v0.13.0) (2024-08-19)

- supports Vec<u8> for Vertex attribute content: *set_attr_vec_u8* and *get_attr_vec_u8*
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gruphst"
version = "0.13.0"
version = "1.0.0"
edition = "2021"
description = "An in-memory graph database"
license = "MIT"
Expand All @@ -11,8 +11,6 @@ homepage = "https://github.com/carvilsi/gruphst"
keywords = ["graph-database", "in-memory-database", "persistence"]
categories = ["database"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bincode = "1.0"
serde = { version = "1.0", features = ["derive", "rc"] }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ fn main() -> Result<(), Box<dyn Error>> {
// a file called "middle-earth.grphst" will be created,
// later we can load it with:
// let loaded_graphs = Graphs::load("middle-earth.grphst")?;
graphs.persists()?;
graphs.persists(None)?;

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion examples/middle-earth/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/middle-earth/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fn main() -> Result<(), Box<dyn Error>> {
// a file called "middle-earth.grphst" will be created,
// later we can load it with:
// let loaded_graphs = Graphs::load("middle-earth.grphst")?;
graphs.persists()?;
graphs.persists(None)?;

Ok(())
}
2 changes: 1 addition & 1 deletion examples/rock-paper-scissors-lizard-spock/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/rock-paper-scissors-lizard-spock/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn main() {

// maybe now you want to persists the game rules
// to use it other day ;)
let _ = rules.persists();
let _ = rules.persists(None);

// get the characters
let characters = rules.get_uniq_vertices(None).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions src/edge/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ impl Edge {

// finds a Vertex by Id on an Edge
pub fn find_vertex_by_id(&self, id: &str) -> Result<Vertex, &'static str> {
if self.get_from_vertex().get_id() == id.to_string() {
if self.get_from_vertex().get_id() == *id {
Ok(self.get_from_vertex())
} else if self.get_to_vertex().get_id() == id.to_string() {
} else if self.get_to_vertex().get_id() == *id {
Ok(self.get_to_vertex())
} else {
Err("Vertex not found")
Expand Down
11 changes: 7 additions & 4 deletions src/graphs/persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ impl Graphs {
///
/// // will write a file called 'Middle-earth.grphst' with
/// // the content of the graphs
/// graphs.persists();
/// graphs.persists(None);
/// ```
pub fn persists(&self) -> Result<(), Box<dyn Error>> {
let file_name = format!("{}.grphst", self.get_label().replace(' ', "_"));
pub fn persists(&self, file_path: Option<&str>) -> Result<(), Box<dyn Error>> {
let file_name = match file_path {
Some(fp) => format!("{}{}.grphst", fp, self.get_label().replace(' ', "_")),
None => format!("{}.grphst", self.get_label().replace(' ', "_")),
};
let mut file = OpenOptions::new()
.create(true)
.write(true)
Expand All @@ -48,7 +51,7 @@ impl Graphs {
/// "created",
/// &Vertex::new("One Ring"));
/// let mut graphs = Graphs::init_with("Middle-earth", &edge);
/// graphs.persists();
/// graphs.persists(None);
///
/// let loaded_graphs = Graphs::load("Middle-earth.grphst").unwrap();
/// ```
Expand Down
2 changes: 1 addition & 1 deletion src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub(crate) fn graphs_memory_watcher(graphs: &Graphs) {
mem_prss if mem_prss >= 99_f32 => {
error!("memory usage critical: {:.2}", mem_prss);
error!("auto persisting current graphs: {}, then panicking", graphs.get_label());
let _ = graphs.persists();
let _ = graphs.persists(None);
panic!("memory usage critical, auto-persisted current graphs");
}
_ => debug!("memory ok: {:.2}", mem_prss),
Expand Down
4 changes: 2 additions & 2 deletions src/vertex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ impl Vertex {
self.vrtx.borrow_mut().attr.insert(attr_k.to_string(), attr_v.to_string());
}

pub fn set_attr_vec_u8(&mut self, attr_k: &str, attr_v: &Vec<u8>) {
self.vrtx.borrow_mut().attr_vec_u8.insert(attr_k.to_string(), attr_v.clone());
pub fn set_attr_vec_u8(&mut self, attr_k: &str, attr_v: &[u8]) {
self.vrtx.borrow_mut().attr_vec_u8.insert(attr_k.to_string(), attr_v.to_owned());
}

/// Get attribute for a vertex
Expand Down
2 changes: 2 additions & 0 deletions tests/data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
!*.grphst
graphs-a.grphst
Binary file added tests/data/big-big-big.grphst
Binary file not shown.
Loading

0 comments on commit f2d71e9

Please sign in to comment.