Created
July 24, 2022 10:45
-
-
Save Mr-Malomz/dafc7c738e7c477b1d9c3658650aec33 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use dotenv::dotenv; | |
| use std::{env, io::Error}; | |
| use mongodb::{ | |
| bson::{doc, oid::ObjectId}, | |
| sync::{Client, Collection, Database}, | |
| }; | |
| use crate::schemas::project_schema::{Owner, Project}; | |
| pub struct DBMongo { | |
| db: Database, | |
| } | |
| impl DBMongo { | |
| pub fn init() -> Self { | |
| dotenv().ok(); | |
| let uri = match env::var("MONGOURI") { | |
| Ok(v) => v.to_string(), | |
| Err(_) => format!("Error loading env variable"), | |
| }; | |
| let client = Client::with_uri_str(uri).unwrap(); | |
| let db = client.database("projectMngt"); | |
| DBMongo { db } | |
| } | |
| fn col_helper<T>(data_source: &Self, collection_name: &str) -> Collection<T> { | |
| data_source.db.collection(collection_name) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment