-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
38 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,51 @@ | ||
bson2v8 | ||
======= | ||
|
||
deps: [mongodb-c-driver](https://github.com/mongodb/mongo-c-driver) | ||
deps: | ||
* [mongodb-c-driver](https://github.com/mongodb/mongo-c-driver) | ||
* [v8](https://github.com/v8/v8) | ||
|
||
purposes: | ||
|
||
* Convert a `v8::Handle<v8::Value>` variable to a `bson*` type. | ||
* Convert a `bson*` or `char*` means the buffer data of a `bson*` variable to a `v8::Local<v8::Value>`. | ||
|
||
Convert from a bson to the v8 object, This project will help u to use mongodb better. | ||
|
||
## API: | ||
|
||
`ParseBSON(const char* buffer)` provide u can pass a bson raw data. | ||
|
||
`ParseBSON(const bson* buffer)` provide u can pass a bson object. | ||
|
||
`ToBSON(Local<Value> in, bson* out)` provide u can pass 1 in v8::Value and out a bson* pointer. | ||
|
||
### Usage: | ||
|
||
#### create a bson from `v8::Local<v8::Value>` | ||
```c | ||
Handle<Value> create_bson(const Arguments& args) { | ||
// create a bson | ||
bson* b = bson_alloc(); | ||
Utilities::ToBSON(args[0], result); | ||
|
||
// now u can print the bson result | ||
bson_print(b); | ||
// the end, remember destroy this bson heap | ||
bson_destroy(b); | ||
} | ||
``` | ||
#### get a `v8::Local<v8::Object>` from a bson in [mongo-c-driver](https://github.com/mongodb/mongo-c-driver) | ||
```c | ||
Local<Object> return_v8_value(const char* buffer) { | ||
// so easy, right? | ||
return Utilities::ParseBSON(buffer); | ||
} | ||
``` | ||
|
||
|
||
|
||
|
||
## LICENSE | ||
|
||
MIT | ||
MIT, I'm so gald for this could help u :) |