feat(main): Add minimal thread listing example
This commit is contained in:
parent
f3f509d463
commit
5604d933e8
3 changed files with 11 additions and 3 deletions
|
@ -7,5 +7,5 @@ authors = ["Vincent Ambo <mail@tazj.in>"]
|
|||
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"
|
||||
|
|
11
src/main.rs
11
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<Thread> = threads
|
||||
.load::<Thread>(&conn)
|
||||
.expect("Error loading threads");
|
||||
|
||||
for thread in result {
|
||||
println!("Subject: {}\nPosted: {}\n", thread.title, thread.posted);
|
||||
println!("{}", thread.body);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ pub struct Thread {
|
|||
pub posted: DateTime<Utc>,
|
||||
}
|
||||
|
||||
#[derive(Queryable)]
|
||||
pub struct Post {
|
||||
pub id: i32,
|
||||
pub thread: i32,
|
||||
|
|
Loading…
Reference in a new issue