From 5604d933e89f9020299f59d927d73f2cd12b4134 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 8 Apr 2018 16:08:26 +0200 Subject: feat(main): Add minimal thread listing example --- Cargo.toml | 2 +- src/main.rs | 11 +++++++++-- src/models.rs | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e2f4b2c62fb3..4800dbd02a3c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,5 +7,5 @@ authors = ["Vincent Ambo "] actix = "0.5" actix-web = { git="https://github.com/actix/actix-web.git" } env_logger = "0.5" -diesel = { version = "1.0", features = ["postgres", "chrono"]} +diesel = { version = "1.2", features = ["postgres", "chrono"]} chrono = "0.4" diff --git a/src/main.rs b/src/main.rs index 2cb814a3434f..6e98fe8b1d73 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,8 +19,15 @@ fn connect_db() -> PgConnection { fn main() { use schema::threads::dsl::*; - use schema::posts::dsl::*; + use models::*; let conn = connect_db(); - let threads = threads. + let result: Vec = threads + .load::(&conn) + .expect("Error loading threads"); + + for thread in result { + println!("Subject: {}\nPosted: {}\n", thread.title, thread.posted); + println!("{}", thread.body); + } } diff --git a/src/models.rs b/src/models.rs index a7ed8a91df03..e502891305a2 100644 --- a/src/models.rs +++ b/src/models.rs @@ -8,6 +8,7 @@ pub struct Thread { pub posted: DateTime, } +#[derive(Queryable)] pub struct Post { pub id: i32, pub thread: i32, -- cgit 1.4.1