Skip to content

Commit abbca49

Browse files
committed
feat: Updated with mongokt new version
- Updated to mongokt:0.2.0-beta.11 - Added overload for `$$`(...) - Added overload for flatBy(...) - Added flatByOne(...)
1 parent 5b77f88 commit abbca49

3 files changed

Lines changed: 38 additions & 6 deletions

File tree

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kotlin = "2.2.0"
33
kotlinx-serialization = "1.8.1"
44

55
mongodb = "5.5.1"
6-
mongokt = "0.2.0-beta.10"
6+
mongokt = "0.2.0-beta.11"
77

88
[libraries]
99
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" }

module-ped-bson/src/commonMain/kotlin/BsonExtensions.kt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,22 @@ infix fun <I> BsonFieldCodec<I>.by(block: BsonDocumentCodecBlock<I>) {
8181
builder[this.name] = BsonDocument(codec, block)
8282
}
8383

84+
@BsonMarker2
85+
context(builder: BsonDocumentBuilder)
86+
infix fun <I> BsonFieldCodec<I>.flatBy(value: /* Document */I) {
87+
(value encode this).let { it as BsonDocument }.forEach { (name, value) ->
88+
builder["${this.name}.${name}"] = value
89+
}
90+
}
91+
92+
@BsonMarker2
93+
context(builder: BsonDocumentBuilder)
94+
infix fun <I> BsonFieldCodec<I>.flatBy(block: BsonDocumentCodecBlock<I>) {
95+
BsonDocument(codec, block).forEach { (name, value) ->
96+
builder["${this.name}.${name}"] = value
97+
}
98+
}
99+
84100
/* ============= ------------------ ============= */
85101

86102
@PEDMarker2
@@ -95,4 +111,20 @@ infix fun <I> BsonFieldCodec<List<I>>.byOne(block: BsonDocumentCodecBlock<I>) {
95111
builder[this.name] = BsonDocument(codec.Single, block)
96112
}
97113

114+
@PEDMarker2
115+
context(builder: BsonDocumentBuilder)
116+
infix fun <I> BsonFieldCodec<List<I>>.flatByOne(value: I) {
117+
(value encodeOne this).let { it as BsonDocument }.forEach { (name, value) ->
118+
builder["${this.name}.${name}"] = value
119+
}
120+
}
121+
122+
@PEDMarker2
123+
context(builder: BsonDocumentBuilder)
124+
infix fun <I> BsonFieldCodec<List<I>>.flatByOne(block: BsonDocumentCodecBlock<I>) {
125+
BsonDocument(codec.Single, block).forEach { (name, value) ->
126+
builder["${this.name}.${name}"] = value
127+
}
128+
}
129+
98130
/* ============= ------------------ ============= */

module-ped-mongodb/src/commonMain/kotlin/expr/Declarations.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33

44
package org.cufy.ped.expr
55

6-
import org.cufy.bson.BsonDocumentBuilder
7-
import org.cufy.bson.BsonMarker2
8-
import org.cufy.bson.bson
9-
import org.cufy.bson.by
6+
import org.cufy.bson.*
107
import org.cufy.mongodb.ExperimentalMongodbApi
118
import org.cufy.mongodb.expr.Expr
129
import org.cufy.mongodb.expr.Expr._Element
@@ -21,7 +18,10 @@ infix fun BsonFieldCodec<*>.by(expr: Expr<*>) =
2118

2219
/* ============= ------------------ ============= */
2320

24-
@BsonMarker2
21+
@BsonMarker4
2522
fun <T : _Element> `$`(path: BsonFieldCodec<*>) = Expr<T>("$${path.name}".bson)
2623

24+
@BsonMarker4
25+
fun <T : _Element> `$$`(path: BsonFieldCodec<*>) = Expr<T>("$$${path.name}".bson)
26+
2727
/* ============= ------------------ ============= */

0 commit comments

Comments
 (0)