Add a new command to dump files to json files

This commit is contained in:
2022-06-01 00:53:53 -04:00
parent f59a0155d8
commit bed49d0953
6 changed files with 99 additions and 3 deletions

View File

@@ -0,0 +1,27 @@
use anyhow::Result;
use std::fs::File;
use std::io::Write;
use std::path::Path;
use crate::models::file;
pub async fn dump_file_data(pool: &sqlx::Pool<sqlx::Postgres>, dir: &str) -> Result<()> {
let page_size = 20;
let mut last_id = None;
loop {
let files =
file::batched_get_with_cells(&pool, page_size, last_id, "Skyrim.esm", 1).await?;
if files.is_empty() {
break;
}
for file_with_cells in files {
let path = Path::new(&dir);
std::fs::create_dir_all(&path)?;
let path = path.join(format!("{}.json", file_with_cells.nexus_file_id));
let mut file = File::create(path)?;
write!(file, "{}", serde_json::to_string(&file_with_cells)?)?;
last_id = Some(file_with_cells.id);
}
}
return Ok(());
}

View File

@@ -6,6 +6,7 @@ pub mod dump_mod_cell_counts;
pub mod dump_mod_data;
pub mod dump_mod_search_index;
pub mod dump_plugin_data;
pub mod dump_file_data;
pub mod update;
pub use download_tiles::download_tiles;
@@ -15,4 +16,5 @@ pub use dump_mod_cell_counts::dump_mod_cell_counts;
pub use dump_mod_data::dump_mod_data;
pub use dump_mod_search_index::dump_mod_search_index;
pub use dump_plugin_data::dump_plugin_data;
pub use dump_file_data::dump_file_data;
pub use update::update;