Skip to content

Commit f065171

Browse files
authored
Merge pull request #26 from thedodd/20-update-should-take-filter-doc
Closes #20. The Model.update method has been updated a decent bit. It now takes an optional filter doc & returns Result<Option<Self>>. See the changelog and #20 for more details.
2 parents 3a431e8 + 9630967 commit f065171

File tree

9 files changed

+108
-58
lines changed

9 files changed

+108
-58
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
changelog
22
=========
33

4+
## 0.7
5+
Minimal changes per this release. The main issue being addressed here is [#20](https://github.com/thedodd/wither/issues/20). It is arguable that this is just a bug fix, but the interface for `Model.update` has changed enough with these updates that a minor version increment is merited.
6+
7+
The main thing to observe here is that `Model.update` now takes an optional filter document. If none is given, then this method will create a filter doc and populate it with the model's ID. If a doc is given, then it will have the `_id` key set (potentially overwritten) to the model's ID. Lastly, this method now returns `Result<Option<Self>>` to reflect the fallible nature of the update with a filter.
8+
49
## 0.6
510
Wow! So much stuff here. `0.6` is a big step forward for the ergonomics & usability of the wither system. A custom derive has been introduced (`#[derive(Model)]`), and it is now the recommended way to use this system. This should greatly simplify the process of getting started. Overall this has been an awesome experience putting this together and delving into the custom derive system in Rust. Here are a few of the changes to highlight.
611
- Use `#[derive(Model)]` to turn your struct into a wither `Model`.

CONTRIBUTING.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,12 @@ For the compile tests, you will need to use nightly.
3737

3838
```bash
3939
# Run the compile tests.
40-
cargo +nightly test -p wither_derive --tests --lib
40+
cargo +nightly test -p wither_tests -p wither_derive --tests --lib
41+
```
42+
43+
For doc tests, you will also need to use nightly.
44+
45+
```bash
46+
# From the wither dir.
47+
cargo +nightly test --features docinclude --doc
4148
```

Cargo.lock

Lines changed: 29 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn main() {
6262
me.save(db.clone(), None);
6363

6464
// Update user's email address.
65-
me = me.update(db.clone(), doc!{"$set": doc!{"email": "[email protected]"}}, None).unwrap();
65+
me.update(db.clone(), None, doc!{"$set": doc!{"email": "[email protected]"}}, None).unwrap();
6666

6767
// Fetch all users.
6868
let all_users = User::find(db.clone(), None, None).unwrap();

wither/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ license = "Apache-2.0"
99
name = "wither"
1010
readme = "../README.md"
1111
repository = "https://github.com/thedodd/wither"
12-
version = "0.6.3"
12+
version = "0.7.0"
1313

1414
[dependencies]
1515
chrono = "0.4"
@@ -20,7 +20,7 @@ serde_derive = "1"
2020

2121
[dev-dependencies]
2222
lazy_static = "1"
23-
wither_derive = { version = "0.6", path = "../wither_derive" }
23+
wither_derive = { version = "0.7", path = "../wither_derive" }
2424

2525
[features]
2626
docinclude = [] # Used only for activating `doc(include="...")` on nightly.

wither/docs/model-derive.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ All `Model` struct & field attributes are declared inside of `model(...)` attrib
66
Deriving `Model` for your struct is straightforward.
77

88
- Ensure that your struct has at least the following derivations: `#[derive(Model, Serialize, Deserialize)]`.
9-
- Ensure that you have a field named `id`, of type `Option<bson::oid::ObjectId>`, with the following serde attributes: `#[serde(rename="_id", skip_serializing_if="Option::is_none")]`.
9+
- Ensure that you have a field named `id`, of type `Option<ObjectId>`, with the following serde attributes: `#[serde(rename="_id", skip_serializing_if="Option::is_none")]`.
1010

1111
For now, it seems logical to disallow customization of the PK. An argument could be made for allowing full customization of the PK for a MongoDB collection, but there really is no end-all reasoning for this argument which I am aware of. If you need to treat a different field as PK, then just add the needed index to the field, and you are good to go. More on indexing soon.
1212

@@ -67,7 +67,7 @@ As you can see, everything is declared within `#[model(index(...))]` attributes.
6767
##### index
6868
Everything related to an index declaration must be declared within these parens. If the field is using a serde `rename` attribute, this system will account for that and use the value of `rename` as the initial field name for the new index.
6969

70-
##### type
70+
##### index_type
7171
This declares the type of index for the field which this attribute appears on, which will also be the first field of the generated index. The value must be one of the valid MongoDB index types: `"asc"`, `"dsc"`, `"2d"`, `"2dsphere"`, `"geoHaystack"`, `"text"` & `"hashed"`.
7272

7373
##### with

0 commit comments

Comments
 (0)