aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index 711c343..622ac1c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,9 +4,26 @@
extern crate rocket;
extern crate rocket_blog;
+extern crate diesel;
+use self::diesel::prelude::*;
+
#[get("/")]
-fn index(conn: rocket_blog::DbConn) -> &'static str {
- "Hallo, for faen!"
+fn index(conn: rocket_blog::DbConn) -> String {
+ use rocket_blog::schema::posts::dsl::*;
+ let results = posts.filter(published.eq(false))
+ .limit(5)
+ .load::<rocket_blog::models::Post>(&*conn)
+ .expect("Error loading posts");
+
+ let mut output = String::from("Hallo, for faen!\n\n");
+
+ for post in results {
+ output += &format!("{}\n", post.title);
+ output += "================\n";
+ output += &format!("{}\n", post.body);
+ }
+
+ output
}
fn main() {