Diesel.rs: How to SET field = field + 1?


#1

Hi everyone,
I am learning Rust for 2 months. I started with diesel but switched to rusqlite due to the lack of documentation for diesel. Now I try diesel again. I try to understand diesel by searching its codes and test-codes on GitHub (Its examples do not help much). I can do most of things, but now I can not find out how to:

UPDATE some_table SET some_field = some_field + 1 WHERE id=?;

Can someone help me with this?
Thanks you all!


#2

I finally found out the answer here (search diesel’s GitHub repo by using keyword increment)

What we need are: line 20,

numeric_expr!(posts::visit_count);

and line 95:

diesel::update(posts).set(visit_count.eq(visit_count + 1)).execute(conn)