Skip to content

Commit

Permalink
feat: update to mongo 3.1, add member generator.
Browse files Browse the repository at this point in the history
  • Loading branch information
IAmTomahawkx committed Dec 7, 2024
1 parent 59aadfd commit a558adb
Show file tree
Hide file tree
Showing 25 changed files with 896 additions and 978 deletions.
445 changes: 230 additions & 215 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ members = [
[patch.crates-io]
redis22 = { package = "redis", version = "0.22.3", git = "https://github.com/revoltchat/redis-rs", rev = "1a41faf356fd21aebba71cea7eb7eb2653e5f0ef" }
redis23 = { package = "redis", version = "0.23.1", git = "https://github.com/revoltchat/redis-rs", rev = "f8ca28ab85da59d2ccde526b4d2fb390eff5a5f9" }
authifier = { package = "authifier", version = "1.0.10", path = "../authifier/crates/authifier" }
rocked_authifier = { package = "rocket_authifier", version = "1.0.10", path = "../authifier/crates/rocket_authifier" }
2 changes: 1 addition & 1 deletion crates/bonfire/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async-std = { version = "1.8.0", features = [
] }

# core
authifier = { version = "1.0.9" }
authifier = { version = "1.0.10" }
revolt-result = { path = "../core/result" }
revolt-models = { path = "../core/models" }
revolt-config = { path = "../core/config" }
Expand Down
4 changes: 2 additions & 2 deletions crates/core/database/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ redis-kiss = { version = "0.1.4" }

# Database
bson = { optional = true, version = "2.1.0" }
mongodb = { optional = true, version = "2.1.0", default-features = false }
mongodb = { optional = true, version = "3.1.0" }

# Database Migration
unicode-segmentation = "1.10.1"
Expand Down Expand Up @@ -96,7 +96,7 @@ web-push = "0.10.0"
revolt_a2 = { version = "0.10", default-features = false, features = ["ring"] }

# Authifier
authifier = { version = "1.0.9", features = ["rocket_impl"] }
authifier = { version = "1.0.10", features = ["rocket_impl"] }

# RabbitMQ
amqprs = { version = "1.7.0" }
18 changes: 10 additions & 8 deletions crates/core/database/src/drivers/mongodb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ impl MongoDb {
}

/// Get a collection by its name
pub fn col<T>(&self, collection: &str) -> mongodb::Collection<T> {
pub fn col<T: Send + Sync>(&self, collection: &str) -> mongodb::Collection<T> {
self.db().collection(collection)
}

/// Insert one document into a collection
pub async fn insert_one<T: Serialize>(
pub async fn insert_one<T: Serialize + Send + Sync>(
&self,
collection: &'static str,
document: T,
) -> Result<InsertOneResult> {
self.col::<T>(collection).insert_one(document, None).await
self.col::<T>(collection).insert_one(document).await
}

/// Count documents by projection
Expand All @@ -51,7 +51,7 @@ impl MongoDb {
projection: Document,
) -> Result<u64> {
self.col::<Document>(collection)
.count_documents(projection, None)
.count_documents(projection)
.await
}

Expand All @@ -67,7 +67,8 @@ impl MongoDb {
{
Ok(self
.col::<T>(collection)
.find(projection, options)
.find(projection)
.with_options(options)
.await?
.filter_map(|s| async {
if cfg!(debug_assertions) {
Expand Down Expand Up @@ -101,7 +102,8 @@ impl MongoDb {
O: Into<Option<FindOneOptions>>,
{
self.col::<T>(collection)
.find_one(projection, options)
.find_one(projection)
.with_options(options)
.await
}

Expand Down Expand Up @@ -165,7 +167,7 @@ impl MongoDb {
};

self.col::<Document>(collection)
.update_one(projection, query, None)
.update_one(projection, query)
.await
}

Expand Down Expand Up @@ -200,7 +202,7 @@ impl MongoDb {
projection: Document,
) -> Result<DeleteResult> {
self.col::<Document>(collection)
.delete_one(projection, None)
.delete_one(projection)
.await
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ impl AbstractMigrations for MongoDb {
#[cfg(test)]
/// Drop the database
async fn drop_database(&self) {
self.db().drop(None).await.ok();
self.db().drop().await.ok();
}

/// Migrate the database
async fn migrate_database(&self) -> Result<(), ()> {
info!("Migrating the database.");

let list = self
.list_database_names(None, None)
.list_database_names()
.await
.expect("Failed to fetch database names.");

Expand Down
Loading

0 comments on commit a558adb

Please sign in to comment.