GithubHelp home page GithubHelp logo

mongorm-rs's Introduction

Logo

MongORM-RS

MongoDB ODM for Rustlang

MongORM-RS is a fast, simple, and powerful Object-Document Mapper (ODM) for MongoDB in Rust. It provides an ORM-like API to interact with MongoDB databases seamlessly.

crates.io crates.io crates.io crates.io

Features

  • ORM-like API for MongoDB in Rust
  • Fast and efficient interactions with MongoDB databases
  • Simplified alternative for simulating relationships (Many-to-One and Many-to-Many)
  • Supports selective fields with dynamic addition of elements
  • Tested on MongoDB versions 4.2, 4.4, 5.0, 6.0

Installation

Run this command at root of your project

cargo add mongorm

Or, add this to your Cargo.toml

mongorm = "0.1.0"

Basic Usage

use mongorm::prelude::*;
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize)]
pub struct Todo {
    task_id: String,
    title: String,
    is_completed: bool
}

#[tokio::main]
async fn main() -> Result<(), mongorm::errors::Error> {
    // establish connection to db
    establish_connection();

    // create a model
    let todo_model = model!(Todo);

    // perform CRUD
    
    // CREATE
    let new_todo = todo_model.create<Todo>(Todo {
        task_id: 1,
        title: "Learn Rust".to_owned(),
        is_completed: false
    });

    // READ
    let todos = todo_model.find(None); 

    // UPDATE
    let _ = todo_model.findByIdAndUpdate<Todo>("...", Todo {
        task_id: 1,
        title: "Learn MONGODB".to_owned(),
        is_completed: false
    });

    // DELETE
    let _ = todo_model.findByIdAndDelete<Todo>("...");
}

Changelog

View the change history.

License

This project is licensed under the MIT and Apache Version 2.0

mongorm-rs's People

Contributors

vilayat-ali avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.