mirror of
https://github.com/diesel-rs/diesel.git
synced 2024-10-04 17:47:17 +03:00
Add a minimal example for delete
Not much to say here, I just want to finish a basic usage example for all of CRUD before I tweet.
This commit is contained in:
parent
c7201b2c49
commit
96e284b862
20
README.md
20
README.md
@ -207,7 +207,7 @@ changeset! {
|
||||
fn save_user(conn: &Connection, user: &mut User) -> DbResult<()> {
|
||||
let command = update(users::table.filter(users::id.eq(user.id)))
|
||||
.set(user);
|
||||
let updated_user = try!(connection.query_one(&command)).unwrap();
|
||||
let updated_user = try!(conn.query_one(&command)).unwrap();
|
||||
*user = updated_user;
|
||||
Ok(())
|
||||
}
|
||||
@ -217,4 +217,22 @@ Note that even though we've implemented `AsChangeset`, we still need to specify
|
||||
what records we want to update. There will likely be changes that make it harder
|
||||
to accidentally update the entire table before 1.0.
|
||||
|
||||
Delete
|
||||
------
|
||||
|
||||
Delete works very similarly to `update`, but does not support returning a
|
||||
record.
|
||||
|
||||
```rust
|
||||
fn delete_user(conn: &Connection, user: User) -> DbResult<()> {
|
||||
use yaqb::query_builder::delete;
|
||||
use users::dsl::*;
|
||||
|
||||
let command = delete(users.filter(id.eq(user.id)));
|
||||
let deleted_rows = try!(conn.execute_returning_count(&command));
|
||||
debug_assert!(deleted_rows == 1);
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
||||
FIXME: Replace links to source code with hosted doc pages
|
||||
|
Loading…
Reference in New Issue
Block a user