DieselRust 的 ORM 框架
Diesel 是一个安全可扩展的 Rust 编程语言的 ORM 框架和查询构建工具。Diesel 可避免运行时错误,提供最好的性能。
示例代码:
extern crate diesel_demo; extern crate diesel; use self::diesel_demo::*; use self::diesel_demo::models::*; use self::diesel::prelude::*; fn main() { use diesel_demo::schema::posts::dsl::*; let connection = establish_connection(); let results = posts.filter(published.eq(true)) .limit(5) .load::<Post>(&connection) .expect("Error loading posts"); println!("Displaying {} posts", results.len()); for post in results { println!("{}", post.title); println!("----------\n"); println!("{}", post.body); } }
评论