From 1767eb2dafbab8b19cc4cf0a9a890539ce2948c1 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sun, 1 Oct 2017 22:38:55 +0200 Subject: Add schema for posts, and display them on index page. --- src/main.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/main.rs') 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::(&*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() { -- cgit v1.2.3