diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2017-10-01 22:38:55 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2017-10-01 22:38:55 +0200 |
commit | 1767eb2dafbab8b19cc4cf0a9a890539ce2948c1 (patch) | |
tree | e8b8942bb9383d2a3986c2d549b1c53863c69ca1 /src/main.rs | |
parent | b62344371e4ce07aa19da5e7faeef322e907653e (diff) | |
download | rocket-blog-1767eb2dafbab8b19cc4cf0a9a890539ce2948c1.tar.gz rocket-blog-1767eb2dafbab8b19cc4cf0a9a890539ce2948c1.tar.bz2 rocket-blog-1767eb2dafbab8b19cc4cf0a9a890539ce2948c1.zip |
Add schema for posts, and display them on index page.
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 21 |
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() { |