diff --git a/src/controller.rs b/src/controller.rs index dde372d..9593370 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -2,7 +2,7 @@ use { crate::{args::Args, database, operations, structs::ExtraArgs}, anyhow::Result, md5, - prettytable::{row, Table}, + prettytable::{Table, row}, sqlite::Connection, }; @@ -80,7 +80,7 @@ pub fn manage_listing(database_connection: &Connection) -> Result<()> { "SOURCE DIR", "DESTINATION DIR", "MACHINE", - "RO/RW", + "RW", "DATE" ]); diff --git a/src/database.rs b/src/database.rs index 4987b58..8ffa8fc 100644 --- a/src/database.rs +++ b/src/database.rs @@ -17,7 +17,13 @@ pub fn setup_initial_database(connection: &Connection) -> Result<()> { pub fn commit_to_database(args: &Args, extra_args: &ExtraArgs) -> Result<()> { let statement = format!( "INSERT INTO snapshots (name, snap_id, kind, source, destination, machine, ro_rw) VALUES ('{}', '{}', '{}', '{}', '{}', '{}', '{}')", - &extra_args.snapshot_name, args.snapshot_id, args.snapshot_kind, args.source_dir, args.dest_dir, args.machine, args.read_write + &extra_args.snapshot_name, + args.snapshot_id, + args.snapshot_kind, + args.source_dir, + args.dest_dir, + args.machine, + args.read_write ); extra_args.database_connection.execute(statement)?; @@ -42,7 +48,7 @@ pub fn return_snapshot_data(connection: &Connection, args: &Args) -> Result Result> { .prepare("SELECT name,snap_id,kind,source,destination,machine,ro_rw,datetime(date, 'localtime') FROM snapshots ORDER BY date DESC")?; while statement.next()? == State::Row { - let db_struct = Database::default(); - snapshots_data.push(populate_db_struct(&statement, db_struct)?); + snapshots_data.push(populate_db_struct(&statement)?); } Ok(snapshots_data) @@ -68,24 +73,21 @@ pub fn return_only_x_items(connection: &Connection, args: &Args) -> Result {}", args.snapshot_prefix, args.snapshot_kind, args.read_write, args.keep_only))?; while statement.next()? == State::Row { - let db_struct = Database::default(); - snapshots_data.push(populate_db_struct(&statement, db_struct)?); + snapshots_data.push(populate_db_struct(&statement)?); } Ok(snapshots_data) } -fn populate_db_struct(row: &Statement, mut db_struct: Database) -> Result { - // I'll improve this later. - - db_struct.name = row.read(0)?; - db_struct.snap_id = row.read(1)?; - db_struct.kind = row.read(2)?; - db_struct.source = row.read(3)?; - db_struct.destination = row.read(4)?; - db_struct.machine = row.read(5)?; - db_struct.ro_rw = row.read(6)?; - db_struct.date = row.read(7)?; - - Ok(db_struct) +fn populate_db_struct(stmt: &Statement) -> Result { + Ok(Database { + name: stmt.read(0)?, + snap_id: stmt.read(1)?, + kind: stmt.read(2)?, + source: stmt.read(3)?, + destination: stmt.read(4)?, + machine: stmt.read(5)?, + ro_rw: stmt.read(6)?, + date: stmt.read(7)?, + }) }