From a0411a61ac9ce7237c12ff7960cda5f736316c9c Mon Sep 17 00:00:00 2001 From: jessekrubin Date: Fri, 10 Nov 2023 14:24:41 -0800 Subject: [PATCH] clippying --- crates/utilesqlite/src/mbtiles.rs | 409 ++++++++++++++---------------- 1 file changed, 196 insertions(+), 213 deletions(-) diff --git a/crates/utilesqlite/src/mbtiles.rs b/crates/utilesqlite/src/mbtiles.rs index 2df39905..3fe480ec 100644 --- a/crates/utilesqlite/src/mbtiles.rs +++ b/crates/utilesqlite/src/mbtiles.rs @@ -14,13 +14,11 @@ pub struct Mbtiles { impl Mbtiles { pub fn from_conn(conn: Connection) -> Mbtiles { - Mbtiles { - conn, - } + Mbtiles { conn } } pub fn metadata(&self) -> RusqliteResult> { - return mbtiles_metadata(&self.conn); + mbtiles_metadata(&self.conn) // let mut stmt = self.conn.as_ref().unwrap().prepare("SELECT name, value FROM metadata")?; // let rows = stmt.query_map([], |row| { // Ok( @@ -40,254 +38,239 @@ impl Mbtiles { Ok(t) => Ok(t), Err(e) => { error!("Error parsing metadata to TileJSON: {}", e); - Err(e.into()) + Err(e) } } // return Ok(tj); } - pub fn from_filepath(fspath: &str) -> RusqliteResult { let conn = Connection::open(fspath)?; - let mbt = Mbtiles { - conn, - }; - return Ok(mbt); + let mbt = Mbtiles { conn }; + Ok(mbt) } pub fn from_filepath_str(fspath: &str) -> Result> { let conn = Connection::open(fspath)?; - let mbt = Mbtiles { - conn, - }; - return Ok(mbt); + let mbt = Mbtiles { conn }; + Ok(mbt) } } impl From<&Path> for Mbtiles { fn from(path: &Path) -> Self { let conn = Connection::open(path).unwrap(); - Mbtiles { - conn, - } + Mbtiles { conn } } } - -pub struct MbtilesManager { - conn: Option, -} - - pub fn mbtiles_metadata(conn: &Connection) -> RusqliteResult> { let mut stmt = conn.prepare("SELECT name, value FROM metadata")?; let mdata = stmt .query_map([], |row| { - Ok( - MbtilesMetadataRow { - name: row.get(0)?, - value: row.get(1)?, - } - ) + Ok(MbtilesMetadataRow { + name: row.get(0)?, + value: row.get(1)?, + }) })? .collect::, rusqlite::Error>>()?; - return Ok(mdata); + Ok(mdata) } -impl MbtilesManager { - // Create a new instance of the MbtilesManager - pub fn new() -> MbtilesManager { - MbtilesManager { conn: None } - } - - // Open a connection to the MBTiles SQLite database - pub fn open(&mut self, path: &str) -> RusqliteResult<()> { - self.conn = Some(Connection::open(path)?); - Ok(()) - } - - // Execute a query on the MBTiles database - pub fn query(&self, sql: &str, mut map_fn: F) -> RusqliteResult> - where - F: FnMut(&rusqlite::Row<'_>) -> RusqliteResult, - { - match &self.conn { - Some(conn) => { - let mut stmt = conn.prepare(sql)?; - let rows = stmt.query_map([], |row| map_fn(row))?; - rows.collect() - } - None => Err(rusqlite::Error::InvalidQuery), - } - } - - pub fn metadata(&self) -> RusqliteResult> { - return mbtiles_metadata(self.conn.as_ref().unwrap()); - // let mut stmt = self.conn.as_ref().unwrap().prepare("SELECT name, value FROM metadata")?; - // let rows = stmt.query_map([], |row| { - // Ok( - // MbtilesMetadataRow { - // name: row.get(0)?, - // value: row.get(1)?, - // } - // ) - // })?; - // rows.collect() - } - - // Close the connection to the MBTiles database - pub fn close(&mut self) -> RusqliteResult<()> { - if let Some(conn) = self.conn.take() { - conn.close().map_err(|(_, e)| e) - } else { - Ok(()) - } - } -} - -// fn main() { -// let mut mbtiles_manager = MbtilesManager::new(); -// -// // Open the database connection -// mbtiles_manager.open("path/to/your/mbtiles/database.mbtiles").unwrap(); -// -// // Execute a query -// let result: Result> = mbtiles_manager.query("SELECT name FROM some_table", |row| { -// Ok(row.get(0)?) -// }); -// match result { -// Ok(rows) => { -// for row in rows { -// println!("{}", row); -// } -// } -// Err(err) => eprintln!("Query failed: {}", err), +// impl MbtilesManager { +// // Create a new instance of the MbtilesManager +// pub fn new() -> MbtilesManager { +// MbtilesManager { conn: None } // } // -// // Close the database connection -// mbtiles_manager.close().unwrap(); -// } - -// #[derive(Debug)] -// pub struct Mbtiles<'a> { -// pub conn: &'a mut rusqlite::Connection, -// } -// #[derive(Debug)] -// pub struct MetadataRow { -// pub name: String, -// pub value: String, -// } -// -// impl Mbtiles<'_> { -// // impl Mbtiles { -// pub fn metadata<'a>(&'a self) -> rusqlite::Result> { -// // return all_metadata(self.conn); -// -// let mut stmt = self.conn.prepare("SELECT name, value FROM metadata")?; -// let mdata = stmt -// .query_map([], |row| { -// Ok( -// MetadataRow { -// name: row.get(0)?, -// value: row.get(1)?, -// } -// ) -// })? -// .collect::>>(); -// return Ok(mdata?); -// } -// -// pub fn open<'a>(fspath: &str) -> rusqlite::Result { -// let mut conn = rusqlite::Connection::open(fspath)?; -// let mbt = Mbtiles { -// conn: &mut conn, -// }; -// -// return Ok(mbt); -// +// // Open a connection to the MBTiles SQLite database +// pub fn open(&mut self, path: &str) -> RusqliteResult<()> { +// self.conn = Some(Connection::open(path)?); +// Ok(()) // } // -// pub fn from_conn<'a>(conn: &mut rusqlite::Connection) -> Mbtiles { -// Mbtiles { -// conn: conn, +// // Execute a query on the MBTiles database +// pub fn query(&self, sql: &str, mut map_fn: F) -> RusqliteResult> +// where +// F: FnMut(&rusqlite::Row<'_>) -> RusqliteResult, +// { +// match &self.conn { +// Some(conn) => { +// let mut stmt = conn.prepare(sql)?; +// let rows = stmt.query_map([], |row| map_fn(row))?; +// rows.collect() +// } +// None => Err(rusqlite::Error::InvalidQuery), // } // } -// } -// -// -// pub fn all_metadata (conn: &rusqlite::Connection) -> rusqlite::Result> { -// let mut stmt = conn.prepare("SELECT name, value FROM metadata")?; -// let mdata = stmt -// .query_map([], |row| { -// Ok( -// MetadataRow { -// name: row.get(0)?, -// value: row.get(1)?, -// } -// ) -// })? -// .collect::>>(); -// return Ok(mdata?); -// } - -// #[derive(Debug)] -// pub struct Mbtiles<'a> { -// pub conn: &'a mut rusqlite::Connection, -// } -// #[derive(Debug)] -// pub struct MetadataRow { -// pub name: String, -// pub value: String, -// } // -// impl Mbtiles<'_> { -// // impl Mbtiles { -// pub fn metadata<'a>(&'a self) -> rusqlite::Result> { -// // return all_metadata(self.conn); -// -// let mut stmt = self.conn.prepare("SELECT name, value FROM metadata")?; -// let mdata = stmt -// .query_map([], |row| { -// Ok( -// MetadataRow { -// name: row.get(0)?, -// value: row.get(1)?, -// } -// ) -// })? -// .collect::>>(); -// return Ok(mdata?); +// pub fn metadata(&self) -> RusqliteResult> { +// return mbtiles_metadata(self.conn.as_ref().unwrap()); +// // let mut stmt = self.conn.as_ref().unwrap().prepare("SELECT name, value FROM metadata")?; +// // let rows = stmt.query_map([], |row| { +// // Ok( +// // MbtilesMetadataRow { +// // name: row.get(0)?, +// // value: row.get(1)?, +// // } +// // ) +// // })?; +// // rows.collect() // } // -// pub fn open<'a>(fspath: &str) -> rusqlite::Result { -// let mut conn = rusqlite::Connection::open(fspath)?; -// let mbt = Mbtiles { -// conn: &mut conn, -// }; -// -// return Ok(mbt); -// -// } -// -// pub fn from_conn<'a>(conn: &mut rusqlite::Connection) -> Mbtiles { -// Mbtiles { -// conn: conn, +// // Close the connection to the MBTiles database +// pub fn close(&mut self) -> RusqliteResult<()> { +// if let Some(conn) = self.conn.take() { +// conn.close().map_err(|(_, e)| e) +// } else { +// Ok(()) // } // } // } // +// // fn main() { +// // let mut mbtiles_manager = MbtilesManager::new(); +// // +// // // Open the database connection +// // mbtiles_manager.open("path/to/your/mbtiles/database.mbtiles").unwrap(); +// // +// // // Execute a query +// // let result: Result> = mbtiles_manager.query("SELECT name FROM some_table", |row| { +// // Ok(row.get(0)?) +// // }); +// // match result { +// // Ok(rows) => { +// // for row in rows { +// // println!("{}", row); +// // } +// // } +// // Err(err) => eprintln!("Query failed: {}", err), +// // } +// // +// // // Close the database connection +// // mbtiles_manager.close().unwrap(); +// // } // -// pub fn all_metadata (conn: &rusqlite::Connection) -> rusqlite::Result> { -// let mut stmt = conn.prepare("SELECT name, value FROM metadata")?; -// let mdata = stmt -// .query_map([], |row| { -// Ok( -// MetadataRow { -// name: row.get(0)?, -// value: row.get(1)?, -// } -// ) -// })? -// .collect::>>(); -// return Ok(mdata?); -// } +// // #[derive(Debug)] +// // pub struct Mbtiles<'a> { +// // pub conn: &'a mut rusqlite::Connection, +// // } +// // #[derive(Debug)] +// // pub struct MetadataRow { +// // pub name: String, +// // pub value: String, +// // } +// // +// // impl Mbtiles<'_> { +// // // impl Mbtiles { +// // pub fn metadata<'a>(&'a self) -> rusqlite::Result> { +// // // return all_metadata(self.conn); +// // +// // let mut stmt = self.conn.prepare("SELECT name, value FROM metadata")?; +// // let mdata = stmt +// // .query_map([], |row| { +// // Ok( +// // MetadataRow { +// // name: row.get(0)?, +// // value: row.get(1)?, +// // } +// // ) +// // })? +// // .collect::>>(); +// // return Ok(mdata?); +// // } +// // +// // pub fn open<'a>(fspath: &str) -> rusqlite::Result { +// // let mut conn = rusqlite::Connection::open(fspath)?; +// // let mbt = Mbtiles { +// // conn: &mut conn, +// // }; +// // +// // return Ok(mbt); +// // +// // } +// // +// // pub fn from_conn<'a>(conn: &mut rusqlite::Connection) -> Mbtiles { +// // Mbtiles { +// // conn: conn, +// // } +// // } +// // } +// // +// // +// // pub fn all_metadata (conn: &rusqlite::Connection) -> rusqlite::Result> { +// // let mut stmt = conn.prepare("SELECT name, value FROM metadata")?; +// // let mdata = stmt +// // .query_map([], |row| { +// // Ok( +// // MetadataRow { +// // name: row.get(0)?, +// // value: row.get(1)?, +// // } +// // ) +// // })? +// // .collect::>>(); +// // return Ok(mdata?); +// // } +// +// // #[derive(Debug)] +// // pub struct Mbtiles<'a> { +// // pub conn: &'a mut rusqlite::Connection, +// // } +// // #[derive(Debug)] +// // pub struct MetadataRow { +// // pub name: String, +// // pub value: String, +// // } +// // +// // impl Mbtiles<'_> { +// // // impl Mbtiles { +// // pub fn metadata<'a>(&'a self) -> rusqlite::Result> { +// // // return all_metadata(self.conn); +// // +// // let mut stmt = self.conn.prepare("SELECT name, value FROM metadata")?; +// // let mdata = stmt +// // .query_map([], |row| { +// // Ok( +// // MetadataRow { +// // name: row.get(0)?, +// // value: row.get(1)?, +// // } +// // ) +// // })? +// // .collect::>>(); +// // return Ok(mdata?); +// // } +// // +// // pub fn open<'a>(fspath: &str) -> rusqlite::Result { +// // let mut conn = rusqlite::Connection::open(fspath)?; +// // let mbt = Mbtiles { +// // conn: &mut conn, +// // }; +// // +// // return Ok(mbt); +// // +// // } +// // +// // pub fn from_conn<'a>(conn: &mut rusqlite::Connection) -> Mbtiles { +// // Mbtiles { +// // conn: conn, +// // } +// // } +// // } +// // +// // +// // pub fn all_metadata (conn: &rusqlite::Connection) -> rusqlite::Result> { +// // let mut stmt = conn.prepare("SELECT name, value FROM metadata")?; +// // let mdata = stmt +// // .query_map([], |row| { +// // Ok( +// // MetadataRow { +// // name: row.get(0)?, +// // value: row.get(1)?, +// // } +// // ) +// // })? +// // .collect::>>(); +// // return Ok(mdata?); +// // }