gluesql_mongo_storage/
lib.rs

1mod description;
2pub mod error;
3pub mod row;
4mod store;
5mod store_mut;
6pub mod utils;
7
8use {
9    error::ResultExt,
10    gluesql_core::{
11        error::Result,
12        store::{
13            AlterTable, CustomFunction, CustomFunctionMut, Index, IndexMut, Metadata, Transaction,
14        },
15    },
16    mongodb::{Client, Database, options::ClientOptions},
17};
18
19pub struct MongoStorage {
20    pub db: Database,
21}
22
23impl MongoStorage {
24    pub async fn new(conn_str: &str, db_name: &str) -> Result<Self> {
25        let client_options = ClientOptions::parse(conn_str).await.map_storage_err()?;
26        let client = Client::with_options(client_options).map_storage_err()?;
27        let db = client.database(db_name);
28
29        Ok(Self { db })
30    }
31
32    pub async fn drop_database(&self) -> Result<()> {
33        self.db.drop(None).await.map_storage_err()
34    }
35}
36
37impl Metadata for MongoStorage {}
38impl AlterTable for MongoStorage {}
39impl CustomFunction for MongoStorage {}
40impl CustomFunctionMut for MongoStorage {}
41impl Index for MongoStorage {}
42impl IndexMut for MongoStorage {}
43impl Transaction for MongoStorage {}