Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/danielsolartech/nongoose
A MongoDB ODM for Rust based on Mongoose
https://github.com/danielsolartech/nongoose
mongodb odm rust rustlang
Last synced: about 1 month ago
JSON representation
A MongoDB ODM for Rust based on Mongoose
- Host: GitHub
- URL: https://github.com/danielsolartech/nongoose
- Owner: dsolartec
- License: gpl-3.0
- Created: 2021-10-17T21:49:44.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-01-08T01:49:45.000Z (almost 2 years ago)
- Last Synced: 2024-09-30T12:04:54.646Z (about 2 months ago)
- Topics: mongodb, odm, rust, rustlang
- Language: Rust
- Homepage: https://nongoose.danielsolarte.com
- Size: 1.25 MB
- Stars: 16
- Watchers: 0
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: COPYING
Awesome Lists containing this project
README
# Nongoose
![Crates.io version](https://img.shields.io/crates/v/nongoose?label=version) ![Crates.io downloads](https://img.shields.io/crates/d/nongoose?label=downloads) ![License](https://img.shields.io/github/license/dsolartec/nongoose) ![GitHub repository stars](https://img.shields.io/github/stars/dsolartec/nongoose?style=social)
ODM for MongoDB based on Mongoose and written in Rust
## Basic usage
```rust
use nongoose::{bson::oid::ObjectId, Client, Schema};
use serde::{Deserialize, Serialize};#[derive(Clone, Debug, Deserialize, Schema, Serialize)]
struct User {
#[schema(id)]
#[serde(rename = "_id")]
pub id: ObjectId,#[schema(unique)]
pub username: String,
}#[tokio::main]
async fn main() {
// Get MongoDB connection.
let client = match Client::with_uri_str("mongodb://localhost:27017").await {
Ok(client) => client,
Err(e) => panic!("Error connecting to the database: {}", e),
};// Nongoose instance.
let nongoose = nongoose::Nongoose::build(client.database("nextchat"))
.add_schema::()
.finish();let user = User {
id: ObjectId::new(),
username: String::from("nongoose"),
};if let Err(error) = user.save().await {
panic!("Cannot create the user: {}", error);
}println!("User created in the database: {}", user.id);
}
```## Tests
```sh
# Sync tests
$ DATABASE_URL=mongodb://localhost:27017 cargo test --no-default-features --features derive,sync# Async tests (Tokio runtime)
$ DATABASE_URL=mongodb://localhost:27017 cargo test
```## License
Check the [COPYING](./COPYING) file for more information.
## Related projects
- [wither](https://github.com/thedodd/wither)
- [MongODM](https://github.com/Devolutions/mongodm-rs)## Contributors
Thanks to this amazing people for make Nongoose better:
- [@dsolartec](https://github.com/dsolartec)
> If you help to Nongoose feel free to add here.