@@ -243,11 +243,48 @@ extension Document: ExpressibleByDictionaryLiteral {
243243}
244244
245245extension Dictionary : BSONPrimitiveRepresentable , Primitive where Key == String , Value: Primitive {
246+ public var document : Document {
247+ var document = Document ( isArray: false )
248+ for (key, value) in self {
249+ document [ key] = value
250+ }
251+ return document
252+ }
253+
246254 public var primitive : Primitive {
255+ return document
256+ }
257+ }
258+
259+ extension Dictionary where Key == String , Value == Primitive {
260+ public var document : Document {
247261 var document = Document ( isArray: false )
248262 for (key, value) in self {
249263 document [ key] = value
250264 }
251265 return document
252266 }
253267}
268+
269+ extension Document {
270+ public init ( dictionary: [ String : Primitive ] ) {
271+ self . init ( isArray: false )
272+ for (key, value) in dictionary {
273+ self . appendValue ( value, forKey: key)
274+ }
275+ }
276+
277+ public init < Value> ( dictionary: [ String : Value ] ) throws where Value: Primitive {
278+ self . init ( isArray: false )
279+ for (key, value) in dictionary {
280+ self . appendValue ( try value. encodePrimitive ( ) , forKey: key)
281+ }
282+ }
283+
284+ public init < Value> ( dictionary: [ String : Value ] ) throws where Value: PrimitiveEncodable {
285+ self . init ( isArray: false )
286+ for (key, value) in dictionary {
287+ self . appendValue ( try value. encodePrimitive ( ) , forKey: key)
288+ }
289+ }
290+ }
0 commit comments