Closed JohnAD closed 6 years ago
I should note that the conversion might not ever be perfect; as BSON supports far more fields. They key will be to document the conversion process well and stick to the ad-hoc conventions seen in other libraries.
I think json-bson conversions are better as a separate lib, at least at this point. The functionality is far from what I would expect from a db driver.
Okay, when I get a chance, I'll create a separate library that depends on nimongo
for the embedded bson library. There was a recent discussion on the forum about that very subject.
As to db driver role, I generally agree. In fact, one could say that bson
itself should be a separate library. While MongoDB is dependent on that serialization, it is not actually part of the database. It is a stand-alone spec that other software, including non-database software, could use.
Though, in practice, I don't know of any outside usage of BSON. Just for fun, I looked around. Nothing uses it AFAIK.
Using BSON is, of course, an absolute requirement of MongoDB library.
However, when using this library with other libraries, such as HTML generators and/or other databases, it would be helpful if they had a common ground to aid in conversion. Since the
json
library is part of Nim's standard library so it could act like a "lingua franca" for documents.To that end, I'd like to create a PR where I add support for importing and exporting JSON to BSON. Perhaps:
proc toBson(j: JsonNode): Bson
and
proc toJson(b: Bson): JsonNode
I could either add this to the
bson.nim
file. Or, perhaps, creating absonjson.nim
to keep the extra code isolated. I'd be okay with either one.PR #45 is more important to me, so I don't know how long it will take for me to get to this.