-
-
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.
* Revert "Revert "Switch to official mongo driver (#351)"" This reverts commit d76bc5c. * Revert "Revert "Fix getting some elements from the database"" This reverts commit 2b0e6f7. * Remove unneeded database reference
- Loading branch information
1 parent
67ed6db
commit 183f4d5
Showing
60 changed files
with
389 additions
and
370 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) |
13 changes: 10 additions & 3 deletions
13
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.