2 个版本
使用旧的 Rust 2015
0.0.2 | 2016 年 6 月 17 日 |
---|---|
0.0.1 | 2016 年 6 月 17 日 |
#59 在 #iron
6KB
Mysql 连接池中间件用于 Iron Web 框架
此中间件将连接池插入到请求的 extensions 中
用法
extern crate iron;
extern crate mysql;
extern crate iron_middleware_mysql;
use iron::prelude::*;
use mysql::conn::pool::Pool;
use iron_middleware_mysql::DBPool;
fn hello_world(request: &mut Request) -> IronResult<Response> {
let db_pool = request.extensions.get::<DBPool>().unwrap();
let res = db_pool.prep_exec("select 23", ()).unwrap().next().unwrap().unwrap().unwrap()[0].clone();
Ok(Response::with((iron::status::Ok, format!("Got {:?}", res))))
}
fn main() {
let pool = Pool::new("mysql://user:password@localhost:3306").unwrap();
let dbpool = DBPool{pool: pool.clone()};
let mut chain = Chain::new(hello_world);
chain.link_before(dbpool);
Iron::new(chain).http("localhost:3000").unwrap();
}
请参阅包含的示例以获取详细信息
依赖项
~11MB
~235K SLoC