summary refs log tree commit diff stats
path: root/src/main.rs
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-08-31 14:03:02 -0400
committerBen Morrison <ben@gbmor.dev>2019-08-31 14:03:02 -0400
commit39894be3eac7d3410d460c8a7b52a6eae2caf841 (patch)
treea8967ac68d900d37633e8f302d9e2ecdf68f892a /src/main.rs
parentcf0ad9b11707abef27ee4acd00f3cfd679eeff23 (diff)
downloadclinte-39894be3eac7d3410d460c8a7b52a6eae2caf841.tar.gz
moved display func to posts.rs
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs36
1 files changed, 1 insertions, 35 deletions
diff --git a/src/main.rs b/src/main.rs
index f5735e7..65652d9 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -48,7 +48,7 @@ fn main() {
         delete(&db);
     }
 
-    list_matches(&db);
+    posts::display(&db);
 }
 
 // Make sure nobody encodes narsty characters
@@ -63,40 +63,6 @@ fn str_to_utf8(str: &str) -> String {
         .collect::<String>()
 }
 
-fn list_matches(db: &db::Conn) {
-    let mut stmt = db.conn.prepare("SELECT * FROM posts").unwrap();
-    let out = stmt
-        .query_map(rusqlite::NO_PARAMS, |row| {
-            let id: u32 = row.get(0)?;
-            let title: String = row.get(1)?;
-            let author: String = row.get(2)?;
-            let body: String = row.get(3)?;
-            Ok(db::Post {
-                id,
-                title,
-                author,
-                body,
-            })
-        })
-        .unwrap();
-
-    let mut postvec = Vec::new();
-    out.for_each(|row| {
-        if let Ok(post) = row {
-            postvec.push(format!(
-                "{}. {} -> by {}\n{}\n\n",
-                post.id, post.title, post.author, post.body
-            ));
-        }
-    });
-
-    for (i, e) in postvec.iter().enumerate() {
-        if (postvec.len() > 14 && i >= postvec.len() - 15) || postvec.len() < 15 {
-            print!("{}", e);
-        }
-    }
-}
-
 fn post(db: &db::Conn) {
     let mut stmt = db
         .conn