< 返回版块

rust r2d2-diesel数据池

kiyoshi 发表于

我最近在学习rust, 在写数据池的时候(我用的数据库是postgresql),我去获取连接,读数据.返回的应该是Vec数组.编辑器也没提示错误.但是编译的时候编译器却提示类型不匹配.不知道有没有大神帮我看看.

impl Handler<Articles> for ConnDsl {
	type Result = Result<ArticleInfoMsgs, Error>;
	fn handle (&mut self, ainfo: Articles, _: &mut Self::Context) -> Self::Result {
		use schema::articles::dsl::*;
		let conn: &PgConnection = self.0.get().deref_ok().map_err(error::ErrorInternalServerError)?;
		let articles: Vec<Article> = articles.load::<Article>(conn).map_err(error::ErrorInternalServerError)?;
		Ok(
			ArticleInfoMsgs {
				status: 200,
				message: "success.....".to_owned(),
				articles: articles,
			}
		)
	}
}

然后错误提示:

let articles: Vec<Article> = articles.load::<Article>(conn).map_err(error::ErrorInternalServerError)?;
    ^^^^^^^^ expected struct `std::vec::Vec`, found struct `schema::articles::table`

note: expected type `std::vec::Vec<models::Article>`
         found type `schema::articles::table`

希望有大神给我解答.感激不尽

评论区

fishfish 2018-08-25T01:50:21.446314

note: expected type std::vec::Vec<models::Article>

     found type `schema::articles::table`

这个其实很明白啊,类型不匹配

damody 2018-09-12T02:32:57.263583

use schema::articles::dsl::*; 這個不要這樣用 常常會衝突 use schema::articles::dsl as articles_dsl; 用這樣吧

fishfish 2018-09-12T23:02:35.830153

diesel 会不会太重了,我用了一段时间,就不再用了。。。 现在在自己写 orm

1 共 3 评论, 共 1 页