mirror of
https://github.com/sreedevk/deduplicator.git
synced 2026-09-04 06:25:32 +00:00
added caching
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use anyhow::{anyhow, Result};
|
||||
use anyhow::Result;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct File {
|
||||
@@ -8,10 +8,8 @@ pub struct File {
|
||||
|
||||
pub fn setup(connection: &sqlite::Connection) -> Result<()> {
|
||||
let query = "CREATE TABLE files (file_identifier STRING, hash STRING)";
|
||||
match connection.execute(query) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(e) => Err(anyhow!("Database Setup Failed! {}", e)),
|
||||
}
|
||||
connection.execute(query).ok();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn put(file: &File, connection: &sqlite::Connection) -> Result<()> {
|
||||
@@ -24,6 +22,25 @@ pub fn put(file: &File, connection: &sqlite::Connection) -> Result<()> {
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
pub fn indexed_paths(connection: &sqlite::Connection) -> Result<Vec<File>> {
|
||||
let query = format!(
|
||||
"SELECT * FROM files"
|
||||
);
|
||||
|
||||
let result: Vec<File> = connection
|
||||
.prepare(query)?
|
||||
.into_iter()
|
||||
.map(|row_result| row_result.unwrap())
|
||||
.map(|row| {
|
||||
let path = row.read::<&str, _>("file_identifier").to_string();
|
||||
let hash = row.read::<&str, _>("hash").to_string();
|
||||
File { path, hash }
|
||||
})
|
||||
.collect();
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
pub fn duplicate_hashes(connection: &sqlite::Connection) -> Result<Vec<File>> {
|
||||
let query = format!(
|
||||
"
|
||||
|
||||
Reference in New Issue
Block a user