feat: add db state persistence
This commit is contained in:
parent
6bf4e34006
commit
e75ea5d5db
4 changed files with 115 additions and 39 deletions
15
server/src/persistence.rs
Normal file
15
server/src/persistence.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
use std::path::PathBuf;
|
||||
use tokio::{fs, io};
|
||||
use minisql::interpreter::State;
|
||||
|
||||
pub async fn state_from_file(path: &PathBuf) -> io::Result<State> {
|
||||
let content = fs::read_to_string(path).await?;
|
||||
let state = serde_json::from_str(&content)?;
|
||||
Ok(state)
|
||||
}
|
||||
|
||||
pub async fn state_to_file(state: &State, path: &PathBuf) -> io::Result<()> {
|
||||
let content = serde_json::to_string(state)?;
|
||||
fs::write(path, content).await?;
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue