Implement some more of the bson types

This commit is contained in:
Patrick Meredith 2019-08-24 19:58:32 -04:00
parent 9814eeae30
commit 722e192c14

View File

@ -46,20 +46,40 @@ fn convert_bson_value_to_nu_value(v: &Bson, tag: impl Into<Tag>) -> Tagged<Value
} }
Bson::Boolean(b) => Value::Primitive(Primitive::Boolean(*b)).tagged(tag), Bson::Boolean(b) => Value::Primitive(Primitive::Boolean(*b)).tagged(tag),
Bson::Null => Value::Primitive(Primitive::String(String::from(""))).tagged(tag), Bson::Null => Value::Primitive(Primitive::String(String::from(""))).tagged(tag),
// Bson::RegExp(r, opts) => { Bson::RegExp(r, opts) => {
// let mut collected = TaggedDictBuilder::new(tag); let mut collected = TaggedDictBuilder::new(tag);
// collected.insert_tagged( collected.insert_tagged(
// "$regex".to_owned(), "$regex".to_string(),
// Value::Primitive(Primitive::String(String::from(r))), Value::Primitive(Primitive::String(String::from(r))).tagged(tag),
// ); );
// collected.insert_tagged( collected.insert_tagged(
// "$options".to_owned(), "$options".to_string(),
// Value::Primitive(Primitive::String(String::from(opts))), Value::Primitive(Primitive::String(String::from(opts))).tagged(tag),
// ); );
// collected.into_tagged_value() collected.into_tagged_value()
// } }
Bson::I32(n) => Value::Primitive(Primitive::Int(*n as i64)).tagged(tag), Bson::I32(n) => Value::Primitive(Primitive::Int(*n as i64)).tagged(tag),
Bson::I64(n) => Value::Primitive(Primitive::Int(*n as i64)).tagged(tag), Bson::I64(n) => Value::Primitive(Primitive::Int(*n as i64)).tagged(tag),
Bson::JavaScriptCode(js) => {
let mut collected = TaggedDictBuilder::new(tag);
collected.insert_tagged(
"$javascript".to_string(),
Value::Primitive(Primitive::String(String::from(js))).tagged(tag),
);
collected.into_tagged_value()
}
Bson::JavaScriptCodeWithScope(js, doc) => {
let mut collected = TaggedDictBuilder::new(tag);
collected.insert_tagged(
"$javascript".to_string(),
Value::Primitive(Primitive::String(String::from(js))).tagged(tag),
);
collected.insert_tagged(
"$scope".to_string(),
convert_bson_value_to_nu_value(&Bson::Document(doc.to_owned()), tag),
);
collected.into_tagged_value()
}
Bson::ObjectId(obj_id) => Value::Primitive(Primitive::String(obj_id.to_hex())).tagged(tag), Bson::ObjectId(obj_id) => Value::Primitive(Primitive::String(obj_id.to_hex())).tagged(tag),
x => { x => {
println!("{:?}", x); println!("{:?}", x);