-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.rs
33 lines (26 loc) · 837 Bytes
/
main.rs
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
extern crate chrono;
#[macro_use]
extern crate diesel;
use chrono::prelude::{Utc};
use diesel::prelude::*;
use diesel::pg::PgConnection;
use std::env;
pub mod schema;
pub mod models;
use self::models::{Example, NewExample};
fn main() {
let postgres_url = env::var("DATABASE_URL")
.expect("requires DATABASE_URL env var");
let pg = PgConnection::establish(&postgres_url)
.expect(&format!("Error connecting to {}", postgres_url));
let now = Utc::now().naive_utc();
let new_example = NewExample {
created_at: now,
updated_at: Some(now),
};
let database_record = diesel::insert_into(schema::examples::table)
.values(&new_example)
.get_result::<Example>(&pg)
.expect("Error saving new example");
println!("Inserted example: {:?}", database_record);
}