loadEdges<T> method
Loads all edges originating from a specific node.
Returns a list of all edges that start from the node with the given
fromNodeId. If no edges are found, an empty list is returned.
The serializer function is used to convert the JSON data back into
your custom edge type. It should match the structure of your edge's
fromJson method.
Example:
final edges = box.loadEdges<MyEdge>(
'node_id',
serializer: (json) => MyEdge.fromJson(json),
);
Returns an empty list if no edges are found or if deserialization fails.
Implementation
List<T> loadEdges<T>(
String fromNodeId, {
required T Function(Map<String, dynamic>) serializer,
}) {
final ptr = fromNodeId.toNativeUtf8().cast<ffi.Char>();
final resultPtr = _bindings.graphdb_load_edges(_handle, ptr);
malloc.free(ptr);
if (resultPtr == ffi.nullptr) {
log('loadEdges: No edges found for node id: $fromNodeId');
return [];
}
try {
final result = resultPtr.cast<Utf8>().toDartString();
_bindings.graphdb_free_string(resultPtr);
final jsonData = jsonDecode(result) as List<dynamic>;
return jsonData
.map((item) => serializer(item as Map<String, dynamic>))
.toList();
} catch (e) {
_bindings.graphdb_free_string(resultPtr);
log('loadEdges: Error deserializing edges for node id $fromNodeId: $e');
return [];
}
}