building db support with diesel.rs
This commit is contained in:
23
cookbook/src/bin/show_recipes.rs
Normal file
23
cookbook/src/bin/show_recipes.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
extern crate cookbook;
|
||||
extern crate diesel;
|
||||
|
||||
use self::cookbook::*;
|
||||
use self::models::*;
|
||||
use self::diesel::prelude::*;
|
||||
|
||||
fn main() {
|
||||
use cookbook::schema::recipes::dsl::*;
|
||||
|
||||
let conn = establish_connection();
|
||||
let result = recipes
|
||||
.limit(5)
|
||||
.load::<Recipe>(&conn)
|
||||
.expect("Error loading recipes");
|
||||
|
||||
println!("Here are {} recipes :", result.len());
|
||||
for rec in result {
|
||||
println!("{}", rec.title);
|
||||
println!("-------------\n");
|
||||
println!("{}", rec.ingredients);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user