blob: 6e98fe8b1d73af5f6f543b685ab2bf826551a796 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#[macro_use]
extern crate diesel;
extern crate chrono;
pub mod schema;
pub mod models;
use diesel::prelude::*;
use diesel::pg::PgConnection;
use std::env;
fn connect_db() -> PgConnection {
let db_url = env::var("DATABASE_URL")
.expect("DATABASE_URL must be set");
PgConnection::establish(&db_url)
.expect(&format!("Error connecting to {}", db_url))
}
fn main() {
use schema::threads::dsl::*;
use models::*;
let conn = connect_db();
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);
}
}
|