thedodd / wither

An ODM for MongoDB built on the official MongoDB Rust driver.
https://docs.rs/wither
Other
324 stars 40 forks source link

Using basic example #81

Open somehowchris opened 3 years ago

somehowchris commented 3 years ago

Hey man,

I love the effort and the crate, but I seem to have a bit of trouble getting the basic things running.

I started using it with rocket the web framework since it will support tokio with 0.5.0, but the find method seems to run into a few compile issues.

error[E0599]: no method named `next` found for struct `ModelCursor<UserEntity>` in the current scope
  --> src/users/service.rs:20:25
   |
20 |   print!("{:?}", cursor.next().await);
   |                         ^^^^ method not found in `ModelCursor<UserEntity>`

To my knowledge, this is basically the same as your basic example, but it should just output the first one (if there is any).

This is the code I call before.

let mut cursor: ModelCursor<UserEntity> = UserEntity::find(db_connection, None, None).await.unwrap();

I have defined the model as followed

#[derive(Debug, Model, Serialize, Deserialize)]
#[serde(rename_all(serialize = "camelCase", deserialize = "snake_case"))]
#[model(index(keys=r#"doc!{"name": 1}"#, options=r#"doc!{"unique": true}"#))]
pub struct UserEntity {
  #[serde(rename="_id", skip_serializing_if="Option::is_none")]
  pub id: Option<ObjectId>,
  pub name: String
}

Am I missing something out? I have also tried to run your exact example, but that neither worked

dariusc93 commented 3 years ago

I assume you figured it out but if not you would need futures::StreamExt.

thedodd commented 3 years ago

Hey, thanks for the follow-up! I apologize about the complete lack of response. And yes, that is correct. The basic example in the readme is compiled and tested. Maybe you forgot to include the StreamExt trait during copy/paste?

somehowchris commented 3 years ago

@thedodd Any chance of updating Tokio? Would be nice since rocket can handle Async things now

thedodd commented 3 years ago

@somehowchris hey, that's a good idea. Will do.

somehowchris commented 3 years ago

@thedodd ever considered (or will you consider) to get synk, depenadabot or renovate? To get dependency updates and for security reasons

thedodd commented 3 years ago

Definitely, though in this case it wouldn't make any difference. The only reason I haven't already done so is due to time constraints, not because I was unaware of the Tokio updates and such :).

Wither was one of my first open source Rust projects ... and I personally do not use it much any more, only because I don't use MongoDB much anymore. So I definitely rely upon the community for update requests and the like.

I would love to have someone else actively using the project to join as a co-maintainer, which would be a boon to everyone involved.

thedodd commented 3 years ago

@somehowchris as it turns out, we are blocked on upgrading to Tokio 1.0 until the underlying MongoDB crate updates. Wither is just a lightweight dependency on top of the mongodb crate, so we do not actually specify any runtime deps in this crate.

patrickfreed commented 3 years ago

Note that mongodb has support for tokio 1.0 starting in 2.0.0-alpha (which is basically just the 1.x driver with tokio 1.0 support). Later 2.0 pre-releases (2.0.0-beta.3 being the most recent) also support tokio 1.0 along with a lot of new features and breaking changes. So if you're okay with depending on a pre-release, you don't need to wait any longer. For what it's worth, 2.0.0-beta.3 will be very similar to the actual 2.0.0 release and there shouldn't be any major breaking changes between the two of them.

simoneromano96 commented 2 years ago

Definitely, though in this case it wouldn't make any difference. The only reason I haven't already done so is due to time constraints, not because I was unaware of the Tokio updates and such :).

Wither was one of my first open source Rust projects ... and I personally do not use it much any more, only because I don't use MongoDB much anymore. So I definitely rely upon the community for update requests and the like.

I would love to have someone else actively using the project to join as a co-maintainer, which would be a boon to everyone involved.

Hi, could you consider me as a co-mantainer? I work fulltime but in my spare time I'd like to keep this project alive, I believe it is one of the best Rust database projects!

thedodd commented 2 years ago

@simoneromano96 I definitely need to get some other folks involved in keeping this project alive. I'll send you an invite!

simoneromano96 commented 2 years ago

@thedodd Any chance of updating Tokio? Would be nice since rocket can handle Async things now

Hi, I would create a feature in wither to use the mongo client beta, WDYT?