#
# * `"nodes"`: An array with all nodes. Each node is an object with the
# following properties:
-# * `"labels"`: An array of all applied labels.
-# * `"properties"`: An object mapping each defined property to its value.
+# * `"labels"`: An array of all applied labels.
+# * `"properties"`: An object mapping each defined property to its value.
# * `"edges"`: An array with all relationships. Each relationship is an object
# with the following properties:
-# * `"type"`: The type (`String`) of the relationship.
-# * `"properties"`: An object mapping each defined property to its value.
-# * `"from"`: The local ID of the source node.
-# * `"to"`: The local ID of the destination node.
+# * `"type"`: The type (`String`) of the relationship.
+# * `"properties"`: An object mapping each defined property to its value.
+# * `"from"`: The local ID of the source node.
+# * `"to"`: The local ID of the destination node.
#
# ~~~nit
# import neo4j::graph::sequential_id
# a.labels.add "Foo"
# a["answer"] = 42
# a["Ultimate question of"] = new JsonArray.from(["life",
-# "the Universe", "and Everything."])
+# "the Universe", "and Everything."])
# graph.nodes.register a
# var b = graph.create_node
# b.labels.add "Foo"
# b.labels.add "Bar"
# graph.edges.add new NeoEdge(a, "BAZ", b)
#
-# var ostream = new StringOStream
+# var ostream = new StringWriter
# var store = new JsonGraphStore(graph)
# store.ostream = ostream
# store.save
#
# graph.nodes.clear
# graph.edges.clear
-# store.istream = new StringIStream(ostream.to_s)
+# store.istream = new StringReader(ostream.to_s)
# store.load
# assert 1 == graph.edges.length
# for edge in graph.edges do
-# assert "BAZ" == edge.rel_type
-# assert a.labels == edge.from.labels
-# for k, v in a.properties do assert v == edge.from.properties[k]
-# assert b.labels == edge.to.labels
-# for k, v in b.properties do assert v == edge.to.properties[k]
+# assert "BAZ" == edge.rel_type
+# assert a.labels == edge.from.labels
+# for k, v in a.properties do assert v == edge.from.properties[k]
+# assert b.labels == edge.to.labels
+# for k, v in b.properties do assert v == edge.to.properties[k]
# end
# assert 2 == graph.nodes.length
# ~~~
super GraphStore
# The stream to use for `load`.
- var istream: nullable IStream = null is writable
+ var istream: nullable Reader = null is writable
# The stream to use for `save` and `save_part`.
- var ostream: nullable OStream = null is writable
+ var ostream: nullable Writer = null is writable
- # Use the specified `IOStream`.
- init from_io(graph: NeoGraph, iostream: IOStream) do
+ # Use the specified `Duplex`.
+ init from_io(graph: NeoGraph, iostream: Duplex) do
init(graph)
istream = iostream
ostream = iostream
# Use the specified string to load the graph.
init from_string(graph: NeoGraph, string: String) do
init(graph)
- istream = new StringIStream(string)
+ istream = new StringReader(string)
end
redef fun isolated_save do return true
redef fun load do
var istream = self.istream
- assert istream isa IStream
+ assert istream isa Reader
fire_started
graph.load_json(istream.read_all)
fire_done
redef fun save_part(nodes, edges) do
var ostream = self.ostream
- assert ostream isa OStream
+ assert ostream isa Writer
fire_started
ostream.write(graph.to_json)
fire_done
# a.labels.add "Foo"
# a["answer"] = 42
# a["Ultimate question of"] = new JsonArray.from(["life",
- # "the Universe", "and Everything."])
+ # "the Universe", "and Everything."])
# graph.nodes.register a
# var b = graph.create_node
# b.labels.add "Foo"
# graph.edges.add new NeoEdge(a, "BAZ", b)
#
# graph = new NeoGraph.from_json(
- # new SequentialNodeCollection("node_id"), graph.to_json)
+ # new SequentialNodeCollection("node_id"), graph.to_json)
# assert 1 == graph.edges.length
# for edge in graph.edges do
- # assert "BAZ" == edge.rel_type
- # assert a.labels == edge.from.labels
- # for k, v in a.properties do assert v == edge.from.properties[k]
- # assert b.labels == edge.to.labels
- # for k, v in b.properties do assert v == edge.to.properties[k]
+ # assert "BAZ" == edge.rel_type
+ # assert a.labels == edge.from.labels
+ # for k, v in a.properties do assert v == edge.from.properties[k]
+ # assert b.labels == edge.to.labels
+ # for k, v in b.properties do assert v == edge.to.properties[k]
# end
# assert 2 == graph.nodes.length
# ~~~
# For the expected format, see `JsonGraphStore`.
fun load_json_object(o: JsonObject) do
var json_nodes = o["nodes"].as(JsonArray)
+ var nodes = self.nodes
+ nodes.enlarge(nodes.length)
for json_node in json_nodes do
assert json_node isa JsonObject
var node = new NeoNode.from_json_object(json_node)
end
var json_edges = o["edges"].as(JsonArray)
+ var edges = self.edges
+ if edges isa AbstractArray[NeoEdge] then edges.enlarge(edges.length)
for json_edge in json_edges do
assert json_edge isa JsonObject
var from = nodes[nodes.id_from_jsonable(json_edge["from"])]
var rel_type = json_edge["type"].as(String)
var json_properties = json_edge["properties"].as(JsonObject)
var edge = new NeoEdge(from, rel_type, to)
- edge.properties.recover_with(json_properties)
+ edge.properties.add_all(json_properties)
edges.add edge
end
end
#
# var node = new NeoNode.from_json("""
# {
- # "labels": ["foo", "Bar"],
- # "properties": {
- # "baz": 42
- # }
+ # "labels": ["foo", "Bar"],
+ # "properties": {
+ # "baz": 42
+ # }
# }
# """)
# assert ["foo", "Bar"] == node.labels
var labels = o["labels"].as(JsonArray)
for lab in labels do self.labels.add(lab.as(String))
var json_properties = o["properties"].as(JsonObject)
- properties.recover_with(json_properties)
+ properties.add_all(json_properties)
end
redef fun to_json do return to_json_by_append
redef fun to_s do return to_json
# Append the JSON representation of the node to the specified buffer.
- redef fun append_json_for(graph: NeoGraph, buffer: Buffer) do
+ redef fun append_json_for(graph, buffer) do
append_json(buffer)
end
end
# Append the JSON representation of the relationship to the specified buffer.
#
# Use the IDs specfied by `graph.nodes`.
- redef fun append_json_for(graph: NeoGraph, buffer: Buffer) do
+ redef fun append_json_for(graph, buffer) do
buffer.append "\{\"type\":"
- rel_type.append_json(buffer)
+ rel_type.as(not null).append_json(buffer)
buffer.append ",\"properties\":"
properties.append_json(buffer)
buffer.append ",\"from\":"