-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to official mongo driver (#351)
* Switch to the Official MongoDB Driver. Needs testing * Some fixes, still broken though * Switch to kordex mongodb data adapter * Update kordex to fix mongo bug * Fix meta breaking the whole thing * Use a constant to determine the collection name * Revert "Use a constant to determine the collection name" This reverts commit f61306c. * Use a constant to determine the collection name but do it better * Simplify filtering in cleanup * Update the README.md
- Loading branch information
1 parent
ee7a972
commit 8557d4f
Showing
60 changed files
with
389 additions
and
368 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
22 changes: 22 additions & 0 deletions
22
src/main/kotlin/org/hyacinthbots/lilybot/database/Collection.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.hyacinthbots.lilybot.database | ||
|
||
/** | ||
* This class stores the name of a collection, so it can be referenced easily, avoiding string duplication | ||
* | ||
* An example of how it should be used can be found below. The name property used in the get collection line comes from | ||
* this class | ||
* ```kt | ||
* class MagicCollection : KordExKoinComponent { | ||
* private val db: Database by inject() | ||
* | ||
* val collection = db.mainDatabase.getCollection<MagicCollectionData>(name) | ||
* | ||
* suspend fun get(): List<MagicCollectionData> = collection.find().toList() | ||
* | ||
* companion object : Collection("magicCollection") | ||
* } | ||
* ``` | ||
* | ||
* @property name The name of the collection | ||
*/ | ||
abstract class Collection(val name: String) |
15 changes: 12 additions & 3 deletions
15
src/main/kotlin/org/hyacinthbots/lilybot/database/Database.kt
This file contains 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
18 changes: 18 additions & 0 deletions
18
src/main/kotlin/org/hyacinthbots/lilybot/database/_DatabaseUtils.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.hyacinthbots.lilybot.database | ||
|
||
import com.mongodb.client.model.Filters | ||
import com.mongodb.client.model.Filters.and | ||
import com.mongodb.kotlin.client.coroutine.FindFlow | ||
import com.mongodb.kotlin.client.coroutine.MongoCollection | ||
import kotlinx.coroutines.flow.firstOrNull | ||
import org.bson.conversions.Bson | ||
|
||
private fun <T : Any> MongoCollection<T>.find(vararg filters: Bson?): FindFlow<T> = find(and(*filters)) | ||
|
||
suspend fun <T : Any> MongoCollection<T>.findOne(filter: Bson): T? = find(filter).firstOrNull() | ||
|
||
suspend fun <T : Any> MongoCollection<T>.findOne(vararg filters: Bson?): T? = find(*filters).firstOrNull() | ||
|
||
suspend fun <T : Any> MongoCollection<T>.deleteOne() = deleteOne(Filters.empty()) | ||
|
||
// TODO Make more cool useful functions |
This file contains 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
This file contains 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
Oops, something went wrong.