Skip to content

Commit 116c3ad

Browse files
authored
Merge pull request diesel-rs#983 from killercup/docs/update-guide-patches
Wording, typo fixes for update guide
2 parents 0c2a093 + b74d3a5 commit 116c3ad

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

guide_drafts/all-about-updates.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
All About Updates
22
=================
33

4-
Most applications fall into a category called "CRUD" apps. CRUD stands for Create Read Update Delete. Diesel provides support for all four pieces, but in this guide we're going to look at all the different ways to go about updating records with Diesel.
4+
Most applications fall into a category called "CRUD" apps. CRUD stands for "Create, Read, Update, Delete". Diesel provides support for all four pieces, but in this guide we're going to look at all the different ways to go about updating records.
55

6-
An update statement is constructed by calling `diesel::update(target).set(changes)`. The resulting statement is then run be calling either `execute`, `get_result`, or `get_results`.
6+
An update statement is constructed by calling `diesel::update(target).set(changes)`. The resulting statement is then run by calling either `execute`, `get_result`, or `get_results`.
77

8-
If you look at the documentation for [`update`](http://docs.diesel.rs/diesel/fn.update.html), you'll notice that the type of the argument is any type `T` which implements `IntoUpdateTarget`. You don't need to worry about what this trait does, but it is important to know which types implement it. There are 3 kinds which implement this trait. The first is tables.
8+
If you look at the documentation for [`update`](http://docs.diesel.rs/diesel/fn.update.html), you'll notice that the type of the argument is any type `T` which implements `IntoUpdateTarget`. You don't need to worry about what this trait does, but it is important to know which types implement it. There are three kinds which implement this trait. The first is tables.
99

1010
If we have a table that looks like this:
1111

@@ -38,7 +38,7 @@ We can look use the [`print_sql!`] macro to inspect the generated SQL. The macro
3838
UPDATE `posts` SET `draft` = ?
3939
```
4040

41-
This is pretty much one-to-one with the Rust code. It's quite rare to want to update an entire table, though. So let's look at how we can scope that down. The second kind that you can pass to `update` is any query which has only had `.filter` called on it. We could scope our update to only touch posts where `publish_at` is in the past like so:
41+
This is pretty much one-to-one with the Rust code (the `?` denotes a bound parameter in SQL, which will be substituted with `false` here). It's quite rare to want to update an entire table, though. So let's look at how we can scope that down. The second kind that you can pass to `update` is any query which has only had `.filter` called on it. We could scope our update to only touch posts where `publish_at` is in the past like so:
4242

4343
```rust
4444
use posts::dsl::*;
@@ -99,7 +99,7 @@ That would generate this SQL:
9999
UPDATE `posts` SET `visit_count` = `posts`.`visit_count` + 1
100100
```
101101

102-
Note that to use the Rust `+` operator on our column, we'll need to have written `numeric_expr!(posts::visit_count)` somewhere after we declared it. Diesel may do this automatically for you in the future. Assigning values directly is great for small, simple changes. If we wanted to update multiple columns this way, we can pass a tuple.
102+
Note that to use the Rust `+` operator on our column, we'll need to have written `numeric_expr!(posts::visit_count)` somewhere after we declared it. (Diesel may do this automatically for you in the future.) Assigning values directly is great for small, simple changes. If we wanted to update multiple columns this way, we can pass a tuple.
103103

104104
```rust
105105
use posts::dsl::*;
@@ -164,5 +164,5 @@ UPDATE `posts` SET `body` = ?
164164

165165
If you wanted to assign `NULL` instead, you can either specify `#[changeset_options(treat_none_as_null="true")]` on the struct, or you can have the field be of type `Option<Option<T>>`. Diesel doesn't currently provide a way to explicitly assign a field to its default value, though it may be provided in the future.
166166

167-
TODO: Cover `execute` vs `get_result` vs `get_results` vs `save_changes`
168-
TODO: Briefly mention upsert exists, point to docs
167+
<!-- TODO: Cover `execute` vs `get_result` vs `get_results` vs `save_changes` -->
168+
<!-- TODO: Briefly mention upsert exists, point to docs -->

0 commit comments

Comments
 (0)