Skip to content

Commit 968f79f

Browse files
committed
feat: added flatBy(...) for BsonDocumentBuilder
1 parent f4d30a5 commit 968f79f

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

module-bsonkt/src/commonMain/kotlin/BsonDocumentLike.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,23 @@ infix fun String.by(block: BsonDocumentBlock) {
254254
builder[this] = BsonDocument(block)
255255
}
256256

257+
@BsonMarker2
258+
context(builder: BsonDocumentBuilder)
259+
infix fun String.flatBy(value: BsonDocumentLike?) {
260+
value ?: return run { builder[this] = null.bson }
261+
value.forEach { (name, value) ->
262+
builder["${this}.${name}"] = value
263+
}
264+
}
265+
266+
@BsonMarker2
267+
context(builder: BsonDocumentBuilder)
268+
infix fun String.flatBy(block: BsonDocumentBlock) {
269+
BsonDocument(block).forEach { (name, value) ->
270+
builder["${this}.${name}"] = value
271+
}
272+
}
273+
257274
/* ============= ------------------ ============= */
258275

259276
/**

0 commit comments

Comments
 (0)