Hello!
I'm currently trying to use JSON extractor and inserting the values into the database using diesel.
Is there a way to do it? I would like to use Insertable diesel's feature but it seems not to work.
This is how I am doing it:
#[post("/create")]
pub(crate) async fn create_user(
pool: web::Data<database::ConnectionPool>,
info: web::Json<User>,
) -> String {
diesel::insert_into(users)
.values(info)
.execute(&mut pool.get().await?)
.await;
format!("User created")
}
Struct:
#[derive(Serialize, Deserialize, Queryable, Selectable, Insertable)]
#[diesel(table_name = crate::schema::users)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub(crate) struct User {
username: String,
online: bool,
user_group: UserGroupEnum,
}