awbt
awbt

Reputation: 51

Why "no method named `execute` found" when using diesel::insert_into?

I have a problem when I use diesel::insert_into to insert data into the database:

table! {
    post (id) {
        id -> Integer,
        username -> Varchar,
        postdata -> Varchar,
    }
}
pub fn create_new_post(post: Post, conn: DbConn) {
    diesel::insert_into(post::table)
            .values(&post)
            .execute(&*conn);
}
6 |             .execute(&*conn);
  |              ^^^^^^^ method not found in `InsertStatement<table, ValuesClause<(ColumnInsertValue<columns::id, diesel::expression::bound::Bound<diesel::sql_types::Integer, &i32>>, ColumnInsertValue<columns::username, diesel::expression::bound::Bound<diesel::sql_types::Text, &std::string::String>>, ColumnInsertValue<columns::postdata, diesel::expression::bound::Bound<diesel::sql_types::Text, &std::string::String>>), table>>`
  |
  = help: items from traits can only be used if the trait is in scope
  = note: the following trait is implemented but not in scope; perhaps add a `use` for it:
          `use crate::diesel::RunQueryDsl; 

Can anyone help me?

Upvotes: 4

Views: 1823

Answers (1)

weiznich
weiznich

Reputation: 3445

As the compiler error message is telling you, you miss a use crate::diesel::RunQueryDsl; in your current module. That means the corresponding trait is not in scope.

Upvotes: 7

Related Questions