SSPkrolik / nimongo

Pure Nim lang MongoDB driver
http://sspkrolik.github.io/nimongo
MIT License
101 stars 20 forks source link

For upcoming PR #2: adding JSON methods to BSON #46

Closed JohnAD closed 6 years ago

JohnAD commented 6 years ago

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 a bsonjson.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.

JohnAD commented 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.

yglukhov commented 6 years ago

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.

JohnAD commented 6 years ago

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.