mongodb :: BSON :: defaultinit
json
.
mongodb :: BSON :: from_json_string
Returns a new BSON object parsed fromjson_string
.
mongodb $ BSON :: finalize_once
Real finalization method ofFinalizableOnce
, will be called only once
core :: FinalizableOnce :: _finalized
Hasself
been finalized? (either by the GC or an explicit call to finalize
)
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
mongodb :: BSON :: defaultinit
core :: FinalizableOnce :: defaultinit
core :: Object :: defaultinit
core :: Finalizable :: defaultinit
core :: Finalizable :: finalize
Liberate any resources held byself
before the memory holding self
is freed
core :: FinalizableOnce :: finalize_once
Real finalization method ofFinalizableOnce
, will be called only once
core :: FinalizableOnce :: finalized
Hasself
been finalized? (either by the GC or an explicit call to finalize
)
core :: FinalizableOnce :: finalized=
Hasself
been finalized? (either by the GC or an explicit call to finalize
)
json
.
mongodb :: BSON :: from_json_string
Returns a new BSON object parsed fromjson_string
.
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Object :: native_class_name
The class name of the object in CString format.core :: Object :: output_class_name
Display class name on stdout (debug only).
# Everything inside MongoDB is manipulated as BSON Objects.
#
# See:
# * [Binary JSON spec](http://bsonspec.org/)
# * [Libbson](http://api.mongodb.org/libbson/1.1.4/)#
private class BSON
super FinalizableOnce
# Native instance pointer.
var native: NativeBSON
# Returns a new BSON object initialized from the content of `json`.
#
# ~~~
# intrude import mongodb
# var obj = new JsonObject
# obj["age"] = 10
# obj["name"] = "Rick"
# obj["ELS"] = new JsonArray
# var bson = new BSON.from_json(obj)
# assert bson.to_s == """{ "age" : 10, "name" : "Rick", "ELS" : [ ] }"""
# ~~~
init from_json(json: JsonObject) do
init(new NativeBSON.from_json_string(json.to_json.to_cstring))
end
# Returns a new BSON object parsed from `json_string`.
#
# If `json_string` is not a valid JSON string, this initializer returns NULL.
#
# ~~~
# intrude import mongodb
# var str = """{ "age" : 10, "name" : "Rick", "ELS" : [ ] }"""
# var bson = new BSON.from_json_string(str)
# assert bson.to_s == str
# ~~~
init from_json_string(json_string: String) do
init(new NativeBSON.from_json_string(json_string.to_cstring))
end
redef fun to_s do
var ns = native.to_c_string
var res = ns.to_s
ns.free # manual free of gc allocated CString
return res
end
# Returns a new JsonObject from `self`.
#
# ~~~
# intrude import mongodb
# var str = """{ "age" : 10, "name" : "Rick", "ELS" : [ ] }"""
# var bson = new BSON.from_json_string(str)
# var json = bson.to_json
# assert json["age"] == 10
# assert json["name"] == "Rick"
# assert json["ELS"].as(JsonArray).is_empty
# ~~~
fun to_json: JsonObject do
var json = to_s.parse_json
if json isa JsonParseError then
print json.message
sys.exit 1
end
return json.as(JsonObject)
end
redef fun finalize_once do native.destroy
end
lib/mongodb/mongodb.nit:58,1--126,3