3

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?

kmdreko
  • 42,554
  • 6
  • 57
  • 106
awbt
  • 41
  • 2

1 Answers1

6

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.

weiznich
  • 2,910
  • 9
  • 16