@@ -18,6 +18,7 @@ package org.cufy.monkt
1818import com.mongodb.ClientSessionOptions
1919import com.mongodb.connection.ClusterDescription
2020import com.mongodb.connection.ClusterSettings
21+ import com.mongodb.reactivestreams.client.MongoClients
2122import com.mongodb.reactivestreams.client.ChangeStreamPublisher
2223import com.mongodb.reactivestreams.client.ClientSession
2324import com.mongodb.reactivestreams.client.ListDatabasesPublisher
@@ -27,6 +28,32 @@ import org.cufy.bson.BsonDocument
2728import org.reactivestreams.Publisher
2829import java.io.Closeable
2930
31+ /* *
32+ * Create a new client with the given connection string.
33+ *
34+ * @param connectionString the connection.
35+ * @return the client.
36+ * @since 2.0.0
37+ * @see MongoClients.create
38+ */
39+ fun createMonktClient (connectionString : String ): MonktClient {
40+ val client = MongoClients .create(connectionString)
41+ return MonktClient (client)
42+ }
43+
44+ /* *
45+ * Create a new [MonktClient] instance wrapping
46+ * the given [client] instance.
47+ *
48+ * @param client the client to be wrapped.
49+ * @since 2.0.0
50+ */
51+ fun MonktClient (client : MongoClient ): MonktClient {
52+ return object : MonktClient {
53+ override val client = client
54+ }
55+ }
56+
3057/* *
3158 * A generic-free coroutine dependant wrapper for
3259 * [MongoClient]s
@@ -36,12 +63,14 @@ import java.io.Closeable
3663 * @author LSafer
3764 * @since 2.0.0
3865 */
39- open class MonktClient (
66+ interface MonktClient : Closeable {
4067 /* *
4168 * The wrapped client.
4269 */
4370 val client: MongoClient
44- ) : Closeable by client {
71+
72+ override fun close () = client.close()
73+
4574 /* *
4675 * Gets the current cluster description.
4776 *
0 commit comments