summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/main.rs36
-rw-r--r--src/posts.rs34
2 files changed, 35 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
diff --git a/src/posts.rs b/src/posts.rs
index 698f8a6..77e24fc 100644
--- a/src/posts.rs
+++ b/src/posts.rs
@@ -15,6 +15,40 @@ pub fn new(stmt: &mut rusqlite::Statement, title: &str, body: &str) -> Result<()
     Ok(())
 }
 
+pub fn display(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);
+        }
+    }
+}
+
 pub fn update(new_title: &str, new_body: &str, id_num_in: u32, db: &db::Conn) -> Result<()> {
     let new_title = new_title.trim();
     let new_body = new_body.trim();
d1fd1b2a6b5bfa2a'>^
3ae1fd00 ^
02684e8d ^




3ae1fd00 ^

02684e8d ^





f7f0d631 ^
e92fa89e ^


f7f0d631 ^









120a7408 ^
f7f0d631 ^
120a7408 ^
f7f0d631 ^










1f0f3813 ^
f7f0d631 ^
02684e8d ^








































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133